From d246385122ffd7dd6cc5c490b7e648f58c2ff7fd Mon Sep 17 00:00:00 2001 From: jumbatm Date: Sun, 2 Feb 2020 09:47:58 +1000 Subject: [PATCH] Run RustFmt --- src/librustc/lint.rs | 11 +- src/librustc/mir/interpret/error.rs | 17 +- src/librustc/traits/object_safety.rs | 12 +- src/librustc/traits/specialize/mod.rs | 10 +- src/librustc/ty/context.rs | 4 +- src/librustc_attr/builtin.rs | 4 +- src/librustc_errors/diagnostic_builder.rs | 6 +- src/librustc_expand/base.rs | 6 +- src/librustc_lint/builtin.rs | 300 ++++++++---------- src/librustc_lint/context.rs | 11 +- src/librustc_lint/internal.rs | 69 ++-- src/librustc_lint/levels.rs | 17 +- src/librustc_lint/non_ascii_idents.rs | 16 +- src/librustc_lint/nonstandard_style.rs | 29 +- src/librustc_lint/types.rs | 95 +++--- src/librustc_mir/borrow_check/mod.rs | 11 +- src/librustc_mir/const_eval/eval_queries.rs | 4 +- src/librustc_mir/transform/check_unsafety.rs | 12 +- src/librustc_mir/transform/const_prop.rs | 15 +- .../hair/pattern/check_match.rs | 42 ++- src/librustc_mir_build/lints.rs | 25 +- src/librustc_parse/config.rs | 6 +- src/librustc_parse/parser/mod.rs | 4 +- src/librustc_parse/validate_attr.rs | 10 +- src/librustc_passes/check_attr.rs | 31 +- src/librustc_passes/liveness.rs | 72 ++--- src/librustc_passes/stability.rs | 8 +- src/librustc_privacy/lib.rs | 24 +- src/librustc_resolve/lifetimes.rs | 19 +- src/librustc_typeck/check/cast.rs | 33 +- src/librustc_typeck/check/method/probe.rs | 4 +- src/librustc_typeck/check/mod.rs | 22 +- src/librustc_typeck/check_unused.rs | 1 - src/librustc_typeck/collect.rs | 5 +- .../passes/collect_intra_doc_links.rs | 13 +- src/librustdoc/passes/mod.rs | 9 +- 36 files changed, 477 insertions(+), 500 deletions(-) diff --git a/src/librustc/lint.rs b/src/librustc/lint.rs index a9273fcb8acd..004835b230ab 100644 --- a/src/librustc/lint.rs +++ b/src/librustc/lint.rs @@ -11,7 +11,6 @@ use rustc_span::hygiene::MacroKind; use rustc_span::source_map::{DesugaringKind, ExpnKind, MultiSpan}; use rustc_span::{Span, Symbol}; - /// How a lint level was set. #[derive(Clone, Copy, PartialEq, Eq, HashStable)] pub enum LintSource { @@ -175,7 +174,6 @@ impl<'a> HashStable> for LintLevelMap { } } - pub struct LintDiagnosticBuilder<'a>(DiagnosticBuilder<'a>); impl<'a> LintDiagnosticBuilder<'a> { @@ -186,7 +184,7 @@ impl<'a> LintDiagnosticBuilder<'a> { } /// Create a LintDiagnosticBuilder from some existing DiagnosticBuilder. - pub fn new(err: DiagnosticBuilder<'a>) -> LintDiagnosticBuilder<'a>{ + pub fn new(err: DiagnosticBuilder<'a>) -> LintDiagnosticBuilder<'a> { LintDiagnosticBuilder(err) } } @@ -207,14 +205,17 @@ pub fn struct_lint_level<'s, 'd>( level: Level, src: LintSource, span: Option, - decorate: Box FnOnce(LintDiagnosticBuilder<'b>) + 'd>) { + decorate: Box FnOnce(LintDiagnosticBuilder<'b>) + 'd>, + ) { let mut err = match (level, span) { (Level::Allow, _) => { return; } (Level::Warn, Some(span)) => sess.struct_span_warn(span, ""), (Level::Warn, None) => sess.struct_warn(""), - (Level::Deny, Some(span)) | (Level::Forbid, Some(span)) => sess.struct_span_err(span, ""), + (Level::Deny, Some(span)) | (Level::Forbid, Some(span)) => { + sess.struct_span_err(span, "") + } (Level::Deny, None) | (Level::Forbid, None) => sess.struct_err(""), }; diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index bb84458cf7b0..df3971a5ac3f 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -120,19 +120,18 @@ impl<'tcx> ConstEvalErr<'tcx> { } } lint.emit(); - } - , Some(lint_root)) { - Ok(_) => { - ErrorHandled::Reported - } + }, + Some(lint_root), + ) { + Ok(_) => ErrorHandled::Reported, Err(err) => err, } } - /// Sets the message passed in via `message`, then adds the span labels for you, before applying - /// further modifications in `emit`. It's up to you to call emit(), stash(..), etc. within the - /// `emit` method. If you don't need to do any additional processing, just use - /// struct_generic. + /// Sets the message passed in via `message`, then adds the span labels for you, before applying + /// further modifications in `emit`. It's up to you to call emit(), stash(..), etc. within the + /// `emit` method. If you don't need to do any additional processing, just use + /// struct_generic. fn struct_generic( &self, tcx: TyCtxtAt<'tcx>, diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs index 0e6347897d2b..4c5cd866b4a0 100644 --- a/src/librustc/traits/object_safety.rs +++ b/src/librustc/traits/object_safety.rs @@ -238,7 +238,10 @@ fn object_safety_violations_for_trait( )); let node = tcx.hir().get_if_local(trait_def_id); let msg = if let Some(hir::Node::Item(item)) = node { - err.span_label(item.ident.span, "this trait cannot be made into an object..."); + err.span_label( + item.ident.span, + "this trait cannot be made into an object...", + ); format!("...because {}", violation.error_msg()) } else { format!( @@ -252,7 +255,12 @@ fn object_safety_violations_for_trait( err.help(¬e); } (Some(_), Some((note, Some((sugg, span))))) => { - err.span_suggestion(span, ¬e, sugg, Applicability::MachineApplicable); + err.span_suggestion( + span, + ¬e, + sugg, + Applicability::MachineApplicable, + ); } // Only provide the help if its a local trait, otherwise it's not actionable. _ => {} diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index 33a78ae896b3..7c93a35158b0 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -16,13 +16,13 @@ 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 rustc::lint::LintDiagnosticBuilder; use rustc_data_structures::fx::FxHashSet; use rustc_errors::struct_span_err; use rustc_hir::def_id::DefId; use rustc_session::lint::builtin::COHERENCE_LEAK_CHECK; use rustc_session::lint::builtin::ORDER_DEPENDENT_TRAIT_OBJECTS; use rustc_span::DUMMY_SP; -use rustc::lint::LintDiagnosticBuilder; use super::util::impl_trait_ref_and_oblig; use super::{FulfillmentContext, SelectionContext}; @@ -357,9 +357,10 @@ pub(super) fn specialization_graph_provider( } Err(cname) => { let msg = match to_pretty_impl_header(tcx, overlap.with_impl) { - Some(s) => { - format!("conflicting implementation in crate `{}`:\n- {}", cname, s) - } + Some(s) => format!( + "conflicting implementation in crate `{}`:\n- {}", + cname, s + ), None => format!("conflicting implementation in crate `{}`", cname), }; err.note(&msg); @@ -396,7 +397,6 @@ pub(super) fn specialization_graph_provider( ) } }; - } } else { let parent = tcx.impl_parent(impl_def_id).unwrap_or(trait_id); diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index a885f9e96009..f2ad01b3d596 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -41,8 +41,8 @@ use crate::ty::{ExistentialPredicate, InferTy, ParamTy, PolyFnSig, Predicate, Pr use crate::ty::{InferConst, ParamConst}; use crate::ty::{List, TyKind, TyS}; use crate::util::common::ErrorReported; -use rustc_attr as attr; use rustc::lint::LintDiagnosticBuilder; +use rustc_attr as attr; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::profiling::SelfProfilerRef; use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap}; @@ -2594,7 +2594,7 @@ impl<'tcx> TyCtxt<'tcx> { lint: &'static Lint, hir_id: HirId, span: impl Into, - decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>) + decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>), ) { let (level, src) = self.lint_level_at_node(lint, hir_id); struct_lint_level(self.sess, lint, level, src, Some(span.into()), decorate); diff --git a/src/librustc_attr/builtin.rs b/src/librustc_attr/builtin.rs index e5381a58dab5..3c13735bbf41 100644 --- a/src/librustc_attr/builtin.rs +++ b/src/librustc_attr/builtin.rs @@ -37,7 +37,9 @@ fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) { .span_label(span, format!("expected one of {}", expected.join(", "))) .emit(); } - AttrError::MissingSince => { struct_span_err!(diag, span, E0542, "missing 'since'").emit(); }, + AttrError::MissingSince => { + struct_span_err!(diag, span, E0542, "missing 'since'").emit(); + } AttrError::MissingFeature => { struct_span_err!(diag, span, E0546, "missing 'feature'").emit(); } diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index 84bfa07d267d..39f585231eea 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -106,7 +106,11 @@ impl<'a> DiagnosticBuilder<'a> { /// /// See `emit` and `delay_as_bug` for details. pub fn emit_unless(&mut self, delay: bool) { - if delay { self.delay_as_bug(); } else { self.emit(); } + if delay { + self.delay_as_bug(); + } else { + self.emit(); + } } /// Stashes diagnostic for possible later improvement in a different, diff --git a/src/librustc_expand/base.rs b/src/librustc_expand/base.rs index 9e583d7e19d7..a5614f900b6f 100644 --- a/src/librustc_expand/base.rs +++ b/src/librustc_expand/base.rs @@ -1113,7 +1113,11 @@ pub fn expr_to_string( err_msg: &str, ) -> Option<(Symbol, ast::StrStyle)> { expr_to_spanned_string(cx, expr, err_msg) - .map_err(|err| err.map(|mut err| { err.emit(); })) + .map_err(|err| { + err.map(|mut err| { + err.emit(); + }) + }) .ok() .map(|(symbol, style, _)| (symbol, style)) } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index e84ef713b42d..9fc81a4a1fda 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -80,12 +80,12 @@ impl EarlyLintPass for WhileTrue { cx.struct_span_lint(WHILE_TRUE, condition_span, |lint| { lint.build(msg) .span_suggestion_short( - condition_span, - "use `loop`", - "loop".to_owned(), - Applicability::MachineApplicable, - ) - .emit(); + condition_span, + "use `loop`", + "loop".to_owned(), + Applicability::MachineApplicable, + ) + .emit(); }) } } @@ -176,31 +176,28 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns { if cx.tcx.find_field_index(ident, &variant) == Some(cx.tcx.field_index(fieldpat.hir_id, cx.tables)) { - cx.struct_span_lint( - NON_SHORTHAND_FIELD_PATTERNS, - fieldpat.span, - |lint| { - let mut err = lint.build(&format!("the `{}:` in this pattern is redundant", ident)); - let binding = match binding_annot { - hir::BindingAnnotation::Unannotated => None, - hir::BindingAnnotation::Mutable => Some("mut"), - hir::BindingAnnotation::Ref => Some("ref"), - hir::BindingAnnotation::RefMut => Some("ref mut"), - }; - let ident = if let Some(binding) = binding { - format!("{} {}", binding, ident) - } else { - ident.to_string() - }; - err.span_suggestion( - fieldpat.span, - "use shorthand field pattern", - ident, - Applicability::MachineApplicable, - ); - err.emit(); - } - ); + cx.struct_span_lint(NON_SHORTHAND_FIELD_PATTERNS, fieldpat.span, |lint| { + let mut err = lint + .build(&format!("the `{}:` in this pattern is redundant", ident)); + let binding = match binding_annot { + hir::BindingAnnotation::Unannotated => None, + hir::BindingAnnotation::Mutable => Some("mut"), + hir::BindingAnnotation::Ref => Some("ref"), + hir::BindingAnnotation::RefMut => Some("ref mut"), + }; + let ident = if let Some(binding) = binding { + format!("{} {}", binding, ident) + } else { + ident.to_string() + }; + err.span_suggestion( + fieldpat.span, + "use shorthand field pattern", + ident, + Applicability::MachineApplicable, + ); + err.emit(); + }); } } } @@ -644,22 +641,20 @@ impl EarlyLintPass for AnonymousParameters { ("".to_owned(), Applicability::HasPlaceholders) }; - cx.struct_span_lint( - ANONYMOUS_PARAMETERS, - arg.pat.span, - |lint| { - lint.build("anonymous parameters are deprecated and will be \ - removed in the next edition.") - .span_suggestion( - arg.pat.span, - "try naming the parameter or explicitly \ + cx.struct_span_lint(ANONYMOUS_PARAMETERS, arg.pat.span, |lint| { + lint.build( + "anonymous parameters are deprecated and will be \ + removed in the next edition.", + ) + .span_suggestion( + arg.pat.span, + "try naming the parameter or explicitly \ ignoring it", - format!("_: {}", ty_snip), - appl, - ) - .emit(); - }, - ) + format!("_: {}", ty_snip), + appl, + ) + .emit(); + }) } } _ => (), @@ -838,22 +833,20 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems { match param.kind { GenericParamKind::Lifetime { .. } => {} GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => { - cx.struct_span_lint( - NO_MANGLE_GENERIC_ITEMS, - it.span, - |lint| { - lint.build("functions generic over types or consts must be mangled") - .span_suggestion_short( - no_mangle_attr.span, - "remove this attribute", - String::new(), - // Use of `#[no_mangle]` suggests FFI intent; correct - // fix may be to monomorphize source by hand - Applicability::MaybeIncorrect, - ) - .emit(); - }, - ); + cx.struct_span_lint(NO_MANGLE_GENERIC_ITEMS, it.span, |lint| { + lint.build( + "functions generic over types or consts must be mangled", + ) + .span_suggestion_short( + no_mangle_attr.span, + "remove this attribute", + String::new(), + // Use of `#[no_mangle]` suggests FFI intent; correct + // fix may be to monomorphize source by hand + Applicability::MaybeIncorrect, + ) + .emit(); + }); break; } } @@ -995,30 +988,26 @@ impl UnreachablePub { applicability = Applicability::MaybeIncorrect; } let def_span = cx.tcx.sess.source_map().def_span(span); - cx.struct_span_lint( - UNREACHABLE_PUB, - def_span, - |lint| { - let mut err = lint.build(&format!("unreachable `pub` {}", what)); - let replacement = if cx.tcx.features().crate_visibility_modifier { - "crate" - } else { - "pub(crate)" - } - .to_owned(); - - err.span_suggestion( - vis.span, - "consider restricting its visibility", - replacement, - applicability, - ); - if exportable { - err.help("or consider exporting it for use by other crates"); - } - err.emit(); + cx.struct_span_lint(UNREACHABLE_PUB, def_span, |lint| { + let mut err = lint.build(&format!("unreachable `pub` {}", what)); + let replacement = if cx.tcx.features().crate_visibility_modifier { + "crate" + } else { + "pub(crate)" } - ); + .to_owned(); + + err.span_suggestion( + vis.span, + "consider restricting its visibility", + replacement, + applicability, + ); + if exportable { + err.help("or consider exporting it for use by other crates"); + } + err.emit(); + }); } _ => {} } @@ -1163,21 +1152,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeAliasBounds { }) .collect(); if !spans.is_empty() { - cx.struct_span_lint( - TYPE_ALIAS_BOUNDS, - spans, - |lint| { - let mut err = lint.build("bounds on generic parameters are not enforced in type aliases"); - let msg = "the bound will not be checked when the type alias is used, \ + cx.struct_span_lint(TYPE_ALIAS_BOUNDS, spans, |lint| { + let mut err = + lint.build("bounds on generic parameters are not enforced in type aliases"); + let msg = "the bound will not be checked when the type alias is used, \ and should be removed"; - err.multipart_suggestion(&msg, suggestion, Applicability::MachineApplicable); - if !suggested_changing_assoc_types { - TypeAliasBounds::suggest_changing_assoc_types(ty, &mut err); - suggested_changing_assoc_types = true; - } - err.emit(); - }, - ); + err.multipart_suggestion(&msg, suggestion, Applicability::MachineApplicable); + if !suggested_changing_assoc_types { + TypeAliasBounds::suggest_changing_assoc_types(ty, &mut err); + suggested_changing_assoc_types = true; + } + err.emit(); + }); } } } @@ -1356,7 +1342,7 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns { join, suggestion, "..=".to_owned(), - Applicability::MachineApplicable + Applicability::MachineApplicable, ) .emit(); }); @@ -1405,7 +1391,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnameableTestItems { } if let Some(attr) = attr::find_by_name(&it.attrs, sym::rustc_test_marker) { - cx.struct_span_lint(UNNAMEABLE_TEST_ITEMS, attr.span, |lint| lint.build("cannot test inner items").emit()); + cx.struct_span_lint(UNNAMEABLE_TEST_ITEMS, attr.span, |lint| { + lint.build("cannot test inner items").emit() + }); } } @@ -1486,20 +1474,16 @@ impl KeywordIdents { return; } - cx.struct_span_lint( - KEYWORD_IDENTS, - ident.span, - |lint| { - lint.build(&format!("`{}` is a keyword in the {} edition", ident, next_edition)) - .span_suggestion( - ident.span, - "you can use a raw identifier to stay compatible", - format!("r#{}", ident), - Applicability::MachineApplicable, - ) - .emit() - }, - ); + cx.struct_span_lint(KEYWORD_IDENTS, ident.span, |lint| { + lint.build(&format!("`{}` is a keyword in the {} edition", ident, next_edition)) + .span_suggestion( + ident.span, + "you can use a raw identifier to stay compatible", + format!("r#{}", ident), + Applicability::MachineApplicable, + ) + .emit() + }); } } @@ -1803,19 +1787,22 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitOutlivesRequirements { } if !lint_spans.is_empty() { - cx.struct_span_lint( - EXPLICIT_OUTLIVES_REQUIREMENTS, - lint_spans.clone(), - |lint| { - lint.build("outlives requirements can be inferred") - .multipart_suggestion( - if bound_count == 1 { "remove this bound" } else { "remove these bounds" }, - lint_spans.into_iter().map(|span| (span, "".to_owned())).collect::>(), - Applicability::MachineApplicable, - ) - .emit(); - }, - ); + cx.struct_span_lint(EXPLICIT_OUTLIVES_REQUIREMENTS, lint_spans.clone(), |lint| { + lint.build("outlives requirements can be inferred") + .multipart_suggestion( + if bound_count == 1 { + "remove this bound" + } else { + "remove these bounds" + }, + lint_spans + .into_iter() + .map(|span| (span, "".to_owned())) + .collect::>(), + Applicability::MachineApplicable, + ) + .emit(); + }); } } } @@ -1842,14 +1829,13 @@ impl EarlyLintPass for IncompleteFeatures { .chain(features.declared_lib_features.iter().map(|(name, span)| (name, span))) .filter(|(name, _)| rustc_feature::INCOMPLETE_FEATURES.iter().any(|f| name == &f)) .for_each(|(name, &span)| { - cx.struct_span_lint( - INCOMPLETE_FEATURES, - span, - |lint| lint.build(&format!( + cx.struct_span_lint(INCOMPLETE_FEATURES, span, |lint| { + lint.build(&format!( "the feature `{}` is incomplete and may cause the compiler to crash", name, - )).emit(), - ) + )) + .emit() + }) }); } } @@ -2039,32 +2025,28 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue { // We are extremely conservative with what we warn about. let conjured_ty = cx.tables.expr_ty(expr); if let Some((msg, span)) = ty_find_init_error(cx.tcx, conjured_ty, init) { - cx.struct_span_lint( - INVALID_VALUE, - expr.span, - |lint| { - let mut err = lint.build(&format!( - "the type `{}` does not permit {}", - conjured_ty, - match init { - InitKind::Zeroed => "zero-initialization", - InitKind::Uninit => "being left uninitialized", - }, - )); - err.span_label(expr.span, "this code causes undefined behavior when executed"); - err.span_label( - expr.span, - "help: use `MaybeUninit` instead, \ + cx.struct_span_lint(INVALID_VALUE, expr.span, |lint| { + let mut err = lint.build(&format!( + "the type `{}` does not permit {}", + conjured_ty, + match init { + InitKind::Zeroed => "zero-initialization", + InitKind::Uninit => "being left uninitialized", + }, + )); + err.span_label(expr.span, "this code causes undefined behavior when executed"); + err.span_label( + expr.span, + "help: use `MaybeUninit` instead, \ and only call `assume_init` after initialization is done", - ); - if let Some(span) = span { - err.span_note(span, &msg); - } else { - err.note(&msg); - } - err.emit(); - }, - ); + ); + if let Some(span) = span { + err.span_note(span, &msg); + } else { + err.note(&msg); + } + err.emit(); + }); } } } diff --git a/src/librustc_lint/context.rs b/src/librustc_lint/context.rs index 7b085f6c2b3d..d9ad97654e04 100644 --- a/src/librustc_lint/context.rs +++ b/src/librustc_lint/context.rs @@ -20,6 +20,7 @@ use crate::levels::LintLevelsBuilder; use crate::passes::{EarlyLintPassObject, LateLintPassObject}; use rustc::hir::map::definitions::{DefPathData, DisambiguatedDefPathData}; use rustc::lint::add_elided_lifetime_in_path_suggestion; +use rustc::lint::LintDiagnosticBuilder; use rustc::middle::privacy::AccessLevels; use rustc::middle::stability; use rustc::ty::layout::{LayoutError, LayoutOf, TyLayout}; @@ -27,7 +28,6 @@ use rustc::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync; use rustc_errors::{struct_span_err, Applicability}; -use rustc::lint::LintDiagnosticBuilder; use rustc_hir as hir; use rustc_hir::def_id::{CrateNum, DefId}; use rustc_session::lint::BuiltinLintDiagnostics; @@ -505,7 +505,8 @@ pub trait LintContext: Sized { Ok(ref s) => { // FIXME(Manishearth) ideally the emitting code // can tell us whether or not this is global - let opt_colon = if s.trim_start().starts_with("::") { "" } else { "::" }; + let opt_colon = + if s.trim_start().starts_with("::") { "" } else { "::" }; (format!("crate{}{}", opt_colon, s), Applicability::MachineApplicable) } @@ -519,7 +520,9 @@ pub trait LintContext: Sized { "names from parent modules are not accessible without an explicit import", ); } - BuiltinLintDiagnostics::MacroExpandedMacroExportsAccessedByAbsolutePaths(span_def) => { + BuiltinLintDiagnostics::MacroExpandedMacroExportsAccessedByAbsolutePaths( + span_def, + ) => { db.span_note(span_def, "the macro is defined here"); } BuiltinLintDiagnostics::ElidedLifetimesInPaths( @@ -585,7 +588,7 @@ pub trait LintContext: Sized { &self, lint: &'static Lint, span: S, - decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>) + decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>), ) { self.lookup(lint, Some(span), decorate); } diff --git a/src/librustc_lint/internal.rs b/src/librustc_lint/internal.rs index 19778a044a49..79a06e81410d 100644 --- a/src/librustc_lint/internal.rs +++ b/src/librustc_lint/internal.rs @@ -47,7 +47,10 @@ impl EarlyLintPass for DefaultHashTypes { replace.to_string(), Applicability::MaybeIncorrect, // FxHashMap, ... needs another import ) - .note(&format!("a `use rustc_data_structures::fx::{}` may be necessary", replace)) + .note(&format!( + "a `use rustc_data_structures::fx::{}` may be necessary", + replace + )) .emit(); }); } @@ -90,13 +93,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind { if lint_ty_kind_usage(cx, last) { cx.struct_span_lint(USAGE_OF_TY_TYKIND, span, |lint| { lint.build("usage of `ty::TyKind::`") - .span_suggestion( - span, - "try using ty:: directly", - "ty".to_string(), - Applicability::MaybeIncorrect, // ty maybe needs an import - ) - .emit(); + .span_suggestion( + span, + "try using ty:: directly", + "ty".to_string(), + Applicability::MaybeIncorrect, // ty maybe needs an import + ) + .emit(); }) } } @@ -108,36 +111,28 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind { if let QPath::Resolved(_, path) = qpath { if let Some(last) = path.segments.iter().last() { if lint_ty_kind_usage(cx, last) { - cx.struct_span_lint( - USAGE_OF_TY_TYKIND, - path.span, - |lint| { - lint.build("usage of `ty::TyKind`") - .help("try using `Ty` instead") - .emit(); - }, - ) + cx.struct_span_lint(USAGE_OF_TY_TYKIND, path.span, |lint| { + lint.build("usage of `ty::TyKind`") + .help("try using `Ty` instead") + .emit(); + }) } else { if ty.span.from_expansion() { return; } if let Some(t) = is_ty_or_ty_ctxt(cx, ty) { if path.segments.len() > 1 { - cx.struct_span_lint( - USAGE_OF_QUALIFIED_TY, - path.span, - |lint| { - lint.build(&format!("usage of qualified `ty::{}`", t)) - .span_suggestion( - path.span, - "try using it unqualified", - t, - // The import probably needs to be changed - Applicability::MaybeIncorrect, - ) - .emit(); - }, - ) + cx.struct_span_lint(USAGE_OF_QUALIFIED_TY, path.span, |lint| { + lint.build(&format!("usage of qualified `ty::{}`", t)) + .span_suggestion( + path.span, + "try using it unqualified", + t, + // The import probably needs to be changed + Applicability::MaybeIncorrect, + ) + .emit(); + }) } } } @@ -151,11 +146,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind { } } if let Some(t) = is_ty_or_ty_ctxt(cx, &inner_ty) { - cx.struct_span_lint( - TY_PASS_BY_REFERENCE, - ty.span, - |lint| { - lint.build(&format!("passing `{}` by reference", t)) + cx.struct_span_lint(TY_PASS_BY_REFERENCE, ty.span, |lint| { + lint.build(&format!("passing `{}` by reference", t)) .span_suggestion( ty.span, "try passing by value", @@ -164,8 +156,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind { Applicability::MaybeIncorrect, ) .emit(); - }, - ) + }) } } _ => {} diff --git a/src/librustc_lint/levels.rs b/src/librustc_lint/levels.rs index 6dd899d14618..b58acac316ef 100644 --- a/src/librustc_lint/levels.rs +++ b/src/librustc_lint/levels.rs @@ -1,13 +1,13 @@ use crate::context::{CheckLintNameResult, LintStore}; use crate::late::unerased_lint_store; use rustc::hir::map::Map; +use rustc::lint::LintDiagnosticBuilder; use rustc::lint::{struct_lint_level, LintLevelMap, LintLevelSets, LintSet, LintSource}; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashMap; use rustc_errors::{struct_span_err, Applicability}; -use rustc::lint::LintDiagnosticBuilder; use rustc_hir as hir; use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; use rustc_hir::{intravisit, HirId}; @@ -248,13 +248,13 @@ impl<'s> LintLevelsBuilder<'s> { Some(li.span().into()), |lint| { lint.build(&msg) - .span_suggestion( - li.span(), - "change it to", - new_lint_name.to_string(), - Applicability::MachineApplicable, - ) - .emit(); + .span_suggestion( + li.span(), + "change it to", + new_lint_name.to_string(), + Applicability::MachineApplicable, + ) + .emit(); }, ); @@ -326,7 +326,6 @@ impl<'s> LintLevelsBuilder<'s> { db.emit(); }, ); - } } } diff --git a/src/librustc_lint/non_ascii_idents.rs b/src/librustc_lint/non_ascii_idents.rs index df91df8f8b59..a0ca7ad1860e 100644 --- a/src/librustc_lint/non_ascii_idents.rs +++ b/src/librustc_lint/non_ascii_idents.rs @@ -22,17 +22,13 @@ impl EarlyLintPass for NonAsciiIdents { if name_str.is_ascii() { return; } - cx.struct_span_lint( - NON_ASCII_IDENTS, - ident.span, - |lint| lint.build("identifier contains non-ASCII characters").emit(), - ); + cx.struct_span_lint(NON_ASCII_IDENTS, ident.span, |lint| { + lint.build("identifier contains non-ASCII characters").emit() + }); if !name_str.chars().all(GeneralSecurityProfile::identifier_allowed) { - cx.struct_span_lint( - UNCOMMON_CODEPOINTS, - ident.span, - |lint| lint.build("identifier contains uncommon Unicode codepoints").emit(), - ) + cx.struct_span_lint(UNCOMMON_CODEPOINTS, ident.span, |lint| { + lint.build("identifier contains uncommon Unicode codepoints").emit() + }) } } } diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index 9e291d2cb74e..52f29b30f3be 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -109,12 +109,14 @@ impl NonCamelCaseTypes { if !is_camel_case(name) { let msg = format!("{} `{}` should have an upper camel case name", sort, name); cx.struct_span_lint(NON_CAMEL_CASE_TYPES, ident.span, |lint| { - lint.build(&msg).span_suggestion( - ident.span, - "convert the identifier to upper camel case", - to_camel_case(name), - Applicability::MaybeIncorrect, - ).emit() + lint.build(&msg) + .span_suggestion( + ident.span, + "convert the identifier to upper camel case", + to_camel_case(name), + Applicability::MaybeIncorrect, + ) + .emit() }) } } @@ -243,7 +245,6 @@ impl NonSnakeCase { err.emit(); }); - } } } @@ -394,13 +395,13 @@ impl NonUpperCaseGlobals { cx.struct_span_lint(NON_UPPER_CASE_GLOBALS, ident.span, |lint| { lint.build(&format!("{} `{}` should have an upper case name", sort, name)) - .span_suggestion( - ident.span, - "convert the identifier to upper case", - uc, - Applicability::MaybeIncorrect, - ) - .emit(); + .span_suggestion( + ident.span, + "convert the identifier to upper case", + uc, + Applicability::MaybeIncorrect, + ) + .emit(); }) } } diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 30a903a2a30d..71a86592396c 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -76,33 +76,29 @@ fn lint_overflowing_range_endpoint<'a, 'tcx>( // (`..=`) instead only if it is the `end` that is // overflowing and only by 1. if eps[1].expr.hir_id == expr.hir_id && lit_val - 1 == max { - cx.struct_span_lint( - OVERFLOWING_LITERALS, - parent_expr.span, - |lint| { - let mut err = lint.build(&format!("range endpoint is out of range for `{}`", ty)); - if let Ok(start) = cx.sess().source_map().span_to_snippet(eps[0].span) { - use ast::{LitIntType, LitKind}; - // We need to preserve the literal's suffix, - // as it may determine typing information. - let suffix = match lit.node { - LitKind::Int(_, LitIntType::Signed(s)) => format!("{}", s.name_str()), - LitKind::Int(_, LitIntType::Unsigned(s)) => format!("{}", s.name_str()), - LitKind::Int(_, LitIntType::Unsuffixed) => "".to_owned(), - _ => bug!(), - }; - let suggestion = format!("{}..={}{}", start, lit_val - 1, suffix); - err.span_suggestion( - parent_expr.span, - &"use an inclusive range instead", - suggestion, - Applicability::MachineApplicable, - ); - err.emit(); - overwritten = true; - } - }, - ); + cx.struct_span_lint(OVERFLOWING_LITERALS, parent_expr.span, |lint| { + let mut err = lint.build(&format!("range endpoint is out of range for `{}`", ty)); + if let Ok(start) = cx.sess().source_map().span_to_snippet(eps[0].span) { + use ast::{LitIntType, LitKind}; + // We need to preserve the literal's suffix, + // as it may determine typing information. + let suffix = match lit.node { + LitKind::Int(_, LitIntType::Signed(s)) => format!("{}", s.name_str()), + LitKind::Int(_, LitIntType::Unsigned(s)) => format!("{}", s.name_str()), + LitKind::Int(_, LitIntType::Unsuffixed) => "".to_owned(), + _ => bug!(), + }; + let suggestion = format!("{}..={}{}", start, lit_val - 1, suffix); + err.span_suggestion( + parent_expr.span, + &"use an inclusive range instead", + suggestion, + Applicability::MachineApplicable, + ); + err.emit(); + overwritten = true; + } + }); } } overwritten @@ -165,32 +161,29 @@ fn report_bin_hex_error( (t.name_str(), actually.to_string()) } }; - cx.struct_span_lint( - OVERFLOWING_LITERALS, - expr.span, - |lint| { - let mut err = lint.build(&format!("literal out of range for {}", t)); - err.note(&format!( - "the literal `{}` (decimal `{}`) does not fit into \ + cx.struct_span_lint(OVERFLOWING_LITERALS, expr.span, |lint| { + let mut err = lint.build(&format!("literal out of range for {}", t)); + err.note(&format!( + "the literal `{}` (decimal `{}`) does not fit into \ an `{}` and will become `{}{}`", - repr_str, val, t, actually, t - )); - if let Some(sugg_ty) = get_type_suggestion(&cx.tables.node_type(expr.hir_id), val, negative) { - if let Some(pos) = repr_str.chars().position(|c| c == 'i' || c == 'u') { - let (sans_suffix, _) = repr_str.split_at(pos); - err.span_suggestion( - expr.span, - &format!("consider using `{}` instead", sugg_ty), - format!("{}{}", sans_suffix, sugg_ty), - Applicability::MachineApplicable, - ); - } else { - err.help(&format!("consider using `{}` instead", sugg_ty)); - } + repr_str, val, t, actually, t + )); + if let Some(sugg_ty) = get_type_suggestion(&cx.tables.node_type(expr.hir_id), val, negative) + { + if let Some(pos) = repr_str.chars().position(|c| c == 'i' || c == 'u') { + let (sans_suffix, _) = repr_str.split_at(pos); + err.span_suggestion( + expr.span, + &format!("consider using `{}` instead", sugg_ty), + format!("{}{}", sans_suffix, sugg_ty), + Applicability::MachineApplicable, + ); + } else { + err.help(&format!("consider using `{}` instead", sugg_ty)); } - err.emit(); - }, - ); + } + err.emit(); + }); } // This function finds the next fitting type and generates a suggestion string. diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 25f1a495ad3e..4dae7fbe9413 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -379,12 +379,8 @@ fn do_mir_borrowck<'a, 'tcx>( } let mut_span = tcx.sess.source_map().span_until_non_whitespace(span); - tcx.struct_span_lint_hir( - UNUSED_MUT, - lint_root, - span, - |lint| { - lint.build("variable does not need to be mutable") + tcx.struct_span_lint_hir(UNUSED_MUT, lint_root, span, |lint| { + lint.build("variable does not need to be mutable") .span_suggestion_short( mut_span, "remove this `mut`", @@ -392,8 +388,7 @@ fn do_mir_borrowck<'a, 'tcx>( Applicability::MachineApplicable, ) .emit(); - }, - ) + }) } // Buffer any move errors that we collected and de-duplicated. diff --git a/src/librustc_mir/const_eval/eval_queries.rs b/src/librustc_mir/const_eval/eval_queries.rs index 99d3b281945e..2e8e4dac237b 100644 --- a/src/librustc_mir/const_eval/eval_queries.rs +++ b/src/librustc_mir/const_eval/eval_queries.rs @@ -213,9 +213,7 @@ fn validate_and_turn_into_const<'tcx>( diag.note(note_on_undefined_behavior_error()); diag.emit(); }) { - Ok(_) => { - ErrorHandled::Reported - } + Ok(_) => ErrorHandled::Reported, Err(err) => err, } }) diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index c019fa57fb78..08ef60aa58ea 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -624,15 +624,13 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) { lint_hir_id, source_info.span, |lint| { - lint.build( - &format!( - "{} is unsafe and requires unsafe function or block (error E0133)", - description - ) - ) + lint.build(&format!( + "{} is unsafe and requires unsafe function or block (error E0133)", + description + )) .note(&details.as_str()) .emit() - } + }, ) } } diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index aeeca52ba3ba..9a2e2c56f142 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -923,17 +923,24 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> { | PanicInfo::DivisionByZero | PanicInfo::RemainderByZero => msg.description().to_owned(), PanicInfo::BoundsCheck { ref len, ref index } => { - let len = - self.eval_operand(len, source_info).expect("len must be const"); + let len = self + .eval_operand(len, source_info) + .expect("len must be const"); let len = match self.ecx.read_scalar(len) { - Ok(ScalarMaybeUndef::Scalar(Scalar::Raw { data, .. })) => data, + Ok(ScalarMaybeUndef::Scalar(Scalar::Raw { + data, + .. + })) => data, other => bug!("const len not primitive: {:?}", other), }; let index = self .eval_operand(index, source_info) .expect("index must be const"); let index = match self.ecx.read_scalar(index) { - Ok(ScalarMaybeUndef::Scalar(Scalar::Raw { data, .. })) => data, + Ok(ScalarMaybeUndef::Scalar(Scalar::Raw { + data, + .. + })) => data, other => bug!("const index not primitive: {:?}", other), }; format!( diff --git a/src/librustc_mir_build/hair/pattern/check_match.rs b/src/librustc_mir_build/hair/pattern/check_match.rs index 421f7958e5f4..acb9829ce5f3 100644 --- a/src/librustc_mir_build/hair/pattern/check_match.rs +++ b/src/librustc_mir_build/hair/pattern/check_match.rs @@ -287,30 +287,26 @@ fn check_for_bindings_named_same_as_variants(cx: &MatchVisitor<'_, '_>, pat: &Pa }) { let ty_path = cx.tcx.def_path_str(edef.did); - cx.tcx - .struct_span_lint_hir( - BINDINGS_WITH_VARIANT_NAME, - p.hir_id, - p.span, - |lint| { - lint - .build( - &format!( - "pattern binding `{}` is named the same as one \ + cx.tcx.struct_span_lint_hir( + BINDINGS_WITH_VARIANT_NAME, + p.hir_id, + p.span, + |lint| { + lint.build(&format!( + "pattern binding `{}` is named the same as one \ of the variants of the type `{}`", - ident, ty_path - ) - ) - .code(error_code!(E0170)) - .span_suggestion( - p.span, - "to match on the variant, qualify the path", - format!("{}::{}", ty_path, ident), - Applicability::MachineApplicable, - ) - .emit(); - }, - ) + ident, ty_path + )) + .code(error_code!(E0170)) + .span_suggestion( + p.span, + "to match on the variant, qualify the path", + format!("{}::{}", ty_path, ident), + Applicability::MachineApplicable, + ) + .emit(); + }, + ) } } } diff --git a/src/librustc_mir_build/lints.rs b/src/librustc_mir_build/lints.rs index 4704f8d034dc..0017f800de70 100644 --- a/src/librustc_mir_build/lints.rs +++ b/src/librustc_mir_build/lints.rs @@ -124,20 +124,15 @@ fn check_fn_for_unconditional_recursion<'tcx>( if !reached_exit_without_self_call && !self_call_locations.is_empty() { let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); let sp = tcx.sess.source_map().def_span(tcx.hir().span(hir_id)); - tcx.struct_span_lint_hir( - UNCONDITIONAL_RECURSION, - hir_id, - sp, - |lint| { - let mut db = lint.build("function cannot return without recursing"); - db.span_label(sp, "cannot return without recursing"); - // offer some help to the programmer. - for location in &self_call_locations { - db.span_label(location.span, "recursive call site"); - } - db.help("a `loop` may express intention better if this is on purpose"); - db.emit(); - }, - ); + tcx.struct_span_lint_hir(UNCONDITIONAL_RECURSION, hir_id, sp, |lint| { + let mut db = lint.build("function cannot return without recursing"); + db.span_label(sp, "cannot return without recursing"); + // offer some help to the programmer. + for location in &self_call_locations { + db.span_label(location.span, "recursive call site"); + } + db.help("a `loop` may express intention better if this is on purpose"); + db.emit(); + }); } } diff --git a/src/librustc_parse/config.rs b/src/librustc_parse/config.rs index cd935a37f7dd..8dec64c579e8 100644 --- a/src/librustc_parse/config.rs +++ b/src/librustc_parse/config.rs @@ -317,9 +317,9 @@ impl<'a> StripUnconfigured<'a> { Ok(r) => return Some(r), Err(mut e) => { e.help(&format!("the valid syntax is `{}`", CFG_ATTR_GRAMMAR_HELP)) - .note(CFG_ATTR_NOTE_REF) - .emit(); - }, + .note(CFG_ATTR_NOTE_REF) + .emit(); + } } } _ => self.error_malformed_cfg_attr_missing(attr.span), diff --git a/src/librustc_parse/parser/mod.rs b/src/librustc_parse/parser/mod.rs index ba97f3feb802..21a738c7f7b1 100644 --- a/src/librustc_parse/parser/mod.rs +++ b/src/librustc_parse/parser/mod.rs @@ -1407,6 +1407,8 @@ pub fn emit_unclosed_delims(unclosed_delims: &mut Vec, sess: &Pa *sess.reached_eof.borrow_mut() |= unclosed_delims.iter().any(|unmatched_delim| unmatched_delim.found_delim.is_none()); for unmatched in unclosed_delims.drain(..) { - make_unclosed_delims_error(unmatched, sess).map(|mut e| { e.emit(); }); + make_unclosed_delims_error(unmatched, sess).map(|mut e| { + e.emit(); + }); } } diff --git a/src/librustc_parse/validate_attr.rs b/src/librustc_parse/validate_attr.rs index f6d5da68be3b..f5e47608d589 100644 --- a/src/librustc_parse/validate_attr.rs +++ b/src/librustc_parse/validate_attr.rs @@ -27,7 +27,11 @@ pub fn check_meta(sess: &ParseSess, attr: &Attribute) { _ => { if let MacArgs::Eq(..) = attr.get_normal_item().args { // All key-value attributes are restricted to meta-item syntax. - parse_meta(sess, attr).map_err(|mut err| { err.emit(); }).ok(); + parse_meta(sess, attr) + .map_err(|mut err| { + err.emit(); + }) + .ok(); } } } @@ -152,6 +156,8 @@ pub fn check_builtin_attribute( } } } - Err(mut err) => { err.emit(); }, + Err(mut err) => { + err.emit(); + } } } diff --git a/src/librustc_passes/check_attr.rs b/src/librustc_passes/check_attr.rs index 6bae61d787b9..fac90525e323 100644 --- a/src/librustc_passes/check_attr.rs +++ b/src/librustc_passes/check_attr.rs @@ -92,13 +92,9 @@ impl CheckAttrVisitor<'tcx> { | Target::Method(MethodKind::Trait { body: true }) | Target::Method(MethodKind::Inherent) => true, Target::Method(MethodKind::Trait { body: false }) | Target::ForeignFn => { - self.tcx - .struct_span_lint_hir( - UNUSED_ATTRIBUTES, - hir_id, - attr.span, - |lint| lint.build("`#[inline]` is ignored on function prototypes").emit(), - ); + self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| { + lint.build("`#[inline]` is ignored on function prototypes").emit() + }); true } // FIXME(#65833): We permit associated consts to have an `#[inline]` attribute with @@ -331,17 +327,16 @@ impl CheckAttrVisitor<'tcx> { || (is_simd && is_c) || (int_reprs == 1 && is_c && item.map_or(false, |item| is_c_like_enum(item))) { - self.tcx - .struct_span_lint_hir( - CONFLICTING_REPR_HINTS, - hir_id, - hint_spans.collect::>(), - |lint| { - lint.build("conflicting representation hints") - .code(rustc_errors::error_code!(E0566)) - .emit(); - } - ); + self.tcx.struct_span_lint_hir( + CONFLICTING_REPR_HINTS, + hir_id, + hint_spans.collect::>(), + |lint| { + lint.build("conflicting representation hints") + .code(rustc_errors::error_code!(E0566)) + .emit(); + }, + ); } } diff --git a/src/librustc_passes/liveness.rs b/src/librustc_passes/liveness.rs index 27ad953e4fa6..709068d21893 100644 --- a/src/librustc_passes/liveness.rs +++ b/src/librustc_passes/liveness.rs @@ -1521,18 +1521,16 @@ impl<'tcx> Liveness<'_, 'tcx> { if ln == self.s.exit_ln { false } else { self.assigned_on_exit(ln, var).is_some() }; if is_assigned { - self.ir - .tcx - .struct_span_lint_hir( - lint::builtin::UNUSED_VARIABLES, - hir_id, - spans, - |lint| { - lint.build(&format!("variable `{}` is assigned to, but never used", name)) - .note(&format!("consider using `_{}` instead", name)) - .emit(); - }, - ) + self.ir.tcx.struct_span_lint_hir( + lint::builtin::UNUSED_VARIABLES, + hir_id, + spans, + |lint| { + lint.build(&format!("variable `{}` is assigned to, but never used", name)) + .note(&format!("consider using `_{}` instead", name)) + .emit(); + }, + ) } else { self.ir.tcx.struct_span_lint_hir( lint::builtin::UNUSED_VARIABLES, @@ -1543,8 +1541,10 @@ impl<'tcx> Liveness<'_, 'tcx> { if self.ir.variable_is_shorthand(var) { if let Node::Binding(pat) = self.ir.tcx.hir().get(hir_id) { // Handle `ref` and `ref mut`. - let spans = - spans.iter().map(|_span| (pat.span, format!("{}: _", name))).collect(); + let spans = spans + .iter() + .map(|_span| (pat.span, format!("{}: _", name))) + .collect(); err.multipart_suggestion( "try ignoring the field", @@ -1575,31 +1575,27 @@ impl<'tcx> Liveness<'_, 'tcx> { fn report_dead_assign(&self, hir_id: HirId, spans: Vec, var: Variable, is_param: bool) { if let Some(name) = self.should_warn(var) { if is_param { - self.ir - .tcx - .struct_span_lint_hir( - lint::builtin::UNUSED_ASSIGNMENTS, - hir_id, - spans, - |lint| { - lint.build(&format!("value passed to `{}` is never read", name)) - .help("maybe it is overwritten before being read?") - .emit(); - }, - ) + self.ir.tcx.struct_span_lint_hir( + lint::builtin::UNUSED_ASSIGNMENTS, + hir_id, + spans, + |lint| { + lint.build(&format!("value passed to `{}` is never read", name)) + .help("maybe it is overwritten before being read?") + .emit(); + }, + ) } else { - self.ir - .tcx - .struct_span_lint_hir( - lint::builtin::UNUSED_ASSIGNMENTS, - hir_id, - spans, - |lint| { - lint.build(&format!("value assigned to `{}` is never read", name)) - .help("maybe it is overwritten before being read?") - .emit(); - }, - ) + self.ir.tcx.struct_span_lint_hir( + lint::builtin::UNUSED_ASSIGNMENTS, + hir_id, + spans, + |lint| { + lint.build(&format!("value assigned to `{}` is never read", name)) + .help("maybe it is overwritten before being read?") + .emit(); + }, + ) } } } diff --git a/src/librustc_passes/stability.rs b/src/librustc_passes/stability.rs index 374b7d1cf7a1..4e2085d07a39 100644 --- a/src/librustc_passes/stability.rs +++ b/src/librustc_passes/stability.rs @@ -608,10 +608,10 @@ fn unnecessary_stable_feature_lint(tcx: TyCtxt<'_>, span: Span, feature: Symbol, lint.build(&format!( "the feature `{}` has been stable since {} and no longer requires \ an attribute to enable", - feature, since - )).emit(); - } - ); + feature, since + )) + .emit(); + }); } fn duplicate_feature_err(sess: &Session, span: Span, feature: Symbol) { diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 43f92ae69c46..7f51bc25642b 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -1786,15 +1786,14 @@ impl SearchInterfaceForPrivateItemsVisitor<'tcx> { self.item_id, self.span, |lint| { - lint.build( - &format!( - "{} `{}` from private dependency '{}' in public \ + lint.build(&format!( + "{} `{}` from private dependency '{}' in public \ interface", - kind, - descr, - self.tcx.crate_name(def_id.krate) - ) - ).emit() + kind, + descr, + self.tcx.crate_name(def_id.krate) + )) + .emit() }, ); } @@ -1818,9 +1817,12 @@ impl SearchInterfaceForPrivateItemsVisitor<'tcx> { err.emit(); } else { let err_code = if kind == "trait" { "E0445" } else { "E0446" }; - self.tcx.struct_span_lint_hir(lint::builtin::PRIVATE_IN_PUBLIC, hir_id, self.span, |lint| { - lint.build(&format!("{} (error {})", msg, err_code)).emit() - }); + self.tcx.struct_span_lint_hir( + lint::builtin::PRIVATE_IN_PUBLIC, + hir_id, + self.span, + |lint| lint.build(&format!("{} (error {})", msg, err_code)).emit(), + ); } } diff --git a/src/librustc_resolve/lifetimes.rs b/src/librustc_resolve/lifetimes.rs index cef5e025741d..fd4d2c718c09 100644 --- a/src/librustc_resolve/lifetimes.rs +++ b/src/librustc_resolve/lifetimes.rs @@ -1580,7 +1580,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { id, span, |lint| { - let mut err = lint.build(&format!("lifetime parameter `{}` only used once", name)); + let mut err = lint.build(&format!( + "lifetime parameter `{}` only used once", + name + )); if span == lifetime.span { // spans are the same for in-band lifetime declarations err.span_label(span, "this lifetime is only used here"); @@ -1588,7 +1591,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { err.span_label(span, "this lifetime..."); err.span_label(lifetime.span, "...is used only here"); } - self.suggest_eliding_single_use_lifetime(&mut err, def_id, lifetime); + self.suggest_eliding_single_use_lifetime( + &mut err, def_id, lifetime, + ); err.emit(); }, ); @@ -1616,10 +1621,14 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { id, span, |lint| { - let mut err = lint.build(&format!("lifetime parameter `{}` never used", name)); + let mut err = lint + .build(&format!("lifetime parameter `{}` never used", name)); if let Some(parent_def_id) = self.tcx.parent(def_id) { - if let Some(generics) = self.tcx.hir().get_generics(parent_def_id) { - let unused_lt_span = self.lifetime_deletion_span(name, generics); + if let Some(generics) = + self.tcx.hir().get_generics(parent_def_id) + { + let unused_lt_span = + self.lifetime_deletion_span(name, generics); if let Some(span) = unused_lt_span { err.span_suggestion( span, diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 02da2766ec66..909f40ee9849 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -468,27 +468,20 @@ impl<'a, 'tcx> CastCheck<'tcx> { } else { ("", lint::builtin::TRIVIAL_CASTS) }; - fcx.tcx.struct_span_lint_hir( - lint, - self.expr.hir_id, - self.span, - |err| { - err.build( - &format!( - "trivial {}cast: `{}` as `{}`", - adjective, - fcx.ty_to_string(t_expr), - fcx.ty_to_string(t_cast) - ) - ) - .help(&format!( - "cast can be replaced by coercion; this might \ + fcx.tcx.struct_span_lint_hir(lint, self.expr.hir_id, self.span, |err| { + err.build(&format!( + "trivial {}cast: `{}` as `{}`", + adjective, + fcx.ty_to_string(t_expr), + fcx.ty_to_string(t_cast) + )) + .help(&format!( + "cast can be replaced by coercion; this might \ require {}a temporary variable", - type_asc_or - )) - .emit(); - }, - ); + type_asc_or + )) + .emit(); + }); } pub fn check(mut self, fcx: &FnCtxt<'a, 'tcx>) { diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 599f7dfe2d41..760b6487045d 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -1285,7 +1285,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { self.fcx.body_id, self.span, |lint| { - let mut diag = lint.build("a method with this name may be added to the standard library in the future"); + let mut diag = lint.build( + "a method with this name may be added to the standard library in the future", + ); // FIXME: This should be a `span_suggestion` instead of `help` // However `self.span` only // highlights the method name, so we can't use it. Also consider reusing the code from diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 2fff5106dd1d..be2052dce3c0 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2895,17 +2895,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { debug!("warn_if_unreachable: id={:?} span={:?} kind={}", id, span, kind); - self.tcx() - .struct_span_lint_hir(lint::builtin::UNREACHABLE_CODE, id, span, |lint| { - let msg = format!("unreachable {}", kind); - lint.build(&msg) - .span_label(span, &msg) - .span_label( - orig_span, - custom_note.unwrap_or("any code following this expression is unreachable"), - ) - .emit(); - }) + self.tcx().struct_span_lint_hir(lint::builtin::UNREACHABLE_CODE, id, span, |lint| { + let msg = format!("unreachable {}", kind); + lint.build(&msg) + .span_label(span, &msg) + .span_label( + orig_span, + custom_note + .unwrap_or("any code following this expression is unreachable"), + ) + .emit(); + }) } } } diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index 71ce5ce0f02c..6471db3efce8 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -180,7 +180,6 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) { }; let replacement = visibility_qualified(&item.vis, base_replacement); tcx.struct_span_lint_hir(lint, id, extern_crate.span, |lint| { - let msg = "`extern crate` is not idiomatic in the new edition"; let help = format!("convert it to a `{}`", visibility_qualified(&item.vis, "use")); diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index d26a4cdc5ca7..1b4f0ffce9c1 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1157,9 +1157,10 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::Generics { param.span, |lint| { lint.build(&format!( - "defaults for type parameters are only allowed in \ + "defaults for type parameters are only allowed in \ `struct`, `enum`, `type`, or `trait` definitions." - )).emit(); + )) + .emit(); }, ); } diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index dfb75c5a98e7..79bcfe7aee74 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -676,7 +676,8 @@ fn build_diagnostic( |lint| { let mut diag = lint.build(&format!("`[{}]` {}", path_str, err_msg)); if let Some(link_range) = link_range { - if let Some(sp) = super::source_span_for_markdown_range(cx, dox, &link_range, attrs) { + if let Some(sp) = super::source_span_for_markdown_range(cx, dox, &link_range, attrs) + { diag.set_span(sp); diag.span_label(sp, short_err_msg); } else { @@ -684,7 +685,8 @@ fn build_diagnostic( // ^ ~~~~ // | link_range // last_new_line_offset - let last_new_line_offset = dox[..link_range.start].rfind('\n').map_or(0, |n| n + 1); + let last_new_line_offset = + dox[..link_range.start].rfind('\n').map_or(0, |n| n + 1); let line = dox[last_new_line_offset..].lines().next().unwrap_or(""); // Print the line containing the `link_range` and manually mark it with '^'s. @@ -804,7 +806,8 @@ fn ambiguity_error( let mut diag = lint.build(&msg); if let Some(link_range) = link_range { - if let Some(sp) = super::source_span_for_markdown_range(cx, dox, &link_range, attrs) { + if let Some(sp) = super::source_span_for_markdown_range(cx, dox, &link_range, attrs) + { diag.set_span(sp); diag.span_label(sp, "ambiguous link"); @@ -851,7 +854,8 @@ fn ambiguity_error( // ^ ~~~~ // | link_range // last_new_line_offset - let last_new_line_offset = dox[..link_range.start].rfind('\n').map_or(0, |n| n + 1); + let last_new_line_offset = + dox[..link_range.start].rfind('\n').map_or(0, |n| n + 1); let line = dox[last_new_line_offset..].lines().next().unwrap_or(""); // Print the line containing the `link_range` and manually mark it with '^'s. @@ -868,7 +872,6 @@ fn ambiguity_error( diag.emit(); }, ); - } /// Given an enum variant's res, return the res of its enum and the associated fragment. diff --git a/src/librustdoc/passes/mod.rs b/src/librustdoc/passes/mod.rs index a5213fe8635f..9e48904a47d3 100644 --- a/src/librustdoc/passes/mod.rs +++ b/src/librustdoc/passes/mod.rs @@ -342,12 +342,9 @@ pub fn look_for_tests<'tcx>( if check_missing_code == true && tests.found_tests == 0 { let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span()); - cx.tcx.struct_span_lint_hir( - lint::builtin::MISSING_DOC_CODE_EXAMPLES, - hir_id, - sp, - |lint| lint.build("missing code example in this documentation").emit(), - ); + cx.tcx.struct_span_lint_hir(lint::builtin::MISSING_DOC_CODE_EXAMPLES, hir_id, sp, |lint| { + lint.build("missing code example in this documentation").emit() + }); } else if check_missing_code == false && tests.found_tests > 0 && !cx.renderinfo.borrow().access_levels.is_public(item.def_id)