aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2024-09-20 17:13:38 +0100
committerPhilip Herron <philip.herron@embecosm.com>2024-09-26 20:22:13 +0000
commit438470e8e327cd4d9c90ad701d1679062ee215ee (patch)
tree132985e2c2e8ecb3fbfaedee0d9b1f024b5b1f8c /gcc
parent09cfe530f9c8c29ee2675ad91f6672a62dcf9519 (diff)
downloadgcc-438470e8e327cd4d9c90ad701d1679062ee215ee.zip
gcc-438470e8e327cd4d9c90ad701d1679062ee215ee.tar.gz
gcc-438470e8e327cd4d9c90ad701d1679062ee215ee.tar.bz2
rust fix ICE when hir lowering qualified path expressions without an as
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>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/hir/rust-ast-lower-type.cc11
-rw-r--r--gcc/testsuite/rust/compile/issue-3082.rs9
-rw-r--r--gcc/testsuite/rust/compile/nr2/exclude1
3 files changed, 19 insertions, 2 deletions
diff --git a/gcc/rust/hir/rust-ast-lower-type.cc b/gcc/rust/hir/rust-ast-lower-type.cc
index ad93526..cc7cb93 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<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
index 0000000..4b87395
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3082.rs
@@ -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 }
+ }
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 5f5863b..3412617 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -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