Skip to content

Commit e447b73

Browse files
committed
Auto merge of #38792 - jseyfried:improve_macros_11_diagnostics, r=nikomatsakis
proc macros 1.1: improve diagnostics Fixes #38586. r? @nrc
2 parents a28701a + fd532a1 commit e447b73

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed

src/libsyntax/fold.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -542,19 +542,19 @@ pub fn noop_fold_arg<T: Folder>(Arg {id, pat, ty}: Arg, fld: &mut T) -> Arg {
542542
pub fn noop_fold_tt<T: Folder>(tt: &TokenTree, fld: &mut T) -> TokenTree {
543543
match *tt {
544544
TokenTree::Token(span, ref tok) =>
545-
TokenTree::Token(span, fld.fold_token(tok.clone())),
545+
TokenTree::Token(fld.new_span(span), fld.fold_token(tok.clone())),
546546
TokenTree::Delimited(span, ref delimed) => {
547-
TokenTree::Delimited(span, Rc::new(
547+
TokenTree::Delimited(fld.new_span(span), Rc::new(
548548
Delimited {
549549
delim: delimed.delim,
550-
open_span: delimed.open_span,
550+
open_span: fld.new_span(delimed.open_span),
551551
tts: fld.fold_tts(&delimed.tts),
552-
close_span: delimed.close_span,
552+
close_span: fld.new_span(delimed.close_span),
553553
}
554554
))
555555
},
556556
TokenTree::Sequence(span, ref seq) =>
557-
TokenTree::Sequence(span,
557+
TokenTree::Sequence(fld.new_span(span),
558558
Rc::new(SequenceRepetition {
559559
tts: fld.fold_tts(&seq.tts),
560560
separator: seq.separator.clone().map(|tok| fld.fold_token(tok)),
@@ -647,7 +647,7 @@ pub fn noop_fold_fn_decl<T: Folder>(decl: P<FnDecl>, fld: &mut T) -> P<FnDecl> {
647647
inputs: inputs.move_map(|x| fld.fold_arg(x)),
648648
output: match output {
649649
FunctionRetTy::Ty(ty) => FunctionRetTy::Ty(fld.fold_ty(ty)),
650-
FunctionRetTy::Default(span) => FunctionRetTy::Default(span),
650+
FunctionRetTy::Default(span) => FunctionRetTy::Default(fld.new_span(span)),
651651
},
652652
variadic: variadic
653653
})
@@ -674,7 +674,7 @@ pub fn noop_fold_ty_param<T: Folder>(tp: TyParam, fld: &mut T) -> TyParam {
674674
ident: fld.fold_ident(ident),
675675
bounds: fld.fold_bounds(bounds),
676676
default: default.map(|x| fld.fold_ty(x)),
677-
span: span
677+
span: fld.new_span(span),
678678
}
679679
}
680680

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2016 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+
// force-host
12+
// no-prefer-dynamic
13+
14+
#![feature(proc_macro, proc_macro_lib)]
15+
#![crate_type = "proc-macro"]
16+
17+
extern crate proc_macro;
18+
19+
#[proc_macro_derive(A)]
20+
pub fn derive_a(_: proc_macro::TokenStream) -> proc_macro::TokenStream {
21+
"fn f() { println!(\"{}\", foo); }".parse().unwrap()
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2016 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+
// aux-build:issue_38586.rs
12+
13+
#![feature(proc_macro)]
14+
15+
#[macro_use]
16+
extern crate issue_38586;
17+
18+
#[derive(A)] //~ ERROR `foo`
19+
struct A;
20+
21+
fn main() {}

0 commit comments

Comments
 (0)