Skip to content
Closed
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
13 changes: 10 additions & 3 deletions compiler/rustc_hir_analysis/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,16 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
VariantData::Unit(..) | VariantData::Struct(..) => {
tcx.type_of(tcx.hir().get_parent_item(hir_id)).subst_identity()
}
VariantData::Tuple(..) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id);
Ty::new_fn_def(tcx, def_id.to_def_id(), substs)
VariantData::Tuple(fields, ..) => {
if let Some(Err(error)) = fields.iter().find_map(|field| {
let field_ty = tcx.type_of(field.def_id).skip_binder();
field_ty.references_error().then_some(field_ty.error_reported())
}) {
Ty::new_error(tcx, error)
} else {
let substs = InternalSubsts::identity_for_item(tcx, def_id);
Ty::new_fn_def(tcx, def_id.to_def_id(), substs)
}
}
},

Expand Down
7 changes: 7 additions & 0 deletions tests/ui/cast/issue-112630.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum Foo {
Bar(B) //~ ERROR cannot find type `B` in this scope [E0412]
}

fn main() {
let _ = [0; Foo::Bar as usize];
}
14 changes: 14 additions & 0 deletions tests/ui/cast/issue-112630.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0412]: cannot find type `B` in this scope
--> $DIR/issue-112630.rs:2:9
|
LL | Bar(B)
| ^ not found in this scope
|
help: you might be missing a type parameter
|
LL | enum Foo<B> {
| +++

error: aborting due to previous error

For more information about this error, try `rustc --explain E0412`.