]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
rust: fix ICE during name resolution for impls on unit-types
authorPhilip Herron <herron.philip@googlemail.com>
Fri, 20 Sep 2024 16:38:14 +0000 (17:38 +0100)
committerPhilip Herron <philip.herron@embecosm.com>
Fri, 27 Sep 2024 11:55:56 +0000 (11:55 +0000)
The canonical paths need to support unit-types which are technically a
TupleType with no fields. This handles this case and adds an unreachable.

Fixes #3036

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-type.cc (ResolveTypeToCanonicalPath::visit): add unit-type catch
* resolve/rust-ast-resolve-type.h: likewise

gcc/testsuite/ChangeLog:

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

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

index e93515811ae4f252075b86743524149c3047f948..15ae8db9389e740bf23aa39410fa4c4d6b802035 100644 (file)
@@ -507,6 +507,15 @@ ResolveTypeToCanonicalPath::visit (AST::NeverType &type)
   result = CanonicalPath::new_seg (type.get_node_id (), "!");
 }
 
+void
+ResolveTypeToCanonicalPath::visit (AST::TupleType &type)
+{
+  if (!type.is_unit_type ())
+    rust_unreachable ();
+
+  result = CanonicalPath::new_seg (type.get_node_id (), "()");
+}
+
 ResolveTypeToCanonicalPath::ResolveTypeToCanonicalPath ()
   : ResolverBase (), result (CanonicalPath::create_empty ())
 {}
index 1df0f2605cd18f076130e7473c844477021505cf..50dd890c4e31a0a50b9f6ac941d2c6be319a527e 100644 (file)
@@ -248,6 +248,8 @@ public:
 
   void visit (AST::NeverType &type) override;
 
+  void visit (AST::TupleType &type) override;
+
 private:
   ResolveTypeToCanonicalPath ();
 
diff --git a/gcc/testsuite/rust/compile/issue-3036.rs b/gcc/testsuite/rust/compile/issue-3036.rs
new file mode 100644 (file)
index 0000000..4418ccc
--- /dev/null
@@ -0,0 +1,14 @@
+#[lang = "sized"]
+trait Sized {}
+
+#[stable(feature = "rust1", since = "1.0.0")]
+pub trait Default: Sized {
+    #[stable(feature = "rust1", since = "1.0.0")]
+    fn default() -> Self;
+}
+
+impl Default for () {
+    fn default() -> () {
+        ()
+    }
+}
index bfb51fd7fee991456d5463acd6495b687bf8d52e..50781e56b85e4d6d697c9c7dcc3532734a4266aa 100644 (file)
@@ -252,3 +252,4 @@ issue-3082.rs
 issue-3139-1.rs
 issue-3139-2.rs
 issue-3139-3.rs
+issue-3036.rs