From a137d00ce52e9db78bb803d1384fdf3a4c4e63ea Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 22 May 2018 08:01:21 -0700 Subject: rustc: Correctly pretty-print macro delimiters This commit updates the `Mac_` AST structure to keep track of the delimiters that it originally had for its invocation. This allows us to faithfully pretty-print macro invocations not using parentheses (e.g. `vec![...]`). This in turn helps procedural macros due to #43081. Closes #50840 --- .../proc-macro/auxiliary/macro-brackets.rs | 22 ++++++++++++++++++ src/test/ui-fulldeps/proc-macro/macro-brackets.rs | 26 ++++++++++++++++++++++ .../ui-fulldeps/proc-macro/macro-brackets.stderr | 9 ++++++++ 3 files changed, 57 insertions(+) create mode 100644 src/test/ui-fulldeps/proc-macro/auxiliary/macro-brackets.rs create mode 100644 src/test/ui-fulldeps/proc-macro/macro-brackets.rs create mode 100644 src/test/ui-fulldeps/proc-macro/macro-brackets.stderr (limited to 'src/test') diff --git a/src/test/ui-fulldeps/proc-macro/auxiliary/macro-brackets.rs b/src/test/ui-fulldeps/proc-macro/auxiliary/macro-brackets.rs new file mode 100644 index 00000000000..ab1cfe1dbd6 --- /dev/null +++ b/src/test/ui-fulldeps/proc-macro/auxiliary/macro-brackets.rs @@ -0,0 +1,22 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// no-prefer-dynamic + +#![crate_type = "proc-macro"] +#![feature(proc_macro)] + +extern crate proc_macro; +use proc_macro::*; + +#[proc_macro_attribute] +pub fn doit(_: TokenStream, input: TokenStream) -> TokenStream { + input.into_iter().collect() +} diff --git a/src/test/ui-fulldeps/proc-macro/macro-brackets.rs b/src/test/ui-fulldeps/proc-macro/macro-brackets.rs new file mode 100644 index 00000000000..cb734e2d10b --- /dev/null +++ b/src/test/ui-fulldeps/proc-macro/macro-brackets.rs @@ -0,0 +1,26 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:macro-brackets.rs + +#![feature(proc_macro)] + +extern crate macro_brackets as bar; +use bar::doit; + +macro_rules! id { + ($($t:tt)*) => ($($t)*) +} + +#[doit] +id![static X: u32 = 'a';]; //~ ERROR: mismatched types + + +fn main() {} diff --git a/src/test/ui-fulldeps/proc-macro/macro-brackets.stderr b/src/test/ui-fulldeps/proc-macro/macro-brackets.stderr new file mode 100644 index 00000000000..1f31a034913 --- /dev/null +++ b/src/test/ui-fulldeps/proc-macro/macro-brackets.stderr @@ -0,0 +1,9 @@ +error[E0308]: mismatched types + --> $DIR/macro-brackets.rs:23:21 + | +LL | id![static X: u32 = 'a';]; //~ ERROR: mismatched types + | ^^^ expected u32, found char + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. -- cgit 1.4.1-3-g733a5