Skip to content

Commit 562b44d

Browse files
committed
Rename ignored_generic_bounds -> type_alias_bounds
First of all, the lint is specific for type aliases. Second, it turns out the bounds are not entirely ignored but actually used when accessing associated types. So change the wording of the lint, and adapt its name to reality. The lint has never been on stable or beta, so renaming is safe.
1 parent 81130ed commit 562b44d

File tree

6 files changed

+68
-33
lines changed

6 files changed

+68
-33
lines changed

src/librustc_lint/builtin.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,24 +1316,25 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnreachablePub {
13161316
}
13171317
}
13181318

1319-
/// Lint for trait and lifetime bounds that are (accidentally) accepted by the parser, but
1320-
/// ignored later.
1319+
/// Lint for trait and lifetime bounds in type aliases being mostly ignored:
1320+
/// They are relevant when using associated types, but otherwise neither checked
1321+
/// at definition site nor enforced at use site.
13211322
1322-
pub struct IgnoredGenericBounds;
1323+
pub struct TypeAliasBounds;
13231324

13241325
declare_lint! {
1325-
IGNORED_GENERIC_BOUNDS,
1326+
TYPE_ALIAS_BOUNDS,
13261327
Warn,
1327-
"these generic bounds are ignored"
1328+
"bounds in type aliases are not enforced"
13281329
}
13291330

1330-
impl LintPass for IgnoredGenericBounds {
1331+
impl LintPass for TypeAliasBounds {
13311332
fn get_lints(&self) -> LintArray {
1332-
lint_array!(IGNORED_GENERIC_BOUNDS)
1333+
lint_array!(TYPE_ALIAS_BOUNDS)
13331334
}
13341335
}
13351336

1336-
impl EarlyLintPass for IgnoredGenericBounds {
1337+
impl EarlyLintPass for TypeAliasBounds {
13371338
fn check_item(&mut self, cx: &EarlyContext, item: &ast::Item) {
13381339
let type_alias_generics = match item.node {
13391340
ast::ItemKind::Ty(_, ref generics) => generics,
@@ -1343,8 +1344,8 @@ impl EarlyLintPass for IgnoredGenericBounds {
13431344
if !type_alias_generics.where_clause.predicates.is_empty() {
13441345
let spans : Vec<_> = type_alias_generics.where_clause.predicates.iter()
13451346
.map(|pred| pred.span()).collect();
1346-
cx.span_lint(IGNORED_GENERIC_BOUNDS, spans,
1347-
"where clauses are ignored in type aliases");
1347+
cx.span_lint(TYPE_ALIAS_BOUNDS, spans,
1348+
"where clauses are not enforced in type aliases");
13481349
}
13491350
// The parameters must not have bounds
13501351
for param in type_alias_generics.params.iter() {
@@ -1354,9 +1355,9 @@ impl EarlyLintPass for IgnoredGenericBounds {
13541355
};
13551356
if !spans.is_empty() {
13561357
cx.span_lint(
1357-
IGNORED_GENERIC_BOUNDS,
1358+
TYPE_ALIAS_BOUNDS,
13581359
spans,
1359-
"bounds on generic parameters are ignored in type aliases",
1360+
"bounds on generic parameters are not enforced in type aliases",
13601361
);
13611362
}
13621363
}

src/librustc_lint/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
109109
UnusedImportBraces,
110110
AnonymousParameters,
111111
UnusedDocComment,
112-
IgnoredGenericBounds,
112+
TypeAliasBounds,
113113
);
114114

115115
add_early_builtin_with_new!(sess,

src/test/compile-fail/issue-17994.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010

1111
trait Tr {}
1212
type Huh<T> where T: Tr = isize; //~ ERROR type parameter `T` is unused
13-
//~| WARNING where clauses are ignored in type aliases
13+
//~| WARNING where clauses are not enforced in type aliases
1414
fn main() {}

src/test/compile-fail/private-in-public-warn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ mod traits {
5858
pub trait PubTr {}
5959

6060
pub type Alias<T: PrivTr> = T; //~ ERROR private trait `traits::PrivTr` in public interface
61-
//~^ WARNING bounds on generic parameters are ignored
61+
//~^ WARNING bounds on generic parameters are not enforced in type aliases
6262
//~| WARNING hard error
6363
pub trait Tr1: PrivTr {} //~ ERROR private trait `traits::PrivTr` in public interface
6464
//~^ WARNING hard error
@@ -85,7 +85,7 @@ mod traits_where {
8585
pub type Alias<T> where T: PrivTr = T;
8686
//~^ ERROR private trait `traits_where::PrivTr` in public interface
8787
//~| WARNING hard error
88-
//~| WARNING where clauses are ignored in type aliases
88+
//~| WARNING where clauses are not enforced in type aliases
8989
pub trait Tr2<T> where T: PrivTr {}
9090
//~^ ERROR private trait `traits_where::PrivTr` in public interface
9191
//~| WARNING hard error

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@
1010

1111
// Test ignored_generic_bounds lint warning about bounds in type aliases
1212

13-
// must-compile-successfully
1413
#![allow(dead_code)]
1514

1615
use std::rc::Rc;
1716

1817
type SVec<T: Send+Send> = Vec<T>;
19-
//~^ WARN bounds on generic parameters are ignored in type aliases
18+
//~^ WARN bounds on generic parameters are not enforced in type aliases [type_alias_bounds]
2019
type S2Vec<T> where T: Send = Vec<T>;
21-
//~^ WARN where clauses are ignored in type aliases
20+
//~^ WARN where clauses are not enforced in type aliases [type_alias_bounds]
2221
type VVec<'b, 'a: 'b+'b> = (&'b u32, Vec<&'a i32>);
23-
//~^ WARN bounds on generic parameters are ignored in type aliases
22+
//~^ WARN bounds on generic parameters are not enforced in type aliases [type_alias_bounds]
2423
type WVec<'b, T: 'b+'b> = (&'b u32, Vec<T>);
25-
//~^ WARN bounds on generic parameters are ignored in type aliases
24+
//~^ WARN bounds on generic parameters are not enforced in type aliases [type_alias_bounds]
2625
type W2Vec<'b, T> where T: 'b, T: 'b = (&'b u32, Vec<T>);
27-
//~^ WARN where clauses are ignored in type aliases
26+
//~^ WARN where clauses are not enforced in type aliases [type_alias_bounds]
2827

2928
static STATIC : u32 = 0;
3029

@@ -48,4 +47,18 @@ fn foo<'a>(y: &'a i32) {
4847
x.1.push(y); // &'a i32: 'static does not hold
4948
}
5049

50+
// Bounds are not checked either, i.e. the definition is not necessarily well-formed
51+
struct Sendable<T: Send>(T);
52+
type MySendable<T> = Sendable<T>; // no error here!
53+
54+
// However, bounds *are* taken into account when accessing associated types
55+
trait Bound { type Assoc; }
56+
type T1<U: Bound> = U::Assoc;
57+
//~^ WARN bounds on generic parameters are not enforced in type aliases
58+
type T2<U> where U: Bound = U::Assoc;
59+
//~^ WARN where clauses are not enforced in type aliases
60+
type T3<U> = U::Assoc;
61+
//~^ ERROR associated type `Assoc` not found for `U`
62+
type T4<U> = <U as Bound>::Assoc;
63+
5164
fn main() {}

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

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,53 @@
1-
warning: bounds on generic parameters are ignored in type aliases
2-
--> $DIR/type-alias-bounds.rs:18:14
1+
warning: bounds on generic parameters are not enforced in type aliases
2+
--> $DIR/type-alias-bounds.rs:17:14
33
|
44
LL | type SVec<T: Send+Send> = Vec<T>;
55
| ^^^^ ^^^^
66
|
7-
= note: #[warn(ignored_generic_bounds)] on by default
7+
= note: #[warn(type_alias_bounds)] on by default
88

9-
warning: where clauses are ignored in type aliases
10-
--> $DIR/type-alias-bounds.rs:20:21
9+
warning: where clauses are not enforced in type aliases
10+
--> $DIR/type-alias-bounds.rs:19:21
1111
|
1212
LL | type S2Vec<T> where T: Send = Vec<T>;
1313
| ^^^^^^^
1414

15-
warning: bounds on generic parameters are ignored in type aliases
16-
--> $DIR/type-alias-bounds.rs:22:19
15+
warning: bounds on generic parameters are not enforced in type aliases
16+
--> $DIR/type-alias-bounds.rs:21:19
1717
|
1818
LL | type VVec<'b, 'a: 'b+'b> = (&'b u32, Vec<&'a i32>);
1919
| ^^ ^^
2020

21-
warning: bounds on generic parameters are ignored in type aliases
22-
--> $DIR/type-alias-bounds.rs:24:18
21+
warning: bounds on generic parameters are not enforced in type aliases
22+
--> $DIR/type-alias-bounds.rs:23:18
2323
|
2424
LL | type WVec<'b, T: 'b+'b> = (&'b u32, Vec<T>);
2525
| ^^ ^^
2626

27-
warning: where clauses are ignored in type aliases
28-
--> $DIR/type-alias-bounds.rs:26:25
27+
warning: where clauses are not enforced in type aliases
28+
--> $DIR/type-alias-bounds.rs:25:25
2929
|
3030
LL | type W2Vec<'b, T> where T: 'b, T: 'b = (&'b u32, Vec<T>);
3131
| ^^^^^ ^^^^^
3232

33+
warning: bounds on generic parameters are not enforced in type aliases
34+
--> $DIR/type-alias-bounds.rs:56:12
35+
|
36+
LL | type T1<U: Bound> = U::Assoc;
37+
| ^^^^^
38+
39+
warning: where clauses are not enforced in type aliases
40+
--> $DIR/type-alias-bounds.rs:58:18
41+
|
42+
LL | type T2<U> where U: Bound = U::Assoc;
43+
| ^^^^^^^^
44+
45+
error[E0220]: associated type `Assoc` not found for `U`
46+
--> $DIR/type-alias-bounds.rs:60:14
47+
|
48+
LL | type T3<U> = U::Assoc;
49+
| ^^^^^^^^ associated type `Assoc` not found
50+
51+
error: aborting due to previous error
52+
53+
If you want more information on this error, try using "rustc --explain E0220"

0 commit comments

Comments
 (0)