Skip to content

Commit 4fe232b

Browse files
Do not ICE when we have fn pointer Fn obligations with bound vars in the self type
1 parent f63ccaf commit 4fe232b

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
601601
debug!(?obligation, "confirm_fn_pointer_candidate");
602602

603603
let tcx = self.tcx();
604-
let self_ty = self
604+
605+
let Some(self_ty) = self
605606
.infcx
606-
.shallow_resolve(obligation.self_ty().no_bound_vars())
607-
.expect("fn pointer should not capture bound vars from predicate");
607+
.shallow_resolve(obligation.self_ty().no_bound_vars()) else
608+
{
609+
// FIXME: Ideally we'd support `for<'a> fn(&'a ()): Fn(&'a ())`,
610+
// but we do not currently. Luckily, such a bound is not
611+
// particularly useful, so we don't expect users to write
612+
// them often.
613+
return Err(SelectionError::Unimplemented);
614+
};
615+
608616
let sig = self_ty.fn_sig(tcx);
609617
let trait_ref = closure_trait_ref_and_return_type(
610618
tcx,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0277]: expected a `Fn<(&'w (),)>` closure, found `fn(&'w ())`
2+
--> $DIR/fn-ptr.rs:12:5
3+
|
4+
LL | ice();
5+
| ^^^ expected an `Fn<(&'w (),)>` closure, found `fn(&'w ())`
6+
|
7+
= help: the trait `for<'w> Fn<(&'w (),)>` is not implemented for `fn(&'w ())`
8+
note: required by a bound in `ice`
9+
--> $DIR/fn-ptr.rs:7:25
10+
|
11+
LL | fn ice()
12+
| --- required by a bound in this function
13+
LL | where
14+
LL | for<'w> fn(&'w ()): Fn(&'w ()),
15+
| ^^^^^^^^^^ required by this bound in `ice`
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// revisions: classic next
2+
//[next] compile-flags: -Ztrait-solver=next
3+
//[next] check-pass
4+
5+
fn ice()
6+
where
7+
for<'w> fn(&'w ()): Fn(&'w ()),
8+
{
9+
}
10+
11+
fn main() {
12+
ice();
13+
//[classic]~^ ERROR expected a `Fn<(&'w (),)>` closure, found `fn(&'w ())`
14+
}

0 commit comments

Comments
 (0)