Skip to content

Commit 6dfe452

Browse files
committed
var_for_def uses actual constness sometimes
1 parent cb8bde3 commit 6dfe452

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
193193
substs: InternalSubsts::for_item(self.tcx, method.def_id, |param, _| {
194194
let i = param.index as usize;
195195
if i < method_generics.parent_count {
196-
self.infcx.var_for_def(DUMMY_SP, param)
196+
self.infcx.var_for_def(DUMMY_SP, param, Some(self.constness))
197197
} else {
198198
*method.substs.get(i).unwrap_or_else(|| {
199199
span_bug!(
@@ -1431,7 +1431,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14311431
// This case also occurs as a result of some malformed input, e.g.
14321432
// a lifetime argument being given instead of a type parameter.
14331433
// Using inference instead of `Error` gives better error messages.
1434-
self.fcx.var_for_def(self.span, param)
1434+
self.fcx.var_for_def(self.span, param, None)
14351435
}
14361436
}
14371437
GenericParamDefKind::Const { has_default } => {
@@ -1440,11 +1440,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14401440
.subst(tcx, substs.unwrap())
14411441
.into()
14421442
} else {
1443-
self.fcx.var_for_def(self.span, param)
1443+
self.fcx.var_for_def(self.span, param, None)
14441444
}
14451445
}
14461446
GenericParamDefKind::Constness => match constness {
1447-
None => self.fcx.var_for_def(self.span, param),
1447+
None => self.fcx.constness().into(),
14481448
Some(constness) => constness.into(),
14491449
},
14501450
}

compiler/rustc_typeck/src/check/fn_ctxt/mod.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
148148
return_type_has_opaque: false,
149149
constness: {
150150
fn get_constness(tcx: TyCtxt<'_>, did: DefId) -> ty::ConstnessArg {
151-
if tcx.is_const_fn_raw(did) || tcx.is_const_default_method(did) || tcx.def_kind(did) == hir::def::DefKind::Const {
151+
if tcx.is_const_fn_raw(did)
152+
|| tcx.is_const_default_method(did)
153+
|| tcx.def_kind(did) == hir::def::DefKind::Const
154+
{
152155
trace!("const");
153156
ty::ConstnessArg::Const
154157
} else {
@@ -159,7 +162,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
159162
if body_id.is_owner() {
160163
let did = body_id.expect_owner();
161164
get_constness(inh.tcx, did.to_def_id())
162-
} else if let Some(hir::Node::Expr(hir::Expr { kind, .. })) = inh.tcx.hir().find(body_id) {
165+
} else if let Some(hir::Node::Expr(hir::Expr { kind, .. })) =
166+
inh.tcx.hir().find(body_id)
167+
{
163168
if let hir::ExprKind::Closure { .. } = kind {
164169
ty::ConstnessArg::Not
165170
} else {
@@ -253,7 +258,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
253258

254259
fn ty_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx> {
255260
if let Some(param) = param {
256-
if let GenericArgKind::Type(ty) = self.var_for_def(span, param).unpack() {
261+
if let GenericArgKind::Type(ty) = self.var_for_def(span, param, None).unpack() {
257262
return ty;
258263
}
259264
unreachable!()
@@ -272,7 +277,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
272277
span: Span,
273278
) -> Const<'tcx> {
274279
if let Some(param) = param {
275-
if let GenericArgKind::Const(ct) = self.var_for_def(span, param).unpack() {
280+
if let GenericArgKind::Const(ct) = self.var_for_def(span, param, None).unpack() {
276281
return ct;
277282
}
278283
unreachable!()

compiler/rustc_typeck/src/check/method/confirm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,10 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
405405
} else {
406406
self.cfcx.fcx.constness()
407407
};
408-
debug!("inferred_kind constness={constness:?}");
408+
debug!(?constness);
409409
constness.into()
410410
} else {
411-
self.cfcx.var_for_def(self.cfcx.span, param)
411+
self.cfcx.var_for_def(self.cfcx.span, param, None)
412412
}
413413
}
414414
}

compiler/rustc_typeck/src/check/method/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
295295
}
296296
}
297297
}
298-
self.var_for_def(span, param)
298+
self.var_for_def(span, param, Some(self.constness()))
299299
});
300300

301301
let trait_ref = ty::TraitRef::new(trait_def_id, substs);
@@ -336,7 +336,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
336336
}
337337
}
338338
}
339-
self.var_for_def(span, param)
339+
self.var_for_def(span, param, Some(self.constness()))
340340
});
341341

342342
let trait_ref = ty::TraitRef::new(trait_def_id, substs);

compiler/rustc_typeck/src/check/method/probe.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18061806
}
18071807
GenericParamDefKind::Constness
18081808
| GenericParamDefKind::Type { .. }
1809-
| GenericParamDefKind::Const { .. } => self.var_for_def(self.span, param),
1809+
| GenericParamDefKind::Const { .. } => {
1810+
self.var_for_def(self.span, param, Some(self.constness()))
1811+
}
18101812
}
18111813
}
18121814
});

0 commit comments

Comments
 (0)