Skip to content

Commit

Permalink
Rollup merge of rust-lang#78980 - thiolliere:gui-fix-qpath, r=estebank
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Dylan-DPC authored Nov 14, 2020
2 parents e70291f + 775f1e5 commit 9eb4693
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
11 changes: 6 additions & 5 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2327,11 +2327,12 @@ impl<'a> State<'a> {
self.print_path(path, false, depth);
}
self.s.word(">");
self.s.word("::");
let item_segment = path.segments.last().unwrap();
self.print_ident(item_segment.ident);
if let Some(ref args) = item_segment.args {
self.print_generic_args(args, colons_before_params)
for item_segment in &path.segments[qself.position..] {
self.s.word("::");
self.print_ident(item_segment.ident);
if let Some(ref args) = item_segment.args {
self.print_generic_args(args, colons_before_params)
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/test/pretty/qpath-associated-type-bound.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// pp-exact


mod m {
pub trait Tr {
type Ts: super::Tu;
}
}

trait Tu {
fn dummy() { }
}

fn foo<T: m::Tr>() { <T as m::Tr>::Ts::dummy(); }

fn main() { }

0 comments on commit 9eb4693

Please sign in to comment.