Auto merge of #54241 - vi:suggest_with_applicability, r=estebank
Remove usages of span_suggestion without Applicability Use `Applicability::Unspecified` for all of them instead. Shall deprecations for the non-`_with_applicability` functions be added? Shall clippy be addressed somehow? r? @estebank
This commit is contained in:
commit
992d1e4d3d
22 changed files with 258 additions and 96 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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<String>) -> &mut Self {
|
||||
self.suggestions.push(CodeSuggestion {
|
||||
substitutions: suggestions.into_iter().map(|snippet| Substitution {
|
||||
|
|
|
@ -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<MultiSpan>
|
||||
// type parameter. No obvious way to make this more generic.
|
||||
(pub fn $n:ident<S: Into<MultiSpan>>(&mut self, $($name:ident: $ty:ty),*) -> &mut Self) => {
|
||||
(pub fn $n:ident<S: Into<MultiSpan>>(
|
||||
&mut self,
|
||||
$($name:ident: $ty:ty),*
|
||||
$(,)*) -> &mut Self) => {
|
||||
pub fn $n<S: Into<MultiSpan>>(&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<S: Into<MultiSpan>>(&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<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self);
|
||||
forward!(pub fn help(&mut self , msg: &str) -> &mut Self);
|
||||
forward!(pub fn span_help<S: Into<MultiSpan>>(&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<String>)
|
||||
-> &mut Self);
|
||||
suggestions: Vec<String>,
|
||||
) -> &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,
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(':');
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
|
|
@ -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(())
|
||||
})();
|
||||
|
|
|
@ -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::<Vec<_>>();
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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!(
|
||||
|
|
|
@ -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("<numeric literal>".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() {
|
||||
|
|
|
@ -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::<Vec<_>>();
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
}};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue