diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc index e56fa397e2a..54f50ec41f1 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-type.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc @@ -360,6 +360,13 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset, seg->as_string ().c_str ()); return new TyTy::ErrorType (path.get_mappings ().get_hirid ()); } + else if (root_tyty == nullptr) + { + rust_error_at (seg->get_locus (), + "unknown reference for resolved name: %qs", + seg->as_string ().c_str ()); + return new TyTy::ErrorType (path.get_mappings ().get_hirid ()); + } return root_tyty; } diff --git a/gcc/testsuite/rust/compile/issue-3613.rs b/gcc/testsuite/rust/compile/issue-3613.rs new file mode 100644 index 00000000000..f2e10921f67 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3613.rs @@ -0,0 +1,18 @@ +mod m1 { + pub enum Baz4 { + foo1, + foo2, + } +} + +fn bar(x: m1::foo) { + // { dg-error "unknown reference for resolved name: .foo." "" { target *-*-* } .-1 } + match x { + m1::foo::foo1 => {} + // { dg-error "failed to type resolve root segment" "" { target *-*-* } .-1 } + m1::NodePosition::foo2 => {} + // { dg-error "failed to type resolve root segment" "" { target *-*-* } .-1 } + } +} + +pub fn main() {}