Skip to content

Commit c185688

Browse files
powerboat9P-E-P
authored andcommitted
Prevent multiple resolution insertion
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc (DeriveClone::clone_impl): Avoid using the same node id multiple times. (DeriveClone::clone_enum_identifier): Likewise. (DeriveClone::clone_enum_tuple): Likewise. * expand/rust-derive-copy.cc (DeriveCopy::copy_impl): Likewise. * resolve/rust-ast-resolve-item.cc (flatten_list): Likewise. * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Prevent reinsertion of resolutions. * resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::resolve_fn_trait_call): Likewise. * resolve/rust-name-resolver.cc (Resolver::insert_resolved_name): Catch multiple resolution insertions. (Resolver::insert_resolved_type): Likewise. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <[email protected]>
1 parent c27eac3 commit c185688

File tree

8 files changed

+302
-81
lines changed

8 files changed

+302
-81
lines changed

gcc/rust/expand/rust-derive-clone.cc

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,17 @@ DeriveClone::clone_impl (
9191
std::unique_ptr<AssociatedItem> &&clone_fn, std::string name,
9292
const std::vector<std::unique_ptr<GenericParam>> &type_generics)
9393
{
94-
auto clone = builder.type_path (LangItem::Kind::CLONE);
94+
// we should have two of these, so we don't run into issues with
95+
// two paths sharing a node id
96+
auto clone_bound = builder.type_path (LangItem::Kind::CLONE);
97+
auto clone_trait_path = builder.type_path (LangItem::Kind::CLONE);
9598

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

98-
auto generics
99-
= setup_impl_generics (name, type_generics, builder.trait_bound (clone));
101+
auto generics = setup_impl_generics (name, type_generics,
102+
builder.trait_bound (clone_bound));
100103

101-
return builder.trait_impl (clone, std::move (generics.self_type),
104+
return builder.trait_impl (clone_trait_path, std::move (generics.self_type),
102105
std::move (trait_items),
103106
std::move (generics.impl));
104107
}
@@ -173,9 +176,14 @@ DeriveClone::clone_enum_identifier (PathInExpression variant_path,
173176
const std::unique_ptr<EnumItem> &variant)
174177
{
175178
auto pattern = std::unique_ptr<Pattern> (new ReferencePattern (
176-
std::unique_ptr<Pattern> (new PathInExpression (variant_path)), false,
177-
false, loc));
178-
auto expr = std::unique_ptr<Expr> (new PathInExpression (variant_path));
179+
std::unique_ptr<Pattern> (new PathInExpression (
180+
variant_path.get_segments (), {}, variant_path.get_locus (),
181+
variant_path.opening_scope_resolution ())),
182+
false, false, loc));
183+
auto expr = std::unique_ptr<Expr> (
184+
new PathInExpression (variant_path.get_segments (), {},
185+
variant_path.get_locus (),
186+
variant_path.opening_scope_resolution ()));
179187

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

209-
auto pattern = std::unique_ptr<Pattern> (
210-
new ReferencePattern (std::unique_ptr<Pattern> (new TupleStructPattern (
211-
variant_path, std::move (pattern_items))),
212-
false, false, loc));
213-
214-
auto expr
215-
= builder.call (std::unique_ptr<Expr> (new PathInExpression (variant_path)),
216-
std::move (cloned_patterns));
217+
auto pattern = std::unique_ptr<Pattern> (new ReferencePattern (
218+
std::unique_ptr<Pattern> (new TupleStructPattern (
219+
PathInExpression (variant_path.get_segments (), {},
220+
variant_path.get_locus (),
221+
variant_path.opening_scope_resolution ()),
222+
std::move (pattern_items))),
223+
false, false, loc));
224+
225+
auto expr = builder.call (std::unique_ptr<Expr> (new PathInExpression (
226+
variant_path.get_segments (), {},
227+
variant_path.get_locus (),
228+
variant_path.opening_scope_resolution ())),
229+
std::move (cloned_patterns));
217230

218231
return builder.match_case (std::move (pattern), std::move (expr));
219232
}

gcc/rust/expand/rust-derive-copy.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@ DeriveCopy::copy_impl (
4242
std::string name,
4343
const std::vector<std::unique_ptr<GenericParam>> &type_generics)
4444
{
45-
auto copy = builder.type_path (LangItem::Kind::COPY);
45+
// we should have two of these, so we don't run into issues with
46+
// two paths sharing a node id
47+
auto copy_bound = builder.type_path (LangItem::Kind::COPY);
48+
auto copy_trait_path = builder.type_path (LangItem::Kind::COPY);
4649

47-
auto generics
48-
= setup_impl_generics (name, type_generics, builder.trait_bound (copy));
50+
auto generics = setup_impl_generics (name, type_generics,
51+
builder.trait_bound (copy_bound));
4952

50-
return builder.trait_impl (copy, std::move (generics.self_type), {},
51-
std::move (generics.impl));
53+
return builder.trait_impl (copy_trait_path, std::move (generics.self_type),
54+
{}, std::move (generics.impl));
5255
}
5356

5457
void

gcc/rust/resolve/rust-ast-resolve-item.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,18 @@ flatten_list (const AST::UseTreeList &list, std::vector<Import> &imports)
903903

904904
for (auto import = imports.begin () + start_idx; import != imports.end ();
905905
import++)
906-
import->add_prefix (prefix);
906+
{
907+
// avoid duplicate node ids
908+
auto prefix_copy
909+
= AST::SimplePath ({}, prefix.has_opening_scope_resolution (),
910+
prefix.get_locus ());
911+
for (auto &seg : prefix.get_segments ())
912+
prefix_copy.get_segments ().push_back (
913+
AST::SimplePathSegment (seg.get_segment_name (),
914+
seg.get_locus ()));
915+
916+
import->add_prefix (std::move (prefix_copy));
917+
}
907918
}
908919
}
909920

0 commit comments

Comments
 (0)