diff options
| -rw-r--r-- | src/test/compile-fail/macro-backtrace-invalid-internals.rs | 57 | ||||
| -rw-r--r-- | src/test/compile-fail/macro-backtrace-nested.rs | 29 | ||||
| -rw-r--r-- | src/test/compile-fail/macro-backtrace-println.rs | 29 |
3 files changed, 115 insertions, 0 deletions
diff --git a/src/test/compile-fail/macro-backtrace-invalid-internals.rs b/src/test/compile-fail/macro-backtrace-invalid-internals.rs new file mode 100644 index 00000000000..df906d72356 --- /dev/null +++ b/src/test/compile-fail/macro-backtrace-invalid-internals.rs @@ -0,0 +1,57 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Macros in statement vs expression position handle backtraces differently. + +macro_rules! fake_method_stmt { //~ NOTE in expansion of + () => { + 1.fake() //~ ERROR does not implement any method + } +} + +macro_rules! fake_field_stmt { //~ NOTE in expansion of + () => { + 1.fake //~ ERROR no field with that name + } +} + +macro_rules! fake_anon_field_stmt { //~ NOTE in expansion of + () => { + (1).0 //~ ERROR type was not a tuple + } +} + +macro_rules! fake_method_expr { //~ NOTE in expansion of + () => { + 1.fake() //~ ERROR does not implement any method + } +} + +macro_rules! fake_field_expr { + () => { + 1.fake + } +} + +macro_rules! fake_anon_field_expr { + () => { + (1).0 + } +} + +fn main() { + fake_method_stmt!(); //~ NOTE expansion site + fake_field_stmt!(); //~ NOTE expansion site + fake_anon_field_stmt!(); //~ NOTE expansion site + + let _ = fake_method_expr!(); //~ NOTE expansion site + let _ = fake_field_expr!(); //~ ERROR no field with that name + let _ = fake_anon_field_expr!(); //~ ERROR type was not a tuple +} diff --git a/src/test/compile-fail/macro-backtrace-nested.rs b/src/test/compile-fail/macro-backtrace-nested.rs new file mode 100644 index 00000000000..7c1dc1a468c --- /dev/null +++ b/src/test/compile-fail/macro-backtrace-nested.rs @@ -0,0 +1,29 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// In expression position, but not statement position, when we expand a macro, +// we replace the span of the expanded expression with that of the call site. + +macro_rules! nested_expr { + () => (fake) +} + +macro_rules! call_nested_expr { + () => (nested_expr!()) +} + +macro_rules! call_nested_expr_sum { //~ NOTE in expansion of + () => { 1 + nested_expr!(); } //~ ERROR unresolved name +} + +fn main() { + 1 + call_nested_expr!(); //~ ERROR unresolved name + call_nested_expr_sum!(); //~ NOTE expansion site +} diff --git a/src/test/compile-fail/macro-backtrace-println.rs b/src/test/compile-fail/macro-backtrace-println.rs new file mode 100644 index 00000000000..0c66bbfcf04 --- /dev/null +++ b/src/test/compile-fail/macro-backtrace-println.rs @@ -0,0 +1,29 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// The `format_args!` syntax extension issues errors before code expansion +// has completed, but we still need a backtrace. + +// This test includes stripped-down versions of `print!` and `println!`, +// because we can't otherwise verify the lines of the backtrace. + +fn print(_args: std::fmt::Arguments) {} + +macro_rules! myprint { //~ NOTE in expansion of + ($($arg:tt)*) => (print(format_args!($($arg)*))); +} + +macro_rules! myprintln { //~ NOTE in expansion of + ($fmt:expr) => (myprint!(concat!($fmt, "\n"))); //~ ERROR invalid reference to argument `0` +} + +fn main() { + myprintln!("{}"); //~ NOTE expansion site +} |
