File tree 2 files changed +15
-4
lines changed
test/ui/rfc-2361-dbg-macro
2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -305,10 +305,16 @@ macro_rules! eprintln {
305
305
/// let _ = dbg!(a); // <-- `a` is moved again; error!
306
306
/// ```
307
307
///
308
+ /// You can also use `dbg!()` without a value to just print the
309
+ /// file and line whenever it's reached.
310
+ ///
308
311
/// [stderr]: https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)
309
312
#[ macro_export]
310
313
#[ stable( feature = "dbg_macro" , since = "1.32.0" ) ]
311
314
macro_rules! dbg {
315
+ ( ) => {
316
+ eprintln!( "[{}:{}]" , file!( ) , line!( ) ) ;
317
+ } ;
312
318
( $val: expr) => {
313
319
// Use of `match` here is intentional because it affects the lifetimes
314
320
// of temporaries - https://stackoverflow.com/a/48732525/1063961
Original file line number Diff line number Diff line change @@ -33,6 +33,9 @@ fn test() {
33
33
// We can move `b` because it's Copy.
34
34
drop ( b) ;
35
35
36
+ // Without parameters works as expected.
37
+ let _: ( ) = dbg ! ( ) ;
38
+
36
39
// Test that we can borrow and that successive applications is still identity.
37
40
let a = NoCopy ( 1337 ) ;
38
41
let b: & NoCopy = dbg ! ( dbg!( & a) ) ;
@@ -69,17 +72,19 @@ fn validate_stderr(stderr: Vec<String>) {
69
72
" y: 24" ,
70
73
"}" ,
71
74
72
- ":38] &a = NoCopy(" ,
75
+ ":37]" ,
76
+
77
+ ":41] &a = NoCopy(" ,
73
78
" 1337" ,
74
79
")" ,
75
80
76
- ":38 ] dbg!(& a) = NoCopy(" ,
81
+ ":41 ] dbg!(& a) = NoCopy(" ,
77
82
" 1337" ,
78
83
")" ,
79
- ":43 ] f(&42) = 42" ,
84
+ ":46 ] f(&42) = 42" ,
80
85
81
86
"before" ,
82
- ":48 ] { foo += 1; eprintln!(\" before\" ); 7331 } = 7331" ,
87
+ ":51 ] { foo += 1; eprintln!(\" before\" ); 7331 } = 7331" ,
83
88
] ) ;
84
89
}
85
90
You can’t perform that action at this time.
0 commit comments