Skip to content

Commit e78e0e2

Browse files
committed
rip out RegionCtxt from hir typeck
1 parent 68d70fc commit e78e0e2

File tree

4 files changed

+13
-896
lines changed

4 files changed

+13
-896
lines changed

compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs

+3-67
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,7 @@
1-
use crate::infer::at::At;
2-
use crate::infer::canonical::OriginalQueryValues;
3-
use crate::infer::InferOk;
4-
5-
use rustc_middle::ty::subst::GenericArg;
61
use rustc_middle::ty::{self, Ty, TyCtxt};
72

83
pub use rustc_middle::traits::query::{DropckConstraint, DropckOutlivesResult};
94

10-
pub trait AtExt<'tcx> {
11-
fn dropck_outlives(&self, ty: Ty<'tcx>) -> InferOk<'tcx, Vec<GenericArg<'tcx>>>;
12-
}
13-
14-
impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
15-
/// Given a type `ty` of some value being dropped, computes a set
16-
/// of "kinds" (types, regions) that must be outlive the execution
17-
/// of the destructor. These basically correspond to data that the
18-
/// destructor might access. This is used during regionck to
19-
/// impose "outlives" constraints on any lifetimes referenced
20-
/// within.
21-
///
22-
/// The rules here are given by the "dropck" RFCs, notably [#1238]
23-
/// and [#1327]. This is a fixed-point computation, where we
24-
/// explore all the data that will be dropped (transitively) when
25-
/// a value of type `ty` is dropped. For each type T that will be
26-
/// dropped and which has a destructor, we must assume that all
27-
/// the types/regions of T are live during the destructor, unless
28-
/// they are marked with a special attribute (`#[may_dangle]`).
29-
///
30-
/// [#1238]: https://github.com/rust-lang/rfcs/blob/master/text/1238-nonparametric-dropck.md
31-
/// [#1327]: https://github.com/rust-lang/rfcs/blob/master/text/1327-dropck-param-eyepatch.md
32-
fn dropck_outlives(&self, ty: Ty<'tcx>) -> InferOk<'tcx, Vec<GenericArg<'tcx>>> {
33-
debug!("dropck_outlives(ty={:?}, param_env={:?})", ty, self.param_env,);
34-
35-
// Quick check: there are a number of cases that we know do not require
36-
// any destructor.
37-
let tcx = self.infcx.tcx;
38-
if trivial_dropck_outlives(tcx, ty) {
39-
return InferOk { value: vec![], obligations: vec![] };
40-
}
41-
42-
let mut orig_values = OriginalQueryValues::default();
43-
let c_ty = self.infcx.canonicalize_query(self.param_env.and(ty), &mut orig_values);
44-
let span = self.cause.span;
45-
debug!("c_ty = {:?}", c_ty);
46-
if let Ok(result) = tcx.dropck_outlives(c_ty)
47-
&& result.is_proven()
48-
&& let Ok(InferOk { value, obligations }) =
49-
self.infcx.instantiate_query_response_and_region_obligations(
50-
self.cause,
51-
self.param_env,
52-
&orig_values,
53-
result,
54-
)
55-
{
56-
let ty = self.infcx.resolve_vars_if_possible(ty);
57-
let kinds = value.into_kinds_reporting_overflows(tcx, span, ty);
58-
return InferOk { value: kinds, obligations };
59-
}
60-
61-
// Errors and ambiguity in dropck occur in two cases:
62-
// - unresolved inference variables at the end of typeck
63-
// - non well-formed types where projections cannot be resolved
64-
// Either of these should have created an error before.
65-
tcx.sess.delay_span_bug(span, "dtorck encountered internal error");
66-
67-
InferOk { value: vec![], obligations: vec![] }
68-
}
69-
}
70-
715
/// This returns true if the type `ty` is "trivial" for
726
/// dropck-outlives -- that is, if it doesn't require any types to
737
/// outlive. This is similar but not *quite* the same as the
@@ -79,6 +13,8 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
7913
///
8014
/// Note also that `needs_drop` requires a "global" type (i.e., one
8115
/// with erased regions), but this function does not.
16+
///
17+
// FIXME(@lcnr): remove this module and move this function somewhere else.
8218
pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
8319
match ty.kind() {
8420
// None of these types have a destructor and hence they do not
@@ -105,7 +41,7 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
10541
ty::Array(ty, _) | ty::Slice(ty) => trivial_dropck_outlives(tcx, *ty),
10642

10743
// (T1..Tn) and closures have same properties as T1..Tn --
108-
// check if *any* of those are trivial.
44+
// check if *all* of them are trivial.
10945
ty::Tuple(tys) => tys.iter().all(|t| trivial_dropck_outlives(tcx, t)),
11046
ty::Closure(_, ref substs) => {
11147
trivial_dropck_outlives(tcx, substs.as_closure().tupled_upvars_ty())

compiler/rustc_typeck/src/check/dropck.rs

+3-16
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
use crate::check::regionck::RegionCtxt;
2-
use crate::hir;
1+
// FIXME(@lcnr): Move this module out of `rustc_typeck`.
2+
//
3+
// We don't do any drop checking during hir typeck.
34
use crate::hir::def_id::{DefId, LocalDefId};
45
use rustc_errors::{struct_span_err, ErrorGuaranteed};
56
use rustc_middle::ty::error::TypeError;
67
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
78
use rustc_middle::ty::subst::SubstsRef;
89
use rustc_middle::ty::util::IgnoreRegions;
910
use rustc_middle::ty::{self, Predicate, Ty, TyCtxt};
10-
use rustc_span::Span;
1111

1212
/// This function confirms that the `Drop` implementation identified by
1313
/// `drop_impl_did` is not any more specialized than the type it is
@@ -229,19 +229,6 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
229229
result
230230
}
231231

232-
/// This function is not only checking that the dropck obligations are met for
233-
/// the given type, but it's also currently preventing non-regular recursion in
234-
/// types from causing stack overflows (dropck_no_diverge_on_nonregular_*.rs).
235-
///
236-
/// FIXME: Completely rip out dropck and regionck.
237-
pub(crate) fn check_drop_obligations<'a, 'tcx>(
238-
_rcx: &mut RegionCtxt<'a, 'tcx>,
239-
_ty: Ty<'tcx>,
240-
_span: Span,
241-
_body_id: hir::HirId,
242-
) {
243-
}
244-
245232
// This is an implementation of the TypeRelation trait with the
246233
// aim of simply comparing for equality (without side-effects).
247234
// It is not intended to be used anywhere else other than here.

compiler/rustc_typeck/src/check/mod.rs

+5-18
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ fn typeck_with_fallback<'tcx>(
368368

369369
let typeck_results = Inherited::build(tcx, def_id).enter(|inh| {
370370
let param_env = tcx.param_env(def_id);
371-
let (fcx, wf_tys) = if let Some(hir::FnSig { header, decl, .. }) = fn_sig {
371+
let fcx = if let Some(hir::FnSig { header, decl, .. }) = fn_sig {
372372
let fn_sig = if crate::collect::get_infer_ret_ty(&decl.output).is_some() {
373373
let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id);
374374
<dyn AstConv<'_>>::ty_of_fn(&fcx, id, header.unsafety, header.abi, decl, None, None)
@@ -378,24 +378,15 @@ fn typeck_with_fallback<'tcx>(
378378

379379
check_abi(tcx, id, span, fn_sig.abi());
380380

381-
// When normalizing the function signature, we assume all types are
382-
// well-formed. So, we don't need to worry about the obligations
383-
// from normalization. We could just discard these, but to align with
384-
// compare_method and elsewhere, we just add implied bounds for
385-
// these types.
386-
let mut wf_tys = FxHashSet::default();
387-
// Compute the fty from point of view of inside the fn.
381+
// Compute the function signature from point of view of inside the fn.
388382
let fn_sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), fn_sig);
389383
let fn_sig = inh.normalize_associated_types_in(
390384
body.value.span,
391385
body_id.hir_id,
392386
param_env,
393387
fn_sig,
394388
);
395-
wf_tys.extend(fn_sig.inputs_and_output.iter());
396-
397-
let fcx = check_fn(&inh, param_env, fn_sig, decl, id, body, None, true).0;
398-
(fcx, wf_tys)
389+
check_fn(&inh, param_env, fn_sig, decl, id, body, None, true).0
399390
} else {
400391
let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id);
401392
let expected_type = body_ty
@@ -458,7 +449,7 @@ fn typeck_with_fallback<'tcx>(
458449

459450
fcx.write_ty(id, expected_type);
460451

461-
(fcx, FxHashSet::default())
452+
fcx
462453
};
463454

464455
let fallback_has_occurred = fcx.type_inference_fallback();
@@ -490,11 +481,7 @@ fn typeck_with_fallback<'tcx>(
490481

491482
fcx.check_asms();
492483

493-
if fn_sig.is_some() {
494-
fcx.regionck_fn(id, body, wf_tys);
495-
} else {
496-
fcx.regionck_body(body);
497-
}
484+
fcx.infcx.skip_region_resolution();
498485

499486
fcx.resolve_type_vars_in_body(body)
500487
});

0 commit comments

Comments
 (0)