Skip to content

Commit e844581

Browse files
Reorder modifiers and polarity to be *after* binder in trait bounds
1 parent 0c81f94 commit e844581

File tree

7 files changed

+19
-45
lines changed

7 files changed

+19
-45
lines changed

compiler/rustc_parse/src/parser/ty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ impl<'a> Parser<'a> {
978978
/// Parses a type bound according to:
979979
/// ```ebnf
980980
/// TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN)
981-
/// TY_BOUND_NOPAREN = [TRAIT_BOUND_MODIFIERS] [for<LT_PARAM_DEFS>] SIMPLE_PATH
981+
/// TY_BOUND_NOPAREN = [for<LT_PARAM_DEFS>] [TRAIT_BOUND_MODIFIERS] SIMPLE_PATH
982982
/// ```
983983
///
984984
/// For example, this grammar accepts `for<'a: 'b> ~const ?m::Trait<'a>`.
@@ -988,8 +988,8 @@ impl<'a> Parser<'a> {
988988
has_parens: bool,
989989
leading_token: &Token,
990990
) -> PResult<'a, GenericBound> {
991-
let modifiers = self.parse_trait_bound_modifiers()?;
992991
let (mut lifetime_defs, binder_span) = self.parse_late_bound_lifetime_defs()?;
992+
let modifiers = self.parse_trait_bound_modifiers()?;
993993

994994
// Recover erroneous lifetime bound with modifiers or binder.
995995
// e.g. `T: for<'a> 'a` or `T: ~const 'a`.

tests/ui/async-await/async-fn/higher-ranked-async-fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async fn f(arg: &i32) {}
1515

1616
async fn func<F>(f: F)
1717
where
18-
F: async for<'a> Fn(&'a i32),
18+
F: for<'a> async Fn(&'a i32),
1919
{
2020
let x: i32 = 0;
2121
f(&x).await;
Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,8 @@
1-
error: `~const` can only be applied to `#[const_trait]` traits
2-
--> $DIR/normalize-tait-in-const.rs:27:42
1+
error: expected a trait, found type
2+
--> $DIR/normalize-tait-in-const.rs:27:34
33
|
44
LL | const fn with_positive<F: ~const for<'a> Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
5-
| ^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
66

7-
error: `~const` can only be applied to `#[const_trait]` traits
8-
--> $DIR/normalize-tait-in-const.rs:27:69
9-
|
10-
LL | const fn with_positive<F: ~const for<'a> Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
11-
| ^^^^^^^^
12-
13-
error[E0015]: cannot call non-const closure in constant functions
14-
--> $DIR/normalize-tait-in-const.rs:28:5
15-
|
16-
LL | fun(filter_positive());
17-
| ^^^^^^^^^^^^^^^^^^^^^^
18-
|
19-
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
20-
help: consider further restricting this bound
21-
|
22-
LL | const fn with_positive<F: ~const for<'a> Fn(&'a Alias<'a>) + ~const Destruct + ~const Fn(&foo::Alias<'_>)>(fun: F) {
23-
| ++++++++++++++++++++++++++++
24-
help: add `#![feature(effects)]` to the crate attributes to enable
25-
|
26-
LL + #![feature(effects)]
27-
|
28-
29-
error[E0493]: destructor of `F` cannot be evaluated at compile-time
30-
--> $DIR/normalize-tait-in-const.rs:27:79
31-
|
32-
LL | const fn with_positive<F: ~const for<'a> Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
33-
| ^^^ the destructor for this type cannot be evaluated in constant functions
34-
LL | fun(filter_positive());
35-
LL | }
36-
| - value is dropped here
37-
38-
error: aborting due to 4 previous errors
7+
error: aborting due to 1 previous error
398

40-
Some errors have detailed explanations: E0015, E0493.
41-
For more information about an error, try `rustc --explain E0015`.

tests/ui/issues/issue-39089.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//@ check-pass
2-
#![allow(dead_code)]
31
fn f<T: ?for<'a> Sized>() {}
2+
//~^ ERROR expected a trait, found type
43

54
fn main() {}

tests/ui/issues/issue-39089.stderr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected a trait, found type
2+
--> $DIR/issue-39089.rs:1:10
3+
|
4+
LL | fn f<T: ?for<'a> Sized>() {}
5+
| ^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+

tests/ui/parser/bounds-type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ struct S<
55
T: Tr + 'a, // OK
66
T: 'a, // OK
77
T:, // OK
8-
T: ?for<'a> Trait, // OK
8+
T: for<'a> ?Trait, // OK
99
T: Tr +, // OK
1010
T: ?'a, //~ ERROR `?` may only modify trait bounds, not lifetime bounds
1111

tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-syntax.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
#![feature(const_trait_impl)]
55

66
struct S<
7-
T: ~const ?for<'a> Tr<'a> + 'static + ~const std::ops::Add,
8-
T: ~const ?for<'a: 'b> m::Trait<'a>,
7+
T: for<'a> ~const ?Tr<'a> + 'static + ~const std::ops::Add,
8+
T: for<'a: 'b> ~const ?m::Trait<'a>,
99
>;

0 commit comments

Comments
 (0)