about summary refs log tree commit diff
path: root/tests/ui/issues
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-07-25 04:43:18 +0200
committerGitHub <noreply@github.com>2024-07-25 04:43:18 +0200
commitcfc5f25b3d7c2f9fa37d0165085cdd4120939716 (patch)
treed0f2623102a192d2a45a1683529eb39405bb793b /tests/ui/issues
parente7d66eac5e8e8f60370c98d186aee9fa0ebd7845 (diff)
parent7da751a108a31b52650d055202e89a15f43ce0e7 (diff)
downloadrust-cfc5f25b3d7c2f9fa37d0165085cdd4120939716.tar.gz
rust-cfc5f25b3d7c2f9fa37d0165085cdd4120939716.zip
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 `?`.
Diffstat (limited to 'tests/ui/issues')
-rw-r--r--tests/ui/issues/issue-39089.rs3
-rw-r--r--tests/ui/issues/issue-39089.stderr10
2 files changed, 11 insertions, 2 deletions
diff --git a/tests/ui/issues/issue-39089.rs b/tests/ui/issues/issue-39089.rs
index b00b8423802..822c47503af 100644
--- a/tests/ui/issues/issue-39089.rs
+++ b/tests/ui/issues/issue-39089.rs
@@ -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() {}
diff --git a/tests/ui/issues/issue-39089.stderr b/tests/ui/issues/issue-39089.stderr
new file mode 100644
index 00000000000..a81010aedff
--- /dev/null
+++ b/tests/ui/issues/issue-39089.stderr
@@ -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
+