Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More reductions in error handling diversity #67770

Merged
merged 2 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3804,6 +3804,7 @@ version = "0.0.0"
dependencies = [
"rustc",
"rustc_error_codes",
"rustc_errors",
"rustc_hir",
"rustc_metadata",
"rustc_span",
Expand All @@ -3818,6 +3819,7 @@ dependencies = [
"rustc",
"rustc_data_structures",
"rustc_error_codes",
"rustc_errors",
"rustc_hir",
"rustc_span",
"rustc_typeck",
Expand Down
16 changes: 12 additions & 4 deletions src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use crate::hir::intravisit::{self, NestedVisitorMap, Visitor};
use crate::lint::builtin::UNUSED_ATTRIBUTES;
use crate::ty::query::Providers;
use crate::ty::TyCtxt;

use errors::struct_span_err;
use rustc_error_codes::*;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
Expand Down Expand Up @@ -430,21 +432,27 @@ impl CheckAttrVisitor<'tcx> {
// Error on repr(transparent, <anything else>).
if is_transparent && hints.len() > 1 {
let hint_spans: Vec<_> = hint_spans.clone().collect();
span_err!(
struct_span_err!(
self.tcx.sess,
hint_spans,
E0692,
"transparent {} cannot have other repr hints",
target
);
)
.emit();
}
// Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8)
if (int_reprs > 1)
|| (is_simd && is_c)
|| (int_reprs == 1 && is_c && item.map_or(false, |item| is_c_like_enum(item)))
{
let hint_spans: Vec<_> = hint_spans.collect();
span_warn!(self.tcx.sess, hint_spans, E0566, "conflicting representation hints");
Centril marked this conversation as resolved.
Show resolved Hide resolved
struct_span_err!(
self.tcx.sess,
hint_spans.collect::<Vec<Span>>(),
E0566,
"conflicting representation hints",
)
.emit();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::Node;

use errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
use errors::{struct_span_err, Applicability, DiagnosticBuilder, DiagnosticStyledString};
use rustc_error_codes::*;
use rustc_span::{Pos, Span};
use rustc_target::spec::abi;
Expand Down
15 changes: 6 additions & 9 deletions src/librustc/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::infer::type_variable::TypeVariableOriginKind;
use crate::infer::InferCtxt;
use crate::ty::print::Print;
use crate::ty::{self, DefIdTree, Infer, Ty, TyVar};
use errors::{Applicability, DiagnosticBuilder};
use errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Namespace};
use rustc_hir::{Body, Expr, ExprKind, FunctionRetTy, HirId, Local, Pat};
Expand Down Expand Up @@ -151,14 +151,11 @@ pub enum TypeAnnotationNeeded {

impl Into<errors::DiagnosticId> for TypeAnnotationNeeded {
fn into(self) -> errors::DiagnosticId {
syntax::diagnostic_used!(E0282);
syntax::diagnostic_used!(E0283);
syntax::diagnostic_used!(E0284);
errors::DiagnosticId::Error(match self {
Self::E0282 => "E0282".to_string(),
Self::E0283 => "E0283".to_string(),
Self::E0284 => "E0284".to_string(),
})
match self {
Self::E0282 => errors::error_code!(E0282),
Self::E0283 => errors::error_code!(E0283),
Self::E0284 => errors::error_code!(E0284),
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::infer::error_reporting::nice_region_error::util::AnonymousParamInfo;
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
use crate::util::common::ErrorReported;

use errors::struct_span_err;
use rustc_error_codes::*;

impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! where one region is named and the other is anonymous.
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
use crate::ty;
use errors::{Applicability, DiagnosticBuilder};
use errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_hir::{FunctionRetTy, TyKind};

use rustc_error_codes::*;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::infer::{self, InferCtxt, SubregionOrigin};
use crate::middle::region;
use crate::ty::error::TypeError;
use crate::ty::{self, Region};
use errors::DiagnosticBuilder;
use errors::{struct_span_err, DiagnosticBuilder};

use rustc_error_codes::*;

Expand Down
8 changes: 2 additions & 6 deletions src/librustc/infer/opaque_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder, TypeVisitor};
use crate::ty::free_region_map::FreeRegionRelations;
use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef};
use crate::ty::{self, GenericParamDefKind, Ty, TyCtxt};
use errors::DiagnosticBuilder;
use errors::{struct_span_err, DiagnosticBuilder};
use rustc::session::config::nightly_options;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::Lrc;
Expand Down Expand Up @@ -524,11 +524,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
err.span_label(span, label);

if nightly_options::is_nightly_build() {
help!(
err,
"add #![feature(member_constraints)] to the crate attributes \
to enable"
);
err.help("add #![feature(member_constraints)] to the crate attributes to enable");
}

err.emit();
Expand Down
7 changes: 7 additions & 0 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ declare_lint! {
"detects overlapping patterns"
}

declare_lint! {
pub BINDINGS_WITH_VARIANT_NAME,
Warn,
"detects pattern bindings with the same name as one of the matched variants"
}

declare_lint! {
pub UNUSED_MACROS,
Warn,
Expand Down Expand Up @@ -459,6 +465,7 @@ declare_lint_pass! {
UNREACHABLE_CODE,
UNREACHABLE_PATTERNS,
OVERLAPPING_PATTERNS,
BINDINGS_WITH_VARIANT_NAME,
UNUSED_MACROS,
WARNINGS,
UNUSED_FEATURES,
Expand Down
11 changes: 6 additions & 5 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ use crate::middle::privacy::AccessLevels;
use crate::session::Session;
use crate::ty::layout::{LayoutError, LayoutOf, TyLayout};
use crate::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt};
use errors::DiagnosticBuilder;
use errors::{struct_span_err, DiagnosticBuilder};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync;
use rustc_error_codes::*;
use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId};
use rustc_span::{symbol::Symbol, MultiSpan, Span};
use std::slice;
use rustc_span::{symbol::Symbol, MultiSpan, Span, DUMMY_SP};
use syntax::ast;
use syntax::util::lev_distance::find_best_match_for_name;

use rustc_error_codes::*;
use std::slice;

/// Information about the registered lints.
///
Expand Down Expand Up @@ -290,7 +290,8 @@ impl LintStore {
CheckLintNameResult::Ok(_) => None,
CheckLintNameResult::Warning(ref msg, _) => Some(sess.struct_warn(msg)),
CheckLintNameResult::NoLint(suggestion) => {
let mut err = struct_err!(sess, E0602, "unknown lint: `{}`", lint_name);
let mut err =
struct_span_err!(sess, DUMMY_SP, E0602, "unknown lint: `{}`", lint_name);

if let Some(suggestion) = suggestion {
err.help(&format!("did you mean: `{}`", suggestion));
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/lint/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::lint::builtin;
use crate::lint::context::{CheckLintNameResult, LintStore};
use crate::lint::{self, Level, Lint, LintId, LintSource};
use crate::session::Session;
use errors::{Applicability, DiagnosticBuilder};
use errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_hir::HirId;
Expand Down Expand Up @@ -274,13 +274,14 @@ impl<'a> LintLevelsBuilder<'a> {
let tool_name = if meta_item.path.segments.len() > 1 {
let tool_ident = meta_item.path.segments[0].ident;
if !attr::is_known_lint_tool(tool_ident) {
span_err!(
struct_span_err!(
sess,
tool_ident.span,
E0710,
"an unknown tool name found in scoped lint: `{}`",
pprust::path_to_string(&meta_item.path),
);
)
.emit();
continue;
}

Expand Down
6 changes: 4 additions & 2 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::middle::cstore::ExternCrate;
use crate::middle::weak_lang_items;
use crate::ty::{self, TyCtxt};

use errors::struct_span_err;
use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
Expand Down Expand Up @@ -184,7 +185,8 @@ impl LanguageItemCollector<'tcx> {
span,
E0152,
"duplicate lang item found: `{}`.",
name),
name
),
None => {
match self.tcx.extern_crate(item_def_id) {
Some(ExternCrate {dependency_of, ..}) => {
Expand All @@ -204,7 +206,7 @@ impl LanguageItemCollector<'tcx> {
},
};
if let Some(span) = self.tcx.hir().span_if_local(original_def_id) {
span_note!(&mut err, span, "first defined here.");
err.span_note(span, "first defined here.");
} else {
match self.tcx.extern_crate(original_def_id) {
Some(ExternCrate {dependency_of, ..}) => {
Expand Down
10 changes: 7 additions & 3 deletions src/librustc/middle/weak_lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::session::config;
use crate::hir::intravisit;
use crate::hir::intravisit::{NestedVisitorMap, Visitor};
use crate::ty::TyCtxt;
use errors::struct_span_err;
use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
Expand Down Expand Up @@ -124,9 +125,12 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
self.items.missing.push(lang_items::$item);
}
} else)* {
span_err!(self.tcx.sess, span, E0264,
"unknown external lang item: `{}`",
name);
struct_span_err!(
self.tcx.sess, span, E0264,
"unknown external lang item: `{}`",
name
)
.emit();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::ty::query::TyCtxtAt;
use crate::ty::{self, layout, Ty};

use backtrace::Backtrace;
use errors::DiagnosticBuilder;
use errors::{struct_span_err, DiagnosticBuilder};
use hir::GeneratorKind;
use rustc_hir as hir;
use rustc_macros::HashStable;
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use crate::ty::GenericParamDefKind;
use crate::ty::SubtypePredicate;
use crate::ty::TypeckTables;
use crate::ty::{self, AdtKind, DefIdTree, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable};
use errors::{pluralize, Applicability, DiagnosticBuilder, Style};

use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, Style};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
Expand Down
12 changes: 8 additions & 4 deletions src/librustc/traits/on_unimplemented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use fmt_macros::{Parser, Piece, Position};

use crate::ty::{self, GenericParamDefKind, TyCtxt};
use crate::util::common::ErrorReported;

use errors::struct_span_err;
use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::DefId;
use rustc_span::symbol::{kw, sym, Symbol};
Expand Down Expand Up @@ -292,26 +294,28 @@ impl<'tcx> OnUnimplementedFormatString {
match generics.params.iter().find(|param| param.name == s) {
Some(_) => (),
None => {
span_err!(
struct_span_err!(
tcx.sess,
span,
E0230,
"there is no parameter `{}` on trait `{}`",
s,
name
);
)
.emit();
result = Err(ErrorReported);
}
}
}
// `{:1}` and `{}` are not to be used
Position::ArgumentIs(_) | Position::ArgumentImplicitlyIs(_) => {
span_err!(
struct_span_err!(
tcx.sess,
span,
E0231,
"only named substitution parameters are allowed"
);
)
.emit();
result = Err(ErrorReported);
}
},
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/traits/query/dropck_outlives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ pub struct DropckOutlivesResult<'tcx> {
impl<'tcx> DropckOutlivesResult<'tcx> {
pub fn report_overflows(&self, tcx: TyCtxt<'tcx>, span: Span, ty: Ty<'tcx>) {
if let Some(overflow_ty) = self.overflows.iter().next() {
let mut err = struct_span_err!(
errors::struct_span_err!(
tcx.sess,
span,
E0320,
"overflow while adding drop-check rules for {}",
ty,
);
err.note(&format!("overflowed on {}", overflow_ty));
err.emit();
)
.note(&format!("overflowed on {}", overflow_ty))
.emit();
}
}

Expand Down
1 change: 1 addition & 0 deletions src/librustc/traits/specialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::traits::select::IntercrateAmbiguityCause;
use crate::traits::{self, coherence, FutureCompatOverlapErrorKind, ObligationCause, TraitEngine};
use crate::ty::subst::{InternalSubsts, Subst, SubstsRef};
use crate::ty::{self, TyCtxt, TypeFoldable};
use errors::struct_span_err;
use rustc_data_structures::fx::FxHashSet;
use rustc_hir::def_id::DefId;
use rustc_span::DUMMY_SP;
Expand Down
6 changes: 1 addition & 5 deletions src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ use crate::ty::query::Query;
use crate::ty::tls;
use crate::ty::{self, TyCtxt};

use errors::Diagnostic;
use errors::DiagnosticBuilder;
use errors::FatalError;
use errors::Handler;
use errors::Level;
use errors::{struct_span_err, Diagnostic, DiagnosticBuilder, FatalError, Handler, Level};
#[cfg(not(parallel_compiler))]
use rustc_data_structures::cold_path;
use rustc_data_structures::fx::{FxHashMap, FxHasher};
Expand Down
Loading