-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tweak output on E0599 for assoc fn used as method #51135
Conversation
When encountering an unexisting method for a given trait where an associated function has the same name, suggest using the appropriate syntax, instead of using `help` text. When only one candidate is found, do not call it "candidate rust-lang#1", just call it "the candidate".
(rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
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.
Doesn't need to be acted upon in this PR, just some thoughts of what we should think about in the future
if static_sources.len() == 1 { | ||
if let Some(expr) = rcvr_expr { | ||
err.span_suggestion(expr.span.to(span), | ||
"use associated function syntax intead", |
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.
Typo: intead
} | ||
if static_sources.len() == 1 { | ||
if let Some(expr) = rcvr_expr { | ||
err.span_suggestion(expr.span.to(span), |
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.
Why is only the single source case a suggestion?
@@ -468,9 +495,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { | |||
} else { | |||
let limit = if candidates.len() == 5 { 5 } else { 4 }; | |||
for (i, trait_did) in candidates.iter().take(limit).enumerate() { | |||
msg.push_str(&format!("\ncandidate #{}: `use {};`", |
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.
These should probably become a real suggestion, in which case you don't need manual limiting anymore, because the renderer takes care of that
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.
The suggestions for inserting use statements do that already
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.
Suggestions currently do not preserve their position in the output, they always come at then end. I need to change that for the first requested fix.
r? @oli-obk |
ping @oli-obk |
@bors r+ |
📌 Commit 59b03b1 has been approved by |
Tweak output on E0599 for assoc fn used as method - Use suggestion instead of `help` when possible - Add primary span label - Remove incorrect `help` suggestion using incorrect syntax - Do not refer to only one possible candidate as `candidate #1`, refer to it as `the candidate`
Rollup of 5 pull requests Successful merges: - #51135 (Tweak output on E0599 for assoc fn used as method) - #51152 (Replace `if` with `if and only if` in the definition dox of `Sync`) - #51262 (Add missing whitespace in num example) - #51272 (Remove feature flag from fs::read_to_string example) - #51286 (Pull 1.26.2 release notes into master) Failed merges:
💥 Test timed out |
help
when possiblehelp
suggestion using incorrect syntaxcandidate #1
, refer to it asthe candidate