mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Remove dead ScopeTree code
This commit is contained in:
parent
52d628f250
commit
3d8a0733ae
@ -61,7 +61,6 @@ use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::Node;
|
||||
use rustc_middle::middle::region;
|
||||
use rustc_middle::ty::error::TypeError;
|
||||
use rustc_middle::ty::{
|
||||
self,
|
||||
@ -81,7 +80,6 @@ pub mod nice_region_error;
|
||||
|
||||
pub(super) fn note_and_explain_region(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
region_scope_tree: ®ion::ScopeTree,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
prefix: &str,
|
||||
region: ty::Region<'tcx>,
|
||||
@ -239,7 +237,6 @@ fn explain_span(tcx: TyCtxt<'tcx>, heading: &str, span: Span) -> (String, Option
|
||||
|
||||
pub fn unexpected_hidden_region_diagnostic(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
region_scope_tree: Option<®ion::ScopeTree>,
|
||||
span: Span,
|
||||
hidden_ty: Ty<'tcx>,
|
||||
hidden_region: ty::Region<'tcx>,
|
||||
@ -264,78 +261,53 @@ pub fn unexpected_hidden_region_diagnostic(
|
||||
err.span_note(span, &message);
|
||||
}
|
||||
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic | ty::ReEmpty(_) => {
|
||||
// Assuming regionck succeeded (*), we ought to always be
|
||||
// capturing *some* region from the fn header, and hence it
|
||||
// ought to be free. So under normal circumstances, we will go
|
||||
// down this path which gives a decent human readable
|
||||
// explanation.
|
||||
//
|
||||
// (*) if not, the `tainted_by_errors` field would be set to
|
||||
// `Some(ErrorReported)` in any case, so we wouldn't be here at all.
|
||||
note_and_explain_free_region(
|
||||
tcx,
|
||||
&mut err,
|
||||
&format!("hidden type `{}` captures ", hidden_ty),
|
||||
hidden_region,
|
||||
"",
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
// Ugh. This is a painful case: the hidden region is not one
|
||||
// that we can easily summarize or explain. This can happen
|
||||
// in a case like
|
||||
// `src/test/ui/multiple-lifetimes/ordinary-bounds-unsuited.rs`:
|
||||
//
|
||||
// ```
|
||||
// fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> {
|
||||
// if condition() { a } else { b }
|
||||
// }
|
||||
// ```
|
||||
//
|
||||
// Here the captured lifetime is the intersection of `'a` and
|
||||
// `'b`, which we can't quite express.
|
||||
|
||||
if let Some(region_scope_tree) = region_scope_tree {
|
||||
// If the `region_scope_tree` is available, this is being
|
||||
// invoked from the "region inferencer error". We can at
|
||||
// least report a really cryptic error for now.
|
||||
note_and_explain_region(
|
||||
// Assuming regionck succeeded (*), we ought to always be
|
||||
// capturing *some* region from the fn header, and hence it
|
||||
// ought to be free. So under normal circumstances, we will go
|
||||
// down this path which gives a decent human readable
|
||||
// explanation.
|
||||
//
|
||||
// (*) if not, the `tainted_by_errors` field would be set to
|
||||
// `Some(ErrorReported)` in any case, so we wouldn't be here at all.
|
||||
note_and_explain_free_region(
|
||||
tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
&format!("hidden type `{}` captures ", hidden_ty),
|
||||
hidden_region,
|
||||
"",
|
||||
);
|
||||
} else {
|
||||
// If the `region_scope_tree` is *unavailable*, this is
|
||||
// being invoked by the code that comes *after* region
|
||||
// inferencing. This is a bug, as the region inferencer
|
||||
// ought to have noticed the failed constraint and invoked
|
||||
// error reporting, which in turn should have prevented us
|
||||
// from getting trying to infer the hidden type
|
||||
// completely.
|
||||
tcx.sess.delay_span_bug(
|
||||
span,
|
||||
&format!(
|
||||
"hidden type captures unexpected lifetime `{:?}` \
|
||||
but no region inference failure",
|
||||
hidden_region,
|
||||
),
|
||||
}
|
||||
_ => {
|
||||
// Ugh. This is a painful case: the hidden region is not one
|
||||
// that we can easily summarize or explain. This can happen
|
||||
// in a case like
|
||||
// `src/test/ui/multiple-lifetimes/ordinary-bounds-unsuited.rs`:
|
||||
//
|
||||
// ```
|
||||
// fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> {
|
||||
// if condition() { a } else { b }
|
||||
// }
|
||||
// ```
|
||||
//
|
||||
// Here the captured lifetime is the intersection of `'a` and
|
||||
// `'b`, which we can't quite express.
|
||||
|
||||
// We can at least report a really cryptic error for now.
|
||||
note_and_explain_region(
|
||||
tcx,
|
||||
&mut err,
|
||||
&format!("hidden type `{}` captures ", hidden_ty),
|
||||
hidden_region,
|
||||
"",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
pub fn report_region_errors(
|
||||
&self,
|
||||
region_scope_tree: ®ion::ScopeTree,
|
||||
errors: &Vec<RegionResolutionError<'tcx>>,
|
||||
) {
|
||||
pub fn report_region_errors(&self, errors: &Vec<RegionResolutionError<'tcx>>) {
|
||||
debug!("report_region_errors(): {} errors to start", errors.len());
|
||||
|
||||
// try to pre-process the errors, which will group some of them
|
||||
@ -358,17 +330,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
// general bit of code that displays the error information
|
||||
RegionResolutionError::ConcreteFailure(origin, sub, sup) => {
|
||||
if sub.is_placeholder() || sup.is_placeholder() {
|
||||
self.report_placeholder_failure(region_scope_tree, origin, sub, sup)
|
||||
.emit();
|
||||
self.report_placeholder_failure(origin, sub, sup).emit();
|
||||
} else {
|
||||
self.report_concrete_failure(region_scope_tree, origin, sub, sup)
|
||||
.emit();
|
||||
self.report_concrete_failure(origin, sub, sup).emit();
|
||||
}
|
||||
}
|
||||
|
||||
RegionResolutionError::GenericBoundFailure(origin, param_ty, sub) => {
|
||||
self.report_generic_bound_failure(
|
||||
region_scope_tree,
|
||||
origin.span(),
|
||||
Some(origin),
|
||||
param_ty,
|
||||
@ -385,29 +354,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
sup_r,
|
||||
) => {
|
||||
if sub_r.is_placeholder() {
|
||||
self.report_placeholder_failure(
|
||||
region_scope_tree,
|
||||
sub_origin,
|
||||
sub_r,
|
||||
sup_r,
|
||||
)
|
||||
.emit();
|
||||
self.report_placeholder_failure(sub_origin, sub_r, sup_r).emit();
|
||||
} else if sup_r.is_placeholder() {
|
||||
self.report_placeholder_failure(
|
||||
region_scope_tree,
|
||||
sup_origin,
|
||||
sub_r,
|
||||
sup_r,
|
||||
)
|
||||
.emit();
|
||||
self.report_placeholder_failure(sup_origin, sub_r, sup_r).emit();
|
||||
} else {
|
||||
self.report_sub_sup_conflict(
|
||||
region_scope_tree,
|
||||
var_origin,
|
||||
sub_origin,
|
||||
sub_r,
|
||||
sup_origin,
|
||||
sup_r,
|
||||
var_origin, sub_origin, sub_r, sup_origin, sup_r,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -428,13 +380,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
// value.
|
||||
let sub_r = self.tcx.mk_region(ty::ReEmpty(var_universe));
|
||||
|
||||
self.report_placeholder_failure(
|
||||
region_scope_tree,
|
||||
sup_origin,
|
||||
sub_r,
|
||||
sup_r,
|
||||
)
|
||||
.emit();
|
||||
self.report_placeholder_failure(sup_origin, sub_r, sup_r).emit();
|
||||
}
|
||||
|
||||
RegionResolutionError::MemberConstraintFailure {
|
||||
@ -445,7 +391,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
let hidden_ty = self.resolve_vars_if_possible(&hidden_ty);
|
||||
unexpected_hidden_region_diagnostic(
|
||||
self.tcx,
|
||||
Some(region_scope_tree),
|
||||
span,
|
||||
hidden_ty,
|
||||
member_region,
|
||||
@ -1722,19 +1667,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
|
||||
pub fn report_generic_bound_failure(
|
||||
&self,
|
||||
region_scope_tree: ®ion::ScopeTree,
|
||||
span: Span,
|
||||
origin: Option<SubregionOrigin<'tcx>>,
|
||||
bound_kind: GenericKind<'tcx>,
|
||||
sub: Region<'tcx>,
|
||||
) {
|
||||
self.construct_generic_bound_failure(region_scope_tree, span, origin, bound_kind, sub)
|
||||
.emit();
|
||||
self.construct_generic_bound_failure(span, origin, bound_kind, sub).emit();
|
||||
}
|
||||
|
||||
pub fn construct_generic_bound_failure(
|
||||
&self,
|
||||
region_scope_tree: ®ion::ScopeTree,
|
||||
span: Span,
|
||||
origin: Option<SubregionOrigin<'tcx>>,
|
||||
bound_kind: GenericKind<'tcx>,
|
||||
@ -1886,7 +1828,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
));
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
&format!("{} must be valid for ", labeled_user_string),
|
||||
sub,
|
||||
@ -1904,7 +1845,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
|
||||
fn report_sub_sup_conflict(
|
||||
&self,
|
||||
region_scope_tree: ®ion::ScopeTree,
|
||||
var_origin: RegionVariableOrigin,
|
||||
sub_origin: SubregionOrigin<'tcx>,
|
||||
sub_region: Region<'tcx>,
|
||||
@ -1915,7 +1855,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
"first, the lifetime cannot outlive ",
|
||||
sup_region,
|
||||
@ -1941,7 +1880,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
if sub_expected == sup_expected && sub_found == sup_found {
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
"...but the lifetime must also be valid for ",
|
||||
sub_region,
|
||||
@ -1963,7 +1901,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
"but, the lifetime must be valid for ",
|
||||
sub_region,
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::infer::error_reporting::{note_and_explain_region, ObligationCauseExt};
|
||||
use crate::infer::{self, InferCtxt, SubregionOrigin};
|
||||
use rustc_errors::{struct_span_err, DiagnosticBuilder};
|
||||
use rustc_middle::middle::region;
|
||||
use rustc_middle::ty::error::TypeError;
|
||||
use rustc_middle::ty::{self, Region};
|
||||
|
||||
@ -91,7 +90,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
|
||||
pub(super) fn report_concrete_failure(
|
||||
&self,
|
||||
region_scope_tree: ®ion::ScopeTree,
|
||||
origin: SubregionOrigin<'tcx>,
|
||||
sub: Region<'tcx>,
|
||||
sup: Region<'tcx>,
|
||||
@ -100,10 +98,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
infer::Subtype(box trace) => {
|
||||
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
|
||||
let mut err = self.report_and_explain_type_error(trace, &terr);
|
||||
note_and_explain_region(self.tcx, region_scope_tree, &mut err, "", sup, "...");
|
||||
note_and_explain_region(self.tcx, &mut err, "", sup, "...");
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
"...does not necessarily outlive ",
|
||||
sub,
|
||||
@ -121,7 +118,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
);
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
"...the reference is valid for ",
|
||||
sub,
|
||||
@ -129,7 +125,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
);
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
"...but the borrowed content is only valid for ",
|
||||
sup,
|
||||
@ -149,7 +144,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
);
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
"...the borrowed pointer is valid for ",
|
||||
sub,
|
||||
@ -157,7 +151,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
);
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
&format!("...but `{}` is only valid for ", var_name),
|
||||
sup,
|
||||
@ -173,17 +166,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
"lifetime of the source pointer does not outlive \
|
||||
lifetime bound of the object type"
|
||||
);
|
||||
note_and_explain_region(self.tcx, &mut err, "object type is valid for ", sub, "");
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
"object type is valid for ",
|
||||
sub,
|
||||
"",
|
||||
);
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
"source pointer is only valid for ",
|
||||
sup,
|
||||
@ -201,22 +186,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
self.ty_to_string(ty)
|
||||
);
|
||||
match *sub {
|
||||
ty::ReStatic => note_and_explain_region(
|
||||
self.tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
"type must satisfy ",
|
||||
sub,
|
||||
"",
|
||||
),
|
||||
_ => note_and_explain_region(
|
||||
self.tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
"type must outlive ",
|
||||
sub,
|
||||
"",
|
||||
),
|
||||
ty::ReStatic => {
|
||||
note_and_explain_region(self.tcx, &mut err, "type must satisfy ", sub, "")
|
||||
}
|
||||
_ => note_and_explain_region(self.tcx, &mut err, "type must outlive ", sub, ""),
|
||||
}
|
||||
err
|
||||
}
|
||||
@ -225,7 +198,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
struct_span_err!(self.tcx.sess, span, E0478, "lifetime bound not satisfied");
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
"lifetime parameter instantiated with ",
|
||||
sup,
|
||||
@ -233,7 +205,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
);
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
"but lifetime parameter must outlive ",
|
||||
sub,
|
||||
@ -251,7 +222,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
);
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
"the return value is only valid for ",
|
||||
sup,
|
||||
@ -267,22 +237,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
"a value of type `{}` is borrowed for too long",
|
||||
self.ty_to_string(ty)
|
||||
);
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
"the type is valid for ",
|
||||
sub,
|
||||
"",
|
||||
);
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
"but the borrow lasts for ",
|
||||
sup,
|
||||
"",
|
||||
);
|
||||
note_and_explain_region(self.tcx, &mut err, "the type is valid for ", sub, "");
|
||||
note_and_explain_region(self.tcx, &mut err, "but the borrow lasts for ", sup, "");
|
||||
err
|
||||
}
|
||||
infer::ReferenceOutlivesReferent(ty, span) => {
|
||||
@ -293,17 +249,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
"in type `{}`, reference has a longer lifetime than the data it references",
|
||||
self.ty_to_string(ty)
|
||||
);
|
||||
note_and_explain_region(self.tcx, &mut err, "the pointer is valid for ", sub, "");
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
"the pointer is valid for ",
|
||||
sub,
|
||||
"",
|
||||
);
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
region_scope_tree,
|
||||
&mut err,
|
||||
"but the referenced data is only valid for ",
|
||||
sup,
|
||||
@ -328,7 +276,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
|
||||
pub(super) fn report_placeholder_failure(
|
||||
&self,
|
||||
region_scope_tree: ®ion::ScopeTree,
|
||||
placeholder_origin: SubregionOrigin<'tcx>,
|
||||
sub: Region<'tcx>,
|
||||
sup: Region<'tcx>,
|
||||
@ -340,7 +287,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
self.report_and_explain_type_error(trace, &terr)
|
||||
}
|
||||
|
||||
_ => self.report_concrete_failure(region_scope_tree, placeholder_origin, sub, sup),
|
||||
_ => self.report_concrete_failure(placeholder_origin, sub, sup),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
|
||||
use rustc_data_structures::transitive_relation::TransitiveRelation;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_middle::middle::region;
|
||||
use rustc_middle::ty::{self, Lift, Region, TyCtxt};
|
||||
|
||||
/// Combines a `region::ScopeTree` (which governs relationships between
|
||||
@ -21,21 +20,13 @@ pub struct RegionRelations<'a, 'tcx> {
|
||||
/// The context used to fetch the region maps.
|
||||
pub context: DefId,
|
||||
|
||||
/// The region maps for the given context.
|
||||
pub region_scope_tree: &'a region::ScopeTree,
|
||||
|
||||
/// Free-region relationships.
|
||||
pub free_regions: &'a FreeRegionMap<'tcx>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> RegionRelations<'a, 'tcx> {
|
||||
pub fn new(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
context: DefId,
|
||||
region_scope_tree: &'a region::ScopeTree,
|
||||
free_regions: &'a FreeRegionMap<'tcx>,
|
||||
) -> Self {
|
||||
Self { tcx, context, region_scope_tree, free_regions }
|
||||
pub fn new(tcx: TyCtxt<'tcx>, context: DefId, free_regions: &'a FreeRegionMap<'tcx>) -> Self {
|
||||
Self { tcx, context, free_regions }
|
||||
}
|
||||
|
||||
pub fn lub_free_regions(&self, r_a: Region<'tcx>, r_b: Region<'tcx>) -> Region<'tcx> {
|
||||
|
@ -20,7 +20,6 @@ use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_middle::infer::canonical::{Canonical, CanonicalVarValues};
|
||||
use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
|
||||
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType};
|
||||
use rustc_middle::middle::region;
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::mir::interpret::ConstEvalResult;
|
||||
use rustc_middle::traits::select;
|
||||
@ -1213,7 +1212,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
pub fn resolve_regions_and_report_errors(
|
||||
&self,
|
||||
region_context: DefId,
|
||||
region_map: ®ion::ScopeTree,
|
||||
outlives_env: &OutlivesEnvironment<'tcx>,
|
||||
mode: RegionckMode,
|
||||
) {
|
||||
@ -1233,12 +1231,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
.into_infos_and_data()
|
||||
};
|
||||
|
||||
let region_rels = &RegionRelations::new(
|
||||
self.tcx,
|
||||
region_context,
|
||||
region_map,
|
||||
outlives_env.free_region_map(),
|
||||
);
|
||||
let region_rels =
|
||||
&RegionRelations::new(self.tcx, region_context, outlives_env.free_region_map());
|
||||
|
||||
let (lexical_region_resolutions, errors) =
|
||||
lexical_region_resolve::resolve(region_rels, var_infos, data, mode);
|
||||
@ -1252,7 +1246,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
// this infcx was in use. This is totally hokey but
|
||||
// otherwise we have a hard time separating legit region
|
||||
// errors from silly ones.
|
||||
self.report_region_errors(region_map, &errors);
|
||||
self.report_region_errors(&errors);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/borrow_check.html
|
||||
|
||||
use crate::ich::{NodeIdHashingMode, StableHashingContext};
|
||||
use crate::ty::{self, DefIdTree, TyCtxt};
|
||||
use crate::ty::TyCtxt;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::Node;
|
||||
|
||||
@ -333,7 +333,7 @@ pub struct YieldData {
|
||||
pub source: hir::YieldSource,
|
||||
}
|
||||
|
||||
impl<'tcx> ScopeTree {
|
||||
impl ScopeTree {
|
||||
pub fn record_scope_parent(&mut self, child: Scope, parent: Option<(Scope, ScopeDepth)>) {
|
||||
debug!("{:?}.parent = {:?}", child, parent);
|
||||
|
||||
@ -348,24 +348,6 @@ impl<'tcx> ScopeTree {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn each_encl_scope<E>(&self, mut e: E)
|
||||
where
|
||||
E: FnMut(Scope, Scope),
|
||||
{
|
||||
for (&child, &parent) in &self.parent_map {
|
||||
e(child, parent.0)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn each_var_scope<E>(&self, mut e: E)
|
||||
where
|
||||
E: FnMut(&hir::ItemLocalId, Scope),
|
||||
{
|
||||
for (child, &parent) in self.var_map.iter() {
|
||||
e(child, parent)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn opt_destruction_scope(&self, n: hir::ItemLocalId) -> Option<Scope> {
|
||||
self.destruction_scopes.get(&n).cloned()
|
||||
}
|
||||
@ -406,12 +388,6 @@ impl<'tcx> ScopeTree {
|
||||
self.parent_map.get(&id).cloned().map(|(p, _)| p)
|
||||
}
|
||||
|
||||
/// Returns the narrowest scope that encloses `id`, if any.
|
||||
#[allow(dead_code)] // used in cfg
|
||||
pub fn encl_scope(&self, id: Scope) -> Scope {
|
||||
self.opt_encl_scope(id).unwrap()
|
||||
}
|
||||
|
||||
/// Returns the lifetime of the local variable `var_id`
|
||||
pub fn var_scope(&self, var_id: hir::ItemLocalId) -> Scope {
|
||||
self.var_map
|
||||
@ -448,17 +424,6 @@ impl<'tcx> ScopeTree {
|
||||
None
|
||||
}
|
||||
|
||||
/// Returns the lifetime of the variable `id`.
|
||||
pub fn var_region(&self, id: hir::ItemLocalId) -> ty::RegionKind {
|
||||
let scope = ty::ReScope(self.var_scope(id));
|
||||
debug!("var_region({:?}) = {:?}", id, scope);
|
||||
scope
|
||||
}
|
||||
|
||||
pub fn scopes_intersect(&self, scope1: Scope, scope2: Scope) -> bool {
|
||||
self.is_subscope_of(scope1, scope2) || self.is_subscope_of(scope2, scope1)
|
||||
}
|
||||
|
||||
/// Returns `true` if `subscope` is equal to or is lexically nested inside `superscope`, and
|
||||
/// `false` otherwise.
|
||||
pub fn is_subscope_of(&self, subscope: Scope, superscope: Scope) -> bool {
|
||||
@ -479,127 +444,6 @@ impl<'tcx> ScopeTree {
|
||||
true
|
||||
}
|
||||
|
||||
/// Returns the ID of the innermost containing body.
|
||||
pub fn containing_body(&self, mut scope: Scope) -> Option<hir::ItemLocalId> {
|
||||
loop {
|
||||
if let ScopeData::CallSite = scope.data {
|
||||
return Some(scope.item_local_id());
|
||||
}
|
||||
|
||||
scope = self.opt_encl_scope(scope)?;
|
||||
}
|
||||
}
|
||||
|
||||
/// Finds the nearest common ancestor of two scopes. That is, finds the
|
||||
/// smallest scope which is greater than or equal to both `scope_a` and
|
||||
/// `scope_b`.
|
||||
pub fn nearest_common_ancestor(&self, scope_a: Scope, scope_b: Scope) -> Scope {
|
||||
if scope_a == scope_b {
|
||||
return scope_a;
|
||||
}
|
||||
|
||||
let mut a = scope_a;
|
||||
let mut b = scope_b;
|
||||
|
||||
// Get the depth of each scope's parent. If either scope has no parent,
|
||||
// it must be the root, which means we can stop immediately because the
|
||||
// root must be the nearest common ancestor. (In practice, this is
|
||||
// moderately common.)
|
||||
let (parent_a, parent_a_depth) = match self.parent_map.get(&a) {
|
||||
Some(pd) => *pd,
|
||||
None => return a,
|
||||
};
|
||||
let (parent_b, parent_b_depth) = match self.parent_map.get(&b) {
|
||||
Some(pd) => *pd,
|
||||
None => return b,
|
||||
};
|
||||
|
||||
if parent_a_depth > parent_b_depth {
|
||||
// `a` is lower than `b`. Move `a` up until it's at the same depth
|
||||
// as `b`. The first move up is trivial because we already found
|
||||
// `parent_a` above; the loop does the remaining N-1 moves.
|
||||
a = parent_a;
|
||||
for _ in 0..(parent_a_depth - parent_b_depth - 1) {
|
||||
a = self.parent_map.get(&a).unwrap().0;
|
||||
}
|
||||
} else if parent_b_depth > parent_a_depth {
|
||||
// `b` is lower than `a`.
|
||||
b = parent_b;
|
||||
for _ in 0..(parent_b_depth - parent_a_depth - 1) {
|
||||
b = self.parent_map.get(&b).unwrap().0;
|
||||
}
|
||||
} else {
|
||||
// Both scopes are at the same depth, and we know they're not equal
|
||||
// because that case was tested for at the top of this function. So
|
||||
// we can trivially move them both up one level now.
|
||||
assert!(parent_a_depth != 0);
|
||||
a = parent_a;
|
||||
b = parent_b;
|
||||
}
|
||||
|
||||
// Now both scopes are at the same level. We move upwards in lockstep
|
||||
// until they match. In practice, this loop is almost always executed
|
||||
// zero times because `a` is almost always a direct ancestor of `b` or
|
||||
// vice versa.
|
||||
while a != b {
|
||||
a = self.parent_map.get(&a).unwrap().0;
|
||||
b = self.parent_map.get(&b).unwrap().0;
|
||||
}
|
||||
|
||||
a
|
||||
}
|
||||
|
||||
/// Assuming that the provided region was defined within this `ScopeTree`,
|
||||
/// returns the outermost `Scope` that the region outlives.
|
||||
pub fn early_free_scope(&self, tcx: TyCtxt<'tcx>, br: &ty::EarlyBoundRegion) -> Scope {
|
||||
let param_owner = tcx.parent(br.def_id).unwrap();
|
||||
|
||||
let param_owner_id = tcx.hir().as_local_hir_id(param_owner.expect_local());
|
||||
let scope = tcx
|
||||
.hir()
|
||||
.maybe_body_owned_by(param_owner_id)
|
||||
.map(|body_id| tcx.hir().body(body_id).value.hir_id.local_id)
|
||||
.unwrap_or_else(|| {
|
||||
// The lifetime was defined on node that doesn't own a body,
|
||||
// which in practice can only mean a trait or an impl, that
|
||||
// is the parent of a method, and that is enforced below.
|
||||
if Some(param_owner_id) != self.root_parent {
|
||||
tcx.sess.delay_span_bug(
|
||||
DUMMY_SP,
|
||||
&format!(
|
||||
"free_scope: {:?} not recognized by the \
|
||||
region scope tree for {:?} / {:?}",
|
||||
param_owner,
|
||||
self.root_parent.map(|id| tcx.hir().local_def_id(id)),
|
||||
self.root_body.map(|hir_id| hir_id.owner)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// The trait/impl lifetime is in scope for the method's body.
|
||||
self.root_body.unwrap().local_id
|
||||
});
|
||||
|
||||
Scope { id: scope, data: ScopeData::CallSite }
|
||||
}
|
||||
|
||||
/// Assuming that the provided region was defined within this `ScopeTree`,
|
||||
/// returns the outermost `Scope` that the region outlives.
|
||||
pub fn free_scope(&self, tcx: TyCtxt<'tcx>, fr: &ty::FreeRegion) -> Scope {
|
||||
let param_owner = match fr.bound_region {
|
||||
ty::BoundRegion::BrNamed(def_id, _) => tcx.parent(def_id).unwrap(),
|
||||
_ => fr.scope,
|
||||
};
|
||||
|
||||
// Ensure that the named late-bound lifetimes were defined
|
||||
// on the same function that they ended up being freed in.
|
||||
assert_eq!(param_owner, fr.scope);
|
||||
|
||||
let param_owner_id = tcx.hir().as_local_hir_id(param_owner.expect_local());
|
||||
let body_id = tcx.hir().body_owned_by(param_owner_id);
|
||||
Scope { id: tcx.hir().body(body_id).value.hir_id.local_id, data: ScopeData::CallSite }
|
||||
}
|
||||
|
||||
/// Checks whether the given scope contains a `yield`. If so,
|
||||
/// returns `Some((span, expr_count))` with the span of a yield we found and
|
||||
/// the number of expressions and patterns appearing before the `yield` in the body + 1.
|
||||
|
@ -162,10 +162,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
let type_test_span = type_test.locations.span(&self.body);
|
||||
|
||||
if let Some(lower_bound_region) = lower_bound_region {
|
||||
let region_scope_tree = &self.infcx.tcx.region_scope_tree(self.mir_def_id);
|
||||
self.infcx
|
||||
.construct_generic_bound_failure(
|
||||
region_scope_tree,
|
||||
type_test_span,
|
||||
None,
|
||||
type_test.generic_kind,
|
||||
@ -194,12 +192,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
}
|
||||
|
||||
RegionErrorKind::UnexpectedHiddenRegion { span, hidden_ty, member_region } => {
|
||||
let region_scope_tree = &self.infcx.tcx.region_scope_tree(self.mir_def_id);
|
||||
let named_ty = self.regioncx.name_regions(self.infcx.tcx, hidden_ty);
|
||||
let named_region = self.regioncx.name_regions(self.infcx.tcx, member_region);
|
||||
unexpected_hidden_region_diagnostic(
|
||||
self.infcx.tcx,
|
||||
Some(region_scope_tree),
|
||||
span,
|
||||
named_ty,
|
||||
named_region,
|
||||
|
@ -835,7 +835,6 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
|
||||
if let Some(hidden_ty) = self.hidden_ty.take() {
|
||||
unexpected_hidden_region_diagnostic(
|
||||
self.tcx,
|
||||
None,
|
||||
self.tcx.def_span(self.opaque_type_def_id),
|
||||
hidden_ty,
|
||||
r,
|
||||
|
@ -28,7 +28,6 @@ use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
|
||||
use rustc_errors::ErrorReported;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_middle::middle::region;
|
||||
use rustc_middle::ty::fold::TypeFoldable;
|
||||
use rustc_middle::ty::subst::{InternalSubsts, SubstsRef};
|
||||
use rustc_middle::ty::{
|
||||
@ -237,15 +236,12 @@ fn do_normalize_predicates<'tcx>(
|
||||
|
||||
debug!("do_normalize_predictes: normalized predicates = {:?}", predicates);
|
||||
|
||||
let region_scope_tree = region::ScopeTree::default();
|
||||
|
||||
// We can use the `elaborated_env` here; the region code only
|
||||
// cares about declarations like `'a: 'b`.
|
||||
let outlives_env = OutlivesEnvironment::new(elaborated_env);
|
||||
|
||||
infcx.resolve_regions_and_report_errors(
|
||||
region_context,
|
||||
®ion_scope_tree,
|
||||
&outlives_env,
|
||||
RegionckMode::default(),
|
||||
);
|
||||
|
@ -3,7 +3,6 @@
|
||||
use super::{check_fn, Expectation, FnCtxt, GeneratorTypes};
|
||||
|
||||
use crate::astconv::AstConv;
|
||||
use crate::middle::region;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::lang_items::{FutureTraitLangItem, GeneratorTraitLangItem};
|
||||
@ -17,7 +16,6 @@ use rustc_span::source_map::Span;
|
||||
use rustc_target::spec::abi::Abi;
|
||||
use rustc_trait_selection::traits::error_reporting::ArgKind;
|
||||
use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _;
|
||||
use rustc_trait_selection::traits::Obligation;
|
||||
use std::cmp;
|
||||
use std::iter;
|
||||
|
||||
|
@ -5,7 +5,6 @@ use rustc_errors::{struct_span_err, ErrorReported};
|
||||
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
|
||||
use rustc_infer::infer::{InferOk, RegionckMode, TyCtxtInferExt};
|
||||
use rustc_infer::traits::TraitEngineExt as _;
|
||||
use rustc_middle::middle::region;
|
||||
use rustc_middle::ty::error::TypeError;
|
||||
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
|
||||
use rustc_middle::ty::subst::{Subst, SubstsRef};
|
||||
@ -120,8 +119,6 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
|
||||
return Err(ErrorReported);
|
||||
}
|
||||
|
||||
let region_scope_tree = region::ScopeTree::default();
|
||||
|
||||
// NB. It seems a bit... suspicious to use an empty param-env
|
||||
// here. The correct thing, I imagine, would be
|
||||
// `OutlivesEnvironment::new(impl_param_env)`, which would
|
||||
@ -134,7 +131,6 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
|
||||
|
||||
infcx.resolve_regions_and_report_errors(
|
||||
drop_impl_did.to_def_id(),
|
||||
®ion_scope_tree,
|
||||
&outlives_env,
|
||||
RegionckMode::default(),
|
||||
);
|
||||
|
@ -11,7 +11,6 @@ use rustc_hir::ItemKind;
|
||||
use rustc_infer::infer;
|
||||
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
|
||||
use rustc_infer::infer::{RegionckMode, TyCtxtInferExt};
|
||||
use rustc_middle::middle::region;
|
||||
use rustc_middle::ty::adjustment::CoerceUnsizedInfo;
|
||||
use rustc_middle::ty::TypeFoldable;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
@ -293,11 +292,9 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
|
||||
}
|
||||
|
||||
// Finally, resolve all regions.
|
||||
let region_scope_tree = region::ScopeTree::default();
|
||||
let outlives_env = OutlivesEnvironment::new(param_env);
|
||||
infcx.resolve_regions_and_report_errors(
|
||||
impl_did.to_def_id(),
|
||||
®ion_scope_tree,
|
||||
&outlives_env,
|
||||
RegionckMode::default(),
|
||||
);
|
||||
@ -552,14 +549,8 @@ pub fn coerce_unsized_info(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUnsizedI
|
||||
}
|
||||
|
||||
// Finally, resolve all regions.
|
||||
let region_scope_tree = region::ScopeTree::default();
|
||||
let outlives_env = OutlivesEnvironment::new(param_env);
|
||||
infcx.resolve_regions_and_report_errors(
|
||||
impl_did,
|
||||
®ion_scope_tree,
|
||||
&outlives_env,
|
||||
RegionckMode::default(),
|
||||
);
|
||||
infcx.resolve_regions_and_report_errors(impl_did, &outlives_env, RegionckMode::default());
|
||||
|
||||
CoerceUnsizedInfo { custom_kind: kind }
|
||||
})
|
||||
|
@ -73,7 +73,6 @@ use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
|
||||
use rustc_infer::infer::{InferCtxt, RegionckMode, TyCtxtInferExt};
|
||||
use rustc_infer::traits::specialization_graph::Node;
|
||||
use rustc_middle::middle::region::ScopeTree;
|
||||
use rustc_middle::ty::subst::{GenericArg, InternalSubsts, SubstsRef};
|
||||
use rustc_middle::ty::trait_def::TraitSpecializationKind;
|
||||
use rustc_middle::ty::{self, InstantiatedPredicates, TyCtxt, TypeFoldable};
|
||||
@ -165,12 +164,7 @@ fn get_impl_substs<'tcx>(
|
||||
|
||||
// Conservatively use an empty `ParamEnv`.
|
||||
let outlives_env = OutlivesEnvironment::new(ty::ParamEnv::empty());
|
||||
infcx.resolve_regions_and_report_errors(
|
||||
impl1_def_id,
|
||||
&ScopeTree::default(),
|
||||
&outlives_env,
|
||||
RegionckMode::default(),
|
||||
);
|
||||
infcx.resolve_regions_and_report_errors(impl1_def_id, &outlives_env, RegionckMode::default());
|
||||
let impl2_substs = match infcx.fully_resolve(&impl2_substs) {
|
||||
Ok(s) => s,
|
||||
Err(_) => {
|
||||
|
Loading…
Reference in New Issue
Block a user