-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 #101834 - compiler-errors:super-deduce-closure-sig, r=lcnr
Elaborate supertrait obligations when deducing closure signatures We elaborate the supertrait obligations of any registered predicates for a closure to see if we can infer a closure signature. This is not as general of a fix as it *could* be, since we just elaborate supertrait bounds instead of doing a theoretical walk of _all_ registered predicates that might cause us to deduce `Fn` trait information for a closure infer var. I don't even know how to come up with an example that fails here but would work with a more general system. Fixes #23012 Also fixes the existing compile failure in #57611 r? `@ghost` for now until I do a perf run cc `@nikomatsakis` since you commented on #23012 (comment)
- Loading branch information
Showing
5 changed files
with
125 additions
and
102 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
29 changes: 29 additions & 0 deletions
29
src/test/ui/closures/issue-23012-supertrait-signature-inference.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,29 @@ | ||
// check-pass | ||
// Checks that we can infer a closure signature even if the `FnOnce` bound is | ||
// a supertrait of the obligations we have currently registered for the Ty var. | ||
|
||
pub trait Receive<T, E>: FnOnce(Result<T, E>) { | ||
fn receive(self, res: Result<T, E>); | ||
} | ||
|
||
impl<T, E, F: FnOnce(Result<T, E>)> Receive<T, E> for F { | ||
fn receive(self, res: Result<T, E>) { | ||
self(res) | ||
} | ||
} | ||
|
||
pub trait Async<T, E> { | ||
fn receive<F: Receive<T, E>>(self, f: F); | ||
} | ||
|
||
impl<T, E> Async<T, E> for Result<T, E> { | ||
fn receive<F: Receive<T, E>>(self, f: F) { | ||
f(self) | ||
} | ||
} | ||
|
||
pub fn main() { | ||
Ok::<u32, ()>(123).receive(|res| { | ||
res.unwrap(); | ||
}); | ||
} |
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
26 changes: 0 additions & 26 deletions
26
src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.stderr
This file was deleted.
Oops, something went wrong.