Skip to content

Commit 9526906

Browse files
philbertydkm
authored andcommitted
gccrs: fix bad monomophization of generic paths
When we have generic paths like T::foobar during codegen sometimes we need to enforce an extra lookup for this generic parameter type to the mono morphized underlying type. Fixes #3915 Fixes #1247 gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): do another lookup gcc/testsuite/ChangeLog: * rust/compile/issue-3915.rs: New test. * rust/execute/torture/sip-hasher.rs: New test. Signed-off-by: Philip Herron <[email protected]>
1 parent 24ab21c commit 9526906

File tree

3 files changed

+477
-4
lines changed

3 files changed

+477
-4
lines changed

gcc/rust/backend/rust-compile-resolve-path.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,18 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup,
329329
rust_assert (lookup->is<TyTy::FnType> ());
330330
auto fn = lookup->as<TyTy::FnType> ();
331331
rust_assert (fn->get_num_type_params () > 0);
332-
auto &self = fn->get_substs ().at (0);
333-
auto receiver = self.get_param_ty ();
332+
TyTy::SubstitutionParamMapping &self = fn->get_substs ().at (0);
333+
TyTy::ParamType *receiver = self.get_param_ty ();
334+
TyTy::BaseType *r = receiver;
335+
if (!receiver->can_resolve ())
336+
{
337+
bool ok
338+
= ctx->get_tyctx ()->lookup_type (receiver->get_ref (), &r);
339+
rust_assert (ok);
340+
}
341+
334342
auto candidates
335-
= Resolver::PathProbeImplTrait::Probe (receiver, final_segment,
336-
trait_ref);
343+
= Resolver::PathProbeImplTrait::Probe (r, final_segment, trait_ref);
337344
if (candidates.size () == 0)
338345
{
339346
// this means we are defaulting back to the trait_item if
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// { dg-options "-w" }
2+
#[lang = "sized"]
3+
trait Sized {}
4+
5+
trait Trait {
6+
fn do_thing();
7+
}
8+
9+
struct MyType;
10+
11+
impl Trait for MyType {
12+
fn do_thing() {}
13+
}
14+
15+
struct Wrapper<T: Trait> {
16+
value: T,
17+
}
18+
19+
impl<T: Trait> Wrapper<T> {
20+
fn call_it() {
21+
T::do_thing();
22+
}
23+
}
24+
25+
fn main() {
26+
let _ = Wrapper::<MyType> { value: MyType };
27+
Wrapper::<MyType>::call_it();
28+
}

0 commit comments

Comments
 (0)