Skip to content

Commit f23c9f4

Browse files
authored
Rollup merge of rust-lang#65181 - nikomatsakis:lazy-norm-anon-const-push-1, r=varkor
fix bug in folding for constants These was a bug in the folding for constants that caused it to overlook bound regions. This branch includes some other little things that I did while trying to track the bug down. r? @oli-obk
2 parents ecdb5e9 + 08c0e84 commit f23c9f4

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

src/librustc/ty/flags.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ impl FlagComputation {
250250
ConstValue::Placeholder(_) => {
251251
self.add_flags(TypeFlags::HAS_FREE_REGIONS | TypeFlags::HAS_CT_PLACEHOLDER);
252252
}
253-
_ => {},
253+
ConstValue::Scalar(_) => { }
254+
ConstValue::Slice { data: _, start: _, end: _ } => { }
255+
ConstValue::ByRef { alloc: _, offset: _ } => { }
254256
}
255257
}
256258

src/librustc/ty/fold.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -911,13 +911,15 @@ impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor {
911911
}
912912

913913
fn visit_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> bool {
914-
if let ty::Const {
915-
val: ConstValue::Infer(ty::InferConst::Canonical(debruijn, _)),
916-
..
917-
} = *ct {
918-
debruijn >= self.outer_index
919-
} else {
920-
false
914+
// we don't have a `visit_infer_const` callback, so we have to
915+
// hook in here to catch this case (annoying...), but
916+
// otherwise we do want to remember to visit the rest of the
917+
// const, as it has types/regions embedded in a lot of other
918+
// places.
919+
match ct.val {
920+
ConstValue::Infer(ty::InferConst::Canonical(debruijn, _))
921+
if debruijn >= self.outer_index => true,
922+
_ => ct.super_visit_with(self),
921923
}
922924
}
923925
}

src/librustc/ty/print/pretty.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ pub trait PrettyPrinter<'tcx>:
689689
if self.tcx().sess.verbose() {
690690
p!(write(
691691
" closure_kind_ty={:?} closure_sig_ty={:?}",
692-
substs.as_closure().kind(did, self.tcx()),
692+
substs.as_closure().kind_ty(did, self.tcx()),
693693
substs.as_closure().sig_ty(did, self.tcx())
694694
));
695695
}
@@ -698,7 +698,9 @@ pub trait PrettyPrinter<'tcx>:
698698
},
699699
ty::Array(ty, sz) => {
700700
p!(write("["), print(ty), write("; "));
701-
if let ConstValue::Unevaluated(..) = sz.val {
701+
if self.tcx().sess.verbose() {
702+
p!(write("{:?}", sz));
703+
} else if let ConstValue::Unevaluated(..) = sz.val {
702704
// do not try to evalute unevaluated constants. If we are const evaluating an
703705
// array length anon const, rustc will (with debug assertions) print the
704706
// constant's path. Which will end up here again.
@@ -855,6 +857,11 @@ pub trait PrettyPrinter<'tcx>:
855857
) -> Result<Self::Const, Self::Error> {
856858
define_scoped_cx!(self);
857859

860+
if self.tcx().sess.verbose() {
861+
p!(write("Const({:?}: {:?})", ct.val, ct.ty));
862+
return Ok(self);
863+
}
864+
858865
let u8 = self.tcx().types.u8;
859866
if let ty::FnDef(did, substs) = ct.ty.kind {
860867
p!(print_value_path(did, substs));

src/librustc/ty/sty.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2203,7 +2203,9 @@ impl<'tcx> TyS<'tcx> {
22032203
_ => bug!("cannot convert type `{:?}` to a closure kind", self),
22042204
},
22052205

2206-
Infer(_) => None,
2206+
// "Bound" types appear in canonical queries when the
2207+
// closure type is not yet known
2208+
Bound(..) | Infer(_) => None,
22072209

22082210
Error => Some(ty::ClosureKind::Fn),
22092211

src/librustc_traits/evaluate_obligation.rs

+2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ fn evaluate_obligation<'tcx>(
1717
tcx: TyCtxt<'tcx>,
1818
canonical_goal: CanonicalPredicateGoal<'tcx>,
1919
) -> Result<EvaluationResult, OverflowError> {
20+
debug!("evaluate_obligation(canonical_goal={:#?})", canonical_goal);
2021
tcx.infer_ctxt().enter_with_canonical(
2122
DUMMY_SP,
2223
&canonical_goal,
2324
|ref infcx, goal, _canonical_inference_vars| {
25+
debug!("evaluate_obligation: goal={:#?}", goal);
2426
let ParamEnvAnd {
2527
param_env,
2628
value: predicate,

0 commit comments

Comments
 (0)