Skip to content

Commit 71bcd35

Browse files
oli-obkfee1-dead
authored andcommitted
Stop appending constness to all substs
1 parent 1727172 commit 71bcd35

File tree

5 files changed

+29
-24
lines changed

5 files changed

+29
-24
lines changed

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11991199
});
12001200
self.tcx.mk_const_var(const_var_id, self.tcx.type_of(param.def_id)).into()
12011201
}
1202+
// TODO: this should actually figure out a yes/no answer from the context
12021203
GenericParamDefKind::Constness => ty::ConstnessArg::Param.into(),
12031204
}
12041205
}

compiler/rustc_typeck/src/astconv/generics.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
225225
if let Some(&param) = params.peek() {
226226
if param.index == 0 {
227227
if let GenericParamDefKind::Type { .. } = param.kind {
228-
substs.push(
229-
self_ty
230-
.map(|ty| ty.into())
231-
.unwrap_or_else(|| ctx.inferred_kind(None, param, true)),
232-
);
228+
substs.push(self_ty.map(|ty| ty.into()).unwrap_or_else(|| {
229+
ctx.inferred_kind(None, param, true, constness)
230+
}));
233231
params.next();
234232
}
235233
}
@@ -278,7 +276,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
278276
) => {
279277
// We expected a lifetime argument, but got a type or const
280278
// argument. That means we're inferring the lifetimes.
281-
substs.push(ctx.inferred_kind(None, param, infer_args));
279+
substs.push(ctx.inferred_kind(None, param, infer_args, constness));
282280
force_infer_lt = Some((arg, param));
283281
params.next();
284282
}
@@ -375,7 +373,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
375373
(None, Some(&param)) => {
376374
// If there are fewer arguments than parameters, it means
377375
// we're inferring the remaining arguments.
378-
substs.push(ctx.inferred_kind(Some(&substs), param, infer_args));
376+
substs.push(ctx.inferred_kind(Some(&substs), param, infer_args, constness));
379377
params.next();
380378
}
381379

@@ -384,8 +382,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
384382
}
385383
}
386384

387-
substs.extend(constness.map(Into::into));
388-
389385
tcx.intern_substs(&substs)
390386
}
391387

compiler/rustc_typeck/src/astconv/mod.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ pub trait CreateSubstsForGenericArgsCtxt<'a, 'tcx> {
196196
substs: Option<&[subst::GenericArg<'tcx>]>,
197197
param: &ty::GenericParamDef,
198198
infer_args: bool,
199+
constness: Option<ty::ConstnessArg>,
199200
) -> subst::GenericArg<'tcx>;
200201
}
201202

@@ -492,6 +493,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
492493
substs: Option<&[subst::GenericArg<'tcx>]>,
493494
param: &ty::GenericParamDef,
494495
infer_args: bool,
496+
constness: Option<ty::ConstnessArg>,
495497
) -> subst::GenericArg<'tcx> {
496498
let tcx = self.astconv.tcx();
497499
match param.kind {
@@ -568,21 +570,22 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
568570
}
569571
}
570572
GenericParamDefKind::Constness => {
571-
match self.astconv.item_def_id() {
572-
// no information available
573-
// TODO: fall back to `Not`?
574-
None => ty::ConstnessArg::Param,
575-
Some(context) => {
576-
if tcx.generics_of(context).has_constness_param() {
577-
ty::ConstnessArg::Param
578-
} else {
579-
// TODO: should use `Required` if we're in a const context
580-
// like `const`/`static` item initializers.
581-
ty::ConstnessArg::Not
573+
constness
574+
.unwrap_or_else(|| match self.astconv.item_def_id() {
575+
// no information available
576+
// TODO: fall back to `Not`?
577+
None => ty::ConstnessArg::Param,
578+
Some(context) => {
579+
if tcx.generics_of(context).has_constness_param() {
580+
ty::ConstnessArg::Param
581+
} else {
582+
// TODO: should use `Required` if we're in a const context
583+
// like `const`/`static` item initializers.
584+
ty::ConstnessArg::Not
585+
}
582586
}
583-
}
584-
}
585-
.into()
587+
})
588+
.into()
586589
}
587590
}
588591
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14091409
substs: Option<&[subst::GenericArg<'tcx>]>,
14101410
param: &ty::GenericParamDef,
14111411
infer_args: bool,
1412+
constness: Option<ty::ConstnessArg>,
14121413
) -> subst::GenericArg<'tcx> {
14131414
let tcx = self.fcx.tcx();
14141415
match param.kind {
@@ -1441,7 +1442,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14411442
self.fcx.var_for_def(self.span, param)
14421443
}
14431444
}
1444-
GenericParamDefKind::Constness => self.fcx.var_for_def(self.span, param),
1445+
GenericParamDefKind::Constness => match constness {
1446+
None => self.fcx.var_for_def(self.span, param),
1447+
Some(constness) => constness.into(),
1448+
},
14451449
}
14461450
}
14471451
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
397397
_substs: Option<&[subst::GenericArg<'tcx>]>,
398398
param: &ty::GenericParamDef,
399399
_infer_args: bool,
400+
_constness: Option<ty::ConstnessArg>,
400401
) -> subst::GenericArg<'tcx> {
401402
self.cfcx.var_for_def(self.cfcx.span, param)
402403
}

0 commit comments

Comments
 (0)