Skip to content

Commit 2d15f1c

Browse files
committed
Don't try to resolve inference variables in WF computation, just register
1 parent c4693bc commit 2d15f1c

File tree

2 files changed

+25
-38
lines changed

2 files changed

+25
-38
lines changed

compiler/rustc_trait_selection/src/traits/wf.rs

+17-35
Original file line numberDiff line numberDiff line change
@@ -452,26 +452,16 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
452452
predicate,
453453
));
454454
}
455-
ty::ConstKind::Infer(infer) => {
456-
let resolved = self.infcx.shallow_resolve(infer);
457-
// the `InferConst` changed, meaning that we made progress.
458-
if resolved != infer {
459-
let cause = self.cause(traits::WellFormed(None));
460-
461-
let resolved_constant = self.infcx.tcx.mk_const(ty::ConstS {
462-
kind: ty::ConstKind::Infer(resolved),
463-
ty: constant.ty(),
464-
});
465-
self.out.push(traits::Obligation::with_depth(
466-
cause,
467-
self.recursion_depth,
468-
self.param_env,
469-
ty::Binder::dummy(ty::PredicateKind::WellFormed(
470-
resolved_constant.into(),
471-
))
455+
ty::ConstKind::Infer(_) => {
456+
let cause = self.cause(traits::WellFormed(None));
457+
458+
self.out.push(traits::Obligation::with_depth(
459+
cause,
460+
self.recursion_depth,
461+
self.param_env,
462+
ty::Binder::dummy(ty::PredicateKind::WellFormed(constant.into()))
472463
.to_predicate(self.tcx()),
473-
));
474-
}
464+
));
475465
}
476466
ty::ConstKind::Error(_)
477467
| ty::ConstKind::Param(_)
@@ -675,22 +665,14 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
675665
// See also the comment on `fn obligations`, describing "livelock"
676666
// prevention, which happens before this can be reached.
677667
ty::Infer(_) => {
678-
let ty = self.infcx.shallow_resolve(ty);
679-
if let ty::Infer(ty::TyVar(_)) = ty.kind() {
680-
// Not yet resolved, but we've made progress.
681-
let cause = self.cause(traits::WellFormed(None));
682-
self.out.push(traits::Obligation::with_depth(
683-
cause,
684-
self.recursion_depth,
685-
param_env,
686-
ty::Binder::dummy(ty::PredicateKind::WellFormed(ty.into()))
687-
.to_predicate(self.tcx()),
688-
));
689-
} else {
690-
// Yes, resolved, proceed with the result.
691-
// FIXME(eddyb) add the type to `walker` instead of recursing.
692-
self.compute(ty.into());
693-
}
668+
let cause = self.cause(traits::WellFormed(None));
669+
self.out.push(traits::Obligation::with_depth(
670+
cause,
671+
self.recursion_depth,
672+
param_env,
673+
ty::Binder::dummy(ty::PredicateKind::WellFormed(ty.into()))
674+
.to_predicate(self.tcx()),
675+
));
694676
}
695677
}
696678
}

src/test/ui/issues/issue-98299.stderr

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
error[E0282]: type annotations needed
2-
--> $DIR/issue-98299.rs:4:5
1+
error[E0282]: type annotations needed for `SmallCString<N>`
2+
--> $DIR/issue-98299.rs:4:36
33
|
44
LL | SmallCString::try_from(p).map(|cstr| cstr);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for enum `Result<SmallCString<{_: usize}>, ()>`
5+
| ^^^^
6+
|
7+
help: consider giving this closure parameter an explicit type, where the the value of const parameter `N` is specified
8+
|
9+
LL | SmallCString::try_from(p).map(|cstr: SmallCString<N>| cstr);
10+
| +++++++++++++++++
611

712
error: aborting due to previous error
813

0 commit comments

Comments
 (0)