Skip to content
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

Merged
merged 1 commit into from
Feb 18, 2021

Conversation

estebank
Copy link
Contributor

Partially address #81971.

@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 16, 2021
@rust-log-analyzer

This comment has been minimized.

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Feb 16, 2021

📌 Commit 4e0a948ced62713a113636367b64b4aa76e05b4e has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 16, 2021
@petrochenkov
Copy link
Contributor

@bors r-
Need to fix CI, but otherwise r=me.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 16, 2021
@rust-log-analyzer

This comment has been minimized.

@estebank
Copy link
Contributor Author

@bors r=petrochenkov

@bors
Copy link
Contributor

bors commented Feb 17, 2021

📌 Commit 32c97da has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 17, 2021
@@ -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 {
Copy link
Member

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

Copy link
Contributor Author

@estebank estebank Feb 20, 2021

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.

Copy link
Contributor Author

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.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Feb 18, 2021
…n, r=petrochenkov

In some limited cases, suggest `where` bounds for non-type params

Partially address rust-lang#81971.
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 18, 2021
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
@bors bors merged commit f01b339 into rust-lang:master Feb 18, 2021
@rustbot rustbot added this to the 1.52.0 milestone Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants