diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2022-09-28 13:07:20 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-28 13:07:20 +0900 |
| commit | ae2028817a9612b47d40093c95d886c2db97a526 (patch) | |
| tree | 1c8181c7bd48c4acb23d8006c4473aa445523d12 | |
| parent | bf54cfe2b247abe6f3e90d088f72257fb2352d72 (diff) | |
| parent | e5776c690328a373ec812471f7a257e6c0920881 (diff) | |
| download | rust-ae2028817a9612b47d40093c95d886c2db97a526.tar.gz rust-ae2028817a9612b47d40093c95d886c2db97a526.zip | |
Rollup merge of #102378 - compiler-errors:issue-102289, r=jackh726
Use already resolved `self_ty` in `confirm_fn_pointer_candidate` Fixes #102289
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/select/confirmation.rs | 3 | ||||
| -rw-r--r-- | src/test/ui/function-pointer/issue-102289.rs | 54 |
2 files changed, 56 insertions, 1 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 27fbfb6dd21..dd49dcecf77 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -626,7 +626,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // the signature, as evidenced by how we treat it during projection. // The safe thing to do here is to liberate it, though, which should // have no worse effect than skipping the binder here. - let liberated_fn_ty = self.infcx.replace_bound_vars_with_placeholders(obligation.self_ty()); + let liberated_fn_ty = + self.infcx.replace_bound_vars_with_placeholders(obligation.predicate.rebind(self_ty)); let output_ty = self .infcx .replace_bound_vars_with_placeholders(liberated_fn_ty.fn_sig(self.tcx()).output()); diff --git a/src/test/ui/function-pointer/issue-102289.rs b/src/test/ui/function-pointer/issue-102289.rs new file mode 100644 index 00000000000..de394ca9ad6 --- /dev/null +++ b/src/test/ui/function-pointer/issue-102289.rs @@ -0,0 +1,54 @@ +// check-pass + +pub(crate) trait Parser: Sized { + type Output; + fn parse(&mut self, _input: &str) -> Result<(), ()> { + loop {} + } + fn map<F, B>(self, _f: F) -> Map<Self, F> + where + F: FnMut(Self::Output) -> B, + { + todo!() + } +} + +pub(crate) struct Chainl1<P, Op>(P, Op); +impl<P, Op> Parser for Chainl1<P, Op> +where + P: Parser, + Op: Parser, + Op::Output: FnOnce(P::Output, P::Output) -> P::Output, +{ + type Output = P::Output; +} +pub(crate) fn chainl1<P, Op>(_parser: P, _op: Op) -> Chainl1<P, Op> +where + P: Parser, + Op: Parser, + Op::Output: FnOnce(P::Output, P::Output) -> P::Output, +{ + loop {} +} + +pub(crate) struct Map<P, F>(P, F); +impl<A, B, P, F> Parser for Map<P, F> +where + P: Parser<Output = A>, + F: FnMut(A) -> B, +{ + type Output = B; +} + +impl Parser for u32 { + type Output = (); +} + +pub fn chainl1_error_consume() { + fn first<T, U>(t: T, _: U) -> T { + t + } + let _ = chainl1(1, 1.map(|_| first)).parse(""); +} + +fn main() {} |
