if let Ok(snippet) = self.sess.source_map().span_to_snippet(data.span) {
// Do not suggest going from `Trait()` to `Trait<>`
if data.inputs.len() > 0 {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
data.span,
"use angle brackets instead",
format!("<{}>", &snippet[1..snippet.len() - 1]),
if let Some(ty::error::ExpectedFound { found, .. }) = exp_found {
if ty.is_box() && ty.boxed_ty() == found {
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"consider dereferencing the boxed value",
format!("*{}", snippet),
err.span_label(then, "expected because of this");
outer.map(|sp| err.span_label(sp, "if and else have incompatible types"));
if let Some(sp) = semicolon {
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
sp,
"consider removing this semicolon",
String::new(),
self.tcx.sess.source_map().span_to_snippet(span),
show_suggestion,
) {
- diag.span_suggestion_with_applicability(
+ diag.span_suggestion(
span,
msg,
format!("{}.as_ref()", snippet),
let tail = if has_lifetimes { " + " } else { "" };
format!("{}: {}{}", bound_kind, sub, tail)
};
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
sp,
&consider,
suggestion,
E0621,
"explicit lifetime required in {}",
error_var
- ).span_suggestion_with_applicability(
+ ).span_suggestion(
new_ty_span,
&format!("add explicit lifetime `{}` to {}", named, span_label_var),
new_ty.to_string(),
_ => "'_".to_owned(),
};
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(return_sp) {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
return_sp,
&format!(
"you can add a constraint to the return type to make it last \
Ok(s) => (format!("dyn {}", s), Applicability::MachineApplicable),
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) => {
let (sugg, app) = match sess.source_map().span_to_snippet(span) {
}
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) => {
db.span_label(later_span, format!("`{}` already exported", ident));
(insertion_span, anon_lts)
}
};
- db.span_suggestion_with_applicability(
+ db.span_suggestion(
replace_span,
&format!("indicate the anonymous lifetime{}", if n >= 2 { "s" } else { "" }),
suggestion,
);
}
BuiltinLintDiagnostics::UnknownCrateTypes(span, note, sugg) => {
- db.span_suggestion_with_applicability(
- span,
- ¬e,
- sugg,
- Applicability::MaybeIncorrect
- );
+ db.span_suggestion(span, ¬e, sugg, Applicability::MaybeIncorrect);
}
}
}
Some(li.span.into()),
&msg,
);
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
li.span,
"change it to",
new_lint_name.to_string(),
Some(li.span.into()),
&msg);
if let Some(new_name) = renamed {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
li.span,
"use the new name",
new_name,
&msg);
if let Some(suggestion) = suggestion {
- db.span_suggestion_with_applicability(
+ db.span_suggestion(
li.span,
"did you mean",
suggestion.to_string(),
let mut err = self.ir.tcx
.struct_span_lint_hir(lint::builtin::UNUSED_VARIABLES, hir_id, sp, &msg);
if self.ir.variable_is_shorthand(var) {
- err.span_suggestion_with_applicability(sp, "try ignoring the field",
- format!("{}: _", name),
- Applicability::MachineApplicable);
+ err.span_suggestion(
+ sp,
+ "try ignoring the field",
+ format!("{}: _", name),
+ Applicability::MachineApplicable,
+ );
} else {
- err.span_suggestion_short_with_applicability(
- sp, &suggest_underscore_msg,
+ err.span_suggestion_short(
+ sp,
+ &suggest_underscore_msg,
format!("_{}", name),
Applicability::MachineApplicable,
);
// place ("start at" because the latter includes trailing
// whitespace), then this is an in-band lifetime
if decl_span.shrink_to_lo() == use_span.shrink_to_lo() {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
use_span,
"elide the single-use lifetime",
String::new(),
Applicability::MachineApplicable,
);
} else {
- err.multipart_suggestion_with_applicability(
+ err.multipart_suggestion(
"elide the single-use lifetime",
vec![(decl_span, String::new()), (use_span, String::new())],
Applicability::MachineApplicable,
if let Some(generics) = self.tcx.hir().get_generics(parent_def_id) {
let unused_lt_span = self.lifetime_deletion_span(name, generics);
if let Some(span) = unused_lt_span {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"elide the unused lifetime",
String::new(),
} else {
(format!("{} + 'static", snippet), Applicability::MaybeIncorrect)
};
- db.span_suggestion_with_applicability(span, msg, sugg, applicability);
+ db.span_suggestion(span, msg, sugg, applicability);
false
}
Err(_) => {
}
DiagnosticBuilderMethod::SpanSuggestion(suggestion) => {
let span = span_maybe.expect("span_suggestion_* needs a span");
- diag_builder.span_suggestion_with_applicability(
+ diag_builder.span_suggestion(
span,
message,
suggestion,
if let Some(ref expr) = local.init {
if let hir::ExprKind::Index(_, _) = expr.node {
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(expr.span) {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
"consider borrowing here",
format!("&{}", snippet),
let format_str = format!("consider removing {} leading `&`-references",
remove_refs);
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
sp, &format_str, String::new(), Applicability::MachineApplicable
);
break;
// For example, if `expected_args_length` is 2, suggest `|_, _|`.
if found_args.is_empty() && is_closure {
let underscores = vec!["_"; expected_args.len()].join(", ");
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
pipe_span,
&format!(
"consider changing the closure to take and ignore the expected argument{}",
.map(|(name, _)| name.to_owned())
.collect::<Vec<String>>()
.join(", ");
- err.span_suggestion_with_applicability(found_span,
- "change the closure to take multiple \
- arguments instead of a single tuple",
- format!("|{}|", sugg),
- Applicability::MachineApplicable);
+ err.span_suggestion(
+ found_span,
+ "change the closure to take multiple arguments instead of a single tuple",
+ format!("|{}|", sugg),
+ Applicability::MachineApplicable,
+ );
}
}
if let &[ArgKind::Tuple(_, ref fields)] = &expected_args[..] {
String::new()
},
);
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
found_span,
- "change the closure to accept a tuple instead of \
- individual arguments",
+ "change the closure to accept a tuple instead of individual arguments",
sugg,
- Applicability::MachineApplicable
+ Applicability::MachineApplicable,
);
}
}
{
if let Ok(snippet) = self.sess.source_map().span_to_snippet(sp) {
if snippet.chars().all(|c| c.is_digit(10) || c == '-' || c == '_') {
- db.span_suggestion_with_applicability(
+ db.span_suggestion(
sp,
"use a float literal",
format!("{}.0", snippet),
let initializer =
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) {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
initializer.span,
"consider using a reference instead",
format!("&{}", snippet),
}) = cmt.cat {
db.note(fn_closure_msg);
} else {
- db.span_suggestion_with_applicability(
+ db.span_suggestion(
sp,
msg,
suggestion,
);
}
} else {
- db.span_suggestion_with_applicability(
+ db.span_suggestion(
sp,
msg,
suggestion,
let let_span = self.tcx.hir().span(node_id);
let suggestion = suggest_ref_mut(self.tcx, let_span);
if let Some(replace_str) = suggestion {
- db.span_suggestion_with_applicability(
+ db.span_suggestion(
let_span,
"use a mutable reference instead",
replace_str,
)) = ty.map(|t| &t.node)
{
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),
"consider removing the `&mut`, as it is an \
immutable binding to a mutable reference",
Applicability::MachineApplicable,
);
} else {
- db.span_suggestion_with_applicability(
+ db.span_suggestion(
let_span,
"make this binding mutable",
format!("mut {}", snippet),
&cmt_path_or_string,
capture_span,
Origin::Ast)
- .span_suggestion_with_applicability(
+ .span_suggestion(
err.span,
&format!("to force the closure to take ownership of {} \
(and any other referenced variables), \
hir_id,
span,
"variable does not need to be mutable")
- .span_suggestion_short_with_applicability(
+ .span_suggestion_short(
mut_span,
"remove this `mut`",
String::new(),
- Applicability::MachineApplicable)
+ Applicability::MachineApplicable,
+ )
.emit();
}
}
self
}
- /// Prints out a message with a suggested edit of the code. If the suggestion is presented
- /// 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(
+ pub fn multipart_suggestion(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
self
}
- #[deprecated(note = "Use `multipart_suggestion_with_applicability`")]
- pub fn multipart_suggestion(
- &mut self,
- msg: &str,
- suggestion: Vec<(Span, String)>,
- ) -> &mut Self {
- self.multipart_suggestion_with_applicability(
- msg,
- suggestion,
- Applicability::Unspecified,
- )
- }
-
- /// Prints out a message with multiple suggested edits of the code.
- #[deprecated(note = "Use `span_suggestions_with_applicability`")]
- pub fn span_suggestions(&mut self, sp: Span, msg: &str, suggestions: Vec<String>) -> &mut Self {
- self.suggestions.push(CodeSuggestion {
- substitutions: suggestions.into_iter().map(|snippet| Substitution {
- 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,
+ /// 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:
+ ///
+ /// ```text
+ /// try adding parentheses: `(tup.0).1`
+ /// ```
+ ///
+ /// The message
+ ///
+ /// * 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.
+ /// * 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.
+ pub fn span_suggestion(&mut self, sp: Span, msg: &str,
suggestion: String,
applicability: Applicability) -> &mut Self {
self.suggestions.push(CodeSuggestion {
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
{
self.suggestions.push(CodeSuggestion {
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 {
self.suggestions.push(CodeSuggestion {
) => {
$(#[$attrs])*
pub fn $n(&self, $($name: $ty),*) -> &Self {
- #[allow(deprecated)]
self.diagnostic.$n($($name),*);
self
}
) => {
$(#[$attrs])*
pub fn $n(&mut self, $($name: $ty),*) -> &mut Self {
- #[allow(deprecated)]
self.diagnostic.$n($($name),*);
self
}
) => {
$(#[$attrs])*
pub fn $n<S: Into<MultiSpan>>(&mut self, $($name: $ty),*) -> &mut Self {
- #[allow(deprecated)]
self.diagnostic.$n($($name),*);
self
}
msg: &str,
) -> &mut Self);
- forward!(
- #[deprecated(note = "Use `span_suggestion_short_with_applicability`")]
- pub fn span_suggestion_short(
- &mut self,
- sp: Span,
- msg: &str,
- 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 {
+ pub fn multipart_suggestion(
+ &mut self,
+ msg: &str,
+ suggestion: Vec<(Span, String)>,
+ applicability: Applicability,
+ ) -> &mut Self {
if !self.allow_suggestions {
return self
}
- self.diagnostic.multipart_suggestion_with_applicability(
+ self.diagnostic.multipart_suggestion(
msg,
suggestion,
applicability,
self
}
- pub fn span_suggestion_with_applicability(&mut self,
- sp: Span,
- msg: &str,
- suggestion: String,
- applicability: Applicability)
- -> &mut Self {
+ pub fn span_suggestion(
+ &mut self,
+ sp: Span,
+ msg: &str,
+ suggestion: String,
+ applicability: Applicability,
+ ) -> &mut Self {
if !self.allow_suggestions {
return self
}
- self.diagnostic.span_suggestion_with_applicability(
+ self.diagnostic.span_suggestion(
sp,
msg,
suggestion,
self
}
- pub fn span_suggestions_with_applicability(&mut self,
- sp: Span,
- msg: &str,
- suggestions: impl Iterator<Item = String>,
- applicability: Applicability)
- -> &mut Self {
+ pub fn span_suggestions(
+ &mut self,
+ sp: Span,
+ msg: &str,
+ suggestions: impl Iterator<Item = String>,
+ applicability: Applicability,
+ ) -> &mut Self {
if !self.allow_suggestions {
return self
}
- self.diagnostic.span_suggestions_with_applicability(
+ self.diagnostic.span_suggestions(
sp,
msg,
suggestions,
self
}
- pub fn span_suggestion_short_with_applicability(&mut self,
- sp: Span,
- msg: &str,
- suggestion: String,
- applicability: Applicability)
- -> &mut Self {
+ pub fn span_suggestion_short(
+ &mut self,
+ sp: Span,
+ msg: &str,
+ suggestion: String,
+ applicability: Applicability,
+ ) -> &mut Self {
if !self.allow_suggestions {
return self
}
- self.diagnostic.span_suggestion_short_with_applicability(
+ self.diagnostic.span_suggestion_short(
sp,
msg,
suggestion,
let msg = "denote infinite loops with `loop { ... }`";
let condition_span = cx.tcx.sess.source_map().def_span(e.span);
let mut err = cx.struct_span_lint(WHILE_TRUE, condition_span, msg);
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
condition_span,
"use `loop`",
"loop".to_owned(),
&format!("the `{}:` in this pattern is redundant", ident));
let subspan = cx.tcx.sess.source_map().span_through_char(fieldpat.span,
':');
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
subspan,
"remove this",
ident.to_string(),
arg.pat.span,
"anonymous parameters are deprecated and will be \
removed in the next edition."
- ).span_suggestion_with_applicability(
+ ).span_suggestion(
arg.pat.span,
"Try naming the parameter or explicitly \
ignoring it",
let msg = format!("use of deprecated attribute `{}`: {}. See {}",
name, reason, link);
let mut err = cx.struct_span_lint(DEPRECATED, attr.span, &msg);
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
attr.span,
suggestion.unwrap_or("remove this attribute"),
String::new(),
it.span,
"functions generic over \
types must be mangled");
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
no_mangle_attr.span,
"remove this attribute",
String::new(),
.unwrap_or(0) as u32;
// `const` is 5 chars
let const_span = it.span.with_hi(BytePos(it.span.lo().0 + start + 5));
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
const_span,
"try a static value",
"pub static".to_owned(),
"pub(crate)"
}.to_owned();
- err.span_suggestion_with_applicability(vis.span,
- "consider restricting its visibility",
- replacement,
- applicability);
+ err.span_suggestion(
+ vis.span,
+ "consider restricting its visibility",
+ replacement,
+ applicability,
+ );
if exportable {
err.help("or consider exporting it for use by other crates");
}
if parenthesise {
*visit_subpats = false;
let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, pat.span, msg);
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
pat.span,
suggestion,
format!("&({}..={})", expr_to_string(&start), expr_to_string(&end)),
err.emit();
} else {
let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, join, msg);
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
join,
suggestion,
"..=".to_owned(),
E0721,
"`await` is a keyword in the {} edition", cur_edition,
);
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
ident.span,
"you can use a raw identifier to stay compatible",
"r#await".to_string(),
ident.as_str(),
next_edition),
);
- lint.span_suggestion_with_applicability(
+ lint.span_suggestion(
ident.span,
"you can use a raw identifier to stay compatible",
format!("r#{}", ident.as_str()),
lint_spans.clone(),
"outlives requirements can be inferred"
);
- err.multipart_suggestion_with_applicability(
+ err.multipart_suggestion(
if bound_count == 1 {
"remove this bound"
} else {
let msg = format!("{} `{}` should have a camel case name", sort, name);
cx.struct_span_lint(NON_CAMEL_CASE_TYPES, ident.span, &msg)
- .span_suggestion_with_applicability(
+ .span_suggestion(
ident.span,
"convert the identifier to camel case",
c,
// 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.
if !ident.span.is_dummy() {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
ident.span,
"convert the identifier to snake case",
sc,
let msg = format!("{} `{}` should have an upper case name", sort, name);
cx.struct_span_lint(NON_UPPER_CASE_GLOBALS, ident.span, &msg)
- .span_suggestion_with_applicability(
+ .span_suggestion(
ident.span,
"convert the identifier to upper case",
uc,
OVERFLOWING_LITERALS,
parent_expr.span,
"only u8 can be cast into char");
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
parent_expr.span,
&"use a char literal instead",
format!("'\\u{{{:X}}}'", lit_val),
{
if let Some(pos) = repr_str.chars().position(|c| c == 'i' || c == 'u') {
let (sans_suffix, _) = repr_str.split_at(pos);
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("consider using `{}` instead", sugg_ty),
format!("{}{}", sans_suffix, sugg_ty),
_ => false,
}
}).to_owned();
- err.span_suggestion_short_with_applicability(
- span,
- "remove these parentheses",
- parens_removed,
- Applicability::MachineApplicable
- );
+ err.span_suggestion_short(
+ span,
+ "remove these parentheses",
+ parens_removed,
+ Applicability::MachineApplicable,
+ );
err.emit();
}
}
Err(_) => "move |<args>| <body>".to_string()
};
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
args_span,
&format!("to force the closure to take ownership of {} (and any \
other referenced variables), use the `move` keyword",
if let Some(decl) = local_decl {
if let Some(name) = decl.name {
if decl.can_be_made_mutable() {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
decl.source_info.span,
"make this binding mutable",
format!("mut {}", name),
span,
"variable does not need to be mutable",
)
- .span_suggestion_short_with_applicability(
+ .span_suggestion_short(
mut_span,
"remove this `mut`",
String::new(),
// expressions `a[b]`, which roughly desugar to
// `*Index::index(&a, b)` or
// `*IndexMut::index_mut(&mut a, b)`.
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"consider removing the `*`",
snippet[1..].to_owned(),
Applicability::Unspecified,
);
} else {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"consider borrowing here",
format!("&{}", snippet),
suggestions.sort_unstable_by_key(|&(span, _, _)| span);
suggestions.dedup_by_key(|&mut (span, _, _)| span);
for (span, to_remove, suggestion) in suggestions {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
&format!("consider removing the `{}`", to_remove),
suggestion,
base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx),
field,
) {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"consider changing this to be mutable",
message,
assert_eq!(local_decl.mutability, Mutability::Not);
err.span_label(span, format!("cannot {ACT}", ACT = act));
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
local_decl.source_info.span,
"consider changing this to be mutable",
format!("mut {}", local_decl.name.unwrap()),
_,
) = pat.node
{
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
upvar_ident.span,
"consider changing this to be mutable",
format!("mut {}", upvar_ident.name),
};
if let Some((err_help_span, suggested_code)) = suggestion {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
err_help_span,
&format!("consider changing this to be a mutable {}", pointer_desc),
suggested_code,
"'_".to_string()
};
- diag.span_suggestion_with_applicability(
+ diag.span_suggestion(
span,
&format!(
"to allow this impl Trait to capture borrowed data with lifetime \
"pattern binding `{}` is named the same as one \
of the variants of the type `{}`",
ident, ty_path);
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
p.span,
"to match on the variant, qualify the path",
format!("{}::{}", ty_path, ident),
);
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),
Applicability::MachineApplicable,
);
);
match val.node {
ExprKind::Lit(ref v) if v.node.is_numeric() => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
place.span.between(val.span),
"if you meant to write a comparison against a negative value, add a \
space in between `<` and `-`",
.span_label(e.span,
"can only break with a value inside \
`loop` or breakable block")
- .span_suggestion_with_applicability(
+ .span_suggestion(
e.span,
&format!(
"instead, use `break` on its own \
let module = if orig_name.is_none() && ident.name == keywords::SelfLower.name() {
self.session
.struct_span_err(item.span, "`extern crate self;` requires renaming")
- .span_suggestion_with_applicability(
+ .span_suggestion(
item.span,
"try",
"extern crate self as name;".into(),
let sugg_msg = "try using a local type parameter instead";
if let Some((sugg_span, new_snippet)) = cm.generate_local_type_param_snippet(span) {
// Suggest the modification to the user
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
sugg_span,
sugg_msg,
new_snippet,
// Emit help message for fake-self from other languages like `this`(javascript)
if ["this", "my"].contains(&&*item_str.as_str())
&& this.self_value_is_available(path[0].ident.span, span) {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"did you mean",
"self".to_string(),
};
let msg = format!("{}try using the variant's enum", preamble);
- err.span_suggestions_with_applicability(
+ err.span_suggestions(
span,
&msg,
enum_candidates.into_iter()
let self_is_available = this.self_value_is_available(path[0].ident.span, span);
match candidate {
AssocSuggestion::Field => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"try",
format!("self.{}", path_str),
}
}
AssocSuggestion::MethodWithSelf if self_is_available => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"try",
format!("self.{}", path_str),
);
}
AssocSuggestion::MethodWithSelf | AssocSuggestion::AssocItem => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"try",
format!("Self::{}", path_str),
"{} {} with a similar name exists",
suggestion.article, suggestion.kind
);
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
ident_span,
&msg,
suggestion.candidate.to_string(),
if let Some(def) = def {
match (def, source) {
(Def::Macro(..), _) => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"use `!` to invoke the macro",
format!("{}!", path_str),
}
(Def::Mod(..), PathSource::Expr(Some(parent))) => match parent.node {
ExprKind::Field(_, ident) => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
parent.span,
"use the path separator to refer to an item",
format!("{}::{}", path_str, ident),
}
ExprKind::MethodCall(ref segment, ..) => {
let span = parent.span.with_hi(segment.ident.span.hi());
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"use the path separator to refer to an item",
format!("{}::{}", path_str, segment.ident),
PathSource::Expr(Some(parent)) => {
match parent.node {
ExprKind::MethodCall(ref path_assignment, _) => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
sm.start_point(parent.span)
.to(path_assignment.ident.span),
"use `::` to access an associated function",
},
PathSource::Expr(None) if followed_by_brace == true => {
if let Some((sp, snippet)) = closing_brace {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
sp,
"surround the struct literal with parenthesis",
format!("({})", snippet),
err.span_label(base_span,
"expecting a type here because of type ascription");
if line_sp != line_base_sp {
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
sp,
"did you mean to use `;` here instead?",
";".to_string(),
} else if ident.span.rust_2018() {
let msg = "relative paths are not supported in visibilities on 2018 edition";
self.session.struct_span_err(ident.span, msg)
- .span_suggestion_with_applicability(
+ .span_suggestion(
path.span,
"try",
format!("crate::{}", path),
let rename_msg = "you can use `as` to change the binding name of the import";
if let Some(suggestion) = suggestion {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
binding_span,
rename_msg,
suggestion,
*candidate = format!("use {};\n{}", candidate, additional_newline);
}
- err.span_suggestions_with_applicability(
+ err.span_suggestions(
span,
&msg,
path_strings.into_iter(),
if let Some(suggestion) = suggestion {
if suggestion != name {
if let MacroKind::Bang = kind {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"you could try the macro",
suggestion.to_string(),
Applicability::MaybeIncorrect
);
} else {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"try",
suggestion.to_string(),
if !suggestions.is_empty() {
let msg = format!("if you meant to specify the associated {}, write",
if suggestions.len() == 1 { "type" } else { "types" });
- err.multipart_suggestion_with_applicability(
+ err.multipart_suggestion(
&msg,
suggestions,
Applicability::MaybeIncorrect,
trait_str: &str,
name: &str) {
struct_span_err!(self.tcx().sess, span, E0223, "ambiguous associated type")
- .span_suggestion_with_applicability(
+ .span_suggestion(
span,
"use fully-qualified syntax",
format!("<{} as {}>::{}", type_str, trait_str, name),
&assoc_ident.as_str(),
None,
) {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"did you mean",
format!("{}::{}", qself_ty, suggested_name),
could_refer_to(variant_def, "");
could_refer_to(def, " also");
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"use fully-qualified syntax",
format!("<{} as {}>::{}", qself_ty, "Trait", assoc_ident),
let suggested_name =
find_best_match_for_name(input, &ident.as_str(), None);
if let Some(suggested_name) = suggested_name {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
*span,
"did you mean",
suggested_name.to_string(),
);
if let Some(ref path) = unit_variant {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
call_expr.span,
&format!(
"`{}` is a unit variant, you need to write it \
self.tcx.sess.source_map().is_multiline(call_expr.span);
if call_is_multiline {
let span = self.tcx.sess.source_map().next_point(callee.span);
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"try adding a semicolon",
";".to_owned(),
fcx.ty_to_string(self.expr_ty),
cast_ty));
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,
"dereference the expression",
format!("*{}", snippet),
if self.expr_ty.is_numeric() {
match fcx.tcx.sess.source_map().span_to_snippet(self.expr.span) {
Ok(snippet) => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
self.span,
"compare with zero instead",
format!("{} != 0", snippet),
err.note("The type information given here is insufficient to check whether \
the pointer cast is valid");
if unknown_cast_to {
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
self.cast_span,
"consider giving more type information",
String::new(),
if self.cast_ty.is_trait() {
match fcx.tcx.sess.source_map().span_to_snippet(self.cast_span) {
Ok(s) => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
self.cast_span,
"try casting to a reference instead",
format!("&{}{}", mtstr, s),
ty::Adt(def, ..) if def.is_box() => {
match fcx.tcx.sess.source_map().span_to_snippet(self.cast_span) {
Ok(s) => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
self.cast_span,
"try casting to a `Box` instead",
format!("Box<{}>", s),
if let Some(trait_err_span) = trait_err_span {
if let Ok(trait_err_str) = tcx.sess.source_map()
.span_to_snippet(trait_err_span) {
- diag.span_suggestion_with_applicability(
+ diag.span_suggestion(
impl_err_span,
"consider change the type to match the mutability in trait",
trait_err_str,
.span_to_snippet(trait_m.generics.span)
.ok()?;
- err.multipart_suggestion_with_applicability(
+ err.multipart_suggestion(
"try changing the `impl Trait` argument to a generic parameter",
vec![
// replace `impl Trait` with `T`
.span_to_snippet(bounds)
.ok()?;
- err.multipart_suggestion_with_applicability(
+ err.multipart_suggestion(
"try removing the generic parameter and using `impl Trait` instead",
vec![
// delete generic parameters
let expr_text = print::to_string(print::NO_ANN, |s| s.print_expr(expr));
let suggestions = compatible_variants
.map(|v| format!("{}({})", v, expr_text));
- err.span_suggestions_with_applicability(
+ err.span_suggestions(
expr.span,
"try using a variant of the expected type",
suggestions,
if needs_paren { ")" } else { "" },
);
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&suggest_msg,
if literal_is_ty_suffixed(expr) {
match (found.bit_width(), exp.bit_width()) {
(Some(found), Some(exp)) if found > exp => {
if can_cast {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("{}, which {}", msg, will_truncate),
cast_suggestion,
}
(None, _) | (_, None) => {
if can_cast {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("{}, which {}", msg, depending_on_isize),
cast_suggestion,
match (found.bit_width(), exp.bit_width()) {
(Some(found), Some(exp)) if found > exp => {
if can_cast {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("{}, which {}", msg, will_truncate),
cast_suggestion,
}
(None, _) | (_, None) => {
if can_cast {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("{}, which {}", msg, depending_on_usize),
cast_suggestion,
if can_cast {
match (found.bit_width(), exp.bit_width()) {
(Some(found), Some(exp)) if found > exp - 1 => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("{}, which {}", msg, will_truncate),
cast_suggestion,
);
}
(None, None) => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("{}, which {}", msg, will_truncate),
cast_suggestion,
);
}
(None, _) => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("{}, which {}", msg, depending_on_isize),
cast_suggestion,
);
}
(_, None) => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("{}, which {}", msg, depending_on_usize),
cast_suggestion,
);
}
_ => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("{}, which {}", msg, will_zero_extend),
cast_suggestion,
if can_cast {
match (found.bit_width(), exp.bit_width()) {
(Some(found), Some(exp)) if found - 1 > exp => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("{}, which {}", msg, will_truncate),
cast_suggestion,
);
}
(None, None) => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("{}, which {}", msg, will_sign_extend),
cast_suggestion,
);
}
(None, _) => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("{}, which {}", msg, depending_on_usize),
cast_suggestion,
);
}
(_, None) => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("{}, which {}", msg, depending_on_isize),
cast_suggestion,
);
}
_ => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("{}, which {}", msg, will_sign_extend),
cast_suggestion,
None,
);
} else if can_cast {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("{}, producing the closest possible value", msg),
cast_suggestion,
}
(&ty::Uint(_), &ty::Float(_)) | (&ty::Int(_), &ty::Float(_)) => {
if can_cast {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("{}, rounding the float towards zero", msg),
cast_suggestion,
(&ty::Float(ref exp), &ty::Uint(ref found)) => {
// if `found` is `None` (meaning found is `usize`), don't suggest `.into()`
if exp.bit_width() > found.bit_width().unwrap_or(256) {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("{}, producing the floating point representation of the \
integer",
Applicability::MachineApplicable
);
} else if can_cast {
- err.span_suggestion_with_applicability(expr.span,
+ err.span_suggestion(
+ expr.span,
&format!("{}, producing the floating point representation of the \
integer, rounded if necessary",
msg),
(&ty::Float(ref exp), &ty::Int(ref found)) => {
// if `found` is `None` (meaning found is `isize`), don't suggest `.into()`
if exp.bit_width() > found.bit_width().unwrap_or(256) {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("{}, producing the floating point representation of the \
integer",
Applicability::MachineApplicable
);
} else if can_cast {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("{}, producing the floating point representation of the \
integer, rounded if necessary",
(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
"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
// highlights the method name, so we can't use it. Also consider reusing the code from
// `report_method_error()`.
let snippet = tcx.sess.source_map().span_to_snippet(lit.span)
.unwrap_or_else(|_| "<numeric literal>".to_owned());
- err.span_suggestion_with_applicability(
- lit.span,
- &format!("you must specify a concrete type for \
- this numeric value, like `{}`",
- concrete_type),
- format!("{}_{}",
- snippet,
- concrete_type),
- Applicability::MaybeIncorrect,
+ err.span_suggestion(
+ lit.span,
+ &format!("you must specify a concrete type for \
+ this numeric value, like `{}`", concrete_type),
+ format!("{}_{}", snippet, concrete_type),
+ Applicability::MaybeIncorrect,
);
}
ExprKind::Path(ref qpath) => {
ty,
..
})) => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
// account for `let x: _ = 42;`
// ^^^^
span.to(ty.as_ref().map(|ty| ty.span)
);
if let Some(suggestion) = suggestion {
// enum variant
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
item_name.span,
"did you mean",
suggestion.to_string(),
}
if static_sources.len() == 1 {
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",
format!("{}::{}",
self.ty_to_string(actual),
}
if let Some(lev_candidate) = lev_candidate {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"did you mean",
lev_candidate.ident.to_string(),
)
});
- err.span_suggestions_with_applicability(
- span,
- &msg,
- path_strings,
- Applicability::MaybeIncorrect,
- );
+ err.span_suggestions(span, &msg, path_strings, Applicability::MaybeIncorrect);
} else {
let limit = if candidates.len() == 5 { 5 } else { 4 };
for (i, trait_did) in candidates.iter().take(limit).enumerate() {
let sugg_span = tcx.sess.source_map().end_point(expr_sp);
// remove closing `)` from the span
let sugg_span = sugg_span.shrink_to_lo();
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
sugg_span,
"expected the unit value `()`; create it with empty parentheses",
String::from("()"),
self.tcx.sess.source_map().span_to_snippet(lhs.span),
self.tcx.sess.source_map().span_to_snippet(rhs.span))
{
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
msg,
format!("{} == {}", left, right),
if let Some(suggested_field_name) =
Self::suggest_field_name(def.non_enum_variant(),
&field.as_str(), vec![]) {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
field.span,
"a field with a similar name exists",
suggested_field_name.to_string(),
} else {
Applicability::MaybeIncorrect
};
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span, help, suggestion, applicability
);
}
.unwrap_or_else(|_| self.tcx.hir().node_to_pretty_string(base.id));
let msg = format!("`{}` is a raw pointer; try dereferencing it", base);
let suggestion = format!("(*{}).{}", base, field);
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&msg,
suggestion,
if let Some(field_name) = Self::suggest_field_name(variant,
&field.ident.as_str(),
skip_fields.collect()) {
- err.span_suggestion_with_applicability(
- field.ident.span,
- "a field with a similar name exists",
- field_name.to_string(),
- Applicability::MaybeIncorrect,
- );
+ err.span_suggestion(
+ field.ident.span,
+ "a field with a similar name exists",
+ field_name.to_string(),
+ Applicability::MaybeIncorrect,
+ );
} else {
match ty.sty {
ty::Adt(adt, ..) => {
ast::LitIntType::Unsuffixed) = lit.node {
let snip = tcx.sess.source_map().span_to_snippet(base.span);
if let Ok(snip) = snip {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
"to access tuple elements, use",
format!("{}.{}", snip, i),
- Applicability::MachineApplicable);
+ Applicability::MachineApplicable,
+ );
needs_note = false;
}
}
found: Ty<'tcx>,
) {
if let Some((sp, msg, suggestion)) = self.check_ref(expr, found, expected) {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
sp,
msg,
suggestion,
}
}).peekable();
if suggestions.peek().is_some() {
- err.span_suggestions_with_applicability(
+ err.span_suggestions(
expr.span,
"try using a conversion method",
suggestions,
ExprKind::Match(..) |
ExprKind::Block(..) => {
let sp = self.tcx.sess.source_map().next_point(cause_span);
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
sp,
"try adding a semicolon",
";".to_string(),
// 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()) {
(&hir::FunctionRetTy::DefaultReturn(span), true, true, true) => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"try adding a return type",
format!("-> {} ", self.resolve_type_vars_with_obligations(found)),
err: &mut DiagnosticBuilder,
) {
if let Some(span_semi) = self.could_remove_semicolon(blk, expected_ty) {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span_semi,
"consider removing this semicolon",
String::new(),
},
AdtKind::Struct |
AdtKind::Union => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"use curly brackets",
String::from("Self { /* fields */ }"),
rty,
lstring,
);
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
lhs_expr.span,
msg,
format!("*{}", lstring),
err.span_label(expr.span,
"`+` can't be used to concatenate two `&str` strings");
match source_map.span_to_snippet(lhs_expr.span) {
- Ok(lstring) => err.span_suggestion_with_applicability(
+ Ok(lstring) => err.span_suggestion(
lhs_expr.span,
msg,
format!("{}.to_owned()", lstring),
is_assign,
) {
(Ok(l), Ok(r), false) => {
- err.multipart_suggestion_with_applicability(
+ err.multipart_suggestion(
msg,
vec![
(lhs_expr.span, format!("{}.to_owned()", l)),
.fold(span, |acc, attr_span| acc.to(attr_span));
tcx.struct_span_lint_node(lint, id, span, msg)
- .span_suggestion_short_with_applicability(
+ .span_suggestion_short(
span_with_attrs,
"remove it",
String::new(),
};
let replacement = visibility_qualified(&item.vis, base_replacement);
tcx.struct_span_lint_node(lint, id, extern_crate.span, msg)
- .span_suggestion_short_with_applicability(
+ .span_suggestion_short(
extern_crate.span,
&help,
replacement,
)
};
if let Ok(snippet) = self.sess.source_map().span_to_snippet(self.span) {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
self.span,
&format!("cast the value to `{}`", self.cast_ty),
format!("{} as {}", snippet, self.cast_ty),
if code_block.syntax.is_none() && code_block.is_fenced {
let sp = sp.from_inner_byte_pos(0, 3);
- diag.span_suggestion_with_applicability(
+ diag.span_suggestion(
sp,
"mark blocks that do not contain Rust code as text",
String::from("```text"),
let mut err = struct_span_err!(diag, span, E0565, "{}", msg);
if is_bytestr {
if let Ok(lint_str) = sess.source_map().span_to_snippet(span) {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"consider removing the prefix",
format!("{}", &lint_str[1..]),
"incorrect `repr(align)` attribute format");
match value.node {
ast::LitKind::Int(int, ast::LitIntType::Unsuffixed) => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
item.span,
"use parentheses instead",
format!("align({})", int),
);
}
ast::LitKind::Str(s, _) => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
item.span,
"use parentheses instead",
format!("align({})", s),
let error = |span, msg, suggestion: &str| {
let mut err = self.sess.span_diagnostic.struct_span_err(span, msg);
if !suggestion.is_empty() {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"expected syntax is",
suggestion.into(),
let trait_list = traits.iter()
.map(|t| t.to_string()).collect::<Vec<_>>();
let suggestion = format!("#[derive({})]", trait_list.join(", "));
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span, "try an outer attribute", suggestion,
// We don't 𝑘𝑛𝑜𝑤 that the following item is an ADT
Applicability::MaybeIncorrect
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) {
Ok(ref snippet) if &snippet[..] != ";" && kind_name == "expression" => {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
semi_span,
"you might be missing a semicolon here",
";".to_owned(),
_ => (String::from("<path>"), Applicability::HasPlaceholders),
};
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
it.span,
"provide a file path with `=`",
format!("include = \"{}\"", path),
if comma_span.is_dummy() {
err.note("you might be missing a comma");
} else {
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
comma_span,
"missing comma here",
", ".to_string(),
}
if i != 0 {
suggestion.push('}');
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
self.mk_sp(start, self.pos),
"format of unicode escape sequences uses braces",
suggestion,
self.sess.span_diagnostic
.struct_span_err(span,
"character literal may only contain one codepoint")
- .span_suggestion_with_applicability(
+ .span_suggestion(
span,
"if you meant to write a `str` literal, use double quotes",
format!("\"{}\"", &self.src[start..end]),
let msg =
format!("Unicode character '{}' ({}) looks like '{}' ({}), but it is not",
ch, u_name, ascii_char, ascii_name);
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
&msg,
ascii_char.to_string(),
};
let mut err = self.fatal(&msg_exp);
if self.token.is_ident_named("and") {
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
self.span,
"use `&&` instead of `and` for the boolean operator",
"&&".to_string(),
);
}
if self.token.is_ident_named("or") {
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
self.span,
"use `||` instead of `or` for the boolean operator",
"||".to_string(),
if ident.is_reserved() && !ident.is_path_segment_keyword() &&
ident.name != keywords::Underscore.name()
{
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
self.span,
"you can escape reserved keywords to use them as identifiers",
format!("r#{}", ident),
} else {
err.span_label(self.span, "expected identifier");
if self.token == token::Comma && self.look_ahead(1, |t| t.is_ident()) {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
self.span,
"remove this comma",
String::new(),
if !allow_plus && impl_dyn_multi {
let sum_with_parens = format!("({})", pprust::ty_to_string(&ty));
self.struct_span_err(ty.span, "ambiguous `+` in a type")
- .span_suggestion_with_applicability(
+ .span_suggestion(
ty.span,
"use parentheses to disambiguate",
sum_with_parens,
s.print_type_bounds(" +", &bounds)?;
s.pclose()
});
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
sum_span,
"try adding parentheses",
sum_with_parens,
self.diagnostic()
.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
).emit();
let ident = self.parse_ident().unwrap();
let span = pat.span.with_hi(ident.span.hi());
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
span,
"declare the type after the parameter binding",
String::from("<identifier>: <type>"),
);
} else if require_name && is_trait_item {
if let PatKind::Ident(_, ident, _) = pat.node {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
pat.span,
"explicitly ignore parameter",
format!("_: {}", ident),
"patterns aren't allowed in methods without bodies",
DiagnosticId::Error("E0642".into()),
);
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
pat.span,
"give this argument a name or use an underscore to ignore it",
"_".to_owned(),
let sp = lo.to(self.prev_span);
let mut err = self.diagnostic()
.struct_span_err(sp, "float literals must have an integer part");
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
sp,
"must have an integer part",
format!("0.{}{}", val, suffix),
if self.token == token::Eq {
self.diagnostic()
.struct_span_err(self.span, "expected `:`, found `=`")
- .span_suggestion_with_applicability(
+ .span_suggestion(
fieldname.span.shrink_to_hi().to(self.span),
"replace equals symbol with a colon",
":".to_string(),
exp_span.to(self.prev_span),
"cannot use a comma after the base struct",
);
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
self.span,
"remove this comma",
String::new(),
span,
&format!("unmatched angle bracket{}", if plural { "s" } else { "" }),
)
- .span_suggestion_with_applicability(
+ .span_suggestion(
span,
&format!("remove extra angle bracket{}", if plural { "s" } else { "" }),
String::new(),
s.s.word(".")?;
s.s.word(fstr.splitn(2, ".").last().unwrap().to_string())
});
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
lo.to(self.prev_span),
"try parenthesizing the first index",
sugg,
let span_of_tilde = lo;
let mut err = self.diagnostic()
.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,
"use `!` to perform bitwise negation",
"!".to_owned(),
// trailing whitespace after the `!` in our suggestion
let to_replace = self.sess.source_map()
.span_until_non_whitespace(lo.to(self.span));
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
to_replace,
"use `!` to perform logical negation",
"!".to_owned(),
let cur_pos = cm.lookup_char_pos(self.span.lo());
let op_pos = cm.lookup_char_pos(cur_op_span.hi());
if cur_pos.line != op_pos.line {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
cur_op_span,
"try using a semicolon",
";".to_string(),
let expr_str = self.sess.source_map().span_to_snippet(expr.span)
.unwrap_or_else(|_| pprust::expr_to_string(&expr));
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
expr.span,
&format!("try {} the cast value", op_verb),
format!("({})", expr_str),
let in_span = self.prev_span.between(self.span);
let mut err = self.sess.span_diagnostic
.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(),
// has been misleading, at least in the past (closed Issue #48492)
Applicability::MaybeIncorrect
self.prev_span,
"expected iterable, found keyword `in`",
);
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
in_span.until(self.prev_span),
"remove the duplicated `in`",
String::new(),
None)?;
if let Err(mut e) = self.expect(&token::OpenDelim(token::Brace)) {
if self.token == token::Token::Semi {
- e.span_suggestion_short_with_applicability(
+ e.span_suggestion_short(
match_span,
"try removing this `match`",
String::new(),
// | - ^^ self.span
// | |
// | parsed until here as `"y" & X`
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
cm.next_point(arm_start_span),
"missing a comma here to end this `match` arm",
",".to_owned(),
if self.token == token::OrOr {
let mut err = self.struct_span_err(self.span,
"unexpected token `||` after pattern");
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
self.span,
"use a single `|` to specify multiple patterns",
"|".to_owned(),
// Accept `...` as if it were `..` to avoid further errors
let mut err = self.struct_span_err(self.span,
"expected field pattern, found `...`");
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
self.span,
"to omit remaining fields, use one fewer `.`",
"..".to_owned(),
if self.token == token::CloseDelim(token::Brace) {
// If the struct looks otherwise well formed, recover and continue.
if let Some(sp) = comma_sp {
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
sp,
"remove this comma",
String::new(),
if let Some(mut err) = delayed_err {
if let Some(etc_span) = etc_span {
- err.multipart_suggestion_with_applicability(
+ err.multipart_suggestion(
"move the `..` to the end of the field list",
vec![
(etc_span, String::new()),
let mut err = self.struct_span_err(comma_span,
"unexpected `,` in pattern");
if let Ok(seq_snippet) = self.sess.source_map().span_to_snippet(seq_span) {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
seq_span,
"try adding parentheses",
format!("({})", seq_snippet),
let binding_mode = if self.eat_keyword(keywords::Ref) {
self.diagnostic()
.struct_span_err(mutref_span, "the order of `mut` and `ref` is incorrect")
- .span_suggestion_with_applicability(
+ .span_suggestion(
mutref_span,
"try switching the order",
"ref mut".into(),
pat.span,
"the range pattern here has ambiguous interpretation",
);
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
pat.span,
"add parentheses to clarify the precedence",
format!("({})", pprust::pat_to_string(&pat)),
(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
// typo in the code: `:` instead of `=`. Add suggestion and emit the error.
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
colon_sp,
"use `=` if you meant to assign",
"=".to_string(),
self.token.is_keyword(keywords::In) || self.token == token::Colon;
if self.token.is_ident_named("and") {
- e.span_suggestion_short_with_applicability(
+ e.span_suggestion_short(
self.span,
"use `&&` instead of `and` for the boolean operator",
"&&".to_string(),
);
}
if self.token.is_ident_named("or") {
- e.span_suggestion_short_with_applicability(
+ e.span_suggestion_short(
self.span,
"use `||` instead of `or` for the boolean operator",
"||".to_string(),
s.print_stmt(&stmt)?;
s.bclose_maybe_open(stmt.span, INDENT_UNIT, false)
});
- e.span_suggestion_with_applicability(
+ e.span_suggestion(
stmt_span,
"try placing this code inside a block",
sugg,
fn err_dotdotdot_syntax(&self, span: Span) {
self.diagnostic().struct_span_err(span, {
"unexpected token: `...`"
- }).span_suggestion_with_applicability(
+ }).span_suggestion(
span, "use `..` for an exclusive range", "..".to_owned(),
Applicability::MaybeIncorrect
- ).span_suggestion_with_applicability(
+ ).span_suggestion(
span, "or `..=` for an inclusive range", "..=".to_owned(),
Applicability::MaybeIncorrect
).emit();
"lifetime parameters must be declared prior to type parameters",
);
if !suggestions.is_empty() {
- err.multipart_suggestion_with_applicability(
+ err.multipart_suggestion(
"move the lifetime parameter prior to the first type parameter",
suggestions,
Applicability::MachineApplicable,
if plural { "s" } else { "" }
),
)
- .span_suggestion_with_applicability(
+ .span_suggestion(
span,
&format!(
"remove extra angle bracket{}",
suggestions.extend_from_slice(&type_suggestions);
let plural = bad_lifetime_pos.len() + bad_type_pos.len() > 1;
- err.multipart_suggestion_with_applicability(
+ err.multipart_suggestion(
&format!(
"move the parameter{}",
if plural { "s" } else { "" },
Applicability::MachineApplicable,
);
} else if !lifetime_suggestions.is_empty() {
- err.multipart_suggestion_with_applicability(
+ err.multipart_suggestion(
&format!(
"move the lifetime parameter{} prior to the first type parameter",
if bad_lifetime_pos.len() > 1 { "s" } else { "" },
Applicability::MachineApplicable,
);
} else if !type_suggestions.is_empty() {
- err.multipart_suggestion_with_applicability(
+ err.multipart_suggestion(
&format!(
"move the type parameter{} prior to the first associated type binding",
if bad_type_pos.len() > 1 { "s" } else { "" },
let mut err = if is_macro_rules {
let mut err = self.diagnostic()
.struct_span_err(sp, "can't qualify macro_rules invocation with `pub`");
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
sp,
"try exporting the macro",
"#[macro_export]".to_owned(),
// impl Trait for Type
if !has_for {
self.struct_span_err(missing_for_span, "missing `for` in a trait impl")
- .span_suggestion_short_with_applicability(
+ .span_suggestion_short(
missing_for_span,
"add `for` here",
" for ".to_string(),
} else {
if seen_comma == false {
let sp = self.sess.source_map().next_point(previous_span);
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
sp,
"missing comma here",
",".into(),
self.this_token_descr()));
if self.token.is_ident() {
// This is likely another field; emit the diagnostic and keep going
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
sp,
"try adding a comma",
",".into(),
self.expect(&token::CloseDelim(token::Paren))?; // `)`
let mut err = struct_span_err!(self.sess.span_diagnostic, sp, E0704, "{}", msg);
err.help(suggestion);
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
sp, &help_msg, format!("in {}", path), Applicability::MachineApplicable
);
err.emit(); // emit diagnostic, but continue with public visibility
fn maybe_consume_incorrect_semicolon(&mut self, items: &[P<Item>]) -> bool {
if self.eat(&token::Semi) {
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,
"remove this semicolon",
String::new(),
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.multipart_suggestion_with_applicability(
+ err.multipart_suggestion(
suggestion_msg,
replacement,
Applicability::MachineApplicable,
let mut err = self.diagnostic()
.struct_span_err(prev_span, "const globals cannot be mutable");
err.span_label(prev_span, "cannot be mutable");
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
const_span,
"you might want to declare a static instead",
"static".to_owned(),
ident);
let mut err = self.diagnostic()
.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
);
return Err(err);
kw,
ident,
kw_name);
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
sp, &suggestion, format!(" {} ", kw), Applicability::MachineApplicable
);
} else {
if let Ok(snippet) = self.sess.source_map().span_to_snippet(ident_sp) {
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
full_sp,
"if you meant to call a macro, try",
format!("{}!", snippet),
let msg = format!("missing `{}` for {} definition", kw, kw_name);
let mut err = self.diagnostic().struct_span_err(sp, &msg);
if !ambiguous {
- err.span_suggestion_short_with_applicability(
+ err.span_suggestion_short(
sp,
&format!("add `{}` here to parse `{}` as a public {}", kw, ident, kw_name),
format!(" {} ", kw),
if self.token.is_keyword(keywords::Const) {
self.diagnostic()
.struct_span_err(self.span, "extern items cannot be `const`")
- .span_suggestion_with_applicability(
+ .span_suggestion(
self.span,
"try using a static value",
"static".to_owned(),
0 => "{}".to_string(),
_ => format!("{}{{}}", "{} ".repeat(args.len())),
};
- err.span_suggestion_with_applicability(
+ err.span_suggestion(
fmt_sp.shrink_to_lo(),
"you might be missing a string literal to format with",
format!("\"{}\", ", sugg_fmt),
));
}
if suggestions.len() > 0 {
- diag.multipart_suggestion_with_applicability(
+ diag.multipart_suggestion(
"format specifiers use curly braces",
suggestions,
Applicability::MachineApplicable,