Reorder modifiers and polarity to be *after* binder in trait bounds

This commit is contained in:
Michael Goulet 2024-06-27 12:58:35 -04:00
parent 0c81f94b9a
commit e8445818d4
7 changed files with 19 additions and 45 deletions

View File

@ -978,7 +978,7 @@ fn parse_trait_bound_modifiers(&mut self) -> PResult<'a, TraitBoundModifiers> {
/// Parses a type bound according to:
/// ```ebnf
/// TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN)
/// TY_BOUND_NOPAREN = [TRAIT_BOUND_MODIFIERS] [for<LT_PARAM_DEFS>] SIMPLE_PATH
/// TY_BOUND_NOPAREN = [for<LT_PARAM_DEFS>] [TRAIT_BOUND_MODIFIERS] SIMPLE_PATH
/// ```
///
/// For example, this grammar accepts `for<'a: 'b> ~const ?m::Trait<'a>`.
@ -988,8 +988,8 @@ fn parse_generic_ty_bound(
has_parens: bool,
leading_token: &Token,
) -> PResult<'a, GenericBound> {
let modifiers = self.parse_trait_bound_modifiers()?;
let (mut lifetime_defs, binder_span) = self.parse_late_bound_lifetime_defs()?;
let modifiers = self.parse_trait_bound_modifiers()?;
// Recover erroneous lifetime bound with modifiers or binder.
// e.g. `T: for<'a> 'a` or `T: ~const 'a`.

View File

@ -15,7 +15,7 @@ async fn f(arg: &i32) {}
async fn func<F>(f: F)
where
F: async for<'a> Fn(&'a i32),
F: for<'a> async Fn(&'a i32),
{
let x: i32 = 0;
f(&x).await;

View File

@ -1,41 +1,8 @@
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/normalize-tait-in-const.rs:27:42
error: expected a trait, found type
--> $DIR/normalize-tait-in-const.rs:27:34
|
LL | const fn with_positive<F: ~const for<'a> Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
| ^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/normalize-tait-in-const.rs:27:69
|
LL | const fn with_positive<F: ~const for<'a> Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
| ^^^^^^^^
error: aborting due to 1 previous error
error[E0015]: cannot call non-const closure in constant functions
--> $DIR/normalize-tait-in-const.rs:28:5
|
LL | fun(filter_positive());
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
help: consider further restricting this bound
|
LL | const fn with_positive<F: ~const for<'a> Fn(&'a Alias<'a>) + ~const Destruct + ~const Fn(&foo::Alias<'_>)>(fun: F) {
| ++++++++++++++++++++++++++++
help: add `#![feature(effects)]` to the crate attributes to enable
|
LL + #![feature(effects)]
|
error[E0493]: destructor of `F` cannot be evaluated at compile-time
--> $DIR/normalize-tait-in-const.rs:27:79
|
LL | const fn with_positive<F: ~const for<'a> Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
| ^^^ the destructor for this type cannot be evaluated in constant functions
LL | fun(filter_positive());
LL | }
| - value is dropped here
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0015, E0493.
For more information about an error, try `rustc --explain E0015`.

View File

@ -1,5 +1,4 @@
//@ check-pass
#![allow(dead_code)]
fn f<T: ?for<'a> Sized>() {}
//~^ ERROR expected a trait, found type
fn main() {}

View File

@ -0,0 +1,8 @@
error: expected a trait, found type
--> $DIR/issue-39089.rs:1:10
|
LL | fn f<T: ?for<'a> Sized>() {}
| ^^^^^^^^^^^^^
error: aborting due to 1 previous error

View File

@ -5,7 +5,7 @@ struct S<
T: Tr + 'a, // OK
T: 'a, // OK
T:, // OK
T: ?for<'a> Trait, // OK
T: for<'a> ?Trait, // OK
T: Tr +, // OK
T: ?'a, //~ ERROR `?` may only modify trait bounds, not lifetime bounds

View File

@ -4,6 +4,6 @@
#![feature(const_trait_impl)]
struct S<
T: ~const ?for<'a> Tr<'a> + 'static + ~const std::ops::Add,
T: ~const ?for<'a: 'b> m::Trait<'a>,
T: for<'a> ~const ?Tr<'a> + 'static + ~const std::ops::Add,
T: for<'a: 'b> ~const ?m::Trait<'a>,
>;