Skip to content

Commit 884dd8c

Browse files
committed
Auto merge of rust-lang#14788 - HKalbasi:derive-impl-f, r=Veykril
Use double reference in debug derive fix rust-lang#14768
2 parents 9b33874 + 7da80d4 commit 884dd8c

File tree

4 files changed

+91
-8
lines changed

4 files changed

+91
-8
lines changed

crates/hir-def/src/macro_expansion_tests/builtin_derive_macro.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ impl < > core::fmt::Debug for Command< > where {
387387
Command::Move {
388388
x: x, y: y,
389389
}
390-
=>f.debug_struct("Move").field("x", x).field("y", y).finish(), Command::Do(f0, )=>f.debug_tuple("Do").field(f0).finish(), Command::Jump=>f.write_str("Jump"),
390+
=>f.debug_struct("Move").field("x", &x).field("y", &y).finish(), Command::Do(f0, )=>f.debug_tuple("Do").field(&f0).finish(), Command::Jump=>f.write_str("Jump"),
391391
}
392392
}
393393
}"#]],

crates/hir-expand/src/builtin_derive_macro.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ fn debug_expand(
519519
let for_fields = fields.iter().map(|x| {
520520
let x_string = x.to_string();
521521
quote! {
522-
.field(#x_string, #x)
522+
.field(#x_string, & #x)
523523
}
524524
});
525525
quote! {
@@ -529,7 +529,7 @@ fn debug_expand(
529529
VariantShape::Tuple(n) => {
530530
let for_fields = tuple_field_iterator(*n).map(|x| {
531531
quote! {
532-
.field(#x)
532+
.field( & #x)
533533
}
534534
});
535535
quote! {

crates/ide-diagnostics/src/handlers/type_mismatch.rs

+20
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,26 @@ fn f() {
658658
//^ error: expected (), found i32
659659
}
660660
}
661+
"#,
662+
);
663+
}
664+
665+
#[test]
666+
fn regression_14768() {
667+
check_diagnostics(
668+
r#"
669+
//- minicore: derive, fmt, slice, coerce_unsized, builtin_impls
670+
use core::fmt::Debug;
671+
672+
#[derive(Debug)]
673+
struct Foo(u8, u16, [u8]);
674+
675+
#[derive(Debug)]
676+
struct Bar {
677+
f1: u8,
678+
f2: &[u16],
679+
f3: dyn Debug,
680+
}
661681
"#,
662682
);
663683
}

crates/test-utils/src/minicore.rs

+68-5
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,38 @@ pub mod fmt {
766766
pub struct Error;
767767
pub type Result = Result<(), Error>;
768768
pub struct Formatter<'a>;
769+
pub struct DebugTuple;
770+
pub struct DebugStruct;
771+
impl Formatter<'_> {
772+
pub fn debug_tuple(&mut self, name: &str) -> DebugTuple {
773+
DebugTuple
774+
}
775+
776+
pub fn debug_struct(&mut self, name: &str) -> DebugStruct {
777+
DebugStruct
778+
}
779+
}
780+
781+
impl DebugTuple {
782+
pub fn field(&mut self, value: &dyn Debug) -> &mut Self {
783+
self
784+
}
785+
786+
pub fn finish(&mut self) -> Result {
787+
Ok(())
788+
}
789+
}
790+
791+
impl DebugStruct {
792+
pub fn field(&mut self, name: &str, value: &dyn Debug) -> &mut Self {
793+
self
794+
}
795+
796+
pub fn finish(&mut self) -> Result {
797+
Ok(())
798+
}
799+
}
800+
769801
pub trait Debug {
770802
fn fmt(&self, f: &mut Formatter<'_>) -> Result;
771803
}
@@ -777,6 +809,39 @@ pub mod fmt {
777809
#[rustc_builtin_macro]
778810
pub macro Debug($item:item) {}
779811
// endregion:derive
812+
813+
// region:builtin_impls
814+
macro_rules! impl_debug {
815+
($($t:ty)*) => {
816+
$(
817+
impl const Debug for $t {
818+
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
819+
Ok(())
820+
}
821+
}
822+
)*
823+
}
824+
}
825+
826+
impl_debug! {
827+
usize u8 u16 u32 u64 u128
828+
isize i8 i16 i32 i64 i128
829+
f32 f64
830+
bool char
831+
}
832+
833+
impl<T: Debug> Debug for [T] {
834+
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
835+
Ok(())
836+
}
837+
}
838+
839+
impl<T: Debug + ?Sized> Debug for &T {
840+
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
841+
(&**self).fmt(f)
842+
}
843+
}
844+
// endregion:builtin_impls
780845
}
781846
// endregion:fmt
782847

@@ -1075,10 +1140,8 @@ pub mod iter {
10751140

10761141
// region:panic
10771142
mod panic {
1078-
pub macro panic_2021 {
1079-
($($t:tt)+) => (
1080-
/* Nothing yet */
1081-
),
1143+
pub macro panic_2021($($t:tt)+) {
1144+
/* Nothing yet */
10821145
}
10831146
}
10841147
// endregion:panic
@@ -1158,8 +1221,8 @@ pub mod prelude {
11581221
ops::Drop, // :drop
11591222
ops::{Fn, FnMut, FnOnce}, // :fn
11601223
option::Option::{self, None, Some}, // :option
1161-
result::Result::{self, Err, Ok}, // :result
11621224
panic, // :panic
1225+
result::Result::{self, Err, Ok}, // :result
11631226
};
11641227
}
11651228

0 commit comments

Comments
 (0)