make bounds on higher-kinded lifetimes a hard error in ast_validation
Also move the check for not having type parameters into ast_validation. I was not sure what to do with compile-fail/issue-23046.rs: The issue looks like maybe the bounds actually played a role in triggering the ICE, but that seems unlikely given that the compiler seems to entirely ignore them. However, I couldn't find a testcase without the bounds, so I figured the best I could do is to just remove the bounds and make sure at least that keeps working.
This commit is contained in:
parent
30b5be0e95
commit
49abd87483
11 changed files with 182 additions and 183 deletions
17
src/test/compile-fail/bounds-lifetime.rs
Normal file
17
src/test/compile-fail/bounds-lifetime.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
type A = for<'b, 'a: 'b> fn(); //~ ERROR lifetime bounds cannot be used in this context
|
||||
type B = for<'b, 'a: 'b,> fn(); //~ ERROR lifetime bounds cannot be used in this context
|
||||
type C = for<'b, 'a: 'b +> fn(); //~ ERROR lifetime bounds cannot be used in this context
|
||||
type D = for<'a, T> fn(); //~ ERROR only lifetime parameters can be used in this context
|
||||
type E = for<T> Fn(); //~ ERROR only lifetime parameters can be used in this context
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -8,11 +8,9 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![allow(ignored_generic_bounds)]
|
||||
|
||||
pub enum Expr<'var, VAR> {
|
||||
Let(Box<Expr<'var, VAR>>,
|
||||
Box<for<'v: 'var> Fn(Expr<'v, VAR>) -> Expr<'v, VAR> + 'var>)
|
||||
Box<for<'v> Fn(Expr<'v, VAR>) -> Expr<'v, VAR> + 'var>)
|
||||
}
|
||||
|
||||
pub fn add<'var, VAR>
|
||||
|
|
@ -20,7 +18,7 @@ pub fn add<'var, VAR>
|
|||
loop {}
|
||||
}
|
||||
|
||||
pub fn let_<'var, VAR, F: for<'v: 'var> Fn(Expr<'v, VAR>) -> Expr<'v, VAR>>
|
||||
pub fn let_<'var, VAR, F: for<'v> Fn(Expr<'v, VAR>) -> Expr<'v, VAR>>
|
||||
(a: Expr<'var, VAR>, b: F) -> Expr<'var, VAR> {
|
||||
loop {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ mod traits {
|
|||
pub trait PubTr {}
|
||||
|
||||
pub type Alias<T: PrivTr> = T; //~ ERROR private trait `traits::PrivTr` in public interface
|
||||
//~^ WARNING bounds on generic type parameters are ignored
|
||||
//~^ WARNING bounds on generic parameters are ignored
|
||||
//~| WARNING hard error
|
||||
pub trait Tr1: PrivTr {} //~ ERROR private trait `traits::PrivTr` in public interface
|
||||
//~^ WARNING hard error
|
||||
|
|
|
|||
|
|
@ -8,17 +8,16 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags: -Z parse-only -Z continue-parse-after-error
|
||||
// compile-flags: -Z parse-only
|
||||
|
||||
type A = for<'a: 'b + 'c> fn(); // OK
|
||||
type A = for<'a: 'b,> fn(); // OK
|
||||
type A = for<'a:> fn(); // OK
|
||||
type A = for<'a:,> fn(); // OK
|
||||
type A = for<'a> fn(); // OK
|
||||
type A = for<> fn(); // OK
|
||||
type A = for<'a: 'b +> fn(); // OK
|
||||
|
||||
type A = for<'a, T> fn(); //~ ERROR only lifetime parameters can be used in this context
|
||||
type A = for<'a: 'b + 'c> fn(); // OK (rejected later by ast_validation)
|
||||
type A = for<'a: 'b,> fn(); // OK(rejected later by ast_validation)
|
||||
type A = for<'a: 'b +> fn(); // OK (rejected later by ast_validation)
|
||||
type A = for<'a, T> fn(); // OK (rejected later by ast_validation)
|
||||
type A = for<,> fn(); //~ ERROR expected one of `>`, identifier, or lifetime, found `,`
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ struct S<
|
|||
T: Tr + 'a, // OK
|
||||
T: 'a, // OK
|
||||
T:, // OK
|
||||
T: ?for<'a: 'b + 'c> Trait, // OK
|
||||
T: ?for<'a> Trait, // OK
|
||||
T: Tr +, // OK
|
||||
T: ?'a, //~ ERROR `?` may only modify trait bounds, not lifetime bounds
|
||||
>;
|
||||
|
|
|
|||
|
|
@ -69,8 +69,8 @@ fn foo(x: &impl Debug) -> &impl Debug { x }
|
|||
fn foo_explicit_lifetime<'a>(x: &'a impl Debug) -> &'a impl Debug { x }
|
||||
fn foo_explicit_arg<T: Debug>(x: &T) -> &impl Debug { x }
|
||||
|
||||
fn mixed_lifetimes<'a>() -> impl for<'b: 'a> Fn(&'b u32) { |_| () }
|
||||
fn mixed_as_static() -> impl Fn(&'static u32) { mixed_lifetimes() }
|
||||
fn mixed_lifetimes<'a>() -> impl for<'b> Fn(&'b &'a u32) { |_| () }
|
||||
fn mixed_as_static() -> impl Fn(&'static &'static u32) { mixed_lifetimes() }
|
||||
|
||||
trait MultiRegionTrait<'a, 'b>: Debug {}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,17 +8,16 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// must-compile-successfully
|
||||
#![allow(dead_code, non_camel_case_types)]
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
type SVec<T: Send+Send> = Vec<T>;
|
||||
//~^ WARN bounds on generic type parameters are ignored in type aliases
|
||||
//~^ WARN bounds on generic parameters are ignored in type aliases
|
||||
type VVec<'b, 'a: 'b+'b> = Vec<&'a i32>;
|
||||
//~^ WARN bounds on generic lifetime parameters are ignored in type aliases
|
||||
//~^ WARN bounds on generic parameters are ignored in type aliases
|
||||
type WVec<'b, T: 'b+'b> = Vec<T>;
|
||||
//~^ WARN bounds on generic type parameters are ignored in type aliases
|
||||
//~^ WARN bounds on generic parameters are ignored in type aliases
|
||||
type W2Vec<'b, T> where T: 'b, T: 'b = Vec<T>;
|
||||
//~^ WARN where clauses are ignored in type aliases
|
||||
|
||||
|
|
@ -40,8 +39,8 @@ fn foo<'a>(y: &'a i32) {
|
|||
fn bar1<'a, 'b>(
|
||||
x: &'a i32,
|
||||
y: &'b i32,
|
||||
f: for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32)
|
||||
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked function types
|
||||
f: for<'xa, 'xb: 'xa+'xa> fn(&'xa i32, &'xb i32) -> &'xa i32)
|
||||
//~^ ERROR lifetime bounds cannot be used in this context
|
||||
{
|
||||
// If the bound in f's type would matter, the call below would (have to)
|
||||
// be rejected.
|
||||
|
|
@ -49,7 +48,7 @@ fn bar1<'a, 'b>(
|
|||
}
|
||||
|
||||
fn bar2<'a, 'b, F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(
|
||||
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds
|
||||
//~^ ERROR lifetime bounds cannot be used in this context
|
||||
x: &'a i32,
|
||||
y: &'b i32,
|
||||
f: F)
|
||||
|
|
@ -64,7 +63,7 @@ fn bar3<'a, 'b, F>(
|
|||
y: &'b i32,
|
||||
f: F)
|
||||
where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32
|
||||
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds
|
||||
//~^ ERROR lifetime bounds cannot be used in this context
|
||||
{
|
||||
// If the bound in f's type would matter, the call below would (have to)
|
||||
// be rejected.
|
||||
|
|
@ -76,7 +75,7 @@ fn bar4<'a, 'b, F>(
|
|||
y: &'b i32,
|
||||
f: F)
|
||||
where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32
|
||||
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds
|
||||
//~^ ERROR lifetime bounds cannot be used in this context
|
||||
{
|
||||
// If the bound in f's type would matter, the call below would (have to)
|
||||
// be rejected.
|
||||
|
|
@ -84,21 +83,21 @@ fn bar4<'a, 'b, F>(
|
|||
}
|
||||
|
||||
struct S1<F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(F);
|
||||
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds
|
||||
//~^ ERROR lifetime bounds cannot be used in this context
|
||||
struct S2<F>(F) where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32;
|
||||
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds
|
||||
//~^ ERROR lifetime bounds cannot be used in this context
|
||||
struct S3<F>(F) where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32;
|
||||
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds
|
||||
//~^ ERROR lifetime bounds cannot be used in this context
|
||||
|
||||
struct S_fnty(for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32);
|
||||
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked function types
|
||||
//~^ ERROR lifetime bounds cannot be used in this context
|
||||
|
||||
type T1 = Box<for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>;
|
||||
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds
|
||||
//~^ ERROR lifetime bounds cannot be used in this context
|
||||
|
||||
fn main() {
|
||||
let _ : Option<for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32> = None;
|
||||
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked function types
|
||||
//~^ ERROR lifetime bounds cannot be used in this context
|
||||
let _ : Option<Box<for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>> = None;
|
||||
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds
|
||||
//~^ ERROR lifetime bounds cannot be used in this context
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,92 +1,94 @@
|
|||
warning: bounds on generic type parameters are ignored in type aliases
|
||||
--> $DIR/param-bounds-ignored.rs:16:14
|
||||
error: lifetime bounds cannot be used in this context
|
||||
--> $DIR/param-bounds-ignored.rs:42:22
|
||||
|
|
||||
LL | f: for<'xa, 'xb: 'xa+'xa> fn(&'xa i32, &'xb i32) -> &'xa i32)
|
||||
| ^^^ ^^^
|
||||
|
||||
error: lifetime bounds cannot be used in this context
|
||||
--> $DIR/param-bounds-ignored.rs:50:34
|
||||
|
|
||||
LL | fn bar2<'a, 'b, F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(
|
||||
| ^^^
|
||||
|
||||
error: lifetime bounds cannot be used in this context
|
||||
--> $DIR/param-bounds-ignored.rs:65:28
|
||||
|
|
||||
LL | where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32
|
||||
| ^^^
|
||||
|
||||
error: lifetime bounds cannot be used in this context
|
||||
--> $DIR/param-bounds-ignored.rs:77:25
|
||||
|
|
||||
LL | where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32
|
||||
| ^^^
|
||||
|
||||
error: lifetime bounds cannot be used in this context
|
||||
--> $DIR/param-bounds-ignored.rs:85:28
|
||||
|
|
||||
LL | struct S1<F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(F);
|
||||
| ^^^
|
||||
|
||||
error: lifetime bounds cannot be used in this context
|
||||
--> $DIR/param-bounds-ignored.rs:87:40
|
||||
|
|
||||
LL | struct S2<F>(F) where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32;
|
||||
| ^^^
|
||||
|
||||
error: lifetime bounds cannot be used in this context
|
||||
--> $DIR/param-bounds-ignored.rs:89:37
|
||||
|
|
||||
LL | struct S3<F>(F) where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32;
|
||||
| ^^^
|
||||
|
||||
error: lifetime bounds cannot be used in this context
|
||||
--> $DIR/param-bounds-ignored.rs:92:29
|
||||
|
|
||||
LL | struct S_fnty(for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32);
|
||||
| ^^^
|
||||
|
||||
error: lifetime bounds cannot be used in this context
|
||||
--> $DIR/param-bounds-ignored.rs:95:29
|
||||
|
|
||||
LL | type T1 = Box<for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>;
|
||||
| ^^^
|
||||
|
||||
error: lifetime bounds cannot be used in this context
|
||||
--> $DIR/param-bounds-ignored.rs:99:34
|
||||
|
|
||||
LL | let _ : Option<for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32> = None;
|
||||
| ^^^
|
||||
|
||||
error: lifetime bounds cannot be used in this context
|
||||
--> $DIR/param-bounds-ignored.rs:101:38
|
||||
|
|
||||
LL | let _ : Option<Box<for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>> = None;
|
||||
| ^^^
|
||||
|
||||
warning: bounds on generic parameters are ignored in type aliases
|
||||
--> $DIR/param-bounds-ignored.rs:15:14
|
||||
|
|
||||
LL | type SVec<T: Send+Send> = Vec<T>;
|
||||
| ^^^^ ^^^^
|
||||
|
|
||||
= note: #[warn(ignored_generic_bounds)] on by default
|
||||
|
||||
warning: bounds on generic lifetime parameters are ignored in type aliases
|
||||
--> $DIR/param-bounds-ignored.rs:18:19
|
||||
warning: bounds on generic parameters are ignored in type aliases
|
||||
--> $DIR/param-bounds-ignored.rs:17:19
|
||||
|
|
||||
LL | type VVec<'b, 'a: 'b+'b> = Vec<&'a i32>;
|
||||
| ^^ ^^
|
||||
|
||||
warning: bounds on generic type parameters are ignored in type aliases
|
||||
--> $DIR/param-bounds-ignored.rs:20:18
|
||||
warning: bounds on generic parameters are ignored in type aliases
|
||||
--> $DIR/param-bounds-ignored.rs:19:18
|
||||
|
|
||||
LL | type WVec<'b, T: 'b+'b> = Vec<T>;
|
||||
| ^^ ^^
|
||||
|
||||
warning: where clauses are ignored in type aliases
|
||||
--> $DIR/param-bounds-ignored.rs:22:25
|
||||
--> $DIR/param-bounds-ignored.rs:21:25
|
||||
|
|
||||
LL | type W2Vec<'b, T> where T: 'b, T: 'b = Vec<T>;
|
||||
| ^^^^^ ^^^^^
|
||||
|
||||
warning: bounds on generic lifetime parameters are ignored in higher-ranked function types (i.e., `for`)
|
||||
--> $DIR/param-bounds-ignored.rs:43:22
|
||||
|
|
||||
LL | f: for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32)
|
||||
| ^^^
|
||||
|
||||
warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`)
|
||||
--> $DIR/param-bounds-ignored.rs:51:34
|
||||
|
|
||||
LL | fn bar2<'a, 'b, F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(
|
||||
| ^^^
|
||||
|
||||
warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`)
|
||||
--> $DIR/param-bounds-ignored.rs:66:28
|
||||
|
|
||||
LL | where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32
|
||||
| ^^^
|
||||
|
||||
warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`)
|
||||
--> $DIR/param-bounds-ignored.rs:78:25
|
||||
|
|
||||
LL | where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32
|
||||
| ^^^
|
||||
|
||||
warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`)
|
||||
--> $DIR/param-bounds-ignored.rs:86:28
|
||||
|
|
||||
LL | struct S1<F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(F);
|
||||
| ^^^
|
||||
|
||||
warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`)
|
||||
--> $DIR/param-bounds-ignored.rs:88:40
|
||||
|
|
||||
LL | struct S2<F>(F) where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32;
|
||||
| ^^^
|
||||
|
||||
warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`)
|
||||
--> $DIR/param-bounds-ignored.rs:90:37
|
||||
|
|
||||
LL | struct S3<F>(F) where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32;
|
||||
| ^^^
|
||||
|
||||
warning: bounds on generic lifetime parameters are ignored in higher-ranked function types (i.e., `for`)
|
||||
--> $DIR/param-bounds-ignored.rs:93:29
|
||||
|
|
||||
LL | struct S_fnty(for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32);
|
||||
| ^^^
|
||||
|
||||
warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`)
|
||||
--> $DIR/param-bounds-ignored.rs:96:29
|
||||
|
|
||||
LL | type T1 = Box<for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>;
|
||||
| ^^^
|
||||
|
||||
warning: bounds on generic lifetime parameters are ignored in higher-ranked function types (i.e., `for`)
|
||||
--> $DIR/param-bounds-ignored.rs:100:34
|
||||
|
|
||||
LL | let _ : Option<for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32> = None;
|
||||
| ^^^
|
||||
|
||||
warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`)
|
||||
--> $DIR/param-bounds-ignored.rs:102:38
|
||||
|
|
||||
LL | let _ : Option<Box<for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>> = None;
|
||||
| ^^^
|
||||
error: aborting due to 11 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue