forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
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#119934 - compiler-errors:could-impl, r=jackh726
Make `InferCtxtExt::could_impl_trait` more precise, less ICEy The implementation for `InferCtxtExt::could_impl_trait` was very wrong. Along with being pretty poorly named, way too specific to ADTs, it was also doing impl substitution wrong -- this caused an ICE (rust-lang#119915). This PR generalizes that code, gives it a clearer name, makes it stop using the new trait solver (lol), and fixes some fallout bad suggestions that are made worse with the code fix. Fixes rust-lang#119915
- Loading branch information
Showing
15 changed files
with
128 additions
and
101 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
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
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,28 @@ | ||
use std::marker::PhantomData; | ||
|
||
struct Example<E, FakeParam>(PhantomData<(fn(E), fn(FakeParam))>); | ||
|
||
struct NoLifetime; | ||
struct Immutable<'a>(PhantomData<&'a ()>); | ||
|
||
impl<'a, E: 'a> Copy for Example<E, Immutable<'a>> {} | ||
impl<'a, E: 'a> Clone for Example<E, Immutable<'a>> { | ||
fn clone(&self) -> Self { | ||
*self | ||
} | ||
} | ||
|
||
impl<E, FakeParam> Example<E, FakeParam> { | ||
unsafe fn change<NewFakeParam>(self) -> Example<E, NewFakeParam> { | ||
Example(PhantomData) | ||
} | ||
} | ||
|
||
impl<E> Example<E, NoLifetime> { | ||
fn the_ice(&mut self) -> Example<E, Immutable<'_>> { | ||
unsafe { self.change() } | ||
//~^ ERROR cannot move out of `*self` which is behind a mutable reference | ||
} | ||
} | ||
|
||
fn main() {} |
17 changes: 17 additions & 0 deletions
17
tests/ui/borrowck/issue-119915-bad-clone-suggestion.stderr
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,17 @@ | ||
error[E0507]: cannot move out of `*self` which is behind a mutable reference | ||
--> $DIR/issue-119915-bad-clone-suggestion.rs:23:18 | ||
| | ||
LL | unsafe { self.change() } | ||
| ^^^^ -------- `*self` moved due to this method call | ||
| | | ||
| move occurs because `*self` has type `Example<E, NoLifetime>`, which does not implement the `Copy` trait | ||
| | ||
note: `Example::<E, FakeParam>::change` takes ownership of the receiver `self`, which moves `*self` | ||
--> $DIR/issue-119915-bad-clone-suggestion.rs:16:36 | ||
| | ||
LL | unsafe fn change<NewFakeParam>(self) -> Example<E, NewFakeParam> { | ||
| ^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0507`. |
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
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
Oops, something went wrong.