diff options
| author | Jonathan Turner <jturner@mozilla.com> | 2016-08-17 07:20:04 -0700 |
|---|---|---|
| committer | Jonathan Turner <jturner@mozilla.com> | 2016-08-17 14:26:14 -0700 |
| commit | 61865384b8fa6d79d2b36cbd7c899eaf15f4aeea (patch) | |
| tree | 136502c033d49ba3e6e28f9460129586a381e92a /src/test/ui | |
| parent | d0a272b797fd538c4b4230bdefea534af8c1ffde (diff) | |
| download | rust-61865384b8fa6d79d2b36cbd7c899eaf15f4aeea.tar.gz rust-61865384b8fa6d79d2b36cbd7c899eaf15f4aeea.zip | |
Replace local backtrace with def-use, repair std macro spans
Diffstat (limited to 'src/test/ui')
17 files changed, 361 insertions, 0 deletions
diff --git a/src/test/ui/codemap_tests/bad-format-args.rs b/src/test/ui/codemap_tests/bad-format-args.rs new file mode 100644 index 00000000000..de7bc88f9ba --- /dev/null +++ b/src/test/ui/codemap_tests/bad-format-args.rs @@ -0,0 +1,15 @@ +// Copyright 2016 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. + +fn main() { + format!(); + format!("" 1); + format!("", 1 1); +} diff --git a/src/test/ui/codemap_tests/bad-format-args.stderr b/src/test/ui/codemap_tests/bad-format-args.stderr new file mode 100644 index 00000000000..fab8e2c8ce1 --- /dev/null +++ b/src/test/ui/codemap_tests/bad-format-args.stderr @@ -0,0 +1,26 @@ +error: requires at least a format string argument + --> $DIR/bad-format-args.rs:12:5 + | +12 | format!(); + | ^^^^^^^^^^ + | + = note: this error originates in a macro from the standard library + +error: expected token: `,` + --> $DIR/bad-format-args.rs:13:5 + | +13 | format!("" 1); + | ^^^^^^^^^^^^^^ + | + = note: this error originates in a macro from the standard library + +error: expected token: `,` + --> $DIR/bad-format-args.rs:14:5 + | +14 | format!("", 1 1); + | ^^^^^^^^^^^^^^^^^ + | + = note: this error originates in a macro from the standard library + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/codemap_tests/issue-28308.rs b/src/test/ui/codemap_tests/issue-28308.rs new file mode 100644 index 00000000000..e3a4920d951 --- /dev/null +++ b/src/test/ui/codemap_tests/issue-28308.rs @@ -0,0 +1,13 @@ +// Copyright 2016 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. + +fn main() { + assert!("foo"); +} diff --git a/src/test/ui/codemap_tests/issue-28308.stderr b/src/test/ui/codemap_tests/issue-28308.stderr new file mode 100644 index 00000000000..0d51a3f36e9 --- /dev/null +++ b/src/test/ui/codemap_tests/issue-28308.stderr @@ -0,0 +1,10 @@ +error: cannot apply unary operator `!` to type `&'static str` + --> $DIR/issue-28308.rs:12:5 + | +12 | assert!("foo"); + | ^^^^^^^^^^^^^^^ + | + = note: this error originates in a macro from the standard library + +error: aborting due to previous error + diff --git a/src/test/ui/codemap_tests/repair_span_std_macros.rs b/src/test/ui/codemap_tests/repair_span_std_macros.rs new file mode 100644 index 00000000000..3abc91d4f5f --- /dev/null +++ b/src/test/ui/codemap_tests/repair_span_std_macros.rs @@ -0,0 +1,13 @@ +// Copyright 2016 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. + +fn main() { + let x = vec![]; +} diff --git a/src/test/ui/codemap_tests/repair_span_std_macros.stderr b/src/test/ui/codemap_tests/repair_span_std_macros.stderr new file mode 100644 index 00000000000..1c9cbd63c33 --- /dev/null +++ b/src/test/ui/codemap_tests/repair_span_std_macros.stderr @@ -0,0 +1,11 @@ +error[E0282]: unable to infer enough type information about `_` + --> $DIR/repair_span_std_macros.rs:12:13 + | +12 | let x = vec![]; + | ^^^^^^ cannot infer type for `_` + | + = note: type annotations or generic parameter binding required + = note: this error originates in a macro from the standard library + +error: aborting due to previous error + diff --git a/src/test/ui/cross-crate-macro-backtrace/auxiliary/extern_macro_crate.rs b/src/test/ui/cross-crate-macro-backtrace/auxiliary/extern_macro_crate.rs new file mode 100644 index 00000000000..598e9f0f53a --- /dev/null +++ b/src/test/ui/cross-crate-macro-backtrace/auxiliary/extern_macro_crate.rs @@ -0,0 +1,23 @@ +// 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. + +#![crate_type = "dylib"] + +pub fn print(_args: std::fmt::Arguments) {} + +#[macro_export] +macro_rules! myprint { + ($($arg:tt)*) => (print(format_args!($($arg)*))); +} + +#[macro_export] +macro_rules! myprintln { + ($fmt:expr) => (myprint!(concat!($fmt, "\n"))); +} diff --git a/src/test/ui/cross-crate-macro-backtrace/main.rs b/src/test/ui/cross-crate-macro-backtrace/main.rs new file mode 100644 index 00000000000..f8bb84abcd4 --- /dev/null +++ b/src/test/ui/cross-crate-macro-backtrace/main.rs @@ -0,0 +1,17 @@ +// Copyright 2012 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. + +// aux-build:extern_macro_crate.rs +#[macro_use(myprintln, myprint)] +extern crate extern_macro_crate; + +fn main() { + myprintln!("{}"); //~ ERROR in this macro +} diff --git a/src/test/ui/cross-crate-macro-backtrace/main.stderr b/src/test/ui/cross-crate-macro-backtrace/main.stderr new file mode 100644 index 00000000000..fceaa70288c --- /dev/null +++ b/src/test/ui/cross-crate-macro-backtrace/main.stderr @@ -0,0 +1,10 @@ +error: invalid reference to argument `0` (no arguments given) + --> $DIR/main.rs:16:5 + | +16 | myprintln!("{}"); //~ ERROR in this macro + | ^^^^^^^^^^^^^^^^^ + | + = note: this error originates in a macro from the standard library + +error: aborting due to previous error + diff --git a/src/test/ui/macros/bad_hello.rs b/src/test/ui/macros/bad_hello.rs new file mode 100644 index 00000000000..a18771deace --- /dev/null +++ b/src/test/ui/macros/bad_hello.rs @@ -0,0 +1,13 @@ +// Copyright 2016 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. + +fn main() { + println!(3 + 4); +} diff --git a/src/test/ui/macros/bad_hello.stderr b/src/test/ui/macros/bad_hello.stderr new file mode 100644 index 00000000000..bffb33f468f --- /dev/null +++ b/src/test/ui/macros/bad_hello.stderr @@ -0,0 +1,8 @@ +error: expected a literal + --> $DIR/bad_hello.rs:12:14 + | +12 | println!(3 + 4); + | ^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/macros/macro-backtrace-invalid-internals.rs b/src/test/ui/macros/macro-backtrace-invalid-internals.rs new file mode 100644 index 00000000000..546e06b6c79 --- /dev/null +++ b/src/test/ui/macros/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 { + () => { + 1.fake() + } +} + +macro_rules! fake_field_stmt { + () => { + 1.fake + } +} + +macro_rules! fake_anon_field_stmt { + () => { + (1).0 + } +} + +macro_rules! fake_method_expr { + () => { + 1.fake() + } +} + +macro_rules! fake_field_expr { + () => { + 1.fake + } +} + +macro_rules! fake_anon_field_expr { + () => { + (1).0 + } +} + +fn main() { + fake_method_stmt!(); + fake_field_stmt!(); + fake_anon_field_stmt!(); + + let _ = fake_method_expr!(); + let _ = fake_field_expr!(); + let _ = fake_anon_field_expr!(); +} diff --git a/src/test/ui/macros/macro-backtrace-invalid-internals.stderr b/src/test/ui/macros/macro-backtrace-invalid-internals.stderr new file mode 100644 index 00000000000..82000a59bfb --- /dev/null +++ b/src/test/ui/macros/macro-backtrace-invalid-internals.stderr @@ -0,0 +1,56 @@ +error: no method named `fake` found for type `{integer}` in the current scope + --> $DIR/macro-backtrace-invalid-internals.rs:15:13 + | +15 | 1.fake() + | ^^^^ +... +50 | fake_method_stmt!(); + | -------------------- in this macro invocation + +error: attempted access of field `fake` on type `{integer}`, but no field with that name was found + --> $DIR/macro-backtrace-invalid-internals.rs:21:11 + | +21 | 1.fake + | ^^^^^^ +... +51 | fake_field_stmt!(); + | ------------------- in this macro invocation + +error: attempted tuple index `0` on type `{integer}`, but the type was not a tuple or tuple struct + --> $DIR/macro-backtrace-invalid-internals.rs:27:11 + | +27 | (1).0 + | ^^^^^ +... +52 | fake_anon_field_stmt!(); + | ------------------------ in this macro invocation + +error: no method named `fake` found for type `{integer}` in the current scope + --> $DIR/macro-backtrace-invalid-internals.rs:33:13 + | +33 | 1.fake() + | ^^^^ +... +54 | let _ = fake_method_expr!(); + | ------------------- in this macro invocation + +error: attempted access of field `fake` on type `{integer}`, but no field with that name was found + --> $DIR/macro-backtrace-invalid-internals.rs:39:11 + | +39 | 1.fake + | ^^^^^^ +... +55 | let _ = fake_field_expr!(); + | ------------------ in this macro invocation + +error: attempted tuple index `0` on type `{integer}`, but the type was not a tuple or tuple struct + --> $DIR/macro-backtrace-invalid-internals.rs:45:11 + | +45 | (1).0 + | ^^^^^ +... +56 | let _ = fake_anon_field_expr!(); + | ----------------------- in this macro invocation + +error: aborting due to 6 previous errors + diff --git a/src/test/ui/macros/macro-backtrace-nested.rs b/src/test/ui/macros/macro-backtrace-nested.rs new file mode 100644 index 00000000000..d8bf6222c1c --- /dev/null +++ b/src/test/ui/macros/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 { + () => { 1 + nested_expr!(); } +} + +fn main() { + 1 + call_nested_expr!(); + call_nested_expr_sum!(); +} diff --git a/src/test/ui/macros/macro-backtrace-nested.stderr b/src/test/ui/macros/macro-backtrace-nested.stderr new file mode 100644 index 00000000000..e452e8d69bd --- /dev/null +++ b/src/test/ui/macros/macro-backtrace-nested.stderr @@ -0,0 +1,20 @@ +error[E0425]: unresolved name `fake` + --> $DIR/macro-backtrace-nested.rs:15:12 + | +15 | () => (fake) + | ^^^^ +... +27 | 1 + call_nested_expr!(); + | ------------------- in this macro invocation + +error[E0425]: unresolved name `fake` + --> $DIR/macro-backtrace-nested.rs:15:12 + | +15 | () => (fake) + | ^^^^ +... +28 | call_nested_expr_sum!(); + | ------------------------ in this macro invocation + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/macros/macro-backtrace-println.rs b/src/test/ui/macros/macro-backtrace-println.rs new file mode 100644 index 00000000000..baf276919a5 --- /dev/null +++ b/src/test/ui/macros/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 { + ($($arg:tt)*) => (print(format_args!($($arg)*))); +} + +macro_rules! myprintln { + ($fmt:expr) => (myprint!(concat!($fmt, "\n"))); +} + +fn main() { + myprintln!("{}"); +} diff --git a/src/test/ui/macros/macro-backtrace-println.stderr b/src/test/ui/macros/macro-backtrace-println.stderr new file mode 100644 index 00000000000..f21253bb67f --- /dev/null +++ b/src/test/ui/macros/macro-backtrace-println.stderr @@ -0,0 +1,11 @@ +error: invalid reference to argument `0` (no arguments given) + --> $DIR/macro-backtrace-println.rs:24:30 + | +24 | ($fmt:expr) => (myprint!(concat!($fmt, "/n"))); + | ^^^^^^^^^^^^^^^^^^^ +... +28 | myprintln!("{}"); + | ----------------- in this macro invocation + +error: aborting due to previous error + |
