Skip to content

Commit

Permalink
Rollup merge of #87256 - Aaron1011:hir-wf-assoc-default, r=oli-obk
Browse files Browse the repository at this point in the history
Extend HIR-based WF checking to associated type defaults

Previously, we would only look at associated types in `impl` blocks.
  • Loading branch information
GuillaumeGomez authored Jul 19, 2021
2 parents 8cf995f + 93aa890 commit 4dd32a1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
6 changes: 5 additions & 1 deletion compiler/rustc_typeck/src/hir_wf_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ fn diagnostic_hir_wf_check<'tcx>(

let ty = match tcx.hir().get(hir_id) {
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,
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/associated-types/defaults-wf.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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]>;
| ^^^^^^^^^^^^^^^^^^^^ 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
|
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/wf/wf-trait-associated-type-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct IsCopy<T:Copy> { x: T }

trait SomeTrait {
type Type1;
type Type2 = IsCopy<Self::Type1>;
type Type2 = (IsCopy<Self::Type1>, bool);
//~^ ERROR E0277
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/wf/wf-trait-associated-type-trait.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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 }
| ---- required by this bound in `IsCopy`
...
LL | type Type2 = IsCopy<Self::Type1>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `<Self as SomeTrait>::Type1`
LL | type Type2 = (IsCopy<Self::Type1>, bool);
| ^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `<Self as SomeTrait>::Type1`
|
help: consider further restricting the associated type
|
Expand Down

0 comments on commit 4dd32a1

Please sign in to comment.