Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions gcc/rust/resolve/rust-name-resolution-context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ CanonicalPathRecordTraitImpl::as_path (const NameResolutionContext &ctx)
impl_id, trait_path_record.as_path (ctx), type_record.as_path (ctx)));
}

Resolver::CanonicalPath
CanonicalPathCtx::get_path (NodeId id) const
{
if (auto rec = get_record_opt (id))
return (*rec)->as_path (*nr_ctx);

return Resolver::CanonicalPath::create_empty ();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing canonical paths shouldn't be silently replaced with empty paths

}

NameResolutionContext::NameResolutionContext ()
: mappings (Analysis::Mappings::get ()), canonical_ctx (*this)
{}
Expand Down
13 changes: 9 additions & 4 deletions gcc/rust/resolve/rust-name-resolution-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,7 @@ class CanonicalPathCtx
: current_record (nullptr), nr_ctx (&ctx)
{}

Resolver::CanonicalPath get_path (NodeId id) const
{
return get_record (id).as_path (*nr_ctx);
}
Resolver::CanonicalPath get_path (NodeId id) const;

CanonicalPathRecord &get_record (NodeId id) const
{
Expand All @@ -380,6 +377,14 @@ class CanonicalPathCtx
return it->second.get ();
}

tl::optional<Resolver::CanonicalPath> get_path_opt (NodeId id) const
{
auto rec = get_record_opt (id);
if (!rec)
return tl::nullopt;
return (*rec)->as_path (*nr_ctx);
}

void insert_record (NodeId id, const Identifier &ident)
{
insert_record (id, ident.as_string ());
Expand Down
19 changes: 19 additions & 0 deletions gcc/testsuite/rust/compile/issue-4143.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// { dg-do compile }
// { dg-options "-frust-incomplete-and-experimental-compiler-do-not-use" }
// { dg-prune-output "failed to locate crate" }
// { dg-prune-output "unknown crate" }

// ICE regression test for canonical path lookup
// Inline items inside const generic block expressions
// must not require canonical paths.

struct Expr<const N: u32>;

trait Trait0 {
fn required(_: Expr<{
struct Type;
0
}>);
}

fn main() {}