Skip to content

Commit

Permalink
rust: fix ICE during name resolution for impls on unit-types
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
philberty committed Sep 20, 2024
1 parent d65c6c9 commit 2d77e76
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions gcc/rust/resolve/rust-ast-resolve-type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,15 @@ ResolveTypeToCanonicalPath::visit (AST::TraitObjectType &)
rust_unreachable ();
}

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 ())
{}
Expand Down
2 changes: 2 additions & 0 deletions gcc/rust/resolve/rust-ast-resolve-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ class ResolveTypeToCanonicalPath : public ResolverBase

void visit (AST::TraitObjectType &type) override;

void visit (AST::TupleType &type) override;

private:
ResolveTypeToCanonicalPath ();

Expand Down
14 changes: 14 additions & 0 deletions gcc/testsuite/rust/compile/issue-3036.rs
Original file line number Diff line number Diff line change
@@ -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() -> () {
()
}
}
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/nr2/exclude
Original file line number Diff line number Diff line change
Expand Up @@ -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-3036.rs

0 comments on commit 2d77e76

Please sign in to comment.