Skip to content

Commit 2dcd791

Browse files
Generated code spans now point to callsite parameters (where applicable)
1 parent 9267a3a commit 2dcd791

File tree

6 files changed

+35
-8
lines changed

6 files changed

+35
-8
lines changed

src/libsyntax/ext/tt/macro_parser.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ pub use self::ParseResult::*;
7979
use self::TokenTreeOrTokenTreeVec::*;
8080

8181
use ast;
82-
use ast::{TokenTree, Name};
83-
use codemap::{BytePos, mk_sp, Span};
82+
use ast::{TokenTree, Name, Ident};
83+
use codemap::{BytePos, mk_sp, Span, Spanned};
8484
use codemap;
8585
use parse::lexer::*; //resolve bug?
8686
use parse::ParseSess;
@@ -526,7 +526,10 @@ pub fn parse_nt(p: &mut Parser, sp: Span, name: &str) -> Nonterminal {
526526
"ty" => token::NtTy(panictry!(p.parse_ty())),
527527
// this could be handled like a token, since it is one
528528
"ident" => match p.token {
529-
token::Ident(sn,b) => { panictry!(p.bump()); token::NtIdent(Box::new(sn),b) }
529+
token::Ident(sn,b) => {
530+
panictry!(p.bump());
531+
token::NtIdent(Box::new(Spanned::<Ident>{node: sn, span: p.span}),b)
532+
}
530533
_ => {
531534
let token_str = pprust::token_to_string(&p.token);
532535
panic!(p.fatal(&format!("expected ident, found {}",

src/libsyntax/ext/tt/transcribe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
293293
// (a) idents can be in lots of places, so it'd be a pain
294294
// (b) we actually can, since it's a token.
295295
MatchedNonterminal(NtIdent(ref sn, b)) => {
296-
r.cur_span = sp;
297-
r.cur_tok = token::Ident(**sn, b);
296+
r.cur_span = sn.span;
297+
r.cur_tok = token::Ident(sn.node, b);
298298
return ret_val;
299299
}
300300
MatchedNonterminal(ref other_whole_nt) => {

src/libsyntax/fold.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,8 @@ pub fn noop_fold_interpolated<T: Folder>(nt: token::Nonterminal, fld: &mut T)
663663
token::NtExpr(expr) => token::NtExpr(fld.fold_expr(expr)),
664664
token::NtTy(ty) => token::NtTy(fld.fold_ty(ty)),
665665
token::NtIdent(id, is_mod_name) =>
666-
token::NtIdent(Box::new(fld.fold_ident(*id)), is_mod_name),
666+
token::NtIdent(Box::new(Spanned::<Ident>{node: fld.fold_ident(id.node), .. *id}),
667+
is_mod_name),
667668
token::NtMeta(meta_item) => token::NtMeta(fld.fold_meta_item(meta_item)),
668669
token::NtPath(path) => token::NtPath(Box::new(fld.fold_path(*path))),
669670
token::NtTT(tt) => token::NtTT(P(fld.fold_tt(&tt))),

src/libsyntax/parse/token.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ pub enum Nonterminal {
377377
NtPat(P<ast::Pat>),
378378
NtExpr(P<ast::Expr>),
379379
NtTy(P<ast::Ty>),
380-
NtIdent(Box<ast::Ident>, IdentStyle),
380+
NtIdent(Box<ast::SpannedIdent>, IdentStyle),
381381
/// Stuff inside brackets for attributes
382382
NtMeta(P<ast::MetaItem>),
383383
NtPath(Box<ast::Path>),

src/libsyntax/print/pprust.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ pub fn token_to_string(tok: &Token) -> String {
296296
token::NtBlock(ref e) => block_to_string(&**e),
297297
token::NtStmt(ref e) => stmt_to_string(&**e),
298298
token::NtPat(ref e) => pat_to_string(&**e),
299-
token::NtIdent(ref e, _) => ident_to_string(**e),
299+
token::NtIdent(ref e, _) => ident_to_string(e.node),
300300
token::NtTT(ref e) => tt_to_string(&**e),
301301
token::NtArm(ref e) => arm_to_string(&*e),
302302
token::NtImplItem(ref e) => impl_item_to_string(&**e),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
macro_rules! foo {
12+
($id: ident) => {
13+
$id
14+
}
15+
}
16+
17+
// Testing that the error span points to the parameter 'x' in the callsite,
18+
// not to the macro variable '$id'
19+
fn main() {
20+
foo!(
21+
x //~ ERROR unresolved name `x`
22+
);
23+
}

0 commit comments

Comments
 (0)