From 4264548283dbaabb854e903994e4055215a956b8 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 15 Jul 2024 21:16:17 +0700 Subject: [PATCH] Add regression test for issue 13077 --- tests/ui/needless_option_as_deref.fixed | 14 ++++++++++++++ tests/ui/needless_option_as_deref.rs | 14 ++++++++++++++ tests/ui/needless_option_as_deref.stderr | 8 +++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/tests/ui/needless_option_as_deref.fixed b/tests/ui/needless_option_as_deref.fixed index 58f56eba0f5..7bde155582b 100644 --- a/tests/ui/needless_option_as_deref.fixed +++ b/tests/ui/needless_option_as_deref.fixed @@ -52,3 +52,17 @@ struct S<'a> { fn from_field<'a>(s: &'a mut S<'a>) -> Option<&'a mut usize> { s.opt.as_deref_mut() } + +mod issue_non_copy_13077 { + pub fn something(mut maybe_side_effect: Option<&mut String>) { + for _ in 0..10 { + let _ = S { field: other(maybe_side_effect) }; + } + } + + fn other(_maybe_side_effect: Option<&mut String>) { + unimplemented!() + } + + pub struct S { pub field: () } +} diff --git a/tests/ui/needless_option_as_deref.rs b/tests/ui/needless_option_as_deref.rs index 842e025f669..ab06a38f742 100644 --- a/tests/ui/needless_option_as_deref.rs +++ b/tests/ui/needless_option_as_deref.rs @@ -52,3 +52,17 @@ struct S<'a> { fn from_field<'a>(s: &'a mut S<'a>) -> Option<&'a mut usize> { s.opt.as_deref_mut() } + +mod issue_non_copy_13077 { + pub fn something(mut maybe_side_effect: Option<&mut String>) { + for _ in 0..10 { + let _ = S { field: other(maybe_side_effect.as_deref_mut()) }; + } + } + + fn other(_maybe_side_effect: Option<&mut String>) { + unimplemented!() + } + + pub struct S { pub field: () } +} diff --git a/tests/ui/needless_option_as_deref.stderr b/tests/ui/needless_option_as_deref.stderr index a05d0aa9276..3211062af91 100644 --- a/tests/ui/needless_option_as_deref.stderr +++ b/tests/ui/needless_option_as_deref.stderr @@ -19,5 +19,11 @@ error: derefed type is same as origin LL | let _ = x.as_deref_mut(); | ^^^^^^^^^^^^^^^^ help: try: `x` -error: aborting due to 3 previous errors +error: derefed type is same as origin + --> tests/ui/needless_option_as_deref.rs:59:38 + | +LL | let _ = S { field: other(maybe_side_effect.as_deref_mut()) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `maybe_side_effect` + +error: aborting due to 4 previous errors