Skip to content

Commit 9eb4693

Browse files
authored
Rollup merge of rust-lang#78980 - thiolliere:gui-fix-qpath, r=estebank
Fix rustc_ast_pretty print_qpath resulting in invalid macro input related rust-lang#76874 (third case) ### Issue: The input for a procedural macro is incorrect, for the rust code: ```rust mod m { pub trait Tr { type Ts: super::Tu; } } trait Tu { fn dummy() { } } #[may_proc_macro] fn foo() { <T as m::Tr>::Ts::dummy(); } ``` the macro will get the input: ```rust fn foo() { <T as m::Tr>::dummy(); } ``` Thus `Ts` has disappeared. ### Fix: This is due to invalid pretty print of qpath. This PR fix it.
2 parents e70291f + 775f1e5 commit 9eb4693

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -2327,11 +2327,12 @@ impl<'a> State<'a> {
23272327
self.print_path(path, false, depth);
23282328
}
23292329
self.s.word(">");
2330-
self.s.word("::");
2331-
let item_segment = path.segments.last().unwrap();
2332-
self.print_ident(item_segment.ident);
2333-
if let Some(ref args) = item_segment.args {
2334-
self.print_generic_args(args, colons_before_params)
2330+
for item_segment in &path.segments[qself.position..] {
2331+
self.s.word("::");
2332+
self.print_ident(item_segment.ident);
2333+
if let Some(ref args) = item_segment.args {
2334+
self.print_generic_args(args, colons_before_params)
2335+
}
23352336
}
23362337
}
23372338

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// pp-exact
2+
3+
4+
mod m {
5+
pub trait Tr {
6+
type Ts: super::Tu;
7+
}
8+
}
9+
10+
trait Tu {
11+
fn dummy() { }
12+
}
13+
14+
fn foo<T: m::Tr>() { <T as m::Tr>::Ts::dummy(); }
15+
16+
fn main() { }

0 commit comments

Comments
 (0)