Skip to content

Commit 337177a

Browse files
Remove ClosureKind predicate kind
1 parent 8534923 commit 337177a

File tree

25 files changed

+81
-198
lines changed

25 files changed

+81
-198
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

-1
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
662662
// this closure yet; this is exactly why the other
663663
// code is looking for a self type of an unresolved
664664
// inference variable.
665-
| ty::PredicateKind::ClosureKind(..)
666665
| ty::PredicateKind::Ambiguous
667666
=> None,
668667
},

compiler/rustc_infer/src/traits/util.rs

-3
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,6 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> {
308308
ty::PredicateKind::Clause(ty::ClauseKind::Projection(..)) => {
309309
// Nothing to elaborate in a projection predicate.
310310
}
311-
ty::PredicateKind::ClosureKind(..) => {
312-
// Nothing to elaborate when waiting for a closure's kind to be inferred.
313-
}
314311
ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..)) => {
315312
// Currently, we do not elaborate const-evaluatable
316313
// predicates.

compiler/rustc_middle/src/ty/flags.rs

-3
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,6 @@ impl FlagComputation {
263263
self.add_args(slice::from_ref(&arg));
264264
}
265265
ty::PredicateKind::ObjectSafe(_def_id) => {}
266-
ty::PredicateKind::ClosureKind(_def_id, args, _kind) => {
267-
self.add_args(args);
268-
}
269266
ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(uv)) => {
270267
self.add_const(uv);
271268
}

compiler/rustc_middle/src/ty/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,6 @@ impl<'tcx> Predicate<'tcx> {
550550
| PredicateKind::Clause(ClauseKind::ConstArgHasType(..))
551551
| PredicateKind::AliasRelate(..)
552552
| PredicateKind::ObjectSafe(_)
553-
| PredicateKind::ClosureKind(_, _, _)
554553
| PredicateKind::Subtype(_)
555554
| PredicateKind::Coerce(_)
556555
| PredicateKind::Clause(ClauseKind::ConstEvaluatable(_))
@@ -1278,7 +1277,6 @@ impl<'tcx> Predicate<'tcx> {
12781277
| PredicateKind::Clause(ClauseKind::RegionOutlives(..))
12791278
| PredicateKind::Clause(ClauseKind::WellFormed(..))
12801279
| PredicateKind::ObjectSafe(..)
1281-
| PredicateKind::ClosureKind(..)
12821280
| PredicateKind::Clause(ClauseKind::TypeOutlives(..))
12831281
| PredicateKind::Clause(ClauseKind::ConstEvaluatable(..))
12841282
| PredicateKind::ConstEquate(..)
@@ -1298,7 +1296,6 @@ impl<'tcx> Predicate<'tcx> {
12981296
| PredicateKind::Clause(ClauseKind::RegionOutlives(..))
12991297
| PredicateKind::Clause(ClauseKind::WellFormed(..))
13001298
| PredicateKind::ObjectSafe(..)
1301-
| PredicateKind::ClosureKind(..)
13021299
| PredicateKind::Clause(ClauseKind::TypeOutlives(..))
13031300
| PredicateKind::Clause(ClauseKind::ConstEvaluatable(..))
13041301
| PredicateKind::ConstEquate(..)
@@ -1319,7 +1316,6 @@ impl<'tcx> Predicate<'tcx> {
13191316
| PredicateKind::Clause(ClauseKind::RegionOutlives(..))
13201317
| PredicateKind::Clause(ClauseKind::WellFormed(..))
13211318
| PredicateKind::ObjectSafe(..)
1322-
| PredicateKind::ClosureKind(..)
13231319
| PredicateKind::Clause(ClauseKind::ConstEvaluatable(..))
13241320
| PredicateKind::ConstEquate(..)
13251321
| PredicateKind::Ambiguous => None,

compiler/rustc_middle/src/ty/print/pretty.rs

-5
Original file line numberDiff line numberDiff line change
@@ -2781,11 +2781,6 @@ define_print! {
27812781
ty::PredicateKind::ObjectSafe(trait_def_id) => {
27822782
p!("the trait `", print_def_path(trait_def_id, &[]), "` is object-safe")
27832783
}
2784-
ty::PredicateKind::ClosureKind(closure_def_id, _closure_args, kind) => p!(
2785-
"the closure `",
2786-
print_value_path(closure_def_id, &[]),
2787-
write("` implements the trait `{}`", kind)
2788-
),
27892784
ty::PredicateKind::ConstEquate(c1, c2) => {
27902785
p!("the constant `", print(c1), "` equals `", print(c2), "`")
27912786
}

compiler/rustc_smir/src/rustc_smir/mod.rs

-7
Original file line numberDiff line numberDiff line change
@@ -1667,13 +1667,6 @@ impl<'tcx> Stable<'tcx> for ty::PredicateKind<'tcx> {
16671667
PredicateKind::ObjectSafe(did) => {
16681668
stable_mir::ty::PredicateKind::ObjectSafe(tables.trait_def(*did))
16691669
}
1670-
PredicateKind::ClosureKind(did, generic_args, closure_kind) => {
1671-
stable_mir::ty::PredicateKind::ClosureKind(
1672-
tables.closure_def(*did),
1673-
generic_args.stable(tables),
1674-
closure_kind.stable(tables),
1675-
)
1676-
}
16771670
PredicateKind::Subtype(subtype_predicate) => {
16781671
stable_mir::ty::PredicateKind::SubType(subtype_predicate.stable(tables))
16791672
}

compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,6 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
406406
ty::PredicateKind::Coerce(predicate) => {
407407
self.compute_coerce_goal(Goal { param_env, predicate })
408408
}
409-
ty::PredicateKind::ClosureKind(def_id, args, kind) => self
410-
.compute_closure_kind_goal(Goal { param_env, predicate: (def_id, args, kind) }),
411409
ty::PredicateKind::ObjectSafe(trait_def_id) => {
412410
self.compute_object_safe_goal(trait_def_id)
413411
}

compiler/rustc_trait_selection/src/solve/fulfill.rs

-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
135135
}
136136
ty::PredicateKind::Clause(_)
137137
| ty::PredicateKind::ObjectSafe(_)
138-
| ty::PredicateKind::ClosureKind(_, _, _)
139138
| ty::PredicateKind::Ambiguous => {
140139
FulfillmentErrorCode::CodeSelectionError(
141140
SelectionError::Unimplemented,

compiler/rustc_trait_selection/src/traits/auto_trait.rs

-1
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,6 @@ impl<'tcx> AutoTraitFinder<'tcx> {
822822
| ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))
823823
| ty::PredicateKind::AliasRelate(..)
824824
| ty::PredicateKind::ObjectSafe(..)
825-
| ty::PredicateKind::ClosureKind(..)
826825
| ty::PredicateKind::Subtype(..)
827826
// FIXME(generic_const_exprs): you can absolutely add this as a where clauses
828827
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

-5
Original file line numberDiff line numberDiff line change
@@ -786,11 +786,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
786786
report_object_safety_error(self.tcx, span, trait_def_id, violations)
787787
}
788788

789-
ty::PredicateKind::ClosureKind(closure_def_id, closure_args, kind) => {
790-
let found_kind = self.closure_kind(closure_args).unwrap();
791-
self.report_closure_error(&obligation, closure_def_id, found_kind, kind)
792-
}
793-
794789
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(ty)) => {
795790
let ty = self.resolve_vars_if_possible(ty);
796791
match self.tcx.sess.opts.unstable_opts.trait_solver {

compiler/rustc_trait_selection/src/traits/fulfill.rs

-14
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
350350
| ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))
351351
| ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_))
352352
| ty::PredicateKind::ObjectSafe(_)
353-
| ty::PredicateKind::ClosureKind(..)
354353
| ty::PredicateKind::Subtype(_)
355354
| ty::PredicateKind::Coerce(_)
356355
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
@@ -411,19 +410,6 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
411410
}
412411
}
413412

414-
ty::PredicateKind::ClosureKind(_, closure_args, kind) => {
415-
match self.selcx.infcx.closure_kind(closure_args) {
416-
Some(closure_kind) => {
417-
if closure_kind.extends(kind) {
418-
ProcessResult::Changed(vec![])
419-
} else {
420-
ProcessResult::Error(CodeSelectionError(Unimplemented))
421-
}
422-
}
423-
None => ProcessResult::Unchanged,
424-
}
425-
}
426-
427413
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(arg)) => {
428414
match wf::obligations(
429415
self.selcx.infcx,

compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs

-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ pub fn compute_implied_outlives_bounds_inner<'tcx>(
130130
| ty::PredicateKind::Subtype(..)
131131
| ty::PredicateKind::Coerce(..)
132132
| ty::PredicateKind::Clause(ty::ClauseKind::Projection(..))
133-
| ty::PredicateKind::ClosureKind(..)
134133
| ty::PredicateKind::ObjectSafe(..)
135134
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
136135
| ty::PredicateKind::ConstEquate(..)

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
291291
}
292292
}
293293
None => {
294-
debug!("assemble_unboxed_candidates: closure_kind not yet known");
295-
candidates.vec.push(ClosureCandidate { is_const });
294+
if kind == ty::ClosureKind::FnOnce {
295+
candidates.vec.push(ClosureCandidate { is_const });
296+
} else {
297+
candidates.ambiguous = true;
298+
}
296299
}
297300
}
298301
}

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

+1-11
Original file line numberDiff line numberDiff line change
@@ -821,11 +821,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
821821
&mut self,
822822
obligation: &PolyTraitObligation<'tcx>,
823823
) -> Result<Vec<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
824-
let kind = self
825-
.tcx()
826-
.fn_trait_kind_from_def_id(obligation.predicate.def_id())
827-
.unwrap_or_else(|| bug!("closure candidate for non-fn trait {:?}", obligation));
828-
829824
// Okay to skip binder because the args on closure types never
830825
// touch bound regions, they just capture the in-scope
831826
// type/region parameters.
@@ -835,15 +830,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
835830
};
836831

837832
let trait_ref = self.closure_trait_ref_unnormalized(obligation, args);
838-
let mut nested = self.confirm_poly_trait_refs(obligation, trait_ref)?;
833+
let nested = self.confirm_poly_trait_refs(obligation, trait_ref)?;
839834

840835
debug!(?closure_def_id, ?trait_ref, ?nested, "confirm closure candidate obligations");
841836

842-
nested.push(obligation.with(
843-
self.tcx(),
844-
ty::Binder::dummy(ty::PredicateKind::ClosureKind(closure_def_id, args, kind)),
845-
));
846-
847837
Ok(nested)
848838
}
849839

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

-13
Original file line numberDiff line numberDiff line change
@@ -885,19 +885,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
885885
}
886886
}
887887

888-
ty::PredicateKind::ClosureKind(_, closure_args, kind) => {
889-
match self.infcx.closure_kind(closure_args) {
890-
Some(closure_kind) => {
891-
if closure_kind.extends(kind) {
892-
Ok(EvaluatedToOk)
893-
} else {
894-
Ok(EvaluatedToErr)
895-
}
896-
}
897-
None => Ok(EvaluatedToAmbig),
898-
}
899-
}
900-
901888
ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(uv)) => {
902889
match const_evaluatable::is_const_evaluatable(
903890
self.infcx,

compiler/rustc_traits/src/normalize_erasing_regions.rs

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ fn not_outlives_predicate(p: ty::Predicate<'_>) -> bool {
5858
| ty::PredicateKind::AliasRelate(..)
5959
| ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(..))
6060
| ty::PredicateKind::ObjectSafe(..)
61-
| ty::PredicateKind::ClosureKind(..)
6261
| ty::PredicateKind::Subtype(..)
6362
| ty::PredicateKind::Coerce(..)
6463
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))

compiler/rustc_type_ir/src/predicate_kind.rs

+5-32
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,6 @@ pub enum PredicateKind<I: Interner> {
172172
/// Trait must be object-safe.
173173
ObjectSafe(I::DefId),
174174

175-
/// No direct syntax. May be thought of as `where T: FnFoo<...>`
176-
/// for some generic args `...` and `T` being a closure type.
177-
/// Satisfied (or refuted) once we know the closure's kind.
178-
ClosureKind(I::DefId, I::GenericArgs, I::ClosureKind),
179-
180175
/// `T1 <: T2`
181176
///
182177
/// This obligation is created most often when we have two
@@ -226,9 +221,6 @@ impl<I: Interner> PartialEq for PredicateKind<I> {
226221
match (self, other) {
227222
(Self::Clause(l0), Self::Clause(r0)) => l0 == r0,
228223
(Self::ObjectSafe(l0), Self::ObjectSafe(r0)) => l0 == r0,
229-
(Self::ClosureKind(l0, l1, l2), Self::ClosureKind(r0, r1, r2)) => {
230-
l0 == r0 && l1 == r1 && l2 == r2
231-
}
232224
(Self::Subtype(l0), Self::Subtype(r0)) => l0 == r0,
233225
(Self::Coerce(l0), Self::Coerce(r0)) => l0 == r0,
234226
(Self::ConstEquate(l0, l1), Self::ConstEquate(r0, r1)) => l0 == r0 && l1 == r1,
@@ -247,12 +239,11 @@ fn predicate_kind_discriminant<I: Interner>(value: &PredicateKind<I>) -> usize {
247239
match value {
248240
PredicateKind::Clause(_) => 0,
249241
PredicateKind::ObjectSafe(_) => 1,
250-
PredicateKind::ClosureKind(_, _, _) => 2,
251-
PredicateKind::Subtype(_) => 3,
252-
PredicateKind::Coerce(_) => 4,
253-
PredicateKind::ConstEquate(_, _) => 5,
254-
PredicateKind::Ambiguous => 6,
255-
PredicateKind::AliasRelate(_, _, _) => 7,
242+
PredicateKind::Subtype(_) => 2,
243+
PredicateKind::Coerce(_) => 3,
244+
PredicateKind::ConstEquate(_, _) => 4,
245+
PredicateKind::Ambiguous => 5,
246+
PredicateKind::AliasRelate(_, _, _) => 6,
256247
}
257248
}
258249

@@ -273,11 +264,6 @@ where
273264
match self {
274265
PredicateKind::Clause(p) => p.hash_stable(hcx, hasher),
275266
PredicateKind::ObjectSafe(d) => d.hash_stable(hcx, hasher),
276-
PredicateKind::ClosureKind(d, g, k) => {
277-
d.hash_stable(hcx, hasher);
278-
g.hash_stable(hcx, hasher);
279-
k.hash_stable(hcx, hasher);
280-
}
281267
PredicateKind::Subtype(p) => p.hash_stable(hcx, hasher),
282268
PredicateKind::Coerce(p) => p.hash_stable(hcx, hasher),
283269
PredicateKind::ConstEquate(c1, c2) => {
@@ -309,11 +295,6 @@ where
309295
Ok(match self {
310296
PredicateKind::Clause(c) => PredicateKind::Clause(c.try_fold_with(folder)?),
311297
PredicateKind::ObjectSafe(d) => PredicateKind::ObjectSafe(d.try_fold_with(folder)?),
312-
PredicateKind::ClosureKind(d, g, k) => PredicateKind::ClosureKind(
313-
d.try_fold_with(folder)?,
314-
g.try_fold_with(folder)?,
315-
k.try_fold_with(folder)?,
316-
),
317298
PredicateKind::Subtype(s) => PredicateKind::Subtype(s.try_fold_with(folder)?),
318299
PredicateKind::Coerce(s) => PredicateKind::Coerce(s.try_fold_with(folder)?),
319300
PredicateKind::ConstEquate(a, b) => {
@@ -344,11 +325,6 @@ where
344325
match self {
345326
PredicateKind::Clause(p) => p.visit_with(visitor),
346327
PredicateKind::ObjectSafe(d) => d.visit_with(visitor),
347-
PredicateKind::ClosureKind(d, g, k) => {
348-
d.visit_with(visitor)?;
349-
g.visit_with(visitor)?;
350-
k.visit_with(visitor)
351-
}
352328
PredicateKind::Subtype(s) => s.visit_with(visitor),
353329
PredicateKind::Coerce(s) => s.visit_with(visitor),
354330
PredicateKind::ConstEquate(a, b) => {
@@ -408,9 +384,6 @@ impl<I: Interner> fmt::Debug for PredicateKind<I> {
408384
PredicateKind::ObjectSafe(trait_def_id) => {
409385
write!(f, "ObjectSafe({trait_def_id:?})")
410386
}
411-
PredicateKind::ClosureKind(closure_def_id, closure_args, kind) => {
412-
write!(f, "ClosureKind({closure_def_id:?}, {closure_args:?}, {kind:?})")
413-
}
414387
PredicateKind::ConstEquate(c1, c2) => write!(f, "ConstEquate({c1:?}, {c2:?})"),
415388
PredicateKind::Ambiguous => write!(f, "Ambiguous"),
416389
PredicateKind::AliasRelate(t1, t2, dir) => {
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
error[E0525]: expected a closure that implements the `Fn` trait, but this closure only implements `FnMut`
2-
--> $DIR/issue-26046-fn-mut.rs:4:19
1+
error[E0277]: expected a `Fn()` closure, found `{closure@$DIR/issue-26046-fn-mut.rs:4:19: 4:21}`
2+
--> $DIR/issue-26046-fn-mut.rs:8:5
33
|
4-
LL | let closure = || {
5-
| ^^ this closure implements `FnMut`, not `Fn`
6-
LL | num += 1;
7-
| --- closure is `FnMut` because it mutates the variable `num` here
8-
...
94
LL | Box::new(closure)
10-
| ----------------- the requirement to implement `Fn` derives from here
5+
| ^^^^^^^^^^^^^^^^^ expected an `Fn()` closure, found `{closure@$DIR/issue-26046-fn-mut.rs:4:19: 4:21}`
116
|
7+
= help: the trait `Fn<()>` is not implemented for closure `{closure@$DIR/issue-26046-fn-mut.rs:4:19: 4:21}`
8+
= note: wrap the `{closure@$DIR/issue-26046-fn-mut.rs:4:19: 4:21}` in a closure with no arguments: `|| { /* code */ }`
9+
= note: `{closure@$DIR/issue-26046-fn-mut.rs:4:19: 4:21}` implements `FnMut`, but it must implement `Fn`, which is more general
1210
= note: required for the cast from `Box<{closure@$DIR/issue-26046-fn-mut.rs:4:19: 4:21}>` to `Box<(dyn Fn() + 'static)>`
1311

1412
error: aborting due to previous error
1513

16-
For more information about this error, try `rustc --explain E0525`.
14+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
error[E0525]: expected a closure that implements the `Fn` trait, but this closure only implements `FnOnce`
2-
--> $DIR/issue-26046-fn-once.rs:4:19
1+
error[E0277]: expected a `Fn()` closure, found `{closure@$DIR/issue-26046-fn-once.rs:4:19: 4:26}`
2+
--> $DIR/issue-26046-fn-once.rs:8:5
33
|
4-
LL | let closure = move || {
5-
| ^^^^^^^ this closure implements `FnOnce`, not `Fn`
6-
LL | vec
7-
| --- closure is `FnOnce` because it moves the variable `vec` out of its environment
8-
...
94
LL | Box::new(closure)
10-
| ----------------- the requirement to implement `Fn` derives from here
5+
| ^^^^^^^^^^^^^^^^^ expected an `Fn()` closure, found `{closure@$DIR/issue-26046-fn-once.rs:4:19: 4:26}`
116
|
7+
= help: the trait `Fn<()>` is not implemented for closure `{closure@$DIR/issue-26046-fn-once.rs:4:19: 4:26}`
8+
= note: wrap the `{closure@$DIR/issue-26046-fn-once.rs:4:19: 4:26}` in a closure with no arguments: `|| { /* code */ }`
9+
= note: `{closure@$DIR/issue-26046-fn-once.rs:4:19: 4:26}` implements `FnOnce`, but it must implement `Fn`, which is more general
1210
= note: required for the cast from `Box<{closure@$DIR/issue-26046-fn-once.rs:4:19: 4:26}>` to `Box<(dyn Fn() -> Vec<u8> + 'static)>`
1311

1412
error: aborting due to previous error
1513

16-
For more information about this error, try `rustc --explain E0525`.
14+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)