Skip to content

Commit ab3e0d2

Browse files
committed
[HACK] don't require T: Trait for type Foo<T> = <T as Trait>::Assoc;
1 parent 5ba5caa commit ab3e0d2

File tree

6 files changed

+27
-46
lines changed

6 files changed

+27
-46
lines changed

src/librustc_typeck/check/wfcheck.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def
135135
let generics = tcx.generics_of(def_id);
136136
let used_params = super::check_params_are_used(tcx, &generics, item_ty);
137137
for_item(tcx, item).with_fcx(|fcx, _this| {
138-
let item_ty = fcx.normalize_associated_types_in(item.span, &item_ty);
138+
// HACK(eddyb) Commented out to not require trait bounds for projections.
139+
// let item_ty = fcx.normalize_associated_types_in(item.span, &item_ty);
139140

140141
// Check the user-declared bounds, assuming the type is WF.
141142
// This ensures that by checking the WF of the aliased type, where
@@ -172,7 +173,8 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def
172173
}));
173174
}
174175

175-
vec![item_ty]
176+
// HACK(eddyb) Commented out to not require trait bounds for projections.
177+
vec![/*item_ty*/]
176178
});
177179
}
178180
hir::ItemKind::Struct(ref struct_def, ref ast_generics) => {

src/test/ui/consts/const-eval/pub_const_err.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
warning: attempt to subtract with overflow
2-
--> $DIR/pub_const_err.rs:19:22
1+
warning: this constant cannot be used
2+
--> $DIR/pub_const_err.rs:16:1
33
|
4-
LL | pub type Foo = [i32; 0 - 1];
5-
| ^^^^^
4+
LL | pub const Z: u32 = 0 - 1;
5+
| ^^^^^^^^^^^^^^^^^^^-----^
6+
| |
7+
| attempt to subtract with overflow
68
|
79
note: lint level defined here
810
--> $DIR/pub_const_err.rs:12:9
911
|
1012
LL | #![warn(const_err)]
1113
| ^^^^^^^^^
1214

13-
warning: this constant cannot be used
14-
--> $DIR/pub_const_err.rs:16:1
15+
warning: attempt to subtract with overflow
16+
--> $DIR/pub_const_err.rs:19:22
1517
|
16-
LL | pub const Z: u32 = 0 - 1;
17-
| ^^^^^^^^^^^^^^^^^^^-----^
18-
| |
19-
| attempt to subtract with overflow
18+
LL | pub type Foo = [i32; 0 - 1];
19+
| ^^^^^
2020

2121
warning: this array length cannot be used
2222
--> $DIR/pub_const_err.rs:19:22

src/test/ui/consts/const-eval/pub_const_err_bin.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
warning: attempt to subtract with overflow
2-
--> $DIR/pub_const_err_bin.rs:17:22
1+
warning: this constant cannot be used
2+
--> $DIR/pub_const_err_bin.rs:14:1
33
|
4-
LL | pub type Foo = [i32; 0 - 1];
5-
| ^^^^^
4+
LL | pub const Z: u32 = 0 - 1;
5+
| ^^^^^^^^^^^^^^^^^^^-----^
6+
| |
7+
| attempt to subtract with overflow
68
|
79
note: lint level defined here
810
--> $DIR/pub_const_err_bin.rs:12:9
911
|
1012
LL | #![warn(const_err)]
1113
| ^^^^^^^^^
1214

13-
warning: this constant cannot be used
14-
--> $DIR/pub_const_err_bin.rs:14:1
15+
warning: attempt to subtract with overflow
16+
--> $DIR/pub_const_err_bin.rs:17:22
1517
|
16-
LL | pub const Z: u32 = 0 - 1;
17-
| ^^^^^^^^^^^^^^^^^^^-----^
18-
| |
19-
| attempt to subtract with overflow
18+
LL | pub type Foo = [i32; 0 - 1];
19+
| ^^^^^
2020

2121
warning: this array length cannot be used
2222
--> $DIR/pub_const_err_bin.rs:17:22

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

-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ type S2Vec<T> where T: Send = Vec<T>;
1919
//~^ ERROR `T` cannot be sent between threads safely
2020

2121
trait Bound { type Assoc; }
22-
type T4<U> = <U as Bound>::Assoc;
23-
//~^ ERROR the trait bound `U: Bound` is not satisfied
24-
//~| ERROR the size for values of type `U` cannot be known at compilation time
2522

2623
type T6<U: Bound> = ::std::vec::Vec<U>;
2724
//~^ ERROR the trait bound `U: Bound` is not satisfied

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

+2-20
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,13 @@ LL | type S2Vec<T> where T: Send = Vec<T>;
1717
= help: consider adding a `where T: std::marker::Send` bound
1818

1919
error[E0277]: the trait bound `U: Bound` is not satisfied
20-
--> $DIR/type-alias-bounds-err.rs:22:1
21-
|
22-
LL | type T4<U> = <U as Bound>::Assoc;
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bound` is not implemented for `U`
24-
|
25-
= help: consider adding a `where U: Bound` bound
26-
27-
error[E0277]: the size for values of type `U` cannot be known at compilation time
28-
--> $DIR/type-alias-bounds-err.rs:22:1
29-
|
30-
LL | type T4<U> = <U as Bound>::Assoc;
31-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
32-
|
33-
= help: the trait `std::marker::Sized` is not implemented for `U`
34-
= note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
35-
= help: consider adding a `where U: std::marker::Sized` bound
36-
37-
error[E0277]: the trait bound `U: Bound` is not satisfied
38-
--> $DIR/type-alias-bounds-err.rs:26:1
20+
--> $DIR/type-alias-bounds-err.rs:23:1
3921
|
4022
LL | type T6<U: Bound> = ::std::vec::Vec<U>;
4123
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bound` is not implemented for `U`
4224
|
4325
= help: consider adding a `where U: Bound` bound
4426

45-
error: aborting due to 5 previous errors
27+
error: aborting due to 3 previous errors
4628

4729
For more information about this error, try `rustc --explain E0277`.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type T2<U> where U: Bound + ?Sized = U::Assoc; //~ WARN not enforced in type al
5959
// This errors
6060
// type T3<U> = U::Assoc;
6161
// Do this instead
62-
// type T4<U: ?Sized> = <U as Bound>::Assoc; // NOTE(eddyb) moved to `type-alias-bounds-err.rs`
62+
type T4<U> = <U as Bound>::Assoc;
6363

6464
// Make sure the help about associatd types is not shown incorrectly
6565
type T5<U: Bound + ?Sized> = <U as Bound>::Assoc; //~ WARN not enforced in type aliases

0 commit comments

Comments
 (0)