From d13bfd294c55a47bb33e5846ce184c80cdf547dd Mon Sep 17 00:00:00 2001 From: Michael Lamparski Date: Mon, 11 Jun 2018 19:44:48 -0400 Subject: [PATCH] fix issue #51331 by updating qself.position --- src/librustc_resolve/macros.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index fe6909f759159..de7a3dc5ceeb2 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -138,7 +138,23 @@ impl<'a> base::Resolver for Resolver<'a> { struct EliminateCrateVar<'b, 'a: 'b>(&'b mut Resolver<'a>, Span); impl<'a, 'b> Folder for EliminateCrateVar<'a, 'b> { - fn fold_path(&mut self, mut path: ast::Path) -> ast::Path { + fn fold_path(&mut self, path: ast::Path) -> ast::Path { + match self.fold_qpath(None, path) { + (None, path) => path, + _ => unreachable!(), + } + } + + fn fold_qpath(&mut self, mut qself: Option, mut path: ast::Path) + -> (Option, ast::Path) { + qself = qself.map(|ast::QSelf { ty, path_span, position }| { + ast::QSelf { + ty: self.fold_ty(ty), + path_span: self.new_span(path_span), + position, + } + }); + let ident = path.segments[0].ident; if ident.name == keywords::DollarCrate.name() { path.segments[0].ident.name = keywords::CrateRoot.name(); @@ -150,10 +166,13 @@ impl<'a> base::Resolver for Resolver<'a> { ast::Ident::with_empty_ctxt(name).with_span_pos(span) ), _ => unreachable!(), - }) + }); + if let Some(qself) = &mut qself { + qself.position += 1; + } } } - path + (qself, path) } fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {