Skip to content

Commit 562389d

Browse files
committed
- remove syntax::{span_warn!, span_err!, span_fatal!. struct_err!}
- 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
1 parent 766fba3 commit 562389d

File tree

103 files changed

+562
-573
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+562
-573
lines changed

Cargo.lock

+2
Original file line numberDiff line numberDiff line change
@@ -3774,6 +3774,7 @@ version = "0.0.0"
37743774
dependencies = [
37753775
"rustc",
37763776
"rustc_error_codes",
3777+
"rustc_errors",
37773778
"rustc_metadata",
37783779
"rustc_span",
37793780
"syntax",
@@ -3787,6 +3788,7 @@ dependencies = [
37873788
"rustc",
37883789
"rustc_data_structures",
37893790
"rustc_error_codes",
3791+
"rustc_errors",
37903792
"rustc_span",
37913793
"rustc_typeck",
37923794
"syntax",

src/librustc/hir/check_attr.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ use crate::hir::def_id::DefId;
88
use crate::hir::intravisit::{self, NestedVisitorMap, Visitor};
99
use crate::hir::DUMMY_HIR_ID;
1010
use crate::hir::{self, Attribute, HirId, Item, ItemKind, TraitItem, TraitItemKind};
11-
use crate::lint::builtin::UNUSED_ATTRIBUTES;
11+
use crate::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES};
1212
use crate::ty::query::Providers;
1313
use crate::ty::TyCtxt;
1414

15+
use errors::{error_code, struct_span_err};
1516
use rustc_span::Span;
17+
1618
use std::fmt::{self, Display};
1719
use syntax::{attr, symbol::sym};
1820

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

195-
self.check_repr(attrs, span, target, item);
197+
self.check_repr(attrs, span, target, item, hir_id);
196198
self.check_used(attrs, target);
197199
}
198200

@@ -353,6 +355,7 @@ impl CheckAttrVisitor<'tcx> {
353355
span: &Span,
354356
target: Target,
355357
item: Option<&Item<'_>>,
358+
hir_id: HirId,
356359
) {
357360
// Extract the names of all repr hints, e.g., [foo, bar, align] for:
358361
// ```
@@ -428,21 +431,29 @@ impl CheckAttrVisitor<'tcx> {
428431
// Error on repr(transparent, <anything else>).
429432
if is_transparent && hints.len() > 1 {
430433
let hint_spans: Vec<_> = hint_spans.clone().collect();
431-
span_err!(
434+
struct_span_err!(
432435
self.tcx.sess,
433436
hint_spans,
434437
E0692,
435438
"transparent {} cannot have other repr hints",
436439
target
437-
);
440+
)
441+
.emit();
438442
}
439443
// Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8)
440444
if (int_reprs > 1)
441445
|| (is_simd && is_c)
442446
|| (int_reprs == 1 && is_c && item.map_or(false, |item| is_c_like_enum(item)))
443447
{
444-
let hint_spans: Vec<_> = hint_spans.collect();
445-
span_warn!(self.tcx.sess, hint_spans, E0566, "conflicting representation hints");
448+
self.tcx
449+
.struct_span_lint_hir(
450+
CONFLICTING_REPR_HINTS,
451+
hir_id,
452+
hint_spans.collect::<Vec<Span>>(),
453+
"conflicting representation hints",
454+
)
455+
.code(error_code!(E0566))
456+
.emit();
446457
}
447458
}
448459

src/librustc/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ use crate::ty::{
6565
Region, Ty, TyCtxt, TypeFoldable,
6666
};
6767

68-
use errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
68+
use errors::{struct_span_err, Applicability, DiagnosticBuilder, DiagnosticStyledString};
6969
use rustc_error_codes::*;
7070
use rustc_span::{Pos, Span};
7171
use rustc_target::spec::abi;

src/librustc/infer/error_reporting/need_type_info.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::infer::type_variable::TypeVariableOriginKind;
55
use crate::infer::InferCtxt;
66
use crate::ty::print::Print;
77
use crate::ty::{self, DefIdTree, Infer, Ty, TyVar};
8-
use errors::{Applicability, DiagnosticBuilder};
8+
use errors::{struct_span_err, Applicability, DiagnosticBuilder};
99
use rustc_span::Span;
1010
use std::borrow::Cow;
1111
use syntax::source_map::DesugaringKind;
@@ -153,14 +153,11 @@ pub enum TypeAnnotationNeeded {
153153

154154
impl Into<errors::DiagnosticId> for TypeAnnotationNeeded {
155155
fn into(self) -> errors::DiagnosticId {
156-
syntax::diagnostic_used!(E0282);
157-
syntax::diagnostic_used!(E0283);
158-
syntax::diagnostic_used!(E0284);
159-
errors::DiagnosticId::Error(match self {
160-
Self::E0282 => "E0282".to_string(),
161-
Self::E0283 => "E0283".to_string(),
162-
Self::E0284 => "E0284".to_string(),
163-
})
156+
match self {
157+
Self::E0282 => errors::error_code!(E0282),
158+
Self::E0283 => errors::error_code!(E0283),
159+
Self::E0284 => errors::error_code!(E0284),
160+
}
164161
}
165162
}
166163

src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::infer::error_reporting::nice_region_error::util::AnonymousParamInfo;
55
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
66
use crate::util::common::ErrorReported;
77

8+
use errors::struct_span_err;
89
use rustc_error_codes::*;
910

1011
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {

src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::hir::{FunctionRetTy, TyKind};
44
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
55
use crate::ty;
6-
use errors::{Applicability, DiagnosticBuilder};
6+
use errors::{struct_span_err, Applicability, DiagnosticBuilder};
77

88
use rustc_error_codes::*;
99

src/librustc/infer/error_reporting/note.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::infer::{self, InferCtxt, SubregionOrigin};
22
use crate::middle::region;
33
use crate::ty::error::TypeError;
44
use crate::ty::{self, Region};
5-
use errors::DiagnosticBuilder;
5+
use errors::{struct_span_err, DiagnosticBuilder};
66

77
use rustc_error_codes::*;
88

src/librustc/infer/opaque_types/mod.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder, TypeVisitor};
99
use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef};
1010
use crate::ty::{self, GenericParamDefKind, Ty, TyCtxt};
1111
use crate::util::nodemap::DefIdMap;
12-
use errors::DiagnosticBuilder;
12+
use errors::{struct_span_err, DiagnosticBuilder};
1313
use rustc::session::config::nightly_options;
1414
use rustc_data_structures::fx::FxHashMap;
1515
use rustc_data_structures::sync::Lrc;
@@ -523,11 +523,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
523523
err.span_label(span, label);
524524

525525
if nightly_options::is_nightly_build() {
526-
help!(
527-
err,
528-
"add #![feature(member_constraints)] to the crate attributes \
529-
to enable"
530-
);
526+
err.help("add #![feature(member_constraints)] to the crate attributes to enable");
531527
}
532528

533529
err.emit();

src/librustc/lint/builtin.rs

+13
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ declare_lint! {
9595
"detects overlapping patterns"
9696
}
9797

98+
declare_lint! {
99+
pub BINDING_VARIANT_NAME,
100+
Warn,
101+
"detects pattern bindings with the same name as one of the matched variants"
102+
}
103+
104+
declare_lint! {
105+
pub CONFLICTING_REPR_HINTS,
106+
Warn,
107+
"detects when more than one `#[repr(..)]` attribute, with different meaning, is applied"
108+
}
109+
98110
declare_lint! {
99111
pub UNUSED_MACROS,
100112
Warn,
@@ -459,6 +471,7 @@ declare_lint_pass! {
459471
UNREACHABLE_CODE,
460472
UNREACHABLE_PATTERNS,
461473
OVERLAPPING_PATTERNS,
474+
BINDING_VARIANT_NAME,
462475
UNUSED_MACROS,
463476
WARNINGS,
464477
UNUSED_FEATURES,

src/librustc/lint/context.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ use crate::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt};
3232
use crate::util::common::time;
3333
use crate::util::nodemap::FxHashMap;
3434

35-
use errors::DiagnosticBuilder;
35+
use errors::{struct_span_err, DiagnosticBuilder};
3636
use rustc_data_structures::sync::{self, join, par_iter, ParallelIterator};
37-
use rustc_span::{symbol::Symbol, MultiSpan, Span};
37+
use rustc_span::{symbol::Symbol, MultiSpan, Span, DUMMY_SP};
3838
use std::slice;
3939
use syntax::ast;
4040
use syntax::util::lev_distance::find_best_match_for_name;
@@ -295,7 +295,8 @@ impl LintStore {
295295
CheckLintNameResult::Ok(_) => None,
296296
CheckLintNameResult::Warning(ref msg, _) => Some(sess.struct_warn(msg)),
297297
CheckLintNameResult::NoLint(suggestion) => {
298-
let mut err = struct_err!(sess, E0602, "unknown lint: `{}`", lint_name);
298+
let mut err =
299+
struct_span_err!(sess, DUMMY_SP, E0602, "unknown lint: `{}`", lint_name);
299300

300301
if let Some(suggestion) = suggestion {
301302
err.help(&format!("did you mean: `{}`", suggestion));

src/librustc/lint/levels.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::lint::context::{CheckLintNameResult, LintStore};
77
use crate::lint::{self, Level, Lint, LintId, LintSource};
88
use crate::session::Session;
99
use crate::util::nodemap::FxHashMap;
10-
use errors::{Applicability, DiagnosticBuilder};
10+
use errors::{struct_span_err, Applicability, DiagnosticBuilder};
1111
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1212
use syntax::ast;
1313
use syntax::attr;
@@ -274,13 +274,14 @@ impl<'a> LintLevelsBuilder<'a> {
274274
let tool_name = if meta_item.path.segments.len() > 1 {
275275
let tool_ident = meta_item.path.segments[0].ident;
276276
if !attr::is_known_lint_tool(tool_ident) {
277-
span_err!(
277+
struct_span_err!(
278278
sess,
279279
tool_ident.span,
280280
E0710,
281281
"an unknown tool name found in scoped lint: `{}`",
282282
pprust::path_to_string(&meta_item.path),
283-
);
283+
)
284+
.emit();
284285
continue;
285286
}
286287

src/librustc/middle/lang_items.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::util::nodemap::FxHashMap;
1818

1919
use crate::hir;
2020
use crate::hir::itemlikevisit::ItemLikeVisitor;
21+
use errors::struct_span_err;
2122
use rustc_macros::HashStable;
2223
use rustc_span::Span;
2324
use syntax::ast;
@@ -184,7 +185,8 @@ impl LanguageItemCollector<'tcx> {
184185
span,
185186
E0152,
186187
"duplicate lang item found: `{}`.",
187-
name),
188+
name
189+
),
188190
None => {
189191
match self.tcx.extern_crate(item_def_id) {
190192
Some(ExternCrate {dependency_of, ..}) => {
@@ -204,7 +206,7 @@ impl LanguageItemCollector<'tcx> {
204206
},
205207
};
206208
if let Some(span) = self.tcx.hir().span_if_local(original_def_id) {
207-
span_note!(&mut err, span, "first defined here.");
209+
err.span_note(span, "first defined here.");
208210
} else {
209211
match self.tcx.extern_crate(original_def_id) {
210212
Some(ExternCrate {dependency_of, ..}) => {

src/librustc/middle/weak_lang_items.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::hir::def_id::DefId;
88
use crate::hir::intravisit;
99
use crate::hir::intravisit::{NestedVisitorMap, Visitor};
1010
use crate::ty::TyCtxt;
11+
use errors::struct_span_err;
1112
use rustc_data_structures::fx::FxHashSet;
1213
use rustc_span::Span;
1314
use rustc_target::spec::PanicStrategy;
@@ -124,9 +125,12 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
124125
self.items.missing.push(lang_items::$item);
125126
}
126127
} else)* {
127-
span_err!(self.tcx.sess, span, E0264,
128-
"unknown external lang item: `{}`",
129-
name);
128+
struct_span_err!(
129+
self.tcx.sess, span, E0264,
130+
"unknown external lang item: `{}`",
131+
name
132+
)
133+
.emit();
130134
}
131135
}
132136
}

src/librustc/mir/interpret/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::ty::query::TyCtxtAt;
88
use crate::ty::{self, layout, Ty};
99

1010
use backtrace::Backtrace;
11-
use errors::DiagnosticBuilder;
11+
use errors::{struct_span_err, DiagnosticBuilder};
1212
use hir::GeneratorKind;
1313
use rustc_macros::HashStable;
1414
use rustc_span::{Pos, Span};

src/librustc/traits/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::ty::TypeckTables;
2323
use crate::ty::{self, AdtKind, DefIdTree, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable};
2424
use crate::util::nodemap::{FxHashMap, FxHashSet};
2525

26-
use errors::{pluralize, Applicability, DiagnosticBuilder, Style};
26+
use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, Style};
2727
use rustc::hir::def_id::LOCAL_CRATE;
2828
use rustc_span::source_map::SourceMap;
2929
use rustc_span::{ExpnKind, MultiSpan, Span, DUMMY_SP};

src/librustc/traits/on_unimplemented.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::ty::{self, GenericParamDefKind, TyCtxt};
55
use crate::util::common::ErrorReported;
66
use crate::util::nodemap::FxHashMap;
77

8+
use errors::struct_span_err;
89
use rustc_span::Span;
910
use syntax::ast::{MetaItem, NestedMetaItem};
1011
use syntax::attr;
@@ -293,26 +294,28 @@ impl<'tcx> OnUnimplementedFormatString {
293294
match generics.params.iter().find(|param| param.name == s) {
294295
Some(_) => (),
295296
None => {
296-
span_err!(
297+
struct_span_err!(
297298
tcx.sess,
298299
span,
299300
E0230,
300301
"there is no parameter `{}` on trait `{}`",
301302
s,
302303
name
303-
);
304+
)
305+
.emit();
304306
result = Err(ErrorReported);
305307
}
306308
}
307309
}
308310
// `{:1}` and `{}` are not to be used
309311
Position::ArgumentIs(_) | Position::ArgumentImplicitlyIs(_) => {
310-
span_err!(
312+
struct_span_err!(
311313
tcx.sess,
312314
span,
313315
E0231,
314316
"only named substitution parameters are allowed"
315-
);
317+
)
318+
.emit();
316319
result = Err(ErrorReported);
317320
}
318321
},

src/librustc/traits/query/dropck_outlives.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ pub struct DropckOutlivesResult<'tcx> {
7676
impl<'tcx> DropckOutlivesResult<'tcx> {
7777
pub fn report_overflows(&self, tcx: TyCtxt<'tcx>, span: Span, ty: Ty<'tcx>) {
7878
if let Some(overflow_ty) = self.overflows.iter().next() {
79-
let mut err = struct_span_err!(
79+
errors::struct_span_err!(
8080
tcx.sess,
8181
span,
8282
E0320,
8383
"overflow while adding drop-check rules for {}",
8484
ty,
85-
);
86-
err.note(&format!("overflowed on {}", overflow_ty));
87-
err.emit();
85+
)
86+
.note(&format!("overflowed on {}", overflow_ty))
87+
.emit();
8888
}
8989
}
9090

src/librustc/traits/specialize/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::traits::select::IntercrateAmbiguityCause;
1818
use crate::traits::{self, coherence, FutureCompatOverlapErrorKind, ObligationCause, TraitEngine};
1919
use crate::ty::subst::{InternalSubsts, Subst, SubstsRef};
2020
use crate::ty::{self, TyCtxt, TypeFoldable};
21+
use errors::struct_span_err;
2122
use rustc_data_structures::fx::FxHashSet;
2223
use rustc_span::DUMMY_SP;
2324

src/librustc/ty/query/plumbing.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ use crate::ty::query::Query;
99
use crate::ty::tls;
1010
use crate::ty::{self, TyCtxt};
1111

12-
use errors::Diagnostic;
13-
use errors::DiagnosticBuilder;
14-
use errors::FatalError;
15-
use errors::Handler;
16-
use errors::Level;
12+
use errors::{struct_span_err, Diagnostic, DiagnosticBuilder, FatalError, Handler, Level};
1713
#[cfg(not(parallel_compiler))]
1814
use rustc_data_structures::cold_path;
1915
use rustc_data_structures::fx::{FxHashMap, FxHasher};

0 commit comments

Comments
 (0)