Reorder modifiers and polarity to be *after* binder in trait bounds
This commit is contained in:
parent
0c81f94b9a
commit
e8445818d4
@ -978,7 +978,7 @@ fn parse_trait_bound_modifiers(&mut self) -> PResult<'a, TraitBoundModifiers> {
|
|||||||
/// Parses a type bound according to:
|
/// Parses a type bound according to:
|
||||||
/// ```ebnf
|
/// ```ebnf
|
||||||
/// TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN)
|
/// 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>`.
|
/// For example, this grammar accepts `for<'a: 'b> ~const ?m::Trait<'a>`.
|
||||||
@ -988,8 +988,8 @@ fn parse_generic_ty_bound(
|
|||||||
has_parens: bool,
|
has_parens: bool,
|
||||||
leading_token: &Token,
|
leading_token: &Token,
|
||||||
) -> PResult<'a, GenericBound> {
|
) -> PResult<'a, GenericBound> {
|
||||||
let modifiers = self.parse_trait_bound_modifiers()?;
|
|
||||||
let (mut lifetime_defs, binder_span) = self.parse_late_bound_lifetime_defs()?;
|
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.
|
// Recover erroneous lifetime bound with modifiers or binder.
|
||||||
// e.g. `T: for<'a> 'a` or `T: ~const 'a`.
|
// e.g. `T: for<'a> 'a` or `T: ~const 'a`.
|
||||||
|
@ -15,7 +15,7 @@ async fn f(arg: &i32) {}
|
|||||||
|
|
||||||
async fn func<F>(f: F)
|
async fn func<F>(f: F)
|
||||||
where
|
where
|
||||||
F: async for<'a> Fn(&'a i32),
|
F: for<'a> async Fn(&'a i32),
|
||||||
{
|
{
|
||||||
let x: i32 = 0;
|
let x: i32 = 0;
|
||||||
f(&x).await;
|
f(&x).await;
|
||||||
|
@ -1,41 +1,8 @@
|
|||||||
error: `~const` can only be applied to `#[const_trait]` traits
|
error: expected a trait, found type
|
||||||
--> $DIR/normalize-tait-in-const.rs:27:42
|
--> $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) {
|
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
|
error: aborting due to 1 previous error
|
||||||
--> $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[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`.
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
//@ check-pass
|
|
||||||
#![allow(dead_code)]
|
|
||||||
fn f<T: ?for<'a> Sized>() {}
|
fn f<T: ?for<'a> Sized>() {}
|
||||||
|
//~^ ERROR expected a trait, found type
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
8
tests/ui/issues/issue-39089.stderr
Normal file
8
tests/ui/issues/issue-39089.stderr
Normal 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
|
||||||
|
|
@ -5,7 +5,7 @@ struct S<
|
|||||||
T: Tr + 'a, // OK
|
T: Tr + 'a, // OK
|
||||||
T: 'a, // OK
|
T: 'a, // OK
|
||||||
T:, // OK
|
T:, // OK
|
||||||
T: ?for<'a> Trait, // OK
|
T: for<'a> ?Trait, // OK
|
||||||
T: Tr +, // OK
|
T: Tr +, // OK
|
||||||
T: ?'a, //~ ERROR `?` may only modify trait bounds, not lifetime bounds
|
T: ?'a, //~ ERROR `?` may only modify trait bounds, not lifetime bounds
|
||||||
|
|
||||||
|
@ -4,6 +4,6 @@
|
|||||||
#![feature(const_trait_impl)]
|
#![feature(const_trait_impl)]
|
||||||
|
|
||||||
struct S<
|
struct S<
|
||||||
T: ~const ?for<'a> Tr<'a> + 'static + ~const std::ops::Add,
|
T: for<'a> ~const ?Tr<'a> + 'static + ~const std::ops::Add,
|
||||||
T: ~const ?for<'a: 'b> m::Trait<'a>,
|
T: for<'a: 'b> ~const ?m::Trait<'a>,
|
||||||
>;
|
>;
|
||||||
|
Loading…
Reference in New Issue
Block a user