Skip to content

Commit a32463a

Browse files
Make MIR typeck use LocalDefId and fix docs
1 parent 9912925 commit a32463a

File tree

4 files changed

+50
-54
lines changed

4 files changed

+50
-54
lines changed

src/librustc_mir/borrow_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ fn do_mir_borrowck<'a, 'tcx>(
209209
nll_errors,
210210
} = nll::compute_regions(
211211
infcx,
212-
def_id.to_def_id(),
212+
def_id,
213213
free_regions,
214214
body,
215215
&promoted,

src/librustc_mir/borrow_check/nll.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use rustc_data_structures::fx::FxHashMap;
44
use rustc_errors::Diagnostic;
5-
use rustc_hir::def_id::DefId;
5+
use rustc_hir::def_id::{DefId, LocalDefId};
66
use rustc_index::vec::IndexVec;
77
use rustc_infer::infer::InferCtxt;
88
use rustc_middle::mir::{
@@ -157,7 +157,7 @@ fn populate_polonius_move_facts(
157157
/// This may result in errors being reported.
158158
pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
159159
infcx: &InferCtxt<'cx, 'tcx>,
160-
def_id: DefId,
160+
def_id: LocalDefId,
161161
universal_regions: UniversalRegions<'tcx>,
162162
body: &Body<'tcx>,
163163
promoted: &IndexVec<Promoted, Body<'tcx>>,
@@ -272,7 +272,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
272272
// Dump facts if requested.
273273
let polonius_output = all_facts.and_then(|all_facts| {
274274
if infcx.tcx.sess.opts.debugging_opts.nll_facts {
275-
let def_path = infcx.tcx.def_path(def_id);
275+
let def_path = infcx.tcx.def_path(def_id.to_def_id());
276276
let dir_path =
277277
PathBuf::from("nll-facts").join(def_path.to_filename_friendly_no_crate());
278278
all_facts.write_to_dir(dir_path, location_table).unwrap();
@@ -292,7 +292,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
292292

293293
// Solve the region constraints.
294294
let (closure_region_requirements, nll_errors) =
295-
regioncx.solve(infcx, &body, def_id, polonius_output.clone());
295+
regioncx.solve(infcx, &body, def_id.to_def_id(), polonius_output.clone());
296296

297297
if !nll_errors.is_empty() {
298298
// Suppress unhelpful extra errors in `infer_opaque_types`.

src/librustc_mir/borrow_check/type_check/input_output.rs

+29-27
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,37 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
3333
//
3434
// e.g., `|x: FxHashMap<_, &'static u32>| ...`
3535
let user_provided_sig;
36-
if !self.tcx().is_closure(self.mir_def_id) {
36+
if !self.tcx().is_closure(self.mir_def_id.to_def_id()) {
3737
user_provided_sig = None;
3838
} else {
39-
let typeck_tables = self.tcx().typeck_tables_of(self.mir_def_id.expect_local());
40-
user_provided_sig = match typeck_tables.user_provided_sigs.get(&self.mir_def_id) {
41-
None => None,
42-
Some(user_provided_poly_sig) => {
43-
// Instantiate the canonicalized variables from
44-
// user-provided signature (e.g., the `_` in the code
45-
// above) with fresh variables.
46-
let (poly_sig, _) = self.infcx.instantiate_canonical_with_fresh_inference_vars(
47-
body.span,
48-
&user_provided_poly_sig,
49-
);
50-
51-
// Replace the bound items in the fn sig with fresh
52-
// variables, so that they represent the view from
53-
// "inside" the closure.
54-
Some(
55-
self.infcx
56-
.replace_bound_vars_with_fresh_vars(
39+
let typeck_tables = self.tcx().typeck_tables_of(self.mir_def_id);
40+
user_provided_sig =
41+
match typeck_tables.user_provided_sigs.get(&self.mir_def_id.to_def_id()) {
42+
None => None,
43+
Some(user_provided_poly_sig) => {
44+
// Instantiate the canonicalized variables from
45+
// user-provided signature (e.g., the `_` in the code
46+
// above) with fresh variables.
47+
let (poly_sig, _) =
48+
self.infcx.instantiate_canonical_with_fresh_inference_vars(
5749
body.span,
58-
LateBoundRegionConversionTime::FnCall,
59-
&poly_sig,
60-
)
61-
.0,
62-
)
50+
&user_provided_poly_sig,
51+
);
52+
53+
// Replace the bound items in the fn sig with fresh
54+
// variables, so that they represent the view from
55+
// "inside" the closure.
56+
Some(
57+
self.infcx
58+
.replace_bound_vars_with_fresh_vars(
59+
body.span,
60+
LateBoundRegionConversionTime::FnCall,
61+
&poly_sig,
62+
)
63+
.0,
64+
)
65+
}
6366
}
64-
}
6567
};
6668

6769
debug!(
@@ -120,7 +122,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
120122
if let Err(terr) = self.eq_opaque_type_and_type(
121123
mir_output_ty,
122124
normalized_output_ty,
123-
self.mir_def_id,
125+
self.mir_def_id.to_def_id(),
124126
Locations::All(output_span),
125127
ConstraintCategory::BoringNoLocation,
126128
) {
@@ -143,7 +145,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
143145
if let Err(err) = self.eq_opaque_type_and_type(
144146
mir_output_ty,
145147
user_provided_output_ty,
146-
self.mir_def_id,
148+
self.mir_def_id.to_def_id(),
147149
Locations::All(output_span),
148150
ConstraintCategory::BoringNoLocation,
149151
) {

src/librustc_mir/borrow_check/type_check/mod.rs

+16-22
Original file line numberDiff line numberDiff line change
@@ -108,26 +108,22 @@ mod relate_tys;
108108
///
109109
/// - `infcx` -- inference context to use
110110
/// - `param_env` -- parameter environment to use for trait solving
111-
/// - `mir` -- MIR to type-check
112-
/// - `mir_def_id` -- DefId from which the MIR is derived (must be local)
113-
/// - `region_bound_pairs` -- the implied outlives obligations between type parameters
114-
/// and lifetimes (e.g., `&'a T` implies `T: 'a`)
115-
/// - `implicit_region_bound` -- a region which all generic parameters are assumed
116-
/// to outlive; should represent the fn body
117-
/// - `input_tys` -- fully liberated, but **not** normalized, expected types of the arguments;
118-
/// the types of the input parameters found in the MIR itself will be equated with these
119-
/// - `output_ty` -- fully liberated, but **not** normalized, expected return type;
120-
/// the type for the RETURN_PLACE will be equated with this
121-
/// - `liveness` -- results of a liveness computation on the MIR; used to create liveness
122-
/// constraints for the regions in the types of variables
111+
/// - `body` -- MIR body to type-check
112+
/// - `promoted` -- map of promoted constants within `body`
113+
/// - `mir_def_id` -- `LocalDefId` from which the MIR is derived
114+
/// - `universal_regions` -- the universal regions from `body`s function signature
115+
/// - `location_table` -- MIR location map of `body`
116+
/// - `borrow_set` -- information about borrows occurring in `body`
117+
/// - `all_facts` -- when using Polonius, this is the generated set of Polonius facts
123118
/// - `flow_inits` -- results of a maybe-init dataflow analysis
124119
/// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysis
120+
/// - `elements` -- MIR region map
125121
pub(crate) fn type_check<'mir, 'tcx>(
126122
infcx: &InferCtxt<'_, 'tcx>,
127123
param_env: ty::ParamEnv<'tcx>,
128124
body: &Body<'tcx>,
129125
promoted: &IndexVec<Promoted, Body<'tcx>>,
130-
mir_def_id: DefId,
126+
mir_def_id: LocalDefId,
131127
universal_regions: &Rc<UniversalRegions<'tcx>>,
132128
location_table: &LocationTable,
133129
borrow_set: &BorrowSet<'tcx>,
@@ -191,7 +187,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
191187

192188
fn type_check_internal<'a, 'tcx, R>(
193189
infcx: &'a InferCtxt<'a, 'tcx>,
194-
mir_def_id: DefId,
190+
mir_def_id: LocalDefId,
195191
param_env: ty::ParamEnv<'tcx>,
196192
body: &'a Body<'tcx>,
197193
promoted: &'a IndexVec<Promoted, Body<'tcx>>,
@@ -271,7 +267,7 @@ struct TypeVerifier<'a, 'b, 'tcx> {
271267
body: &'b Body<'tcx>,
272268
promoted: &'b IndexVec<Promoted, Body<'tcx>>,
273269
last_span: Span,
274-
mir_def_id: DefId,
270+
mir_def_id: LocalDefId,
275271
errors_reported: bool,
276272
}
277273

@@ -815,7 +811,7 @@ struct TypeChecker<'a, 'tcx> {
815811
/// User type annotations are shared between the main MIR and the MIR of
816812
/// all of the promoted items.
817813
user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>,
818-
mir_def_id: DefId,
814+
mir_def_id: LocalDefId,
819815
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
820816
implicit_region_bound: ty::Region<'tcx>,
821817
reported_errors: FxHashSet<(Ty<'tcx>, Span)>,
@@ -963,7 +959,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
963959
fn new(
964960
infcx: &'a InferCtxt<'a, 'tcx>,
965961
body: &'a Body<'tcx>,
966-
mir_def_id: DefId,
962+
mir_def_id: LocalDefId,
967963
param_env: ty::ParamEnv<'tcx>,
968964
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
969965
implicit_region_bound: ty::Region<'tcx>,
@@ -1142,7 +1138,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
11421138
// When you have `let x: impl Foo = ...` in a closure,
11431139
// the resulting inferend values are stored with the
11441140
// def-id of the base function.
1145-
let parent_def_id = self.tcx().closure_base_def_id(self.mir_def_id);
1141+
let parent_def_id = self.tcx().closure_base_def_id(self.mir_def_id.to_def_id());
11461142
return self.eq_opaque_type_and_type(sub, sup, parent_def_id, locations, category);
11471143
} else {
11481144
return Err(terr);
@@ -1994,7 +1990,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19941990
if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span) {
19951991
let ccx = ConstCx::new_with_param_env(
19961992
tcx,
1997-
self.mir_def_id.expect_local(),
1993+
self.mir_def_id,
19981994
body,
19991995
self.param_env,
20001996
);
@@ -2010,9 +2006,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20102006
&traits::Obligation::new(
20112007
ObligationCause::new(
20122008
span,
2013-
self.tcx()
2014-
.hir()
2015-
.local_def_id_to_hir_id(self.mir_def_id.expect_local()),
2009+
self.tcx().hir().local_def_id_to_hir_id(self.mir_def_id),
20162010
traits::ObligationCauseCode::RepeatVec(should_suggest),
20172011
),
20182012
self.param_env,

0 commit comments

Comments
 (0)