Skip to content

Commit ed6468d

Browse files
committed
Auto merge of #67770 - Centril:reduce-diversity-2, r=petrochenkov
More reductions in error handling diversity In this follow up to #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. Fixes #67933.
2 parents 87540bd + 20ebb80 commit ed6468d

File tree

111 files changed

+629
-655
lines changed

Some content is hidden

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

111 files changed

+629
-655
lines changed

Diff for: Cargo.lock

+2
Original file line numberDiff line numberDiff line change
@@ -3804,6 +3804,7 @@ version = "0.0.0"
38043804
dependencies = [
38053805
"rustc",
38063806
"rustc_error_codes",
3807+
"rustc_errors",
38073808
"rustc_hir",
38083809
"rustc_metadata",
38093810
"rustc_span",
@@ -3818,6 +3819,7 @@ dependencies = [
38183819
"rustc",
38193820
"rustc_data_structures",
38203821
"rustc_error_codes",
3822+
"rustc_errors",
38213823
"rustc_hir",
38223824
"rustc_span",
38233825
"rustc_typeck",

Diff for: src/librustc/hir/check_attr.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use crate::hir::intravisit::{self, NestedVisitorMap, Visitor};
88
use crate::lint::builtin::UNUSED_ATTRIBUTES;
99
use crate::ty::query::Providers;
1010
use crate::ty::TyCtxt;
11+
12+
use errors::struct_span_err;
1113
use rustc_error_codes::*;
1214
use rustc_hir as hir;
1315
use rustc_hir::def_id::DefId;
@@ -430,21 +432,27 @@ impl CheckAttrVisitor<'tcx> {
430432
// Error on repr(transparent, <anything else>).
431433
if is_transparent && hints.len() > 1 {
432434
let hint_spans: Vec<_> = hint_spans.clone().collect();
433-
span_err!(
435+
struct_span_err!(
434436
self.tcx.sess,
435437
hint_spans,
436438
E0692,
437439
"transparent {} cannot have other repr hints",
438440
target
439-
);
441+
)
442+
.emit();
440443
}
441444
// Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8)
442445
if (int_reprs > 1)
443446
|| (is_simd && is_c)
444447
|| (int_reprs == 1 && is_c && item.map_or(false, |item| is_c_like_enum(item)))
445448
{
446-
let hint_spans: Vec<_> = hint_spans.collect();
447-
span_warn!(self.tcx.sess, hint_spans, E0566, "conflicting representation hints");
449+
struct_span_err!(
450+
self.tcx.sess,
451+
hint_spans.collect::<Vec<Span>>(),
452+
E0566,
453+
"conflicting representation hints",
454+
)
455+
.emit();
448456
}
449457
}
450458

Diff for: src/librustc/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use rustc_hir as hir;
6868
use rustc_hir::def_id::DefId;
6969
use rustc_hir::Node;
7070

71-
use errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
71+
use errors::{struct_span_err, Applicability, DiagnosticBuilder, DiagnosticStyledString};
7272
use rustc_error_codes::*;
7373
use rustc_span::{Pos, Span};
7474
use rustc_target::spec::abi;

Diff for: src/librustc/infer/error_reporting/need_type_info.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::infer::type_variable::TypeVariableOriginKind;
44
use crate::infer::InferCtxt;
55
use crate::ty::print::Print;
66
use crate::ty::{self, DefIdTree, Infer, Ty, TyVar};
7-
use errors::{Applicability, DiagnosticBuilder};
7+
use errors::{struct_span_err, Applicability, DiagnosticBuilder};
88
use rustc_hir as hir;
99
use rustc_hir::def::{DefKind, Namespace};
1010
use rustc_hir::{Body, Expr, ExprKind, FunctionRetTy, HirId, Local, Pat};
@@ -151,14 +151,11 @@ pub enum TypeAnnotationNeeded {
151151

152152
impl Into<errors::DiagnosticId> for TypeAnnotationNeeded {
153153
fn into(self) -> errors::DiagnosticId {
154-
syntax::diagnostic_used!(E0282);
155-
syntax::diagnostic_used!(E0283);
156-
syntax::diagnostic_used!(E0284);
157-
errors::DiagnosticId::Error(match self {
158-
Self::E0282 => "E0282".to_string(),
159-
Self::E0283 => "E0283".to_string(),
160-
Self::E0284 => "E0284".to_string(),
161-
})
154+
match self {
155+
Self::E0282 => errors::error_code!(E0282),
156+
Self::E0283 => errors::error_code!(E0283),
157+
Self::E0284 => errors::error_code!(E0284),
158+
}
162159
}
163160
}
164161

Diff for: 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> {

Diff for: src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! where one region is named and the other is anonymous.
33
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
44
use crate::ty;
5-
use errors::{Applicability, DiagnosticBuilder};
5+
use errors::{struct_span_err, Applicability, DiagnosticBuilder};
66
use rustc_hir::{FunctionRetTy, TyKind};
77

88
use rustc_error_codes::*;

Diff for: src/librustc/infer/error_reporting/note.rs

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

88
use rustc_error_codes::*;
99

Diff for: src/librustc/infer/opaque_types/mod.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder, TypeVisitor};
66
use crate::ty::free_region_map::FreeRegionRelations;
77
use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef};
88
use crate::ty::{self, GenericParamDefKind, Ty, TyCtxt};
9-
use errors::DiagnosticBuilder;
9+
use errors::{struct_span_err, DiagnosticBuilder};
1010
use rustc::session::config::nightly_options;
1111
use rustc_data_structures::fx::FxHashMap;
1212
use rustc_data_structures::sync::Lrc;
@@ -524,11 +524,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
524524
err.span_label(span, label);
525525

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

534530
err.emit();

Diff for: src/librustc/lint/builtin.rs

+7
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,

Diff for: src/librustc/lint/context.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ use crate::middle::privacy::AccessLevels;
2525
use crate::session::Session;
2626
use crate::ty::layout::{LayoutError, LayoutOf, TyLayout};
2727
use crate::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt};
28-
use errors::DiagnosticBuilder;
28+
use errors::{struct_span_err, DiagnosticBuilder};
2929
use rustc_data_structures::fx::FxHashMap;
3030
use rustc_data_structures::sync;
31+
use rustc_error_codes::*;
3132
use rustc_hir as hir;
3233
use rustc_hir::def_id::{CrateNum, DefId};
33-
use rustc_span::{symbol::Symbol, MultiSpan, Span};
34-
use std::slice;
34+
use rustc_span::{symbol::Symbol, MultiSpan, Span, DUMMY_SP};
3535
use syntax::ast;
3636
use syntax::util::lev_distance::find_best_match_for_name;
3737

38-
use rustc_error_codes::*;
38+
use std::slice;
3939

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

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

Diff for: src/librustc/lint/levels.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::lint::builtin;
55
use crate::lint::context::{CheckLintNameResult, LintStore};
66
use crate::lint::{self, Level, Lint, LintId, LintSource};
77
use crate::session::Session;
8-
use errors::{Applicability, DiagnosticBuilder};
8+
use errors::{struct_span_err, Applicability, DiagnosticBuilder};
99
use rustc_data_structures::fx::FxHashMap;
1010
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1111
use rustc_hir::HirId;
@@ -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

Diff for: src/librustc/middle/lang_items.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::middle::cstore::ExternCrate;
1414
use crate::middle::weak_lang_items;
1515
use crate::ty::{self, TyCtxt};
1616

17+
use errors::struct_span_err;
1718
use rustc_data_structures::fx::FxHashMap;
1819
use rustc_hir as hir;
1920
use rustc_hir::def_id::DefId;
@@ -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, ..}) => {

Diff for: src/librustc/middle/weak_lang_items.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::session::config;
66
use crate::hir::intravisit;
77
use crate::hir::intravisit::{NestedVisitorMap, Visitor};
88
use crate::ty::TyCtxt;
9+
use errors::struct_span_err;
910
use rustc_data_structures::fx::FxHashSet;
1011
use rustc_hir as hir;
1112
use rustc_hir::def_id::DefId;
@@ -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
}

Diff for: src/librustc/mir/interpret/error.rs

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

99
use backtrace::Backtrace;
10-
use errors::DiagnosticBuilder;
10+
use errors::{struct_span_err, DiagnosticBuilder};
1111
use hir::GeneratorKind;
1212
use rustc_hir as hir;
1313
use rustc_macros::HashStable;

Diff for: src/librustc/traits/error_reporting.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use crate::ty::GenericParamDefKind;
2020
use crate::ty::SubtypePredicate;
2121
use crate::ty::TypeckTables;
2222
use crate::ty::{self, AdtKind, DefIdTree, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable};
23-
use errors::{pluralize, Applicability, DiagnosticBuilder, Style};
23+
24+
use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, Style};
2425
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2526
use rustc_hir as hir;
2627
use rustc_hir::def_id::{DefId, LOCAL_CRATE};

Diff for: src/librustc/traits/on_unimplemented.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use fmt_macros::{Parser, Piece, Position};
22

33
use crate::ty::{self, GenericParamDefKind, TyCtxt};
44
use crate::util::common::ErrorReported;
5+
6+
use errors::struct_span_err;
57
use rustc_data_structures::fx::FxHashMap;
68
use rustc_hir::def_id::DefId;
79
use rustc_span::symbol::{kw, sym, Symbol};
@@ -292,26 +294,28 @@ impl<'tcx> OnUnimplementedFormatString {
292294
match generics.params.iter().find(|param| param.name == s) {
293295
Some(_) => (),
294296
None => {
295-
span_err!(
297+
struct_span_err!(
296298
tcx.sess,
297299
span,
298300
E0230,
299301
"there is no parameter `{}` on trait `{}`",
300302
s,
301303
name
302-
);
304+
)
305+
.emit();
303306
result = Err(ErrorReported);
304307
}
305308
}
306309
}
307310
// `{:1}` and `{}` are not to be used
308311
Position::ArgumentIs(_) | Position::ArgumentImplicitlyIs(_) => {
309-
span_err!(
312+
struct_span_err!(
310313
tcx.sess,
311314
span,
312315
E0231,
313316
"only named substitution parameters are allowed"
314-
);
317+
)
318+
.emit();
315319
result = Err(ErrorReported);
316320
}
317321
},

Diff for: 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

Diff for: src/librustc/traits/specialize/mod.rs

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

Diff for: 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)