This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed
compiler/rustc_trait_selection/src/solve/trait_goals
tests/ui/traits/new-solver Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -214,9 +214,20 @@ pub(crate) fn extract_tupled_inputs_and_output_from_callable<'tcx>(
214
214
ty:: Closure ( _, substs) => {
215
215
let closure_substs = substs. as_closure ( ) ;
216
216
match closure_substs. kind_ty ( ) . to_opt_closure_kind ( ) {
217
- Some ( closure_kind) if closure_kind. extends ( goal_kind) => { }
218
- None => return Ok ( None ) ,
219
- _ => return Err ( NoSolution ) ,
217
+ // If the closure's kind doesn't extend the goal kind,
218
+ // then the closure doesn't implement the trait.
219
+ Some ( closure_kind) => {
220
+ if !closure_kind. extends ( goal_kind) {
221
+ return Err ( NoSolution ) ;
222
+ }
223
+ }
224
+ // Closure kind is not yet determined, so we return ambiguity unless
225
+ // the expected kind is `FnOnce` as that is always implemented.
226
+ None => {
227
+ if goal_kind != ty:: ClosureKind :: FnOnce {
228
+ return Ok ( None ) ;
229
+ }
230
+ }
220
231
}
221
232
Ok ( Some ( closure_substs. sig ( ) . map_bound ( |sig| ( sig. inputs ( ) [ 0 ] , sig. output ( ) ) ) ) )
222
233
}
Original file line number Diff line number Diff line change
1
+ // compile-flags: -Ztrait-solver=next
2
+ // check-pass
3
+
4
+ fn foo ( i : isize ) -> isize { i + 1 }
5
+
6
+ fn apply < A , F > ( f : F , v : A ) -> A where F : FnOnce ( A ) -> A { f ( v) }
7
+
8
+ pub fn main ( ) {
9
+ let f = |i| foo ( i) ;
10
+ assert_eq ! ( apply( f, 2 ) , 3 ) ;
11
+ }
You can’t perform that action at this time.
0 commit comments