Skip to content

Commit

Permalink
rust fix ICE when hir lowering qualified path expressions without an as
Browse files Browse the repository at this point in the history
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:
	* rust/compile/issue-3082.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
  • Loading branch information
philberty committed Sep 20, 2024
1 parent 522576d commit 298df2a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
11 changes: 9 additions & 2 deletions gcc/rust/hir/rust-ast-lower-type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
9 changes: 9 additions & 0 deletions gcc/testsuite/rust/compile/issue-3082.rs
Original file line number Diff line number Diff line change
@@ -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 }
}
}
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-3082.rs

0 comments on commit 298df2a

Please sign in to comment.