]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/type-alias-bounds.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Test ignored_generic_bounds lint warning about bounds in type aliases
13 // must-compile-successfully
18 type SVec
<T
: Send
+Send
> = Vec
<T
>;
19 //~^ WARN bounds on generic parameters are not enforced in type aliases [type_alias_bounds]
20 type S2Vec
<T
> where T
: Send
= Vec
<T
>;
21 //~^ WARN where clauses are not enforced in type aliases [type_alias_bounds]
22 type VVec
<'b
, 'a
: 'b
+'b
> = (&'b
u32, Vec
<&'a
i32>);
23 //~^ WARN bounds on generic parameters are not enforced in type aliases [type_alias_bounds]
24 type WVec
<'b
, T
: 'b
+'b
> = (&'b
u32, Vec
<T
>);
25 //~^ WARN bounds on generic parameters are not enforced in type aliases [type_alias_bounds]
26 type W2Vec
<'b
, T
> where T
: 'b
, T
: 'b
= (&'b
u32, Vec
<T
>);
27 //~^ WARN where clauses are not enforced in type aliases [type_alias_bounds]
29 static STATIC
: u32 = 0;
31 fn foo
<'a
>(y
: &'a
i32) {
32 // If any of the bounds above would matter, the code below would be rejected.
33 // This can be seen when replacing the type aliases above by newtype structs.
34 // (The type aliases have no unused parameters to make that a valid transformation.)
35 let mut x
: SVec
<_
> = Vec
::new();
36 x
.push(Rc
::new(42)); // is not send
38 let mut x
: S2Vec
<_
> = Vec
::new();
39 x
.push(Rc
::new(42)); // is not send
41 let mut x
: VVec
<'
static, 'a
> = (&STATIC
, Vec
::new());
42 x
.1.push(y
); // 'a: 'static does not hold
44 let mut x
: WVec
<'
static, &'a
i32> = (&STATIC
, Vec
::new());
45 x
.1.push(y
); // &'a i32: 'static does not hold
47 let mut x
: W2Vec
<'
static, &'a
i32> = (&STATIC
, Vec
::new());
48 x
.1.push(y
); // &'a i32: 'static does not hold
51 // Bounds are not checked either, i.e. the definition is not necessarily well-formed
52 struct Sendable
<T
: Send
>(T
);
53 type MySendable
<T
> = Sendable
<T
>; // no error here!
55 // However, bounds *are* taken into account when accessing associated types
56 trait Bound { type Assoc; }
57 type T1
<U
: Bound
> = U
::Assoc
; //~ WARN not enforced in type aliases
58 type T2
<U
> where U
: Bound
= U
::Assoc
; //~ WARN not enforced in type aliases
61 // type T3<U> = U::Assoc;
63 type T4
<U
> = <U
as Bound
>::Assoc
;
65 // Make sure the help about associatd types is not shown incorrectly
66 type T5
<U
: Bound
> = <U
as Bound
>::Assoc
; //~ WARN not enforced in type aliases
67 type T6
<U
: Bound
> = ::std
::vec
::Vec
<U
>; //~ WARN not enforced in type aliases