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.
Rollup merge of rust-lang#111747 - compiler-errors:structural-probe-s…
…ide-effects, r=fee1-dead Don't structurally resolve during method ambiguity in probe See comment in UI test for reason for the failure. This is all on the error path anyways, not really sure what the assertion is there to achieve anyways... Fixes rust-lang#111739
- Loading branch information
Showing
3 changed files
with
71 additions
and
5 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
40 changes: 40 additions & 0 deletions
40
tests/ui/autoref-autoderef/deref-ambiguity-becomes-nonambiguous.rs
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,40 @@ | ||
use std::ops::Deref; | ||
use std::rc::Rc; | ||
|
||
struct Value<T>(T); | ||
|
||
pub trait Wrap<T> { | ||
fn wrap() -> Self; | ||
} | ||
|
||
impl<R, A1, A2> Wrap<fn(A1, A2) -> R> for Value<fn(A1, A2) -> R> { | ||
fn wrap() -> Self { | ||
todo!() | ||
} | ||
} | ||
|
||
impl<F, R, A1, A2> Wrap<F> for Value<Rc<dyn Fn(A1, A2) -> R>> { | ||
fn wrap() -> Self { | ||
todo!() | ||
} | ||
} | ||
|
||
impl<F> Deref for Value<Rc<F>> { | ||
type Target = F; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&*self.0 | ||
} | ||
} | ||
|
||
fn main() { | ||
let var_fn = Value::wrap(); | ||
//~^ ERROR type annotations needed for `Value<Rc<_>>` | ||
|
||
// The combination of `Value: Wrap` obligation plus the autoderef steps | ||
// (caused by the `Deref` impl above) actually means that the self type | ||
// of the method fn below is constrained to be `Value<Rc<dyn Fn(?0, ?1) -> ?2>>`. | ||
// However, that's only known to us on the error path -- we still need | ||
// to emit an ambiguity error, though. | ||
let _ = var_fn.clone(); | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ui/autoref-autoderef/deref-ambiguity-becomes-nonambiguous.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[E0282]: type annotations needed for `Value<Rc<_>>` | ||
--> $DIR/deref-ambiguity-becomes-nonambiguous.rs:31:9 | ||
| | ||
LL | let var_fn = Value::wrap(); | ||
| ^^^^^^ | ||
... | ||
LL | let _ = var_fn.clone(); | ||
| ----- type must be known at this point | ||
| | ||
help: consider giving `var_fn` an explicit type, where the placeholders `_` are specified | ||
| | ||
LL | let var_fn: Value<Rc<_>> = Value::wrap(); | ||
| ++++++++++++++ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0282`. |