forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#48909 - RalfJung:type_alias_bounds, r=petro…
…chenkov Improve lint for type alias bounds First of all, I learned just today that I was wrong assuming that the bounds in type aliases are entirely ignored: It turns out they are used to resolve associated types in type aliases. So: ```rust type T1<U: Bound> = U::Assoc; // compiles type T2<U> = U::Assoc; // fails type T3<U> = <U as Bound>::Assoc; // "correct" way to write this, maybe? ``` I am sorry for creating this mess. This PR changes the wording of the lint accordingly. Moreover, since just removing the bound is no longer always a possible fix, I tried to detect cases like `T1` above and show a helpful message to the user: ``` warning: bounds on generic parameters are not enforced in type aliases --> $DIR/type-alias-bounds.rs:57:12 | LL | type T1<U: Bound> = U::Assoc; //~ WARN not enforced in type aliases | ^^^^^ | = help: the bound will not be checked when the type alias is used, and should be removed help: use absolute paths (i.e., <T as Trait>::Assoc) to refer to associated types in type aliases --> $DIR/type-alias-bounds.rs:57:21 | LL | type T1<U: Bound> = U::Assoc; //~ WARN not enforced in type aliases | ^^^^^^^^ ``` I am not sure if I got this entirely right. Ideally, we could provide a suggestion involving the correct trait and type name -- however, while I have access to the HIR in the lint, I do not know how to get access to the resolved name information, like which trait `Assoc` belongs to above. The lint does not even run if that resolution fails, so I assume that information is available *somewhere*... This is a follow-up for (parts of) rust-lang#48326. Also see rust-lang#21903. This changes the name of a lint, but that lint was just merged to master yesterday and has never even been on beta.
- Loading branch information
Showing
9 changed files
with
270 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 11 additions & 37 deletions
48
src/test/ui/param-bounds-ignored.stderr → src/test/ui/higher-lifetime-bounds.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,68 @@ | ||
error: lifetime bounds cannot be used in this context | ||
--> $DIR/param-bounds-ignored.rs:42:22 | ||
--> $DIR/higher-lifetime-bounds.rs:18:22 | ||
| | ||
LL | f: for<'xa, 'xb: 'xa+'xa> fn(&'xa i32, &'xb i32) -> &'xa i32) | ||
| ^^^ ^^^ | ||
|
||
error: lifetime bounds cannot be used in this context | ||
--> $DIR/param-bounds-ignored.rs:50:34 | ||
--> $DIR/higher-lifetime-bounds.rs:26:34 | ||
| | ||
LL | fn bar2<'a, 'b, F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>( | ||
| ^^^ | ||
|
||
error: lifetime bounds cannot be used in this context | ||
--> $DIR/param-bounds-ignored.rs:65:28 | ||
--> $DIR/higher-lifetime-bounds.rs:41:28 | ||
| | ||
LL | where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32 | ||
| ^^^ | ||
|
||
error: lifetime bounds cannot be used in this context | ||
--> $DIR/param-bounds-ignored.rs:77:25 | ||
--> $DIR/higher-lifetime-bounds.rs:53:25 | ||
| | ||
LL | where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32 | ||
| ^^^ | ||
|
||
error: lifetime bounds cannot be used in this context | ||
--> $DIR/param-bounds-ignored.rs:85:28 | ||
--> $DIR/higher-lifetime-bounds.rs:61:28 | ||
| | ||
LL | struct S1<F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(F); | ||
| ^^^ | ||
|
||
error: lifetime bounds cannot be used in this context | ||
--> $DIR/param-bounds-ignored.rs:87:40 | ||
--> $DIR/higher-lifetime-bounds.rs:63:40 | ||
| | ||
LL | struct S2<F>(F) where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32; | ||
| ^^^ | ||
|
||
error: lifetime bounds cannot be used in this context | ||
--> $DIR/param-bounds-ignored.rs:89:37 | ||
--> $DIR/higher-lifetime-bounds.rs:65:37 | ||
| | ||
LL | struct S3<F>(F) where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32; | ||
| ^^^ | ||
|
||
error: lifetime bounds cannot be used in this context | ||
--> $DIR/param-bounds-ignored.rs:92:29 | ||
--> $DIR/higher-lifetime-bounds.rs:68:29 | ||
| | ||
LL | struct S_fnty(for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32); | ||
| ^^^ | ||
|
||
error: lifetime bounds cannot be used in this context | ||
--> $DIR/param-bounds-ignored.rs:95:29 | ||
--> $DIR/higher-lifetime-bounds.rs:71:29 | ||
| | ||
LL | type T1 = Box<for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>; | ||
| ^^^ | ||
|
||
error: lifetime bounds cannot be used in this context | ||
--> $DIR/param-bounds-ignored.rs:99:34 | ||
--> $DIR/higher-lifetime-bounds.rs:75:34 | ||
| | ||
LL | let _ : Option<for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32> = None; | ||
| ^^^ | ||
|
||
error: lifetime bounds cannot be used in this context | ||
--> $DIR/param-bounds-ignored.rs:101:38 | ||
--> $DIR/higher-lifetime-bounds.rs:77:38 | ||
| | ||
LL | let _ : Option<Box<for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>> = None; | ||
| ^^^ | ||
|
||
warning: bounds on generic parameters are ignored in type aliases | ||
--> $DIR/param-bounds-ignored.rs:15:14 | ||
| | ||
LL | type SVec<T: Send+Send> = Vec<T>; | ||
| ^^^^ ^^^^ | ||
| | ||
= note: #[warn(ignored_generic_bounds)] on by default | ||
|
||
warning: bounds on generic parameters are ignored in type aliases | ||
--> $DIR/param-bounds-ignored.rs:17:19 | ||
| | ||
LL | type VVec<'b, 'a: 'b+'b> = Vec<&'a i32>; | ||
| ^^ ^^ | ||
|
||
warning: bounds on generic parameters are ignored in type aliases | ||
--> $DIR/param-bounds-ignored.rs:19:18 | ||
| | ||
LL | type WVec<'b, T: 'b+'b> = Vec<T>; | ||
| ^^ ^^ | ||
|
||
warning: where clauses are ignored in type aliases | ||
--> $DIR/param-bounds-ignored.rs:21:25 | ||
| | ||
LL | type W2Vec<'b, T> where T: 'b, T: 'b = Vec<T>; | ||
| ^^^^^ ^^^^^ | ||
|
||
error: aborting due to 11 previous errors | ||
|
Oops, something went wrong.