Skip to content

Commit 5116f84

Browse files
committed
more precise spans; list phased-out error code in diagnostics.rs
1 parent 0c5bc12 commit 5116f84

File tree

5 files changed

+120
-76
lines changed

5 files changed

+120
-76
lines changed

src/librustc_lint/builtin.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,24 +1407,32 @@ impl LintPass for IgnoredGenericBounds {
14071407
impl IgnoredGenericBounds {
14081408
fn ensure_no_param_bounds(
14091409
cx: &EarlyContext,
1410-
span: Span,
14111410
generics: &Vec<ast::GenericParam>,
14121411
thing: &'static str,
14131412
) {
1414-
let has_bound = generics.iter().any(|param|
1413+
for param in generics.iter() {
14151414
match param {
14161415
&ast::GenericParam::Lifetime(ref lifetime) => {
1417-
!lifetime.bounds.is_empty()
1416+
if !lifetime.bounds.is_empty() {
1417+
cx.span_lint(
1418+
IGNORED_GENERIC_BOUNDS,
1419+
lifetime.bounds[0].span,
1420+
format!("bounds on generic lifetime parameters are ignored in {}",
1421+
thing).as_ref()
1422+
);
1423+
}
14181424
}
14191425
&ast::GenericParam::Type(ref ty) => {
1420-
!ty.bounds.is_empty()
1426+
if !ty.bounds.is_empty() {
1427+
cx.span_lint(
1428+
IGNORED_GENERIC_BOUNDS,
1429+
ty.bounds[0].span(),
1430+
format!("bounds on generic type parameters are ignored in {}", thing)
1431+
.as_ref()
1432+
);
1433+
}
14211434
}
14221435
}
1423-
);
1424-
1425-
if has_bound {
1426-
cx.span_lint(IGNORED_GENERIC_BOUNDS, span,
1427-
format!("bounds on generic parameters are ignored in {}", thing).as_ref());
14281436
}
14291437
}
14301438
}
@@ -1434,10 +1442,11 @@ impl EarlyLintPass for IgnoredGenericBounds {
14341442
match item.node {
14351443
ast::ItemKind::Ty(_, ref generics) => {
14361444
if !generics.where_clause.predicates.is_empty() {
1437-
cx.span_lint(IGNORED_GENERIC_BOUNDS, item.span,
1438-
"where clauses are ignored in trait bounds");
1445+
cx.span_lint(IGNORED_GENERIC_BOUNDS,
1446+
generics.where_clause.predicates[0].span(),
1447+
"where clauses are ignored in type aliases");
14391448
}
1440-
IgnoredGenericBounds::ensure_no_param_bounds(cx, item.span, &generics.params,
1449+
IgnoredGenericBounds::ensure_no_param_bounds(cx, &generics.params,
14411450
"type aliases");
14421451
}
14431452
_ => {}
@@ -1447,21 +1456,21 @@ impl EarlyLintPass for IgnoredGenericBounds {
14471456
fn check_where_predicate(&mut self, cx: &EarlyContext, p: &ast::WherePredicate) {
14481457
if let &ast::WherePredicate::BoundPredicate(ref bound_predicate) = p {
14491458
// A type binding, eg `for<'c> Foo: Send+Clone+'c`
1450-
IgnoredGenericBounds::ensure_no_param_bounds(cx, bound_predicate.span,
1459+
IgnoredGenericBounds::ensure_no_param_bounds(cx,
14511460
&bound_predicate.bound_generic_params, "higher-ranked trait bounds (i.e., `for`)");
14521461
}
14531462
}
14541463

14551464
fn check_poly_trait_ref(&mut self, cx: &EarlyContext, t: &ast::PolyTraitRef,
14561465
_: &ast::TraitBoundModifier) {
1457-
IgnoredGenericBounds::ensure_no_param_bounds(cx, t.span, &t.bound_generic_params,
1466+
IgnoredGenericBounds::ensure_no_param_bounds(cx, &t.bound_generic_params,
14581467
"higher-ranked trait bounds (i.e., `for`)");
14591468
}
14601469

14611470
fn check_ty(&mut self, cx: &EarlyContext, ty: &ast::Ty) {
14621471
match ty.node {
14631472
ast::TyKind::BareFn(ref fn_ty) => {
1464-
IgnoredGenericBounds::ensure_no_param_bounds(cx, ty.span, &fn_ty.generic_params,
1473+
IgnoredGenericBounds::ensure_no_param_bounds(cx, &fn_ty.generic_params,
14651474
"higher-ranked function types (i.e., `for`)");
14661475
}
14671476
_ => {}

src/librustc_typeck/diagnostics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4737,6 +4737,7 @@ register_diagnostics! {
47374737
// E0086,
47384738
// E0103,
47394739
// E0104,
4740+
// E0122, // bounds in type aliases are ignored, turned into proper lint
47404741
// E0123,
47414742
// E0127,
47424743
// E0129,

src/libsyntax/ast.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,15 @@ pub enum TyParamBound {
294294
RegionTyParamBound(Lifetime)
295295
}
296296

297+
impl TyParamBound {
298+
pub fn span(&self) -> Span {
299+
match self {
300+
&TraitTyParamBound(ref t, ..) => t.span,
301+
&RegionTyParamBound(ref l) => l.span,
302+
}
303+
}
304+
}
305+
297306
/// A modifier on a bound, currently this is only used for `?Sized`, where the
298307
/// modifier is `Maybe`. Negative bounds should also be handled here.
299308
#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
@@ -404,6 +413,16 @@ pub enum WherePredicate {
404413
EqPredicate(WhereEqPredicate),
405414
}
406415

416+
impl WherePredicate {
417+
pub fn span(&self) -> Span {
418+
match self {
419+
&WherePredicate::BoundPredicate(ref p) => p.span,
420+
&WherePredicate::RegionPredicate(ref p) => p.span,
421+
&WherePredicate::EqPredicate(ref p) => p.span,
422+
}
423+
}
424+
}
425+
407426
/// A type bound.
408427
///
409428
/// E.g. `for<'c> Foo: Send+Clone+'c`

src/test/ui/param-bounds-ignored.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
use std::rc::Rc;
1515

1616
type SVec<T: Send> = Vec<T>;
17+
//~^ WARN bounds on generic type parameters are ignored in type aliases
1718
type VVec<'b, 'a: 'b> = Vec<&'a i32>;
19+
//~^ WARN bounds on generic lifetime parameters are ignored in type aliases
1820
type WVec<'b, T: 'b> = Vec<T>;
21+
//~^ WARN bounds on generic type parameters are ignored in type aliases
1922
type W2Vec<'b, T> where T: 'b = Vec<T>;
23+
//~^ WARN where clauses are ignored in type aliases
2024

2125
fn foo<'a>(y: &'a i32) {
2226
// If the bounds above would matter, the code below would be rejected.
@@ -37,13 +41,15 @@ fn bar1<'a, 'b>(
3741
x: &'a i32,
3842
y: &'b i32,
3943
f: for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32)
44+
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked function types
4045
{
4146
// If the bound in f's type would matter, the call below would (have to)
4247
// be rejected.
4348
f(x, y);
4449
}
4550

4651
fn bar2<'a, 'b, F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(
52+
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds
4753
x: &'a i32,
4854
y: &'b i32,
4955
f: F)
@@ -58,6 +64,7 @@ fn bar3<'a, 'b, F>(
5864
y: &'b i32,
5965
f: F)
6066
where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32
67+
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds
6168
{
6269
// If the bound in f's type would matter, the call below would (have to)
6370
// be rejected.
@@ -69,21 +76,29 @@ fn bar4<'a, 'b, F>(
6976
y: &'b i32,
7077
f: F)
7178
where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32
79+
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds
7280
{
7381
// If the bound in f's type would matter, the call below would (have to)
7482
// be rejected.
7583
f(x, y);
7684
}
7785

7886
struct S1<F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(F);
87+
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds
7988
struct S2<F>(F) where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32;
89+
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds
8090
struct S3<F>(F) where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32;
91+
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds
8192

8293
struct S_fnty(for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32);
94+
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked function types
8395

8496
type T1 = Box<for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>;
97+
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds
8598

8699
fn main() {
87100
let _ : Option<for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32> = None;
101+
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked function types
88102
let _ : Option<Box<for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>> = None;
103+
//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds
89104
}
Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,92 @@
1-
warning: bounds on generic parameters are ignored in type aliases
2-
--> $DIR/param-bounds-ignored.rs:16:1
1+
warning: bounds on generic type parameters are ignored in type aliases
2+
--> $DIR/param-bounds-ignored.rs:16:14
33
|
44
16 | type SVec<T: Send> = Vec<T>;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^
66
|
77
= note: #[warn(ignored_generic_bounds)] on by default
88

9-
warning: bounds on generic parameters are ignored in type aliases
10-
--> $DIR/param-bounds-ignored.rs:17:1
9+
warning: bounds on generic lifetime parameters are ignored in type aliases
10+
--> $DIR/param-bounds-ignored.rs:18:19
1111
|
12-
17 | type VVec<'b, 'a: 'b> = Vec<&'a i32>;
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
18 | type VVec<'b, 'a: 'b> = Vec<&'a i32>;
13+
| ^^
1414

15-
warning: bounds on generic parameters are ignored in type aliases
16-
--> $DIR/param-bounds-ignored.rs:18:1
15+
warning: bounds on generic type parameters are ignored in type aliases
16+
--> $DIR/param-bounds-ignored.rs:20:18
1717
|
18-
18 | type WVec<'b, T: 'b> = Vec<T>;
19-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
20 | type WVec<'b, T: 'b> = Vec<T>;
19+
| ^^
2020

21-
warning: where clauses are ignored in trait bounds
22-
--> $DIR/param-bounds-ignored.rs:19:1
21+
warning: where clauses are ignored in type aliases
22+
--> $DIR/param-bounds-ignored.rs:22:25
2323
|
24-
19 | type W2Vec<'b, T> where T: 'b = Vec<T>;
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24+
22 | type W2Vec<'b, T> where T: 'b = Vec<T>;
25+
| ^^^^^
2626

27-
warning: bounds on generic parameters are ignored in higher-ranked function types (i.e., `for`)
28-
--> $DIR/param-bounds-ignored.rs:39:8
27+
warning: bounds on generic lifetime parameters are ignored in higher-ranked function types (i.e., `for`)
28+
--> $DIR/param-bounds-ignored.rs:43:22
2929
|
30-
39 | f: for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32)
31-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
43 | f: for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32)
31+
| ^^^
3232

33-
warning: bounds on generic parameters are ignored in higher-ranked trait bounds (i.e., `for`)
34-
--> $DIR/param-bounds-ignored.rs:46:20
33+
warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`)
34+
--> $DIR/param-bounds-ignored.rs:51:34
3535
|
36-
46 | fn bar2<'a, 'b, F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(
37-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
51 | fn bar2<'a, 'b, F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(
37+
| ^^^
3838

39-
warning: bounds on generic parameters are ignored in higher-ranked trait bounds (i.e., `for`)
40-
--> $DIR/param-bounds-ignored.rs:60:14
39+
warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`)
40+
--> $DIR/param-bounds-ignored.rs:66:28
4141
|
42-
60 | where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32
43-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42+
66 | where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32
43+
| ^^^
4444

45-
warning: bounds on generic parameters are ignored in higher-ranked trait bounds (i.e., `for`)
46-
--> $DIR/param-bounds-ignored.rs:71:11
45+
warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`)
46+
--> $DIR/param-bounds-ignored.rs:78:25
4747
|
48-
71 | where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32
49-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
48+
78 | where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32
49+
| ^^^
5050

51-
warning: bounds on generic parameters are ignored in higher-ranked trait bounds (i.e., `for`)
52-
--> $DIR/param-bounds-ignored.rs:78:14
51+
warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`)
52+
--> $DIR/param-bounds-ignored.rs:86:28
5353
|
54-
78 | struct S1<F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(F);
55-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
54+
86 | struct S1<F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(F);
55+
| ^^^
5656

57-
warning: bounds on generic parameters are ignored in higher-ranked trait bounds (i.e., `for`)
58-
--> $DIR/param-bounds-ignored.rs:79:26
57+
warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`)
58+
--> $DIR/param-bounds-ignored.rs:88:40
5959
|
60-
79 | struct S2<F>(F) where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32;
61-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60+
88 | struct S2<F>(F) where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32;
61+
| ^^^
6262

63-
warning: bounds on generic parameters are ignored in higher-ranked trait bounds (i.e., `for`)
64-
--> $DIR/param-bounds-ignored.rs:80:23
63+
warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`)
64+
--> $DIR/param-bounds-ignored.rs:90:37
6565
|
66-
80 | struct S3<F>(F) where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32;
67-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66+
90 | struct S3<F>(F) where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32;
67+
| ^^^
6868

69-
warning: bounds on generic parameters are ignored in higher-ranked function types (i.e., `for`)
70-
--> $DIR/param-bounds-ignored.rs:82:15
69+
warning: bounds on generic lifetime parameters are ignored in higher-ranked function types (i.e., `for`)
70+
--> $DIR/param-bounds-ignored.rs:93:29
7171
|
72-
82 | struct S_fnty(for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32);
73-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
72+
93 | struct S_fnty(for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32);
73+
| ^^^
7474

75-
warning: bounds on generic parameters are ignored in higher-ranked trait bounds (i.e., `for`)
76-
--> $DIR/param-bounds-ignored.rs:84:15
75+
warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`)
76+
--> $DIR/param-bounds-ignored.rs:96:29
7777
|
78-
84 | type T1 = Box<for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>;
79-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
78+
96 | type T1 = Box<for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>;
79+
| ^^^
8080

81-
warning: bounds on generic parameters are ignored in higher-ranked function types (i.e., `for`)
82-
--> $DIR/param-bounds-ignored.rs:87:20
83-
|
84-
87 | let _ : Option<for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32> = None;
85-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
81+
warning: bounds on generic lifetime parameters are ignored in higher-ranked function types (i.e., `for`)
82+
--> $DIR/param-bounds-ignored.rs:100:34
83+
|
84+
100 | let _ : Option<for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32> = None;
85+
| ^^^
8686

87-
warning: bounds on generic parameters are ignored in higher-ranked trait bounds (i.e., `for`)
88-
--> $DIR/param-bounds-ignored.rs:88:24
89-
|
90-
88 | let _ : Option<Box<for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>> = None;
91-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
87+
warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`)
88+
--> $DIR/param-bounds-ignored.rs:102:38
89+
|
90+
102 | let _ : Option<Box<for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>> = None;
91+
| ^^^
9292

0 commit comments

Comments
 (0)