-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 #127054 - compiler-errors:bound-ordering, r=fmease
Reorder trait bound modifiers *after* `for<...>` binder in trait bounds This PR suggests changing the grammar of trait bounds from: ``` [CONSTNESS] [ASYNCNESS] [?] [BINDER] [TRAIT_PATH] const async ? for<'a> Sized ``` to ``` ([BINDER] [CONSTNESS] [ASYNCNESS] | [?]) [TRAIT_PATH] ``` i.e., either ``` ? Sized ``` or ``` for<'a> const async Sized ``` (but not both) ### Why? I think it's strange that the binder applies "more tightly" than the `?` trait polarity. This becomes even weirder when considering that we (or at least, I) want to have `async` trait bounds expressed like: ``` where T: for<'a> async Fn(&'a ()) -> i32, ``` and not: ``` where T: async for<'a> Fn(&'a ()) -> i32, ``` ### Fallout No crates on crater use this syntax, presumably because it's literally useless. This will require modifying the reference grammar, though. ### Alternatives If this is not desirable, then we can alternatively keep parsing `for<'a>` after the `?` but deprecate it with either an FCW (or an immediate hard error), and begin parsing `for<'a>` *before* the `?`.
- Loading branch information
Showing
20 changed files
with
201 additions
and
68 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
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 |
---|---|---|
|
@@ -3,9 +3,3 @@ where | |
i32: !Copy, | ||
{ | ||
} | ||
|
||
fn maybe_const_negative() | ||
where | ||
i32: ~const !Copy, | ||
{ | ||
} |
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
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
//@ check-pass | ||
#![allow(dead_code)] | ||
fn f<T: ?for<'a> Sized>() {} | ||
//~^ ERROR `for<...>` binder should be placed before trait bound modifiers | ||
|
||
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,10 @@ | ||
error: `for<...>` binder should be placed before trait bound modifiers | ||
--> $DIR/issue-39089.rs:1:13 | ||
| | ||
LL | fn f<T: ?for<'a> Sized>() {} | ||
| - ^^^^ | ||
| | | ||
| place the `for<...>` binder before any modifiers | ||
|
||
error: aborting due to 1 previous error | ||
|
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 |
---|---|---|
@@ -1,19 +1,30 @@ | ||
//@ compile-flags: -Z parse-only | ||
//@ edition: 2021 | ||
|
||
struct S< | ||
T: 'a + Tr, // OK | ||
T: Tr + 'a, // OK | ||
T: 'a, // OK | ||
T:, // OK | ||
T: ?for<'a> Trait, // OK | ||
T: for<'a> ?Trait, //~ ERROR `for<...>` binder not allowed with `?` trait polarity modifier | ||
T: Tr +, // OK | ||
T: ?'a, //~ ERROR `?` may only modify trait bounds, not lifetime bounds | ||
|
||
T: ~const Tr, // OK | ||
T: ~const ?Tr, // OK | ||
T: ~const ?Tr, //~ ERROR `~const` trait not allowed with `?` trait polarity modifier | ||
T: ~const Tr + 'a, // OK | ||
T: ~const 'a, //~ ERROR `~const` may only modify trait bounds, not lifetime bounds | ||
T: const 'a, //~ ERROR `const` may only modify trait bounds, not lifetime bounds | ||
|
||
T: async Tr, // OK | ||
T: async ?Tr, //~ ERROR `async` trait not allowed with `?` trait polarity modifier | ||
T: async Tr + 'a, // OK | ||
T: async 'a, //~ ERROR `async` may only modify trait bounds, not lifetime bounds | ||
|
||
T: const async Tr, // OK | ||
T: const async ?Tr, //~ ERROR `const async` trait not allowed with `?` trait polarity modifier | ||
T: const async Tr + 'a, // OK | ||
T: const async 'a, //~ ERROR `const` may only modify trait bounds, not lifetime bounds | ||
>; | ||
|
||
fn main() {} |
Oops, something went wrong.