remove _with_applicability
from suggestion fns
This commit is contained in:
parent
8eaa84c79f
commit
0897ffc28f
53 changed files with 315 additions and 418 deletions
|
@ -1829,7 +1829,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
if let Ok(snippet) = self.sess.source_map().span_to_snippet(data.span) {
|
if let Ok(snippet) = self.sess.source_map().span_to_snippet(data.span) {
|
||||||
// Do not suggest going from `Trait()` to `Trait<>`
|
// Do not suggest going from `Trait()` to `Trait<>`
|
||||||
if data.inputs.len() > 0 {
|
if data.inputs.len() > 0 {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
data.span,
|
data.span,
|
||||||
"use angle brackets instead",
|
"use angle brackets instead",
|
||||||
format!("<{}>", &snippet[1..snippet.len() - 1]),
|
format!("<{}>", &snippet[1..snippet.len() - 1]),
|
||||||
|
|
|
@ -499,7 +499,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
if let Some(ty::error::ExpectedFound { found, .. }) = exp_found {
|
if let Some(ty::error::ExpectedFound { found, .. }) = exp_found {
|
||||||
if ty.is_box() && ty.boxed_ty() == found {
|
if ty.is_box() && ty.boxed_ty() == found {
|
||||||
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
|
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"consider dereferencing the boxed value",
|
"consider dereferencing the boxed value",
|
||||||
format!("*{}", snippet),
|
format!("*{}", snippet),
|
||||||
|
@ -532,7 +532,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
err.span_label(then, "expected because of this");
|
err.span_label(then, "expected because of this");
|
||||||
outer.map(|sp| err.span_label(sp, "if and else have incompatible types"));
|
outer.map(|sp| err.span_label(sp, "if and else have incompatible types"));
|
||||||
if let Some(sp) = semicolon {
|
if let Some(sp) = semicolon {
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
sp,
|
sp,
|
||||||
"consider removing this semicolon",
|
"consider removing this semicolon",
|
||||||
String::new(),
|
String::new(),
|
||||||
|
@ -1084,7 +1084,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
self.tcx.sess.source_map().span_to_snippet(span),
|
self.tcx.sess.source_map().span_to_snippet(span),
|
||||||
show_suggestion,
|
show_suggestion,
|
||||||
) {
|
) {
|
||||||
diag.span_suggestion_with_applicability(
|
diag.span_suggestion(
|
||||||
span,
|
span,
|
||||||
msg,
|
msg,
|
||||||
format!("{}.as_ref()", snippet),
|
format!("{}.as_ref()", snippet),
|
||||||
|
@ -1273,7 +1273,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
let tail = if has_lifetimes { " + " } else { "" };
|
let tail = if has_lifetimes { " + " } else { "" };
|
||||||
format!("{}: {}{}", bound_kind, sub, tail)
|
format!("{}: {}{}", bound_kind, sub, tail)
|
||||||
};
|
};
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
sp,
|
sp,
|
||||||
&consider,
|
&consider,
|
||||||
suggestion,
|
suggestion,
|
||||||
|
|
|
@ -102,7 +102,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
|
||||||
E0621,
|
E0621,
|
||||||
"explicit lifetime required in {}",
|
"explicit lifetime required in {}",
|
||||||
error_var
|
error_var
|
||||||
).span_suggestion_with_applicability(
|
).span_suggestion(
|
||||||
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(),
|
||||||
|
|
|
@ -53,7 +53,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_with_applicability(
|
err.span_suggestion(
|
||||||
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 \
|
||||||
|
|
|
@ -473,7 +473,7 @@ impl BuiltinLintDiagnostics {
|
||||||
Ok(s) => (format!("dyn {}", s), Applicability::MachineApplicable),
|
Ok(s) => (format!("dyn {}", s), Applicability::MachineApplicable),
|
||||||
Err(_) => ("dyn <type>".to_string(), Applicability::HasPlaceholders)
|
Err(_) => ("dyn <type>".to_string(), Applicability::HasPlaceholders)
|
||||||
};
|
};
|
||||||
db.span_suggestion_with_applicability(span, "use `dyn`", sugg, app);
|
db.span_suggestion(span, "use `dyn`", sugg, app);
|
||||||
}
|
}
|
||||||
BuiltinLintDiagnostics::AbsPathWithModule(span) => {
|
BuiltinLintDiagnostics::AbsPathWithModule(span) => {
|
||||||
let (sugg, app) = match sess.source_map().span_to_snippet(span) {
|
let (sugg, app) = match sess.source_map().span_to_snippet(span) {
|
||||||
|
@ -490,7 +490,7 @@ impl BuiltinLintDiagnostics {
|
||||||
}
|
}
|
||||||
Err(_) => ("crate::<path>".to_string(), Applicability::HasPlaceholders)
|
Err(_) => ("crate::<path>".to_string(), Applicability::HasPlaceholders)
|
||||||
};
|
};
|
||||||
db.span_suggestion_with_applicability(span, "use `crate`", sugg, app);
|
db.span_suggestion(span, "use `crate`", sugg, app);
|
||||||
}
|
}
|
||||||
BuiltinLintDiagnostics::DuplicatedMacroExports(ident, earlier_span, later_span) => {
|
BuiltinLintDiagnostics::DuplicatedMacroExports(ident, earlier_span, later_span) => {
|
||||||
db.span_label(later_span, format!("`{}` already exported", ident));
|
db.span_label(later_span, format!("`{}` already exported", ident));
|
||||||
|
@ -531,7 +531,7 @@ impl BuiltinLintDiagnostics {
|
||||||
(insertion_span, anon_lts)
|
(insertion_span, anon_lts)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
replace_span,
|
replace_span,
|
||||||
&format!("indicate the anonymous lifetime{}", if n >= 2 { "s" } else { "" }),
|
&format!("indicate the anonymous lifetime{}", if n >= 2 { "s" } else { "" }),
|
||||||
suggestion,
|
suggestion,
|
||||||
|
@ -539,12 +539,7 @@ impl BuiltinLintDiagnostics {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
BuiltinLintDiagnostics::UnknownCrateTypes(span, note, sugg) => {
|
BuiltinLintDiagnostics::UnknownCrateTypes(span, note, sugg) => {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(span, ¬e, sugg, Applicability::MaybeIncorrect);
|
||||||
span,
|
|
||||||
¬e,
|
|
||||||
sugg,
|
|
||||||
Applicability::MaybeIncorrect
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -324,7 +324,7 @@ impl<'a> LintLevelsBuilder<'a> {
|
||||||
Some(li.span.into()),
|
Some(li.span.into()),
|
||||||
&msg,
|
&msg,
|
||||||
);
|
);
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
li.span,
|
li.span,
|
||||||
"change it to",
|
"change it to",
|
||||||
new_lint_name.to_string(),
|
new_lint_name.to_string(),
|
||||||
|
@ -362,7 +362,7 @@ impl<'a> LintLevelsBuilder<'a> {
|
||||||
Some(li.span.into()),
|
Some(li.span.into()),
|
||||||
&msg);
|
&msg);
|
||||||
if let Some(new_name) = renamed {
|
if let Some(new_name) = renamed {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
li.span,
|
li.span,
|
||||||
"use the new name",
|
"use the new name",
|
||||||
new_name,
|
new_name,
|
||||||
|
@ -386,7 +386,7 @@ impl<'a> LintLevelsBuilder<'a> {
|
||||||
&msg);
|
&msg);
|
||||||
|
|
||||||
if let Some(suggestion) = suggestion {
|
if let Some(suggestion) = suggestion {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
li.span,
|
li.span,
|
||||||
"did you mean",
|
"did you mean",
|
||||||
suggestion.to_string(),
|
suggestion.to_string(),
|
||||||
|
|
|
@ -1600,12 +1600,16 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||||
let mut err = self.ir.tcx
|
let mut err = self.ir.tcx
|
||||||
.struct_span_lint_hir(lint::builtin::UNUSED_VARIABLES, hir_id, sp, &msg);
|
.struct_span_lint_hir(lint::builtin::UNUSED_VARIABLES, hir_id, sp, &msg);
|
||||||
if self.ir.variable_is_shorthand(var) {
|
if self.ir.variable_is_shorthand(var) {
|
||||||
err.span_suggestion_with_applicability(sp, "try ignoring the field",
|
err.span_suggestion(
|
||||||
format!("{}: _", name),
|
sp,
|
||||||
Applicability::MachineApplicable);
|
"try ignoring the field",
|
||||||
|
format!("{}: _", name),
|
||||||
|
Applicability::MachineApplicable,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
sp, &suggest_underscore_msg,
|
sp,
|
||||||
|
&suggest_underscore_msg,
|
||||||
format!("_{}", name),
|
format!("_{}", name),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1526,14 +1526,14 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||||
// place ("start at" because the latter includes trailing
|
// place ("start at" because the latter includes trailing
|
||||||
// whitespace), then this is an in-band lifetime
|
// whitespace), then this is an in-band lifetime
|
||||||
if decl_span.shrink_to_lo() == use_span.shrink_to_lo() {
|
if decl_span.shrink_to_lo() == use_span.shrink_to_lo() {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
use_span,
|
use_span,
|
||||||
"elide the single-use lifetime",
|
"elide the single-use lifetime",
|
||||||
String::new(),
|
String::new(),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
err.multipart_suggestion_with_applicability(
|
err.multipart_suggestion(
|
||||||
"elide the single-use lifetime",
|
"elide the single-use lifetime",
|
||||||
vec![(decl_span, String::new()), (use_span, String::new())],
|
vec![(decl_span, String::new()), (use_span, String::new())],
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
|
@ -1644,7 +1644,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||||
if let Some(generics) = self.tcx.hir().get_generics(parent_def_id) {
|
if let Some(generics) = self.tcx.hir().get_generics(parent_def_id) {
|
||||||
let unused_lt_span = self.lifetime_deletion_span(name, generics);
|
let unused_lt_span = self.lifetime_deletion_span(name, generics);
|
||||||
if let Some(span) = unused_lt_span {
|
if let Some(span) = unused_lt_span {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"elide the unused lifetime",
|
"elide the unused lifetime",
|
||||||
String::new(),
|
String::new(),
|
||||||
|
@ -2350,7 +2350,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||||
} else {
|
} else {
|
||||||
(format!("{} + 'static", snippet), Applicability::MaybeIncorrect)
|
(format!("{} + 'static", snippet), Applicability::MaybeIncorrect)
|
||||||
};
|
};
|
||||||
db.span_suggestion_with_applicability(span, msg, sugg, applicability);
|
db.span_suggestion(span, msg, sugg, applicability);
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
|
|
|
@ -435,7 +435,7 @@ impl Session {
|
||||||
}
|
}
|
||||||
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_with_applicability(
|
diag_builder.span_suggestion(
|
||||||
span,
|
span,
|
||||||
message,
|
message,
|
||||||
suggestion,
|
suggestion,
|
||||||
|
|
|
@ -904,7 +904,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
if let Some(ref expr) = local.init {
|
if let Some(ref expr) = local.init {
|
||||||
if let hir::ExprKind::Index(_, _) = expr.node {
|
if let hir::ExprKind::Index(_, _) = expr.node {
|
||||||
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(expr.span) {
|
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(expr.span) {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
"consider borrowing here",
|
"consider borrowing here",
|
||||||
format!("&{}", snippet),
|
format!("&{}", snippet),
|
||||||
|
@ -952,7 +952,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
let format_str = format!("consider removing {} leading `&`-references",
|
let format_str = format!("consider removing {} leading `&`-references",
|
||||||
remove_refs);
|
remove_refs);
|
||||||
|
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
sp, &format_str, String::new(), Applicability::MachineApplicable
|
sp, &format_str, String::new(), Applicability::MachineApplicable
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
@ -1109,7 +1109,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
// For example, if `expected_args_length` is 2, suggest `|_, _|`.
|
// For example, if `expected_args_length` is 2, suggest `|_, _|`.
|
||||||
if found_args.is_empty() && is_closure {
|
if found_args.is_empty() && is_closure {
|
||||||
let underscores = vec!["_"; expected_args.len()].join(", ");
|
let underscores = vec!["_"; expected_args.len()].join(", ");
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
pipe_span,
|
pipe_span,
|
||||||
&format!(
|
&format!(
|
||||||
"consider changing the closure to take and ignore the expected argument{}",
|
"consider changing the closure to take and ignore the expected argument{}",
|
||||||
|
@ -1130,11 +1130,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
.map(|(name, _)| name.to_owned())
|
.map(|(name, _)| name.to_owned())
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join(", ");
|
.join(", ");
|
||||||
err.span_suggestion_with_applicability(found_span,
|
err.span_suggestion(
|
||||||
"change the closure to take multiple \
|
found_span,
|
||||||
arguments instead of a single tuple",
|
"change the closure to take multiple arguments instead of a single tuple",
|
||||||
format!("|{}|", sugg),
|
format!("|{}|", sugg),
|
||||||
Applicability::MachineApplicable);
|
Applicability::MachineApplicable,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let &[ArgKind::Tuple(_, ref fields)] = &expected_args[..] {
|
if let &[ArgKind::Tuple(_, ref fields)] = &expected_args[..] {
|
||||||
|
@ -1162,12 +1163,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
String::new()
|
String::new()
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
found_span,
|
found_span,
|
||||||
"change the closure to accept a tuple instead of \
|
"change the closure to accept a tuple instead of individual arguments",
|
||||||
individual arguments",
|
|
||||||
sugg,
|
sugg,
|
||||||
Applicability::MachineApplicable
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,7 +237,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||||
{
|
{
|
||||||
if let Ok(snippet) = self.sess.source_map().span_to_snippet(sp) {
|
if let Ok(snippet) = self.sess.source_map().span_to_snippet(sp) {
|
||||||
if snippet.chars().all(|c| c.is_digit(10) || c == '-' || c == '_') {
|
if snippet.chars().all(|c| c.is_digit(10) || c == '-' || c == '_') {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
sp,
|
sp,
|
||||||
"use a float literal",
|
"use a float literal",
|
||||||
format!("{}.0", snippet),
|
format!("{}.0", snippet),
|
||||||
|
|
|
@ -70,7 +70,7 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, errors: &[MoveErr
|
||||||
let initializer =
|
let initializer =
|
||||||
e.init.as_ref().expect("should have an initializer to get an error");
|
e.init.as_ref().expect("should have an initializer to get an error");
|
||||||
if let Ok(snippet) = bccx.tcx.sess.source_map().span_to_snippet(initializer.span) {
|
if let Ok(snippet) = bccx.tcx.sess.source_map().span_to_snippet(initializer.span) {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
initializer.span,
|
initializer.span,
|
||||||
"consider using a reference instead",
|
"consider using a reference instead",
|
||||||
format!("&{}", snippet),
|
format!("&{}", snippet),
|
||||||
|
|
|
@ -850,7 +850,7 @@ 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_with_applicability(
|
db.span_suggestion(
|
||||||
sp,
|
sp,
|
||||||
msg,
|
msg,
|
||||||
suggestion,
|
suggestion,
|
||||||
|
@ -858,7 +858,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
sp,
|
sp,
|
||||||
msg,
|
msg,
|
||||||
suggestion,
|
suggestion,
|
||||||
|
@ -1229,7 +1229,7 @@ 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_with_applicability(
|
db.span_suggestion(
|
||||||
let_span,
|
let_span,
|
||||||
"use a mutable reference instead",
|
"use a mutable reference instead",
|
||||||
replace_str,
|
replace_str,
|
||||||
|
@ -1291,7 +1291,7 @@ 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_with_applicability(
|
db.span_suggestion(
|
||||||
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",
|
||||||
|
@ -1299,7 +1299,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
let_span,
|
let_span,
|
||||||
"make this binding mutable",
|
"make this binding mutable",
|
||||||
format!("mut {}", snippet),
|
format!("mut {}", snippet),
|
||||||
|
@ -1326,7 +1326,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
||||||
&cmt_path_or_string,
|
&cmt_path_or_string,
|
||||||
capture_span,
|
capture_span,
|
||||||
Origin::Ast)
|
Origin::Ast)
|
||||||
.span_suggestion_with_applicability(
|
.span_suggestion(
|
||||||
err.span,
|
err.span,
|
||||||
&format!("to force the closure to take ownership of {} \
|
&format!("to force the closure to take ownership of {} \
|
||||||
(and any other referenced variables), \
|
(and any other referenced variables), \
|
||||||
|
|
|
@ -78,11 +78,12 @@ impl<'a, 'tcx> UnusedMutCx<'a, 'tcx> {
|
||||||
hir_id,
|
hir_id,
|
||||||
span,
|
span,
|
||||||
"variable does not need to be mutable")
|
"variable does not need to be mutable")
|
||||||
.span_suggestion_short_with_applicability(
|
.span_suggestion_short(
|
||||||
mut_span,
|
mut_span,
|
||||||
"remove this `mut`",
|
"remove this `mut`",
|
||||||
String::new(),
|
String::new(),
|
||||||
Applicability::MachineApplicable)
|
Applicability::MachineApplicable,
|
||||||
|
)
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,59 +229,7 @@ impl Diagnostic {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prints out a message with a suggested edit of the code. If the suggestion is presented
|
pub fn multipart_suggestion(
|
||||||
/// 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 {
|
|
||||||
parts: vec![SubstitutionPart {
|
|
||||||
snippet: suggestion,
|
|
||||||
span: sp,
|
|
||||||
}],
|
|
||||||
}],
|
|
||||||
msg: msg.to_owned(),
|
|
||||||
show_code_when_inline: false,
|
|
||||||
applicability: Applicability::Unspecified,
|
|
||||||
});
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Prints out a message with a suggested edit of the code.
|
|
||||||
///
|
|
||||||
/// In case of short messages and a simple suggestion,
|
|
||||||
/// rustc displays it as a label like
|
|
||||||
///
|
|
||||||
/// "try adding parentheses: `(tup.0).1`"
|
|
||||||
///
|
|
||||||
/// The message
|
|
||||||
///
|
|
||||||
/// * should not end in any punctuation (a `:` is added automatically)
|
|
||||||
/// * should not be a question
|
|
||||||
/// * should not contain any parts like "the following", "as shown"
|
|
||||||
/// * may look like "to do xyz, use" or "to do xyz, use abc"
|
|
||||||
/// * 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 {
|
|
||||||
parts: vec![SubstitutionPart {
|
|
||||||
snippet: suggestion,
|
|
||||||
span: sp,
|
|
||||||
}],
|
|
||||||
}],
|
|
||||||
msg: msg.to_owned(),
|
|
||||||
show_code_when_inline: true,
|
|
||||||
applicability: Applicability::Unspecified,
|
|
||||||
});
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn multipart_suggestion_with_applicability(
|
|
||||||
&mut self,
|
&mut self,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
suggestion: Vec<(Span, String)>,
|
suggestion: Vec<(Span, String)>,
|
||||||
|
@ -301,39 +249,24 @@ impl Diagnostic {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deprecated(note = "Use `multipart_suggestion_with_applicability`")]
|
/// Prints out a message with a suggested edit of the code.
|
||||||
pub fn multipart_suggestion(
|
///
|
||||||
&mut self,
|
/// In case of short messages and a simple suggestion, rustc displays it as a label:
|
||||||
msg: &str,
|
///
|
||||||
suggestion: Vec<(Span, String)>,
|
/// ```text
|
||||||
) -> &mut Self {
|
/// try adding parentheses: `(tup.0).1`
|
||||||
self.multipart_suggestion_with_applicability(
|
/// ```
|
||||||
msg,
|
///
|
||||||
suggestion,
|
/// The message
|
||||||
Applicability::Unspecified,
|
///
|
||||||
)
|
/// * should not end in any punctuation (a `:` is added automatically)
|
||||||
}
|
/// * should not be a question (avoid language like "did you mean")
|
||||||
|
/// * should not contain any phrases like "the following", "as shown", etc.
|
||||||
/// Prints out a message with multiple suggested edits of the code.
|
/// * may look like "to do xyz, use" or "to do xyz, use abc"
|
||||||
#[deprecated(note = "Use `span_suggestions_with_applicability`")]
|
/// * may contain a name of a function, variable, or type, but not whole expressions
|
||||||
pub fn span_suggestions(&mut self, sp: Span, msg: &str, suggestions: Vec<String>) -> &mut Self {
|
///
|
||||||
self.suggestions.push(CodeSuggestion {
|
/// See `CodeSuggestion` for more information.
|
||||||
substitutions: suggestions.into_iter().map(|snippet| Substitution {
|
pub fn span_suggestion(&mut self, sp: Span, msg: &str,
|
||||||
parts: vec![SubstitutionPart {
|
|
||||||
snippet,
|
|
||||||
span: sp,
|
|
||||||
}],
|
|
||||||
}).collect(),
|
|
||||||
msg: msg.to_owned(),
|
|
||||||
show_code_when_inline: true,
|
|
||||||
applicability: Applicability::Unspecified,
|
|
||||||
});
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This is a suggestion that may contain mistakes or fillers and should
|
|
||||||
/// be read and understood by a human.
|
|
||||||
pub fn span_suggestion_with_applicability(&mut self, sp: Span, msg: &str,
|
|
||||||
suggestion: String,
|
suggestion: String,
|
||||||
applicability: Applicability) -> &mut Self {
|
applicability: Applicability) -> &mut Self {
|
||||||
self.suggestions.push(CodeSuggestion {
|
self.suggestions.push(CodeSuggestion {
|
||||||
|
@ -350,7 +283,8 @@ impl Diagnostic {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn span_suggestions_with_applicability(&mut self, sp: Span, msg: &str,
|
/// Prints out a message with multiple suggested edits of the code.
|
||||||
|
pub fn span_suggestions(&mut self, sp: Span, msg: &str,
|
||||||
suggestions: impl Iterator<Item = String>, applicability: Applicability) -> &mut Self
|
suggestions: impl Iterator<Item = String>, applicability: Applicability) -> &mut Self
|
||||||
{
|
{
|
||||||
self.suggestions.push(CodeSuggestion {
|
self.suggestions.push(CodeSuggestion {
|
||||||
|
@ -367,7 +301,11 @@ impl Diagnostic {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn span_suggestion_short_with_applicability(
|
/// Prints out a message with a suggested edit of the code. If the suggestion is presented
|
||||||
|
/// inline, it will only show the message and not the suggestion.
|
||||||
|
///
|
||||||
|
/// See `CodeSuggestion` for more information.
|
||||||
|
pub fn span_suggestion_short(
|
||||||
&mut self, sp: Span, msg: &str, suggestion: String, applicability: Applicability
|
&mut self, sp: Span, msg: &str, suggestion: String, applicability: Applicability
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
self.suggestions.push(CodeSuggestion {
|
self.suggestions.push(CodeSuggestion {
|
||||||
|
|
|
@ -39,7 +39,6 @@ macro_rules! forward {
|
||||||
) => {
|
) => {
|
||||||
$(#[$attrs])*
|
$(#[$attrs])*
|
||||||
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
|
||||||
}
|
}
|
||||||
|
@ -52,7 +51,6 @@ macro_rules! forward {
|
||||||
) => {
|
) => {
|
||||||
$(#[$attrs])*
|
$(#[$attrs])*
|
||||||
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
|
||||||
}
|
}
|
||||||
|
@ -70,7 +68,6 @@ macro_rules! forward {
|
||||||
) => {
|
) => {
|
||||||
$(#[$attrs])*
|
$(#[$attrs])*
|
||||||
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
|
||||||
}
|
}
|
||||||
|
@ -190,53 +187,16 @@ impl<'a> DiagnosticBuilder<'a> {
|
||||||
msg: &str,
|
msg: &str,
|
||||||
) -> &mut Self);
|
) -> &mut Self);
|
||||||
|
|
||||||
forward!(
|
pub fn multipart_suggestion(
|
||||||
#[deprecated(note = "Use `span_suggestion_short_with_applicability`")]
|
&mut self,
|
||||||
pub fn span_suggestion_short(
|
msg: &str,
|
||||||
&mut self,
|
suggestion: Vec<(Span, String)>,
|
||||||
sp: Span,
|
applicability: Applicability,
|
||||||
msg: &str,
|
) -> &mut Self {
|
||||||
suggestion: String,
|
|
||||||
) -> &mut Self
|
|
||||||
);
|
|
||||||
|
|
||||||
forward!(
|
|
||||||
#[deprecated(note = "Use `multipart_suggestion_with_applicability`")]
|
|
||||||
pub fn multipart_suggestion(
|
|
||||||
&mut self,
|
|
||||||
msg: &str,
|
|
||||||
suggestion: Vec<(Span, String)>,
|
|
||||||
) -> &mut Self
|
|
||||||
);
|
|
||||||
|
|
||||||
forward!(
|
|
||||||
#[deprecated(note = "Use `span_suggestion_with_applicability`")]
|
|
||||||
pub fn span_suggestion(
|
|
||||||
&mut self,
|
|
||||||
sp: Span,
|
|
||||||
msg: &str,
|
|
||||||
suggestion: String,
|
|
||||||
) -> &mut Self
|
|
||||||
);
|
|
||||||
|
|
||||||
forward!(
|
|
||||||
#[deprecated(note = "Use `span_suggestions_with_applicability`")]
|
|
||||||
pub fn span_suggestions(&mut self,
|
|
||||||
sp: Span,
|
|
||||||
msg: &str,
|
|
||||||
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 {
|
if !self.allow_suggestions {
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
self.diagnostic.multipart_suggestion_with_applicability(
|
self.diagnostic.multipart_suggestion(
|
||||||
msg,
|
msg,
|
||||||
suggestion,
|
suggestion,
|
||||||
applicability,
|
applicability,
|
||||||
|
@ -244,16 +204,17 @@ impl<'a> DiagnosticBuilder<'a> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn span_suggestion_with_applicability(&mut self,
|
pub fn span_suggestion(
|
||||||
sp: Span,
|
&mut self,
|
||||||
msg: &str,
|
sp: Span,
|
||||||
suggestion: String,
|
msg: &str,
|
||||||
applicability: Applicability)
|
suggestion: String,
|
||||||
-> &mut Self {
|
applicability: Applicability,
|
||||||
|
) -> &mut Self {
|
||||||
if !self.allow_suggestions {
|
if !self.allow_suggestions {
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
self.diagnostic.span_suggestion_with_applicability(
|
self.diagnostic.span_suggestion(
|
||||||
sp,
|
sp,
|
||||||
msg,
|
msg,
|
||||||
suggestion,
|
suggestion,
|
||||||
|
@ -262,16 +223,17 @@ impl<'a> DiagnosticBuilder<'a> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn span_suggestions_with_applicability(&mut self,
|
pub fn span_suggestions(
|
||||||
sp: Span,
|
&mut self,
|
||||||
msg: &str,
|
sp: Span,
|
||||||
suggestions: impl Iterator<Item = String>,
|
msg: &str,
|
||||||
applicability: Applicability)
|
suggestions: impl Iterator<Item = String>,
|
||||||
-> &mut Self {
|
applicability: Applicability,
|
||||||
|
) -> &mut Self {
|
||||||
if !self.allow_suggestions {
|
if !self.allow_suggestions {
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
self.diagnostic.span_suggestions_with_applicability(
|
self.diagnostic.span_suggestions(
|
||||||
sp,
|
sp,
|
||||||
msg,
|
msg,
|
||||||
suggestions,
|
suggestions,
|
||||||
|
@ -280,16 +242,17 @@ impl<'a> DiagnosticBuilder<'a> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn span_suggestion_short_with_applicability(&mut self,
|
pub fn span_suggestion_short(
|
||||||
sp: Span,
|
&mut self,
|
||||||
msg: &str,
|
sp: Span,
|
||||||
suggestion: String,
|
msg: &str,
|
||||||
applicability: Applicability)
|
suggestion: String,
|
||||||
-> &mut Self {
|
applicability: Applicability,
|
||||||
|
) -> &mut Self {
|
||||||
if !self.allow_suggestions {
|
if !self.allow_suggestions {
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
self.diagnostic.span_suggestion_short_with_applicability(
|
self.diagnostic.span_suggestion_short(
|
||||||
sp,
|
sp,
|
||||||
msg,
|
msg,
|
||||||
suggestion,
|
suggestion,
|
||||||
|
|
|
@ -78,7 +78,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for WhileTrue {
|
||||||
let msg = "denote infinite loops with `loop { ... }`";
|
let msg = "denote infinite loops with `loop { ... }`";
|
||||||
let condition_span = cx.tcx.sess.source_map().def_span(e.span);
|
let condition_span = cx.tcx.sess.source_map().def_span(e.span);
|
||||||
let mut err = cx.struct_span_lint(WHILE_TRUE, condition_span, msg);
|
let mut err = cx.struct_span_lint(WHILE_TRUE, condition_span, msg);
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
condition_span,
|
condition_span,
|
||||||
"use `loop`",
|
"use `loop`",
|
||||||
"loop".to_owned(),
|
"loop".to_owned(),
|
||||||
|
@ -199,7 +199,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {
|
||||||
&format!("the `{}:` in this pattern is redundant", ident));
|
&format!("the `{}:` in this pattern is redundant", ident));
|
||||||
let subspan = cx.tcx.sess.source_map().span_through_char(fieldpat.span,
|
let subspan = cx.tcx.sess.source_map().span_through_char(fieldpat.span,
|
||||||
':');
|
':');
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
subspan,
|
subspan,
|
||||||
"remove this",
|
"remove this",
|
||||||
ident.to_string(),
|
ident.to_string(),
|
||||||
|
@ -704,7 +704,7 @@ impl EarlyLintPass for AnonymousParameters {
|
||||||
arg.pat.span,
|
arg.pat.span,
|
||||||
"anonymous parameters are deprecated and will be \
|
"anonymous parameters are deprecated and will be \
|
||||||
removed in the next edition."
|
removed in the next edition."
|
||||||
).span_suggestion_with_applicability(
|
).span_suggestion(
|
||||||
arg.pat.span,
|
arg.pat.span,
|
||||||
"Try naming the parameter or explicitly \
|
"Try naming the parameter or explicitly \
|
||||||
ignoring it",
|
ignoring it",
|
||||||
|
@ -759,7 +759,7 @@ impl EarlyLintPass for DeprecatedAttr {
|
||||||
let msg = format!("use of deprecated attribute `{}`: {}. See {}",
|
let msg = format!("use of deprecated attribute `{}`: {}. See {}",
|
||||||
name, reason, link);
|
name, reason, link);
|
||||||
let mut err = cx.struct_span_lint(DEPRECATED, attr.span, &msg);
|
let mut err = cx.struct_span_lint(DEPRECATED, attr.span, &msg);
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
attr.span,
|
attr.span,
|
||||||
suggestion.unwrap_or("remove this attribute"),
|
suggestion.unwrap_or("remove this attribute"),
|
||||||
String::new(),
|
String::new(),
|
||||||
|
@ -906,7 +906,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {
|
||||||
it.span,
|
it.span,
|
||||||
"functions generic over \
|
"functions generic over \
|
||||||
types must be mangled");
|
types must be mangled");
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
no_mangle_attr.span,
|
no_mangle_attr.span,
|
||||||
"remove this attribute",
|
"remove this attribute",
|
||||||
String::new(),
|
String::new(),
|
||||||
|
@ -934,7 +934,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {
|
||||||
.unwrap_or(0) as u32;
|
.unwrap_or(0) as u32;
|
||||||
// `const` is 5 chars
|
// `const` is 5 chars
|
||||||
let const_span = it.span.with_hi(BytePos(it.span.lo().0 + start + 5));
|
let const_span = it.span.with_hi(BytePos(it.span.lo().0 + start + 5));
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
const_span,
|
const_span,
|
||||||
"try a static value",
|
"try a static value",
|
||||||
"pub static".to_owned(),
|
"pub static".to_owned(),
|
||||||
|
@ -1116,10 +1116,12 @@ impl UnreachablePub {
|
||||||
"pub(crate)"
|
"pub(crate)"
|
||||||
}.to_owned();
|
}.to_owned();
|
||||||
|
|
||||||
err.span_suggestion_with_applicability(vis.span,
|
err.span_suggestion(
|
||||||
"consider restricting its visibility",
|
vis.span,
|
||||||
replacement,
|
"consider restricting its visibility",
|
||||||
applicability);
|
replacement,
|
||||||
|
applicability,
|
||||||
|
);
|
||||||
if exportable {
|
if exportable {
|
||||||
err.help("or consider exporting it for use by other crates");
|
err.help("or consider exporting it for use by other crates");
|
||||||
}
|
}
|
||||||
|
@ -1452,7 +1454,7 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
|
||||||
if parenthesise {
|
if parenthesise {
|
||||||
*visit_subpats = false;
|
*visit_subpats = false;
|
||||||
let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, pat.span, msg);
|
let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, pat.span, msg);
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
pat.span,
|
pat.span,
|
||||||
suggestion,
|
suggestion,
|
||||||
format!("&({}..={})", expr_to_string(&start), expr_to_string(&end)),
|
format!("&({}..={})", expr_to_string(&start), expr_to_string(&end)),
|
||||||
|
@ -1461,7 +1463,7 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
|
||||||
err.emit();
|
err.emit();
|
||||||
} else {
|
} else {
|
||||||
let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, join, msg);
|
let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, join, msg);
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
join,
|
join,
|
||||||
suggestion,
|
suggestion,
|
||||||
"..=".to_owned(),
|
"..=".to_owned(),
|
||||||
|
@ -1613,7 +1615,7 @@ impl EarlyLintPass for KeywordIdents {
|
||||||
E0721,
|
E0721,
|
||||||
"`await` is a keyword in the {} edition", cur_edition,
|
"`await` is a keyword in the {} edition", cur_edition,
|
||||||
);
|
);
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
ident.span,
|
ident.span,
|
||||||
"you can use a raw identifier to stay compatible",
|
"you can use a raw identifier to stay compatible",
|
||||||
"r#await".to_string(),
|
"r#await".to_string(),
|
||||||
|
@ -1637,7 +1639,7 @@ impl EarlyLintPass for KeywordIdents {
|
||||||
ident.as_str(),
|
ident.as_str(),
|
||||||
next_edition),
|
next_edition),
|
||||||
);
|
);
|
||||||
lint.span_suggestion_with_applicability(
|
lint.span_suggestion(
|
||||||
ident.span,
|
ident.span,
|
||||||
"you can use a raw identifier to stay compatible",
|
"you can use a raw identifier to stay compatible",
|
||||||
format!("r#{}", ident.as_str()),
|
format!("r#{}", ident.as_str()),
|
||||||
|
@ -1865,7 +1867,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitOutlivesRequirements {
|
||||||
lint_spans.clone(),
|
lint_spans.clone(),
|
||||||
"outlives requirements can be inferred"
|
"outlives requirements can be inferred"
|
||||||
);
|
);
|
||||||
err.multipart_suggestion_with_applicability(
|
err.multipart_suggestion(
|
||||||
if bound_count == 1 {
|
if bound_count == 1 {
|
||||||
"remove this bound"
|
"remove this bound"
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -93,7 +93,7 @@ impl NonCamelCaseTypes {
|
||||||
|
|
||||||
let msg = format!("{} `{}` should have a camel case name", sort, name);
|
let msg = format!("{} `{}` should have a camel case name", sort, name);
|
||||||
cx.struct_span_lint(NON_CAMEL_CASE_TYPES, ident.span, &msg)
|
cx.struct_span_lint(NON_CAMEL_CASE_TYPES, ident.span, &msg)
|
||||||
.span_suggestion_with_applicability(
|
.span_suggestion(
|
||||||
ident.span,
|
ident.span,
|
||||||
"convert the identifier to camel case",
|
"convert the identifier to camel case",
|
||||||
c,
|
c,
|
||||||
|
@ -223,7 +223,7 @@ impl NonSnakeCase {
|
||||||
// We have a valid span in almost all cases, but we don't have one when linting a crate
|
// We have a valid span in almost all cases, but we don't have one when linting a crate
|
||||||
// name provided via the command line.
|
// name provided via the command line.
|
||||||
if !ident.span.is_dummy() {
|
if !ident.span.is_dummy() {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
ident.span,
|
ident.span,
|
||||||
"convert the identifier to snake case",
|
"convert the identifier to snake case",
|
||||||
sc,
|
sc,
|
||||||
|
@ -377,7 +377,7 @@ impl NonUpperCaseGlobals {
|
||||||
|
|
||||||
let msg = format!("{} `{}` should have an upper case name", sort, name);
|
let msg = format!("{} `{}` should have an upper case name", sort, name);
|
||||||
cx.struct_span_lint(NON_UPPER_CASE_GLOBALS, ident.span, &msg)
|
cx.struct_span_lint(NON_UPPER_CASE_GLOBALS, ident.span, &msg)
|
||||||
.span_suggestion_with_applicability(
|
.span_suggestion(
|
||||||
ident.span,
|
ident.span,
|
||||||
"convert the identifier to upper case",
|
"convert the identifier to upper case",
|
||||||
uc,
|
uc,
|
||||||
|
|
|
@ -143,7 +143,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
|
||||||
OVERFLOWING_LITERALS,
|
OVERFLOWING_LITERALS,
|
||||||
parent_expr.span,
|
parent_expr.span,
|
||||||
"only u8 can be cast into char");
|
"only u8 can be cast into char");
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
parent_expr.span,
|
parent_expr.span,
|
||||||
&"use a char literal instead",
|
&"use a char literal instead",
|
||||||
format!("'\\u{{{:X}}}'", lit_val),
|
format!("'\\u{{{:X}}}'", lit_val),
|
||||||
|
@ -401,7 +401,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
|
||||||
{
|
{
|
||||||
if let Some(pos) = repr_str.chars().position(|c| c == 'i' || c == 'u') {
|
if let Some(pos) = repr_str.chars().position(|c| c == 'i' || c == 'u') {
|
||||||
let (sans_suffix, _) = repr_str.split_at(pos);
|
let (sans_suffix, _) = repr_str.split_at(pos);
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("consider using `{}` instead", sugg_ty),
|
&format!("consider using `{}` instead", sugg_ty),
|
||||||
format!("{}{}", sans_suffix, sugg_ty),
|
format!("{}{}", sans_suffix, sugg_ty),
|
||||||
|
|
|
@ -366,12 +366,12 @@ impl UnusedParens {
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}).to_owned();
|
}).to_owned();
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
span,
|
span,
|
||||||
"remove these parentheses",
|
"remove these parentheses",
|
||||||
parens_removed,
|
parens_removed,
|
||||||
Applicability::MachineApplicable
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
err.emit();
|
err.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1139,7 +1139,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
||||||
Err(_) => "move |<args>| <body>".to_string()
|
Err(_) => "move |<args>| <body>".to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
args_span,
|
args_span,
|
||||||
&format!("to force the closure to take ownership of {} (and any \
|
&format!("to force the closure to take ownership of {} (and any \
|
||||||
other referenced variables), use the `move` keyword",
|
other referenced variables), use the `move` keyword",
|
||||||
|
@ -1428,7 +1428,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
||||||
if let Some(decl) = local_decl {
|
if let Some(decl) = local_decl {
|
||||||
if let Some(name) = decl.name {
|
if let Some(name) = decl.name {
|
||||||
if decl.can_be_made_mutable() {
|
if decl.can_be_made_mutable() {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
decl.source_info.span,
|
decl.source_info.span,
|
||||||
"make this binding mutable",
|
"make this binding mutable",
|
||||||
format!("mut {}", name),
|
format!("mut {}", name),
|
||||||
|
|
|
@ -307,7 +307,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
|
||||||
span,
|
span,
|
||||||
"variable does not need to be mutable",
|
"variable does not need to be mutable",
|
||||||
)
|
)
|
||||||
.span_suggestion_short_with_applicability(
|
.span_suggestion_short(
|
||||||
mut_span,
|
mut_span,
|
||||||
"remove this `mut`",
|
"remove this `mut`",
|
||||||
String::new(),
|
String::new(),
|
||||||
|
|
|
@ -368,14 +368,14 @@ 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_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"consider removing the `*`",
|
"consider removing the `*`",
|
||||||
snippet[1..].to_owned(),
|
snippet[1..].to_owned(),
|
||||||
Applicability::Unspecified,
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"consider borrowing here",
|
"consider borrowing here",
|
||||||
format!("&{}", snippet),
|
format!("&{}", snippet),
|
||||||
|
@ -439,7 +439,7 @@ 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_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
&format!("consider removing the `{}`", to_remove),
|
&format!("consider removing the `{}`", to_remove),
|
||||||
suggestion,
|
suggestion,
|
||||||
|
|
|
@ -231,7 +231,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
|
||||||
base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx),
|
base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx),
|
||||||
field,
|
field,
|
||||||
) {
|
) {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"consider changing this to be mutable",
|
"consider changing this to be mutable",
|
||||||
message,
|
message,
|
||||||
|
@ -285,7 +285,7 @@ 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_with_applicability(
|
err.span_suggestion(
|
||||||
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()),
|
||||||
|
@ -316,7 +316,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
|
||||||
_,
|
_,
|
||||||
) = pat.node
|
) = pat.node
|
||||||
{
|
{
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
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),
|
||||||
|
@ -410,7 +410,7 @@ 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_with_applicability(
|
err.span_suggestion(
|
||||||
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,
|
||||||
|
|
|
@ -626,7 +626,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
"'_".to_string()
|
"'_".to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
diag.span_suggestion_with_applicability(
|
diag.span_suggestion(
|
||||||
span,
|
span,
|
||||||
&format!(
|
&format!(
|
||||||
"to allow this impl Trait to capture borrowed data with lifetime \
|
"to allow this impl Trait to capture borrowed data with lifetime \
|
||||||
|
|
|
@ -313,7 +313,7 @@ fn check_for_bindings_named_same_as_variants(cx: &MatchVisitor, pat: &Pat) {
|
||||||
"pattern binding `{}` is named the same as one \
|
"pattern binding `{}` is named the same as one \
|
||||||
of the variants of the type `{}`",
|
of the variants of the type `{}`",
|
||||||
ident, ty_path);
|
ident, ty_path);
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
p.span,
|
p.span,
|
||||||
"to match on the variant, qualify the path",
|
"to match on the variant, qualify the path",
|
||||||
format!("{}::{}", ty_path, ident),
|
format!("{}::{}", ty_path, ident),
|
||||||
|
|
|
@ -237,7 +237,7 @@ 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_with_applicability(
|
err.span_suggestion(
|
||||||
span, "consider adding parentheses", format!("({})", snippet),
|
span, "consider adding parentheses", format!("({})", snippet),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
|
@ -290,7 +290,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||||
);
|
);
|
||||||
match val.node {
|
match val.node {
|
||||||
ExprKind::Lit(ref v) if v.node.is_numeric() => {
|
ExprKind::Lit(ref v) if v.node.is_numeric() => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
place.span.between(val.span),
|
place.span.between(val.span),
|
||||||
"if you meant to write a comparison against a negative value, add a \
|
"if you meant to write a comparison against a negative value, add a \
|
||||||
space in between `<` and `-`",
|
space in between `<` and `-`",
|
||||||
|
|
|
@ -140,7 +140,7 @@ 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_with_applicability(
|
.span_suggestion(
|
||||||
e.span,
|
e.span,
|
||||||
&format!(
|
&format!(
|
||||||
"instead, use `break` on its own \
|
"instead, use `break` on its own \
|
||||||
|
|
|
@ -347,7 +347,7 @@ impl<'a> Resolver<'a> {
|
||||||
let module = if orig_name.is_none() && ident.name == keywords::SelfLower.name() {
|
let module = if orig_name.is_none() && ident.name == keywords::SelfLower.name() {
|
||||||
self.session
|
self.session
|
||||||
.struct_span_err(item.span, "`extern crate self;` requires renaming")
|
.struct_span_err(item.span, "`extern crate self;` requires renaming")
|
||||||
.span_suggestion_with_applicability(
|
.span_suggestion(
|
||||||
item.span,
|
item.span,
|
||||||
"try",
|
"try",
|
||||||
"extern crate self as name;".into(),
|
"extern crate self as name;".into(),
|
||||||
|
|
|
@ -247,7 +247,7 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
|
||||||
let sugg_msg = "try using a local type parameter instead";
|
let sugg_msg = "try using a local type parameter instead";
|
||||||
if let Some((sugg_span, new_snippet)) = cm.generate_local_type_param_snippet(span) {
|
if let Some((sugg_span, new_snippet)) = cm.generate_local_type_param_snippet(span) {
|
||||||
// Suggest the modification to the user
|
// Suggest the modification to the user
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
sugg_span,
|
sugg_span,
|
||||||
sugg_msg,
|
sugg_msg,
|
||||||
new_snippet,
|
new_snippet,
|
||||||
|
@ -3175,7 +3175,7 @@ impl<'a> Resolver<'a> {
|
||||||
// Emit help message for fake-self from other languages like `this`(javascript)
|
// Emit help message for fake-self from other languages like `this`(javascript)
|
||||||
if ["this", "my"].contains(&&*item_str.as_str())
|
if ["this", "my"].contains(&&*item_str.as_str())
|
||||||
&& this.self_value_is_available(path[0].ident.span, span) {
|
&& this.self_value_is_available(path[0].ident.span, span) {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"did you mean",
|
"did you mean",
|
||||||
"self".to_string(),
|
"self".to_string(),
|
||||||
|
@ -3239,7 +3239,7 @@ impl<'a> Resolver<'a> {
|
||||||
};
|
};
|
||||||
let msg = format!("{}try using the variant's enum", preamble);
|
let msg = format!("{}try using the variant's enum", preamble);
|
||||||
|
|
||||||
err.span_suggestions_with_applicability(
|
err.span_suggestions(
|
||||||
span,
|
span,
|
||||||
&msg,
|
&msg,
|
||||||
enum_candidates.into_iter()
|
enum_candidates.into_iter()
|
||||||
|
@ -3262,7 +3262,7 @@ impl<'a> Resolver<'a> {
|
||||||
let self_is_available = this.self_value_is_available(path[0].ident.span, span);
|
let self_is_available = this.self_value_is_available(path[0].ident.span, span);
|
||||||
match candidate {
|
match candidate {
|
||||||
AssocSuggestion::Field => {
|
AssocSuggestion::Field => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"try",
|
"try",
|
||||||
format!("self.{}", path_str),
|
format!("self.{}", path_str),
|
||||||
|
@ -3275,7 +3275,7 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AssocSuggestion::MethodWithSelf if self_is_available => {
|
AssocSuggestion::MethodWithSelf if self_is_available => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"try",
|
"try",
|
||||||
format!("self.{}", path_str),
|
format!("self.{}", path_str),
|
||||||
|
@ -3283,7 +3283,7 @@ impl<'a> Resolver<'a> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
AssocSuggestion::MethodWithSelf | AssocSuggestion::AssocItem => {
|
AssocSuggestion::MethodWithSelf | AssocSuggestion::AssocItem => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"try",
|
"try",
|
||||||
format!("Self::{}", path_str),
|
format!("Self::{}", path_str),
|
||||||
|
@ -3304,7 +3304,7 @@ impl<'a> Resolver<'a> {
|
||||||
"{} {} with a similar name exists",
|
"{} {} with a similar name exists",
|
||||||
suggestion.article, suggestion.kind
|
suggestion.article, suggestion.kind
|
||||||
);
|
);
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
ident_span,
|
ident_span,
|
||||||
&msg,
|
&msg,
|
||||||
suggestion.candidate.to_string(),
|
suggestion.candidate.to_string(),
|
||||||
|
@ -3318,7 +3318,7 @@ impl<'a> Resolver<'a> {
|
||||||
if let Some(def) = def {
|
if let Some(def) = def {
|
||||||
match (def, source) {
|
match (def, source) {
|
||||||
(Def::Macro(..), _) => {
|
(Def::Macro(..), _) => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"use `!` to invoke the macro",
|
"use `!` to invoke the macro",
|
||||||
format!("{}!", path_str),
|
format!("{}!", path_str),
|
||||||
|
@ -3335,7 +3335,7 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
(Def::Mod(..), PathSource::Expr(Some(parent))) => match parent.node {
|
(Def::Mod(..), PathSource::Expr(Some(parent))) => match parent.node {
|
||||||
ExprKind::Field(_, ident) => {
|
ExprKind::Field(_, ident) => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
parent.span,
|
parent.span,
|
||||||
"use the path separator to refer to an item",
|
"use the path separator to refer to an item",
|
||||||
format!("{}::{}", path_str, ident),
|
format!("{}::{}", path_str, ident),
|
||||||
|
@ -3345,7 +3345,7 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
ExprKind::MethodCall(ref segment, ..) => {
|
ExprKind::MethodCall(ref segment, ..) => {
|
||||||
let span = parent.span.with_hi(segment.ident.span.hi());
|
let span = parent.span.with_hi(segment.ident.span.hi());
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"use the path separator to refer to an item",
|
"use the path separator to refer to an item",
|
||||||
format!("{}::{}", path_str, segment.ident),
|
format!("{}::{}", path_str, segment.ident),
|
||||||
|
@ -3428,7 +3428,7 @@ impl<'a> Resolver<'a> {
|
||||||
PathSource::Expr(Some(parent)) => {
|
PathSource::Expr(Some(parent)) => {
|
||||||
match parent.node {
|
match parent.node {
|
||||||
ExprKind::MethodCall(ref path_assignment, _) => {
|
ExprKind::MethodCall(ref path_assignment, _) => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
sm.start_point(parent.span)
|
sm.start_point(parent.span)
|
||||||
.to(path_assignment.ident.span),
|
.to(path_assignment.ident.span),
|
||||||
"use `::` to access an associated function",
|
"use `::` to access an associated function",
|
||||||
|
@ -3451,7 +3451,7 @@ impl<'a> Resolver<'a> {
|
||||||
},
|
},
|
||||||
PathSource::Expr(None) if followed_by_brace == true => {
|
PathSource::Expr(None) if followed_by_brace == true => {
|
||||||
if let Some((sp, snippet)) = closing_brace {
|
if let Some((sp, snippet)) = closing_brace {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
sp,
|
sp,
|
||||||
"surround the struct literal with parenthesis",
|
"surround the struct literal with parenthesis",
|
||||||
format!("({})", snippet),
|
format!("({})", snippet),
|
||||||
|
@ -3589,7 +3589,7 @@ impl<'a> Resolver<'a> {
|
||||||
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_with_applicability(
|
err.span_suggestion_short(
|
||||||
sp,
|
sp,
|
||||||
"did you mean to use `;` here instead?",
|
"did you mean to use `;` here instead?",
|
||||||
";".to_string(),
|
";".to_string(),
|
||||||
|
@ -4866,7 +4866,7 @@ impl<'a> Resolver<'a> {
|
||||||
} else if ident.span.rust_2018() {
|
} else if ident.span.rust_2018() {
|
||||||
let msg = "relative paths are not supported in visibilities on 2018 edition";
|
let msg = "relative paths are not supported in visibilities on 2018 edition";
|
||||||
self.session.struct_span_err(ident.span, msg)
|
self.session.struct_span_err(ident.span, msg)
|
||||||
.span_suggestion_with_applicability(
|
.span_suggestion(
|
||||||
path.span,
|
path.span,
|
||||||
"try",
|
"try",
|
||||||
format!("crate::{}", path),
|
format!("crate::{}", path),
|
||||||
|
@ -5179,7 +5179,7 @@ impl<'a> Resolver<'a> {
|
||||||
|
|
||||||
let rename_msg = "you can use `as` to change the binding name of the import";
|
let rename_msg = "you can use `as` to change the binding name of the import";
|
||||||
if let Some(suggestion) = suggestion {
|
if let Some(suggestion) = suggestion {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
binding_span,
|
binding_span,
|
||||||
rename_msg,
|
rename_msg,
|
||||||
suggestion,
|
suggestion,
|
||||||
|
@ -5302,7 +5302,7 @@ fn show_candidates(err: &mut DiagnosticBuilder,
|
||||||
*candidate = format!("use {};\n{}", candidate, additional_newline);
|
*candidate = format!("use {};\n{}", candidate, additional_newline);
|
||||||
}
|
}
|
||||||
|
|
||||||
err.span_suggestions_with_applicability(
|
err.span_suggestions(
|
||||||
span,
|
span,
|
||||||
&msg,
|
&msg,
|
||||||
path_strings.into_iter(),
|
path_strings.into_iter(),
|
||||||
|
|
|
@ -1021,14 +1021,14 @@ impl<'a> Resolver<'a> {
|
||||||
if let Some(suggestion) = suggestion {
|
if let Some(suggestion) = suggestion {
|
||||||
if suggestion != name {
|
if suggestion != name {
|
||||||
if let MacroKind::Bang = kind {
|
if let MacroKind::Bang = kind {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"you could try the macro",
|
"you could try the macro",
|
||||||
suggestion.to_string(),
|
suggestion.to_string(),
|
||||||
Applicability::MaybeIncorrect
|
Applicability::MaybeIncorrect
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"try",
|
"try",
|
||||||
suggestion.to_string(),
|
suggestion.to_string(),
|
||||||
|
|
|
@ -1096,7 +1096,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
|
||||||
if !suggestions.is_empty() {
|
if !suggestions.is_empty() {
|
||||||
let msg = format!("if you meant to specify the associated {}, write",
|
let msg = format!("if you meant to specify the associated {}, write",
|
||||||
if suggestions.len() == 1 { "type" } else { "types" });
|
if suggestions.len() == 1 { "type" } else { "types" });
|
||||||
err.multipart_suggestion_with_applicability(
|
err.multipart_suggestion(
|
||||||
&msg,
|
&msg,
|
||||||
suggestions,
|
suggestions,
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
|
@ -1172,7 +1172,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
|
||||||
trait_str: &str,
|
trait_str: &str,
|
||||||
name: &str) {
|
name: &str) {
|
||||||
struct_span_err!(self.tcx().sess, span, E0223, "ambiguous associated type")
|
struct_span_err!(self.tcx().sess, span, E0223, "ambiguous associated type")
|
||||||
.span_suggestion_with_applicability(
|
.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"use fully-qualified syntax",
|
"use fully-qualified syntax",
|
||||||
format!("<{} as {}>::{}", type_str, trait_str, name),
|
format!("<{} as {}>::{}", type_str, trait_str, name),
|
||||||
|
@ -1353,7 +1353,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
|
||||||
&assoc_ident.as_str(),
|
&assoc_ident.as_str(),
|
||||||
None,
|
None,
|
||||||
) {
|
) {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"did you mean",
|
"did you mean",
|
||||||
format!("{}::{}", qself_ty, suggested_name),
|
format!("{}::{}", qself_ty, suggested_name),
|
||||||
|
@ -1407,7 +1407,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
|
||||||
could_refer_to(variant_def, "");
|
could_refer_to(variant_def, "");
|
||||||
could_refer_to(def, " also");
|
could_refer_to(def, " also");
|
||||||
|
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"use fully-qualified syntax",
|
"use fully-qualified syntax",
|
||||||
format!("<{} as {}>::{}", qself_ty, "Trait", assoc_ident),
|
format!("<{} as {}>::{}", qself_ty, "Trait", assoc_ident),
|
||||||
|
|
|
@ -990,7 +990,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
|
||||||
let suggested_name =
|
let suggested_name =
|
||||||
find_best_match_for_name(input, &ident.as_str(), None);
|
find_best_match_for_name(input, &ident.as_str(), None);
|
||||||
if let Some(suggested_name) = suggested_name {
|
if let Some(suggested_name) = suggested_name {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
*span,
|
*span,
|
||||||
"did you mean",
|
"did you mean",
|
||||||
suggested_name.to_string(),
|
suggested_name.to_string(),
|
||||||
|
|
|
@ -269,7 +269,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(ref path) = unit_variant {
|
if let Some(ref path) = unit_variant {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
call_expr.span,
|
call_expr.span,
|
||||||
&format!(
|
&format!(
|
||||||
"`{}` is a unit variant, you need to write it \
|
"`{}` is a unit variant, you need to write it \
|
||||||
|
@ -294,7 +294,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
self.tcx.sess.source_map().is_multiline(call_expr.span);
|
self.tcx.sess.source_map().is_multiline(call_expr.span);
|
||||||
if call_is_multiline {
|
if call_is_multiline {
|
||||||
let span = self.tcx.sess.source_map().next_point(callee.span);
|
let span = self.tcx.sess.source_map().next_point(callee.span);
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"try adding a semicolon",
|
"try adding a semicolon",
|
||||||
";".to_owned(),
|
";".to_owned(),
|
||||||
|
|
|
@ -213,7 +213,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
|
||||||
fcx.ty_to_string(self.expr_ty),
|
fcx.ty_to_string(self.expr_ty),
|
||||||
cast_ty));
|
cast_ty));
|
||||||
if let Ok(snippet) = fcx.sess().source_map().span_to_snippet(self.expr.span) {
|
if let Ok(snippet) = fcx.sess().source_map().span_to_snippet(self.expr.span) {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
self.expr.span,
|
self.expr.span,
|
||||||
"dereference the expression",
|
"dereference the expression",
|
||||||
format!("*{}", snippet),
|
format!("*{}", snippet),
|
||||||
|
@ -263,7 +263,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
|
||||||
if self.expr_ty.is_numeric() {
|
if self.expr_ty.is_numeric() {
|
||||||
match fcx.tcx.sess.source_map().span_to_snippet(self.expr.span) {
|
match fcx.tcx.sess.source_map().span_to_snippet(self.expr.span) {
|
||||||
Ok(snippet) => {
|
Ok(snippet) => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
self.span,
|
self.span,
|
||||||
"compare with zero instead",
|
"compare with zero instead",
|
||||||
format!("{} != 0", snippet),
|
format!("{} != 0", snippet),
|
||||||
|
@ -314,7 +314,7 @@ 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_with_applicability(
|
err.span_suggestion_short(
|
||||||
self.cast_span,
|
self.cast_span,
|
||||||
"consider giving more type information",
|
"consider giving more type information",
|
||||||
String::new(),
|
String::new(),
|
||||||
|
@ -345,7 +345,7 @@ 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_with_applicability(
|
err.span_suggestion(
|
||||||
self.cast_span,
|
self.cast_span,
|
||||||
"try casting to a reference instead",
|
"try casting to a reference instead",
|
||||||
format!("&{}{}", mtstr, s),
|
format!("&{}{}", mtstr, s),
|
||||||
|
@ -367,7 +367,7 @@ 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_with_applicability(
|
err.span_suggestion(
|
||||||
self.cast_span,
|
self.cast_span,
|
||||||
"try casting to a `Box` instead",
|
"try casting to a `Box` instead",
|
||||||
format!("Box<{}>", s),
|
format!("Box<{}>", s),
|
||||||
|
|
|
@ -316,7 +316,7 @@ 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_with_applicability(
|
diag.span_suggestion(
|
||||||
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",
|
||||||
trait_err_str,
|
trait_err_str,
|
||||||
|
@ -784,7 +784,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_with_applicability(
|
err.multipart_suggestion(
|
||||||
"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`
|
||||||
|
@ -855,7 +855,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_with_applicability(
|
err.multipart_suggestion(
|
||||||
"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
|
||||||
|
|
|
@ -143,7 +143,7 @@ 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
|
let suggestions = compatible_variants
|
||||||
.map(|v| format!("{}({})", v, expr_text));
|
.map(|v| format!("{}({})", v, expr_text));
|
||||||
err.span_suggestions_with_applicability(
|
err.span_suggestions(
|
||||||
expr.span,
|
expr.span,
|
||||||
"try using a variant of the expected type",
|
"try using a variant of the expected type",
|
||||||
suggestions,
|
suggestions,
|
||||||
|
@ -558,7 +558,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
if needs_paren { ")" } else { "" },
|
if needs_paren { ")" } else { "" },
|
||||||
);
|
);
|
||||||
|
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&suggest_msg,
|
&suggest_msg,
|
||||||
if literal_is_ty_suffixed(expr) {
|
if literal_is_ty_suffixed(expr) {
|
||||||
|
@ -575,7 +575,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
match (found.bit_width(), exp.bit_width()) {
|
match (found.bit_width(), exp.bit_width()) {
|
||||||
(Some(found), Some(exp)) if found > exp => {
|
(Some(found), Some(exp)) if found > exp => {
|
||||||
if can_cast {
|
if can_cast {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("{}, which {}", msg, will_truncate),
|
&format!("{}, which {}", msg, will_truncate),
|
||||||
cast_suggestion,
|
cast_suggestion,
|
||||||
|
@ -585,7 +585,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
(None, _) | (_, None) => {
|
(None, _) | (_, None) => {
|
||||||
if can_cast {
|
if can_cast {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("{}, which {}", msg, depending_on_isize),
|
&format!("{}, which {}", msg, depending_on_isize),
|
||||||
cast_suggestion,
|
cast_suggestion,
|
||||||
|
@ -606,7 +606,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
match (found.bit_width(), exp.bit_width()) {
|
match (found.bit_width(), exp.bit_width()) {
|
||||||
(Some(found), Some(exp)) if found > exp => {
|
(Some(found), Some(exp)) if found > exp => {
|
||||||
if can_cast {
|
if can_cast {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("{}, which {}", msg, will_truncate),
|
&format!("{}, which {}", msg, will_truncate),
|
||||||
cast_suggestion,
|
cast_suggestion,
|
||||||
|
@ -616,7 +616,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
(None, _) | (_, None) => {
|
(None, _) | (_, None) => {
|
||||||
if can_cast {
|
if can_cast {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("{}, which {}", msg, depending_on_usize),
|
&format!("{}, which {}", msg, depending_on_usize),
|
||||||
cast_suggestion,
|
cast_suggestion,
|
||||||
|
@ -637,7 +637,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
if can_cast {
|
if can_cast {
|
||||||
match (found.bit_width(), exp.bit_width()) {
|
match (found.bit_width(), exp.bit_width()) {
|
||||||
(Some(found), Some(exp)) if found > exp - 1 => {
|
(Some(found), Some(exp)) if found > exp - 1 => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("{}, which {}", msg, will_truncate),
|
&format!("{}, which {}", msg, will_truncate),
|
||||||
cast_suggestion,
|
cast_suggestion,
|
||||||
|
@ -645,7 +645,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
(None, None) => {
|
(None, None) => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("{}, which {}", msg, will_truncate),
|
&format!("{}, which {}", msg, will_truncate),
|
||||||
cast_suggestion,
|
cast_suggestion,
|
||||||
|
@ -653,7 +653,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
(None, _) => {
|
(None, _) => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("{}, which {}", msg, depending_on_isize),
|
&format!("{}, which {}", msg, depending_on_isize),
|
||||||
cast_suggestion,
|
cast_suggestion,
|
||||||
|
@ -661,7 +661,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
(_, None) => {
|
(_, None) => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("{}, which {}", msg, depending_on_usize),
|
&format!("{}, which {}", msg, depending_on_usize),
|
||||||
cast_suggestion,
|
cast_suggestion,
|
||||||
|
@ -669,7 +669,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("{}, which {}", msg, will_zero_extend),
|
&format!("{}, which {}", msg, will_zero_extend),
|
||||||
cast_suggestion,
|
cast_suggestion,
|
||||||
|
@ -684,7 +684,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
if can_cast {
|
if can_cast {
|
||||||
match (found.bit_width(), exp.bit_width()) {
|
match (found.bit_width(), exp.bit_width()) {
|
||||||
(Some(found), Some(exp)) if found - 1 > exp => {
|
(Some(found), Some(exp)) if found - 1 > exp => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("{}, which {}", msg, will_truncate),
|
&format!("{}, which {}", msg, will_truncate),
|
||||||
cast_suggestion,
|
cast_suggestion,
|
||||||
|
@ -692,7 +692,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
(None, None) => {
|
(None, None) => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("{}, which {}", msg, will_sign_extend),
|
&format!("{}, which {}", msg, will_sign_extend),
|
||||||
cast_suggestion,
|
cast_suggestion,
|
||||||
|
@ -700,7 +700,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
(None, _) => {
|
(None, _) => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("{}, which {}", msg, depending_on_usize),
|
&format!("{}, which {}", msg, depending_on_usize),
|
||||||
cast_suggestion,
|
cast_suggestion,
|
||||||
|
@ -708,7 +708,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
(_, None) => {
|
(_, None) => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("{}, which {}", msg, depending_on_isize),
|
&format!("{}, which {}", msg, depending_on_isize),
|
||||||
cast_suggestion,
|
cast_suggestion,
|
||||||
|
@ -716,7 +716,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("{}, which {}", msg, will_sign_extend),
|
&format!("{}, which {}", msg, will_sign_extend),
|
||||||
cast_suggestion,
|
cast_suggestion,
|
||||||
|
@ -734,7 +734,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
} else if can_cast {
|
} else if can_cast {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("{}, producing the closest possible value", msg),
|
&format!("{}, producing the closest possible value", msg),
|
||||||
cast_suggestion,
|
cast_suggestion,
|
||||||
|
@ -745,7 +745,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
(&ty::Uint(_), &ty::Float(_)) | (&ty::Int(_), &ty::Float(_)) => {
|
(&ty::Uint(_), &ty::Float(_)) | (&ty::Int(_), &ty::Float(_)) => {
|
||||||
if can_cast {
|
if can_cast {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("{}, rounding the float towards zero", msg),
|
&format!("{}, rounding the float towards zero", msg),
|
||||||
cast_suggestion,
|
cast_suggestion,
|
||||||
|
@ -760,7 +760,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
(&ty::Float(ref exp), &ty::Uint(ref found)) => {
|
(&ty::Float(ref exp), &ty::Uint(ref found)) => {
|
||||||
// if `found` is `None` (meaning found is `usize`), don't suggest `.into()`
|
// if `found` is `None` (meaning found is `usize`), don't suggest `.into()`
|
||||||
if exp.bit_width() > found.bit_width().unwrap_or(256) {
|
if exp.bit_width() > found.bit_width().unwrap_or(256) {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("{}, producing the floating point representation of the \
|
&format!("{}, producing the floating point representation of the \
|
||||||
integer",
|
integer",
|
||||||
|
@ -769,7 +769,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
Applicability::MachineApplicable
|
Applicability::MachineApplicable
|
||||||
);
|
);
|
||||||
} else if can_cast {
|
} else if can_cast {
|
||||||
err.span_suggestion_with_applicability(expr.span,
|
err.span_suggestion(
|
||||||
|
expr.span,
|
||||||
&format!("{}, producing the floating point representation of the \
|
&format!("{}, producing the floating point representation of the \
|
||||||
integer, rounded if necessary",
|
integer, rounded if necessary",
|
||||||
msg),
|
msg),
|
||||||
|
@ -782,7 +783,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
(&ty::Float(ref exp), &ty::Int(ref found)) => {
|
(&ty::Float(ref exp), &ty::Int(ref found)) => {
|
||||||
// if `found` is `None` (meaning found is `isize`), don't suggest `.into()`
|
// if `found` is `None` (meaning found is `isize`), don't suggest `.into()`
|
||||||
if exp.bit_width() > found.bit_width().unwrap_or(256) {
|
if exp.bit_width() > found.bit_width().unwrap_or(256) {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("{}, producing the floating point representation of the \
|
&format!("{}, producing the floating point representation of the \
|
||||||
integer",
|
integer",
|
||||||
|
@ -791,7 +792,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
Applicability::MachineApplicable
|
Applicability::MachineApplicable
|
||||||
);
|
);
|
||||||
} else if can_cast {
|
} else if can_cast {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("{}, producing the floating point representation of the \
|
&format!("{}, producing the floating point representation of the \
|
||||||
integer, rounded if necessary",
|
integer, rounded if necessary",
|
||||||
|
|
|
@ -157,7 +157,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
(format!("{}()", method_name), Applicability::MaybeIncorrect)
|
(format!("{}()", method_name), Applicability::MaybeIncorrect)
|
||||||
};
|
};
|
||||||
|
|
||||||
err.span_suggestion_with_applicability(method_name.span, msg, suggestion, applicability);
|
err.span_suggestion(method_name.span, msg, suggestion, applicability);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Performs method lookup. If lookup is successful, it will return the callee
|
/// Performs method lookup. If lookup is successful, it will return the callee
|
||||||
|
|
|
@ -1144,7 +1144,7 @@ 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_with_applicability` instead of `help`
|
// FIXME: This should be a `span_suggestion` instead of `help`
|
||||||
// However `self.span` only
|
// 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()`.
|
||||||
|
|
|
@ -237,15 +237,12 @@ 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_else(|_| "<numeric literal>".to_owned());
|
.unwrap_or_else(|_| "<numeric literal>".to_owned());
|
||||||
|
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
lit.span,
|
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!("{}_{}", snippet, concrete_type),
|
||||||
format!("{}_{}",
|
Applicability::MaybeIncorrect,
|
||||||
snippet,
|
|
||||||
concrete_type),
|
|
||||||
Applicability::MaybeIncorrect,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
ExprKind::Path(ref qpath) => {
|
ExprKind::Path(ref qpath) => {
|
||||||
|
@ -271,7 +268,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
ty,
|
ty,
|
||||||
..
|
..
|
||||||
})) => {
|
})) => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
// 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)
|
||||||
|
@ -304,7 +301,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
);
|
);
|
||||||
if let Some(suggestion) = suggestion {
|
if let Some(suggestion) = suggestion {
|
||||||
// enum variant
|
// enum variant
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
item_name.span,
|
item_name.span,
|
||||||
"did you mean",
|
"did you mean",
|
||||||
suggestion.to_string(),
|
suggestion.to_string(),
|
||||||
|
@ -404,7 +401,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
if static_sources.len() == 1 {
|
if static_sources.len() == 1 {
|
||||||
if let SelfSource::MethodCall(expr) = source {
|
if let SelfSource::MethodCall(expr) = source {
|
||||||
err.span_suggestion_with_applicability(expr.span.to(span),
|
err.span_suggestion(expr.span.to(span),
|
||||||
"use associated function syntax instead",
|
"use associated function syntax instead",
|
||||||
format!("{}::{}",
|
format!("{}::{}",
|
||||||
self.ty_to_string(actual),
|
self.ty_to_string(actual),
|
||||||
|
@ -445,7 +442,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(lev_candidate) = lev_candidate {
|
if let Some(lev_candidate) = lev_candidate {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"did you mean",
|
"did you mean",
|
||||||
lev_candidate.ident.to_string(),
|
lev_candidate.ident.to_string(),
|
||||||
|
@ -522,12 +519,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
err.span_suggestions_with_applicability(
|
err.span_suggestions(span, &msg, path_strings, Applicability::MaybeIncorrect);
|
||||||
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() {
|
||||||
|
|
|
@ -2903,7 +2903,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
let sugg_span = tcx.sess.source_map().end_point(expr_sp);
|
let sugg_span = tcx.sess.source_map().end_point(expr_sp);
|
||||||
// remove closing `)` from the span
|
// remove closing `)` from the span
|
||||||
let sugg_span = sugg_span.shrink_to_lo();
|
let sugg_span = sugg_span.shrink_to_lo();
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
sugg_span,
|
sugg_span,
|
||||||
"expected the unit value `()`; create it with empty parentheses",
|
"expected the unit value `()`; create it with empty parentheses",
|
||||||
String::from("()"),
|
String::from("()"),
|
||||||
|
@ -3170,7 +3170,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
self.tcx.sess.source_map().span_to_snippet(lhs.span),
|
self.tcx.sess.source_map().span_to_snippet(lhs.span),
|
||||||
self.tcx.sess.source_map().span_to_snippet(rhs.span))
|
self.tcx.sess.source_map().span_to_snippet(rhs.span))
|
||||||
{
|
{
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
msg,
|
msg,
|
||||||
format!("{} == {}", left, right),
|
format!("{} == {}", left, right),
|
||||||
|
@ -3587,7 +3587,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
if let Some(suggested_field_name) =
|
if let Some(suggested_field_name) =
|
||||||
Self::suggest_field_name(def.non_enum_variant(),
|
Self::suggest_field_name(def.non_enum_variant(),
|
||||||
&field.as_str(), vec![]) {
|
&field.as_str(), vec![]) {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
field.span,
|
field.span,
|
||||||
"a field with a similar name exists",
|
"a field with a similar name exists",
|
||||||
suggested_field_name.to_string(),
|
suggested_field_name.to_string(),
|
||||||
|
@ -3618,7 +3618,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
} else {
|
} else {
|
||||||
Applicability::MaybeIncorrect
|
Applicability::MaybeIncorrect
|
||||||
};
|
};
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span, help, suggestion, applicability
|
expr.span, help, suggestion, applicability
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3629,7 +3629,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
.unwrap_or_else(|_| self.tcx.hir().node_to_pretty_string(base.id));
|
.unwrap_or_else(|_| self.tcx.hir().node_to_pretty_string(base.id));
|
||||||
let msg = format!("`{}` is a raw pointer; try dereferencing it", base);
|
let msg = format!("`{}` is a raw pointer; try dereferencing it", base);
|
||||||
let suggestion = format!("(*{}).{}", base, field);
|
let suggestion = format!("(*{}).{}", base, field);
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&msg,
|
&msg,
|
||||||
suggestion,
|
suggestion,
|
||||||
|
@ -3719,12 +3719,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
if let Some(field_name) = Self::suggest_field_name(variant,
|
if let Some(field_name) = Self::suggest_field_name(variant,
|
||||||
&field.ident.as_str(),
|
&field.ident.as_str(),
|
||||||
skip_fields.collect()) {
|
skip_fields.collect()) {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
field.ident.span,
|
field.ident.span,
|
||||||
"a field with a similar name exists",
|
"a field with a similar name exists",
|
||||||
field_name.to_string(),
|
field_name.to_string(),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
match ty.sty {
|
match ty.sty {
|
||||||
ty::Adt(adt, ..) => {
|
ty::Adt(adt, ..) => {
|
||||||
|
@ -4670,11 +4670,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
ast::LitIntType::Unsuffixed) = lit.node {
|
ast::LitIntType::Unsuffixed) = lit.node {
|
||||||
let snip = tcx.sess.source_map().span_to_snippet(base.span);
|
let snip = tcx.sess.source_map().span_to_snippet(base.span);
|
||||||
if let Ok(snip) = snip {
|
if let Ok(snip) = snip {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
"to access tuple elements, use",
|
"to access tuple elements, use",
|
||||||
format!("{}.{}", snip, i),
|
format!("{}.{}", snip, i),
|
||||||
Applicability::MachineApplicable);
|
Applicability::MachineApplicable,
|
||||||
|
);
|
||||||
needs_note = false;
|
needs_note = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5106,7 +5107,7 @@ 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_with_applicability(
|
err.span_suggestion(
|
||||||
sp,
|
sp,
|
||||||
msg,
|
msg,
|
||||||
suggestion,
|
suggestion,
|
||||||
|
@ -5133,7 +5134,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
}).peekable();
|
}).peekable();
|
||||||
if suggestions.peek().is_some() {
|
if suggestions.peek().is_some() {
|
||||||
err.span_suggestions_with_applicability(
|
err.span_suggestions(
|
||||||
expr.span,
|
expr.span,
|
||||||
"try using a conversion method",
|
"try using a conversion method",
|
||||||
suggestions,
|
suggestions,
|
||||||
|
@ -5172,7 +5173,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
ExprKind::Match(..) |
|
ExprKind::Match(..) |
|
||||||
ExprKind::Block(..) => {
|
ExprKind::Block(..) => {
|
||||||
let sp = self.tcx.sess.source_map().next_point(cause_span);
|
let sp = self.tcx.sess.source_map().next_point(cause_span);
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
sp,
|
sp,
|
||||||
"try adding a semicolon",
|
"try adding a semicolon",
|
||||||
";".to_string(),
|
";".to_string(),
|
||||||
|
@ -5206,7 +5207,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
// haven't set a return type at all (and aren't `fn main()` or an impl).
|
// haven't set a return type at all (and aren't `fn main()` or an impl).
|
||||||
match (&fn_decl.output, found.is_suggestable(), can_suggest, expected.is_unit()) {
|
match (&fn_decl.output, found.is_suggestable(), can_suggest, expected.is_unit()) {
|
||||||
(&hir::FunctionRetTy::DefaultReturn(span), true, true, true) => {
|
(&hir::FunctionRetTy::DefaultReturn(span), true, true, true) => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"try adding a return type",
|
"try adding a return type",
|
||||||
format!("-> {} ", self.resolve_type_vars_with_obligations(found)),
|
format!("-> {} ", self.resolve_type_vars_with_obligations(found)),
|
||||||
|
@ -5260,7 +5261,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
err: &mut DiagnosticBuilder,
|
err: &mut DiagnosticBuilder,
|
||||||
) {
|
) {
|
||||||
if let Some(span_semi) = self.could_remove_semicolon(blk, expected_ty) {
|
if let Some(span_semi) = self.could_remove_semicolon(blk, expected_ty) {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span_semi,
|
span_semi,
|
||||||
"consider removing this semicolon",
|
"consider removing this semicolon",
|
||||||
String::new(),
|
String::new(),
|
||||||
|
@ -5436,7 +5437,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
},
|
},
|
||||||
AdtKind::Struct |
|
AdtKind::Struct |
|
||||||
AdtKind::Union => {
|
AdtKind::Union => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"use curly brackets",
|
"use curly brackets",
|
||||||
String::from("Self { /* fields */ }"),
|
String::from("Self { /* fields */ }"),
|
||||||
|
|
|
@ -280,7 +280,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
rty,
|
rty,
|
||||||
lstring,
|
lstring,
|
||||||
);
|
);
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
lhs_expr.span,
|
lhs_expr.span,
|
||||||
msg,
|
msg,
|
||||||
format!("*{}", lstring),
|
format!("*{}", lstring),
|
||||||
|
@ -434,7 +434,7 @@ 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_with_applicability(
|
Ok(lstring) => err.span_suggestion(
|
||||||
lhs_expr.span,
|
lhs_expr.span,
|
||||||
msg,
|
msg,
|
||||||
format!("{}.to_owned()", lstring),
|
format!("{}.to_owned()", lstring),
|
||||||
|
@ -455,7 +455,7 @@ 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_with_applicability(
|
err.multipart_suggestion(
|
||||||
msg,
|
msg,
|
||||||
vec![
|
vec![
|
||||||
(lhs_expr.span, format!("{}.to_owned()", l)),
|
(lhs_expr.span, format!("{}.to_owned()", l)),
|
||||||
|
|
|
@ -136,7 +136,7 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) {
|
||||||
.fold(span, |acc, attr_span| acc.to(attr_span));
|
.fold(span, |acc, attr_span| acc.to(attr_span));
|
||||||
|
|
||||||
tcx.struct_span_lint_node(lint, id, span, msg)
|
tcx.struct_span_lint_node(lint, id, span, msg)
|
||||||
.span_suggestion_short_with_applicability(
|
.span_suggestion_short(
|
||||||
span_with_attrs,
|
span_with_attrs,
|
||||||
"remove it",
|
"remove it",
|
||||||
String::new(),
|
String::new(),
|
||||||
|
@ -178,7 +178,7 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) {
|
||||||
};
|
};
|
||||||
let replacement = visibility_qualified(&item.vis, base_replacement);
|
let replacement = visibility_qualified(&item.vis, base_replacement);
|
||||||
tcx.struct_span_lint_node(lint, id, extern_crate.span, msg)
|
tcx.struct_span_lint_node(lint, id, extern_crate.span, msg)
|
||||||
.span_suggestion_short_with_applicability(
|
.span_suggestion_short(
|
||||||
extern_crate.span,
|
extern_crate.span,
|
||||||
&help,
|
&help,
|
||||||
replacement,
|
replacement,
|
||||||
|
|
|
@ -63,7 +63,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for VariadicError<'tcx> {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
if let Ok(snippet) = self.sess.source_map().span_to_snippet(self.span) {
|
if let Ok(snippet) = self.sess.source_map().span_to_snippet(self.span) {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
self.span,
|
self.span,
|
||||||
&format!("cast the value to `{}`", self.cast_ty),
|
&format!("cast the value to `{}`", self.cast_ty),
|
||||||
format!("{} as {}", snippet, self.cast_ty),
|
format!("{} as {}", snippet, self.cast_ty),
|
||||||
|
|
|
@ -62,7 +62,7 @@ impl<'a, 'tcx, 'rcx> SyntaxChecker<'a, 'tcx, 'rcx> {
|
||||||
|
|
||||||
if code_block.syntax.is_none() && code_block.is_fenced {
|
if code_block.syntax.is_none() && code_block.is_fenced {
|
||||||
let sp = sp.from_inner_byte_pos(0, 3);
|
let sp = sp.from_inner_byte_pos(0, 3);
|
||||||
diag.span_suggestion_with_applicability(
|
diag.span_suggestion(
|
||||||
sp,
|
sp,
|
||||||
"mark blocks that do not contain Rust code as text",
|
"mark blocks that do not contain Rust code as text",
|
||||||
String::from("```text"),
|
String::from("```text"),
|
||||||
|
|
|
@ -42,7 +42,7 @@ fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) {
|
||||||
let mut err = struct_span_err!(diag, span, E0565, "{}", msg);
|
let mut err = struct_span_err!(diag, span, E0565, "{}", msg);
|
||||||
if is_bytestr {
|
if is_bytestr {
|
||||||
if let Ok(lint_str) = sess.source_map().span_to_snippet(span) {
|
if let Ok(lint_str) = sess.source_map().span_to_snippet(span) {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"consider removing the prefix",
|
"consider removing the prefix",
|
||||||
format!("{}", &lint_str[1..]),
|
format!("{}", &lint_str[1..]),
|
||||||
|
@ -794,7 +794,7 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec<ReprAttr> {
|
||||||
"incorrect `repr(align)` attribute format");
|
"incorrect `repr(align)` attribute format");
|
||||||
match value.node {
|
match value.node {
|
||||||
ast::LitKind::Int(int, ast::LitIntType::Unsuffixed) => {
|
ast::LitKind::Int(int, ast::LitIntType::Unsuffixed) => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
item.span,
|
item.span,
|
||||||
"use parentheses instead",
|
"use parentheses instead",
|
||||||
format!("align({})", int),
|
format!("align({})", int),
|
||||||
|
@ -802,7 +802,7 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec<ReprAttr> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
ast::LitKind::Str(s, _) => {
|
ast::LitKind::Str(s, _) => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
item.span,
|
item.span,
|
||||||
"use parentheses instead",
|
"use parentheses instead",
|
||||||
format!("align({})", s),
|
format!("align({})", s),
|
||||||
|
|
|
@ -155,7 +155,7 @@ 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_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"expected syntax is",
|
"expected syntax is",
|
||||||
suggestion.into(),
|
suggestion.into(),
|
||||||
|
|
|
@ -361,7 +361,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
let trait_list = traits.iter()
|
let trait_list = traits.iter()
|
||||||
.map(|t| t.to_string()).collect::<Vec<_>>();
|
.map(|t| t.to_string()).collect::<Vec<_>>();
|
||||||
let suggestion = format!("#[derive({})]", trait_list.join(", "));
|
let suggestion = format!("#[derive({})]", trait_list.join(", "));
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span, "try an outer attribute", suggestion,
|
span, "try an outer attribute", suggestion,
|
||||||
// We don't 𝑘𝑛𝑜𝑤 that the following item is an ADT
|
// We don't 𝑘𝑛𝑜𝑤 that the following item is an ADT
|
||||||
Applicability::MaybeIncorrect
|
Applicability::MaybeIncorrect
|
||||||
|
@ -1043,7 +1043,7 @@ impl<'a> Parser<'a> {
|
||||||
let semi_full_span = semi_span.to(self.sess.source_map().next_point(semi_span));
|
let semi_full_span = semi_span.to(self.sess.source_map().next_point(semi_span));
|
||||||
match self.sess.source_map().span_to_snippet(semi_full_span) {
|
match self.sess.source_map().span_to_snippet(semi_full_span) {
|
||||||
Ok(ref snippet) if &snippet[..] != ";" && kind_name == "expression" => {
|
Ok(ref snippet) if &snippet[..] != ";" && kind_name == "expression" => {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
semi_span,
|
semi_span,
|
||||||
"you might be missing a semicolon here",
|
"you might be missing a semicolon here",
|
||||||
";".to_owned(),
|
";".to_owned(),
|
||||||
|
@ -1574,7 +1574,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
|
||||||
_ => (String::from("<path>"), Applicability::HasPlaceholders),
|
_ => (String::from("<path>"), Applicability::HasPlaceholders),
|
||||||
};
|
};
|
||||||
|
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
it.span,
|
it.span,
|
||||||
"provide a file path with `=`",
|
"provide a file path with `=`",
|
||||||
format!("include = \"{}\"", path),
|
format!("include = \"{}\"", path),
|
||||||
|
|
|
@ -221,7 +221,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
|
||||||
if comma_span.is_dummy() {
|
if comma_span.is_dummy() {
|
||||||
err.note("you might be missing a comma");
|
err.note("you might be missing a comma");
|
||||||
} else {
|
} else {
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
comma_span,
|
comma_span,
|
||||||
"missing comma here",
|
"missing comma here",
|
||||||
", ".to_string(),
|
", ".to_string(),
|
||||||
|
|
|
@ -949,7 +949,7 @@ impl<'a> StringReader<'a> {
|
||||||
}
|
}
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
suggestion.push('}');
|
suggestion.push('}');
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
self.mk_sp(start, self.pos),
|
self.mk_sp(start, self.pos),
|
||||||
"format of unicode escape sequences uses braces",
|
"format of unicode escape sequences uses braces",
|
||||||
suggestion,
|
suggestion,
|
||||||
|
@ -1427,7 +1427,7 @@ impl<'a> StringReader<'a> {
|
||||||
self.sess.span_diagnostic
|
self.sess.span_diagnostic
|
||||||
.struct_span_err(span,
|
.struct_span_err(span,
|
||||||
"character literal may only contain one codepoint")
|
"character literal may only contain one codepoint")
|
||||||
.span_suggestion_with_applicability(
|
.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"if you meant to write a `str` literal, use double quotes",
|
"if you meant to write a `str` literal, use double quotes",
|
||||||
format!("\"{}\"", &self.src[start..end]),
|
format!("\"{}\"", &self.src[start..end]),
|
||||||
|
|
|
@ -336,7 +336,7 @@ crate fn check_for_substitution<'a>(reader: &StringReader<'a>,
|
||||||
let msg =
|
let msg =
|
||||||
format!("Unicode character '{}' ({}) looks like '{}' ({}), but it is not",
|
format!("Unicode character '{}' ({}) looks like '{}' ({}), but it is not",
|
||||||
ch, u_name, ascii_char, ascii_name);
|
ch, u_name, ascii_char, ascii_name);
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
&msg,
|
&msg,
|
||||||
ascii_char.to_string(),
|
ascii_char.to_string(),
|
||||||
|
|
|
@ -736,7 +736,7 @@ impl<'a> Parser<'a> {
|
||||||
};
|
};
|
||||||
let mut err = self.fatal(&msg_exp);
|
let mut err = self.fatal(&msg_exp);
|
||||||
if self.token.is_ident_named("and") {
|
if self.token.is_ident_named("and") {
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
self.span,
|
self.span,
|
||||||
"use `&&` instead of `and` for the boolean operator",
|
"use `&&` instead of `and` for the boolean operator",
|
||||||
"&&".to_string(),
|
"&&".to_string(),
|
||||||
|
@ -744,7 +744,7 @@ impl<'a> Parser<'a> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if self.token.is_ident_named("or") {
|
if self.token.is_ident_named("or") {
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
self.span,
|
self.span,
|
||||||
"use `||` instead of `or` for the boolean operator",
|
"use `||` instead of `or` for the boolean operator",
|
||||||
"||".to_string(),
|
"||".to_string(),
|
||||||
|
@ -810,7 +810,7 @@ impl<'a> Parser<'a> {
|
||||||
if ident.is_reserved() && !ident.is_path_segment_keyword() &&
|
if ident.is_reserved() && !ident.is_path_segment_keyword() &&
|
||||||
ident.name != keywords::Underscore.name()
|
ident.name != keywords::Underscore.name()
|
||||||
{
|
{
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
self.span,
|
self.span,
|
||||||
"you can escape reserved keywords to use them as identifiers",
|
"you can escape reserved keywords to use them as identifiers",
|
||||||
format!("r#{}", ident),
|
format!("r#{}", ident),
|
||||||
|
@ -823,7 +823,7 @@ impl<'a> Parser<'a> {
|
||||||
} else {
|
} else {
|
||||||
err.span_label(self.span, "expected identifier");
|
err.span_label(self.span, "expected identifier");
|
||||||
if self.token == token::Comma && self.look_ahead(1, |t| t.is_ident()) {
|
if self.token == token::Comma && self.look_ahead(1, |t| t.is_ident()) {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
self.span,
|
self.span,
|
||||||
"remove this comma",
|
"remove this comma",
|
||||||
String::new(),
|
String::new(),
|
||||||
|
@ -1696,7 +1696,7 @@ impl<'a> Parser<'a> {
|
||||||
if !allow_plus && impl_dyn_multi {
|
if !allow_plus && impl_dyn_multi {
|
||||||
let sum_with_parens = format!("({})", pprust::ty_to_string(&ty));
|
let sum_with_parens = format!("({})", pprust::ty_to_string(&ty));
|
||||||
self.struct_span_err(ty.span, "ambiguous `+` in a type")
|
self.struct_span_err(ty.span, "ambiguous `+` in a type")
|
||||||
.span_suggestion_with_applicability(
|
.span_suggestion(
|
||||||
ty.span,
|
ty.span,
|
||||||
"use parentheses to disambiguate",
|
"use parentheses to disambiguate",
|
||||||
sum_with_parens,
|
sum_with_parens,
|
||||||
|
@ -1731,7 +1731,7 @@ impl<'a> Parser<'a> {
|
||||||
s.print_type_bounds(" +", &bounds)?;
|
s.print_type_bounds(" +", &bounds)?;
|
||||||
s.pclose()
|
s.pclose()
|
||||||
});
|
});
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
sum_span,
|
sum_span,
|
||||||
"try adding parentheses",
|
"try adding parentheses",
|
||||||
sum_with_parens,
|
sum_with_parens,
|
||||||
|
@ -1774,7 +1774,7 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
self.diagnostic()
|
self.diagnostic()
|
||||||
.struct_span_err(span, "missing angle brackets in associated item path")
|
.struct_span_err(span, "missing angle brackets in associated item path")
|
||||||
.span_suggestion_with_applicability( // this is a best-effort recovery
|
.span_suggestion( // this is a best-effort recovery
|
||||||
span, "try", recovered.to_string(), Applicability::MaybeIncorrect
|
span, "try", recovered.to_string(), Applicability::MaybeIncorrect
|
||||||
).emit();
|
).emit();
|
||||||
|
|
||||||
|
@ -1878,7 +1878,7 @@ impl<'a> Parser<'a> {
|
||||||
let ident = self.parse_ident().unwrap();
|
let ident = self.parse_ident().unwrap();
|
||||||
let span = pat.span.with_hi(ident.span.hi());
|
let span = pat.span.with_hi(ident.span.hi());
|
||||||
|
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"declare the type after the parameter binding",
|
"declare the type after the parameter binding",
|
||||||
String::from("<identifier>: <type>"),
|
String::from("<identifier>: <type>"),
|
||||||
|
@ -1886,7 +1886,7 @@ impl<'a> Parser<'a> {
|
||||||
);
|
);
|
||||||
} else if require_name && is_trait_item {
|
} else if require_name && is_trait_item {
|
||||||
if let PatKind::Ident(_, ident, _) = pat.node {
|
if let PatKind::Ident(_, ident, _) = pat.node {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
pat.span,
|
pat.span,
|
||||||
"explicitly ignore parameter",
|
"explicitly ignore parameter",
|
||||||
format!("_: {}", ident),
|
format!("_: {}", ident),
|
||||||
|
@ -1937,7 +1937,7 @@ impl<'a> Parser<'a> {
|
||||||
"patterns aren't allowed in methods without bodies",
|
"patterns aren't allowed in methods without bodies",
|
||||||
DiagnosticId::Error("E0642".into()),
|
DiagnosticId::Error("E0642".into()),
|
||||||
);
|
);
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
pat.span,
|
pat.span,
|
||||||
"give this argument a name or use an underscore to ignore it",
|
"give this argument a name or use an underscore to ignore it",
|
||||||
"_".to_owned(),
|
"_".to_owned(),
|
||||||
|
@ -2034,7 +2034,7 @@ impl<'a> Parser<'a> {
|
||||||
let sp = lo.to(self.prev_span);
|
let sp = lo.to(self.prev_span);
|
||||||
let mut err = self.diagnostic()
|
let mut err = self.diagnostic()
|
||||||
.struct_span_err(sp, "float literals must have an integer part");
|
.struct_span_err(sp, "float literals must have an integer part");
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
sp,
|
sp,
|
||||||
"must have an integer part",
|
"must have an integer part",
|
||||||
format!("0.{}{}", val, suffix),
|
format!("0.{}{}", val, suffix),
|
||||||
|
@ -2365,7 +2365,7 @@ impl<'a> Parser<'a> {
|
||||||
if self.token == token::Eq {
|
if self.token == token::Eq {
|
||||||
self.diagnostic()
|
self.diagnostic()
|
||||||
.struct_span_err(self.span, "expected `:`, found `=`")
|
.struct_span_err(self.span, "expected `:`, found `=`")
|
||||||
.span_suggestion_with_applicability(
|
.span_suggestion(
|
||||||
fieldname.span.shrink_to_hi().to(self.span),
|
fieldname.span.shrink_to_hi().to(self.span),
|
||||||
"replace equals symbol with a colon",
|
"replace equals symbol with a colon",
|
||||||
":".to_string(),
|
":".to_string(),
|
||||||
|
@ -2751,7 +2751,7 @@ impl<'a> Parser<'a> {
|
||||||
exp_span.to(self.prev_span),
|
exp_span.to(self.prev_span),
|
||||||
"cannot use a comma after the base struct",
|
"cannot use a comma after the base struct",
|
||||||
);
|
);
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
self.span,
|
self.span,
|
||||||
"remove this comma",
|
"remove this comma",
|
||||||
String::new(),
|
String::new(),
|
||||||
|
@ -3019,7 +3019,7 @@ impl<'a> Parser<'a> {
|
||||||
span,
|
span,
|
||||||
&format!("unmatched angle bracket{}", if plural { "s" } else { "" }),
|
&format!("unmatched angle bracket{}", if plural { "s" } else { "" }),
|
||||||
)
|
)
|
||||||
.span_suggestion_with_applicability(
|
.span_suggestion(
|
||||||
span,
|
span,
|
||||||
&format!("remove extra angle bracket{}", if plural { "s" } else { "" }),
|
&format!("remove extra angle bracket{}", if plural { "s" } else { "" }),
|
||||||
String::new(),
|
String::new(),
|
||||||
|
@ -3072,7 +3072,7 @@ impl<'a> Parser<'a> {
|
||||||
s.s.word(".")?;
|
s.s.word(".")?;
|
||||||
s.s.word(fstr.splitn(2, ".").last().unwrap().to_string())
|
s.s.word(fstr.splitn(2, ".").last().unwrap().to_string())
|
||||||
});
|
});
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
lo.to(self.prev_span),
|
lo.to(self.prev_span),
|
||||||
"try parenthesizing the first index",
|
"try parenthesizing the first index",
|
||||||
sugg,
|
sugg,
|
||||||
|
@ -3219,7 +3219,7 @@ impl<'a> Parser<'a> {
|
||||||
let span_of_tilde = lo;
|
let span_of_tilde = lo;
|
||||||
let mut err = self.diagnostic()
|
let mut err = self.diagnostic()
|
||||||
.struct_span_err(span_of_tilde, "`~` cannot be used as a unary operator");
|
.struct_span_err(span_of_tilde, "`~` cannot be used as a unary operator");
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
span_of_tilde,
|
span_of_tilde,
|
||||||
"use `!` to perform bitwise negation",
|
"use `!` to perform bitwise negation",
|
||||||
"!".to_owned(),
|
"!".to_owned(),
|
||||||
|
@ -3292,7 +3292,7 @@ impl<'a> Parser<'a> {
|
||||||
// trailing whitespace after the `!` in our suggestion
|
// trailing whitespace after the `!` in our suggestion
|
||||||
let to_replace = self.sess.source_map()
|
let to_replace = self.sess.source_map()
|
||||||
.span_until_non_whitespace(lo.to(self.span));
|
.span_until_non_whitespace(lo.to(self.span));
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
to_replace,
|
to_replace,
|
||||||
"use `!` to perform logical negation",
|
"use `!` to perform logical negation",
|
||||||
"!".to_owned(),
|
"!".to_owned(),
|
||||||
|
@ -3393,7 +3393,7 @@ impl<'a> Parser<'a> {
|
||||||
let cur_pos = cm.lookup_char_pos(self.span.lo());
|
let cur_pos = cm.lookup_char_pos(self.span.lo());
|
||||||
let op_pos = cm.lookup_char_pos(cur_op_span.hi());
|
let op_pos = cm.lookup_char_pos(cur_op_span.hi());
|
||||||
if cur_pos.line != op_pos.line {
|
if cur_pos.line != op_pos.line {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
cur_op_span,
|
cur_op_span,
|
||||||
"try using a semicolon",
|
"try using a semicolon",
|
||||||
";".to_string(),
|
";".to_string(),
|
||||||
|
@ -3552,7 +3552,7 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
let expr_str = self.sess.source_map().span_to_snippet(expr.span)
|
let expr_str = self.sess.source_map().span_to_snippet(expr.span)
|
||||||
.unwrap_or_else(|_| pprust::expr_to_string(&expr));
|
.unwrap_or_else(|_| pprust::expr_to_string(&expr));
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("try {} the cast value", op_verb),
|
&format!("try {} the cast value", op_verb),
|
||||||
format!("({})", expr_str),
|
format!("({})", expr_str),
|
||||||
|
@ -3768,7 +3768,7 @@ impl<'a> Parser<'a> {
|
||||||
let in_span = self.prev_span.between(self.span);
|
let in_span = self.prev_span.between(self.span);
|
||||||
let mut err = self.sess.span_diagnostic
|
let mut err = self.sess.span_diagnostic
|
||||||
.struct_span_err(in_span, "missing `in` in `for` loop");
|
.struct_span_err(in_span, "missing `in` in `for` loop");
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
in_span, "try adding `in` here", " in ".into(),
|
in_span, "try adding `in` here", " in ".into(),
|
||||||
// has been misleading, at least in the past (closed Issue #48492)
|
// has been misleading, at least in the past (closed Issue #48492)
|
||||||
Applicability::MaybeIncorrect
|
Applicability::MaybeIncorrect
|
||||||
|
@ -3782,7 +3782,7 @@ impl<'a> Parser<'a> {
|
||||||
self.prev_span,
|
self.prev_span,
|
||||||
"expected iterable, found keyword `in`",
|
"expected iterable, found keyword `in`",
|
||||||
);
|
);
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
in_span.until(self.prev_span),
|
in_span.until(self.prev_span),
|
||||||
"remove the duplicated `in`",
|
"remove the duplicated `in`",
|
||||||
String::new(),
|
String::new(),
|
||||||
|
@ -3874,7 +3874,7 @@ impl<'a> Parser<'a> {
|
||||||
None)?;
|
None)?;
|
||||||
if let Err(mut e) = self.expect(&token::OpenDelim(token::Brace)) {
|
if let Err(mut e) = self.expect(&token::OpenDelim(token::Brace)) {
|
||||||
if self.token == token::Token::Semi {
|
if self.token == token::Token::Semi {
|
||||||
e.span_suggestion_short_with_applicability(
|
e.span_suggestion_short(
|
||||||
match_span,
|
match_span,
|
||||||
"try removing this `match`",
|
"try removing this `match`",
|
||||||
String::new(),
|
String::new(),
|
||||||
|
@ -3949,7 +3949,7 @@ impl<'a> Parser<'a> {
|
||||||
// | - ^^ self.span
|
// | - ^^ self.span
|
||||||
// | |
|
// | |
|
||||||
// | parsed until here as `"y" & X`
|
// | parsed until here as `"y" & X`
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
cm.next_point(arm_start_span),
|
cm.next_point(arm_start_span),
|
||||||
"missing a comma here to end this `match` arm",
|
"missing a comma here to end this `match` arm",
|
||||||
",".to_owned(),
|
",".to_owned(),
|
||||||
|
@ -4026,7 +4026,7 @@ impl<'a> Parser<'a> {
|
||||||
if self.token == token::OrOr {
|
if self.token == token::OrOr {
|
||||||
let mut err = self.struct_span_err(self.span,
|
let mut err = self.struct_span_err(self.span,
|
||||||
"unexpected token `||` after pattern");
|
"unexpected token `||` after pattern");
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
self.span,
|
self.span,
|
||||||
"use a single `|` to specify multiple patterns",
|
"use a single `|` to specify multiple patterns",
|
||||||
"|".to_owned(),
|
"|".to_owned(),
|
||||||
|
@ -4234,7 +4234,7 @@ impl<'a> Parser<'a> {
|
||||||
// Accept `...` as if it were `..` to avoid further errors
|
// Accept `...` as if it were `..` to avoid further errors
|
||||||
let mut err = self.struct_span_err(self.span,
|
let mut err = self.struct_span_err(self.span,
|
||||||
"expected field pattern, found `...`");
|
"expected field pattern, found `...`");
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
self.span,
|
self.span,
|
||||||
"to omit remaining fields, use one fewer `.`",
|
"to omit remaining fields, use one fewer `.`",
|
||||||
"..".to_owned(),
|
"..".to_owned(),
|
||||||
|
@ -4266,7 +4266,7 @@ 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_with_applicability(
|
err.span_suggestion_short(
|
||||||
sp,
|
sp,
|
||||||
"remove this comma",
|
"remove this comma",
|
||||||
String::new(),
|
String::new(),
|
||||||
|
@ -4308,7 +4308,7 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
if let Some(mut err) = delayed_err {
|
if let Some(mut err) = delayed_err {
|
||||||
if let Some(etc_span) = etc_span {
|
if let Some(etc_span) = etc_span {
|
||||||
err.multipart_suggestion_with_applicability(
|
err.multipart_suggestion(
|
||||||
"move the `..` to the end of the field list",
|
"move the `..` to the end of the field list",
|
||||||
vec![
|
vec![
|
||||||
(etc_span, String::new()),
|
(etc_span, String::new()),
|
||||||
|
@ -4379,7 +4379,7 @@ impl<'a> Parser<'a> {
|
||||||
let mut err = self.struct_span_err(comma_span,
|
let mut err = self.struct_span_err(comma_span,
|
||||||
"unexpected `,` in pattern");
|
"unexpected `,` in pattern");
|
||||||
if let Ok(seq_snippet) = self.sess.source_map().span_to_snippet(seq_span) {
|
if let Ok(seq_snippet) = self.sess.source_map().span_to_snippet(seq_span) {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
seq_span,
|
seq_span,
|
||||||
"try adding parentheses",
|
"try adding parentheses",
|
||||||
format!("({})", seq_snippet),
|
format!("({})", seq_snippet),
|
||||||
|
@ -4447,7 +4447,7 @@ impl<'a> Parser<'a> {
|
||||||
let binding_mode = if self.eat_keyword(keywords::Ref) {
|
let binding_mode = if self.eat_keyword(keywords::Ref) {
|
||||||
self.diagnostic()
|
self.diagnostic()
|
||||||
.struct_span_err(mutref_span, "the order of `mut` and `ref` is incorrect")
|
.struct_span_err(mutref_span, "the order of `mut` and `ref` is incorrect")
|
||||||
.span_suggestion_with_applicability(
|
.span_suggestion(
|
||||||
mutref_span,
|
mutref_span,
|
||||||
"try switching the order",
|
"try switching the order",
|
||||||
"ref mut".into(),
|
"ref mut".into(),
|
||||||
|
@ -4591,7 +4591,7 @@ impl<'a> Parser<'a> {
|
||||||
pat.span,
|
pat.span,
|
||||||
"the range pattern here has ambiguous interpretation",
|
"the range pattern here has ambiguous interpretation",
|
||||||
);
|
);
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
pat.span,
|
pat.span,
|
||||||
"add parentheses to clarify the precedence",
|
"add parentheses to clarify the precedence",
|
||||||
format!("({})", pprust::pat_to_string(&pat)),
|
format!("({})", pprust::pat_to_string(&pat)),
|
||||||
|
@ -4667,7 +4667,7 @@ impl<'a> Parser<'a> {
|
||||||
(Ok(init), Some((_, colon_sp, mut err))) => { // init parsed, ty error
|
(Ok(init), Some((_, colon_sp, mut err))) => { // init parsed, ty error
|
||||||
// Could parse the type as if it were the initializer, it is likely there was a
|
// Could parse the type as if it were the initializer, it is likely there was a
|
||||||
// typo in the code: `:` instead of `=`. Add suggestion and emit the error.
|
// typo in the code: `:` instead of `=`. Add suggestion and emit the error.
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
colon_sp,
|
colon_sp,
|
||||||
"use `=` if you meant to assign",
|
"use `=` if you meant to assign",
|
||||||
"=".to_string(),
|
"=".to_string(),
|
||||||
|
@ -5170,7 +5170,7 @@ impl<'a> Parser<'a> {
|
||||||
self.token.is_keyword(keywords::In) || self.token == token::Colon;
|
self.token.is_keyword(keywords::In) || self.token == token::Colon;
|
||||||
|
|
||||||
if self.token.is_ident_named("and") {
|
if self.token.is_ident_named("and") {
|
||||||
e.span_suggestion_short_with_applicability(
|
e.span_suggestion_short(
|
||||||
self.span,
|
self.span,
|
||||||
"use `&&` instead of `and` for the boolean operator",
|
"use `&&` instead of `and` for the boolean operator",
|
||||||
"&&".to_string(),
|
"&&".to_string(),
|
||||||
|
@ -5178,7 +5178,7 @@ impl<'a> Parser<'a> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if self.token.is_ident_named("or") {
|
if self.token.is_ident_named("or") {
|
||||||
e.span_suggestion_short_with_applicability(
|
e.span_suggestion_short(
|
||||||
self.span,
|
self.span,
|
||||||
"use `||` instead of `or` for the boolean operator",
|
"use `||` instead of `or` for the boolean operator",
|
||||||
"||".to_string(),
|
"||".to_string(),
|
||||||
|
@ -5213,7 +5213,7 @@ impl<'a> Parser<'a> {
|
||||||
s.print_stmt(&stmt)?;
|
s.print_stmt(&stmt)?;
|
||||||
s.bclose_maybe_open(stmt.span, INDENT_UNIT, false)
|
s.bclose_maybe_open(stmt.span, INDENT_UNIT, false)
|
||||||
});
|
});
|
||||||
e.span_suggestion_with_applicability(
|
e.span_suggestion(
|
||||||
stmt_span,
|
stmt_span,
|
||||||
"try placing this code inside a block",
|
"try placing this code inside a block",
|
||||||
sugg,
|
sugg,
|
||||||
|
@ -5331,10 +5331,10 @@ impl<'a> Parser<'a> {
|
||||||
fn err_dotdotdot_syntax(&self, span: Span) {
|
fn err_dotdotdot_syntax(&self, span: Span) {
|
||||||
self.diagnostic().struct_span_err(span, {
|
self.diagnostic().struct_span_err(span, {
|
||||||
"unexpected token: `...`"
|
"unexpected token: `...`"
|
||||||
}).span_suggestion_with_applicability(
|
}).span_suggestion(
|
||||||
span, "use `..` for an exclusive range", "..".to_owned(),
|
span, "use `..` for an exclusive range", "..".to_owned(),
|
||||||
Applicability::MaybeIncorrect
|
Applicability::MaybeIncorrect
|
||||||
).span_suggestion_with_applicability(
|
).span_suggestion(
|
||||||
span, "or `..=` for an inclusive range", "..=".to_owned(),
|
span, "or `..=` for an inclusive range", "..=".to_owned(),
|
||||||
Applicability::MaybeIncorrect
|
Applicability::MaybeIncorrect
|
||||||
).emit();
|
).emit();
|
||||||
|
@ -5534,7 +5534,7 @@ impl<'a> Parser<'a> {
|
||||||
"lifetime parameters must be declared prior to type parameters",
|
"lifetime parameters must be declared prior to type parameters",
|
||||||
);
|
);
|
||||||
if !suggestions.is_empty() {
|
if !suggestions.is_empty() {
|
||||||
err.multipart_suggestion_with_applicability(
|
err.multipart_suggestion(
|
||||||
"move the lifetime parameter prior to the first type parameter",
|
"move the lifetime parameter prior to the first type parameter",
|
||||||
suggestions,
|
suggestions,
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
|
@ -5702,7 +5702,7 @@ impl<'a> Parser<'a> {
|
||||||
if plural { "s" } else { "" }
|
if plural { "s" } else { "" }
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.span_suggestion_with_applicability(
|
.span_suggestion(
|
||||||
span,
|
span,
|
||||||
&format!(
|
&format!(
|
||||||
"remove extra angle bracket{}",
|
"remove extra angle bracket{}",
|
||||||
|
@ -5863,7 +5863,7 @@ impl<'a> Parser<'a> {
|
||||||
suggestions.extend_from_slice(&type_suggestions);
|
suggestions.extend_from_slice(&type_suggestions);
|
||||||
|
|
||||||
let plural = bad_lifetime_pos.len() + bad_type_pos.len() > 1;
|
let plural = bad_lifetime_pos.len() + bad_type_pos.len() > 1;
|
||||||
err.multipart_suggestion_with_applicability(
|
err.multipart_suggestion(
|
||||||
&format!(
|
&format!(
|
||||||
"move the parameter{}",
|
"move the parameter{}",
|
||||||
if plural { "s" } else { "" },
|
if plural { "s" } else { "" },
|
||||||
|
@ -5872,7 +5872,7 @@ impl<'a> Parser<'a> {
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
} else if !lifetime_suggestions.is_empty() {
|
} else if !lifetime_suggestions.is_empty() {
|
||||||
err.multipart_suggestion_with_applicability(
|
err.multipart_suggestion(
|
||||||
&format!(
|
&format!(
|
||||||
"move the lifetime parameter{} prior to the first type parameter",
|
"move the lifetime parameter{} prior to the first type parameter",
|
||||||
if bad_lifetime_pos.len() > 1 { "s" } else { "" },
|
if bad_lifetime_pos.len() > 1 { "s" } else { "" },
|
||||||
|
@ -5881,7 +5881,7 @@ impl<'a> Parser<'a> {
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
} else if !type_suggestions.is_empty() {
|
} else if !type_suggestions.is_empty() {
|
||||||
err.multipart_suggestion_with_applicability(
|
err.multipart_suggestion(
|
||||||
&format!(
|
&format!(
|
||||||
"move the type parameter{} prior to the first associated type binding",
|
"move the type parameter{} prior to the first associated type binding",
|
||||||
if bad_type_pos.len() > 1 { "s" } else { "" },
|
if bad_type_pos.len() > 1 { "s" } else { "" },
|
||||||
|
@ -6385,7 +6385,7 @@ impl<'a> Parser<'a> {
|
||||||
let mut err = if is_macro_rules {
|
let mut err = if is_macro_rules {
|
||||||
let mut err = self.diagnostic()
|
let mut err = self.diagnostic()
|
||||||
.struct_span_err(sp, "can't qualify macro_rules invocation with `pub`");
|
.struct_span_err(sp, "can't qualify macro_rules invocation with `pub`");
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
sp,
|
sp,
|
||||||
"try exporting the macro",
|
"try exporting the macro",
|
||||||
"#[macro_export]".to_owned(),
|
"#[macro_export]".to_owned(),
|
||||||
|
@ -6593,7 +6593,7 @@ impl<'a> Parser<'a> {
|
||||||
// impl Trait for Type
|
// impl Trait for Type
|
||||||
if !has_for {
|
if !has_for {
|
||||||
self.struct_span_err(missing_for_span, "missing `for` in a trait impl")
|
self.struct_span_err(missing_for_span, "missing `for` in a trait impl")
|
||||||
.span_suggestion_short_with_applicability(
|
.span_suggestion_short(
|
||||||
missing_for_span,
|
missing_for_span,
|
||||||
"add `for` here",
|
"add `for` here",
|
||||||
" for ".to_string(),
|
" for ".to_string(),
|
||||||
|
@ -6817,7 +6817,7 @@ impl<'a> Parser<'a> {
|
||||||
} else {
|
} else {
|
||||||
if seen_comma == false {
|
if seen_comma == false {
|
||||||
let sp = self.sess.source_map().next_point(previous_span);
|
let sp = self.sess.source_map().next_point(previous_span);
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
sp,
|
sp,
|
||||||
"missing comma here",
|
"missing comma here",
|
||||||
",".into(),
|
",".into(),
|
||||||
|
@ -6833,7 +6833,7 @@ impl<'a> Parser<'a> {
|
||||||
self.this_token_descr()));
|
self.this_token_descr()));
|
||||||
if self.token.is_ident() {
|
if self.token.is_ident() {
|
||||||
// This is likely another field; emit the diagnostic and keep going
|
// This is likely another field; emit the diagnostic and keep going
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
sp,
|
sp,
|
||||||
"try adding a comma",
|
"try adding a comma",
|
||||||
",".into(),
|
",".into(),
|
||||||
|
@ -6931,7 +6931,7 @@ impl<'a> Parser<'a> {
|
||||||
self.expect(&token::CloseDelim(token::Paren))?; // `)`
|
self.expect(&token::CloseDelim(token::Paren))?; // `)`
|
||||||
let mut err = struct_span_err!(self.sess.span_diagnostic, sp, E0704, "{}", msg);
|
let mut err = struct_span_err!(self.sess.span_diagnostic, sp, E0704, "{}", msg);
|
||||||
err.help(suggestion);
|
err.help(suggestion);
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
sp, &help_msg, format!("in {}", path), Applicability::MachineApplicable
|
sp, &help_msg, format!("in {}", path), Applicability::MachineApplicable
|
||||||
);
|
);
|
||||||
err.emit(); // emit diagnostic, but continue with public visibility
|
err.emit(); // emit diagnostic, but continue with public visibility
|
||||||
|
@ -6962,7 +6962,7 @@ impl<'a> Parser<'a> {
|
||||||
fn maybe_consume_incorrect_semicolon(&mut self, items: &[P<Item>]) -> bool {
|
fn maybe_consume_incorrect_semicolon(&mut self, items: &[P<Item>]) -> bool {
|
||||||
if self.eat(&token::Semi) {
|
if self.eat(&token::Semi) {
|
||||||
let mut err = self.struct_span_err(self.prev_span, "expected item, found `;`");
|
let mut err = self.struct_span_err(self.prev_span, "expected item, found `;`");
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
self.prev_span,
|
self.prev_span,
|
||||||
"remove this semicolon",
|
"remove this semicolon",
|
||||||
String::new(),
|
String::new(),
|
||||||
|
@ -7390,7 +7390,7 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
let mut err = self.struct_span_err(fixed_name_sp, error_msg);
|
let mut err = self.struct_span_err(fixed_name_sp, error_msg);
|
||||||
err.span_label(fixed_name_sp, "dash-separated idents are not valid");
|
err.span_label(fixed_name_sp, "dash-separated idents are not valid");
|
||||||
err.multipart_suggestion_with_applicability(
|
err.multipart_suggestion(
|
||||||
suggestion_msg,
|
suggestion_msg,
|
||||||
replacement,
|
replacement,
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
|
@ -7759,7 +7759,7 @@ impl<'a> Parser<'a> {
|
||||||
let mut err = self.diagnostic()
|
let mut err = self.diagnostic()
|
||||||
.struct_span_err(prev_span, "const globals cannot be mutable");
|
.struct_span_err(prev_span, "const globals cannot be mutable");
|
||||||
err.span_label(prev_span, "cannot be mutable");
|
err.span_label(prev_span, "cannot be mutable");
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
const_span,
|
const_span,
|
||||||
"you might want to declare a static instead",
|
"you might want to declare a static instead",
|
||||||
"static".to_owned(),
|
"static".to_owned(),
|
||||||
|
@ -7996,7 +7996,7 @@ impl<'a> Parser<'a> {
|
||||||
ident);
|
ident);
|
||||||
let mut err = self.diagnostic()
|
let mut err = self.diagnostic()
|
||||||
.struct_span_err(sp, "missing `struct` for struct definition");
|
.struct_span_err(sp, "missing `struct` for struct definition");
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
sp, &msg, " struct ".into(), Applicability::MaybeIncorrect // speculative
|
sp, &msg, " struct ".into(), Applicability::MaybeIncorrect // speculative
|
||||||
);
|
);
|
||||||
return Err(err);
|
return Err(err);
|
||||||
|
@ -8031,12 +8031,12 @@ impl<'a> Parser<'a> {
|
||||||
kw,
|
kw,
|
||||||
ident,
|
ident,
|
||||||
kw_name);
|
kw_name);
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
sp, &suggestion, format!(" {} ", kw), Applicability::MachineApplicable
|
sp, &suggestion, format!(" {} ", kw), Applicability::MachineApplicable
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if let Ok(snippet) = self.sess.source_map().span_to_snippet(ident_sp) {
|
if let Ok(snippet) = self.sess.source_map().span_to_snippet(ident_sp) {
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
full_sp,
|
full_sp,
|
||||||
"if you meant to call a macro, try",
|
"if you meant to call a macro, try",
|
||||||
format!("{}!", snippet),
|
format!("{}!", snippet),
|
||||||
|
@ -8067,7 +8067,7 @@ impl<'a> Parser<'a> {
|
||||||
let msg = format!("missing `{}` for {} definition", kw, kw_name);
|
let msg = format!("missing `{}` for {} definition", kw, kw_name);
|
||||||
let mut err = self.diagnostic().struct_span_err(sp, &msg);
|
let mut err = self.diagnostic().struct_span_err(sp, &msg);
|
||||||
if !ambiguous {
|
if !ambiguous {
|
||||||
err.span_suggestion_short_with_applicability(
|
err.span_suggestion_short(
|
||||||
sp,
|
sp,
|
||||||
&format!("add `{}` here to parse `{}` as a public {}", kw, ident, kw_name),
|
&format!("add `{}` here to parse `{}` as a public {}", kw, ident, kw_name),
|
||||||
format!(" {} ", kw),
|
format!(" {} ", kw),
|
||||||
|
@ -8094,7 +8094,7 @@ impl<'a> Parser<'a> {
|
||||||
if self.token.is_keyword(keywords::Const) {
|
if self.token.is_keyword(keywords::Const) {
|
||||||
self.diagnostic()
|
self.diagnostic()
|
||||||
.struct_span_err(self.span, "extern items cannot be `const`")
|
.struct_span_err(self.span, "extern items cannot be `const`")
|
||||||
.span_suggestion_with_applicability(
|
.span_suggestion(
|
||||||
self.span,
|
self.span,
|
||||||
"try using a static value",
|
"try using a static value",
|
||||||
"static".to_owned(),
|
"static".to_owned(),
|
||||||
|
|
|
@ -763,7 +763,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
|
||||||
0 => "{}".to_string(),
|
0 => "{}".to_string(),
|
||||||
_ => format!("{}{{}}", "{} ".repeat(args.len())),
|
_ => format!("{}{{}}", "{} ".repeat(args.len())),
|
||||||
};
|
};
|
||||||
err.span_suggestion_with_applicability(
|
err.span_suggestion(
|
||||||
fmt_sp.shrink_to_lo(),
|
fmt_sp.shrink_to_lo(),
|
||||||
"you might be missing a string literal to format with",
|
"you might be missing a string literal to format with",
|
||||||
format!("\"{}\", ", sugg_fmt),
|
format!("\"{}\", ", sugg_fmt),
|
||||||
|
@ -1080,7 +1080,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if suggestions.len() > 0 {
|
if suggestions.len() > 0 {
|
||||||
diag.multipart_suggestion_with_applicability(
|
diag.multipart_suggestion(
|
||||||
"format specifiers use curly braces",
|
"format specifiers use curly braces",
|
||||||
suggestions,
|
suggestions,
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue