diff options
| author | Caio <c410.f3r@gmail.com> | 2024-04-21 15:43:43 -0300 |
|---|---|---|
| committer | Caio <c410.f3r@gmail.com> | 2024-04-21 15:43:43 -0300 |
| commit | 3aaa3941fd62fb4aeea559eafe8a6aa6472eb87d (patch) | |
| tree | 370d74ef8239f923cae41848afd9e71648850de3 /tests/ui/coercion | |
| parent | fecb7b43093e4fa59e2d366e88bf0085ce350f29 (diff) | |
| download | rust-3aaa3941fd62fb4aeea559eafe8a6aa6472eb87d.tar.gz rust-3aaa3941fd62fb4aeea559eafe8a6aa6472eb87d.zip | |
Move some tests
Diffstat (limited to 'tests/ui/coercion')
| -rw-r--r-- | tests/ui/coercion/issue-32122-1.fixed | 17 | ||||
| -rw-r--r-- | tests/ui/coercion/issue-32122-1.rs | 17 | ||||
| -rw-r--r-- | tests/ui/coercion/issue-32122-1.stderr | 18 | ||||
| -rw-r--r-- | tests/ui/coercion/issue-32122-2.fixed | 28 | ||||
| -rw-r--r-- | tests/ui/coercion/issue-32122-2.rs | 28 | ||||
| -rw-r--r-- | tests/ui/coercion/issue-32122-2.stderr | 18 |
6 files changed, 126 insertions, 0 deletions
diff --git a/tests/ui/coercion/issue-32122-1.fixed b/tests/ui/coercion/issue-32122-1.fixed new file mode 100644 index 00000000000..abcef9fcbd9 --- /dev/null +++ b/tests/ui/coercion/issue-32122-1.fixed @@ -0,0 +1,17 @@ +//@ run-rustfix +use std::ops::Deref; + +struct Foo(u8); + +impl Deref for Foo { + type Target = u8; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +fn main() { + let a = Foo(0); + // Should suggest `&*` when coercing &ty to *const ty + let _: *const u8 = &*a; //~ ERROR mismatched types +} diff --git a/tests/ui/coercion/issue-32122-1.rs b/tests/ui/coercion/issue-32122-1.rs new file mode 100644 index 00000000000..920ec348419 --- /dev/null +++ b/tests/ui/coercion/issue-32122-1.rs @@ -0,0 +1,17 @@ +//@ run-rustfix +use std::ops::Deref; + +struct Foo(u8); + +impl Deref for Foo { + type Target = u8; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +fn main() { + let a = Foo(0); + // Should suggest `&*` when coercing &ty to *const ty + let _: *const u8 = &a; //~ ERROR mismatched types +} diff --git a/tests/ui/coercion/issue-32122-1.stderr b/tests/ui/coercion/issue-32122-1.stderr new file mode 100644 index 00000000000..ae5dffe1fad --- /dev/null +++ b/tests/ui/coercion/issue-32122-1.stderr @@ -0,0 +1,18 @@ +error[E0308]: mismatched types + --> $DIR/issue-32122-1.rs:16:24 + | +LL | let _: *const u8 = &a; + | --------- ^^ expected `*const u8`, found `&Foo` + | | + | expected due to this + | + = note: expected raw pointer `*const u8` + found reference `&Foo` +help: consider dereferencing + | +LL | let _: *const u8 = &*a; + | + + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/coercion/issue-32122-2.fixed b/tests/ui/coercion/issue-32122-2.fixed new file mode 100644 index 00000000000..db406a4c3ac --- /dev/null +++ b/tests/ui/coercion/issue-32122-2.fixed @@ -0,0 +1,28 @@ +//@ run-rustfix +use std::ops::Deref; +struct Bar(u8); +struct Foo(Bar); +struct Emm(Foo); +impl Deref for Bar{ + type Target = u8; + fn deref(&self) -> &Self::Target { + &self.0 + } +} +impl Deref for Foo { + type Target = Bar; + fn deref(&self) -> &Self::Target { + &self.0 + } +} +impl Deref for Emm { + type Target = Foo; + fn deref(&self) -> &Self::Target { + &self.0 + } +} +fn main() { + let a = Emm(Foo(Bar(0))); + // Should suggest `&***` even when deref is pretty deep + let _: *const u8 = &***a; //~ ERROR mismatched types +} diff --git a/tests/ui/coercion/issue-32122-2.rs b/tests/ui/coercion/issue-32122-2.rs new file mode 100644 index 00000000000..74242931b4e --- /dev/null +++ b/tests/ui/coercion/issue-32122-2.rs @@ -0,0 +1,28 @@ +//@ run-rustfix +use std::ops::Deref; +struct Bar(u8); +struct Foo(Bar); +struct Emm(Foo); +impl Deref for Bar{ + type Target = u8; + fn deref(&self) -> &Self::Target { + &self.0 + } +} +impl Deref for Foo { + type Target = Bar; + fn deref(&self) -> &Self::Target { + &self.0 + } +} +impl Deref for Emm { + type Target = Foo; + fn deref(&self) -> &Self::Target { + &self.0 + } +} +fn main() { + let a = Emm(Foo(Bar(0))); + // Should suggest `&***` even when deref is pretty deep + let _: *const u8 = &a; //~ ERROR mismatched types +} diff --git a/tests/ui/coercion/issue-32122-2.stderr b/tests/ui/coercion/issue-32122-2.stderr new file mode 100644 index 00000000000..eb4327bef62 --- /dev/null +++ b/tests/ui/coercion/issue-32122-2.stderr @@ -0,0 +1,18 @@ +error[E0308]: mismatched types + --> $DIR/issue-32122-2.rs:27:24 + | +LL | let _: *const u8 = &a; + | --------- ^^ expected `*const u8`, found `&Emm` + | | + | expected due to this + | + = note: expected raw pointer `*const u8` + found reference `&Emm` +help: consider dereferencing + | +LL | let _: *const u8 = &***a; + | +++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. |
