Skip to content

Commit

Permalink
[HACK] don't require T: Trait for type Foo<T> = <T as Trait>::Assoc;
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Sep 9, 2018
1 parent 5ba5caa commit ab3e0d2
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 46 deletions.
6 changes: 4 additions & 2 deletions src/librustc_typeck/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def
let generics = tcx.generics_of(def_id);
let used_params = super::check_params_are_used(tcx, &generics, item_ty);
for_item(tcx, item).with_fcx(|fcx, _this| {
let item_ty = fcx.normalize_associated_types_in(item.span, &item_ty);
// HACK(eddyb) Commented out to not require trait bounds for projections.
// let item_ty = fcx.normalize_associated_types_in(item.span, &item_ty);

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

vec![item_ty]
// HACK(eddyb) Commented out to not require trait bounds for projections.
vec![/*item_ty*/]
});
}
hir::ItemKind::Struct(ref struct_def, ref ast_generics) => {
Expand Down
20 changes: 10 additions & 10 deletions src/test/ui/consts/const-eval/pub_const_err.stderr
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
warning: attempt to subtract with overflow
--> $DIR/pub_const_err.rs:19:22
warning: this constant cannot be used
--> $DIR/pub_const_err.rs:16:1
|
LL | pub type Foo = [i32; 0 - 1];
| ^^^^^
LL | pub const Z: u32 = 0 - 1;
| ^^^^^^^^^^^^^^^^^^^-----^
| |
| attempt to subtract with overflow
|
note: lint level defined here
--> $DIR/pub_const_err.rs:12:9
|
LL | #![warn(const_err)]
| ^^^^^^^^^

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

warning: this array length cannot be used
--> $DIR/pub_const_err.rs:19:22
Expand Down
20 changes: 10 additions & 10 deletions src/test/ui/consts/const-eval/pub_const_err_bin.stderr
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
warning: attempt to subtract with overflow
--> $DIR/pub_const_err_bin.rs:17:22
warning: this constant cannot be used
--> $DIR/pub_const_err_bin.rs:14:1
|
LL | pub type Foo = [i32; 0 - 1];
| ^^^^^
LL | pub const Z: u32 = 0 - 1;
| ^^^^^^^^^^^^^^^^^^^-----^
| |
| attempt to subtract with overflow
|
note: lint level defined here
--> $DIR/pub_const_err_bin.rs:12:9
|
LL | #![warn(const_err)]
| ^^^^^^^^^

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

warning: this array length cannot be used
--> $DIR/pub_const_err_bin.rs:17:22
Expand Down
3 changes: 0 additions & 3 deletions src/test/ui/type/type-alias-bounds-err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ type S2Vec<T> where T: Send = Vec<T>;
//~^ ERROR `T` cannot be sent between threads safely

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

type T6<U: Bound> = ::std::vec::Vec<U>;
//~^ ERROR the trait bound `U: Bound` is not satisfied
Expand Down
22 changes: 2 additions & 20 deletions src/test/ui/type/type-alias-bounds-err.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,13 @@ LL | type S2Vec<T> where T: Send = Vec<T>;
= help: consider adding a `where T: std::marker::Send` bound

error[E0277]: the trait bound `U: Bound` is not satisfied
--> $DIR/type-alias-bounds-err.rs:22:1
|
LL | type T4<U> = <U as Bound>::Assoc;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bound` is not implemented for `U`
|
= help: consider adding a `where U: Bound` bound

error[E0277]: the size for values of type `U` cannot be known at compilation time
--> $DIR/type-alias-bounds-err.rs:22:1
|
LL | type T4<U> = <U as Bound>::Assoc;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `U`
= 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>
= help: consider adding a `where U: std::marker::Sized` bound

error[E0277]: the trait bound `U: Bound` is not satisfied
--> $DIR/type-alias-bounds-err.rs:26:1
--> $DIR/type-alias-bounds-err.rs:23:1
|
LL | type T6<U: Bound> = ::std::vec::Vec<U>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bound` is not implemented for `U`
|
= help: consider adding a `where U: Bound` bound

error: aborting due to 5 previous errors
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0277`.
2 changes: 1 addition & 1 deletion src/test/ui/type/type-alias-bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type T2<U> where U: Bound + ?Sized = U::Assoc; //~ WARN not enforced in type al
// This errors
// type T3<U> = U::Assoc;
// Do this instead
// type T4<U: ?Sized> = <U as Bound>::Assoc; // NOTE(eddyb) moved to `type-alias-bounds-err.rs`
type T4<U> = <U as Bound>::Assoc;

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

0 comments on commit ab3e0d2

Please sign in to comment.