-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
585 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
...est/ui/macros/assert-trailing-junk.stderr → ...t-trailing-junk.with-generic-asset.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/test/ui/macros/assert-trailing-junk.without-generic-asset.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
error: expected one of `,`, `.`, `?`, or an operator, found `some` | ||
--> $DIR/assert-trailing-junk.rs:9:18 | ||
| | ||
LL | assert!(true some extra junk, "whatever"); | ||
| ^^^^ expected one of `,`, `.`, `?`, or an operator | ||
|
||
error: expected one of `,`, `.`, `?`, or an operator, found `some` | ||
--> $DIR/assert-trailing-junk.rs:12:18 | ||
| | ||
LL | assert!(true some extra junk); | ||
| ^^^^ expected one of `,`, `.`, `?`, or an operator | ||
|
||
error: no rules expected the token `blah` | ||
--> $DIR/assert-trailing-junk.rs:15:30 | ||
| | ||
LL | assert!(true, "whatever" blah); | ||
| -^^^^ no rules expected this token in macro call | ||
| | | ||
| help: missing comma here | ||
|
||
error: unexpected string literal | ||
--> $DIR/assert-trailing-junk.rs:18:18 | ||
| | ||
LL | assert!(true "whatever" blah); | ||
| -^^^^^^^^^^ | ||
| | | ||
| help: try adding a comma | ||
|
||
error: no rules expected the token `blah` | ||
--> $DIR/assert-trailing-junk.rs:18:29 | ||
| | ||
LL | assert!(true "whatever" blah); | ||
| -^^^^ no rules expected this token in macro call | ||
| | | ||
| help: missing comma here | ||
|
||
error: macro requires an expression as an argument | ||
--> $DIR/assert-trailing-junk.rs:22:5 | ||
| | ||
LL | assert!(true;); | ||
| ^^^^^^^^^^^^-^ | ||
| | | ||
| help: try removing semicolon | ||
|
||
error: unexpected string literal | ||
--> $DIR/assert-trailing-junk.rs:25:27 | ||
| | ||
LL | assert!(false || true "error message"); | ||
| -^^^^^^^^^^^^^^^ | ||
| | | ||
| help: try adding a comma | ||
|
||
error: aborting due to 7 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
src/test/ui/macros/assert.stderr → ...i/macros/assert.with-generic-asset.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
error: macro requires a boolean expression as an argument | ||
--> $DIR/assert.rs:5:5 | ||
| | ||
LL | assert!(); | ||
| ^^^^^^^^^ boolean expression required | ||
|
||
error: expected expression, found keyword `struct` | ||
--> $DIR/assert.rs:6:13 | ||
| | ||
LL | assert!(struct); | ||
| ^^^^^^ expected expression | ||
|
||
error: macro requires a boolean expression as an argument | ||
--> $DIR/assert.rs:7:5 | ||
| | ||
LL | debug_assert!(); | ||
| ^^^^^^^^^^^^^^^ boolean expression required | ||
| | ||
= note: this error originates in the macro `debug_assert` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: expected expression, found keyword `struct` | ||
--> $DIR/assert.rs:8:19 | ||
| | ||
LL | debug_assert!(struct); | ||
| ^^^^^^ expected expression | ||
|
||
error: aborting due to 4 previous errors | ||
|
188 changes: 188 additions & 0 deletions
188
src/test/ui/rfc-2011-nicer-assert-messages/all-expr-kinds.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
// aux-build:common.rs | ||
// edition:2021 | ||
// ignore-tidy-linelength | ||
// run-pass | ||
|
||
#![allow(path_statements, unused_allocation)] | ||
#![feature(box_syntax, core_intrinsics, generic_assert, generic_assert_internals)] | ||
|
||
extern crate common; | ||
|
||
// Use common::test once https://github.com/rust-lang/rust/issues/96997 is fixed | ||
macro_rules! test { | ||
( | ||
let mut $elem_ident:ident = $elem_expr:expr; | ||
[ $($assert:tt)* ] => $msg:literal | ||
) => { | ||
{ | ||
#[allow(unused_assignments, unused_mut, unused_variables)] | ||
let rslt = std::panic::catch_unwind(|| { | ||
let mut $elem_ident = $elem_expr; | ||
assert!($($assert)*); | ||
}); | ||
let err = rslt.unwrap_err(); | ||
if let Some(elem) = err.downcast_ref::<String>() { | ||
assert_eq!(elem, &$msg); | ||
} | ||
else if let Some(elem) = err.downcast_ref::<&str>() { | ||
assert_eq!(elem, &$msg); | ||
} | ||
else { | ||
panic!("assert!( ... ) should return a string"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
macro_rules! tests { | ||
( | ||
let mut $elem_ident:ident = $elem_expr:expr; | ||
|
||
$( | ||
[ $($elem_assert:tt)* ] => $elem_msg:literal | ||
)+ | ||
) => { | ||
$( | ||
test!( | ||
let mut $elem_ident = $elem_expr; | ||
[ $($elem_assert)* ] => $elem_msg | ||
); | ||
)+ | ||
} | ||
} | ||
|
||
const FOO: Foo = Foo { bar: 1 }; | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
struct Foo { | ||
bar: i32 | ||
} | ||
|
||
impl Foo { | ||
fn add(&self, a: i32, b: i32) -> i32 { a + b } | ||
} | ||
|
||
fn add(a: i32, b: i32) -> i32 { a + b } | ||
|
||
fn main() { | ||
// ***** Allowed ***** | ||
|
||
tests!( | ||
let mut elem = 1i32; | ||
|
||
// addr of | ||
[ &elem == &3 ] => "Assertion failed: &elem == &3\nWith captures:\n elem = 1\n" | ||
|
||
// array | ||
[ [elem][0] == 3 ] => "Assertion failed: [elem][0] == 3\nWith captures:\n elem = 1\n" | ||
|
||
// binary | ||
[ elem + 1 == 3 ] => "Assertion failed: elem + 1 == 3\nWith captures:\n elem = 1\n" | ||
|
||
// call | ||
[ add(elem, elem) == 3 ] => "Assertion failed: add(elem, elem) == 3\nWith captures:\n elem = 1\n" | ||
|
||
// cast | ||
[ elem as i32 == 3 ] => "Assertion failed: elem as i32 == 3\nWith captures:\n elem = 1\n" | ||
|
||
// index | ||
[ [1i32, 1][elem as usize] == 3 ] => "Assertion failed: [1i32, 1][elem as usize] == 3\nWith captures:\n elem = 1\n" | ||
|
||
// method call | ||
[ FOO.add(elem, elem) == 3 ] => "Assertion failed: FOO.add(elem, elem) == 3\nWith captures:\n elem = 1\n" | ||
|
||
// paren | ||
[ (elem) == 3 ] => "Assertion failed: (elem) == 3\nWith captures:\n elem = 1\n" | ||
|
||
// range | ||
[ (0..elem) == (0..3) ] => "Assertion failed: (0..elem) == (0..3)\nWith captures:\n elem = 1\n" | ||
|
||
// repeat | ||
[ [elem; 1] == [3; 1] ] => "Assertion failed: [elem; 1] == [3; 1]\nWith captures:\n elem = 1\n" | ||
|
||
// struct | ||
[ Foo { bar: elem } == Foo { bar: 3 } ] => "Assertion failed: Foo { bar: elem } == Foo { bar: 3 }\nWith captures:\n elem = 1\n" | ||
|
||
// tuple | ||
[ (elem, 1) == (3, 3) ] => "Assertion failed: (elem, 1) == (3, 3)\nWith captures:\n elem = 1\n" | ||
|
||
// unary | ||
[ -elem == -3 ] => "Assertion failed: -elem == -3\nWith captures:\n elem = 1\n" | ||
); | ||
|
||
// ***** Disallowed ***** | ||
|
||
tests!( | ||
let mut elem = 1i32; | ||
|
||
// assign | ||
[ { let local = elem; local } == 3 ] => "Assertion failed: { let local = elem; local } == 3" | ||
|
||
// assign op | ||
[ { elem += 1; elem } == 3 ] => "Assertion failed: { elem += 1; elem } == 3" | ||
|
||
// async | ||
[ { let _ = async { elem }; elem } == 3 ] => "Assertion failed: { let _ = async { elem }; elem } == 3" | ||
|
||
// await | ||
|
||
// block | ||
[ { elem } == 3 ] => "Assertion failed: { elem } == 3" | ||
|
||
// box | ||
[ box elem == box 3 ] => "Assertion failed: box elem == box 3" | ||
|
||
// break | ||
[ loop { break elem; } == 3 ] => "Assertion failed: loop { break elem; } == 3" | ||
|
||
// closure | ||
[(|| elem)() == 3 ] => "Assertion failed: (|| elem)() == 3" | ||
|
||
// const block | ||
|
||
// continue | ||
|
||
// err | ||
|
||
// field | ||
[ FOO.bar == 3 ] => "Assertion failed: FOO.bar == 3" | ||
|
||
// for loop | ||
[ { for _ in 0..elem { elem; } elem } == 3 ] => "Assertion failed: { for _ in 0..elem { elem; } elem } == 3" | ||
|
||
// if | ||
[ if true { elem } else { elem } == 3 ] => "Assertion failed: if true { elem } else { elem } == 3" | ||
|
||
// inline asm | ||
|
||
// let | ||
[ if let true = true { elem } else { elem } == 3 ] => "Assertion failed: if let true = true { elem } else { elem } == 3" | ||
|
||
// lit | ||
|
||
// loop | ||
[ loop { elem; break elem; } == 3 ] => "Assertion failed: loop { elem; break elem; } == 3" | ||
|
||
// mac call | ||
|
||
// match | ||
[ match elem { _ => elem } == 3 ] => "Assertion failed: match elem { _ => elem, } == 3" | ||
|
||
// ret | ||
[ (|| { return elem; })() == 3 ] => "Assertion failed: (|| { return elem; })() == 3" | ||
|
||
// try | ||
[ (|| { Some(Some(elem)?) })() == Some(3) ] => "Assertion failed: (|| { Some(Some(elem)?) })() == Some(3)" | ||
|
||
// try block | ||
|
||
// underscore | ||
|
||
// while | ||
[ { while false { elem; break; } elem } == 3 ] => "Assertion failed: { while false { elem; break; } elem } == 3" | ||
|
||
// yeet | ||
|
||
// yield | ||
); | ||
} |
Oops, something went wrong.