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 infer::error_reporting::nice_region_error::NiceRegionError;
|
||||||
use ty;
|
use ty;
|
||||||
use util::common::ErrorReported;
|
use util::common::ErrorReported;
|
||||||
|
use errors::Applicability;
|
||||||
|
|
||||||
impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
|
impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
|
||||||
/// When given a `ConcreteFailure` for a function with arguments containing a named region and
|
/// 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,
|
E0621,
|
||||||
"explicit lifetime required in {}",
|
"explicit lifetime required in {}",
|
||||||
error_var
|
error_var
|
||||||
).span_suggestion(
|
).span_suggestion_with_applicability(
|
||||||
new_ty_span,
|
new_ty_span,
|
||||||
&format!("add explicit lifetime `{}` to {}", named, span_label_var),
|
&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))
|
.span_label(span, format!("lifetime `{}` required", named))
|
||||||
.emit();
|
.emit();
|
||||||
return Some(ErrorReported);
|
return Some(ErrorReported);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ use infer::error_reporting::nice_region_error::NiceRegionError;
|
||||||
use infer::lexical_region_resolve::RegionResolutionError;
|
use infer::lexical_region_resolve::RegionResolutionError;
|
||||||
use ty::{BoundRegion, FreeRegion, RegionKind};
|
use ty::{BoundRegion, FreeRegion, RegionKind};
|
||||||
use util::common::ErrorReported;
|
use util::common::ErrorReported;
|
||||||
|
use errors::Applicability;
|
||||||
|
|
||||||
impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
|
impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
|
||||||
/// Print the error message for lifetime errors when the return type is a static impl Trait.
|
/// 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(),
|
_ => "'_".to_owned(),
|
||||||
};
|
};
|
||||||
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(return_sp) {
|
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(return_sp) {
|
||||||
err.span_suggestion(
|
err.span_suggestion_with_applicability(
|
||||||
return_sp,
|
return_sp,
|
||||||
&format!(
|
&format!(
|
||||||
"you can add a constraint to the return type to make it last \
|
"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,
|
lifetime,
|
||||||
),
|
),
|
||||||
format!("{} + {}", snippet, lifetime_name),
|
format!("{} + {}", snippet, lifetime_name),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
err.emit();
|
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 rustc_data_structures::sync::{self, Lrc, Lock, LockCell, OneThread, Once, RwLock};
|
||||||
|
|
||||||
use syntax::ast::NodeId;
|
use syntax::ast::NodeId;
|
||||||
use errors::{self, DiagnosticBuilder, DiagnosticId};
|
use errors::{self, DiagnosticBuilder, DiagnosticId, Applicability};
|
||||||
use errors::emitter::{Emitter, EmitterWriter};
|
use errors::emitter::{Emitter, EmitterWriter};
|
||||||
use syntax::edition::Edition;
|
use syntax::edition::Edition;
|
||||||
use syntax::json::JsonEmitter;
|
use syntax::json::JsonEmitter;
|
||||||
|
@ -431,8 +431,13 @@ impl Session {
|
||||||
diag_builder.span_note(span, message);
|
diag_builder.span_note(span, message);
|
||||||
}
|
}
|
||||||
DiagnosticBuilderMethod::SpanSuggestion(suggestion) => {
|
DiagnosticBuilderMethod::SpanSuggestion(suggestion) => {
|
||||||
let span = span_maybe.expect("span_suggestion needs a span");
|
let span = span_maybe.expect("span_suggestion_* needs a span");
|
||||||
diag_builder.span_suggestion(span, message, suggestion);
|
diag_builder.span_suggestion_with_applicability(
|
||||||
|
span,
|
||||||
|
message,
|
||||||
|
suggestion,
|
||||||
|
Applicability::Unspecified,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -867,10 +867,20 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
||||||
}) = cmt.cat {
|
}) = cmt.cat {
|
||||||
db.note(fn_closure_msg);
|
db.note(fn_closure_msg);
|
||||||
} else {
|
} else {
|
||||||
db.span_suggestion(sp, msg, suggestion);
|
db.span_suggestion_with_applicability(
|
||||||
|
sp,
|
||||||
|
msg,
|
||||||
|
suggestion,
|
||||||
|
Applicability::Unspecified,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} 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 let_span = self.tcx.hir.span(node_id);
|
||||||
let suggestion = suggest_ref_mut(self.tcx, let_span);
|
let suggestion = suggest_ref_mut(self.tcx, let_span);
|
||||||
if let Some(replace_str) = suggestion {
|
if let Some(replace_str) = suggestion {
|
||||||
db.span_suggestion(
|
db.span_suggestion_with_applicability(
|
||||||
let_span,
|
let_span,
|
||||||
"use a mutable reference instead",
|
"use a mutable reference instead",
|
||||||
replace_str,
|
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)
|
)) = ty.map(|t| &t.node)
|
||||||
{
|
{
|
||||||
let borrow_expr_id = self.tcx.hir.get_parent_node(borrowed_node_id);
|
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),
|
self.tcx.hir.span(borrow_expr_id),
|
||||||
"consider removing the `&mut`, as it is an \
|
"consider removing the `&mut`, as it is an \
|
||||||
immutable binding to a mutable reference",
|
immutable binding to a mutable reference",
|
||||||
snippet
|
snippet,
|
||||||
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion_with_applicability(
|
||||||
|
@ -1326,12 +1343,15 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
||||||
&cmt_path_or_string,
|
&cmt_path_or_string,
|
||||||
capture_span,
|
capture_span,
|
||||||
Origin::Ast)
|
Origin::Ast)
|
||||||
.span_suggestion(err.span,
|
.span_suggestion_with_applicability(
|
||||||
&format!("to force the closure to take ownership of {} \
|
err.span,
|
||||||
(and any other referenced variables), \
|
&format!("to force the closure to take ownership of {} \
|
||||||
use the `move` keyword",
|
(and any other referenced variables), \
|
||||||
cmt_path_or_string),
|
use the `move` keyword",
|
||||||
suggestion)
|
cmt_path_or_string),
|
||||||
|
suggestion,
|
||||||
|
Applicability::MachineApplicable,
|
||||||
|
)
|
||||||
.emit();
|
.emit();
|
||||||
self.signal_error();
|
self.signal_error();
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,6 +232,7 @@ impl Diagnostic {
|
||||||
/// inline it will only show the text message and not the text.
|
/// inline it will only show the text message and not the text.
|
||||||
///
|
///
|
||||||
/// See `CodeSuggestion` for more information.
|
/// 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 {
|
pub fn span_suggestion_short(&mut self, sp: Span, msg: &str, suggestion: String) -> &mut Self {
|
||||||
self.suggestions.push(CodeSuggestion {
|
self.suggestions.push(CodeSuggestion {
|
||||||
substitutions: vec![Substitution {
|
substitutions: vec![Substitution {
|
||||||
|
@ -263,6 +264,7 @@ impl Diagnostic {
|
||||||
/// * may contain a name of a function, variable or type, but not whole expressions
|
/// * may contain a name of a function, variable or type, but not whole expressions
|
||||||
///
|
///
|
||||||
/// See `CodeSuggestion` for more information.
|
/// 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 {
|
pub fn span_suggestion(&mut self, sp: Span, msg: &str, suggestion: String) -> &mut Self {
|
||||||
self.suggestions.push(CodeSuggestion {
|
self.suggestions.push(CodeSuggestion {
|
||||||
substitutions: vec![Substitution {
|
substitutions: vec![Substitution {
|
||||||
|
@ -278,10 +280,11 @@ impl Diagnostic {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn multipart_suggestion(
|
pub fn multipart_suggestion_with_applicability(
|
||||||
&mut self,
|
&mut self,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
suggestion: Vec<(Span, String)>,
|
suggestion: Vec<(Span, String)>,
|
||||||
|
applicability: Applicability,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
self.suggestions.push(CodeSuggestion {
|
self.suggestions.push(CodeSuggestion {
|
||||||
substitutions: vec![Substitution {
|
substitutions: vec![Substitution {
|
||||||
|
@ -292,12 +295,26 @@ impl Diagnostic {
|
||||||
}],
|
}],
|
||||||
msg: msg.to_owned(),
|
msg: msg.to_owned(),
|
||||||
show_code_when_inline: true,
|
show_code_when_inline: true,
|
||||||
applicability: Applicability::Unspecified,
|
applicability,
|
||||||
});
|
});
|
||||||
self
|
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.
|
/// 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 {
|
pub fn span_suggestions(&mut self, sp: Span, msg: &str, suggestions: Vec<String>) -> &mut Self {
|
||||||
self.suggestions.push(CodeSuggestion {
|
self.suggestions.push(CodeSuggestion {
|
||||||
substitutions: suggestions.into_iter().map(|snippet| Substitution {
|
substitutions: suggestions.into_iter().map(|snippet| Substitution {
|
||||||
|
|
|
@ -43,16 +43,18 @@ pub struct DiagnosticBuilder<'a> {
|
||||||
/// it easy to declare such methods on the builder.
|
/// it easy to declare such methods on the builder.
|
||||||
macro_rules! forward {
|
macro_rules! forward {
|
||||||
// Forward pattern for &self -> &Self
|
// 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 {
|
pub fn $n(&self, $($name: $ty),*) -> &Self {
|
||||||
|
#[allow(deprecated)]
|
||||||
self.diagnostic.$n($($name),*);
|
self.diagnostic.$n($($name),*);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Forward pattern for &mut self -> &mut 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 {
|
pub fn $n(&mut self, $($name: $ty),*) -> &mut Self {
|
||||||
|
#[allow(deprecated)]
|
||||||
self.diagnostic.$n($($name),*);
|
self.diagnostic.$n($($name),*);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -60,8 +62,12 @@ macro_rules! forward {
|
||||||
|
|
||||||
// Forward pattern for &mut self -> &mut Self, with S: Into<MultiSpan>
|
// Forward pattern for &mut self -> &mut Self, with S: Into<MultiSpan>
|
||||||
// type parameter. No obvious way to make this more generic.
|
// 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 {
|
pub fn $n<S: Into<MultiSpan>>(&mut self, $($name: $ty),*) -> &mut Self {
|
||||||
|
#[allow(deprecated)]
|
||||||
self.diagnostic.$n($($name),*);
|
self.diagnostic.$n($($name),*);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -157,49 +163,75 @@ impl<'a> DiagnosticBuilder<'a> {
|
||||||
forward!(pub fn note_expected_found(&mut self,
|
forward!(pub fn note_expected_found(&mut self,
|
||||||
label: &dyn fmt::Display,
|
label: &dyn fmt::Display,
|
||||||
expected: DiagnosticStyledString,
|
expected: DiagnosticStyledString,
|
||||||
found: DiagnosticStyledString)
|
found: DiagnosticStyledString,
|
||||||
-> &mut Self);
|
) -> &mut Self);
|
||||||
|
|
||||||
forward!(pub fn note_expected_found_extra(&mut self,
|
forward!(pub fn note_expected_found_extra(&mut self,
|
||||||
label: &dyn fmt::Display,
|
label: &dyn fmt::Display,
|
||||||
expected: DiagnosticStyledString,
|
expected: DiagnosticStyledString,
|
||||||
found: DiagnosticStyledString,
|
found: DiagnosticStyledString,
|
||||||
expected_extra: &dyn fmt::Display,
|
expected_extra: &dyn fmt::Display,
|
||||||
found_extra: &dyn fmt::Display)
|
found_extra: &dyn fmt::Display,
|
||||||
-> &mut Self);
|
) -> &mut Self);
|
||||||
|
|
||||||
forward!(pub fn note(&mut self, msg: &str) -> &mut Self);
|
forward!(pub fn note(&mut self, msg: &str) -> &mut Self);
|
||||||
forward!(pub fn span_note<S: Into<MultiSpan>>(&mut self,
|
forward!(pub fn span_note<S: Into<MultiSpan>>(&mut self,
|
||||||
sp: S,
|
sp: S,
|
||||||
msg: &str)
|
msg: &str,
|
||||||
-> &mut Self);
|
) -> &mut Self);
|
||||||
forward!(pub fn warn(&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 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 help(&mut self , msg: &str) -> &mut Self);
|
||||||
forward!(pub fn span_help<S: Into<MultiSpan>>(&mut self,
|
forward!(pub fn span_help<S: Into<MultiSpan>>(&mut self,
|
||||||
sp: S,
|
sp: S,
|
||||||
msg: &str)
|
msg: &str,
|
||||||
-> &mut Self);
|
) -> &mut Self);
|
||||||
forward!(pub fn span_suggestion_short(&mut self,
|
|
||||||
sp: Span,
|
#[deprecated(note = "Use `span_suggestion_short_with_applicability`")]
|
||||||
msg: &str,
|
forward!(pub fn span_suggestion_short(
|
||||||
suggestion: String)
|
&mut self,
|
||||||
-> &mut Self);
|
sp: Span,
|
||||||
|
msg: &str,
|
||||||
|
suggestion: String,
|
||||||
|
) -> &mut Self);
|
||||||
|
|
||||||
|
#[deprecated(note = "Use `multipart_suggestion_with_applicability`")]
|
||||||
forward!(pub fn multipart_suggestion(
|
forward!(pub fn multipart_suggestion(
|
||||||
&mut self,
|
&mut self,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
suggestion: Vec<(Span, String)>
|
suggestion: Vec<(Span, String)>,
|
||||||
) -> &mut Self);
|
) -> &mut Self);
|
||||||
|
|
||||||
|
#[deprecated(note = "Use `span_suggestion_with_applicability`")]
|
||||||
forward!(pub fn span_suggestion(&mut self,
|
forward!(pub fn span_suggestion(&mut self,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
suggestion: String)
|
suggestion: String,
|
||||||
-> &mut Self);
|
) -> &mut Self);
|
||||||
|
|
||||||
|
#[deprecated(note = "Use `span_suggestions_with_applicability`")]
|
||||||
forward!(pub fn span_suggestions(&mut self,
|
forward!(pub fn span_suggestions(&mut self,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
suggestions: Vec<String>)
|
suggestions: Vec<String>,
|
||||||
-> &mut Self);
|
) -> &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,
|
pub fn span_suggestion_with_applicability(&mut self,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
use core::unicode::property::Pattern_White_Space;
|
use core::unicode::property::Pattern_White_Space;
|
||||||
use rustc::mir::*;
|
use rustc::mir::*;
|
||||||
use rustc::ty;
|
use rustc::ty;
|
||||||
use rustc_errors::DiagnosticBuilder;
|
use rustc_errors::{DiagnosticBuilder,Applicability};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
|
||||||
use borrow_check::MirBorrowckCtxt;
|
use borrow_check::MirBorrowckCtxt;
|
||||||
|
@ -350,16 +350,18 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
|
||||||
// expressions `a[b]`, which roughly desugar to
|
// expressions `a[b]`, which roughly desugar to
|
||||||
// `*Index::index(&a, b)` or
|
// `*Index::index(&a, b)` or
|
||||||
// `*IndexMut::index_mut(&mut a, b)`.
|
// `*IndexMut::index_mut(&mut a, b)`.
|
||||||
err.span_suggestion(
|
err.span_suggestion_with_applicability(
|
||||||
span,
|
span,
|
||||||
"consider removing the `*`",
|
"consider removing the `*`",
|
||||||
snippet[1..].to_owned(),
|
snippet[1..].to_owned(),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
err.span_suggestion(
|
err.span_suggestion_with_applicability(
|
||||||
span,
|
span,
|
||||||
"consider borrowing here",
|
"consider borrowing here",
|
||||||
format!("&{}", snippet),
|
format!("&{}", snippet),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,10 +422,11 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
|
||||||
suggestions.sort_unstable_by_key(|&(span, _, _)| span);
|
suggestions.sort_unstable_by_key(|&(span, _, _)| span);
|
||||||
suggestions.dedup_by_key(|&mut (span, _, _)| span);
|
suggestions.dedup_by_key(|&mut (span, _, _)| span);
|
||||||
for (span, to_remove, suggestion) in suggestions {
|
for (span, to_remove, suggestion) in suggestions {
|
||||||
err.span_suggestion(
|
err.span_suggestion_with_applicability(
|
||||||
span,
|
span,
|
||||||
&format!("consider removing the `{}`", to_remove),
|
&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::borrowck_errors::{BorrowckErrors, Origin};
|
||||||
use util::collect_writes::FindAssignments;
|
use util::collect_writes::FindAssignments;
|
||||||
use util::suggest_ref_mut;
|
use util::suggest_ref_mut;
|
||||||
|
use rustc_errors::Applicability;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
pub(super) enum AccessKind {
|
pub(super) enum AccessKind {
|
||||||
|
@ -227,10 +228,11 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
|
||||||
assert_eq!(local_decl.mutability, Mutability::Not);
|
assert_eq!(local_decl.mutability, Mutability::Not);
|
||||||
|
|
||||||
err.span_label(span, format!("cannot {ACT}", ACT = act));
|
err.span_label(span, format!("cannot {ACT}", ACT = act));
|
||||||
err.span_suggestion(
|
err.span_suggestion_with_applicability(
|
||||||
local_decl.source_info.span,
|
local_decl.source_info.span,
|
||||||
"consider changing this to be mutable",
|
"consider changing this to be mutable",
|
||||||
format!("mut {}", local_decl.name.unwrap()),
|
format!("mut {}", local_decl.name.unwrap()),
|
||||||
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,10 +259,11 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
|
||||||
_,
|
_,
|
||||||
) = pat.node
|
) = pat.node
|
||||||
{
|
{
|
||||||
err.span_suggestion(
|
err.span_suggestion_with_applicability(
|
||||||
upvar_ident.span,
|
upvar_ident.span,
|
||||||
"consider changing this to be mutable",
|
"consider changing this to be mutable",
|
||||||
format!("mut {}", upvar_ident.name),
|
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 {
|
if let Some((err_help_span, suggested_code)) = suggestion {
|
||||||
err.span_suggestion(
|
err.span_suggestion_with_applicability(
|
||||||
err_help_span,
|
err_help_span,
|
||||||
&format!("consider changing this to be a mutable {}", pointer_desc),
|
&format!("consider changing this to be a mutable {}", pointer_desc),
|
||||||
suggested_code,
|
suggested_code,
|
||||||
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -182,8 +182,9 @@ impl<'a> AstValidator<'a> {
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Ok(snippet) = self.session.source_map().span_to_snippet(span) {
|
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),
|
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 rustc::hir::{self, Node, Destination};
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
use errors::Applicability;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
enum LoopKind {
|
enum LoopKind {
|
||||||
|
@ -140,11 +141,16 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
|
||||||
.span_label(e.span,
|
.span_label(e.span,
|
||||||
"can only break with a value inside \
|
"can only break with a value inside \
|
||||||
`loop` or breakable block")
|
`loop` or breakable block")
|
||||||
.span_suggestion(e.span,
|
.span_suggestion_with_applicability(
|
||||||
&format!("instead, use `break` on its own \
|
e.span,
|
||||||
without a value inside this `{}` loop",
|
&format!(
|
||||||
kind.name()),
|
"instead, use `break` on its own \
|
||||||
"break".to_string())
|
without a value inside this `{}` loop",
|
||||||
|
kind.name()
|
||||||
|
),
|
||||||
|
"break".to_string(),
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
)
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3292,9 +3292,12 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
||||||
err.span_label(base_span,
|
err.span_label(base_span,
|
||||||
"expecting a type here because of type ascription");
|
"expecting a type here because of type ascription");
|
||||||
if line_sp != line_base_sp {
|
if line_sp != line_base_sp {
|
||||||
err.span_suggestion_short(sp,
|
err.span_suggestion_short_with_applicability(
|
||||||
"did you mean to use `;` here instead?",
|
sp,
|
||||||
";".to_string());
|
"did you mean to use `;` here instead?",
|
||||||
|
";".to_string(),
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else if snippet.trim().len() != 0 {
|
} else if snippet.trim().len() != 0 {
|
||||||
|
@ -4818,7 +4821,12 @@ fn show_candidates(err: &mut DiagnosticBuilder,
|
||||||
*candidate = format!("use {};\n{}", candidate, additional_newline);
|
*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 {
|
} else {
|
||||||
let mut msg = msg;
|
let mut msg = msg;
|
||||||
msg.push(':');
|
msg.push(':');
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
|
|
||||||
use super::FnCtxt;
|
use super::FnCtxt;
|
||||||
|
|
||||||
use errors::DiagnosticBuilder;
|
use errors::{DiagnosticBuilder,Applicability};
|
||||||
use hir::def_id::DefId;
|
use hir::def_id::DefId;
|
||||||
use lint;
|
use lint;
|
||||||
use rustc::hir;
|
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 \
|
err.note("The type information given here is insufficient to check whether \
|
||||||
the pointer cast is valid");
|
the pointer cast is valid");
|
||||||
if unknown_cast_to {
|
if unknown_cast_to {
|
||||||
err.span_suggestion_short(self.cast_span,
|
err.span_suggestion_short_with_applicability(
|
||||||
"consider giving more type information",
|
self.cast_span,
|
||||||
String::new());
|
"consider giving more type information",
|
||||||
|
String::new(),
|
||||||
|
Applicability::Unspecified,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
err.emit();
|
err.emit();
|
||||||
}
|
}
|
||||||
|
@ -327,9 +330,12 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
|
||||||
if self.cast_ty.is_trait() {
|
if self.cast_ty.is_trait() {
|
||||||
match fcx.tcx.sess.source_map().span_to_snippet(self.cast_span) {
|
match fcx.tcx.sess.source_map().span_to_snippet(self.cast_span) {
|
||||||
Ok(s) => {
|
Ok(s) => {
|
||||||
err.span_suggestion(self.cast_span,
|
err.span_suggestion_with_applicability(
|
||||||
"try casting to a reference instead",
|
self.cast_span,
|
||||||
format!("&{}{}", mtstr, s));
|
"try casting to a reference instead",
|
||||||
|
format!("&{}{}", mtstr, s),
|
||||||
|
Applicability::MachineApplicable,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
span_help!(err, self.cast_span, "did you mean `&{}{}`?", mtstr, tstr)
|
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() => {
|
ty::Adt(def, ..) if def.is_box() => {
|
||||||
match fcx.tcx.sess.source_map().span_to_snippet(self.cast_span) {
|
match fcx.tcx.sess.source_map().span_to_snippet(self.cast_span) {
|
||||||
Ok(s) => {
|
Ok(s) => {
|
||||||
err.span_suggestion(self.cast_span,
|
err.span_suggestion_with_applicability(
|
||||||
"try casting to a `Box` instead",
|
self.cast_span,
|
||||||
format!("Box<{}>", s));
|
"try casting to a `Box` instead",
|
||||||
|
format!("Box<{}>", s),
|
||||||
|
Applicability::MachineApplicable,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Err(_) => span_help!(err, self.cast_span, "did you mean `Box<{}>`?", tstr),
|
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::error::{ExpectedFound, TypeError};
|
||||||
use rustc::ty::subst::{Subst, Substs};
|
use rustc::ty::subst::{Subst, Substs};
|
||||||
use rustc::util::common::ErrorReported;
|
use rustc::util::common::ErrorReported;
|
||||||
|
use errors::Applicability;
|
||||||
|
|
||||||
use syntax_pos::Span;
|
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 Some(trait_err_span) = trait_err_span {
|
||||||
if let Ok(trait_err_str) = tcx.sess.source_map().
|
if let Ok(trait_err_str) = tcx.sess.source_map().
|
||||||
span_to_snippet(trait_err_span) {
|
span_to_snippet(trait_err_span) {
|
||||||
diag.span_suggestion(
|
diag.span_suggestion_with_applicability(
|
||||||
impl_err_span,
|
impl_err_span,
|
||||||
"consider change the type to match the mutability in trait",
|
"consider change the type to match the mutability in trait",
|
||||||
format!("{}", trait_err_str),
|
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)
|
.span_to_snippet(trait_m.generics.span)
|
||||||
.ok()?;
|
.ok()?;
|
||||||
|
|
||||||
err.multipart_suggestion(
|
err.multipart_suggestion_with_applicability(
|
||||||
"try changing the `impl Trait` argument to a generic parameter",
|
"try changing the `impl Trait` argument to a generic parameter",
|
||||||
vec![
|
vec![
|
||||||
// replace `impl Trait` with `T`
|
// 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
|
// of the generics, but it works for the common case
|
||||||
(generics_span, new_generics),
|
(generics_span, new_generics),
|
||||||
],
|
],
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
Some(())
|
Some(())
|
||||||
})();
|
})();
|
||||||
|
@ -870,7 +873,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
.span_to_snippet(bounds)
|
.span_to_snippet(bounds)
|
||||||
.ok()?;
|
.ok()?;
|
||||||
|
|
||||||
err.multipart_suggestion(
|
err.multipart_suggestion_with_applicability(
|
||||||
"try removing the generic parameter and using `impl Trait` instead",
|
"try removing the generic parameter and using `impl Trait` instead",
|
||||||
vec![
|
vec![
|
||||||
// delete generic parameters
|
// delete generic parameters
|
||||||
|
@ -878,6 +881,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
// replace param usage with `impl Trait`
|
// replace param usage with `impl Trait`
|
||||||
(span, format!("impl {}", bounds)),
|
(span, format!("impl {}", bounds)),
|
||||||
],
|
],
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
Some(())
|
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 expr_text = print::to_string(print::NO_ANN, |s| s.print_expr(expr));
|
||||||
let suggestions = compatible_variants.iter()
|
let suggestions = compatible_variants.iter()
|
||||||
.map(|v| format!("{}({})", v, expr_text)).collect::<Vec<_>>();
|
.map(|v| format!("{}({})", v, expr_text)).collect::<Vec<_>>();
|
||||||
err.span_suggestions(expr.span,
|
err.span_suggestions_with_applicability(
|
||||||
"try using a variant of the expected type",
|
expr.span,
|
||||||
suggestions);
|
"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",
|
"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
|
// highlights the method name, so we can't use it. Also consider reusing the code from
|
||||||
// `report_method_error()`.
|
// `report_method_error()`.
|
||||||
diag.help(&format!(
|
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)
|
let snippet = tcx.sess.source_map().span_to_snippet(lit.span)
|
||||||
.unwrap_or("<numeric literal>".to_string());
|
.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 \
|
&format!("you must specify a concrete type for \
|
||||||
this numeric value, like `{}`",
|
this numeric value, like `{}`",
|
||||||
concrete_type),
|
concrete_type),
|
||||||
format!("{}_{}",
|
format!("{}_{}",
|
||||||
snippet,
|
snippet,
|
||||||
concrete_type));
|
concrete_type),
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
hir::ExprKind::Path(ref qpath) => { // local binding
|
hir::ExprKind::Path(ref qpath) => { // local binding
|
||||||
if let &hir::QPath::Resolved(_, ref path) = &qpath {
|
if let &hir::QPath::Resolved(_, ref path) = &qpath {
|
||||||
|
@ -281,13 +284,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
ty,
|
ty,
|
||||||
..
|
..
|
||||||
})) => {
|
})) => {
|
||||||
err.span_suggestion(
|
err.span_suggestion_with_applicability(
|
||||||
// account for `let x: _ = 42;`
|
// account for `let x: _ = 42;`
|
||||||
// ^^^^
|
// ^^^^
|
||||||
span.to(ty.as_ref().map(|ty| ty.span)
|
span.to(ty.as_ref().map(|ty| ty.span)
|
||||||
.unwrap_or(span)),
|
.unwrap_or(span)),
|
||||||
&msg,
|
&msg,
|
||||||
format!("{}: {}", snippet, concrete_type),
|
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)
|
format!("use {};\n{}", self.tcx.item_path_str(*did), additional_newline)
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
err.span_suggestions(span, &msg, path_strings);
|
err.span_suggestions_with_applicability(
|
||||||
|
span,
|
||||||
|
&msg,
|
||||||
|
path_strings,
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
let limit = if candidates.len() == 5 { 5 } else { 4 };
|
let limit = if candidates.len() == 5 { 5 } else { 4 };
|
||||||
for (i, trait_did) in candidates.iter().take(limit).enumerate() {
|
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 base = self.tcx.hir.node_to_pretty_string(base.id);
|
||||||
let msg = format!("`{}` is a native pointer; try dereferencing it", base);
|
let msg = format!("`{}` is a native pointer; try dereferencing it", base);
|
||||||
let suggestion = format!("(*{}).{}", base, field);
|
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>,
|
found: Ty<'tcx>,
|
||||||
) {
|
) {
|
||||||
if let Some((sp, msg, suggestion)) = self.check_ref(expr, found, expected) {
|
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) {
|
} else if !self.check_for_cast(err, expr, found, expected) {
|
||||||
let methods = self.get_conversion_methods(expr.span, expected, found);
|
let methods = self.get_conversion_methods(expr.span, expected, found);
|
||||||
if let Ok(expr_text) = self.sess().source_map().span_to_snippet(expr.span) {
|
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<_>>();
|
}) .collect::<Vec<_>>();
|
||||||
if !suggestions.is_empty() {
|
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::TyKind::{Ref, Adt, Str, Uint, Never, Tuple, Char, Array};
|
||||||
use rustc::ty::adjustment::{Adjustment, Adjust, AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
|
use rustc::ty::adjustment::{Adjustment, Adjust, AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
|
||||||
use rustc::infer::type_variable::TypeVariableOrigin;
|
use rustc::infer::type_variable::TypeVariableOrigin;
|
||||||
use errors;
|
use errors::{self,Applicability};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
use syntax::ast::Ident;
|
use syntax::ast::Ident;
|
||||||
use rustc::hir;
|
use rustc::hir;
|
||||||
|
@ -444,9 +444,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
err.span_label(expr.span,
|
err.span_label(expr.span,
|
||||||
"`+` can't be used to concatenate two `&str` strings");
|
"`+` can't be used to concatenate two `&str` strings");
|
||||||
match source_map.span_to_snippet(lhs_expr.span) {
|
match source_map.span_to_snippet(lhs_expr.span) {
|
||||||
Ok(lstring) => err.span_suggestion(lhs_expr.span,
|
Ok(lstring) => err.span_suggestion_with_applicability(
|
||||||
msg,
|
lhs_expr.span,
|
||||||
format!("{}.to_owned()", lstring)),
|
msg,
|
||||||
|
format!("{}.to_owned()", lstring),
|
||||||
|
Applicability::MachineApplicable,
|
||||||
|
),
|
||||||
_ => err.help(msg),
|
_ => err.help(msg),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -462,10 +465,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
is_assign,
|
is_assign,
|
||||||
) {
|
) {
|
||||||
(Ok(l), Ok(r), false) => {
|
(Ok(l), Ok(r), false) => {
|
||||||
err.multipart_suggestion(msg, vec![
|
err.multipart_suggestion_with_applicability(
|
||||||
(lhs_expr.span, format!("{}.to_owned()", l)),
|
msg,
|
||||||
(rhs_expr.span, format!("&{}", r)),
|
vec![
|
||||||
]);
|
(lhs_expr.span, format!("{}.to_owned()", l)),
|
||||||
|
(rhs_expr.span, format!("&{}", r)),
|
||||||
|
],
|
||||||
|
Applicability::MachineApplicable,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
err.help(msg);
|
err.help(msg);
|
||||||
|
|
|
@ -16,6 +16,7 @@ use source_map::Spanned;
|
||||||
use edition::Edition;
|
use edition::Edition;
|
||||||
use parse::{token, ParseSess};
|
use parse::{token, ParseSess};
|
||||||
use OneVector;
|
use OneVector;
|
||||||
|
use errors::Applicability;
|
||||||
|
|
||||||
use ptr::P;
|
use ptr::P;
|
||||||
|
|
||||||
|
@ -123,7 +124,12 @@ impl<'a> StripUnconfigured<'a> {
|
||||||
let error = |span, msg, suggestion: &str| {
|
let error = |span, msg, suggestion: &str| {
|
||||||
let mut err = self.sess.span_diagnostic.struct_span_err(span, msg);
|
let mut err = self.sess.span_diagnostic.struct_span_err(span, msg);
|
||||||
if !suggestion.is_empty() {
|
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();
|
err.emit();
|
||||||
true
|
true
|
||||||
|
|
|
@ -32,6 +32,7 @@ use std::borrow::Cow;
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
|
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
|
use errors::Applicability;
|
||||||
|
|
||||||
pub struct ParserAnyMacro<'a> {
|
pub struct ParserAnyMacro<'a> {
|
||||||
parser: Parser<'a>,
|
parser: Parser<'a>,
|
||||||
|
@ -187,10 +188,11 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
|
||||||
if comma_span == DUMMY_SP {
|
if comma_span == DUMMY_SP {
|
||||||
err.note("you might be missing a comma");
|
err.note("you might be missing a comma");
|
||||||
} else {
|
} else {
|
||||||
err.span_suggestion_short(
|
err.span_suggestion_short_with_applicability(
|
||||||
comma_span,
|
comma_span,
|
||||||
"missing comma here",
|
"missing comma here",
|
||||||
", ".to_string(),
|
", ".to_string(),
|
||||||
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3882,7 +3882,12 @@ impl<'a> Parser<'a> {
|
||||||
if self.token == token::CloseDelim(token::Brace) {
|
if self.token == token::CloseDelim(token::Brace) {
|
||||||
// If the struct looks otherwise well formed, recover and continue.
|
// If the struct looks otherwise well formed, recover and continue.
|
||||||
if let Some(sp) = comma_sp {
|
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();
|
err.emit();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -996,9 +996,10 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if suggestions.len() > 0 {
|
if suggestions.len() > 0 {
|
||||||
diag.multipart_suggestion(
|
diag.multipart_suggestion_with_applicability(
|
||||||
"format specifiers use curly braces",
|
"format specifiers use curly braces",
|
||||||
suggestions,
|
suggestions,
|
||||||
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue