-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #95585 - compiler-errors:ref-clone, r=estebank
Explain why `&T` is cloned when `T` is not `Clone` Fixes #95535
- Loading branch information
Showing
4 changed files
with
86 additions
and
6 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
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,13 @@ | ||
struct NotClone; | ||
|
||
fn main() { | ||
clone_thing(&NotClone); | ||
} | ||
|
||
fn clone_thing(nc: &NotClone) -> NotClone { | ||
//~^ NOTE expected `NotClone` because of return type | ||
nc.clone() | ||
//~^ ERROR mismatched type | ||
//~| NOTE `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead | ||
//~| NOTE expected struct `NotClone`, found `&NotClone` | ||
} |
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,18 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/explain_clone_autoref.rs:9:5 | ||
| | ||
LL | fn clone_thing(nc: &NotClone) -> NotClone { | ||
| -------- expected `NotClone` because of return type | ||
LL | | ||
LL | nc.clone() | ||
| ^^^^^^^^^^ expected struct `NotClone`, found `&NotClone` | ||
| | ||
note: `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead | ||
--> $DIR/explain_clone_autoref.rs:9:5 | ||
| | ||
LL | nc.clone() | ||
| ^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |