diff --git a/gcc/rust/hir/rust-ast-lower-type.cc b/gcc/rust/hir/rust-ast-lower-type.cc index ad93526644e7..cc7cb937f7cc 100644 --- a/gcc/rust/hir/rust-ast-lower-type.cc +++ b/gcc/rust/hir/rust-ast-lower-type.cc @@ -145,8 +145,15 @@ ASTLowerQualifiedPathInType::visit (AST::QualifiedPathInType &path) HIR::Type *qual_type = ASTLoweringType::translate (path.get_qualified_path_type ().get_type ()); - HIR::TypePath *qual_trait = ASTLowerTypePath::translate ( - path.get_qualified_path_type ().get_as_type_path ()); + + HIR::TypePath *qual_trait = nullptr; + if (!path.get_qualified_path_type ().is_error ()) + { + AST::QualifiedPathType &qualifier = path.get_qualified_path_type (); + if (qualifier.has_as_clause ()) + qual_trait + = ASTLowerTypePath::translate (qualifier.get_as_type_path ()); + } HIR::QualifiedPathType qual_path_type ( qual_mappings, std::unique_ptr (qual_type), diff --git a/gcc/testsuite/rust/compile/issue-3082.rs b/gcc/testsuite/rust/compile/issue-3082.rs new file mode 100644 index 000000000000..4b873955dde1 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3082.rs @@ -0,0 +1,9 @@ +#![allow(unused)] +fn main() { + trait Hello { + type Who; + + fn hello() -> ::You; + // { dg-error "failed to resolve return type" "" { target *-*-* } .-1 } + } +} diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude index ca07ed6ecd2b..8bd0dc7de5cd 100644 --- a/gcc/testsuite/rust/compile/nr2/exclude +++ b/gcc/testsuite/rust/compile/nr2/exclude @@ -291,3 +291,4 @@ unknown-associated-item.rs box_syntax_feature_gate.rs dropck_eyepatch_feature_gate.rs inline_asm_parse_output_operand.rs +issue-3082.rs \ No newline at end of file