Skip to content

Commit

Permalink
- remove syntax::{span_warn!, span_err!, span_fatal!. struct_err!}
Browse files Browse the repository at this point in the history
- remove syntax::{help!, span_help!, span_note!}
- remove unused syntax::{struct_span_fatal, struct_span_err_or_warn!, span_err_or_warn!}
- lintify check_for_bindings_named_same_as_variants + conflicting_repr_hints
- inline syntax::{struct_span_warn!, diagnostic_used!}
- stringify_error_code! -> error_code! & use it more.
- find_plugin_registrar: de-fatalize an error
- de-fatalize metadata errors
- move type_error_struct! to rustc_typeck
- struct_span_err! -> rustc_errors
  • Loading branch information
Centril committed Jan 2, 2020
1 parent 766fba3 commit 562389d
Show file tree
Hide file tree
Showing 103 changed files with 562 additions and 573 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3774,6 +3774,7 @@ version = "0.0.0"
dependencies = [
"rustc",
"rustc_error_codes",
"rustc_errors",
"rustc_metadata",
"rustc_span",
"syntax",
Expand All @@ -3787,6 +3788,7 @@ dependencies = [
"rustc",
"rustc_data_structures",
"rustc_error_codes",
"rustc_errors",
"rustc_span",
"rustc_typeck",
"syntax",
Expand Down
23 changes: 17 additions & 6 deletions src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ use crate::hir::def_id::DefId;
use crate::hir::intravisit::{self, NestedVisitorMap, Visitor};
use crate::hir::DUMMY_HIR_ID;
use crate::hir::{self, Attribute, HirId, Item, ItemKind, TraitItem, TraitItemKind};
use crate::lint::builtin::UNUSED_ATTRIBUTES;
use crate::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES};
use crate::ty::query::Providers;
use crate::ty::TyCtxt;

use errors::{error_code, struct_span_err};
use rustc_span::Span;

use std::fmt::{self, Display};
use syntax::{attr, symbol::sym};

Expand Down Expand Up @@ -192,7 +194,7 @@ impl CheckAttrVisitor<'tcx> {
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id));
}

self.check_repr(attrs, span, target, item);
self.check_repr(attrs, span, target, item, hir_id);
self.check_used(attrs, target);
}

Expand Down Expand Up @@ -353,6 +355,7 @@ impl CheckAttrVisitor<'tcx> {
span: &Span,
target: Target,
item: Option<&Item<'_>>,
hir_id: HirId,
) {
// Extract the names of all repr hints, e.g., [foo, bar, align] for:
// ```
Expand Down Expand Up @@ -428,21 +431,29 @@ 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");
self.tcx
.struct_span_lint_hir(
CONFLICTING_REPR_HINTS,
hir_id,
hint_spans.collect::<Vec<Span>>(),
"conflicting representation hints",
)
.code(error_code!(E0566))
.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 @@ -65,7 +65,7 @@ use crate::ty::{
Region, Ty, TyCtxt, TypeFoldable,
};

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 @@ -5,7 +5,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_span::Span;
use std::borrow::Cow;
use syntax::source_map::DesugaringKind;
Expand Down Expand Up @@ -153,14 +153,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 @@ -3,7 +3,7 @@
use crate::hir::{FunctionRetTy, TyKind};
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_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 @@ -2,7 +2,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 @@ -9,7 +9,7 @@ use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder, TypeVisitor};
use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef};
use crate::ty::{self, GenericParamDefKind, Ty, TyCtxt};
use crate::util::nodemap::DefIdMap;
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 @@ -523,11 +523,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
13 changes: 13 additions & 0 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ declare_lint! {
"detects overlapping patterns"
}

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

declare_lint! {
pub CONFLICTING_REPR_HINTS,
Warn,
"detects when more than one `#[repr(..)]` attribute, with different meaning, is applied"
}

declare_lint! {
pub UNUSED_MACROS,
Warn,
Expand Down Expand Up @@ -459,6 +471,7 @@ declare_lint_pass! {
UNREACHABLE_CODE,
UNREACHABLE_PATTERNS,
OVERLAPPING_PATTERNS,
BINDING_VARIANT_NAME,
UNUSED_MACROS,
WARNINGS,
UNUSED_FEATURES,
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ use crate::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt};
use crate::util::common::time;
use crate::util::nodemap::FxHashMap;

use errors::DiagnosticBuilder;
use errors::{struct_span_err, DiagnosticBuilder};
use rustc_data_structures::sync::{self, join, par_iter, ParallelIterator};
use rustc_span::{symbol::Symbol, MultiSpan, Span};
use rustc_span::{symbol::Symbol, MultiSpan, Span, DUMMY_SP};
use std::slice;
use syntax::ast;
use syntax::util::lev_distance::find_best_match_for_name;
Expand Down Expand Up @@ -295,7 +295,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 @@ -7,7 +7,7 @@ use crate::lint::context::{CheckLintNameResult, LintStore};
use crate::lint::{self, Level, Lint, LintId, LintSource};
use crate::session::Session;
use crate::util::nodemap::FxHashMap;
use errors::{Applicability, DiagnosticBuilder};
use errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use syntax::ast;
use syntax::attr;
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 @@ -18,6 +18,7 @@ use crate::util::nodemap::FxHashMap;

use crate::hir;
use crate::hir::itemlikevisit::ItemLikeVisitor;
use errors::struct_span_err;
use rustc_macros::HashStable;
use rustc_span::Span;
use syntax::ast;
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 @@ -8,6 +8,7 @@ use crate::hir::def_id::DefId;
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_span::Span;
use rustc_target::spec::PanicStrategy;
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 @@ -8,7 +8,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_macros::HashStable;
use rustc_span::{Pos, Span};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::ty::TypeckTables;
use crate::ty::{self, AdtKind, DefIdTree, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable};
use crate::util::nodemap::{FxHashMap, FxHashSet};

use errors::{pluralize, Applicability, DiagnosticBuilder, Style};
use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, Style};
use rustc::hir::def_id::LOCAL_CRATE;
use rustc_span::source_map::SourceMap;
use rustc_span::{ExpnKind, MultiSpan, Span, DUMMY_SP};
Expand Down
11 changes: 7 additions & 4 deletions src/librustc/traits/on_unimplemented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::ty::{self, GenericParamDefKind, TyCtxt};
use crate::util::common::ErrorReported;
use crate::util::nodemap::FxHashMap;

use errors::struct_span_err;
use rustc_span::Span;
use syntax::ast::{MetaItem, NestedMetaItem};
use syntax::attr;
Expand Down Expand Up @@ -293,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 @@ -18,6 +18,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_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

0 comments on commit 562389d

Please sign in to comment.