]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: rust fix ICE when hir lowering qualified path expressions without an as
authorPhilip Herron <herron.philip@googlemail.com>
Fri, 20 Sep 2024 16:13:38 +0000 (17:13 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Wed, 19 Mar 2025 14:32:11 +0000 (15:32 +0100)
Qualified path expressions usually are <X as Y>::... but the as is optional
this adds the extra checking in hir lowering to not hit that nullptr.

Fixes #3082

gcc/rust/ChangeLog:

* hir/rust-ast-lower-type.cc (ASTLowerQualifiedPathInType::visit):
check for valid as segment

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3082.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/hir/rust-ast-lower-type.cc
gcc/testsuite/rust/compile/issue-3082.rs [new file with mode: 0644]
gcc/testsuite/rust/compile/nr2/exclude

index 883af4adb47f4e9b85ed7243dd8c88272bb94ccb..7d6ac5ddffa3f843e59306a0f1e1aa341cfe8fd8 100644 (file)
@@ -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<HIR::Type> (qual_type),
diff --git a/gcc/testsuite/rust/compile/issue-3082.rs b/gcc/testsuite/rust/compile/issue-3082.rs
new file mode 100644 (file)
index 0000000..4b87395
--- /dev/null
@@ -0,0 +1,9 @@
+#![allow(unused)]
+fn main() {
+    trait Hello {
+        type Who;
+
+        fn hello() -> <i32>::You;
+        // { dg-error "failed to resolve return type" "" { target *-*-* } .-1 }
+    }
+}
index 5f5863bde87a8959b508a34baa1b5ed67def3fbe..3412617f7eb23d212fb5ee4920ed5508cb88a958 100644 (file)
@@ -277,3 +277,4 @@ dropck_eyepatch_feature_gate.rs
 inline_asm_parse_output_operand.rs
 issue-3030.rs
 issue-3035.rs
+issue-3082.rs
\ No newline at end of file