Skip to content

Commit 81130ed

Browse files
committed
Split param-bounds-ignored into two, it was testing two independent things
Also, tweak the test for ignored type aliases such that replacing the type alias by a newtype struct leads to a well-formed type definition, and errors when used the way the type alias is used.
1 parent 3edb3cc commit 81130ed

File tree

4 files changed

+95
-62
lines changed

4 files changed

+95
-62
lines changed

src/test/ui/param-bounds-ignored.rs renamed to src/test/ui/higher-lifetime-bounds.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,7 @@
1010

1111
#![allow(dead_code, non_camel_case_types)]
1212

13-
use std::rc::Rc;
14-
15-
type SVec<T: Send+Send> = Vec<T>;
16-
//~^ WARN bounds on generic parameters are ignored in type aliases
17-
type VVec<'b, 'a: 'b+'b> = Vec<&'a i32>;
18-
//~^ WARN bounds on generic parameters are ignored in type aliases
19-
type WVec<'b, T: 'b+'b> = Vec<T>;
20-
//~^ WARN bounds on generic parameters are ignored in type aliases
21-
type W2Vec<'b, T> where T: 'b, T: 'b = Vec<T>;
22-
//~^ WARN where clauses are ignored in type aliases
23-
24-
fn foo<'a>(y: &'a i32) {
25-
// If the bounds above would matter, the code below would be rejected.
26-
let mut x : SVec<_> = Vec::new();
27-
x.push(Rc::new(42));
28-
29-
let mut x : VVec<'static, 'a> = Vec::new();
30-
x.push(y);
31-
32-
let mut x : WVec<'static, & 'a i32> = Vec::new();
33-
x.push(y);
34-
35-
let mut x : W2Vec<'static, & 'a i32> = Vec::new();
36-
x.push(y);
37-
}
13+
// Test that bounds on higher-kinded lifetime binders are rejected.
3814

3915
fn bar1<'a, 'b>(
4016
x: &'a i32,
Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,68 @@
11
error: lifetime bounds cannot be used in this context
2-
--> $DIR/param-bounds-ignored.rs:42:22
2+
--> $DIR/higher-lifetime-bounds.rs:18:22
33
|
44
LL | f: for<'xa, 'xb: 'xa+'xa> fn(&'xa i32, &'xb i32) -> &'xa i32)
55
| ^^^ ^^^
66

77
error: lifetime bounds cannot be used in this context
8-
--> $DIR/param-bounds-ignored.rs:50:34
8+
--> $DIR/higher-lifetime-bounds.rs:26:34
99
|
1010
LL | fn bar2<'a, 'b, F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(
1111
| ^^^
1212

1313
error: lifetime bounds cannot be used in this context
14-
--> $DIR/param-bounds-ignored.rs:65:28
14+
--> $DIR/higher-lifetime-bounds.rs:41:28
1515
|
1616
LL | where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32
1717
| ^^^
1818

1919
error: lifetime bounds cannot be used in this context
20-
--> $DIR/param-bounds-ignored.rs:77:25
20+
--> $DIR/higher-lifetime-bounds.rs:53:25
2121
|
2222
LL | where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32
2323
| ^^^
2424

2525
error: lifetime bounds cannot be used in this context
26-
--> $DIR/param-bounds-ignored.rs:85:28
26+
--> $DIR/higher-lifetime-bounds.rs:61:28
2727
|
2828
LL | struct S1<F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(F);
2929
| ^^^
3030

3131
error: lifetime bounds cannot be used in this context
32-
--> $DIR/param-bounds-ignored.rs:87:40
32+
--> $DIR/higher-lifetime-bounds.rs:63:40
3333
|
3434
LL | struct S2<F>(F) where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32;
3535
| ^^^
3636

3737
error: lifetime bounds cannot be used in this context
38-
--> $DIR/param-bounds-ignored.rs:89:37
38+
--> $DIR/higher-lifetime-bounds.rs:65:37
3939
|
4040
LL | struct S3<F>(F) where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32;
4141
| ^^^
4242

4343
error: lifetime bounds cannot be used in this context
44-
--> $DIR/param-bounds-ignored.rs:92:29
44+
--> $DIR/higher-lifetime-bounds.rs:68:29
4545
|
4646
LL | struct S_fnty(for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32);
4747
| ^^^
4848

4949
error: lifetime bounds cannot be used in this context
50-
--> $DIR/param-bounds-ignored.rs:95:29
50+
--> $DIR/higher-lifetime-bounds.rs:71:29
5151
|
5252
LL | type T1 = Box<for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>;
5353
| ^^^
5454

5555
error: lifetime bounds cannot be used in this context
56-
--> $DIR/param-bounds-ignored.rs:99:34
56+
--> $DIR/higher-lifetime-bounds.rs:75:34
5757
|
5858
LL | let _ : Option<for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32> = None;
5959
| ^^^
6060

6161
error: lifetime bounds cannot be used in this context
62-
--> $DIR/param-bounds-ignored.rs:101:38
62+
--> $DIR/higher-lifetime-bounds.rs:77:38
6363
|
6464
LL | let _ : Option<Box<for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>> = None;
6565
| ^^^
6666

67-
warning: bounds on generic parameters are ignored in type aliases
68-
--> $DIR/param-bounds-ignored.rs:15:14
69-
|
70-
LL | type SVec<T: Send+Send> = Vec<T>;
71-
| ^^^^ ^^^^
72-
|
73-
= note: #[warn(ignored_generic_bounds)] on by default
74-
75-
warning: bounds on generic parameters are ignored in type aliases
76-
--> $DIR/param-bounds-ignored.rs:17:19
77-
|
78-
LL | type VVec<'b, 'a: 'b+'b> = Vec<&'a i32>;
79-
| ^^ ^^
80-
81-
warning: bounds on generic parameters are ignored in type aliases
82-
--> $DIR/param-bounds-ignored.rs:19:18
83-
|
84-
LL | type WVec<'b, T: 'b+'b> = Vec<T>;
85-
| ^^ ^^
86-
87-
warning: where clauses are ignored in type aliases
88-
--> $DIR/param-bounds-ignored.rs:21:25
89-
|
90-
LL | type W2Vec<'b, T> where T: 'b, T: 'b = Vec<T>;
91-
| ^^^^^ ^^^^^
92-
9367
error: aborting due to 11 previous errors
9468

src/test/ui/type-alias-bounds.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.
4+
//
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.
10+
11+
// Test ignored_generic_bounds lint warning about bounds in type aliases
12+
13+
// must-compile-successfully
14+
#![allow(dead_code)]
15+
16+
use std::rc::Rc;
17+
18+
type SVec<T: Send+Send> = Vec<T>;
19+
//~^ WARN bounds on generic parameters are ignored in type aliases
20+
type S2Vec<T> where T: Send = Vec<T>;
21+
//~^ WARN where clauses are ignored in type aliases
22+
type VVec<'b, 'a: 'b+'b> = (&'b u32, Vec<&'a i32>);
23+
//~^ WARN bounds on generic parameters are ignored in type aliases
24+
type WVec<'b, T: 'b+'b> = (&'b u32, Vec<T>);
25+
//~^ WARN bounds on generic parameters are ignored in type aliases
26+
type W2Vec<'b, T> where T: 'b, T: 'b = (&'b u32, Vec<T>);
27+
//~^ WARN where clauses are ignored in type aliases
28+
29+
static STATIC : u32 = 0;
30+
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
37+
38+
let mut x : S2Vec<_> = Vec::new();
39+
x.push(Rc::new(42)); // is not send
40+
41+
let mut x : VVec<'static, 'a> = (&STATIC, Vec::new());
42+
x.1.push(y); // 'a: 'static does not hold
43+
44+
let mut x : WVec<'static, &'a i32> = (&STATIC, Vec::new());
45+
x.1.push(y); // &'a i32: 'static does not hold
46+
47+
let mut x : W2Vec<'static, &'a i32> = (&STATIC, Vec::new());
48+
x.1.push(y); // &'a i32: 'static does not hold
49+
}
50+
51+
fn main() {}

src/test/ui/type-alias-bounds.stderr

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
warning: bounds on generic parameters are ignored in type aliases
2+
--> $DIR/type-alias-bounds.rs:18:14
3+
|
4+
LL | type SVec<T: Send+Send> = Vec<T>;
5+
| ^^^^ ^^^^
6+
|
7+
= note: #[warn(ignored_generic_bounds)] on by default
8+
9+
warning: where clauses are ignored in type aliases
10+
--> $DIR/type-alias-bounds.rs:20:21
11+
|
12+
LL | type S2Vec<T> where T: Send = Vec<T>;
13+
| ^^^^^^^
14+
15+
warning: bounds on generic parameters are ignored in type aliases
16+
--> $DIR/type-alias-bounds.rs:22:19
17+
|
18+
LL | type VVec<'b, 'a: 'b+'b> = (&'b u32, Vec<&'a i32>);
19+
| ^^ ^^
20+
21+
warning: bounds on generic parameters are ignored in type aliases
22+
--> $DIR/type-alias-bounds.rs:24:18
23+
|
24+
LL | type WVec<'b, T: 'b+'b> = (&'b u32, Vec<T>);
25+
| ^^ ^^
26+
27+
warning: where clauses are ignored in type aliases
28+
--> $DIR/type-alias-bounds.rs:26:25
29+
|
30+
LL | type W2Vec<'b, T> where T: 'b, T: 'b = (&'b u32, Vec<T>);
31+
| ^^^^^ ^^^^^
32+

0 commit comments

Comments
 (0)