Skip to content

Extend HIR-based WF checking to associated type defaults #87256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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