-
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
Provide a better error and a suggestion for Fn
traits with lifetime params
#104531
Provide a better error and a suggestion for Fn
traits with lifetime params
#104531
Conversation
r? @jackh726 (rustbot has picked a reviewer for you, use r? to override) |
Probably best reviewed by a member of the diagnostics working group. |
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.
Thanks for working on this! I have some suggestions.
37f27f8
to
9e692c3
Compare
9e692c3
to
2a07a2e
Compare
@estebank |
☔ The latest upstream changes (presumably #106215) made this pull request unmergeable. Please resolve the merge conflicts. |
let generic_args = if let Some(p_args) = &fn_path_segment.args { | ||
p_args.clone().into_inner() | ||
} else { |
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.
This can now be
let generic_args = if let Some(p_args) = &fn_path_segment.args { | |
p_args.clone().into_inner() | |
} else { | |
let Some(p_args) = &fn_path_segment.args { | |
p_args.clone().into_inner() | |
} else { |
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.
Is this valid syntax? I got the following error:
error: expected one of `(`, `.`, `::`, `;`, `?`, `else`, or an operator, found `{`
--> compiler/rustc_parse/src/parser/ty.rs:1033:50
|
1033 | let Some(p_args) = &fn_path_segment.args {
| ^ expected one of 7 possible tokens
error: could not compile `rustc_parse` due to previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `rustc_parse` due to previous error
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.
With let
/else
syntax, it's
let Some(p_args) = &fn_path_segment.args else {
// ... ... ...
return Ok(());
};
let p_args = p_args.clone().into_inner();
or
let Some(p_args) = fn_path_segment.args.cloned().map(|arg| arg) else {
// ... ... ...
return Ok(());
};
or
let Some(p_args) = fn_path.segments
.last_mut()
.unwrap()
.args
.cloned()
.map(|arg| arg)
else {
// ... ... ...
return Ok(());
};
or something similar at your choosing.
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.
Ah, yeah, I mistyped what I meant. Thanks @fmease for clarifying it
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.
r=me after rebase
Currently, given `Fn`-family traits with lifetime params like `Fn<'a>(&'a str) -> bool`, many unhelpful errors show up. These are a bit confusing. This commit allows these situations to suggest simply using higher-ranked trait bounds like `for<'a> Fn(&'a str) -> bool`.
2a07a2e
to
e5281c3
Compare
@bors r+ |
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#104531 (Provide a better error and a suggestion for `Fn` traits with lifetime params) - rust-lang#105899 (`./x doc library --open` opens `std`) - rust-lang#106190 (Account for multiple multiline spans with empty padding) - rust-lang#106202 (Trim more paths in obligation types) - rust-lang#106234 (rustdoc: simplify settings, help, and copy button CSS by not reusing) - rust-lang#106236 (docs/test: add docs and a UI test for `E0514` and `E0519`) - rust-lang#106259 (Update Clippy) - rust-lang#106260 (Fix index out of bounds issues in rustdoc) - rust-lang#106263 (Formatter should not try to format non-Rust files) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#104531 (Provide a better error and a suggestion for `Fn` traits with lifetime params) - rust-lang#105899 (`./x doc library --open` opens `std`) - rust-lang#106190 (Account for multiple multiline spans with empty padding) - rust-lang#106202 (Trim more paths in obligation types) - rust-lang#106234 (rustdoc: simplify settings, help, and copy button CSS by not reusing) - rust-lang#106236 (docs/test: add docs and a UI test for `E0514` and `E0519`) - rust-lang#106259 (Update Clippy) - rust-lang#106260 (Fix index out of bounds issues in rustdoc) - rust-lang#106263 (Formatter should not try to format non-Rust files) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#104531 (Provide a better error and a suggestion for `Fn` traits with lifetime params) - rust-lang#105899 (`./x doc library --open` opens `std`) - rust-lang#106190 (Account for multiple multiline spans with empty padding) - rust-lang#106202 (Trim more paths in obligation types) - rust-lang#106234 (rustdoc: simplify settings, help, and copy button CSS by not reusing) - rust-lang#106236 (docs/test: add docs and a UI test for `E0514` and `E0519`) - rust-lang#106259 (Update Clippy) - rust-lang#106260 (Fix index out of bounds issues in rustdoc) - rust-lang#106263 (Formatter should not try to format non-Rust files) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Given
Fn
-family traits with lifetime params in trait bounds likefn f(_: impl Fn<'a>(&'a str) -> bool)
, we currently produce many unhelpful errors.This PR allows these situations to suggest simply using Higher-Rank Trait Bounds like
for<'a> Fn(&'a str) -> bool
.Fixes #103490.