Skip to content

Commit 6a42b64

Browse files
authored
Rollup merge of rust-lang#67770 - Centril:reduce-diversity-2, r=petrochenkov
More reductions in error handling diversity In this follow up to rust-lang#67744, we: - Remove all fatal / error / warning macros in `syntax` except for `struct_span_err`, which is moved to `rustc_errors`. - Lintify some hard-coded warnings which used warning macros. - Defatalize some errors. In general, the goal here is to make it painful to use fatal or unstructured errors and so we hopefully won't see many of these creep in.
2 parents 10f153f + 67be07d commit 6a42b64

File tree

109 files changed

+620
-656
lines changed

Some content is hidden

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

109 files changed

+620
-656
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use crate::lint::builtin::UNUSED_ATTRIBUTES;
1212
use crate::ty::query::Providers;
1313
use crate::ty::TyCtxt;
1414

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

@@ -428,21 +430,27 @@ impl CheckAttrVisitor<'tcx> {
428430
// Error on repr(transparent, <anything else>).
429431
if is_transparent && hints.len() > 1 {
430432
let hint_spans: Vec<_> = hint_spans.clone().collect();
431-
span_err!(
433+
struct_span_err!(
432434
self.tcx.sess,
433435
hint_spans,
434436
E0692,
435437
"transparent {} cannot have other repr hints",
436438
target
437-
);
439+
)
440+
.emit();
438441
}
439442
// Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8)
440443
if (int_reprs > 1)
441444
|| (is_simd && is_c)
442445
|| (int_reprs == 1 && is_c && item.map_or(false, |item| is_c_like_enum(item)))
443446
{
444-
let hint_spans: Vec<_> = hint_spans.collect();
445-
span_warn!(self.tcx.sess, hint_spans, E0566, "conflicting representation hints");
447+
struct_span_err!(
448+
self.tcx.sess,
449+
hint_spans.collect::<Vec<Span>>(),
450+
E0566,
451+
"conflicting representation hints",
452+
)
453+
.emit();
446454
}
447455
}
448456

src/librustc/infer/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 9 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 6 deletions
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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ declare_lint! {
9595
"detects overlapping patterns"
9696
}
9797

98+
declare_lint! {
99+
pub BINDINGS_WITH_VARIANT_NAME,
100+
Warn,
101+
"detects pattern bindings with the same name as one of the matched variants"
102+
}
103+
98104
declare_lint! {
99105
pub UNUSED_MACROS,
100106
Warn,
@@ -459,6 +465,7 @@ declare_lint_pass! {
459465
UNREACHABLE_CODE,
460466
UNREACHABLE_PATTERNS,
461467
OVERLAPPING_PATTERNS,
468+
BINDINGS_WITH_VARIANT_NAME,
462469
UNUSED_MACROS,
463470
WARNINGS,
464471
UNUSED_FEATURES,

src/librustc/lint/context.rs

Lines changed: 4 additions & 3 deletions
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 7 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 4 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 5 deletions
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)