summaryrefslogtreecommitdiffstats
path: root/tests/ui/rfcs/rfc-2361-dbg-macro
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /tests/ui/rfcs/rfc-2361-dbg-macro
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/rfcs/rfc-2361-dbg-macro')
-rw-r--r--tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs69
-rw-r--r--tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-expected-behavior.run.stderr28
-rw-r--r--tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-move-semantics.rs10
-rw-r--r--tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-move-semantics.stderr14
-rw-r--r--tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-requires-debug.rs7
-rw-r--r--tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-requires-debug.stderr18
6 files changed, 146 insertions, 0 deletions
diff --git a/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs b/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs
new file mode 100644
index 000000000..542be3942
--- /dev/null
+++ b/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs
@@ -0,0 +1,69 @@
+// 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.
+
+#![allow(dropping_copy_types)]
+
+#[derive(Copy, Clone, Debug)]
+struct Unit;
+
+#[derive(Copy, Clone, Debug, PartialEq)]
+struct Point<T> {
+ 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<T>` will be faithfully formatted according to `{:#?}`.
+ let a = Point { x: 42, y: 24 };
+ let b: Point<u8> = dbg!(Point { x: 42, y: 24 }); // test stringify!(..)
+ let c: Point<u8> = 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/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-expected-behavior.run.stderr b/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-expected-behavior.run.stderr
new file mode 100644
index 000000000..a20a6062c
--- /dev/null
+++ b/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-expected-behavior.run.stderr
@@ -0,0 +1,28 @@
+[$DIR/dbg-macro-expected-behavior.rs:22] Unit = Unit
+[$DIR/dbg-macro-expected-behavior.rs:23] a = Unit
+[$DIR/dbg-macro-expected-behavior.rs:29] Point { x: 42, y: 24 } = Point {
+ x: 42,
+ y: 24,
+}
+[$DIR/dbg-macro-expected-behavior.rs:30] b = Point {
+ x: 42,
+ y: 24,
+}
+[$DIR/dbg-macro-expected-behavior.rs:38]
+[$DIR/dbg-macro-expected-behavior.rs:42] &a = NoCopy(
+ 1337,
+)
+[$DIR/dbg-macro-expected-behavior.rs:42] dbg!(& a) = NoCopy(
+ 1337,
+)
+[$DIR/dbg-macro-expected-behavior.rs:47] f(&42) = 42
+before
+[$DIR/dbg-macro-expected-behavior.rs:52] { foo += 1; eprintln!("before"); 7331 } = 7331
+[$DIR/dbg-macro-expected-behavior.rs:60] ("Yeah",) = (
+ "Yeah",
+)
+[$DIR/dbg-macro-expected-behavior.rs:63] 1 = 1
+[$DIR/dbg-macro-expected-behavior.rs:63] 2 = 2
+[$DIR/dbg-macro-expected-behavior.rs:67] 1u8 = 1
+[$DIR/dbg-macro-expected-behavior.rs:67] 2u32 = 2
+[$DIR/dbg-macro-expected-behavior.rs:67] "Yeah" = "Yeah"
diff --git a/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-move-semantics.rs b/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-move-semantics.rs
new file mode 100644
index 000000000..9f3c567b6
--- /dev/null
+++ b/tests/ui/rfcs/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/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-move-semantics.stderr b/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-move-semantics.stderr
new file mode 100644
index 000000000..e97fdcce1
--- /dev/null
+++ b/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-move-semantics.stderr
@@ -0,0 +1,14 @@
+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/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-requires-debug.rs b/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-requires-debug.rs
new file mode 100644
index 000000000..f2fb62d76
--- /dev/null
+++ b/tests/ui/rfcs/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/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-requires-debug.stderr b/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-requires-debug.stderr
new file mode 100644
index 000000000..ce165e646
--- /dev/null
+++ b/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-requires-debug.stderr
@@ -0,0 +1,18 @@
+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)]
+LL | struct NotDebug;
+ |
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.