-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Distinguish guesses from suggestions #39458
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2167,18 +2167,20 @@ impl<'a> Resolver<'a> { | |
let self_is_available = this.self_value_is_available(path[0].ctxt); | ||
match candidate { | ||
AssocSuggestion::Field => { | ||
err.span_label(span, &format!("did you mean `self.{}`?", path_str)); | ||
err.guess(span, "did you intend to access a struct field?", | ||
format!("self.{}", path_str)); | ||
if !self_is_available { | ||
err.span_label(span, &format!("`self` value is only available in \ | ||
methods with `self` parameter")); | ||
} | ||
} | ||
AssocSuggestion::MethodWithSelf if self_is_available => { | ||
err.span_label(span, &format!("did you mean `self.{}(...)`?", | ||
path_str)); | ||
err.guess(span, "did you intend to call a method of the same name?", | ||
format!("self.{}", path_str)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I though that the span was for the entire call, instead of just the |
||
} | ||
AssocSuggestion::MethodWithSelf | AssocSuggestion::AssocItem => { | ||
err.span_label(span, &format!("did you mean `Self::{}`?", path_str)); | ||
err.guess(span, "did you mean an associated item of the same name?", | ||
format!("Self::{}", path_str)); | ||
} | ||
} | ||
return err; | ||
|
@@ -2189,22 +2191,33 @@ impl<'a> Resolver<'a> { | |
if let Some(def) = def { | ||
match (def, source) { | ||
(Def::Macro(..), _) => { | ||
err.span_label(span, &format!("did you mean `{}!(...)`?", path_str)); | ||
err.guess(span, "did you intend to invoke a macro of the same name?", | ||
format!("{}!", path_str)); | ||
return err; | ||
} | ||
(Def::TyAlias(..), PathSource::Trait) => { | ||
err.span_label(span, &format!("type aliases cannot be used for traits")); | ||
err.span_label(span, &"type aliases cannot be used for traits"); | ||
return err; | ||
} | ||
(Def::Mod(..), PathSource::Expr(Some(parent))) => match *parent { | ||
ExprKind::Field(_, ident) => { | ||
err.span_label(span, &format!("did you mean `{}::{}`?", | ||
path_str, ident.node)); | ||
let span = Span { | ||
hi: ident.span.hi, | ||
.. span | ||
}; | ||
err.guess(span, | ||
"did you mean", | ||
format!("{}::{}", path_str, ident.node)); | ||
return err; | ||
} | ||
ExprKind::MethodCall(ident, ..) => { | ||
err.span_label(span, &format!("did you mean `{}::{}(...)`?", | ||
path_str, ident.node)); | ||
let span = Span { | ||
hi: ident.span.hi, | ||
.. span | ||
}; | ||
err.guess(span, | ||
"did you mean", | ||
format!("{}::{}", path_str, ident.node)); | ||
return err; | ||
} | ||
_ => {} | ||
|
@@ -2216,11 +2229,13 @@ impl<'a> Resolver<'a> { | |
if is_expected(ctor_def) && !this.is_accessible(ctor_vis) { | ||
err.span_label(span, &format!("constructor is not visible \ | ||
here due to private fields")); | ||
return err; | ||
} | ||
} | ||
} | ||
err.span_label(span, &format!("did you mean `{} {{ /* fields */ }}`?", | ||
path_str)); | ||
err.span_label(span, | ||
&format!("did you mean `{} {{ /* fields */ }}`?", | ||
path_str)); | ||
return err; | ||
} | ||
_ => {} | ||
|
@@ -2229,7 +2244,7 @@ impl<'a> Resolver<'a> { | |
|
||
// Try Levenshtein if nothing else worked. | ||
if let Some(candidate) = this.lookup_typo_candidate(path, ns, is_expected) { | ||
err.span_label(span, &format!("did you mean `{}`?", candidate)); | ||
err.guess(span, "did you mean", candidate); | ||
return err; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,17 +199,25 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { | |
let field_ty = field.ty(tcx, substs); | ||
|
||
if self.is_fn_ty(&field_ty, span) { | ||
err.span_note(span, | ||
&format!("use `({0}.{1})(...)` if you \ | ||
meant to call the function \ | ||
stored in the `{1}` field", | ||
expr_string, | ||
item_name)); | ||
if expr.span.expn_id == span.expn_id { | ||
let span = Span { | ||
lo: expr.span.lo, | ||
hi: span.hi, | ||
expn_id: expr.span.expn_id, | ||
}; | ||
err.guess( | ||
span, | ||
&format!("did you mean to call the function \ | ||
stored in the `{}` field?", item_name), | ||
format!("({}.{})", expr_string, item_name), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above. |
||
); | ||
} else { | ||
err.help(&format!("did you mean to call the function \ | ||
stored in the `{}` field?", item_name)); | ||
} | ||
} else { | ||
err.span_note(span, | ||
&format!("did you mean to write `{0}.{1}`?", | ||
expr_string, | ||
item_name)); | ||
err.guess(span, "did you mean to write", | ||
format!("{}.{}", expr_string, item_name)); | ||
} | ||
break; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thinks
span_guess
is a better name, because all other functions taking a span have span in the name. ( for exanplespan_suggestion
)