Skip to content

Commit 7b76b94

Browse files
committed
add test 12969 and 9841
1 parent 0ce07f6 commit 7b76b94

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

tests/ui/explicit_auto_deref.fixed

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,35 @@ fn main() {
345345
let _ = &mut ({ *x.u }).x;
346346
}
347347
}
348+
349+
mod issue_12969 {
350+
use std::ops::Deref;
351+
352+
struct Wrapper<T>(T);
353+
354+
impl<T> Deref for Wrapper<T> {
355+
type Target = T;
356+
357+
fn deref(&self) -> &T {
358+
&self.0
359+
}
360+
}
361+
362+
fn foo(_bar: &str) {}
363+
364+
fn bar() {
365+
let wrapped_bar = Wrapper("");
366+
367+
foo(wrapped_bar);
368+
}
369+
}
370+
371+
mod issue_9841 {
372+
fn takes_array_ref<T, const N: usize>(array: &&[T; N]) {
373+
takes_slice(array)
374+
}
375+
376+
fn takes_slice<T>(slice: &[T]) {
377+
todo!()
378+
}
379+
}

tests/ui/explicit_auto_deref.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,35 @@ fn main() {
345345
let _ = &mut ({ *x.u }).x;
346346
}
347347
}
348+
349+
mod issue_12969 {
350+
use std::ops::Deref;
351+
352+
struct Wrapper<T>(T);
353+
354+
impl<T> Deref for Wrapper<T> {
355+
type Target = T;
356+
357+
fn deref(&self) -> &T {
358+
&self.0
359+
}
360+
}
361+
362+
fn foo(_bar: &str) {}
363+
364+
fn bar() {
365+
let wrapped_bar = Wrapper("");
366+
367+
foo(&*wrapped_bar);
368+
}
369+
}
370+
371+
mod issue_9841 {
372+
fn takes_array_ref<T, const N: usize>(array: &&[T; N]) {
373+
takes_slice(*array)
374+
}
375+
376+
fn takes_slice<T>(slice: &[T]) {
377+
todo!()
378+
}
379+
}

tests/ui/explicit_auto_deref.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,5 +271,17 @@ error: deref which would be done by auto-deref
271271
LL | let _ = &mut (*{ x.u }).x;
272272
| ^^^^^^^^^^ help: try: `{ x.u }`
273273

274-
error: aborting due to 45 previous errors
274+
error: deref which would be done by auto-deref
275+
--> tests/ui/explicit_auto_deref.rs:367:13
276+
|
277+
LL | foo(&*wrapped_bar);
278+
| ^^^^^^^^^^^^^ help: try: `wrapped_bar`
279+
280+
error: deref which would be done by auto-deref
281+
--> tests/ui/explicit_auto_deref.rs:373:21
282+
|
283+
LL | takes_slice(*array)
284+
| ^^^^^^ help: try: `array`
285+
286+
error: aborting due to 47 previous errors
275287

0 commit comments

Comments
 (0)