Skip to content

Commit 41a39fd

Browse files
authored
Rollup merge of rust-lang#100761 - lcnr:mir-typeck-cleanup, r=compiler-errors
some general mir typeck cleanup this pr contains the parts of rust-lang#95763 which already work correctly. the remaining commits of that PR have some issues which are more complex to fix. r? types
2 parents e0cd0cd + 56b5ec8 commit 41a39fd

File tree

3 files changed

+58
-90
lines changed

3 files changed

+58
-90
lines changed

compiler/rustc_borrowck/src/type_check/canonical.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
9090
locations: Locations,
9191
category: ConstraintCategory<'tcx>,
9292
) {
93-
self.prove_predicates(
94-
Some(ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate {
93+
self.prove_predicate(
94+
ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate {
9595
trait_ref,
9696
constness: ty::BoundConstness::NotConst,
9797
polarity: ty::ImplPolarity::Positive,
98-
}))),
98+
}))
99+
.to_predicate(self.tcx()),
99100
locations,
100101
category,
101102
);

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
268268
// }
269269
// impl Foo for () {
270270
// type Bar = ();
271-
// fn foo(&self) ->&() {}
271+
// fn foo(&self) -> &() {}
272272
// }
273273
// ```
274274
// Both &Self::Bar and &() are WF

compiler/rustc_borrowck/src/type_check/mod.rs

+53-86
Original file line numberDiff line numberDiff line change
@@ -178,97 +178,15 @@ pub(crate) fn type_check<'mir, 'tcx>(
178178
upvars,
179179
};
180180

181-
let opaque_type_values = type_check_internal(
181+
let mut checker = TypeChecker::new(
182182
infcx,
183-
param_env,
184183
body,
185-
promoted,
184+
param_env,
186185
&region_bound_pairs,
187186
implicit_region_bound,
188187
&mut borrowck_context,
189-
|mut cx| {
190-
debug!("inside extra closure of type_check_internal");
191-
cx.equate_inputs_and_outputs(&body, universal_regions, &normalized_inputs_and_output);
192-
liveness::generate(
193-
&mut cx,
194-
body,
195-
elements,
196-
flow_inits,
197-
move_data,
198-
location_table,
199-
use_polonius,
200-
);
201-
202-
translate_outlives_facts(&mut cx);
203-
let opaque_type_values =
204-
infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
205-
206-
opaque_type_values
207-
.into_iter()
208-
.map(|(opaque_type_key, decl)| {
209-
cx.fully_perform_op(
210-
Locations::All(body.span),
211-
ConstraintCategory::OpaqueType,
212-
CustomTypeOp::new(
213-
|infcx| {
214-
infcx.register_member_constraints(
215-
param_env,
216-
opaque_type_key,
217-
decl.hidden_type.ty,
218-
decl.hidden_type.span,
219-
);
220-
Ok(InferOk { value: (), obligations: vec![] })
221-
},
222-
|| "opaque_type_map".to_string(),
223-
),
224-
)
225-
.unwrap();
226-
let mut hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
227-
trace!(
228-
"finalized opaque type {:?} to {:#?}",
229-
opaque_type_key,
230-
hidden_type.ty.kind()
231-
);
232-
if hidden_type.has_infer_types_or_consts() {
233-
infcx.tcx.sess.delay_span_bug(
234-
decl.hidden_type.span,
235-
&format!("could not resolve {:#?}", hidden_type.ty.kind()),
236-
);
237-
hidden_type.ty = infcx.tcx.ty_error();
238-
}
239-
240-
(opaque_type_key, (hidden_type, decl.origin))
241-
})
242-
.collect()
243-
},
244188
);
245189

246-
MirTypeckResults { constraints, universal_region_relations, opaque_type_values }
247-
}
248-
249-
#[instrument(
250-
skip(infcx, body, promoted, region_bound_pairs, borrowck_context, extra),
251-
level = "debug"
252-
)]
253-
fn type_check_internal<'a, 'tcx, R>(
254-
infcx: &'a InferCtxt<'a, 'tcx>,
255-
param_env: ty::ParamEnv<'tcx>,
256-
body: &'a Body<'tcx>,
257-
promoted: &'a IndexVec<Promoted, Body<'tcx>>,
258-
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
259-
implicit_region_bound: ty::Region<'tcx>,
260-
borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>,
261-
extra: impl FnOnce(TypeChecker<'a, 'tcx>) -> R,
262-
) -> R {
263-
debug!("body: {:#?}", body);
264-
let mut checker = TypeChecker::new(
265-
infcx,
266-
body,
267-
param_env,
268-
region_bound_pairs,
269-
implicit_region_bound,
270-
borrowck_context,
271-
);
272190
let errors_reported = {
273191
let mut verifier = TypeVerifier::new(&mut checker, promoted);
274192
verifier.visit_body(&body);
@@ -280,7 +198,56 @@ fn type_check_internal<'a, 'tcx, R>(
280198
checker.typeck_mir(body);
281199
}
282200

283-
extra(checker)
201+
checker.equate_inputs_and_outputs(&body, universal_regions, &normalized_inputs_and_output);
202+
liveness::generate(
203+
&mut checker,
204+
body,
205+
elements,
206+
flow_inits,
207+
move_data,
208+
location_table,
209+
use_polonius,
210+
);
211+
212+
translate_outlives_facts(&mut checker);
213+
let opaque_type_values = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
214+
215+
let opaque_type_values = opaque_type_values
216+
.into_iter()
217+
.map(|(opaque_type_key, decl)| {
218+
checker
219+
.fully_perform_op(
220+
Locations::All(body.span),
221+
ConstraintCategory::OpaqueType,
222+
CustomTypeOp::new(
223+
|infcx| {
224+
infcx.register_member_constraints(
225+
param_env,
226+
opaque_type_key,
227+
decl.hidden_type.ty,
228+
decl.hidden_type.span,
229+
);
230+
Ok(InferOk { value: (), obligations: vec![] })
231+
},
232+
|| "opaque_type_map".to_string(),
233+
),
234+
)
235+
.unwrap();
236+
let mut hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
237+
trace!("finalized opaque type {:?} to {:#?}", opaque_type_key, hidden_type.ty.kind());
238+
if hidden_type.has_infer_types_or_consts() {
239+
infcx.tcx.sess.delay_span_bug(
240+
decl.hidden_type.span,
241+
&format!("could not resolve {:#?}", hidden_type.ty.kind()),
242+
);
243+
hidden_type.ty = infcx.tcx.ty_error();
244+
}
245+
246+
(opaque_type_key, (hidden_type, decl.origin))
247+
})
248+
.collect();
249+
250+
MirTypeckResults { constraints, universal_region_relations, opaque_type_values }
284251
}
285252

286253
fn translate_outlives_facts(typeck: &mut TypeChecker<'_, '_>) {
@@ -1911,7 +1878,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19111878
}
19121879
}
19131880

1914-
&Rvalue::NullaryOp(_, ty) => {
1881+
&Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => {
19151882
let trait_ref = ty::TraitRef {
19161883
def_id: tcx.require_lang_item(LangItem::Sized, Some(self.last_span)),
19171884
substs: tcx.mk_substs_trait(ty, &[]),

0 commit comments

Comments
 (0)