1
Fork 0

Rollup merge of #87256 - Aaron1011:hir-wf-assoc-default, r=oli-obk

Extend HIR-based WF checking to associated type defaults

Previously, we would only look at associated types in `impl` blocks.
This commit is contained in:
Guillaume Gomez 2021-07-19 11:37:47 +02:00 committed by GitHub
commit 4dd32a1cac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 7 deletions

View file

@ -121,7 +121,11 @@ fn diagnostic_hir_wf_check<'tcx>(
let ty = match tcx.hir().get(hir_id) { let ty = match tcx.hir().get(hir_id) {
hir::Node::ImplItem(item) => match item.kind { hir::Node::ImplItem(item) => match item.kind {
hir::ImplItemKind::TyAlias(ref ty) => Some(ty), hir::ImplItemKind::TyAlias(ty) => Some(ty),
_ => None,
},
hir::Node::TraitItem(item) => match item.kind {
hir::TraitItemKind::Type(_, ty) => ty,
_ => None, _ => None,
}, },
_ => None, _ => None,

View file

@ -1,8 +1,8 @@
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> $DIR/defaults-wf.rs:7:5 --> $DIR/defaults-wf.rs:7:15
| |
LL | type Ty = Vec<[u8]>; LL | type Ty = Vec<[u8]>;
| ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | ^^^^^^^^^ doesn't have a size known at compile-time
| |
::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL ::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
| |

View file

@ -8,7 +8,7 @@ struct IsCopy<T:Copy> { x: T }
trait SomeTrait { trait SomeTrait {
type Type1; type Type1;
type Type2 = IsCopy<Self::Type1>; type Type2 = (IsCopy<Self::Type1>, bool);
//~^ ERROR E0277 //~^ ERROR E0277
} }

View file

@ -1,11 +1,11 @@
error[E0277]: the trait bound `<Self as SomeTrait>::Type1: Copy` is not satisfied error[E0277]: the trait bound `<Self as SomeTrait>::Type1: Copy` is not satisfied
--> $DIR/wf-trait-associated-type-trait.rs:11:5 --> $DIR/wf-trait-associated-type-trait.rs:11:19
| |
LL | struct IsCopy<T:Copy> { x: T } LL | struct IsCopy<T:Copy> { x: T }
| ---- required by this bound in `IsCopy` | ---- required by this bound in `IsCopy`
... ...
LL | type Type2 = IsCopy<Self::Type1>; LL | type Type2 = (IsCopy<Self::Type1>, bool);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `<Self as SomeTrait>::Type1` | ^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `<Self as SomeTrait>::Type1`
| |
help: consider further restricting the associated type help: consider further restricting the associated type
| |