Suggest removing bounds even when potential typo
This commit is contained in:
parent
5217007a20
commit
e89ce461d3
2 changed files with 38 additions and 16 deletions
|
@ -439,14 +439,11 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.type_ascription_suggestion(&mut err, base_span)
|
if !self.type_ascription_suggestion(&mut err, base_span) {
|
||||||
&& !self.r.add_typo_suggestion(&mut err, typo_sugg, ident_span)
|
let mut fallback = false;
|
||||||
{
|
|
||||||
// Fallback label.
|
|
||||||
err.span_label(base_span, fallback_label);
|
|
||||||
|
|
||||||
if let PathSource::Trait(AliasPossibility::Maybe) = source {
|
if let PathSource::Trait(AliasPossibility::Maybe) = source {
|
||||||
if let Some(bounds @ [_, .., _]) = self.diagnostic_metadata.current_trait_object {
|
if let Some(bounds @ [_, .., _]) = self.diagnostic_metadata.current_trait_object {
|
||||||
|
fallback = true;
|
||||||
let spans: Vec<Span> = bounds
|
let spans: Vec<Span> = bounds
|
||||||
.iter()
|
.iter()
|
||||||
.map(|bound| bound.span())
|
.map(|bound| bound.span())
|
||||||
|
@ -500,16 +497,25 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match self.diagnostic_metadata.current_let_binding {
|
if !self.r.add_typo_suggestion(&mut err, typo_sugg, ident_span) {
|
||||||
Some((pat_sp, Some(ty_sp), None)) if ty_sp.contains(base_span) && could_be_expr => {
|
fallback = true;
|
||||||
err.span_suggestion_short(
|
match self.diagnostic_metadata.current_let_binding {
|
||||||
pat_sp.between(ty_sp),
|
Some((pat_sp, Some(ty_sp), None))
|
||||||
"use `=` if you meant to assign",
|
if ty_sp.contains(base_span) && could_be_expr =>
|
||||||
" = ".to_string(),
|
{
|
||||||
Applicability::MaybeIncorrect,
|
err.span_suggestion_short(
|
||||||
);
|
pat_sp.between(ty_sp),
|
||||||
|
"use `=` if you meant to assign",
|
||||||
|
" = ".to_string(),
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
_ => {}
|
}
|
||||||
|
if fallback {
|
||||||
|
// Fallback label.
|
||||||
|
err.span_label(base_span, fallback_label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(err, candidates)
|
(err, candidates)
|
||||||
|
|
|
@ -144,7 +144,23 @@ error[E0404]: expected trait, found struct `Traitor`
|
||||||
LL | trait Trait {}
|
LL | trait Trait {}
|
||||||
| ----------- similarly named trait `Trait` defined here
|
| ----------- similarly named trait `Trait` defined here
|
||||||
LL | fn g() -> Traitor + 'static {
|
LL | fn g() -> Traitor + 'static {
|
||||||
| ^^^^^^^ help: a trait with a similar name exists: `Trait`
|
| ^^^^^^^ not a trait
|
||||||
|
|
|
||||||
|
help: `+` is used to constrain a "trait object" type with lifetimes or auto-traits; structs and enums can't be bound in that way
|
||||||
|
--> $DIR/trait-bounds-not-on-struct.rs:35:21
|
||||||
|
|
|
||||||
|
LL | fn g() -> Traitor + 'static {
|
||||||
|
| ------- ^^^^^^^ ...because of this bound
|
||||||
|
| |
|
||||||
|
| expected this type to be a trait...
|
||||||
|
help: if you meant to use a type and not a trait here, remove the bounds
|
||||||
|
|
|
||||||
|
LL | fn g() -> Traitor {
|
||||||
|
| --
|
||||||
|
help: a trait with a similar name exists
|
||||||
|
|
|
||||||
|
LL | fn g() -> Trait + 'static {
|
||||||
|
| ^^^^^
|
||||||
|
|
||||||
error: aborting due to 11 previous errors
|
error: aborting due to 11 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue