Skip to content

Commit 4dd32a1

Browse files
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.
2 parents 8cf995f + 93aa890 commit 4dd32a1

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

compiler/rustc_typeck/src/hir_wf_check.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ fn diagnostic_hir_wf_check<'tcx>(
121121

122122
let ty = match tcx.hir().get(hir_id) {
123123
hir::Node::ImplItem(item) => match item.kind {
124-
hir::ImplItemKind::TyAlias(ref ty) => Some(ty),
124+
hir::ImplItemKind::TyAlias(ty) => Some(ty),
125+
_ => None,
126+
},
127+
hir::Node::TraitItem(item) => match item.kind {
128+
hir::TraitItemKind::Type(_, ty) => ty,
125129
_ => None,
126130
},
127131
_ => None,

src/test/ui/associated-types/defaults-wf.stderr

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

src/test/ui/wf/wf-trait-associated-type-trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct IsCopy<T:Copy> { x: T }
88

99
trait SomeTrait {
1010
type Type1;
11-
type Type2 = IsCopy<Self::Type1>;
11+
type Type2 = (IsCopy<Self::Type1>, bool);
1212
//~^ ERROR E0277
1313
}
1414

src/test/ui/wf/wf-trait-associated-type-trait.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0277]: the trait bound `<Self as SomeTrait>::Type1: Copy` is not satisfied
2-
--> $DIR/wf-trait-associated-type-trait.rs:11:5
2+
--> $DIR/wf-trait-associated-type-trait.rs:11:19
33
|
44
LL | struct IsCopy<T:Copy> { x: T }
55
| ---- required by this bound in `IsCopy`
66
...
7-
LL | type Type2 = IsCopy<Self::Type1>;
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `<Self as SomeTrait>::Type1`
7+
LL | type Type2 = (IsCopy<Self::Type1>, bool);
8+
| ^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `<Self as SomeTrait>::Type1`
99
|
1010
help: consider further restricting the associated type
1111
|

0 commit comments

Comments
 (0)