Skip to content

Commit a1c076f

Browse files
authored
Rollup merge of #74027 - lcnr:ConstCx-local-def-id, r=varkor
Convert more `DefId`s to `LocalDefId`s
2 parents aef2ca6 + f5305c3 commit a1c076f

File tree

11 files changed

+40
-49
lines changed

11 files changed

+40
-49
lines changed

src/librustc_mir/borrow_check/type_check/input_output.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
122122
if let Err(terr) = self.eq_opaque_type_and_type(
123123
mir_output_ty,
124124
normalized_output_ty,
125-
self.mir_def_id.to_def_id(),
125+
self.mir_def_id,
126126
Locations::All(output_span),
127127
ConstraintCategory::BoringNoLocation,
128128
) {
@@ -145,7 +145,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
145145
if let Err(err) = self.eq_opaque_type_and_type(
146146
mir_output_ty,
147147
user_provided_output_ty,
148-
self.mir_def_id.to_def_id(),
148+
self.mir_def_id,
149149
Locations::All(output_span),
150150
ConstraintCategory::BoringNoLocation,
151151
) {

src/librustc_mir/borrow_check/type_check/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
11441144
// When you have `let x: impl Foo = ...` in a closure,
11451145
// the resulting inferend values are stored with the
11461146
// def-id of the base function.
1147-
let parent_def_id = self.tcx().closure_base_def_id(self.mir_def_id.to_def_id());
1147+
let parent_def_id =
1148+
self.tcx().closure_base_def_id(self.mir_def_id.to_def_id()).expect_local();
11481149
return self.eq_opaque_type_and_type(sub, sup, parent_def_id, locations, category);
11491150
} else {
11501151
return Err(terr);
@@ -1208,7 +1209,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12081209
&mut self,
12091210
revealed_ty: Ty<'tcx>,
12101211
anon_ty: Ty<'tcx>,
1211-
anon_owner_def_id: DefId,
1212+
anon_owner_def_id: LocalDefId,
12121213
locations: Locations,
12131214
category: ConstraintCategory,
12141215
) -> Fallible<()> {
@@ -1238,8 +1239,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12381239
let tcx = infcx.tcx;
12391240
let param_env = self.param_env;
12401241
let body = self.body;
1241-
let concrete_opaque_types =
1242-
&tcx.typeck_tables_of(anon_owner_def_id.expect_local()).concrete_opaque_types;
1242+
let concrete_opaque_types = &tcx.typeck_tables_of(anon_owner_def_id).concrete_opaque_types;
12431243
let mut opaque_type_values = Vec::new();
12441244

12451245
debug!("eq_opaque_type_and_type: mir_def_id={:?}", self.mir_def_id);

src/librustc_mir/const_eval/eval_queries.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,9 @@ pub fn const_eval_raw_provider<'tcx>(
334334
}
335335

336336
v
337-
} else if def_id.is_local() {
337+
} else if let Some(def_id) = def_id.as_local() {
338338
// constant defined in this crate, we can figure out a lint level!
339-
match tcx.def_kind(def_id) {
339+
match tcx.def_kind(def_id.to_def_id()) {
340340
// constants never produce a hard error at the definition site. Anything else is
341341
// a backwards compatibility hazard (and will break old versions of winapi for
342342
// sure)
@@ -346,7 +346,7 @@ pub fn const_eval_raw_provider<'tcx>(
346346
// validation thus preventing such a hard error from being a backwards
347347
// compatibility hazard
348348
DefKind::Const | DefKind::AssocConst => {
349-
let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
349+
let hir_id = tcx.hir().as_local_hir_id(def_id);
350350
err.report_as_lint(
351351
tcx.at(tcx.def_span(def_id)),
352352
"any use of this value will cause an error",
@@ -369,7 +369,7 @@ pub fn const_eval_raw_provider<'tcx>(
369369
err.report_as_lint(
370370
tcx.at(span),
371371
"reaching this expression at runtime will panic or abort",
372-
tcx.hir().as_local_hir_id(def_id.expect_local()),
372+
tcx.hir().as_local_hir_id(def_id),
373373
Some(err.span),
374374
)
375375
}

src/librustc_mir/transform/check_consts/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub mod validation;
2222
pub struct ConstCx<'mir, 'tcx> {
2323
pub body: &'mir mir::Body<'tcx>,
2424
pub tcx: TyCtxt<'tcx>,
25-
pub def_id: DefId,
25+
pub def_id: LocalDefId,
2626
pub param_env: ty::ParamEnv<'tcx>,
2727
pub const_kind: Option<hir::ConstContext>,
2828
}
@@ -40,7 +40,7 @@ impl ConstCx<'mir, 'tcx> {
4040
param_env: ty::ParamEnv<'tcx>,
4141
) -> Self {
4242
let const_kind = tcx.hir().body_const_context(def_id);
43-
ConstCx { body, tcx, def_id: def_id.to_def_id(), param_env, const_kind }
43+
ConstCx { body, tcx, def_id: def_id, param_env, const_kind }
4444
}
4545

4646
/// Returns the kind of const context this `Item` represents (`const`, `static`, etc.).

src/librustc_mir/transform/check_consts/post_drop_elaboration.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,7 @@ pub fn check_live_drops(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &mir::Body<
2929
return;
3030
}
3131

32-
let ccx = ConstCx {
33-
body,
34-
tcx,
35-
def_id: def_id.to_def_id(),
36-
const_kind,
37-
param_env: tcx.param_env(def_id),
38-
};
32+
let ccx = ConstCx { body, tcx, def_id, const_kind, param_env: tcx.param_env(def_id) };
3933

4034
let mut visitor = CheckLiveDrops { ccx: &ccx, qualifs: Qualifs::default() };
4135

src/librustc_mir/transform/check_consts/qualifs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl Qualif for CustomEq {
126126
// because that component may be part of an enum variant (e.g.,
127127
// `Option::<NonStructuralMatchTy>::Some`), in which case some values of this type may be
128128
// structural-match (`Option::None`).
129-
let id = cx.tcx.hir().local_def_id_to_hir_id(cx.def_id.as_local().unwrap());
129+
let id = cx.tcx.hir().local_def_id_to_hir_id(cx.def_id);
130130
traits::search_for_structural_match_violation(id, cx.body.span, cx.tcx, ty).is_some()
131131
}
132132

src/librustc_mir/transform/check_consts/validation.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl Qualifs<'mir, 'tcx> {
5656
// without breaking stable code?
5757
MaybeMutBorrowedLocals::mut_borrows_only(tcx, &body, param_env)
5858
.unsound_ignore_borrow_on_drop()
59-
.into_engine(tcx, &body, def_id)
59+
.into_engine(tcx, &body, def_id.to_def_id())
6060
.iterate_to_fixpoint()
6161
.into_results_cursor(&body)
6262
});
@@ -83,7 +83,7 @@ impl Qualifs<'mir, 'tcx> {
8383
let ConstCx { tcx, body, def_id, .. } = *ccx;
8484

8585
FlowSensitiveAnalysis::new(NeedsDrop, ccx)
86-
.into_engine(tcx, &body, def_id)
86+
.into_engine(tcx, &body, def_id.to_def_id())
8787
.iterate_to_fixpoint()
8888
.into_results_cursor(&body)
8989
});
@@ -110,7 +110,7 @@ impl Qualifs<'mir, 'tcx> {
110110
let ConstCx { tcx, body, def_id, .. } = *ccx;
111111

112112
FlowSensitiveAnalysis::new(HasMutInterior, ccx)
113-
.into_engine(tcx, &body, def_id)
113+
.into_engine(tcx, &body, def_id.to_def_id())
114114
.iterate_to_fixpoint()
115115
.into_results_cursor(&body)
116116
});
@@ -153,7 +153,7 @@ impl Qualifs<'mir, 'tcx> {
153153

154154
hir::ConstContext::Const | hir::ConstContext::Static(_) => {
155155
let mut cursor = FlowSensitiveAnalysis::new(CustomEq, ccx)
156-
.into_engine(ccx.tcx, &ccx.body, ccx.def_id)
156+
.into_engine(ccx.tcx, &ccx.body, ccx.def_id.to_def_id())
157157
.iterate_to_fixpoint()
158158
.into_results_cursor(&ccx.body);
159159

@@ -195,13 +195,13 @@ impl Validator<'mir, 'tcx> {
195195
let ConstCx { tcx, body, def_id, const_kind, .. } = *self.ccx;
196196

197197
let use_min_const_fn_checks = (const_kind == Some(hir::ConstContext::ConstFn)
198-
&& crate::const_eval::is_min_const_fn(tcx, def_id))
198+
&& crate::const_eval::is_min_const_fn(tcx, def_id.to_def_id()))
199199
&& !tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you;
200200

201201
if use_min_const_fn_checks {
202202
// Enforce `min_const_fn` for stable `const fn`s.
203203
use crate::transform::qualify_min_const_fn::is_min_const_fn;
204-
if let Err((span, err)) = is_min_const_fn(tcx, def_id, &body) {
204+
if let Err((span, err)) = is_min_const_fn(tcx, def_id.to_def_id(), &body) {
205205
error_min_const_fn_violation(tcx, span, err);
206206
return;
207207
}
@@ -212,10 +212,10 @@ impl Validator<'mir, 'tcx> {
212212
// Ensure that the end result is `Sync` in a non-thread local `static`.
213213
let should_check_for_sync = const_kind
214214
== Some(hir::ConstContext::Static(hir::Mutability::Not))
215-
&& !tcx.is_thread_local_static(def_id);
215+
&& !tcx.is_thread_local_static(def_id.to_def_id());
216216

217217
if should_check_for_sync {
218-
let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
218+
let hir_id = tcx.hir().as_local_hir_id(def_id);
219219
check_return_ty_is_sync(tcx, &body, hir_id);
220220
}
221221
}
@@ -535,7 +535,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
535535
// `#[allow_internal_unstable]`.
536536
use crate::transform::qualify_min_const_fn::lib_feature_allowed;
537537
if !self.span.allows_unstable(feature)
538-
&& !lib_feature_allowed(self.tcx, self.def_id, feature)
538+
&& !lib_feature_allowed(self.tcx, self.def_id.to_def_id(), feature)
539539
{
540540
self.check_op(ops::FnCallUnstable(def_id, feature));
541541
}

src/librustc_mir/transform/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ pub fn run_passes(
203203
}
204204

205205
fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs {
206-
let const_kind = tcx.hir().body_const_context(def_id.expect_local());
206+
let def_id = def_id.expect_local();
207+
let const_kind = tcx.hir().body_const_context(def_id);
207208

208209
// No need to const-check a non-const `fn`.
209210
if const_kind.is_none() {
@@ -214,7 +215,7 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs {
214215
// cannot yet be stolen), because `mir_validated()`, which steals
215216
// from `mir_const(), forces this query to execute before
216217
// performing the steal.
217-
let body = &tcx.mir_const(def_id).borrow();
218+
let body = &tcx.mir_const(def_id.to_def_id()).borrow();
218219

219220
if body.return_ty().references_error() {
220221
tcx.sess.delay_span_bug(body.span, "mir_const_qualif: MIR had errors");

src/librustc_mir/transform/promote_consts.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,16 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {
6060
return;
6161
}
6262

63-
let def_id = src.def_id();
63+
let def_id = src.def_id().expect_local();
6464

6565
let mut rpo = traversal::reverse_postorder(body);
66-
let ccx = ConstCx::new(tcx, def_id.expect_local(), body);
66+
let ccx = ConstCx::new(tcx, def_id, body);
6767
let (temps, all_candidates) = collect_temps_and_candidates(&ccx, &mut rpo);
6868

6969
let promotable_candidates = validate_candidates(&ccx, &temps, &all_candidates);
7070

71-
let promoted = promote_candidates(def_id, body, tcx, temps, promotable_candidates);
71+
let promoted =
72+
promote_candidates(def_id.to_def_id(), body, tcx, temps, promotable_candidates);
7273
self.promoted_fragments.set(promoted);
7374
}
7475
}
@@ -724,7 +725,7 @@ impl<'tcx> Validator<'_, 'tcx> {
724725
ty::FnDef(def_id, _) => {
725726
is_const_fn(self.tcx, def_id)
726727
|| is_unstable_const_fn(self.tcx, def_id).is_some()
727-
|| is_lang_panic_fn(self.tcx, self.def_id)
728+
|| is_lang_panic_fn(self.tcx, self.def_id.to_def_id())
728729
}
729730
_ => false,
730731
};

src/librustc_trait_selection/opaque_types.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub enum GenerateMemberConstraints {
108108
pub trait InferCtxtExt<'tcx> {
109109
fn instantiate_opaque_types<T: TypeFoldable<'tcx>>(
110110
&self,
111-
parent_def_id: DefId,
111+
parent_def_id: LocalDefId,
112112
body_id: hir::HirId,
113113
param_env: ty::ParamEnv<'tcx>,
114114
value: &T,
@@ -184,7 +184,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
184184
/// - `value_span` -- the span where the value came from, used in error reporting
185185
fn instantiate_opaque_types<T: TypeFoldable<'tcx>>(
186186
&self,
187-
parent_def_id: DefId,
187+
parent_def_id: LocalDefId,
188188
body_id: hir::HirId,
189189
param_env: ty::ParamEnv<'tcx>,
190190
value: &T,
@@ -986,7 +986,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
986986

987987
struct Instantiator<'a, 'tcx> {
988988
infcx: &'a InferCtxt<'a, 'tcx>,
989-
parent_def_id: DefId,
989+
parent_def_id: LocalDefId,
990990
body_id: hir::HirId,
991991
param_env: ty::ParamEnv<'tcx>,
992992
value_span: Span,
@@ -1043,8 +1043,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
10431043
let parent_def_id = self.parent_def_id;
10441044
let def_scope_default = || {
10451045
let opaque_parent_hir_id = tcx.hir().get_parent_item(opaque_hir_id);
1046-
parent_def_id
1047-
== tcx.hir().local_def_id(opaque_parent_hir_id).to_def_id()
1046+
parent_def_id == tcx.hir().local_def_id(opaque_parent_hir_id)
10481047
};
10491048
let (in_definition_scope, origin) = match tcx.hir().find(opaque_hir_id) {
10501049
Some(Node::Item(item)) => match item.kind {
@@ -1053,18 +1052,14 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
10531052
impl_trait_fn: Some(parent),
10541053
origin,
10551054
..
1056-
}) => (parent == self.parent_def_id, origin),
1055+
}) => (parent == self.parent_def_id.to_def_id(), origin),
10571056
// Named `type Foo = impl Bar;`
10581057
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
10591058
impl_trait_fn: None,
10601059
origin,
10611060
..
10621061
}) => (
1063-
may_define_opaque_type(
1064-
tcx,
1065-
self.parent_def_id.expect_local(),
1066-
opaque_hir_id,
1067-
),
1062+
may_define_opaque_type(tcx, self.parent_def_id, opaque_hir_id),
10681063
origin,
10691064
),
10701065
_ => (def_scope_default(), hir::OpaqueTyOrigin::Misc),

src/librustc_typeck/check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1321,8 +1321,8 @@ fn check_fn<'a, 'tcx>(
13211321
fcx.resume_yield_tys = Some((resume_ty, yield_ty));
13221322
}
13231323

1324-
let outer_def_id = tcx.closure_base_def_id(hir.local_def_id(fn_id).to_def_id());
1325-
let outer_hir_id = hir.as_local_hir_id(outer_def_id.expect_local());
1324+
let outer_def_id = tcx.closure_base_def_id(hir.local_def_id(fn_id).to_def_id()).expect_local();
1325+
let outer_hir_id = hir.as_local_hir_id(outer_def_id);
13261326
GatherLocalsVisitor { fcx: &fcx, parent_id: outer_hir_id }.visit_body(body);
13271327

13281328
// C-variadic fns also have a `VaList` input that's not listed in `fn_sig`
@@ -3427,7 +3427,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
34273427

34283428
let (value, opaque_type_map) =
34293429
self.register_infer_ok_obligations(self.instantiate_opaque_types(
3430-
parent_def_id.to_def_id(),
3430+
parent_def_id,
34313431
self.body_id,
34323432
self.param_env,
34333433
value,

0 commit comments

Comments
 (0)