forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#127103 - compiler-errors:tighten-trait-bound-parsing, r=fmease Move binder and polarity parsing into `parse_generic_ty_bound` Let's pull out the parts of rust-lang#127054 which just: 1. Make the parsing code less confusing 2. Fix `?use<>` (to correctly be denied) 3. Improve `T: for<'a> 'a` diagnostics This should have no user-facing effects on stable parsing. r? fmease
- Loading branch information
Showing
7 changed files
with
204 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fn foo<T>() where T: for<'a> 'a {} | ||
//~^ ERROR `for<...>` may only modify trait bounds, not lifetime bounds | ||
//~| ERROR use of undeclared lifetime name `'a` [E0261] | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
error: `for<...>` may only modify trait bounds, not lifetime bounds | ||
--> $DIR/erroneous-lifetime-bound.rs:1:25 | ||
| | ||
LL | fn foo<T>() where T: for<'a> 'a {} | ||
| ^^^^ | ||
|
||
error[E0261]: use of undeclared lifetime name `'a` | ||
--> $DIR/erroneous-lifetime-bound.rs:1:30 | ||
| | ||
LL | fn foo<T>() where T: for<'a> 'a {} | ||
| ^^ undeclared lifetime | ||
| | ||
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html | ||
help: consider making the bound lifetime-generic with a new `'a` lifetime | ||
| | ||
LL | fn foo<T>() where for<'a> T: for<'a> 'a {} | ||
| +++++++ | ||
help: consider introducing lifetime `'a` here | ||
| | ||
LL | fn foo<'a, T>() where T: for<'a> 'a {} | ||
| +++ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0261`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//@ edition: 2021 | ||
|
||
#![feature(precise_capturing)] | ||
|
||
fn polarity() -> impl Sized + ?use<> {} | ||
//~^ ERROR expected identifier, found keyword `use` | ||
//~| ERROR cannot find trait `r#use` in this scope | ||
//~| WARN relaxing a default bound only does something for `?Sized` | ||
//~| WARN relaxing a default bound only does something for `?Sized` | ||
|
||
fn asyncness() -> impl Sized + async use<> {} | ||
//~^ ERROR expected identifier, found keyword `use` | ||
//~| ERROR cannot find trait `r#use` in this scope | ||
//~| ERROR async closures are unstable | ||
|
||
fn constness() -> impl Sized + const use<> {} | ||
//~^ ERROR expected identifier, found keyword `use` | ||
//~| ERROR cannot find trait `r#use` in this scope | ||
//~| ERROR const trait impls are experimental | ||
|
||
fn binder() -> impl Sized + for<'a> use<> {} | ||
//~^ ERROR expected identifier, found keyword `use` | ||
//~| ERROR cannot find trait `r#use` in this scope | ||
|
||
fn main() {} |
87 changes: 87 additions & 0 deletions
87
tests/ui/impl-trait/precise-capturing/bound-modifiers.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
error: expected identifier, found keyword `use` | ||
--> $DIR/bound-modifiers.rs:5:32 | ||
| | ||
LL | fn polarity() -> impl Sized + ?use<> {} | ||
| ^^^ expected identifier, found keyword | ||
|
||
error: expected identifier, found keyword `use` | ||
--> $DIR/bound-modifiers.rs:11:38 | ||
| | ||
LL | fn asyncness() -> impl Sized + async use<> {} | ||
| ^^^ expected identifier, found keyword | ||
|
||
error: expected identifier, found keyword `use` | ||
--> $DIR/bound-modifiers.rs:16:38 | ||
| | ||
LL | fn constness() -> impl Sized + const use<> {} | ||
| ^^^ expected identifier, found keyword | ||
|
||
error: expected identifier, found keyword `use` | ||
--> $DIR/bound-modifiers.rs:21:37 | ||
| | ||
LL | fn binder() -> impl Sized + for<'a> use<> {} | ||
| ^^^ expected identifier, found keyword | ||
|
||
error[E0405]: cannot find trait `r#use` in this scope | ||
--> $DIR/bound-modifiers.rs:5:32 | ||
| | ||
LL | fn polarity() -> impl Sized + ?use<> {} | ||
| ^^^ not found in this scope | ||
|
||
error[E0405]: cannot find trait `r#use` in this scope | ||
--> $DIR/bound-modifiers.rs:11:38 | ||
| | ||
LL | fn asyncness() -> impl Sized + async use<> {} | ||
| ^^^ not found in this scope | ||
|
||
error[E0405]: cannot find trait `r#use` in this scope | ||
--> $DIR/bound-modifiers.rs:16:38 | ||
| | ||
LL | fn constness() -> impl Sized + const use<> {} | ||
| ^^^ not found in this scope | ||
|
||
error[E0405]: cannot find trait `r#use` in this scope | ||
--> $DIR/bound-modifiers.rs:21:37 | ||
| | ||
LL | fn binder() -> impl Sized + for<'a> use<> {} | ||
| ^^^ not found in this scope | ||
|
||
error[E0658]: async closures are unstable | ||
--> $DIR/bound-modifiers.rs:11:32 | ||
| | ||
LL | fn asyncness() -> impl Sized + async use<> {} | ||
| ^^^^^ | ||
| | ||
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information | ||
= help: add `#![feature(async_closure)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
= help: to use an async block, remove the `||`: `async {` | ||
|
||
error[E0658]: const trait impls are experimental | ||
--> $DIR/bound-modifiers.rs:16:32 | ||
| | ||
LL | fn constness() -> impl Sized + const use<> {} | ||
| ^^^^^ | ||
| | ||
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information | ||
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default | ||
--> $DIR/bound-modifiers.rs:5:31 | ||
| | ||
LL | fn polarity() -> impl Sized + ?use<> {} | ||
| ^^^^^^ | ||
|
||
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default | ||
--> $DIR/bound-modifiers.rs:5:31 | ||
| | ||
LL | fn polarity() -> impl Sized + ?use<> {} | ||
| ^^^^^^ | ||
| | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
||
error: aborting due to 10 previous errors; 2 warnings emitted | ||
|
||
Some errors have detailed explanations: E0405, E0658. | ||
For more information about an error, try `rustc --explain E0405`. |