mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-02 10:18:25 +00:00
Stop dbg! macro yapping about format modifiers
This commit is contained in:
parent
b1d18129d1
commit
29ce695cd4
@ -363,7 +363,14 @@ macro_rules! dbg {
|
||||
match $val {
|
||||
tmp => {
|
||||
$crate::eprintln!("[{}:{}:{}] {} = {:#?}",
|
||||
$crate::file!(), $crate::line!(), $crate::column!(), $crate::stringify!($val), &tmp);
|
||||
$crate::file!(),
|
||||
$crate::line!(),
|
||||
$crate::column!(),
|
||||
$crate::stringify!($val),
|
||||
// The `&T: Debug` check happens here (not in the format literal desugaring)
|
||||
// to avoid format literal related messages and suggestions.
|
||||
&&tmp as &dyn $crate::fmt::Debug,
|
||||
);
|
||||
tmp
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,10 @@ error[E0277]: `Dummy` doesn't implement `Debug`
|
||||
--> $DIR/issue-107649.rs:105:5
|
||||
|
|
||||
105 | dbg!(lib::Dummy);
|
||||
| ^^^^^^^^^^^^^^^^ `Dummy` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
||||
| ^^^^^^^^^^^^^^^^ the trait `Debug` is not implemented for `Dummy`
|
||||
|
|
||||
= help: the trait `Debug` is not implemented for `Dummy`
|
||||
= note: add `#[derive(Debug)]` to `Dummy` or manually `impl Debug for Dummy`
|
||||
= note: required for `&Dummy` to implement `Debug`
|
||||
= 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)
|
||||
= note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: consider annotating `Dummy` with `#[derive(Debug)]`
|
||||
--> $DIR/auxiliary/dummy_lib.rs:2:1
|
||||
|
|
||||
|
17
tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-ref-impl.rs
Normal file
17
tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-ref-impl.rs
Normal file
@ -0,0 +1,17 @@
|
||||
/// Check that only `&X: Debug` is required, not `X: Debug`
|
||||
//@check-pass
|
||||
|
||||
use std::fmt::Debug;
|
||||
use std::fmt::Formatter;
|
||||
|
||||
struct X;
|
||||
|
||||
impl Debug for &X {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
f.write_str("X")
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
dbg!(X);
|
||||
}
|
@ -1,4 +1,7 @@
|
||||
// Test ensuring that `dbg!(expr)` requires the passed type to implement `Debug`.
|
||||
//
|
||||
// `dbg!` shouldn't tell the user about format literal syntax; the user didn't write one.
|
||||
//@ forbid-output: cannot be formatted using
|
||||
|
||||
struct NotDebug;
|
||||
|
||||
|
@ -1,13 +1,11 @@
|
||||
error[E0277]: `NotDebug` doesn't implement `Debug`
|
||||
--> $DIR/dbg-macro-requires-debug.rs:6:23
|
||||
--> $DIR/dbg-macro-requires-debug.rs:9:23
|
||||
|
|
||||
LL | let _: NotDebug = dbg!(NotDebug);
|
||||
| ^^^^^^^^^^^^^^ `NotDebug` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
||||
| ^^^^^^^^^^^^^^ the trait `Debug` is not implemented for `NotDebug`
|
||||
|
|
||||
= help: the trait `Debug` is not implemented for `NotDebug`
|
||||
= note: add `#[derive(Debug)]` to `NotDebug` or manually `impl Debug for NotDebug`
|
||||
= note: required for `&NotDebug` to implement `Debug`
|
||||
= 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)
|
||||
= note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: consider annotating `NotDebug` with `#[derive(Debug)]`
|
||||
|
|
||||
LL + #[derive(Debug)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user