2018-03-10 11:22:55 +01:00
|
|
|
// Test ignored_generic_bounds lint warning about bounds in type aliases
|
|
|
|
|
2018-04-02 13:20:06 +02:00
|
|
|
// compile-pass
|
2018-03-10 11:22:55 +01:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
|
|
|
use std::rc::Rc;
|
|
|
|
|
|
|
|
type SVec<T: Send+Send> = Vec<T>;
|
2018-03-10 11:43:51 +01:00
|
|
|
//~^ WARN bounds on generic parameters are not enforced in type aliases [type_alias_bounds]
|
2018-03-10 11:22:55 +01:00
|
|
|
type S2Vec<T> where T: Send = Vec<T>;
|
2018-03-10 11:43:51 +01:00
|
|
|
//~^ WARN where clauses are not enforced in type aliases [type_alias_bounds]
|
2018-03-10 11:22:55 +01:00
|
|
|
type VVec<'b, 'a: 'b+'b> = (&'b u32, Vec<&'a i32>);
|
2018-03-10 11:43:51 +01:00
|
|
|
//~^ WARN bounds on generic parameters are not enforced in type aliases [type_alias_bounds]
|
2018-03-10 11:22:55 +01:00
|
|
|
type WVec<'b, T: 'b+'b> = (&'b u32, Vec<T>);
|
2018-03-10 11:43:51 +01:00
|
|
|
//~^ WARN bounds on generic parameters are not enforced in type aliases [type_alias_bounds]
|
2018-03-10 11:22:55 +01:00
|
|
|
type W2Vec<'b, T> where T: 'b, T: 'b = (&'b u32, Vec<T>);
|
2018-03-10 11:43:51 +01:00
|
|
|
//~^ WARN where clauses are not enforced in type aliases [type_alias_bounds]
|
2018-03-10 11:22:55 +01:00
|
|
|
|
|
|
|
static STATIC : u32 = 0;
|
|
|
|
|
|
|
|
fn foo<'a>(y: &'a i32) {
|
|
|
|
// If any of the bounds above would matter, the code below would be rejected.
|
|
|
|
// This can be seen when replacing the type aliases above by newtype structs.
|
|
|
|
// (The type aliases have no unused parameters to make that a valid transformation.)
|
|
|
|
let mut x : SVec<_> = Vec::new();
|
|
|
|
x.push(Rc::new(42)); // is not send
|
|
|
|
|
|
|
|
let mut x : S2Vec<_> = Vec::new();
|
|
|
|
x.push(Rc::new(42)); // is not send
|
|
|
|
|
|
|
|
let mut x : VVec<'static, 'a> = (&STATIC, Vec::new());
|
|
|
|
x.1.push(y); // 'a: 'static does not hold
|
|
|
|
|
|
|
|
let mut x : WVec<'static, &'a i32> = (&STATIC, Vec::new());
|
|
|
|
x.1.push(y); // &'a i32: 'static does not hold
|
|
|
|
|
|
|
|
let mut x : W2Vec<'static, &'a i32> = (&STATIC, Vec::new());
|
|
|
|
x.1.push(y); // &'a i32: 'static does not hold
|
|
|
|
}
|
|
|
|
|
2018-11-27 03:59:49 +01:00
|
|
|
// Bounds are not checked either, i.e., the definition is not necessarily well-formed
|
2018-03-10 11:43:51 +01:00
|
|
|
struct Sendable<T: Send>(T);
|
|
|
|
type MySendable<T> = Sendable<T>; // no error here!
|
|
|
|
|
|
|
|
// However, bounds *are* taken into account when accessing associated types
|
|
|
|
trait Bound { type Assoc; }
|
2018-03-10 13:32:11 +01:00
|
|
|
type T1<U: Bound> = U::Assoc; //~ WARN not enforced in type aliases
|
|
|
|
type T2<U> where U: Bound = U::Assoc; //~ WARN not enforced in type aliases
|
|
|
|
|
|
|
|
// This errors
|
|
|
|
// type T3<U> = U::Assoc;
|
|
|
|
// Do this instead
|
2018-03-10 11:43:51 +01:00
|
|
|
type T4<U> = <U as Bound>::Assoc;
|
|
|
|
|
2018-03-10 13:32:11 +01:00
|
|
|
// Make sure the help about associatd types is not shown incorrectly
|
|
|
|
type T5<U: Bound> = <U as Bound>::Assoc; //~ WARN not enforced in type aliases
|
|
|
|
type T6<U: Bound> = ::std::vec::Vec<U>; //~ WARN not enforced in type aliases
|
|
|
|
|
2018-03-10 11:22:55 +01:00
|
|
|
fn main() {}
|