forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#85100 - HKalbasi:issue-68049-fix, r=Aaron1011
Fix invalid suggestion of changing impl trait signature Fix rust-lang#68049
- Loading branch information
Showing
5 changed files
with
149 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; //~ ERROR cannot assign | ||
0 as *mut u8 | ||
} | ||
|
||
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) { | ||
unimplemented!(); | ||
} | ||
} | ||
|
||
fn main() { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; //~ ERROR cannot assign | ||
} | ||
} | ||
|
||
struct Test2(i32); | ||
|
||
impl Hello for Test2 { | ||
fn example(&self, input: &i32) { // should not suggest here | ||
self.0 += *input; //~ ERROR cannot assign | ||
} | ||
} | ||
|
||
fn main() { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |