Skip to content

Commit 10a3afa

Browse files
committed
find the generic container rather than simply looking up for the assoc with const arg
1 parent 59ae5eb commit 10a3afa

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

compiler/rustc_hir_analysis/src/collect/type_of.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,31 @@ fn const_arg_anon_type_of<'tcx>(tcx: TyCtxt<'tcx>, arg_hir_id: HirId, span: Span
175175
// arm would handle this.
176176
//
177177
// I believe this match arm is only needed for GAT but I am not 100% sure - BoxyUwU
178-
Node::Ty(hir_ty @ hir::Ty { kind: TyKind::Path(QPath::TypeRelative(_, segment)), .. }) => {
178+
Node::Ty(hir_ty @ hir::Ty { kind: TyKind::Path(QPath::TypeRelative(ty, segment)), .. }) => {
179179
// Find the Item containing the associated type so we can create an ItemCtxt.
180180
// Using the ItemCtxt lower the HIR for the unresolved assoc type into a
181181
// ty which is a fully resolved projection.
182182
// For the code example above, this would mean lowering `Self::Assoc<3>`
183183
// to a ty::Alias(ty::Projection, `<Self as Foo>::Assoc<3>`).
184-
let item_def_id = tcx
185-
.hir()
186-
.parent_owner_iter(arg_hir_id)
187-
.find(|(_, node)| matches!(node, OwnerNode::Item(_)))
188-
.unwrap()
189-
.0
190-
.def_id;
184+
let node = if let TyKind::Path(QPath::Resolved(_, path)) = ty.kind
185+
&& let def::Res::Def(def::DefKind::TyParam, did) = path.res
186+
{
187+
tcx.hir()
188+
.parent_owner_iter(arg_hir_id)
189+
.find(|(_, node)| {
190+
tcx.generics_of(node.def_id())
191+
.own_params
192+
.iter()
193+
.any(|param| param.def_id == did)
194+
})
195+
.unwrap()
196+
} else {
197+
tcx.hir()
198+
.parent_owner_iter(arg_hir_id)
199+
.find(|(_, node)| matches!(node, OwnerNode::Item(_)))
200+
.unwrap()
201+
};
202+
let item_def_id = node.0.def_id;
191203
let ty = ItemCtxt::new(tcx, item_def_id).lower_ty(hir_ty);
192204

193205
// Iterate through the generics of the projection to find the one that corresponds to
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// issue#132534
2+
3+
trait X {
4+
fn a<T>() -> T::unknown<{}> {}
5+
//~^ ERROR: associated type `unknown` not found for `T`
6+
//~| ERROR: associated type `unknown` not found for `T`
7+
}
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0220]: associated type `unknown` not found for `T`
2+
--> $DIR/unknown-assoc-with-const-arg.rs:4:21
3+
|
4+
LL | fn a<T>() -> T::unknown<{}> {}
5+
| ^^^^^^^ associated type `unknown` not found
6+
7+
error[E0220]: associated type `unknown` not found for `T`
8+
--> $DIR/unknown-assoc-with-const-arg.rs:4:21
9+
|
10+
LL | fn a<T>() -> T::unknown<{}> {}
11+
| ^^^^^^^ associated type `unknown` not found
12+
|
13+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
14+
15+
error: aborting due to 2 previous errors
16+
17+
For more information about this error, try `rustc --explain E0220`.

0 commit comments

Comments
 (0)