add lint to detect ignored generic bounds; this subsumes the previous 'generic bounds in type aliases are ignored' warning
This commit is contained in:
parent
d1ed6cce6c
commit
86821f7fb6
7 changed files with 279 additions and 78 deletions
|
|
@ -9,12 +9,18 @@
|
|||
// except according to those terms.
|
||||
|
||||
// must-compile-successfully
|
||||
#![allow(dead_code, non_camel_case_types)]
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
type SVec<T: Send> = Vec<T>;
|
||||
type VVec<'b, 'a: 'b> = Vec<&'a i32>;
|
||||
type WVec<'b, T: 'b> = Vec<T>;
|
||||
type SVec<T: Send+Send> = Vec<T>;
|
||||
//~^ WARN bounds on generic type 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
|
||||
type WVec<'b, T: 'b+'b> = Vec<T>;
|
||||
//~^ WARN bounds on generic type 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
|
||||
|
||||
fn foo<'a>(y: &'a i32) {
|
||||
// If the bounds above would matter, the code below would be rejected.
|
||||
|
|
@ -26,8 +32,73 @@ fn foo<'a>(y: &'a i32) {
|
|||
|
||||
let mut x : WVec<'static, & 'a i32> = Vec::new();
|
||||
x.push(y);
|
||||
|
||||
let mut x : W2Vec<'static, & 'a i32> = Vec::new();
|
||||
x.push(y);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo(&42);
|
||||
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
|
||||
{
|
||||
// If the bound in f's type would matter, the call below would (have to)
|
||||
// be rejected.
|
||||
f(x, y);
|
||||
}
|
||||
|
||||
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
|
||||
x: &'a i32,
|
||||
y: &'b i32,
|
||||
f: F)
|
||||
{
|
||||
// If the bound in f's type would matter, the call below would (have to)
|
||||
// be rejected.
|
||||
f(x, y);
|
||||
}
|
||||
|
||||
fn bar3<'a, 'b, F>(
|
||||
x: &'a i32,
|
||||
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
|
||||
{
|
||||
// If the bound in f's type would matter, the call below would (have to)
|
||||
// be rejected.
|
||||
f(x, y);
|
||||
}
|
||||
|
||||
fn bar4<'a, 'b, F>(
|
||||
x: &'a i32,
|
||||
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
|
||||
{
|
||||
// If the bound in f's type would matter, the call below would (have to)
|
||||
// be rejected.
|
||||
f(x, y);
|
||||
}
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,92 @@
|
|||
warning[E0122]: generic bounds are ignored in type aliases
|
||||
--> $DIR/param-bounds-ignored.rs:15:1
|
||||
warning: bounds on generic type parameters are ignored in type aliases
|
||||
--> $DIR/param-bounds-ignored.rs:16:14
|
||||
|
|
||||
LL | type SVec<T: Send> = Vec<T>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning[E0122]: generic bounds are ignored in type aliases
|
||||
--> $DIR/param-bounds-ignored.rs:16:1
|
||||
LL | type SVec<T: Send+Send> = Vec<T>;
|
||||
| ^^^^ ^^^^
|
||||
|
|
||||
LL | type VVec<'b, 'a: 'b> = Vec<&'a i32>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: #[warn(ignored_generic_bounds)] on by default
|
||||
|
||||
warning[E0122]: generic bounds are ignored in type aliases
|
||||
--> $DIR/param-bounds-ignored.rs:17:1
|
||||
warning: bounds on generic lifetime parameters are ignored in type aliases
|
||||
--> $DIR/param-bounds-ignored.rs:18:19
|
||||
|
|
||||
LL | type WVec<'b, T: 'b> = Vec<T>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
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
|
||||
|
|
||||
LL | type WVec<'b, T: 'b+'b> = Vec<T>;
|
||||
| ^^ ^^
|
||||
|
||||
warning: where clauses are ignored in type aliases
|
||||
--> $DIR/param-bounds-ignored.rs:22: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;
|
||||
| ^^^
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue