Skip to content

Commit cbb81bd

Browse files
committed
dbg_macro: feature gate + move semantics test.
1 parent 000be8f commit cbb81bd

5 files changed

+89
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Feature gate test for `dbg!(..)`.
2+
3+
fn main() {
4+
dbg!(1);
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0658]: macro dbg! is unstable (see issue #54306)
2+
--> $DIR/dbg-macro-feature-gate.rs:4:5
3+
|
4+
LL | dbg!(1);
5+
| ^^^^^^^^
6+
|
7+
= help: add #![feature(dbg_macro)] to the crate attributes to enable
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0658`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
error[E0382]: use of moved value: `a`
2+
--> $DIR/dbg-macro-move-semantics.rs:11:18
3+
|
4+
LL | let _ = dbg!(a);
5+
| ------- value moved here
6+
LL | let _ = dbg!(a);
7+
| ^ value used here after move
8+
|
9+
= note: move occurs because `a` has type `NoCopy`, which does not implement the `Copy` trait
10+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
11+
12+
error[E0382]: borrow of moved value: `a`
13+
--> $DIR/dbg-macro-move-semantics.rs:11:18
14+
|
15+
LL | let _ = dbg!(a);
16+
| ------- value moved here
17+
LL | let _ = dbg!(a);
18+
| ^ value borrowed here after move
19+
|
20+
= note: move occurs because `a` has type `NoCopy`, which does not implement the `Copy` trait
21+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
22+
23+
error[E0382]: use of moved value: `a`
24+
--> $DIR/dbg-macro-move-semantics.rs:11:13
25+
|
26+
LL | let _ = dbg!(a);
27+
| ------- value moved here
28+
LL | let _ = dbg!(a);
29+
| ^^^^^^^ value used here after move
30+
|
31+
= note: move occurs because `a` has type `NoCopy`, which does not implement the `Copy` trait
32+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
33+
34+
error: aborting due to 3 previous errors
35+
36+
For more information about this error, try `rustc --explain E0382`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Test ensuring that `dbg!(expr)` will take ownership of the argument.
2+
3+
#![feature(dbg_macro)]
4+
5+
#[derive(Debug)]
6+
struct NoCopy(usize);
7+
8+
fn main() {
9+
let a = NoCopy(0);
10+
let _ = dbg!(a);
11+
let _ = dbg!(a);
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0382]: use of moved value: `a`
2+
--> $DIR/dbg-macro-move-semantics.rs:11:18
3+
|
4+
LL | let _ = dbg!(a);
5+
| ------- value moved here
6+
LL | let _ = dbg!(a);
7+
| ^ value used here after move
8+
|
9+
= note: move occurs because `a` has type `NoCopy`, which does not implement the `Copy` trait
10+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
11+
12+
error[E0382]: use of moved value: `a`
13+
--> $DIR/dbg-macro-move-semantics.rs:11:13
14+
|
15+
LL | let _ = dbg!(a);
16+
| ------- value moved here
17+
LL | let _ = dbg!(a);
18+
| ^^^^^^^ value used here after move
19+
|
20+
= note: move occurs because `a` has type `NoCopy`, which does not implement the `Copy` trait
21+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
22+
23+
error: aborting due to 2 previous errors
24+
25+
For more information about this error, try `rustc --explain E0382`.

0 commit comments

Comments
 (0)