Skip to content

Commit b275d2c

Browse files
committed
Remove WithOptconstParam.
1 parent 0e017fc commit b275d2c

File tree

68 files changed

+332
-957
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+332
-957
lines changed

compiler/rustc_borrowck/src/consumers.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_hir::def_id::LocalDefId;
66
use rustc_index::vec::IndexSlice;
77
use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt};
88
use rustc_middle::mir::Body;
9-
use rustc_middle::ty::{self, TyCtxt};
9+
use rustc_middle::ty::TyCtxt;
1010

1111
pub use super::{
1212
facts::{AllFacts as PoloniusInput, RustcFacts},
@@ -28,12 +28,9 @@ pub use super::{
2828
/// that shows how to do this at `tests/run-make/obtain-borrowck/`.
2929
///
3030
/// * Polonius is highly unstable, so expect regular changes in its signature or other details.
31-
pub fn get_body_with_borrowck_facts(
32-
tcx: TyCtxt<'_>,
33-
def: ty::WithOptConstParam<LocalDefId>,
34-
) -> BodyWithBorrowckFacts<'_> {
31+
pub fn get_body_with_borrowck_facts(tcx: TyCtxt<'_>, def: LocalDefId) -> BodyWithBorrowckFacts<'_> {
3532
let (input_body, promoted) = tcx.mir_promoted(def);
36-
let infcx = tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(def.did)).build();
33+
let infcx = tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(def)).build();
3734
let input_body: &Body<'_> = &input_body.borrow();
3835
let promoted: &IndexSlice<_, _> = &promoted.borrow();
3936
*super::do_mir_borrowck(&infcx, input_body, promoted, true).1.unwrap()

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_middle::mir::{
1919
FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef,
2020
ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm,
2121
};
22-
use rustc_middle::ty::{self, suggest_constraining_type_params, PredicateKind, Ty, TypeckResults};
22+
use rustc_middle::ty::{self, suggest_constraining_type_params, PredicateKind, Ty};
2323
use rustc_middle::util::CallKind;
2424
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
2525
use rustc_span::def_id::LocalDefId;
@@ -1350,8 +1350,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13501350
finder.visit_expr(body_expr);
13511351
let Some((closure_expr, closure)) = finder.res else { return };
13521352

1353-
let typeck_results: &TypeckResults<'_> =
1354-
tcx.typeck_opt_const_arg(self.body.source.with_opt_param().as_local().unwrap());
1353+
let typeck_results = tcx.typeck(self.mir_def_id());
13551354

13561355
// Check that the parent of the closure is a method call,
13571356
// with receiver matching with local's type (modulo refs)

compiler/rustc_borrowck/src/lib.rs

+9-21
Original file line numberDiff line numberDiff line change
@@ -119,24 +119,12 @@ impl<'tcx> TyCtxtConsts<'tcx> {
119119
}
120120

121121
pub fn provide(providers: &mut Providers) {
122-
*providers = Providers {
123-
mir_borrowck: |tcx, did| {
124-
if let Some(def) = ty::WithOptConstParam::try_lookup(did, tcx) {
125-
tcx.mir_borrowck_const_arg(def)
126-
} else {
127-
mir_borrowck(tcx, ty::WithOptConstParam::unknown(did))
128-
}
129-
},
130-
mir_borrowck_const_arg: |tcx, (did, param_did)| {
131-
mir_borrowck(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) })
132-
},
133-
..*providers
134-
};
122+
*providers = Providers { mir_borrowck, ..*providers };
135123
}
136124

137-
fn mir_borrowck(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> &BorrowCheckResult<'_> {
125+
fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
138126
let (input_body, promoted) = tcx.mir_promoted(def);
139-
debug!("run query mir_borrowck: {}", tcx.def_path_str(def.did.to_def_id()));
127+
debug!("run query mir_borrowck: {}", tcx.def_path_str(def.to_def_id()));
140128

141129
if input_body.borrow().should_skip() {
142130
debug!("Skipping borrowck because of injected body");
@@ -150,7 +138,7 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> &Bor
150138
return tcx.arena.alloc(result);
151139
}
152140

153-
let hir_owner = tcx.hir().local_def_id_to_hir_id(def.did).owner;
141+
let hir_owner = tcx.hir().local_def_id_to_hir_id(def).owner;
154142

155143
let infcx =
156144
tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(hir_owner.def_id)).build();
@@ -167,19 +155,19 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> &Bor
167155
/// If `return_body_with_facts` is true, then return the body with non-erased
168156
/// region ids on which the borrow checking was performed together with Polonius
169157
/// facts.
170-
#[instrument(skip(infcx, input_body, input_promoted), fields(id=?input_body.source.with_opt_param().as_local().unwrap()), level = "debug")]
158+
#[instrument(skip(infcx, input_body, input_promoted), fields(id=?input_body.source.def_id()), level = "debug")]
171159
fn do_mir_borrowck<'tcx>(
172160
infcx: &InferCtxt<'tcx>,
173161
input_body: &Body<'tcx>,
174162
input_promoted: &IndexSlice<Promoted, Body<'tcx>>,
175163
return_body_with_facts: bool,
176164
) -> (BorrowCheckResult<'tcx>, Option<Box<BodyWithBorrowckFacts<'tcx>>>) {
177-
let def = input_body.source.with_opt_param().as_local().unwrap();
165+
let def = input_body.source.def_id().expect_local();
178166
debug!(?def);
179167

180168
let tcx = infcx.tcx;
181169
let infcx = BorrowckInferCtxt::new(infcx);
182-
let param_env = tcx.param_env(def.did);
170+
let param_env = tcx.param_env(def);
183171

184172
let mut local_names = IndexVec::from_elem(None, &input_body.local_decls);
185173
for var_debug_info in &input_body.var_debug_info {
@@ -207,7 +195,7 @@ fn do_mir_borrowck<'tcx>(
207195
errors.set_tainted_by_errors(e);
208196
}
209197
let upvars: Vec<_> = tcx
210-
.closure_captures(def.did)
198+
.closure_captures(def)
211199
.iter()
212200
.map(|&captured_place| {
213201
let capture = captured_place.info.capture_kind;
@@ -249,7 +237,7 @@ fn do_mir_borrowck<'tcx>(
249237
.iterate_to_fixpoint()
250238
.into_results_cursor(&body);
251239

252-
let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind(def.did).is_fn_or_closure();
240+
let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind(def).is_fn_or_closure();
253241
let borrow_set =
254242
Rc::new(BorrowSet::build(tcx, body, locals_are_invalidated_at_exit, &mdpe.move_data));
255243

compiler/rustc_borrowck/src/nll.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub(crate) fn replace_regions_in_mir<'tcx>(
6161
body: &mut Body<'tcx>,
6262
promoted: &mut IndexSlice<Promoted, Body<'tcx>>,
6363
) -> UniversalRegions<'tcx> {
64-
let def = body.source.with_opt_param().as_local().unwrap();
64+
let def = body.source.def_id().expect_local();
6565

6666
debug!(?def);
6767

compiler/rustc_borrowck/src/type_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
394394
self.cx.ascribe_user_type(
395395
constant.literal.ty(),
396396
UserType::TypeOf(
397-
uv.def.did,
397+
uv.def,
398398
UserSubsts { substs: uv.substs, user_self_ty: None },
399399
),
400400
locations.span(&self.cx.body),
@@ -1766,7 +1766,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
17661766
if let Some(uv) = maybe_uneval {
17671767
if uv.promoted.is_none() {
17681768
let tcx = self.tcx();
1769-
let def_id = uv.def.def_id_for_type_of();
1769+
let def_id = uv.def;
17701770
if tcx.def_kind(def_id) == DefKind::InlineConst {
17711771
let def_id = def_id.expect_local();
17721772
let predicates =

compiler/rustc_borrowck/src/universal_regions.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl<'tcx> UniversalRegions<'tcx> {
226226
/// known between those regions.
227227
pub fn new(
228228
infcx: &BorrowckInferCtxt<'_, 'tcx>,
229-
mir_def: ty::WithOptConstParam<LocalDefId>,
229+
mir_def: LocalDefId,
230230
param_env: ty::ParamEnv<'tcx>,
231231
) -> Self {
232232
UniversalRegionsBuilder { infcx, mir_def, param_env }.build()
@@ -388,7 +388,7 @@ impl<'tcx> UniversalRegions<'tcx> {
388388

389389
struct UniversalRegionsBuilder<'cx, 'tcx> {
390390
infcx: &'cx BorrowckInferCtxt<'cx, 'tcx>,
391-
mir_def: ty::WithOptConstParam<LocalDefId>,
391+
mir_def: LocalDefId,
392392
param_env: ty::ParamEnv<'tcx>,
393393
}
394394

@@ -417,12 +417,12 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
417417
let mut indices = self.compute_indices(fr_static, defining_ty);
418418
debug!("build: indices={:?}", indices);
419419

420-
let typeck_root_def_id = self.infcx.tcx.typeck_root_def_id(self.mir_def.did.to_def_id());
420+
let typeck_root_def_id = self.infcx.tcx.typeck_root_def_id(self.mir_def.to_def_id());
421421

422422
// If this is a 'root' body (not a closure/generator/inline const), then
423423
// there are no extern regions, so the local regions start at the same
424424
// position as the (empty) sub-list of extern regions
425-
let first_local_index = if self.mir_def.did.to_def_id() == typeck_root_def_id {
425+
let first_local_index = if self.mir_def.to_def_id() == typeck_root_def_id {
426426
first_extern_index
427427
} else {
428428
// If this is a closure, generator, or inline-const, then the late-bound regions from the enclosing
@@ -433,7 +433,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
433433
// }
434434
for_each_late_bound_region_in_recursive_scope(
435435
self.infcx.tcx,
436-
self.infcx.tcx.local_parent(self.mir_def.did),
436+
self.infcx.tcx.local_parent(self.mir_def),
437437
|r| {
438438
debug!(?r);
439439
if !indices.indices.contains_key(&r) {
@@ -462,13 +462,13 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
462462

463463
let inputs_and_output = self.infcx.replace_bound_regions_with_nll_infer_vars(
464464
FR,
465-
self.mir_def.did,
465+
self.mir_def,
466466
bound_inputs_and_output,
467467
&mut indices,
468468
);
469469
// Converse of above, if this is a function/closure then the late-bound regions declared on its
470470
// signature are local.
471-
for_each_late_bound_region_in_item(self.infcx.tcx, self.mir_def.did, |r| {
471+
for_each_late_bound_region_in_item(self.infcx.tcx, self.mir_def, |r| {
472472
debug!(?r);
473473
if !indices.indices.contains_key(&r) {
474474
let region_vid = {
@@ -492,7 +492,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
492492
if self.infcx.tcx.fn_sig(def_id).skip_binder().c_variadic() {
493493
let va_list_did = self.infcx.tcx.require_lang_item(
494494
LangItem::VaList,
495-
Some(self.infcx.tcx.def_span(self.mir_def.did)),
495+
Some(self.infcx.tcx.def_span(self.mir_def)),
496496
);
497497

498498
let reg_vid = self
@@ -544,11 +544,11 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
544544
/// see `DefiningTy` for details.
545545
fn defining_ty(&self) -> DefiningTy<'tcx> {
546546
let tcx = self.infcx.tcx;
547-
let typeck_root_def_id = tcx.typeck_root_def_id(self.mir_def.did.to_def_id());
547+
let typeck_root_def_id = tcx.typeck_root_def_id(self.mir_def.to_def_id());
548548

549-
match tcx.hir().body_owner_kind(self.mir_def.did) {
549+
match tcx.hir().body_owner_kind(self.mir_def) {
550550
BodyOwnerKind::Closure | BodyOwnerKind::Fn => {
551-
let defining_ty = tcx.type_of(self.mir_def.def_id_for_type_of()).subst_identity();
551+
let defining_ty = tcx.type_of(self.mir_def).subst_identity();
552552

553553
debug!("defining_ty (pre-replacement): {:?}", defining_ty);
554554

@@ -562,20 +562,20 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
562562
}
563563
ty::FnDef(def_id, substs) => DefiningTy::FnDef(def_id, substs),
564564
_ => span_bug!(
565-
tcx.def_span(self.mir_def.did),
565+
tcx.def_span(self.mir_def),
566566
"expected defining type for `{:?}`: `{:?}`",
567-
self.mir_def.did,
567+
self.mir_def,
568568
defining_ty
569569
),
570570
}
571571
}
572572

573573
BodyOwnerKind::Const | BodyOwnerKind::Static(..) => {
574574
let identity_substs = InternalSubsts::identity_for_item(tcx, typeck_root_def_id);
575-
if self.mir_def.did.to_def_id() == typeck_root_def_id {
575+
if self.mir_def.to_def_id() == typeck_root_def_id {
576576
let substs =
577577
self.infcx.replace_free_regions_with_nll_infer_vars(FR, identity_substs);
578-
DefiningTy::Const(self.mir_def.did.to_def_id(), substs)
578+
DefiningTy::Const(self.mir_def.to_def_id(), substs)
579579
} else {
580580
// FIXME this line creates a dependency between borrowck and typeck.
581581
//
@@ -587,15 +587,15 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
587587
// below), so that `type_of(inline_const_def_id).substs(substs)` uses the
588588
// proper type with NLL infer vars.
589589
let ty = tcx
590-
.typeck(self.mir_def.did)
591-
.node_type(tcx.local_def_id_to_hir_id(self.mir_def.did));
590+
.typeck(self.mir_def)
591+
.node_type(tcx.local_def_id_to_hir_id(self.mir_def));
592592
let substs = InlineConstSubsts::new(
593593
tcx,
594594
InlineConstSubstsParts { parent_substs: identity_substs, ty },
595595
)
596596
.substs;
597597
let substs = self.infcx.replace_free_regions_with_nll_infer_vars(FR, substs);
598-
DefiningTy::InlineConst(self.mir_def.did.to_def_id(), substs)
598+
DefiningTy::InlineConst(self.mir_def.to_def_id(), substs)
599599
}
600600
}
601601
}
@@ -611,7 +611,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
611611
defining_ty: DefiningTy<'tcx>,
612612
) -> UniversalRegionIndices<'tcx> {
613613
let tcx = self.infcx.tcx;
614-
let typeck_root_def_id = tcx.typeck_root_def_id(self.mir_def.did.to_def_id());
614+
let typeck_root_def_id = tcx.typeck_root_def_id(self.mir_def.to_def_id());
615615
let identity_substs = InternalSubsts::identity_for_item(tcx, typeck_root_def_id);
616616
let fr_substs = match defining_ty {
617617
DefiningTy::Closure(_, substs)
@@ -647,7 +647,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
647647
let tcx = self.infcx.tcx;
648648
match defining_ty {
649649
DefiningTy::Closure(def_id, substs) => {
650-
assert_eq!(self.mir_def.did.to_def_id(), def_id);
650+
assert_eq!(self.mir_def.to_def_id(), def_id);
651651
let closure_sig = substs.as_closure().sig();
652652
let inputs_and_output = closure_sig.inputs_and_output();
653653
let bound_vars = tcx.mk_bound_variable_kinds_from_iter(
@@ -682,7 +682,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
682682
}
683683

684684
DefiningTy::Generator(def_id, substs, movability) => {
685-
assert_eq!(self.mir_def.did.to_def_id(), def_id);
685+
assert_eq!(self.mir_def.to_def_id(), def_id);
686686
let resume_ty = substs.as_generator().resume_ty();
687687
let output = substs.as_generator().return_ty();
688688
let generator_ty = tcx.mk_generator(def_id, substs, movability);
@@ -700,14 +700,14 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
700700
DefiningTy::Const(def_id, _) => {
701701
// For a constant body, there are no inputs, and one
702702
// "output" (the type of the constant).
703-
assert_eq!(self.mir_def.did.to_def_id(), def_id);
704-
let ty = tcx.type_of(self.mir_def.def_id_for_type_of()).subst_identity();
703+
assert_eq!(self.mir_def.to_def_id(), def_id);
704+
let ty = tcx.type_of(self.mir_def).subst_identity();
705705
let ty = indices.fold_to_region_vids(tcx, ty);
706706
ty::Binder::dummy(tcx.mk_type_list(&[ty]))
707707
}
708708

709709
DefiningTy::InlineConst(def_id, substs) => {
710-
assert_eq!(self.mir_def.did.to_def_id(), def_id);
710+
assert_eq!(self.mir_def.to_def_id(), def_id);
711711
let ty = substs.as_inline_const().ty();
712712
ty::Binder::dummy(tcx.mk_type_list(&[ty]))
713713
}

compiler/rustc_codegen_cranelift/src/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub(crate) fn eval_mir_constant<'tcx>(
9191
),
9292
},
9393
ConstantKind::Unevaluated(mir::UnevaluatedConst { def, .. }, _)
94-
if fx.tcx.is_static(def.did) =>
94+
if fx.tcx.is_static(def) =>
9595
{
9696
span_bug!(constant.span, "MIR constant refers to static");
9797
}

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ fn exported_symbols_provider_local(
333333
match *mono_item {
334334
MonoItem::Fn(Instance { def: InstanceDef::Item(def), substs }) => {
335335
if substs.non_erasable_generics().next().is_some() {
336-
let symbol = ExportedSymbol::Generic(def.did, substs);
336+
let symbol = ExportedSymbol::Generic(def, substs);
337337
symbols.push((
338338
symbol,
339339
SymbolExportInfo {

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,12 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
296296
}
297297

298298
let cid = key.value;
299-
let def = cid.instance.def.with_opt_param();
300-
let is_static = tcx.is_static(def.did);
299+
let def = cid.instance.def.def_id();
300+
let is_static = tcx.is_static(def);
301301

302302
let mut ecx = InterpCx::new(
303303
tcx,
304-
tcx.def_span(def.did),
304+
tcx.def_span(def),
305305
key.param_env,
306306
// Statics (and promoteds inside statics) may access other statics, because unlike consts
307307
// they do not have to behave "as if" they were evaluated at runtime.

compiler/rustc_const_eval/src/const_eval/machine.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,9 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
375375
) -> InterpResult<'tcx, &'tcx mir::Body<'tcx>> {
376376
match instance {
377377
ty::InstanceDef::Item(def) => {
378-
if ecx.tcx.is_ctfe_mir_available(def.did) {
379-
Ok(ecx.tcx.mir_for_ctfe_opt_const_arg(def))
380-
} else if ecx.tcx.def_kind(def.did) == DefKind::AssocConst {
378+
if ecx.tcx.is_ctfe_mir_available(def) {
379+
Ok(ecx.tcx.mir_for_ctfe(def))
380+
} else if ecx.tcx.def_kind(def) == DefKind::AssocConst {
381381
let guar = ecx.tcx.sess.delay_span_bug(
382382
rustc_span::DUMMY_SP,
383383
"This is likely a const item that is missing from its impl",
@@ -386,7 +386,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
386386
} else {
387387
// `find_mir_or_eval_fn` checks that this is a const fn before even calling us,
388388
// so this should be unreachable.
389-
let path = ecx.tcx.def_path_str(def.did);
389+
let path = ecx.tcx.def_path_str(def);
390390
bug!("trying to call extern function `{path}` at compile-time");
391391
}
392392
}
@@ -410,9 +410,9 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
410410
// Execution might have wandered off into other crates, so we cannot do a stability-
411411
// sensitive check here. But we can at least rule out functions that are not const
412412
// at all.
413-
if !ecx.tcx.is_const_fn_raw(def.did) {
413+
if !ecx.tcx.is_const_fn_raw(def) {
414414
// allow calling functions inside a trait marked with #[const_trait].
415-
if !ecx.tcx.is_const_default_method(def.did) {
415+
if !ecx.tcx.is_const_default_method(def) {
416416
// We certainly do *not* want to actually call the fn
417417
// though, so be sure we return here.
418418
throw_unsup_format!("calling non-const function `{}`", instance)

0 commit comments

Comments
 (0)