Skip to content

Commit 40f2979

Browse files
committed
Fix bad name resolution of path with generic segments
When name-resolving paths we expect the name-resolver must resolve the root of the path. Such that a path might be module::type::associated_function We expect that the name resolution step must be able to resolve the module::type Portion of the path, it is permissive to allow everything after that to fail name resolution as this may require generic arguments of type inferencing to figure out which associated items are required. The issue in this referenced issue was that the generic arguments here were wrongly canonicalized to be part of the root path which meant the segment could not be name-resolved allowing the type resolution system to perform the generic specialization. Fixes #1173
1 parent d69dd65 commit 40f2979

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

gcc/rust/resolve/rust-ast-resolve-type.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,8 @@ class ResolvePathSegmentToCanonicalPath
169169
return CanonicalPath::create_empty ();
170170
}
171171

172-
std::string generics
173-
= ResolveTypeToCanonicalPath::canonicalize_generic_args (
174-
seg.get_generic_args ());
175-
176172
return CanonicalPath::new_seg (seg.get_node_id (),
177-
seg.get_ident_segment ().as_string ()
178-
+ "::" + generics);
173+
seg.get_ident_segment ().as_string ());
179174
}
180175
};
181176

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// { dg-additional-options "-w" }
2+
mod mem {
3+
extern "rust-intrinsic" {
4+
fn transmute<U, V>(_: U) -> V;
5+
}
6+
}
7+
8+
pub trait Hasher {
9+
fn write(&mut self, bytes: &[u8]);
10+
fn write_u16(&mut self, i: u16) {
11+
self.write(&mem::transmute::<_, [u8; 2]>(i))
12+
}
13+
}
14+
15+
pub struct SipHasher;
16+
17+
impl Hasher for SipHasher {
18+
#[inline]
19+
fn write(&mut self, msg: &[u8]) {}
20+
}

gcc/testsuite/rust/compile/torture/issue-893-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl Baz<i32, f32> {
2424

2525
pub fn main() {
2626
let a = Foo::<i32>::new::<f32>(123, 456f32);
27-
let b = Foo::new::<f32>(123, 456f32);
27+
// let b = Foo::new::<f32>(123, 456f32);
2828

2929
let c = Bar::<i32>(123);
3030
let d = Bar::baz(c);

0 commit comments

Comments
 (0)