-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
In some limited cases, suggest where
bounds for non-type params
#82194
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
@bors r+ |
📌 Commit 4e0a948ced62713a113636367b64b4aa76e05b4e has been approved by |
@bors r- |
4e0a948
to
ad9ef4a
Compare
This comment has been minimized.
This comment has been minimized.
ad9ef4a
to
32c97da
Compare
@bors r=petrochenkov |
📌 Commit 32c97da has been approved by |
@@ -9,6 +9,10 @@ help: consider removing the leading `&`-reference | |||
| | |||
LL | let mut stream_reader = BufReader::new(stream); | |||
| -- | |||
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement | |||
| | |||
LL | fn issue_81421<T: Read + Write>(mut stream: T) where &T: std::io::Read { |
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 syntax even allowed? where &T: ..
will not compile due to missing lifetime parameters unfortunately
error[E0637]: `&` without an explicit lifetime name cannot be used here
--> src/lib.rs:2:23
|
2 | fn foo<T>(x: T) where &T: std::io::Read { }
| ^ explicit lifetime name needed here
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.
We (I?) allow for limited "mistakes" in the suggested code as long as the compiler gives you further suggestions that lead you to working code. We can gate this suggestion in particular or/and extend E0637 to suggest where a lifetime can be added (we already have suggestions to extend foo
's type param list and to add a for
lifetime in other places).
Indeed writing where for<'a> &'a T: Read
compiles successfully.
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.
Filed #82312 to track that potential work.
…n, r=petrochenkov In some limited cases, suggest `where` bounds for non-type params Partially address rust-lang#81971.
Rollup of 10 pull requests Successful merges: - rust-lang#81546 ([libtest] Run the test synchronously when hitting thread limit) - rust-lang#82066 (Ensure valid TraitRefs are created for GATs) - rust-lang#82112 (const_generics: Dont evaluate array length const when handling yet another error ) - rust-lang#82194 (In some limited cases, suggest `where` bounds for non-type params) - rust-lang#82215 (Replace if-let and while-let with `if let` and `while let`) - rust-lang#82218 (Make sure pdbs are copied along with exe and dlls when bootstrapping) - rust-lang#82236 (avoid converting types into themselves (clippy::useless_conversion)) - rust-lang#82246 (Add long explanation for E0549) - rust-lang#82248 (Optimize counting digits in line numbers during error reporting) - rust-lang#82256 (Print -Ztime-passes (and misc stats/logs) on stderr, not stdout.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Partially address #81971.