diff options
| author | hamidreza kalbasi <hamidrezakalbasi@protonmail.com> | 2021-05-09 05:26:59 +0430 |
|---|---|---|
| committer | hamidreza kalbasi <hamidrezakalbasi@protonmail.com> | 2021-05-09 05:26:59 +0430 |
| commit | efc8f65b852b7ce5203ce22f54066a0e647019a5 (patch) | |
| tree | 073ce7294f366fe7aaa88ecda18b4c97e3ff6851 /src/test/ui | |
| parent | 1773f14a24c49356b384e45ebb45643bc9bef2c4 (diff) | |
| download | rust-efc8f65b852b7ce5203ce22f54066a0e647019a5.tar.gz rust-efc8f65b852b7ce5203ce22f54066a0e647019a5.zip | |
Try to fix issue 68049
Diffstat (limited to 'src/test/ui')
| -rw-r--r-- | src/test/ui/suggestions/issue-68049-1.rs | 16 | ||||
| -rw-r--r-- | src/test/ui/suggestions/issue-68049-1.stderr | 9 | ||||
| -rw-r--r-- | src/test/ui/suggestions/issue-68049-2.rs | 21 | ||||
| -rw-r--r-- | src/test/ui/suggestions/issue-68049-2.stderr | 21 |
4 files changed, 67 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/issue-68049-1.rs b/src/test/ui/suggestions/issue-68049-1.rs new file mode 100644 index 00000000000..9b9ae429aeb --- /dev/null +++ b/src/test/ui/suggestions/issue-68049-1.rs @@ -0,0 +1,16 @@ +use std::alloc::{GlobalAlloc, Layout}; + +struct Test(u32); + +unsafe impl GlobalAlloc for Test { + unsafe fn alloc(&self, _layout: Layout) -> *mut u8 { + self.0 += 1; + 0 as *mut u8 + } + + unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) { + unimplemented!(); + } +} + +fn main() { } diff --git a/src/test/ui/suggestions/issue-68049-1.stderr b/src/test/ui/suggestions/issue-68049-1.stderr new file mode 100644 index 00000000000..32367d2d0cf --- /dev/null +++ b/src/test/ui/suggestions/issue-68049-1.stderr @@ -0,0 +1,9 @@ +error[E0594]: cannot assign to `self.0` which is behind a `&` reference + --> $DIR/issue-68049-1.rs:7:9 + | +LL | self.0 += 1; + | ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/suggestions/issue-68049-2.rs b/src/test/ui/suggestions/issue-68049-2.rs new file mode 100644 index 00000000000..22bb6b85d6f --- /dev/null +++ b/src/test/ui/suggestions/issue-68049-2.rs @@ -0,0 +1,21 @@ +trait Hello { + fn example(&self, input: &i32); // should suggest here +} + +struct Test1(i32); + +impl Hello for Test1 { + fn example(&self, input: &i32) { // should not suggest here + *input = self.0; + } +} + +struct Test2(i32); + +impl Hello for Test2 { + fn example(&self, input: &i32) { // should not suggest here + self.0 += *input; + } +} + +fn main() { } diff --git a/src/test/ui/suggestions/issue-68049-2.stderr b/src/test/ui/suggestions/issue-68049-2.stderr new file mode 100644 index 00000000000..f10a83c68a8 --- /dev/null +++ b/src/test/ui/suggestions/issue-68049-2.stderr @@ -0,0 +1,21 @@ +error[E0594]: cannot assign to `*input` which is behind a `&` reference + --> $DIR/issue-68049-2.rs:9:7 + | +LL | fn example(&self, input: &i32); // should suggest here + | ---- help: consider changing that to be a mutable reference: `&mut i32` +... +LL | *input = self.0; + | ^^^^^^^^^^^^^^^ `input` is a `&` reference, so the data it refers to cannot be written + +error[E0594]: cannot assign to `self.0` which is behind a `&` reference + --> $DIR/issue-68049-2.rs:17:5 + | +LL | fn example(&self, input: &i32); // should suggest here + | ----- help: consider changing that to be a mutable reference: `&mut self` +... +LL | self.0 += *input; + | ^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0594`. |
