Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent duplicate resolution insertions #3456

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
43 changes: 28 additions & 15 deletions gcc/rust/expand/rust-derive-clone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,17 @@ DeriveClone::clone_impl (
std::unique_ptr<AssociatedItem> &&clone_fn, std::string name,
const std::vector<std::unique_ptr<GenericParam>> &type_generics)
{
auto clone = builder.type_path (LangItem::Kind::CLONE);
// we should have two of these, so we don't run into issues with
// two paths sharing a node id
auto clone_bound = builder.type_path (LangItem::Kind::CLONE);
auto clone_trait_path = builder.type_path (LangItem::Kind::CLONE);

auto trait_items = vec (std::move (clone_fn));

auto generics
= setup_impl_generics (name, type_generics, builder.trait_bound (clone));
auto generics = setup_impl_generics (name, type_generics,
builder.trait_bound (clone_bound));

return builder.trait_impl (clone, std::move (generics.self_type),
return builder.trait_impl (clone_trait_path, std::move (generics.self_type),
std::move (trait_items),
std::move (generics.impl));
}
Expand Down Expand Up @@ -173,9 +176,14 @@ DeriveClone::clone_enum_identifier (PathInExpression variant_path,
const std::unique_ptr<EnumItem> &variant)
{
auto pattern = std::unique_ptr<Pattern> (new ReferencePattern (
std::unique_ptr<Pattern> (new PathInExpression (variant_path)), false,
false, loc));
auto expr = std::unique_ptr<Expr> (new PathInExpression (variant_path));
std::unique_ptr<Pattern> (new PathInExpression (
variant_path.get_segments (), {}, variant_path.get_locus (),
variant_path.opening_scope_resolution ())),
false, false, loc));
auto expr = std::unique_ptr<Expr> (
new PathInExpression (variant_path.get_segments (), {},
variant_path.get_locus (),
variant_path.opening_scope_resolution ()));

return builder.match_case (std::move (pattern), std::move (expr));
}
Expand Down Expand Up @@ -206,14 +214,19 @@ DeriveClone::clone_enum_tuple (PathInExpression variant_path,
auto pattern_items = std::unique_ptr<TupleStructItems> (
new TupleStructItemsNoRange (std::move (patterns)));

auto pattern = std::unique_ptr<Pattern> (
new ReferencePattern (std::unique_ptr<Pattern> (new TupleStructPattern (
variant_path, std::move (pattern_items))),
false, false, loc));

auto expr
= builder.call (std::unique_ptr<Expr> (new PathInExpression (variant_path)),
std::move (cloned_patterns));
auto pattern = std::unique_ptr<Pattern> (new ReferencePattern (
std::unique_ptr<Pattern> (new TupleStructPattern (
PathInExpression (variant_path.get_segments (), {},
variant_path.get_locus (),
variant_path.opening_scope_resolution ()),
std::move (pattern_items))),
false, false, loc));

auto expr = builder.call (std::unique_ptr<Expr> (new PathInExpression (
variant_path.get_segments (), {},
variant_path.get_locus (),
variant_path.opening_scope_resolution ())),
std::move (cloned_patterns));

return builder.match_case (std::move (pattern), std::move (expr));
}
Expand Down
13 changes: 8 additions & 5 deletions gcc/rust/expand/rust-derive-copy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ DeriveCopy::copy_impl (
std::string name,
const std::vector<std::unique_ptr<GenericParam>> &type_generics)
{
auto copy = builder.type_path (LangItem::Kind::COPY);
// we should have two of these, so we don't run into issues with
// two paths sharing a node id
auto copy_bound = builder.type_path (LangItem::Kind::COPY);
auto copy_trait_path = builder.type_path (LangItem::Kind::COPY);

auto generics
= setup_impl_generics (name, type_generics, builder.trait_bound (copy));
auto generics = setup_impl_generics (name, type_generics,
builder.trait_bound (copy_bound));

return builder.trait_impl (copy, std::move (generics.self_type), {},
std::move (generics.impl));
return builder.trait_impl (copy_trait_path, std::move (generics.self_type),
{}, std::move (generics.impl));
}

void
Expand Down
13 changes: 12 additions & 1 deletion gcc/rust/resolve/rust-ast-resolve-item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,18 @@ flatten_list (const AST::UseTreeList &list, std::vector<Import> &imports)

for (auto import = imports.begin () + start_idx; import != imports.end ();
import++)
import->add_prefix (prefix);
{
// avoid duplicate node ids
auto prefix_copy
= AST::SimplePath ({}, prefix.has_opening_scope_resolution (),
prefix.get_locus ());
for (auto &seg : prefix.get_segments ())
prefix_copy.get_segments ().push_back (
AST::SimplePathSegment (seg.get_segment_name (),
seg.get_locus ()));

import->add_prefix (std::move (prefix_copy));
}
}
}

Expand Down
Loading