diff --git a/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs b/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs index 0eb634ea2cc..6ff008919e5 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs @@ -13,6 +13,7 @@ use infer::error_reporting::nice_region_error::NiceRegionError; use ty; use util::common::ErrorReported; +use errors::Applicability; impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { /// When given a `ConcreteFailure` for a function with arguments containing a named region and @@ -111,13 +112,14 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { E0621, "explicit lifetime required in {}", error_var - ).span_suggestion( + ).span_suggestion_with_applicability( new_ty_span, &format!("add explicit lifetime `{}` to {}", named, span_label_var), - new_ty.to_string() + new_ty.to_string(), + Applicability::Unspecified, ) - .span_label(span, format!("lifetime `{}` required", named)) - .emit(); + .span_label(span, format!("lifetime `{}` required", named)) + .emit(); return Some(ErrorReported); } diff --git a/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs b/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs index 29ba23b58bc..3393eb65089 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -14,6 +14,7 @@ use infer::error_reporting::nice_region_error::NiceRegionError; use infer::lexical_region_resolve::RegionResolutionError; use ty::{BoundRegion, FreeRegion, RegionKind}; use util::common::ErrorReported; +use errors::Applicability; impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { /// Print the error message for lifetime errors when the return type is a static impl Trait. @@ -61,7 +62,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { _ => "'_".to_owned(), }; if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(return_sp) { - err.span_suggestion( + err.span_suggestion_with_applicability( return_sp, &format!( "you can add a constraint to the return type to make it last \ @@ -69,6 +70,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { lifetime, ), format!("{} + {}", snippet, lifetime_name), + Applicability::Unspecified, ); } err.emit(); diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 52e1ab47703..7bf0d8ecec8 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -28,7 +28,7 @@ use rustc_data_structures::base_n; use rustc_data_structures::sync::{self, Lrc, Lock, LockCell, OneThread, Once, RwLock}; use syntax::ast::NodeId; -use errors::{self, DiagnosticBuilder, DiagnosticId}; +use errors::{self, DiagnosticBuilder, DiagnosticId, Applicability}; use errors::emitter::{Emitter, EmitterWriter}; use syntax::edition::Edition; use syntax::json::JsonEmitter; @@ -431,8 +431,13 @@ impl Session { diag_builder.span_note(span, message); } DiagnosticBuilderMethod::SpanSuggestion(suggestion) => { - let span = span_maybe.expect("span_suggestion needs a span"); - diag_builder.span_suggestion(span, message, suggestion); + let span = span_maybe.expect("span_suggestion_* needs a span"); + diag_builder.span_suggestion_with_applicability( + span, + message, + suggestion, + Applicability::Unspecified, + ); } } } diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 56187c09b4f..fb8744e4d96 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -867,10 +867,20 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { }) = cmt.cat { db.note(fn_closure_msg); } else { - db.span_suggestion(sp, msg, suggestion); + db.span_suggestion_with_applicability( + sp, + msg, + suggestion, + Applicability::Unspecified, + ); } } else { - db.span_suggestion(sp, msg, suggestion); + db.span_suggestion_with_applicability( + sp, + msg, + suggestion, + Applicability::Unspecified, + ); } } _ => { @@ -1236,10 +1246,16 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { let let_span = self.tcx.hir.span(node_id); let suggestion = suggest_ref_mut(self.tcx, let_span); if let Some(replace_str) = suggestion { - db.span_suggestion( + db.span_suggestion_with_applicability( let_span, "use a mutable reference instead", replace_str, + // I believe this can be machine applicable, + // but if there are multiple attempted uses of an immutable + // reference, I don't know how rustfix handles it, it might + // attempt fixing them multiple times. + // @estebank + Applicability::Unspecified, ); } } @@ -1292,11 +1308,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { )) = ty.map(|t| &t.node) { let borrow_expr_id = self.tcx.hir.get_parent_node(borrowed_node_id); - db.span_suggestion( + db.span_suggestion_with_applicability( self.tcx.hir.span(borrow_expr_id), "consider removing the `&mut`, as it is an \ immutable binding to a mutable reference", - snippet + snippet, + Applicability::MachineApplicable, ); } else { db.span_suggestion_with_applicability( @@ -1326,12 +1343,15 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { &cmt_path_or_string, capture_span, Origin::Ast) - .span_suggestion(err.span, - &format!("to force the closure to take ownership of {} \ - (and any other referenced variables), \ - use the `move` keyword", - cmt_path_or_string), - suggestion) + .span_suggestion_with_applicability( + err.span, + &format!("to force the closure to take ownership of {} \ + (and any other referenced variables), \ + use the `move` keyword", + cmt_path_or_string), + suggestion, + Applicability::MachineApplicable, + ) .emit(); self.signal_error(); } diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs index 825e31539c8..2799f2cc81f 100644 --- a/src/librustc_errors/diagnostic.rs +++ b/src/librustc_errors/diagnostic.rs @@ -232,6 +232,7 @@ impl Diagnostic { /// inline it will only show the text message and not the text. /// /// See `CodeSuggestion` for more information. + #[deprecated(note = "Use `span_suggestion_short_with_applicability`")] pub fn span_suggestion_short(&mut self, sp: Span, msg: &str, suggestion: String) -> &mut Self { self.suggestions.push(CodeSuggestion { substitutions: vec![Substitution { @@ -263,6 +264,7 @@ impl Diagnostic { /// * may contain a name of a function, variable or type, but not whole expressions /// /// See `CodeSuggestion` for more information. + #[deprecated(note = "Use `span_suggestion_with_applicability`")] pub fn span_suggestion(&mut self, sp: Span, msg: &str, suggestion: String) -> &mut Self { self.suggestions.push(CodeSuggestion { substitutions: vec![Substitution { @@ -278,10 +280,11 @@ impl Diagnostic { self } - pub fn multipart_suggestion( + pub fn multipart_suggestion_with_applicability( &mut self, msg: &str, suggestion: Vec<(Span, String)>, + applicability: Applicability, ) -> &mut Self { self.suggestions.push(CodeSuggestion { substitutions: vec![Substitution { @@ -292,12 +295,26 @@ impl Diagnostic { }], msg: msg.to_owned(), show_code_when_inline: true, - applicability: Applicability::Unspecified, + applicability, }); self } + #[deprecated(note = "Use `multipart_suggestion_with_applicability`")] + pub fn multipart_suggestion( + &mut self, + msg: &str, + suggestion: Vec<(Span, String)>, + ) -> &mut Self { + self.multipart_suggestion_with_applicability( + msg, + suggestion, + Applicability::Unspecified, + ) + } + /// Prints out a message with multiple suggested edits of the code. + #[deprecated(note = "Use `span_suggestions_with_applicability`")] pub fn span_suggestions(&mut self, sp: Span, msg: &str, suggestions: Vec) -> &mut Self { self.suggestions.push(CodeSuggestion { substitutions: suggestions.into_iter().map(|snippet| Substitution { diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index a4b5b000f87..60a68b1e496 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -43,16 +43,18 @@ pub struct DiagnosticBuilder<'a> { /// it easy to declare such methods on the builder. macro_rules! forward { // Forward pattern for &self -> &Self - (pub fn $n:ident(&self, $($name:ident: $ty:ty),*) -> &Self) => { + (pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)*) -> &Self) => { pub fn $n(&self, $($name: $ty),*) -> &Self { + #[allow(deprecated)] self.diagnostic.$n($($name),*); self } }; // Forward pattern for &mut self -> &mut Self - (pub fn $n:ident(&mut self, $($name:ident: $ty:ty),*) -> &mut Self) => { + (pub fn $n:ident(&mut self, $($name:ident: $ty:ty),* $(,)*) -> &mut Self) => { pub fn $n(&mut self, $($name: $ty),*) -> &mut Self { + #[allow(deprecated)] self.diagnostic.$n($($name),*); self } @@ -60,8 +62,12 @@ macro_rules! forward { // Forward pattern for &mut self -> &mut Self, with S: Into // type parameter. No obvious way to make this more generic. - (pub fn $n:ident>(&mut self, $($name:ident: $ty:ty),*) -> &mut Self) => { + (pub fn $n:ident>( + &mut self, + $($name:ident: $ty:ty),* + $(,)*) -> &mut Self) => { pub fn $n>(&mut self, $($name: $ty),*) -> &mut Self { + #[allow(deprecated)] self.diagnostic.$n($($name),*); self } @@ -157,49 +163,75 @@ impl<'a> DiagnosticBuilder<'a> { forward!(pub fn note_expected_found(&mut self, label: &dyn fmt::Display, expected: DiagnosticStyledString, - found: DiagnosticStyledString) - -> &mut Self); + found: DiagnosticStyledString, + ) -> &mut Self); forward!(pub fn note_expected_found_extra(&mut self, label: &dyn fmt::Display, expected: DiagnosticStyledString, found: DiagnosticStyledString, expected_extra: &dyn fmt::Display, - found_extra: &dyn fmt::Display) - -> &mut Self); + found_extra: &dyn fmt::Display, + ) -> &mut Self); forward!(pub fn note(&mut self, msg: &str) -> &mut Self); forward!(pub fn span_note>(&mut self, sp: S, - msg: &str) - -> &mut Self); + msg: &str, + ) -> &mut Self); forward!(pub fn warn(&mut self, msg: &str) -> &mut Self); forward!(pub fn span_warn>(&mut self, sp: S, msg: &str) -> &mut Self); forward!(pub fn help(&mut self , msg: &str) -> &mut Self); forward!(pub fn span_help>(&mut self, sp: S, - msg: &str) - -> &mut Self); - forward!(pub fn span_suggestion_short(&mut self, - sp: Span, - msg: &str, - suggestion: String) - -> &mut Self); + msg: &str, + ) -> &mut Self); + + #[deprecated(note = "Use `span_suggestion_short_with_applicability`")] + forward!(pub fn span_suggestion_short( + &mut self, + sp: Span, + msg: &str, + suggestion: String, + ) -> &mut Self); + + #[deprecated(note = "Use `multipart_suggestion_with_applicability`")] forward!(pub fn multipart_suggestion( &mut self, msg: &str, - suggestion: Vec<(Span, String)> + suggestion: Vec<(Span, String)>, ) -> &mut Self); + + #[deprecated(note = "Use `span_suggestion_with_applicability`")] forward!(pub fn span_suggestion(&mut self, sp: Span, msg: &str, - suggestion: String) - -> &mut Self); + suggestion: String, + ) -> &mut Self); + + #[deprecated(note = "Use `span_suggestions_with_applicability`")] forward!(pub fn span_suggestions(&mut self, sp: Span, msg: &str, - suggestions: Vec) - -> &mut Self); + suggestions: Vec, + ) -> &mut Self); + + pub fn multipart_suggestion_with_applicability(&mut self, + msg: &str, + suggestion: Vec<(Span, String)>, + applicability: Applicability, + ) -> &mut Self { + if !self.allow_suggestions { + return self + } + self.diagnostic.multipart_suggestion_with_applicability( + msg, + suggestion, + applicability, + ); + self + } + pub fn span_suggestion_with_applicability(&mut self, sp: Span, msg: &str, diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index 290c7032388..52d051ebe7b 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -11,7 +11,7 @@ use core::unicode::property::Pattern_White_Space; use rustc::mir::*; use rustc::ty; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::{DiagnosticBuilder,Applicability}; use syntax_pos::Span; use borrow_check::MirBorrowckCtxt; @@ -350,16 +350,18 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { // expressions `a[b]`, which roughly desugar to // `*Index::index(&a, b)` or // `*IndexMut::index_mut(&mut a, b)`. - err.span_suggestion( + err.span_suggestion_with_applicability( span, "consider removing the `*`", snippet[1..].to_owned(), + Applicability::Unspecified, ); } else { - err.span_suggestion( + err.span_suggestion_with_applicability( span, "consider borrowing here", format!("&{}", snippet), + Applicability::Unspecified, ); } @@ -420,10 +422,11 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { suggestions.sort_unstable_by_key(|&(span, _, _)| span); suggestions.dedup_by_key(|&mut (span, _, _)| span); for (span, to_remove, suggestion) in suggestions { - err.span_suggestion( + err.span_suggestion_with_applicability( span, &format!("consider removing the `{}`", to_remove), - suggestion + suggestion, + Applicability::MachineApplicable, ); } } diff --git a/src/librustc_mir/borrow_check/mutability_errors.rs b/src/librustc_mir/borrow_check/mutability_errors.rs index 78ab772d9ad..a078aa59a7d 100644 --- a/src/librustc_mir/borrow_check/mutability_errors.rs +++ b/src/librustc_mir/borrow_check/mutability_errors.rs @@ -22,6 +22,7 @@ use borrow_check::MirBorrowckCtxt; use util::borrowck_errors::{BorrowckErrors, Origin}; use util::collect_writes::FindAssignments; use util::suggest_ref_mut; +use rustc_errors::Applicability; #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub(super) enum AccessKind { @@ -227,10 +228,11 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { assert_eq!(local_decl.mutability, Mutability::Not); err.span_label(span, format!("cannot {ACT}", ACT = act)); - err.span_suggestion( + err.span_suggestion_with_applicability( local_decl.source_info.span, "consider changing this to be mutable", format!("mut {}", local_decl.name.unwrap()), + Applicability::MachineApplicable, ); } @@ -257,10 +259,11 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { _, ) = pat.node { - err.span_suggestion( + err.span_suggestion_with_applicability( upvar_ident.span, "consider changing this to be mutable", format!("mut {}", upvar_ident.name), + Applicability::MachineApplicable, ); } } @@ -351,10 +354,11 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { }; if let Some((err_help_span, suggested_code)) = suggestion { - err.span_suggestion( + err.span_suggestion_with_applicability( err_help_span, &format!("consider changing this to be a mutable {}", pointer_desc), suggested_code, + Applicability::MachineApplicable, ); } diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 2ee5415018f..f6ace57f5e0 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -182,8 +182,9 @@ impl<'a> AstValidator<'a> { ); if let Ok(snippet) = self.session.source_map().span_to_snippet(span) { - err.span_suggestion( + err.span_suggestion_with_applicability( span, "consider adding parentheses", format!("({})", snippet), + Applicability::MachineApplicable, ); } diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs index 61c2ac161bb..a87e86aee0c 100644 --- a/src/librustc_passes/loops.rs +++ b/src/librustc_passes/loops.rs @@ -16,6 +16,7 @@ use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap}; use rustc::hir::{self, Node, Destination}; use syntax::ast; use syntax_pos::Span; +use errors::Applicability; #[derive(Clone, Copy, Debug, PartialEq)] enum LoopKind { @@ -140,11 +141,16 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> { .span_label(e.span, "can only break with a value inside \ `loop` or breakable block") - .span_suggestion(e.span, - &format!("instead, use `break` on its own \ - without a value inside this `{}` loop", - kind.name()), - "break".to_string()) + .span_suggestion_with_applicability( + e.span, + &format!( + "instead, use `break` on its own \ + without a value inside this `{}` loop", + kind.name() + ), + "break".to_string(), + Applicability::MaybeIncorrect, + ) .emit(); } } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 3f9c1520957..343ef067a6c 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -3292,9 +3292,12 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { err.span_label(base_span, "expecting a type here because of type ascription"); if line_sp != line_base_sp { - err.span_suggestion_short(sp, - "did you mean to use `;` here instead?", - ";".to_string()); + err.span_suggestion_short_with_applicability( + sp, + "did you mean to use `;` here instead?", + ";".to_string(), + Applicability::MaybeIncorrect, + ); } break; } else if snippet.trim().len() != 0 { @@ -4818,7 +4821,12 @@ fn show_candidates(err: &mut DiagnosticBuilder, *candidate = format!("use {};\n{}", candidate, additional_newline); } - err.span_suggestions(span, &msg, path_strings); + err.span_suggestions_with_applicability( + span, + &msg, + path_strings, + Applicability::Unspecified, + ); } else { let mut msg = msg; msg.push(':'); diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index ebe0c279aaf..85641854e6e 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -40,7 +40,7 @@ use super::FnCtxt; -use errors::DiagnosticBuilder; +use errors::{DiagnosticBuilder,Applicability}; use hir::def_id::DefId; use lint; use rustc::hir; @@ -299,9 +299,12 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { err.note("The type information given here is insufficient to check whether \ the pointer cast is valid"); if unknown_cast_to { - err.span_suggestion_short(self.cast_span, - "consider giving more type information", - String::new()); + err.span_suggestion_short_with_applicability( + self.cast_span, + "consider giving more type information", + String::new(), + Applicability::Unspecified, + ); } err.emit(); } @@ -327,9 +330,12 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { if self.cast_ty.is_trait() { match fcx.tcx.sess.source_map().span_to_snippet(self.cast_span) { Ok(s) => { - err.span_suggestion(self.cast_span, - "try casting to a reference instead", - format!("&{}{}", mtstr, s)); + err.span_suggestion_with_applicability( + self.cast_span, + "try casting to a reference instead", + format!("&{}{}", mtstr, s), + Applicability::MachineApplicable, + ); } Err(_) => { span_help!(err, self.cast_span, "did you mean `&{}{}`?", mtstr, tstr) @@ -346,9 +352,12 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { ty::Adt(def, ..) if def.is_box() => { match fcx.tcx.sess.source_map().span_to_snippet(self.cast_span) { Ok(s) => { - err.span_suggestion(self.cast_span, - "try casting to a `Box` instead", - format!("Box<{}>", s)); + err.span_suggestion_with_applicability( + self.cast_span, + "try casting to a `Box` instead", + format!("Box<{}>", s), + Applicability::MachineApplicable, + ); } Err(_) => span_help!(err, self.cast_span, "did you mean `Box<{}>`?", tstr), } diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 9aa2ba363ed..a192068d28f 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -16,6 +16,7 @@ use rustc::traits::{self, ObligationCause, ObligationCauseCode, Reveal}; use rustc::ty::error::{ExpectedFound, TypeError}; use rustc::ty::subst::{Subst, Substs}; use rustc::util::common::ErrorReported; +use errors::Applicability; use syntax_pos::Span; @@ -321,10 +322,11 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, if let Some(trait_err_span) = trait_err_span { if let Ok(trait_err_str) = tcx.sess.source_map(). span_to_snippet(trait_err_span) { - diag.span_suggestion( + diag.span_suggestion_with_applicability( impl_err_span, "consider change the type to match the mutability in trait", format!("{}", trait_err_str), + Applicability::MachineApplicable, ); } } @@ -799,7 +801,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, .span_to_snippet(trait_m.generics.span) .ok()?; - err.multipart_suggestion( + err.multipart_suggestion_with_applicability( "try changing the `impl Trait` argument to a generic parameter", vec![ // replace `impl Trait` with `T` @@ -809,6 +811,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // of the generics, but it works for the common case (generics_span, new_generics), ], + Applicability::MaybeIncorrect, ); Some(()) })(); @@ -870,7 +873,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, .span_to_snippet(bounds) .ok()?; - err.multipart_suggestion( + err.multipart_suggestion_with_applicability( "try removing the generic parameter and using `impl Trait` instead", vec![ // delete generic parameters @@ -878,6 +881,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // replace param usage with `impl Trait` (span, format!("impl {}", bounds)), ], + Applicability::MaybeIncorrect, ); Some(()) })(); diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index e78cd4891a5..ee19574dc4e 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -132,9 +132,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let expr_text = print::to_string(print::NO_ANN, |s| s.print_expr(expr)); let suggestions = compatible_variants.iter() .map(|v| format!("{}({})", v, expr_text)).collect::>(); - err.span_suggestions(expr.span, - "try using a variant of the expected type", - suggestions); + err.span_suggestions_with_applicability( + expr.span, + "try using a variant of the expected type", + suggestions, + Applicability::MaybeIncorrect, + ); } } diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 85a437283fa..499daccf5e8 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -1064,7 +1064,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { "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 + // FIXME: This should be a `span_suggestion_with_applicability` instead of `help` + // However `self.span` only // highlights the method name, so we can't use it. Also consider reusing the code from // `report_method_error()`. diag.help(&format!( diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index abc32ed2ea0..fe5128a6958 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -251,13 +251,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let snippet = tcx.sess.source_map().span_to_snippet(lit.span) .unwrap_or("".to_string()); - err.span_suggestion(lit.span, + err.span_suggestion_with_applicability( + lit.span, &format!("you must specify a concrete type for \ this numeric value, like `{}`", concrete_type), format!("{}_{}", snippet, - concrete_type)); + concrete_type), + Applicability::MaybeIncorrect, + ); } hir::ExprKind::Path(ref qpath) => { // local binding if let &hir::QPath::Resolved(_, ref path) = &qpath { @@ -281,13 +284,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ty, .. })) => { - err.span_suggestion( + err.span_suggestion_with_applicability( // account for `let x: _ = 42;` // ^^^^ span.to(ty.as_ref().map(|ty| ty.span) .unwrap_or(span)), &msg, format!("{}: {}", snippet, concrete_type), + Applicability::MaybeIncorrect, ); } _ => { @@ -516,7 +520,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { format!("use {};\n{}", self.tcx.item_path_str(*did), additional_newline) }).collect(); - err.span_suggestions(span, &msg, path_strings); + err.span_suggestions_with_applicability( + span, + &msg, + path_strings, + Applicability::MaybeIncorrect, + ); } else { let limit = if candidates.len() == 5 { 5 } else { 4 }; for (i, trait_did) in candidates.iter().take(limit).enumerate() { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index db0c4fdb03a..80df7faf39d 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3351,7 +3351,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let base = self.tcx.hir.node_to_pretty_string(base.id); let msg = format!("`{}` is a native pointer; try dereferencing it", base); let suggestion = format!("(*{}).{}", base, field); - err.span_suggestion(field.span, &msg, suggestion); + err.span_suggestion_with_applicability( + field.span, + &msg, + suggestion, + Applicability::MaybeIncorrect, + ); } _ => {} } @@ -4719,7 +4724,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { found: Ty<'tcx>, ) { if let Some((sp, msg, suggestion)) = self.check_ref(expr, found, expected) { - err.span_suggestion(sp, msg, suggestion); + err.span_suggestion_with_applicability( + sp, + msg, + suggestion, + Applicability::MachineApplicable, + ); } else if !self.check_for_cast(err, expr, found, expected) { let methods = self.get_conversion_methods(expr.span, expected, found); if let Ok(expr_text) = self.sess().source_map().span_to_snippet(expr.span) { @@ -4749,7 +4759,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } }) .collect::>(); if !suggestions.is_empty() { - err.span_suggestions(expr.span, "try using a conversion method", suggestions); + err.span_suggestions_with_applicability( + expr.span, + "try using a conversion method", + suggestions, + Applicability::MaybeIncorrect, + ); } } } diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index 5004880ce47..5969f288d73 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -16,7 +16,7 @@ use rustc::ty::{self, Ty, TypeFoldable}; use rustc::ty::TyKind::{Ref, Adt, Str, Uint, Never, Tuple, Char, Array}; use rustc::ty::adjustment::{Adjustment, Adjust, AllowTwoPhase, AutoBorrow, AutoBorrowMutability}; use rustc::infer::type_variable::TypeVariableOrigin; -use errors; +use errors::{self,Applicability}; use syntax_pos::Span; use syntax::ast::Ident; use rustc::hir; @@ -444,9 +444,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { err.span_label(expr.span, "`+` can't be used to concatenate two `&str` strings"); match source_map.span_to_snippet(lhs_expr.span) { - Ok(lstring) => err.span_suggestion(lhs_expr.span, - msg, - format!("{}.to_owned()", lstring)), + Ok(lstring) => err.span_suggestion_with_applicability( + lhs_expr.span, + msg, + format!("{}.to_owned()", lstring), + Applicability::MachineApplicable, + ), _ => err.help(msg), }; } @@ -462,10 +465,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { is_assign, ) { (Ok(l), Ok(r), false) => { - err.multipart_suggestion(msg, vec![ - (lhs_expr.span, format!("{}.to_owned()", l)), - (rhs_expr.span, format!("&{}", r)), - ]); + err.multipart_suggestion_with_applicability( + msg, + vec![ + (lhs_expr.span, format!("{}.to_owned()", l)), + (rhs_expr.span, format!("&{}", r)), + ], + Applicability::MachineApplicable, + ); } _ => { err.help(msg); diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index 63b70b12248..5d978b6b9e6 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -16,6 +16,7 @@ use source_map::Spanned; use edition::Edition; use parse::{token, ParseSess}; use OneVector; +use errors::Applicability; use ptr::P; @@ -123,7 +124,12 @@ impl<'a> StripUnconfigured<'a> { let error = |span, msg, suggestion: &str| { let mut err = self.sess.span_diagnostic.struct_span_err(span, msg); if !suggestion.is_empty() { - err.span_suggestion(span, "expected syntax is", suggestion.into()); + err.span_suggestion_with_applicability( + span, + "expected syntax is", + suggestion.into(), + Applicability::MaybeIncorrect, + ); } err.emit(); true diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 86247745c41..214bc9cffc4 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -32,6 +32,7 @@ use std::borrow::Cow; use std::collections::hash_map::Entry; use rustc_data_structures::sync::Lrc; +use errors::Applicability; pub struct ParserAnyMacro<'a> { parser: Parser<'a>, @@ -187,10 +188,11 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt, if comma_span == DUMMY_SP { err.note("you might be missing a comma"); } else { - err.span_suggestion_short( + err.span_suggestion_short_with_applicability( comma_span, "missing comma here", ", ".to_string(), + Applicability::MachineApplicable, ); } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 48e034b117f..6ec1ad969ee 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3882,7 +3882,12 @@ impl<'a> Parser<'a> { if self.token == token::CloseDelim(token::Brace) { // If the struct looks otherwise well formed, recover and continue. if let Some(sp) = comma_sp { - err.span_suggestion_short(sp, "remove this comma", String::new()); + err.span_suggestion_short_with_applicability( + sp, + "remove this comma", + String::new(), + Applicability::MachineApplicable, + ); } err.emit(); break; diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index efe9c2cefde..31e608de1f8 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -996,9 +996,10 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, )); } if suggestions.len() > 0 { - diag.multipart_suggestion( + diag.multipart_suggestion_with_applicability( "format specifiers use curly braces", suggestions, + Applicability::MachineApplicable, ); } }};