From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../dbg-macro-expected-behavior.rs | 67 ++++++++++++++++++++++ .../dbg-macro-expected-behavior.run.stderr | 28 +++++++++ .../rfc-2361-dbg-macro/dbg-macro-move-semantics.rs | 10 ++++ .../dbg-macro-move-semantics.stderr | 13 +++++ .../rfc-2361-dbg-macro/dbg-macro-requires-debug.rs | 7 +++ .../dbg-macro-requires-debug.stderr | 17 ++++++ 6 files changed, 142 insertions(+) create mode 100644 src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs create mode 100644 src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.run.stderr create mode 100644 src/test/ui/rfc-2361-dbg-macro/dbg-macro-move-semantics.rs create mode 100644 src/test/ui/rfc-2361-dbg-macro/dbg-macro-move-semantics.stderr create mode 100644 src/test/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.rs create mode 100644 src/test/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.stderr (limited to 'src/test/ui/rfc-2361-dbg-macro') diff --git a/src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs new file mode 100644 index 000000000..04d924a9a --- /dev/null +++ b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs @@ -0,0 +1,67 @@ +// run-pass +// check-run-results + +// Tests ensuring that `dbg!(expr)` has the expected run-time behavior. +// as well as some compile time properties we expect. + +#[derive(Copy, Clone, Debug)] +struct Unit; + +#[derive(Copy, Clone, Debug, PartialEq)] +struct Point { + x: T, + y: T, +} + +#[derive(Debug, PartialEq)] +struct NoCopy(usize); + +fn main() { + let a: Unit = dbg!(Unit); + let _: Unit = dbg!(a); + // We can move `a` because it's Copy. + drop(a); + + // `Point` will be faithfully formatted according to `{:#?}`. + let a = Point { x: 42, y: 24 }; + let b: Point = dbg!(Point { x: 42, y: 24 }); // test stringify!(..) + let c: Point = dbg!(b); + // Identity conversion: + assert_eq!(a, b); + assert_eq!(a, c); + // We can move `b` because it's Copy. + drop(b); + + // Without parameters works as expected. + let _: () = dbg!(); + + // Test that we can borrow and that successive applications is still identity. + let a = NoCopy(1337); + let b: &NoCopy = dbg!(dbg!(&a)); + assert_eq!(&a, b); + + // Test involving lifetimes of temporaries: + fn f<'a>(x: &'a u8) -> &'a u8 { x } + let a: &u8 = dbg!(f(&42)); + assert_eq!(a, &42); + + // Test side effects: + let mut foo = 41; + assert_eq!(7331, dbg!({ + foo += 1; + eprintln!("before"); + 7331 + })); + assert_eq!(foo, 42); + + // Test trailing comma: + assert_eq!(("Yeah",), dbg!(("Yeah",))); + + // Test multiple arguments: + assert_eq!((1u8, 2u32), dbg!(1, + 2)); + + // Test multiple arguments + trailing comma: + assert_eq!((1u8, 2u32, "Yeah"), dbg!(1u8, 2u32, + "Yeah",)); +} diff --git a/src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.run.stderr b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.run.stderr new file mode 100644 index 000000000..49d72158e --- /dev/null +++ b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.run.stderr @@ -0,0 +1,28 @@ +[$DIR/dbg-macro-expected-behavior.rs:20] Unit = Unit +[$DIR/dbg-macro-expected-behavior.rs:21] a = Unit +[$DIR/dbg-macro-expected-behavior.rs:27] Point { x: 42, y: 24 } = Point { + x: 42, + y: 24, +} +[$DIR/dbg-macro-expected-behavior.rs:28] b = Point { + x: 42, + y: 24, +} +[$DIR/dbg-macro-expected-behavior.rs:36] +[$DIR/dbg-macro-expected-behavior.rs:40] &a = NoCopy( + 1337, +) +[$DIR/dbg-macro-expected-behavior.rs:40] dbg!(& a) = NoCopy( + 1337, +) +[$DIR/dbg-macro-expected-behavior.rs:45] f(&42) = 42 +before +[$DIR/dbg-macro-expected-behavior.rs:50] { foo += 1; eprintln!("before"); 7331 } = 7331 +[$DIR/dbg-macro-expected-behavior.rs:58] ("Yeah",) = ( + "Yeah", +) +[$DIR/dbg-macro-expected-behavior.rs:61] 1 = 1 +[$DIR/dbg-macro-expected-behavior.rs:61] 2 = 2 +[$DIR/dbg-macro-expected-behavior.rs:65] 1u8 = 1 +[$DIR/dbg-macro-expected-behavior.rs:65] 2u32 = 2 +[$DIR/dbg-macro-expected-behavior.rs:65] "Yeah" = "Yeah" diff --git a/src/test/ui/rfc-2361-dbg-macro/dbg-macro-move-semantics.rs b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-move-semantics.rs new file mode 100644 index 000000000..9f3c567b6 --- /dev/null +++ b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-move-semantics.rs @@ -0,0 +1,10 @@ +// Test ensuring that `dbg!(expr)` will take ownership of the argument. + +#[derive(Debug)] +struct NoCopy(usize); + +fn main() { + let a = NoCopy(0); + let _ = dbg!(a); + let _ = dbg!(a); //~ ERROR use of moved value +} diff --git a/src/test/ui/rfc-2361-dbg-macro/dbg-macro-move-semantics.stderr b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-move-semantics.stderr new file mode 100644 index 000000000..5611b5f4e --- /dev/null +++ b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-move-semantics.stderr @@ -0,0 +1,13 @@ +error[E0382]: use of moved value: `a` + --> $DIR/dbg-macro-move-semantics.rs:9:18 + | +LL | let a = NoCopy(0); + | - move occurs because `a` has type `NoCopy`, which does not implement the `Copy` trait +LL | let _ = dbg!(a); + | ------- value moved here +LL | let _ = dbg!(a); + | ^ value used here after move + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0382`. diff --git a/src/test/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.rs b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.rs new file mode 100644 index 000000000..f2fb62d76 --- /dev/null +++ b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.rs @@ -0,0 +1,7 @@ +// Test ensuring that `dbg!(expr)` requires the passed type to implement `Debug`. + +struct NotDebug; + +fn main() { + let _: NotDebug = dbg!(NotDebug); //~ ERROR `NotDebug` doesn't implement `Debug` +} diff --git a/src/test/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.stderr b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.stderr new file mode 100644 index 000000000..d8b5a9e63 --- /dev/null +++ b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.stderr @@ -0,0 +1,17 @@ +error[E0277]: `NotDebug` doesn't implement `Debug` + --> $DIR/dbg-macro-requires-debug.rs:6:23 + | +LL | let _: NotDebug = dbg!(NotDebug); + | ^^^^^^^^^^^^^^ `NotDebug` cannot be formatted using `{:?}` + | + = help: the trait `Debug` is not implemented for `NotDebug` + = note: add `#[derive(Debug)]` to `NotDebug` or manually `impl Debug for NotDebug` + = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `NotDebug` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. -- cgit v1.2.3