-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 #122317 - compiler-errors:fulfill-method-probe, r=lcnr
Use fulfillment in method probe, not evaluation This PR reworks method probing to use fulfillment instead of a `for`-loop of `evaluate_predicate` calls, and moves normalization from method candidate assembly into the `consider_probe`, where it's applied to *all* candidates. This last part coincidentally fixes #121643 (comment). Regarding *why* this large rewrite is done: In general, it's an anti-pattern to do `for o in obligations { evaluate(o); }` because it's not compatible with the way that the new solver emits alias-relate obligations which constrain variables that may show up in other predicates. r? lcnr
- Loading branch information
Showing
19 changed files
with
322 additions
and
457 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,32 @@ | ||
// Tests that using fulfillment in the trait solver means that we detect that a | ||
// method is impossible, leading to no ambiguity. | ||
//@ check-pass | ||
//@ revisions: current next | ||
//@ ignore-compare-mode-next-solver (explicit revisions) | ||
//@[next] compile-flags: -Znext-solver | ||
|
||
#[derive(Default)] | ||
struct W<A, B>(A, B); | ||
|
||
trait Constrain { | ||
type Output; | ||
} | ||
|
||
impl Constrain for i32 { | ||
type Output = u32; | ||
} | ||
|
||
trait Impossible {} | ||
|
||
impl<A, B> W<A, B> where A: Constrain<Output = B>, B: Impossible { | ||
fn method(&self) {} | ||
} | ||
|
||
impl W<i32, u32> { | ||
fn method(&self) {} | ||
} | ||
|
||
fn main() { | ||
let w: W<i32, _> = W::default(); | ||
w.method(); | ||
} |
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,26 @@ | ||
// Tests that using fulfillment in the trait solver means that we detect that a | ||
// method is impossible, leading to no ambiguity. | ||
//@ check-pass | ||
//@ revisions: current next | ||
//@ ignore-compare-mode-next-solver (explicit revisions) | ||
//@[next] compile-flags: -Znext-solver | ||
|
||
struct W<T, U>(Option<T>, Option<U>); | ||
|
||
impl<'a> W<fn(&'a ()), u32> { | ||
fn method(&self) {} | ||
} | ||
|
||
trait Leak {} | ||
impl<T: Fn(&())> Leak for T {} | ||
|
||
impl<T: Leak> W<T, i32> { | ||
fn method(&self) {} | ||
} | ||
|
||
fn test<'a>() { | ||
let x: W<fn(&'a ()), _> = W(None, None); | ||
x.method(); | ||
} | ||
|
||
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,24 @@ | ||
//@ check-pass | ||
|
||
// Test that we use `sup` not `eq` during method probe, since this has an effect | ||
// on the leak check. This is (conceptually) minimized from a crater run for | ||
// `wrend 0.3.6`. | ||
|
||
use std::ops::Deref; | ||
|
||
struct A; | ||
|
||
impl Deref for A { | ||
type Target = B<dyn Fn(&())>; | ||
|
||
fn deref(&self) -> &<Self as Deref>::Target { todo!() } | ||
} | ||
|
||
struct B<T: ?Sized>(T); | ||
impl<T> B<dyn Fn(T)> { | ||
fn method(&self) {} | ||
} | ||
|
||
fn main() { | ||
A.method(); | ||
} |
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.