mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-29 03:27:44 +00:00
Overhaul RegionKind
and Region
.
Specifically, change `Region` from this: ``` pub type Region<'tcx> = &'tcx RegionKind; ``` to this: ``` pub struct Region<'tcx>(&'tcx Interned<RegionKind>); ``` This now matches `Ty` and `Predicate` more closely. Things to note - Regions have always been interned, but we haven't been using pointer-based `Eq` and `Hash`. This is now happening. - I chose to impl `Deref` for `Region` because it makes pattern matching a lot nicer, and `Region` can be viewed as just a smart wrapper for `RegionKind`. - Various methods are moved from `RegionKind` to `Region`. - There is a lot of tedious sigil changes. - A couple of types like `HighlightBuilder`, `RegionHighlightMode` now have a `'tcx` lifetime because they hold a `Ty<'tcx>`, so they can call `mk_region`. - A couple of test outputs change slightly, I'm not sure why, but the new outputs are a little better.
This commit is contained in:
parent
925ec0d3c7
commit
7024dc523a
@ -60,8 +60,8 @@ impl<'cg, 'cx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'tcx> {
|
|||||||
|
|
||||||
/// We sometimes have `region` within an rvalue, or within a
|
/// We sometimes have `region` within an rvalue, or within a
|
||||||
/// call. Make them live at the location where they appear.
|
/// call. Make them live at the location where they appear.
|
||||||
fn visit_region(&mut self, region: &ty::Region<'tcx>, location: Location) {
|
fn visit_region(&mut self, region: ty::Region<'tcx>, location: Location) {
|
||||||
self.add_regular_live_constraint(*region, location);
|
self.add_regular_live_constraint(region, location);
|
||||||
self.super_region(region);
|
self.super_region(region);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,8 +356,8 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
debug!(?sub_region, "cause = {:#?}", cause);
|
debug!(?sub_region, "cause = {:#?}", cause);
|
||||||
let nice_error = match (error_region, sub_region) {
|
let nice_error = match (error_region, *sub_region) {
|
||||||
(Some(error_region), &ty::ReVar(vid)) => NiceRegionError::new(
|
(Some(error_region), ty::ReVar(vid)) => NiceRegionError::new(
|
||||||
infcx,
|
infcx,
|
||||||
RegionResolutionError::SubSupConflict(
|
RegionResolutionError::SubSupConflict(
|
||||||
vid,
|
vid,
|
||||||
@ -374,7 +374,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
|
|||||||
RegionResolutionError::ConcreteFailure(cause.clone(), error_region, placeholder_region),
|
RegionResolutionError::ConcreteFailure(cause.clone(), error_region, placeholder_region),
|
||||||
),
|
),
|
||||||
// Note universe here is wrong...
|
// Note universe here is wrong...
|
||||||
(None, &ty::ReVar(vid)) => NiceRegionError::new(
|
(None, ty::ReVar(vid)) => NiceRegionError::new(
|
||||||
infcx,
|
infcx,
|
||||||
RegionResolutionError::UpperBoundUniverseConflict(
|
RegionResolutionError::UpperBoundUniverseConflict(
|
||||||
vid,
|
vid,
|
||||||
|
@ -497,15 +497,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||||||
// We need to add synthesized lifetimes where appropriate. We do
|
// We need to add synthesized lifetimes where appropriate. We do
|
||||||
// this by hooking into the pretty printer and telling it to label the
|
// this by hooking into the pretty printer and telling it to label the
|
||||||
// lifetimes without names with the value `'0`.
|
// lifetimes without names with the value `'0`.
|
||||||
match ty.kind() {
|
if let ty::Ref(region, ..) = ty.kind() {
|
||||||
ty::Ref(
|
match **region {
|
||||||
ty::RegionKind::ReLateBound(_, ty::BoundRegion { kind: br, .. })
|
ty::ReLateBound(_, ty::BoundRegion { kind: br, .. })
|
||||||
| ty::RegionKind::RePlaceholder(ty::PlaceholderRegion { name: br, .. }),
|
| ty::RePlaceholder(ty::PlaceholderRegion { name: br, .. }) => {
|
||||||
_,
|
printer.region_highlight_mode.highlighting_bound_region(br, counter)
|
||||||
_,
|
}
|
||||||
) => printer.region_highlight_mode.highlighting_bound_region(*br, counter),
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let _ = ty.print(printer);
|
let _ = ty.print(printer);
|
||||||
s
|
s
|
||||||
@ -517,19 +517,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
let mut printer = ty::print::FmtPrinter::new(self.infcx.tcx, &mut s, Namespace::TypeNS);
|
let mut printer = ty::print::FmtPrinter::new(self.infcx.tcx, &mut s, Namespace::TypeNS);
|
||||||
|
|
||||||
let region = match ty.kind() {
|
let region = if let ty::Ref(region, ..) = ty.kind() {
|
||||||
ty::Ref(region, _, _) => {
|
match **region {
|
||||||
match region {
|
ty::ReLateBound(_, ty::BoundRegion { kind: br, .. })
|
||||||
ty::RegionKind::ReLateBound(_, ty::BoundRegion { kind: br, .. })
|
| ty::RePlaceholder(ty::PlaceholderRegion { name: br, .. }) => {
|
||||||
| ty::RegionKind::RePlaceholder(ty::PlaceholderRegion { name: br, .. }) => {
|
printer.region_highlight_mode.highlighting_bound_region(br, counter)
|
||||||
printer.region_highlight_mode.highlighting_bound_region(*br, counter)
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
region
|
region
|
||||||
}
|
} else {
|
||||||
_ => bug!("ty for annotation of borrow region is not a reference"),
|
bug!("ty for annotation of borrow region is not a reference");
|
||||||
};
|
};
|
||||||
|
|
||||||
let _ = region.print(printer);
|
let _ = region.print(printer);
|
||||||
|
@ -139,7 +139,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||||||
|
|
||||||
/// Returns `true` if a closure is inferred to be an `FnMut` closure.
|
/// Returns `true` if a closure is inferred to be an `FnMut` closure.
|
||||||
fn is_closure_fn_mut(&self, fr: RegionVid) -> bool {
|
fn is_closure_fn_mut(&self, fr: RegionVid) -> bool {
|
||||||
if let Some(ty::ReFree(free_region)) = self.to_error_region(fr) {
|
if let Some(ty::ReFree(free_region)) = self.to_error_region(fr).as_deref() {
|
||||||
if let ty::BoundRegionKind::BrEnv = free_region.bound_region {
|
if let ty::BoundRegionKind::BrEnv = free_region.bound_region {
|
||||||
if let DefiningTy::Closure(_, substs) =
|
if let DefiningTy::Closure(_, substs) =
|
||||||
self.regioncx.universal_regions().defining_ty
|
self.regioncx.universal_regions().defining_ty
|
||||||
@ -628,8 +628,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||||||
fr_name: RegionName,
|
fr_name: RegionName,
|
||||||
outlived_fr: RegionVid,
|
outlived_fr: RegionVid,
|
||||||
) {
|
) {
|
||||||
if let (Some(f), Some(ty::RegionKind::ReStatic)) =
|
if let (Some(f), Some(ty::ReStatic)) =
|
||||||
(self.to_error_region(fr), self.to_error_region(outlived_fr))
|
(self.to_error_region(fr), self.to_error_region(outlived_fr).as_deref())
|
||||||
{
|
{
|
||||||
if let Some(&ty::Opaque(did, substs)) = self
|
if let Some(&ty::Opaque(did, substs)) = self
|
||||||
.infcx
|
.infcx
|
||||||
@ -652,7 +652,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||||||
bound.kind().skip_binder()
|
bound.kind().skip_binder()
|
||||||
{
|
{
|
||||||
let r = r.subst(self.infcx.tcx, substs);
|
let r = r.subst(self.infcx.tcx, substs);
|
||||||
if let ty::RegionKind::ReStatic = r {
|
if r.is_static() {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
@ -264,7 +264,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||||||
let tcx = self.infcx.tcx;
|
let tcx = self.infcx.tcx;
|
||||||
|
|
||||||
debug!("give_region_a_name: error_region = {:?}", error_region);
|
debug!("give_region_a_name: error_region = {:?}", error_region);
|
||||||
match error_region {
|
match *error_region {
|
||||||
ty::ReEarlyBound(ebr) => {
|
ty::ReEarlyBound(ebr) => {
|
||||||
if ebr.has_name() {
|
if ebr.has_name() {
|
||||||
let span = tcx.hir().span_if_local(ebr.def_id).unwrap_or(DUMMY_SP);
|
let span = tcx.hir().span_if_local(ebr.def_id).unwrap_or(DUMMY_SP);
|
||||||
@ -433,7 +433,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||||||
span: Span,
|
span: Span,
|
||||||
counter: usize,
|
counter: usize,
|
||||||
) -> RegionNameHighlight {
|
) -> RegionNameHighlight {
|
||||||
let mut highlight = RegionHighlightMode::default();
|
let mut highlight = RegionHighlightMode::new(self.infcx.tcx);
|
||||||
highlight.highlighting_region_vid(needle_fr, counter);
|
highlight.highlighting_region_vid(needle_fr, counter);
|
||||||
let type_name =
|
let type_name =
|
||||||
self.infcx.extract_inference_diagnostics_data(ty.into(), Some(highlight)).name;
|
self.infcx.extract_inference_diagnostics_data(ty.into(), Some(highlight)).name;
|
||||||
@ -818,7 +818,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut highlight = RegionHighlightMode::default();
|
let mut highlight = RegionHighlightMode::new(tcx);
|
||||||
highlight.highlighting_region_vid(fr, *self.next_region_name.try_borrow().unwrap());
|
highlight.highlighting_region_vid(fr, *self.next_region_name.try_borrow().unwrap());
|
||||||
let type_name =
|
let type_name =
|
||||||
self.infcx.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight)).name;
|
self.infcx.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight)).name;
|
||||||
|
@ -8,7 +8,7 @@ use rustc_middle::mir::{
|
|||||||
BasicBlock, Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location,
|
BasicBlock, Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location,
|
||||||
Promoted,
|
Promoted,
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::{self, OpaqueTypeKey, RegionKind, RegionVid, Ty};
|
use rustc_middle::ty::{self, OpaqueTypeKey, Region, RegionVid, Ty};
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
@ -443,9 +443,9 @@ pub trait ToRegionVid {
|
|||||||
fn to_region_vid(self) -> RegionVid;
|
fn to_region_vid(self) -> RegionVid;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> ToRegionVid for &'tcx RegionKind {
|
impl<'tcx> ToRegionVid for Region<'tcx> {
|
||||||
fn to_region_vid(self) -> RegionVid {
|
fn to_region_vid(self) -> RegionVid {
|
||||||
if let ty::ReVar(vid) = self { *vid } else { bug!("region is not an ReVar: {:?}", self) }
|
if let ty::ReVar(vid) = *self { vid } else { bug!("region is not an ReVar: {:?}", self) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1178,7 +1178,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
VerifyBound::OutlivedBy(r) => {
|
VerifyBound::OutlivedBy(r) => {
|
||||||
let r_vid = self.to_region_vid(r);
|
let r_vid = self.to_region_vid(*r);
|
||||||
self.eval_outlives(r_vid, lower_bound)
|
self.eval_outlives(r_vid, lower_bound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||||||
for vid in self.rev_scc_graph.as_ref().unwrap().upper_bounds(scc) {
|
for vid in self.rev_scc_graph.as_ref().unwrap().upper_bounds(scc) {
|
||||||
match self.definitions[vid].external_name {
|
match self.definitions[vid].external_name {
|
||||||
None => {}
|
None => {}
|
||||||
Some(&ty::ReStatic) => {}
|
Some(region) if region.is_static() => {}
|
||||||
Some(region) => return region,
|
Some(region) => return region,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ fn check_opaque_type_parameter_valid(
|
|||||||
for (i, arg) in opaque_type_key.substs.iter().enumerate() {
|
for (i, arg) in opaque_type_key.substs.iter().enumerate() {
|
||||||
let arg_is_param = match arg.unpack() {
|
let arg_is_param = match arg.unpack() {
|
||||||
GenericArgKind::Type(ty) => matches!(ty.kind(), ty::Param(_)),
|
GenericArgKind::Type(ty) => matches!(ty.kind(), ty::Param(_)),
|
||||||
GenericArgKind::Lifetime(ty::ReStatic) => {
|
GenericArgKind::Lifetime(lt) if lt.is_static() => {
|
||||||
tcx.sess
|
tcx.sess
|
||||||
.struct_span_err(span, "non-defining opaque type use in defining scope")
|
.struct_span_err(span, "non-defining opaque type use in defining scope")
|
||||||
.span_label(
|
.span_label(
|
||||||
@ -196,7 +196,7 @@ fn check_opaque_type_parameter_valid(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
GenericArgKind::Lifetime(lt) => {
|
GenericArgKind::Lifetime(lt) => {
|
||||||
matches!(lt, ty::ReEarlyBound(_) | ty::ReFree(_))
|
matches!(*lt, ty::ReEarlyBound(_) | ty::ReFree(_))
|
||||||
}
|
}
|
||||||
GenericArgKind::Const(ct) => matches!(ct.val, ty::ConstKind::Param(_)),
|
GenericArgKind::Const(ct) => matches!(ct.val, ty::ConstKind::Param(_)),
|
||||||
};
|
};
|
||||||
|
@ -72,7 +72,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
|
|||||||
#[instrument(skip(self), level = "debug")]
|
#[instrument(skip(self), level = "debug")]
|
||||||
fn visit_region(&mut self, region: &mut ty::Region<'tcx>, location: Location) {
|
fn visit_region(&mut self, region: &mut ty::Region<'tcx>, location: Location) {
|
||||||
let old_region = *region;
|
let old_region = *region;
|
||||||
*region = self.renumber_regions(&old_region);
|
*region = self.renumber_regions(old_region);
|
||||||
|
|
||||||
debug!(?region);
|
debug!(?region);
|
||||||
}
|
}
|
||||||
|
@ -142,8 +142,8 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn to_region_vid(&mut self, r: ty::Region<'tcx>) -> ty::RegionVid {
|
fn to_region_vid(&mut self, r: ty::Region<'tcx>) -> ty::RegionVid {
|
||||||
if let ty::RePlaceholder(placeholder) = r {
|
if let ty::RePlaceholder(placeholder) = *r {
|
||||||
self.constraints.placeholder_region(self.infcx, *placeholder).to_region_vid()
|
self.constraints.placeholder_region(self.infcx, placeholder).to_region_vid()
|
||||||
} else {
|
} else {
|
||||||
self.universal_regions.to_region_vid(r)
|
self.universal_regions.to_region_vid(r)
|
||||||
}
|
}
|
||||||
|
@ -358,7 +358,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
|
|||||||
// `where Type:` is lowered to `where Type: 'empty` so that
|
// `where Type:` is lowered to `where Type: 'empty` so that
|
||||||
// we check `Type` is well formed, but there's no use for
|
// we check `Type` is well formed, but there's no use for
|
||||||
// this bound here.
|
// this bound here.
|
||||||
if let ty::ReEmpty(_) = r1 {
|
if r1.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2318,7 +2318,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Rvalue::Ref(region, _borrow_kind, borrowed_place) => {
|
Rvalue::Ref(region, _borrow_kind, borrowed_place) => {
|
||||||
self.add_reborrow_constraint(&body, location, region, borrowed_place);
|
self.add_reborrow_constraint(&body, location, *region, borrowed_place);
|
||||||
}
|
}
|
||||||
|
|
||||||
Rvalue::BinaryOp(
|
Rvalue::BinaryOp(
|
||||||
|
@ -323,7 +323,7 @@ impl<'tcx> UniversalRegions<'tcx> {
|
|||||||
|
|
||||||
/// See `UniversalRegionIndices::to_region_vid`.
|
/// See `UniversalRegionIndices::to_region_vid`.
|
||||||
pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
|
pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
|
||||||
if let ty::ReEmpty(ty::UniverseIndex::ROOT) = r {
|
if let ty::ReEmpty(ty::UniverseIndex::ROOT) = *r {
|
||||||
self.root_empty
|
self.root_empty
|
||||||
} else {
|
} else {
|
||||||
self.indices.to_region_vid(r)
|
self.indices.to_region_vid(r)
|
||||||
@ -805,7 +805,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
|
|||||||
/// during initialization. Relies on the `indices` map having been
|
/// during initialization. Relies on the `indices` map having been
|
||||||
/// fully initialized.
|
/// fully initialized.
|
||||||
pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
|
pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
|
||||||
if let ty::ReVar(..) = r {
|
if let ty::ReVar(..) = *r {
|
||||||
r.to_region_vid()
|
r.to_region_vid()
|
||||||
} else {
|
} else {
|
||||||
*self
|
*self
|
||||||
|
@ -544,7 +544,7 @@ pub(crate) fn codegen_drop<'tcx>(
|
|||||||
let arg_value = drop_place.place_ref(
|
let arg_value = drop_place.place_ref(
|
||||||
fx,
|
fx,
|
||||||
fx.layout_of(fx.tcx.mk_ref(
|
fx.layout_of(fx.tcx.mk_ref(
|
||||||
&ty::RegionKind::ReErased,
|
fx.tcx.lifetimes.re_erased,
|
||||||
TypeAndMut { ty, mutbl: crate::rustc_hir::Mutability::Mut },
|
TypeAndMut { ty, mutbl: crate::rustc_hir::Mutability::Mut },
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
|
@ -179,7 +179,7 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
|
|||||||
canonicalizer: &mut Canonicalizer<'_, 'tcx>,
|
canonicalizer: &mut Canonicalizer<'_, 'tcx>,
|
||||||
r: ty::Region<'tcx>,
|
r: ty::Region<'tcx>,
|
||||||
) -> ty::Region<'tcx> {
|
) -> ty::Region<'tcx> {
|
||||||
match r {
|
match *r {
|
||||||
ty::ReFree(_)
|
ty::ReFree(_)
|
||||||
| ty::ReErased
|
| ty::ReErased
|
||||||
| ty::ReStatic
|
| ty::ReStatic
|
||||||
@ -187,12 +187,12 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
|
|||||||
| ty::ReEarlyBound(..) => r,
|
| ty::ReEarlyBound(..) => r,
|
||||||
|
|
||||||
ty::RePlaceholder(placeholder) => canonicalizer.canonical_var_for_region(
|
ty::RePlaceholder(placeholder) => canonicalizer.canonical_var_for_region(
|
||||||
CanonicalVarInfo { kind: CanonicalVarKind::PlaceholderRegion(*placeholder) },
|
CanonicalVarInfo { kind: CanonicalVarKind::PlaceholderRegion(placeholder) },
|
||||||
r,
|
r,
|
||||||
),
|
),
|
||||||
|
|
||||||
ty::ReVar(vid) => {
|
ty::ReVar(vid) => {
|
||||||
let universe = canonicalizer.region_var_universe(*vid);
|
let universe = canonicalizer.region_var_universe(vid);
|
||||||
canonicalizer.canonical_var_for_region(
|
canonicalizer.canonical_var_for_region(
|
||||||
CanonicalVarInfo { kind: CanonicalVarKind::Region(universe) },
|
CanonicalVarInfo { kind: CanonicalVarKind::Region(universe) },
|
||||||
r,
|
r,
|
||||||
@ -240,7 +240,7 @@ impl CanonicalizeMode for CanonicalizeUserTypeAnnotation {
|
|||||||
canonicalizer: &mut Canonicalizer<'_, 'tcx>,
|
canonicalizer: &mut Canonicalizer<'_, 'tcx>,
|
||||||
r: ty::Region<'tcx>,
|
r: ty::Region<'tcx>,
|
||||||
) -> ty::Region<'tcx> {
|
) -> ty::Region<'tcx> {
|
||||||
match r {
|
match *r {
|
||||||
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReErased | ty::ReStatic => r,
|
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReErased | ty::ReStatic => r,
|
||||||
ty::ReVar(_) => canonicalizer.canonical_var_for_region_in_root_universe(r),
|
ty::ReVar(_) => canonicalizer.canonical_var_for_region_in_root_universe(r),
|
||||||
_ => {
|
_ => {
|
||||||
@ -311,11 +311,7 @@ impl CanonicalizeMode for CanonicalizeFreeRegionsOtherThanStatic {
|
|||||||
canonicalizer: &mut Canonicalizer<'_, 'tcx>,
|
canonicalizer: &mut Canonicalizer<'_, 'tcx>,
|
||||||
r: ty::Region<'tcx>,
|
r: ty::Region<'tcx>,
|
||||||
) -> ty::Region<'tcx> {
|
) -> ty::Region<'tcx> {
|
||||||
if let ty::ReStatic = r {
|
if r.is_static() { r } else { canonicalizer.canonical_var_for_region_in_root_universe(r) }
|
||||||
r
|
|
||||||
} else {
|
|
||||||
canonicalizer.canonical_var_for_region_in_root_universe(r)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn any(&self) -> bool {
|
fn any(&self) -> bool {
|
||||||
|
@ -237,10 +237,9 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||||||
v.var_values[BoundVar::new(index)]
|
v.var_values[BoundVar::new(index)]
|
||||||
});
|
});
|
||||||
match (original_value.unpack(), result_value.unpack()) {
|
match (original_value.unpack(), result_value.unpack()) {
|
||||||
(
|
(GenericArgKind::Lifetime(re1), GenericArgKind::Lifetime(re2))
|
||||||
GenericArgKind::Lifetime(ty::ReErased),
|
if re1.is_erased() && re2.is_erased() =>
|
||||||
GenericArgKind::Lifetime(ty::ReErased),
|
{
|
||||||
) => {
|
|
||||||
// No action needed.
|
// No action needed.
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,7 +428,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||||||
}
|
}
|
||||||
GenericArgKind::Lifetime(result_value) => {
|
GenericArgKind::Lifetime(result_value) => {
|
||||||
// e.g., here `result_value` might be `'?1` in the example above...
|
// e.g., here `result_value` might be `'?1` in the example above...
|
||||||
if let &ty::RegionKind::ReLateBound(debruijn, br) = result_value {
|
if let ty::RegionKind::ReLateBound(debruijn, br) = *result_value {
|
||||||
// ... in which case we would set `canonical_vars[0]` to `Some('static)`.
|
// ... in which case we would set `canonical_vars[0]` to `Some('static)`.
|
||||||
|
|
||||||
// We only allow a `ty::INNERMOST` index in substitutions.
|
// We only allow a `ty::INNERMOST` index in substitutions.
|
||||||
@ -558,10 +557,9 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||||||
obligations
|
obligations
|
||||||
.extend(self.at(cause, param_env).eq(v1, v2)?.into_obligations());
|
.extend(self.at(cause, param_env).eq(v1, v2)?.into_obligations());
|
||||||
}
|
}
|
||||||
(
|
(GenericArgKind::Lifetime(re1), GenericArgKind::Lifetime(re2))
|
||||||
GenericArgKind::Lifetime(ty::ReErased),
|
if re1.is_erased() && re2.is_erased() =>
|
||||||
GenericArgKind::Lifetime(ty::ReErased),
|
{
|
||||||
) => {
|
|
||||||
// no action needed
|
// no action needed
|
||||||
}
|
}
|
||||||
(GenericArgKind::Lifetime(v1), GenericArgKind::Lifetime(v2)) => {
|
(GenericArgKind::Lifetime(v1), GenericArgKind::Lifetime(v2)) => {
|
||||||
|
@ -915,7 +915,7 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
|
|||||||
debug_assert_eq!(r, _r);
|
debug_assert_eq!(r, _r);
|
||||||
debug!("ConstInferUnifier: r={:?}", r);
|
debug!("ConstInferUnifier: r={:?}", r);
|
||||||
|
|
||||||
match r {
|
match *r {
|
||||||
// Never make variables for regions bound within the type itself,
|
// Never make variables for regions bound within the type itself,
|
||||||
// nor for erased regions.
|
// nor for erased regions.
|
||||||
ty::ReLateBound(..) | ty::ReErased => {
|
ty::ReLateBound(..) | ty::ReErased => {
|
||||||
|
@ -239,7 +239,7 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Explain the region we are capturing.
|
// Explain the region we are capturing.
|
||||||
match hidden_region {
|
match *hidden_region {
|
||||||
ty::ReEmpty(ty::UniverseIndex::ROOT) => {
|
ty::ReEmpty(ty::UniverseIndex::ROOT) => {
|
||||||
// All lifetimes shorter than the function body are `empty` in
|
// All lifetimes shorter than the function body are `empty` in
|
||||||
// lexical region resolution. The default explanation of "an empty
|
// lexical region resolution. The default explanation of "an empty
|
||||||
@ -1114,7 +1114,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn push_ty_ref<'tcx>(
|
fn push_ty_ref<'tcx>(
|
||||||
region: &ty::Region<'tcx>,
|
region: ty::Region<'tcx>,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
mutbl: hir::Mutability,
|
mutbl: hir::Mutability,
|
||||||
s: &mut DiagnosticStyledString,
|
s: &mut DiagnosticStyledString,
|
||||||
@ -1335,14 +1335,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
// When finding T != &T, highlight only the borrow
|
// When finding T != &T, highlight only the borrow
|
||||||
(&ty::Ref(r1, ref_ty1, mutbl1), _) if equals(ref_ty1, t2) => {
|
(&ty::Ref(r1, ref_ty1, mutbl1), _) if equals(ref_ty1, t2) => {
|
||||||
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
|
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
|
||||||
push_ty_ref(&r1, ref_ty1, mutbl1, &mut values.0);
|
push_ty_ref(r1, ref_ty1, mutbl1, &mut values.0);
|
||||||
values.1.push_normal(t2.to_string());
|
values.1.push_normal(t2.to_string());
|
||||||
values
|
values
|
||||||
}
|
}
|
||||||
(_, &ty::Ref(r2, ref_ty2, mutbl2)) if equals(t1, ref_ty2) => {
|
(_, &ty::Ref(r2, ref_ty2, mutbl2)) if equals(t1, ref_ty2) => {
|
||||||
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
|
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
|
||||||
values.0.push_normal(t1.to_string());
|
values.0.push_normal(t1.to_string());
|
||||||
push_ty_ref(&r2, ref_ty2, mutbl2, &mut values.1);
|
push_ty_ref(r2, ref_ty2, mutbl2, &mut values.1);
|
||||||
values
|
values
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1351,8 +1351,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
if equals(ref_ty1, ref_ty2) =>
|
if equals(ref_ty1, ref_ty2) =>
|
||||||
{
|
{
|
||||||
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
|
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
|
||||||
push_ty_ref(&r1, ref_ty1, mutbl1, &mut values.0);
|
push_ty_ref(r1, ref_ty1, mutbl1, &mut values.0);
|
||||||
push_ty_ref(&r2, ref_ty2, mutbl2, &mut values.1);
|
push_ty_ref(r2, ref_ty2, mutbl2, &mut values.1);
|
||||||
values
|
values
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,7 +369,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
pub fn extract_inference_diagnostics_data(
|
pub fn extract_inference_diagnostics_data(
|
||||||
&self,
|
&self,
|
||||||
arg: GenericArg<'tcx>,
|
arg: GenericArg<'tcx>,
|
||||||
highlight: Option<ty::print::RegionHighlightMode>,
|
highlight: Option<ty::print::RegionHighlightMode<'tcx>>,
|
||||||
) -> InferenceDiagnosticsData {
|
) -> InferenceDiagnosticsData {
|
||||||
match arg.unpack() {
|
match arg.unpack() {
|
||||||
GenericArgKind::Type(ty) => {
|
GenericArgKind::Type(ty) => {
|
||||||
|
@ -10,7 +10,7 @@ use rustc_data_structures::stable_set::FxHashSet;
|
|||||||
use rustc_errors::{Applicability, ErrorReported};
|
use rustc_errors::{Applicability, ErrorReported};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::intravisit::Visitor;
|
use rustc_hir::intravisit::Visitor;
|
||||||
use rustc_middle::ty::{self, TypeVisitor};
|
use rustc_middle::ty::TypeVisitor;
|
||||||
use rustc_span::MultiSpan;
|
use rustc_span::MultiSpan;
|
||||||
|
|
||||||
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
@ -22,7 +22,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
RegionResolutionError::ConcreteFailure(origin, sub, sup) => (origin, sub, sup),
|
RegionResolutionError::ConcreteFailure(origin, sub, sup) => (origin, sub, sup),
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
if *sub != ty::RegionKind::ReStatic {
|
if !sub.is_static() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let cause = match origin {
|
let cause = match origin {
|
||||||
|
@ -66,9 +66,9 @@ impl<'cx, 'tcx> NiceRegionError<'cx, 'tcx> {
|
|||||||
|
|
||||||
pub fn regions(&self) -> Option<(Span, ty::Region<'tcx>, ty::Region<'tcx>)> {
|
pub fn regions(&self) -> Option<(Span, ty::Region<'tcx>, ty::Region<'tcx>)> {
|
||||||
match (&self.error, self.regions) {
|
match (&self.error, self.regions) {
|
||||||
(Some(ConcreteFailure(origin, sub, sup)), None) => Some((origin.span(), sub, sup)),
|
(Some(ConcreteFailure(origin, sub, sup)), None) => Some((origin.span(), *sub, *sup)),
|
||||||
(Some(SubSupConflict(_, _, origin, sub, _, sup, _)), None) => {
|
(Some(SubSupConflict(_, _, origin, sub, _, sup, _)), None) => {
|
||||||
Some((origin.span(), sub, sup))
|
Some((origin.span(), *sub, *sup))
|
||||||
}
|
}
|
||||||
(None, Some((span, sub, sup))) => Some((span, sub, sup)),
|
(None, Some((span, sub, sup))) => Some((span, sub, sup)),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -48,7 +48,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
|
|
||||||
// Suggesting to add a `'static` lifetime to a parameter is nearly always incorrect,
|
// Suggesting to add a `'static` lifetime to a parameter is nearly always incorrect,
|
||||||
// and can steer users down the wrong path.
|
// and can steer users down the wrong path.
|
||||||
if *named == ty::ReStatic {
|
if named.is_static() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,13 +3,14 @@ use crate::infer::lexical_region_resolve::RegionResolutionError;
|
|||||||
use crate::infer::ValuePairs;
|
use crate::infer::ValuePairs;
|
||||||
use crate::infer::{SubregionOrigin, TypeTrace};
|
use crate::infer::{SubregionOrigin, TypeTrace};
|
||||||
use crate::traits::{ObligationCause, ObligationCauseCode};
|
use crate::traits::{ObligationCause, ObligationCauseCode};
|
||||||
|
use rustc_data_structures::intern::Interned;
|
||||||
use rustc_errors::DiagnosticBuilder;
|
use rustc_errors::DiagnosticBuilder;
|
||||||
use rustc_hir::def::Namespace;
|
use rustc_hir::def::Namespace;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_middle::ty::error::ExpectedFound;
|
use rustc_middle::ty::error::ExpectedFound;
|
||||||
use rustc_middle::ty::print::{FmtPrinter, Print, RegionHighlightMode};
|
use rustc_middle::ty::print::{FmtPrinter, Print, RegionHighlightMode};
|
||||||
use rustc_middle::ty::subst::SubstsRef;
|
use rustc_middle::ty::subst::SubstsRef;
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, RePlaceholder, ReVar, Region, TyCtxt};
|
||||||
|
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
|
|
||||||
@ -31,15 +32,15 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||||||
vid,
|
vid,
|
||||||
_,
|
_,
|
||||||
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
|
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
|
||||||
sub_placeholder @ ty::RePlaceholder(_),
|
sub_placeholder @ Region(Interned(RePlaceholder(_), _)),
|
||||||
_,
|
_,
|
||||||
sup_placeholder @ ty::RePlaceholder(_),
|
sup_placeholder @ Region(Interned(RePlaceholder(_), _)),
|
||||||
_,
|
_,
|
||||||
)) => self.try_report_trait_placeholder_mismatch(
|
)) => self.try_report_trait_placeholder_mismatch(
|
||||||
Some(self.tcx().mk_region(ty::ReVar(*vid))),
|
Some(self.tcx().mk_region(ReVar(*vid))),
|
||||||
cause,
|
cause,
|
||||||
Some(sub_placeholder),
|
Some(*sub_placeholder),
|
||||||
Some(sup_placeholder),
|
Some(*sup_placeholder),
|
||||||
values,
|
values,
|
||||||
),
|
),
|
||||||
|
|
||||||
@ -47,14 +48,14 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||||||
vid,
|
vid,
|
||||||
_,
|
_,
|
||||||
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
|
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
|
||||||
sub_placeholder @ ty::RePlaceholder(_),
|
sub_placeholder @ Region(Interned(RePlaceholder(_), _)),
|
||||||
_,
|
_,
|
||||||
_,
|
_,
|
||||||
_,
|
_,
|
||||||
)) => self.try_report_trait_placeholder_mismatch(
|
)) => self.try_report_trait_placeholder_mismatch(
|
||||||
Some(self.tcx().mk_region(ty::ReVar(*vid))),
|
Some(self.tcx().mk_region(ReVar(*vid))),
|
||||||
cause,
|
cause,
|
||||||
Some(sub_placeholder),
|
Some(*sub_placeholder),
|
||||||
None,
|
None,
|
||||||
values,
|
values,
|
||||||
),
|
),
|
||||||
@ -65,10 +66,10 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||||||
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
|
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
|
||||||
_,
|
_,
|
||||||
_,
|
_,
|
||||||
sup_placeholder @ ty::RePlaceholder(_),
|
sup_placeholder @ Region(Interned(RePlaceholder(_), _)),
|
||||||
_,
|
_,
|
||||||
)) => self.try_report_trait_placeholder_mismatch(
|
)) => self.try_report_trait_placeholder_mismatch(
|
||||||
Some(self.tcx().mk_region(ty::ReVar(*vid))),
|
Some(self.tcx().mk_region(ReVar(*vid))),
|
||||||
cause,
|
cause,
|
||||||
None,
|
None,
|
||||||
Some(*sup_placeholder),
|
Some(*sup_placeholder),
|
||||||
@ -81,10 +82,10 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||||||
_,
|
_,
|
||||||
_,
|
_,
|
||||||
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
|
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
|
||||||
sup_placeholder @ ty::RePlaceholder(_),
|
sup_placeholder @ Region(Interned(RePlaceholder(_), _)),
|
||||||
_,
|
_,
|
||||||
)) => self.try_report_trait_placeholder_mismatch(
|
)) => self.try_report_trait_placeholder_mismatch(
|
||||||
Some(self.tcx().mk_region(ty::ReVar(*vid))),
|
Some(self.tcx().mk_region(ReVar(*vid))),
|
||||||
cause,
|
cause,
|
||||||
None,
|
None,
|
||||||
Some(*sup_placeholder),
|
Some(*sup_placeholder),
|
||||||
@ -96,9 +97,9 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||||||
_,
|
_,
|
||||||
_,
|
_,
|
||||||
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
|
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
|
||||||
sup_placeholder @ ty::RePlaceholder(_),
|
sup_placeholder @ Region(Interned(RePlaceholder(_), _)),
|
||||||
)) => self.try_report_trait_placeholder_mismatch(
|
)) => self.try_report_trait_placeholder_mismatch(
|
||||||
Some(self.tcx().mk_region(ty::ReVar(*vid))),
|
Some(self.tcx().mk_region(ReVar(*vid))),
|
||||||
cause,
|
cause,
|
||||||
None,
|
None,
|
||||||
Some(*sup_placeholder),
|
Some(*sup_placeholder),
|
||||||
@ -107,8 +108,8 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||||||
|
|
||||||
Some(RegionResolutionError::ConcreteFailure(
|
Some(RegionResolutionError::ConcreteFailure(
|
||||||
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
|
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
|
||||||
sub_region @ ty::RePlaceholder(_),
|
sub_region @ Region(Interned(RePlaceholder(_), _)),
|
||||||
sup_region @ ty::RePlaceholder(_),
|
sup_region @ Region(Interned(RePlaceholder(_), _)),
|
||||||
)) => self.try_report_trait_placeholder_mismatch(
|
)) => self.try_report_trait_placeholder_mismatch(
|
||||||
None,
|
None,
|
||||||
cause,
|
cause,
|
||||||
@ -119,12 +120,12 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||||||
|
|
||||||
Some(RegionResolutionError::ConcreteFailure(
|
Some(RegionResolutionError::ConcreteFailure(
|
||||||
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
|
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
|
||||||
sub_region @ ty::RePlaceholder(_),
|
sub_region @ Region(Interned(RePlaceholder(_), _)),
|
||||||
sup_region,
|
sup_region,
|
||||||
)) => self.try_report_trait_placeholder_mismatch(
|
)) => self.try_report_trait_placeholder_mismatch(
|
||||||
(!sup_region.has_name()).then_some(sup_region),
|
(!sup_region.has_name()).then_some(*sup_region),
|
||||||
cause,
|
cause,
|
||||||
Some(sub_region),
|
Some(*sub_region),
|
||||||
None,
|
None,
|
||||||
values,
|
values,
|
||||||
),
|
),
|
||||||
@ -132,12 +133,12 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||||||
Some(RegionResolutionError::ConcreteFailure(
|
Some(RegionResolutionError::ConcreteFailure(
|
||||||
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
|
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
|
||||||
sub_region,
|
sub_region,
|
||||||
sup_region @ ty::RePlaceholder(_),
|
sup_region @ Region(Interned(RePlaceholder(_), _)),
|
||||||
)) => self.try_report_trait_placeholder_mismatch(
|
)) => self.try_report_trait_placeholder_mismatch(
|
||||||
(!sub_region.has_name()).then_some(sub_region),
|
(!sub_region.has_name()).then_some(*sub_region),
|
||||||
cause,
|
cause,
|
||||||
None,
|
None,
|
||||||
Some(sup_region),
|
Some(*sup_region),
|
||||||
values,
|
values,
|
||||||
),
|
),
|
||||||
|
|
||||||
@ -147,10 +148,10 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||||||
|
|
||||||
fn try_report_trait_placeholder_mismatch(
|
fn try_report_trait_placeholder_mismatch(
|
||||||
&self,
|
&self,
|
||||||
vid: Option<ty::Region<'tcx>>,
|
vid: Option<Region<'tcx>>,
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
sub_placeholder: Option<ty::Region<'tcx>>,
|
sub_placeholder: Option<Region<'tcx>>,
|
||||||
sup_placeholder: Option<ty::Region<'tcx>>,
|
sup_placeholder: Option<Region<'tcx>>,
|
||||||
value_pairs: &ValuePairs<'tcx>,
|
value_pairs: &ValuePairs<'tcx>,
|
||||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
) -> Option<DiagnosticBuilder<'tcx>> {
|
||||||
let (expected_substs, found_substs, trait_def_id) = match value_pairs {
|
let (expected_substs, found_substs, trait_def_id) = match value_pairs {
|
||||||
@ -193,10 +194,10 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||||||
#[instrument(level = "debug", skip(self))]
|
#[instrument(level = "debug", skip(self))]
|
||||||
fn report_trait_placeholder_mismatch(
|
fn report_trait_placeholder_mismatch(
|
||||||
&self,
|
&self,
|
||||||
vid: Option<ty::Region<'tcx>>,
|
vid: Option<Region<'tcx>>,
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
sub_placeholder: Option<ty::Region<'tcx>>,
|
sub_placeholder: Option<Region<'tcx>>,
|
||||||
sup_placeholder: Option<ty::Region<'tcx>>,
|
sup_placeholder: Option<Region<'tcx>>,
|
||||||
trait_def_id: DefId,
|
trait_def_id: DefId,
|
||||||
expected_substs: SubstsRef<'tcx>,
|
expected_substs: SubstsRef<'tcx>,
|
||||||
actual_substs: SubstsRef<'tcx>,
|
actual_substs: SubstsRef<'tcx>,
|
||||||
@ -306,13 +307,13 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||||||
fn explain_actual_impl_that_was_found(
|
fn explain_actual_impl_that_was_found(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut DiagnosticBuilder<'_>,
|
||||||
sub_placeholder: Option<ty::Region<'tcx>>,
|
sub_placeholder: Option<Region<'tcx>>,
|
||||||
sup_placeholder: Option<ty::Region<'tcx>>,
|
sup_placeholder: Option<Region<'tcx>>,
|
||||||
has_sub: Option<usize>,
|
has_sub: Option<usize>,
|
||||||
has_sup: Option<usize>,
|
has_sup: Option<usize>,
|
||||||
expected_trait_ref: ty::TraitRef<'tcx>,
|
expected_trait_ref: ty::TraitRef<'tcx>,
|
||||||
actual_trait_ref: ty::TraitRef<'tcx>,
|
actual_trait_ref: ty::TraitRef<'tcx>,
|
||||||
vid: Option<ty::Region<'tcx>>,
|
vid: Option<Region<'tcx>>,
|
||||||
expected_has_vid: Option<usize>,
|
expected_has_vid: Option<usize>,
|
||||||
actual_has_vid: Option<usize>,
|
actual_has_vid: Option<usize>,
|
||||||
any_self_ty_has_vid: bool,
|
any_self_ty_has_vid: bool,
|
||||||
@ -322,7 +323,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
struct Highlighted<'tcx, T> {
|
struct Highlighted<'tcx, T> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
highlight: RegionHighlightMode,
|
highlight: RegionHighlightMode<'tcx>,
|
||||||
value: T,
|
value: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,7 +367,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||||||
|
|
||||||
let highlight_trait_ref = |trait_ref| Highlighted {
|
let highlight_trait_ref = |trait_ref| Highlighted {
|
||||||
tcx: self.tcx(),
|
tcx: self.tcx(),
|
||||||
highlight: RegionHighlightMode::default(),
|
highlight: RegionHighlightMode::new(self.tcx()),
|
||||||
value: trait_ref,
|
value: trait_ref,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,8 +10,7 @@ use rustc_hir::def_id::DefId;
|
|||||||
use rustc_hir::intravisit::{walk_ty, Visitor};
|
use rustc_hir::intravisit::{walk_ty, Visitor};
|
||||||
use rustc_hir::{self as hir, GenericBound, Item, ItemKind, Lifetime, LifetimeName, Node, TyKind};
|
use rustc_hir::{self as hir, GenericBound, Item, ItemKind, Lifetime, LifetimeName, Node, TyKind};
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
self, AssocItemContainer, RegionKind, StaticLifetimeVisitor, Ty, TyCtxt, TypeFoldable,
|
self, AssocItemContainer, StaticLifetimeVisitor, Ty, TyCtxt, TypeFoldable, TypeVisitor,
|
||||||
TypeVisitor,
|
|
||||||
};
|
};
|
||||||
use rustc_span::symbol::Ident;
|
use rustc_span::symbol::Ident;
|
||||||
use rustc_span::{MultiSpan, Span};
|
use rustc_span::{MultiSpan, Span};
|
||||||
@ -33,25 +32,23 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
sup_origin,
|
sup_origin,
|
||||||
sup_r,
|
sup_r,
|
||||||
spans,
|
spans,
|
||||||
) if **sub_r == RegionKind::ReStatic => {
|
) if sub_r.is_static() => (var_origin, sub_origin, sub_r, sup_origin, sup_r, spans),
|
||||||
(var_origin, sub_origin, sub_r, sup_origin, sup_r, spans)
|
|
||||||
}
|
|
||||||
RegionResolutionError::ConcreteFailure(
|
RegionResolutionError::ConcreteFailure(
|
||||||
SubregionOrigin::Subtype(box TypeTrace { cause, .. }),
|
SubregionOrigin::Subtype(box TypeTrace { cause, .. }),
|
||||||
sub_r,
|
sub_r,
|
||||||
sup_r,
|
sup_r,
|
||||||
) if **sub_r == RegionKind::ReStatic => {
|
) if sub_r.is_static() => {
|
||||||
// This is for an implicit `'static` requirement coming from `impl dyn Trait {}`.
|
// This is for an implicit `'static` requirement coming from `impl dyn Trait {}`.
|
||||||
if let ObligationCauseCode::UnifyReceiver(ctxt) = cause.code() {
|
if let ObligationCauseCode::UnifyReceiver(ctxt) = cause.code() {
|
||||||
// This may have a closure and it would cause ICE
|
// This may have a closure and it would cause ICE
|
||||||
// through `find_param_with_region` (#78262).
|
// through `find_param_with_region` (#78262).
|
||||||
let anon_reg_sup = tcx.is_suitable_region(sup_r)?;
|
let anon_reg_sup = tcx.is_suitable_region(*sup_r)?;
|
||||||
let fn_returns = tcx.return_type_impl_or_dyn_traits(anon_reg_sup.def_id);
|
let fn_returns = tcx.return_type_impl_or_dyn_traits(anon_reg_sup.def_id);
|
||||||
if fn_returns.is_empty() {
|
if fn_returns.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let param = self.find_param_with_region(sup_r, sub_r)?;
|
let param = self.find_param_with_region(*sup_r, *sub_r)?;
|
||||||
let lifetime = if sup_r.has_name() {
|
let lifetime = if sup_r.has_name() {
|
||||||
format!("lifetime `{}`", sup_r)
|
format!("lifetime `{}`", sup_r)
|
||||||
} else {
|
} else {
|
||||||
@ -101,11 +98,11 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
"try_report_static_impl_trait(var={:?}, sub={:?} {:?} sup={:?} {:?})",
|
"try_report_static_impl_trait(var={:?}, sub={:?} {:?} sup={:?} {:?})",
|
||||||
var_origin, sub_origin, sub_r, sup_origin, sup_r
|
var_origin, sub_origin, sub_r, sup_origin, sup_r
|
||||||
);
|
);
|
||||||
let anon_reg_sup = tcx.is_suitable_region(sup_r)?;
|
let anon_reg_sup = tcx.is_suitable_region(*sup_r)?;
|
||||||
debug!("try_report_static_impl_trait: anon_reg_sup={:?}", anon_reg_sup);
|
debug!("try_report_static_impl_trait: anon_reg_sup={:?}", anon_reg_sup);
|
||||||
let sp = var_origin.span();
|
let sp = var_origin.span();
|
||||||
let return_sp = sub_origin.span();
|
let return_sp = sub_origin.span();
|
||||||
let param = self.find_param_with_region(sup_r, sub_r)?;
|
let param = self.find_param_with_region(*sup_r, *sub_r)?;
|
||||||
let (lifetime_name, lifetime) = if sup_r.has_name() {
|
let (lifetime_name, lifetime) = if sup_r.has_name() {
|
||||||
(sup_r.to_string(), format!("lifetime `{}`", sup_r))
|
(sup_r.to_string(), format!("lifetime `{}`", sup_r))
|
||||||
} else {
|
} else {
|
||||||
@ -560,7 +557,7 @@ pub(super) struct TraitObjectVisitor(pub(super) FxHashSet<DefId>);
|
|||||||
impl<'tcx> TypeVisitor<'tcx> for TraitObjectVisitor {
|
impl<'tcx> TypeVisitor<'tcx> for TraitObjectVisitor {
|
||||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
match t.kind() {
|
match t.kind() {
|
||||||
ty::Dynamic(preds, RegionKind::ReStatic) => {
|
ty::Dynamic(preds, re) if re.is_static() => {
|
||||||
if let Some(def_id) = preds.principal_def_id() {
|
if let Some(def_id) = preds.principal_def_id() {
|
||||||
self.0.insert(def_id);
|
self.0.insert(def_id);
|
||||||
}
|
}
|
||||||
|
@ -81,21 +81,21 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
|
|
||||||
// Mark all unnamed regions in the type with a number.
|
// Mark all unnamed regions in the type with a number.
|
||||||
// This diagnostic is called in response to lifetime errors, so be informative.
|
// This diagnostic is called in response to lifetime errors, so be informative.
|
||||||
struct HighlightBuilder {
|
struct HighlightBuilder<'tcx> {
|
||||||
highlight: RegionHighlightMode,
|
highlight: RegionHighlightMode<'tcx>,
|
||||||
counter: usize,
|
counter: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HighlightBuilder {
|
impl<'tcx> HighlightBuilder<'tcx> {
|
||||||
fn build(ty: Ty<'_>) -> RegionHighlightMode {
|
fn build(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> RegionHighlightMode<'tcx> {
|
||||||
let mut builder =
|
let mut builder =
|
||||||
HighlightBuilder { highlight: RegionHighlightMode::default(), counter: 1 };
|
HighlightBuilder { highlight: RegionHighlightMode::new(tcx), counter: 1 };
|
||||||
builder.visit_ty(ty);
|
builder.visit_ty(ty);
|
||||||
builder.highlight
|
builder.highlight
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> ty::fold::TypeVisitor<'tcx> for HighlightBuilder {
|
impl<'tcx> ty::fold::TypeVisitor<'tcx> for HighlightBuilder<'tcx> {
|
||||||
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
if !r.has_name() && self.counter <= 3 {
|
if !r.has_name() && self.counter <= 3 {
|
||||||
self.highlight.highlighting_region(r, self.counter);
|
self.highlight.highlighting_region(r, self.counter);
|
||||||
@ -105,12 +105,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let expected_highlight = HighlightBuilder::build(expected);
|
let expected_highlight = HighlightBuilder::build(self.tcx(), expected);
|
||||||
let expected = self
|
let expected = self
|
||||||
.infcx
|
.infcx
|
||||||
.extract_inference_diagnostics_data(expected.into(), Some(expected_highlight))
|
.extract_inference_diagnostics_data(expected.into(), Some(expected_highlight))
|
||||||
.name;
|
.name;
|
||||||
let found_highlight = HighlightBuilder::build(found);
|
let found_highlight = HighlightBuilder::build(self.tcx(), found);
|
||||||
let found =
|
let found =
|
||||||
self.infcx.extract_inference_diagnostics_data(found.into(), Some(found_highlight)).name;
|
self.infcx.extract_inference_diagnostics_data(found.into(), Some(found_highlight)).name;
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
let ty = fn_sig.inputs()[index];
|
let ty = fn_sig.inputs()[index];
|
||||||
let mut found_anon_region = false;
|
let mut found_anon_region = false;
|
||||||
let new_param_ty = self.tcx().fold_regions(ty, &mut false, |r, _| {
|
let new_param_ty = self.tcx().fold_regions(ty, &mut false, |r, _| {
|
||||||
if *r == *anon_region {
|
if r == anon_region {
|
||||||
found_anon_region = true;
|
found_anon_region = true;
|
||||||
replace_region
|
replace_region
|
||||||
} else {
|
} else {
|
||||||
|
@ -115,7 +115,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
infer::Subtype(box trace) => {
|
infer::Subtype(box trace) => {
|
||||||
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
|
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
|
||||||
let mut err = self.report_and_explain_type_error(trace, &terr);
|
let mut err = self.report_and_explain_type_error(trace, &terr);
|
||||||
match (sub, sup) {
|
match (*sub, *sup) {
|
||||||
(ty::RePlaceholder(_), ty::RePlaceholder(_)) => {}
|
(ty::RePlaceholder(_), ty::RePlaceholder(_)) => {}
|
||||||
(ty::RePlaceholder(_), _) => {
|
(ty::RePlaceholder(_), _) => {
|
||||||
note_and_explain_region(
|
note_and_explain_region(
|
||||||
|
@ -41,8 +41,8 @@ pub struct FreeRegionMap<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> FreeRegionMap<'tcx> {
|
impl<'tcx> FreeRegionMap<'tcx> {
|
||||||
pub fn elements(&self) -> impl Iterator<Item = &Region<'tcx>> {
|
pub fn elements(&self) -> impl Iterator<Item = Region<'tcx>> + '_ {
|
||||||
self.relation.elements()
|
self.relation.elements().copied()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
@ -91,7 +91,7 @@ impl<'tcx> FreeRegionMap<'tcx> {
|
|||||||
|
|
||||||
/// True for free regions other than `'static`.
|
/// True for free regions other than `'static`.
|
||||||
pub fn is_free(&self, r: Region<'_>) -> bool {
|
pub fn is_free(&self, r: Region<'_>) -> bool {
|
||||||
matches!(r, ty::ReEarlyBound(_) | ty::ReFree(_))
|
matches!(*r, ty::ReEarlyBound(_) | ty::ReFree(_))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// True if `r` is a free region or static of the sort that this
|
/// True if `r` is a free region or static of the sort that this
|
||||||
|
@ -13,6 +13,7 @@ use rustc_data_structures::fx::FxHashSet;
|
|||||||
use rustc_data_structures::graph::implementation::{
|
use rustc_data_structures::graph::implementation::{
|
||||||
Direction, Graph, NodeIndex, INCOMING, OUTGOING,
|
Direction, Graph, NodeIndex, INCOMING, OUTGOING,
|
||||||
};
|
};
|
||||||
|
use rustc_data_structures::intern::Interned;
|
||||||
use rustc_index::vec::{Idx, IndexVec};
|
use rustc_index::vec::{Idx, IndexVec};
|
||||||
use rustc_middle::ty::fold::TypeFoldable;
|
use rustc_middle::ty::fold::TypeFoldable;
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
@ -250,8 +251,8 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||||||
changes.push(b_vid);
|
changes.push(b_vid);
|
||||||
}
|
}
|
||||||
if let Some(a_vid) = a_vid {
|
if let Some(a_vid) = a_vid {
|
||||||
match *b_data {
|
match b_data {
|
||||||
VarValue::Value(ReStatic) | VarValue::ErrorValue => (),
|
VarValue::Value(Region(Interned(ReStatic, _))) | VarValue::ErrorValue => (),
|
||||||
_ => {
|
_ => {
|
||||||
constraints[a_vid].push((a_vid, b_vid));
|
constraints[a_vid].push((a_vid, b_vid));
|
||||||
constraints[b_vid].push((a_vid, b_vid));
|
constraints[b_vid].push((a_vid, b_vid));
|
||||||
@ -270,7 +271,10 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||||||
if self.expand_node(a_region, b_vid, b_data) {
|
if self.expand_node(a_region, b_vid, b_data) {
|
||||||
changes.push(b_vid);
|
changes.push(b_vid);
|
||||||
}
|
}
|
||||||
!matches!(b_data, VarValue::Value(ReStatic) | VarValue::ErrorValue)
|
!matches!(
|
||||||
|
b_data,
|
||||||
|
VarValue::Value(Region(Interned(ReStatic, _))) | VarValue::ErrorValue
|
||||||
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -301,8 +305,8 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||||||
// check below for a common case, here purely as an
|
// check below for a common case, here purely as an
|
||||||
// optimization.
|
// optimization.
|
||||||
let b_universe = self.var_infos[b_vid].universe;
|
let b_universe = self.var_infos[b_vid].universe;
|
||||||
if let ReEmpty(a_universe) = a_region {
|
if let ReEmpty(a_universe) = *a_region {
|
||||||
if *a_universe == b_universe {
|
if a_universe == b_universe {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -321,7 +325,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||||||
// tighter bound than `'static`.
|
// tighter bound than `'static`.
|
||||||
//
|
//
|
||||||
// (This might e.g. arise from being asked to prove `for<'a> { 'b: 'a }`.)
|
// (This might e.g. arise from being asked to prove `for<'a> { 'b: 'a }`.)
|
||||||
if let ty::RePlaceholder(p) = lub {
|
if let ty::RePlaceholder(p) = *lub {
|
||||||
if b_universe.cannot_name(p.universe) {
|
if b_universe.cannot_name(p.universe) {
|
||||||
lub = self.tcx().lifetimes.re_static;
|
lub = self.tcx().lifetimes.re_static;
|
||||||
}
|
}
|
||||||
@ -372,12 +376,12 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||||||
/// term "concrete regions").
|
/// term "concrete regions").
|
||||||
#[instrument(level = "trace", skip(self))]
|
#[instrument(level = "trace", skip(self))]
|
||||||
fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> {
|
fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> {
|
||||||
let r = match (a, b) {
|
let r = match (*a, *b) {
|
||||||
(&ReLateBound(..), _) | (_, &ReLateBound(..)) | (&ReErased, _) | (_, &ReErased) => {
|
(ReLateBound(..), _) | (_, ReLateBound(..)) | (ReErased, _) | (_, ReErased) => {
|
||||||
bug!("cannot relate region: LUB({:?}, {:?})", a, b);
|
bug!("cannot relate region: LUB({:?}, {:?})", a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
(&ReVar(v_id), _) | (_, &ReVar(v_id)) => {
|
(ReVar(v_id), _) | (_, ReVar(v_id)) => {
|
||||||
span_bug!(
|
span_bug!(
|
||||||
self.var_infos[v_id].origin.span(),
|
self.var_infos[v_id].origin.span(),
|
||||||
"lub_concrete_regions invoked with non-concrete \
|
"lub_concrete_regions invoked with non-concrete \
|
||||||
@ -387,27 +391,32 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
(&ReStatic, _) | (_, &ReStatic) => {
|
(ReStatic, _) | (_, ReStatic) => {
|
||||||
// nothing lives longer than `'static`
|
// nothing lives longer than `'static`
|
||||||
self.tcx().lifetimes.re_static
|
self.tcx().lifetimes.re_static
|
||||||
}
|
}
|
||||||
|
|
||||||
(&ReEmpty(_), r @ (ReEarlyBound(_) | ReFree(_)))
|
(ReEmpty(_), ReEarlyBound(_) | ReFree(_)) => {
|
||||||
| (r @ (ReEarlyBound(_) | ReFree(_)), &ReEmpty(_)) => {
|
|
||||||
// All empty regions are less than early-bound, free,
|
// All empty regions are less than early-bound, free,
|
||||||
// and scope regions.
|
// and scope regions.
|
||||||
r
|
b
|
||||||
}
|
}
|
||||||
|
|
||||||
(&ReEmpty(a_ui), &ReEmpty(b_ui)) => {
|
(ReEarlyBound(_) | ReFree(_), ReEmpty(_)) => {
|
||||||
|
// All empty regions are less than early-bound, free,
|
||||||
|
// and scope regions.
|
||||||
|
a
|
||||||
|
}
|
||||||
|
|
||||||
|
(ReEmpty(a_ui), ReEmpty(b_ui)) => {
|
||||||
// Empty regions are ordered according to the universe
|
// Empty regions are ordered according to the universe
|
||||||
// they are associated with.
|
// they are associated with.
|
||||||
let ui = a_ui.min(b_ui);
|
let ui = a_ui.min(b_ui);
|
||||||
self.tcx().mk_region(ReEmpty(ui))
|
self.tcx().mk_region(ReEmpty(ui))
|
||||||
}
|
}
|
||||||
|
|
||||||
(&ReEmpty(empty_ui), &RePlaceholder(placeholder))
|
(ReEmpty(empty_ui), RePlaceholder(placeholder))
|
||||||
| (&RePlaceholder(placeholder), &ReEmpty(empty_ui)) => {
|
| (RePlaceholder(placeholder), ReEmpty(empty_ui)) => {
|
||||||
// If this empty region is from a universe that can
|
// If this empty region is from a universe that can
|
||||||
// name the placeholder, then the placeholder is
|
// name the placeholder, then the placeholder is
|
||||||
// larger; otherwise, the only ancestor is `'static`.
|
// larger; otherwise, the only ancestor is `'static`.
|
||||||
@ -418,13 +427,13 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(&ReEarlyBound(_) | &ReFree(_), &ReEarlyBound(_) | &ReFree(_)) => {
|
(ReEarlyBound(_) | ReFree(_), ReEarlyBound(_) | ReFree(_)) => {
|
||||||
self.region_rels.lub_free_regions(a, b)
|
self.region_rels.lub_free_regions(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// For these types, we cannot define any additional
|
// For these types, we cannot define any additional
|
||||||
// relationship:
|
// relationship:
|
||||||
(&RePlaceholder(..), _) | (_, &RePlaceholder(..)) => {
|
(RePlaceholder(..), _) | (_, RePlaceholder(..)) => {
|
||||||
if a == b {
|
if a == b {
|
||||||
a
|
a
|
||||||
} else {
|
} else {
|
||||||
@ -676,7 +685,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||||||
let node_universe = self.var_infos[node_idx].universe;
|
let node_universe = self.var_infos[node_idx].universe;
|
||||||
|
|
||||||
for lower_bound in &lower_bounds {
|
for lower_bound in &lower_bounds {
|
||||||
let effective_lower_bound = if let ty::RePlaceholder(p) = lower_bound.region {
|
let effective_lower_bound = if let ty::RePlaceholder(p) = *lower_bound.region {
|
||||||
if node_universe.cannot_name(p.universe) {
|
if node_universe.cannot_name(p.universe) {
|
||||||
self.tcx().lifetimes.re_static
|
self.tcx().lifetimes.re_static
|
||||||
} else {
|
} else {
|
||||||
@ -721,7 +730,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||||||
.expect("lower_vid_bounds should at least include `node_idx`");
|
.expect("lower_vid_bounds should at least include `node_idx`");
|
||||||
|
|
||||||
for upper_bound in &upper_bounds {
|
for upper_bound in &upper_bounds {
|
||||||
if let ty::RePlaceholder(p) = upper_bound.region {
|
if let ty::RePlaceholder(p) = *upper_bound.region {
|
||||||
if min_universe.cannot_name(p.universe) {
|
if min_universe.cannot_name(p.universe) {
|
||||||
let origin = self.var_infos[node_idx].origin;
|
let origin = self.var_infos[node_idx].origin;
|
||||||
errors.push(RegionResolutionError::UpperBoundUniverseConflict(
|
errors.push(RegionResolutionError::UpperBoundUniverseConflict(
|
||||||
@ -855,11 +864,11 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
VerifyBound::OutlivedBy(r) => {
|
VerifyBound::OutlivedBy(r) => {
|
||||||
self.sub_concrete_regions(min, var_values.normalize(self.tcx(), r))
|
self.sub_concrete_regions(min, var_values.normalize(self.tcx(), *r))
|
||||||
}
|
}
|
||||||
|
|
||||||
VerifyBound::IsEmpty => {
|
VerifyBound::IsEmpty => {
|
||||||
matches!(min, ty::ReEmpty(_))
|
matches!(*min, ty::ReEmpty(_))
|
||||||
}
|
}
|
||||||
|
|
||||||
VerifyBound::AnyBound(bs) => {
|
VerifyBound::AnyBound(bs) => {
|
||||||
@ -884,8 +893,8 @@ impl<'tcx> LexicalRegionResolutions<'tcx> {
|
|||||||
where
|
where
|
||||||
T: TypeFoldable<'tcx>,
|
T: TypeFoldable<'tcx>,
|
||||||
{
|
{
|
||||||
tcx.fold_regions(value, &mut false, |r, _db| match r {
|
tcx.fold_regions(value, &mut false, |r, _db| match *r {
|
||||||
ty::ReVar(rid) => self.resolve_var(*rid),
|
ty::ReVar(rid) => self.resolve_var(rid),
|
||||||
_ => r,
|
_ => r,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -244,8 +244,8 @@ where
|
|||||||
scopes: &[BoundRegionScope<'tcx>],
|
scopes: &[BoundRegionScope<'tcx>],
|
||||||
) -> ty::Region<'tcx> {
|
) -> ty::Region<'tcx> {
|
||||||
debug!("replace_bound_regions(scopes={:?})", scopes);
|
debug!("replace_bound_regions(scopes={:?})", scopes);
|
||||||
if let ty::ReLateBound(debruijn, br) = r {
|
if let ty::ReLateBound(debruijn, br) = *r {
|
||||||
Self::lookup_bound_region(*debruijn, br, first_free_index, scopes)
|
Self::lookup_bound_region(debruijn, &br, first_free_index, scopes)
|
||||||
} else {
|
} else {
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
@ -779,9 +779,9 @@ impl<'me, 'tcx> TypeVisitor<'tcx> for ScopeInstantiator<'me, 'tcx> {
|
|||||||
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
let ScopeInstantiator { bound_region_scope, next_region, .. } = self;
|
let ScopeInstantiator { bound_region_scope, next_region, .. } = self;
|
||||||
|
|
||||||
match r {
|
match *r {
|
||||||
ty::ReLateBound(debruijn, br) if *debruijn == self.target_index => {
|
ty::ReLateBound(debruijn, br) if debruijn == self.target_index => {
|
||||||
bound_region_scope.map.entry(*br).or_insert_with(|| next_region(*br));
|
bound_region_scope.map.entry(br).or_insert_with(|| next_region(br));
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
@ -963,8 +963,8 @@ where
|
|||||||
) -> RelateResult<'tcx, ty::Region<'tcx>> {
|
) -> RelateResult<'tcx, ty::Region<'tcx>> {
|
||||||
debug!("TypeGeneralizer::regions(a={:?})", a);
|
debug!("TypeGeneralizer::regions(a={:?})", a);
|
||||||
|
|
||||||
if let ty::ReLateBound(debruijn, _) = a {
|
if let ty::ReLateBound(debruijn, _) = *a {
|
||||||
if *debruijn < self.first_free_index {
|
if debruijn < self.first_free_index {
|
||||||
return Ok(a);
|
return Ok(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,9 @@ use crate::infer::free_regions::FreeRegionMap;
|
|||||||
use crate::infer::{GenericKind, InferCtxt};
|
use crate::infer::{GenericKind, InferCtxt};
|
||||||
use crate::traits::query::OutlivesBound;
|
use crate::traits::query::OutlivesBound;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
|
use rustc_data_structures::intern::Interned;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty::{self, ReEarlyBound, ReFree, ReVar, Region};
|
||||||
|
|
||||||
use super::explicit_outlives_bounds;
|
use super::explicit_outlives_bounds;
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ pub struct OutlivesEnvironment<'tcx> {
|
|||||||
/// "Region-bound pairs" tracks outlives relations that are known to
|
/// "Region-bound pairs" tracks outlives relations that are known to
|
||||||
/// be true, either because of explicit where-clauses like `T: 'a` or
|
/// be true, either because of explicit where-clauses like `T: 'a` or
|
||||||
/// because of implied bounds.
|
/// because of implied bounds.
|
||||||
pub type RegionBoundPairs<'tcx> = Vec<(ty::Region<'tcx>, GenericKind<'tcx>)>;
|
pub type RegionBoundPairs<'tcx> = Vec<(Region<'tcx>, GenericKind<'tcx>)>;
|
||||||
|
|
||||||
impl<'a, 'tcx> OutlivesEnvironment<'tcx> {
|
impl<'a, 'tcx> OutlivesEnvironment<'tcx> {
|
||||||
pub fn new(param_env: ty::ParamEnv<'tcx>) -> Self {
|
pub fn new(param_env: ty::ParamEnv<'tcx>) -> Self {
|
||||||
@ -164,10 +165,10 @@ impl<'a, 'tcx> OutlivesEnvironment<'tcx> {
|
|||||||
debug!("add_outlives_bounds: outlives_bound={:?}", outlives_bound);
|
debug!("add_outlives_bounds: outlives_bound={:?}", outlives_bound);
|
||||||
match outlives_bound {
|
match outlives_bound {
|
||||||
OutlivesBound::RegionSubRegion(
|
OutlivesBound::RegionSubRegion(
|
||||||
r_a @ (&ty::ReEarlyBound(_) | &ty::ReFree(_)),
|
r_a @ (Region(Interned(ReEarlyBound(_), _)) | Region(Interned(ReFree(_), _))),
|
||||||
&ty::ReVar(vid_b),
|
Region(Interned(ReVar(vid_b), _)),
|
||||||
) => {
|
) => {
|
||||||
infcx.expect("no infcx provided but region vars found").add_given(r_a, vid_b);
|
infcx.expect("no infcx provided but region vars found").add_given(r_a, *vid_b);
|
||||||
}
|
}
|
||||||
OutlivesBound::RegionSubParam(r_a, param_b) => {
|
OutlivesBound::RegionSubParam(r_a, param_b) => {
|
||||||
self.region_bound_pairs_accum.push((r_a, GenericKind::Param(param_b)));
|
self.region_bound_pairs_accum.push((r_a, GenericKind::Param(param_b)));
|
||||||
|
@ -285,7 +285,7 @@ where
|
|||||||
let origin = origin.clone();
|
let origin = origin.clone();
|
||||||
match component {
|
match component {
|
||||||
Component::Region(region1) => {
|
Component::Region(region1) => {
|
||||||
self.delegate.push_sub_region_constraint(origin, region, region1);
|
self.delegate.push_sub_region_constraint(origin, region, *region1);
|
||||||
}
|
}
|
||||||
Component::Param(param_ty) => {
|
Component::Param(param_ty) => {
|
||||||
self.param_ty_must_outlive(origin, region, *param_ty);
|
self.param_ty_must_outlive(origin, region, *param_ty);
|
||||||
|
@ -154,17 +154,17 @@ impl<'me, 'tcx> LeakCheck<'me, 'tcx> {
|
|||||||
let scc = self.mini_graph.sccs.scc(*leak_check_node);
|
let scc = self.mini_graph.sccs.scc(*leak_check_node);
|
||||||
|
|
||||||
// Set the universe of each SCC to be the minimum of its constituent universes
|
// Set the universe of each SCC to be the minimum of its constituent universes
|
||||||
let universe = self.rcc.universe(region);
|
let universe = self.rcc.universe(*region);
|
||||||
debug!(
|
debug!(
|
||||||
"assign_placeholder_values: scc={:?} universe={:?} region={:?}",
|
"assign_placeholder_values: scc={:?} universe={:?} region={:?}",
|
||||||
scc, universe, region
|
scc, universe, region
|
||||||
);
|
);
|
||||||
self.scc_universes[scc].take_min(universe, region);
|
self.scc_universes[scc].take_min(universe, *region);
|
||||||
|
|
||||||
// Detect those SCCs that directly contain a placeholder
|
// Detect those SCCs that directly contain a placeholder
|
||||||
if let ty::RePlaceholder(placeholder) = region {
|
if let ty::RePlaceholder(placeholder) = **region {
|
||||||
if self.universe_at_start_of_snapshot.cannot_name(placeholder.universe) {
|
if self.universe_at_start_of_snapshot.cannot_name(placeholder.universe) {
|
||||||
self.assign_scc_value(scc, *placeholder)?;
|
self.assign_scc_value(scc, placeholder)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ use super::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
|
use rustc_data_structures::intern::Interned;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_data_structures::undo_log::UndoLogs;
|
use rustc_data_structures::undo_log::UndoLogs;
|
||||||
use rustc_data_structures::unify as ut;
|
use rustc_data_structures::unify as ut;
|
||||||
@ -502,14 +503,15 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
|||||||
self.make_subregion(origin, sup, sub);
|
self.make_subregion(origin, sup, sub);
|
||||||
|
|
||||||
match (sub, sup) {
|
match (sub, sup) {
|
||||||
(&ty::ReVar(sub), &ty::ReVar(sup)) => {
|
(Region(Interned(ReVar(sub), _)), Region(Interned(ReVar(sup), _))) => {
|
||||||
debug!("make_eqregion: unifying {:?} with {:?}", sub, sup);
|
debug!("make_eqregion: unifying {:?} with {:?}", sub, sup);
|
||||||
self.unification_table().union(sub, sup);
|
self.unification_table().union(*sub, *sup);
|
||||||
self.any_unifications = true;
|
self.any_unifications = true;
|
||||||
}
|
}
|
||||||
(&ty::ReVar(vid), value) | (value, &ty::ReVar(vid)) => {
|
(Region(Interned(ReVar(vid), _)), value)
|
||||||
|
| (value, Region(Interned(ReVar(vid), _))) => {
|
||||||
debug!("make_eqregion: unifying {:?} with {:?}", vid, value);
|
debug!("make_eqregion: unifying {:?} with {:?}", vid, value);
|
||||||
self.unification_table().union_value(vid, UnifiedRegion(Some(value)));
|
self.unification_table().union_value(*vid, UnifiedRegion(Some(value)));
|
||||||
self.any_unifications = true;
|
self.any_unifications = true;
|
||||||
}
|
}
|
||||||
(_, _) => {}
|
(_, _) => {}
|
||||||
@ -550,20 +552,20 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
|||||||
// cannot add constraints once regions are resolved
|
// cannot add constraints once regions are resolved
|
||||||
debug!("origin = {:#?}", origin);
|
debug!("origin = {:#?}", origin);
|
||||||
|
|
||||||
match (sub, sup) {
|
match (*sub, *sup) {
|
||||||
(&ReLateBound(..), _) | (_, &ReLateBound(..)) => {
|
(ReLateBound(..), _) | (_, ReLateBound(..)) => {
|
||||||
span_bug!(origin.span(), "cannot relate bound region: {:?} <= {:?}", sub, sup);
|
span_bug!(origin.span(), "cannot relate bound region: {:?} <= {:?}", sub, sup);
|
||||||
}
|
}
|
||||||
(_, &ReStatic) => {
|
(_, ReStatic) => {
|
||||||
// all regions are subregions of static, so we can ignore this
|
// all regions are subregions of static, so we can ignore this
|
||||||
}
|
}
|
||||||
(&ReVar(sub_id), &ReVar(sup_id)) => {
|
(ReVar(sub_id), ReVar(sup_id)) => {
|
||||||
self.add_constraint(Constraint::VarSubVar(sub_id, sup_id), origin);
|
self.add_constraint(Constraint::VarSubVar(sub_id, sup_id), origin);
|
||||||
}
|
}
|
||||||
(_, &ReVar(sup_id)) => {
|
(_, ReVar(sup_id)) => {
|
||||||
self.add_constraint(Constraint::RegSubVar(sub, sup_id), origin);
|
self.add_constraint(Constraint::RegSubVar(sub, sup_id), origin);
|
||||||
}
|
}
|
||||||
(&ReVar(sub_id), _) => {
|
(ReVar(sub_id), _) => {
|
||||||
self.add_constraint(Constraint::VarSubReg(sub_id, sup), origin);
|
self.add_constraint(Constraint::VarSubReg(sub_id, sup), origin);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@ -591,16 +593,12 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
|||||||
) -> Region<'tcx> {
|
) -> Region<'tcx> {
|
||||||
// cannot add constraints once regions are resolved
|
// cannot add constraints once regions are resolved
|
||||||
debug!("RegionConstraintCollector: lub_regions({:?}, {:?})", a, b);
|
debug!("RegionConstraintCollector: lub_regions({:?}, {:?})", a, b);
|
||||||
match (a, b) {
|
if a.is_static() || b.is_static() {
|
||||||
(r @ &ReStatic, _) | (_, r @ &ReStatic) => {
|
a // nothing lives longer than static
|
||||||
r // nothing lives longer than static
|
} else if a == b {
|
||||||
}
|
|
||||||
|
|
||||||
_ if a == b => {
|
|
||||||
a // LUB(a,a) = a
|
a // LUB(a,a) = a
|
||||||
}
|
} else {
|
||||||
|
self.combine_vars(tcx, Lub, a, b, origin)
|
||||||
_ => self.combine_vars(tcx, Lub, a, b, origin),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -613,16 +611,14 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
|||||||
) -> Region<'tcx> {
|
) -> Region<'tcx> {
|
||||||
// cannot add constraints once regions are resolved
|
// cannot add constraints once regions are resolved
|
||||||
debug!("RegionConstraintCollector: glb_regions({:?}, {:?})", a, b);
|
debug!("RegionConstraintCollector: glb_regions({:?}, {:?})", a, b);
|
||||||
match (a, b) {
|
if a.is_static() {
|
||||||
(&ReStatic, r) | (r, &ReStatic) => {
|
b // static lives longer than everything else
|
||||||
r // static lives longer than everything else
|
} else if b.is_static() {
|
||||||
}
|
a // static lives longer than everything else
|
||||||
|
} else if a == b {
|
||||||
_ if a == b => {
|
|
||||||
a // GLB(a,a) = a
|
a // GLB(a,a) = a
|
||||||
}
|
} else {
|
||||||
|
self.combine_vars(tcx, Glb, a, b, origin)
|
||||||
_ => self.combine_vars(tcx, Glb, a, b, origin),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -639,11 +635,11 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
|||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
region: ty::Region<'tcx>,
|
region: ty::Region<'tcx>,
|
||||||
) -> ty::Region<'tcx> {
|
) -> ty::Region<'tcx> {
|
||||||
match region {
|
match *region {
|
||||||
ty::ReVar(rid) => {
|
ty::ReVar(rid) => {
|
||||||
let unified_region = self.unification_table().probe_value(*rid);
|
let unified_region = self.unification_table().probe_value(rid);
|
||||||
unified_region.0.unwrap_or_else(|| {
|
unified_region.0.unwrap_or_else(|| {
|
||||||
let root = self.unification_table().find(*rid).vid;
|
let root = self.unification_table().find(rid).vid;
|
||||||
tcx.reuse_or_mk_region(region, ty::ReVar(root))
|
tcx.reuse_or_mk_region(region, ty::ReVar(root))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -767,8 +763,7 @@ impl<'tcx> VerifyBound<'tcx> {
|
|||||||
pub fn must_hold(&self) -> bool {
|
pub fn must_hold(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
VerifyBound::IfEq(..) => false,
|
VerifyBound::IfEq(..) => false,
|
||||||
VerifyBound::OutlivedBy(ty::ReStatic) => true,
|
VerifyBound::OutlivedBy(re) => re.is_static(),
|
||||||
VerifyBound::OutlivedBy(_) => false,
|
|
||||||
VerifyBound::IsEmpty => false,
|
VerifyBound::IsEmpty => false,
|
||||||
VerifyBound::AnyBound(bs) => bs.iter().any(|b| b.must_hold()),
|
VerifyBound::AnyBound(bs) => bs.iter().any(|b| b.must_hold()),
|
||||||
VerifyBound::AllBounds(bs) => bs.iter().all(|b| b.must_hold()),
|
VerifyBound::AllBounds(bs) => bs.iter().all(|b| b.must_hold()),
|
||||||
|
@ -2050,7 +2050,7 @@ impl ExplicitOutlivesRequirements {
|
|||||||
inferred_outlives
|
inferred_outlives
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(pred, _)| match pred.kind().skip_binder() {
|
.filter_map(|(pred, _)| match pred.kind().skip_binder() {
|
||||||
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => match a {
|
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => match *a {
|
||||||
ty::ReEarlyBound(ebr) if ebr.index == index => Some(b),
|
ty::ReEarlyBound(ebr) if ebr.index == index => Some(b),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
@ -2111,10 +2111,10 @@ impl ExplicitOutlivesRequirements {
|
|||||||
if let hir::GenericBound::Outlives(lifetime) = bound {
|
if let hir::GenericBound::Outlives(lifetime) = bound {
|
||||||
let is_inferred = match tcx.named_region(lifetime.hir_id) {
|
let is_inferred = match tcx.named_region(lifetime.hir_id) {
|
||||||
Some(Region::Static) if infer_static => {
|
Some(Region::Static) if infer_static => {
|
||||||
inferred_outlives.iter().any(|r| matches!(r, ty::ReStatic))
|
inferred_outlives.iter().any(|r| matches!(**r, ty::ReStatic))
|
||||||
}
|
}
|
||||||
Some(Region::EarlyBound(index, ..)) => inferred_outlives.iter().any(|r| {
|
Some(Region::EarlyBound(index, ..)) => inferred_outlives.iter().any(|r| {
|
||||||
if let ty::ReEarlyBound(ebr) = r { ebr.index == index } else { false }
|
if let ty::ReEarlyBound(ebr) = **r { ebr.index == index } else { false }
|
||||||
}),
|
}),
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
@ -194,7 +194,7 @@ macro_rules! make_mir_visitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn visit_region(&mut self,
|
fn visit_region(&mut self,
|
||||||
region: & $($mutability)? ty::Region<'tcx>,
|
region: $(& $mutability)? ty::Region<'tcx>,
|
||||||
_: Location) {
|
_: Location) {
|
||||||
self.super_region(region);
|
self.super_region(region);
|
||||||
}
|
}
|
||||||
@ -641,7 +641,7 @@ macro_rules! make_mir_visitor {
|
|||||||
Rvalue::ThreadLocalRef(_) => {}
|
Rvalue::ThreadLocalRef(_) => {}
|
||||||
|
|
||||||
Rvalue::Ref(r, bk, path) => {
|
Rvalue::Ref(r, bk, path) => {
|
||||||
self.visit_region(r, location);
|
self.visit_region($(& $mutability)? *r, location);
|
||||||
let ctx = match bk {
|
let ctx = match bk {
|
||||||
BorrowKind::Shared => PlaceContext::NonMutatingUse(
|
BorrowKind::Shared => PlaceContext::NonMutatingUse(
|
||||||
NonMutatingUseContext::SharedBorrow
|
NonMutatingUseContext::SharedBorrow
|
||||||
@ -900,7 +900,7 @@ macro_rules! make_mir_visitor {
|
|||||||
fn super_ty(&mut self, _ty: $(& $mutability)? Ty<'tcx>) {
|
fn super_ty(&mut self, _ty: $(& $mutability)? Ty<'tcx>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn super_region(&mut self, _region: & $($mutability)? ty::Region<'tcx>) {
|
fn super_region(&mut self, _region: $(& $mutability)? ty::Region<'tcx>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn super_const(&mut self, _const: & $($mutability)? &'tcx ty::Const<'tcx>) {
|
fn super_const(&mut self, _const: & $($mutability)? &'tcx ty::Const<'tcx>) {
|
||||||
|
@ -138,6 +138,12 @@ impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for ty::Predicate<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for ty::Region<'tcx> {
|
||||||
|
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
|
||||||
|
self.kind().encode(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for AllocId {
|
impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for AllocId {
|
||||||
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
|
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
|
||||||
e.encode_alloc_id(self)
|
e.encode_alloc_id(self)
|
||||||
@ -156,7 +162,6 @@ macro_rules! encodable_via_deref {
|
|||||||
|
|
||||||
encodable_via_deref! {
|
encodable_via_deref! {
|
||||||
&'tcx ty::TypeckResults<'tcx>,
|
&'tcx ty::TypeckResults<'tcx>,
|
||||||
ty::Region<'tcx>,
|
|
||||||
&'tcx traits::ImplSource<'tcx, ()>,
|
&'tcx traits::ImplSource<'tcx, ()>,
|
||||||
&'tcx mir::Body<'tcx>,
|
&'tcx mir::Body<'tcx>,
|
||||||
&'tcx mir::UnsafetyCheckResult,
|
&'tcx mir::UnsafetyCheckResult,
|
||||||
|
@ -860,10 +860,10 @@ impl<'tcx> CanonicalUserType<'tcx> {
|
|||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
|
|
||||||
GenericArgKind::Lifetime(r) => match r {
|
GenericArgKind::Lifetime(r) => match *r {
|
||||||
ty::ReLateBound(debruijn, br) => {
|
ty::ReLateBound(debruijn, br) => {
|
||||||
// We only allow a `ty::INNERMOST` index in substitutions.
|
// We only allow a `ty::INNERMOST` index in substitutions.
|
||||||
assert_eq!(*debruijn, ty::INNERMOST);
|
assert_eq!(debruijn, ty::INNERMOST);
|
||||||
cvar == br.var
|
cvar == br.var
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
@ -930,7 +930,11 @@ impl<'tcx> CommonTypes<'tcx> {
|
|||||||
|
|
||||||
impl<'tcx> CommonLifetimes<'tcx> {
|
impl<'tcx> CommonLifetimes<'tcx> {
|
||||||
fn new(interners: &CtxtInterners<'tcx>) -> CommonLifetimes<'tcx> {
|
fn new(interners: &CtxtInterners<'tcx>) -> CommonLifetimes<'tcx> {
|
||||||
let mk = |r| interners.region.intern(r, |r| InternedInSet(interners.arena.alloc(r))).0;
|
let mk = |r| {
|
||||||
|
Region(Interned::new_unchecked(
|
||||||
|
interners.region.intern(r, |r| InternedInSet(interners.arena.alloc(r))).0,
|
||||||
|
))
|
||||||
|
};
|
||||||
|
|
||||||
CommonLifetimes {
|
CommonLifetimes {
|
||||||
re_root_empty: mk(RegionKind::ReEmpty(ty::UniverseIndex::ROOT)),
|
re_root_empty: mk(RegionKind::ReEmpty(ty::UniverseIndex::ROOT)),
|
||||||
@ -1680,7 +1684,7 @@ macro_rules! nop_list_lift {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nop_lift! {type_; Ty<'a> => Ty<'tcx>}
|
nop_lift! {type_; Ty<'a> => Ty<'tcx>}
|
||||||
nop_lift_old! {region; Region<'a> => Region<'tcx>}
|
nop_lift! {region; Region<'a> => Region<'tcx>}
|
||||||
nop_lift_old! {const_; &'a Const<'a> => &'tcx Const<'tcx>}
|
nop_lift_old! {const_; &'a Const<'a> => &'tcx Const<'tcx>}
|
||||||
nop_lift_old! {const_allocation; &'a Allocation => &'tcx Allocation}
|
nop_lift_old! {const_allocation; &'a Allocation => &'tcx Allocation}
|
||||||
nop_lift! {predicate; Predicate<'a> => Predicate<'tcx>}
|
nop_lift! {predicate; Predicate<'a> => Predicate<'tcx>}
|
||||||
@ -2086,6 +2090,46 @@ impl<'tcx, T: Hash> Hash for InternedInSet<'tcx, List<T>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! direct_interners {
|
macro_rules! direct_interners {
|
||||||
|
($($name:ident: $method:ident($ty:ty): $ret_ctor:ident -> $ret_ty:ty,)+) => {
|
||||||
|
$(impl<'tcx> Borrow<$ty> for InternedInSet<'tcx, $ty> {
|
||||||
|
fn borrow<'a>(&'a self) -> &'a $ty {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> PartialEq for InternedInSet<'tcx, $ty> {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
// The `Borrow` trait requires that `x.borrow() == y.borrow()`
|
||||||
|
// equals `x == y`.
|
||||||
|
self.0 == other.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> Eq for InternedInSet<'tcx, $ty> {}
|
||||||
|
|
||||||
|
impl<'tcx> Hash for InternedInSet<'tcx, $ty> {
|
||||||
|
fn hash<H: Hasher>(&self, s: &mut H) {
|
||||||
|
// The `Borrow` trait requires that `x.borrow().hash(s) ==
|
||||||
|
// x.hash(s)`.
|
||||||
|
self.0.hash(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
pub fn $method(self, v: $ty) -> $ret_ty {
|
||||||
|
$ret_ctor(Interned::new_unchecked(self.interners.$name.intern(v, |v| {
|
||||||
|
InternedInSet(self.interners.arena.alloc(v))
|
||||||
|
}).0))
|
||||||
|
}
|
||||||
|
})+
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
direct_interners! {
|
||||||
|
region: mk_region(RegionKind): Region -> Region<'tcx>,
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! direct_interners_old {
|
||||||
($($name:ident: $method:ident($ty:ty),)+) => {
|
($($name:ident: $method:ident($ty:ty),)+) => {
|
||||||
$(impl<'tcx> Borrow<$ty> for InternedInSet<'tcx, $ty> {
|
$(impl<'tcx> Borrow<$ty> for InternedInSet<'tcx, $ty> {
|
||||||
fn borrow<'a>(&'a self) -> &'a $ty {
|
fn borrow<'a>(&'a self) -> &'a $ty {
|
||||||
@ -2121,8 +2165,8 @@ macro_rules! direct_interners {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
direct_interners! {
|
// FIXME: eventually these should all be converted to `direct_interners`.
|
||||||
region: mk_region(RegionKind),
|
direct_interners_old! {
|
||||||
const_: mk_const(Const<'tcx>),
|
const_: mk_const(Const<'tcx>),
|
||||||
const_allocation: intern_const_alloc(Allocation),
|
const_allocation: intern_const_alloc(Allocation),
|
||||||
layout: intern_layout(Layout),
|
layout: intern_layout(Layout),
|
||||||
|
@ -960,10 +960,10 @@ impl<'tcx> TypeVisitor<'tcx> for ValidateBoundVars<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
match r {
|
match *r {
|
||||||
ty::ReLateBound(index, br) if *index == self.binder_index => {
|
ty::ReLateBound(index, br) if index == self.binder_index => {
|
||||||
if self.bound_vars.len() <= br.var.as_usize() {
|
if self.bound_vars.len() <= br.var.as_usize() {
|
||||||
bug!("Not enough bound vars: {:?} not found in {:?}", *br, self.bound_vars);
|
bug!("Not enough bound vars: {:?} not found in {:?}", br, self.bound_vars);
|
||||||
}
|
}
|
||||||
let list_var = self.bound_vars[br.var.as_usize()];
|
let list_var = self.bound_vars[br.var.as_usize()];
|
||||||
match list_var {
|
match list_var {
|
||||||
@ -1076,9 +1076,9 @@ pub fn shift_region<'tcx>(
|
|||||||
region: ty::Region<'tcx>,
|
region: ty::Region<'tcx>,
|
||||||
amount: u32,
|
amount: u32,
|
||||||
) -> ty::Region<'tcx> {
|
) -> ty::Region<'tcx> {
|
||||||
match region {
|
match *region {
|
||||||
ty::ReLateBound(debruijn, br) if amount > 0 => {
|
ty::ReLateBound(debruijn, br) if amount > 0 => {
|
||||||
tcx.mk_region(ty::ReLateBound(debruijn.shifted_in(amount), *br))
|
tcx.mk_region(ty::ReLateBound(debruijn.shifted_in(amount), br))
|
||||||
}
|
}
|
||||||
_ => region,
|
_ => region,
|
||||||
}
|
}
|
||||||
|
@ -326,19 +326,11 @@ pub fn characteristic_def_id_of_type(ty: Ty<'_>) -> Option<DefId> {
|
|||||||
characteristic_def_id_of_type_cached(ty, &mut SsoHashSet::new())
|
characteristic_def_id_of_type_cached(ty, &mut SsoHashSet::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for ty::RegionKind {
|
|
||||||
type Output = P::Region;
|
|
||||||
type Error = P::Error;
|
|
||||||
fn print(&self, cx: P) -> Result<Self::Output, Self::Error> {
|
|
||||||
cx.print_region(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for ty::Region<'_> {
|
impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for ty::Region<'_> {
|
||||||
type Output = P::Region;
|
type Output = P::Region;
|
||||||
type Error = P::Error;
|
type Error = P::Error;
|
||||||
fn print(&self, cx: P) -> Result<Self::Output, Self::Error> {
|
fn print(&self, cx: P) -> Result<Self::Output, Self::Error> {
|
||||||
cx.print_region(self)
|
cx.print_region(*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,11 +131,13 @@ pub fn with_no_visible_paths<F: FnOnce() -> R, R>(f: F) -> R {
|
|||||||
///
|
///
|
||||||
/// Regions not selected by the region highlight mode are presently
|
/// Regions not selected by the region highlight mode are presently
|
||||||
/// unaffected.
|
/// unaffected.
|
||||||
#[derive(Copy, Clone, Default)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct RegionHighlightMode {
|
pub struct RegionHighlightMode<'tcx> {
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
|
|
||||||
/// If enabled, when we see the selected region, use "`'N`"
|
/// If enabled, when we see the selected region, use "`'N`"
|
||||||
/// instead of the ordinary behavior.
|
/// instead of the ordinary behavior.
|
||||||
highlight_regions: [Option<(ty::RegionKind, usize)>; 3],
|
highlight_regions: [Option<(ty::Region<'tcx>, usize)>; 3],
|
||||||
|
|
||||||
/// If enabled, when printing a "free region" that originated from
|
/// If enabled, when printing a "free region" that originated from
|
||||||
/// the given `ty::BoundRegionKind`, print it as "`'1`". Free regions that would ordinarily
|
/// the given `ty::BoundRegionKind`, print it as "`'1`". Free regions that would ordinarily
|
||||||
@ -147,12 +149,20 @@ pub struct RegionHighlightMode {
|
|||||||
highlight_bound_region: Option<(ty::BoundRegionKind, usize)>,
|
highlight_bound_region: Option<(ty::BoundRegionKind, usize)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RegionHighlightMode {
|
impl<'tcx> RegionHighlightMode<'tcx> {
|
||||||
|
pub fn new(tcx: TyCtxt<'tcx>) -> Self {
|
||||||
|
Self {
|
||||||
|
tcx,
|
||||||
|
highlight_regions: Default::default(),
|
||||||
|
highlight_bound_region: Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// If `region` and `number` are both `Some`, invokes
|
/// If `region` and `number` are both `Some`, invokes
|
||||||
/// `highlighting_region`.
|
/// `highlighting_region`.
|
||||||
pub fn maybe_highlighting_region(
|
pub fn maybe_highlighting_region(
|
||||||
&mut self,
|
&mut self,
|
||||||
region: Option<ty::Region<'_>>,
|
region: Option<ty::Region<'tcx>>,
|
||||||
number: Option<usize>,
|
number: Option<usize>,
|
||||||
) {
|
) {
|
||||||
if let Some(k) = region {
|
if let Some(k) = region {
|
||||||
@ -163,24 +173,24 @@ impl RegionHighlightMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Highlights the region inference variable `vid` as `'N`.
|
/// Highlights the region inference variable `vid` as `'N`.
|
||||||
pub fn highlighting_region(&mut self, region: ty::Region<'_>, number: usize) {
|
pub fn highlighting_region(&mut self, region: ty::Region<'tcx>, number: usize) {
|
||||||
let num_slots = self.highlight_regions.len();
|
let num_slots = self.highlight_regions.len();
|
||||||
let first_avail_slot =
|
let first_avail_slot =
|
||||||
self.highlight_regions.iter_mut().find(|s| s.is_none()).unwrap_or_else(|| {
|
self.highlight_regions.iter_mut().find(|s| s.is_none()).unwrap_or_else(|| {
|
||||||
bug!("can only highlight {} placeholders at a time", num_slots,)
|
bug!("can only highlight {} placeholders at a time", num_slots,)
|
||||||
});
|
});
|
||||||
*first_avail_slot = Some((*region, number));
|
*first_avail_slot = Some((region, number));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience wrapper for `highlighting_region`.
|
/// Convenience wrapper for `highlighting_region`.
|
||||||
pub fn highlighting_region_vid(&mut self, vid: ty::RegionVid, number: usize) {
|
pub fn highlighting_region_vid(&mut self, vid: ty::RegionVid, number: usize) {
|
||||||
self.highlighting_region(&ty::ReVar(vid), number)
|
self.highlighting_region(self.tcx.mk_region(ty::ReVar(vid)), number)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `Some(n)` with the number to use for the given region, if any.
|
/// Returns `Some(n)` with the number to use for the given region, if any.
|
||||||
fn region_highlighted(&self, region: ty::Region<'_>) -> Option<usize> {
|
fn region_highlighted(&self, region: ty::Region<'_>) -> Option<usize> {
|
||||||
self.highlight_regions.iter().find_map(|h| match h {
|
self.highlight_regions.iter().find_map(|h| match h {
|
||||||
Some((r, n)) if r == region => Some(*n),
|
Some((r, n)) if *r == region => Some(*n),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1054,7 +1064,7 @@ pub trait PrettyPrinter<'tcx>:
|
|||||||
|
|
||||||
// Don't print `'_` if there's no unerased regions.
|
// Don't print `'_` if there's no unerased regions.
|
||||||
let print_regions = args.iter().any(|arg| match arg.unpack() {
|
let print_regions = args.iter().any(|arg| match arg.unpack() {
|
||||||
GenericArgKind::Lifetime(r) => *r != ty::ReErased,
|
GenericArgKind::Lifetime(r) => !r.is_erased(),
|
||||||
_ => false,
|
_ => false,
|
||||||
});
|
});
|
||||||
let mut args = args.iter().cloned().filter(|arg| match arg.unpack() {
|
let mut args = args.iter().cloned().filter(|arg| match arg.unpack() {
|
||||||
@ -1536,7 +1546,7 @@ pub struct FmtPrinterData<'a, 'tcx, F> {
|
|||||||
binder_depth: usize,
|
binder_depth: usize,
|
||||||
printed_type_count: usize,
|
printed_type_count: usize,
|
||||||
|
|
||||||
pub region_highlight_mode: RegionHighlightMode,
|
pub region_highlight_mode: RegionHighlightMode<'tcx>,
|
||||||
|
|
||||||
pub name_resolver: Option<Box<&'a dyn Fn(ty::TyVid) -> Option<String>>>,
|
pub name_resolver: Option<Box<&'a dyn Fn(ty::TyVid) -> Option<String>>>,
|
||||||
}
|
}
|
||||||
@ -1566,7 +1576,7 @@ impl<'a, 'tcx, F> FmtPrinter<'a, 'tcx, F> {
|
|||||||
region_index: 0,
|
region_index: 0,
|
||||||
binder_depth: 0,
|
binder_depth: 0,
|
||||||
printed_type_count: 0,
|
printed_type_count: 0,
|
||||||
region_highlight_mode: RegionHighlightMode::default(),
|
region_highlight_mode: RegionHighlightMode::new(tcx),
|
||||||
name_resolver: None,
|
name_resolver: None,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@ -1802,7 +1812,7 @@ impl<'tcx, F: fmt::Write> Printer<'tcx> for FmtPrinter<'_, 'tcx, F> {
|
|||||||
// Don't print `'_` if there's no unerased regions.
|
// Don't print `'_` if there's no unerased regions.
|
||||||
let print_regions = self.tcx.sess.verbose()
|
let print_regions = self.tcx.sess.verbose()
|
||||||
|| args.iter().any(|arg| match arg.unpack() {
|
|| args.iter().any(|arg| match arg.unpack() {
|
||||||
GenericArgKind::Lifetime(r) => *r != ty::ReErased,
|
GenericArgKind::Lifetime(r) => !r.is_erased(),
|
||||||
_ => false,
|
_ => false,
|
||||||
});
|
});
|
||||||
let args = args.iter().cloned().filter(|arg| match arg.unpack() {
|
let args = args.iter().cloned().filter(|arg| match arg.unpack() {
|
||||||
@ -2061,7 +2071,7 @@ impl<'a, 'tcx> ty::TypeFolder<'tcx> for RegionFolder<'a, 'tcx> {
|
|||||||
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
||||||
let name = &mut self.name;
|
let name = &mut self.name;
|
||||||
let region = match *r {
|
let region = match *r {
|
||||||
ty::ReLateBound(_, br) => self.region_map.entry(br).or_insert_with(|| name(br)),
|
ty::ReLateBound(_, br) => *self.region_map.entry(br).or_insert_with(|| name(br)),
|
||||||
ty::RePlaceholder(ty::PlaceholderRegion { name: kind, .. }) => {
|
ty::RePlaceholder(ty::PlaceholderRegion { name: kind, .. }) => {
|
||||||
// If this is an anonymous placeholder, don't rename. Otherwise, in some
|
// If this is an anonymous placeholder, don't rename. Otherwise, in some
|
||||||
// async fns, we get a `for<'r> Send` bound
|
// async fns, we get a `for<'r> Send` bound
|
||||||
@ -2070,7 +2080,7 @@ impl<'a, 'tcx> ty::TypeFolder<'tcx> for RegionFolder<'a, 'tcx> {
|
|||||||
_ => {
|
_ => {
|
||||||
// Index doesn't matter, since this is just for naming and these never get bound
|
// Index doesn't matter, since this is just for naming and these never get bound
|
||||||
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind };
|
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind };
|
||||||
self.region_map.entry(br).or_insert_with(|| name(br))
|
*self.region_map.entry(br).or_insert_with(|| name(br))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2272,7 +2282,7 @@ impl<'tcx, F: fmt::Write> FmtPrinter<'_, 'tcx, F> {
|
|||||||
|
|
||||||
#[instrument(skip(self), level = "trace")]
|
#[instrument(skip(self), level = "trace")]
|
||||||
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
trace!("address: {:p}", r);
|
trace!("address: {:p}", r.0.0);
|
||||||
if let ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrNamed(_, name), .. }) = *r {
|
if let ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrNamed(_, name), .. }) = *r {
|
||||||
self.used_region_names.insert(name);
|
self.used_region_names.insert(name);
|
||||||
} else if let ty::RePlaceholder(ty::PlaceholderRegion {
|
} else if let ty::RePlaceholder(ty::PlaceholderRegion {
|
||||||
@ -2369,7 +2379,7 @@ macro_rules! define_print_and_forward_display {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HACK(eddyb) this is separate because `ty::RegionKind` doesn't need lifting.
|
// HACK(eddyb) this is separate because `ty::RegionKind` doesn't need lifting.
|
||||||
impl fmt::Display for ty::RegionKind {
|
impl<'tcx> fmt::Display for ty::Region<'tcx> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
ty::tls::with(|tcx| {
|
ty::tls::with(|tcx| {
|
||||||
self.print(FmtPrinter::new(tcx, f, Namespace::TypeNS))?;
|
self.print(FmtPrinter::new(tcx, f, Namespace::TypeNS))?;
|
||||||
|
@ -12,6 +12,7 @@ use crate::ty::{self, AdtDef, DefIdTree, Discr, Term, Ty, TyCtxt, TypeFlags, Typ
|
|||||||
use crate::ty::{DelaySpanBugEmitted, List, ParamEnv};
|
use crate::ty::{DelaySpanBugEmitted, List, ParamEnv};
|
||||||
use polonius_engine::Atom;
|
use polonius_engine::Atom;
|
||||||
use rustc_data_structures::captures::Captures;
|
use rustc_data_structures::captures::Captures;
|
||||||
|
use rustc_data_structures::intern::Interned;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_index::vec::Idx;
|
use rustc_index::vec::Idx;
|
||||||
@ -21,8 +22,9 @@ use rustc_target::abi::VariantIdx;
|
|||||||
use rustc_target::spec::abi;
|
use rustc_target::spec::abi;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
|
use std::fmt;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::ops::Range;
|
use std::ops::{Deref, Range};
|
||||||
use ty::util::IntTypeExt;
|
use ty::util::IntTypeExt;
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
|
||||||
@ -1391,7 +1393,24 @@ impl ParamConst {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Region<'tcx> = &'tcx RegionKind;
|
/// Use this rather than `TyKind`, whenever possible.
|
||||||
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable)]
|
||||||
|
#[cfg_attr(not(bootstrap), rustc_pass_by_value)]
|
||||||
|
pub struct Region<'tcx>(pub Interned<'tcx, RegionKind>);
|
||||||
|
|
||||||
|
impl<'tcx> Deref for Region<'tcx> {
|
||||||
|
type Target = RegionKind;
|
||||||
|
|
||||||
|
fn deref(&self) -> &RegionKind {
|
||||||
|
&self.0.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> fmt::Debug for Region<'tcx> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "{:?}", self.kind())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Representation of regions. Note that the NLL checker uses a distinct
|
/// Representation of regions. Note that the NLL checker uses a distinct
|
||||||
/// representation of regions. For this reason, it internally replaces all the
|
/// representation of regions. For this reason, it internally replaces all the
|
||||||
@ -1399,6 +1418,9 @@ pub type Region<'tcx> = &'tcx RegionKind;
|
|||||||
/// to index into internal NLL data structures. See `rustc_const_eval::borrow_check`
|
/// to index into internal NLL data structures. See `rustc_const_eval::borrow_check`
|
||||||
/// module for more information.
|
/// module for more information.
|
||||||
///
|
///
|
||||||
|
/// Note: operations are on the wrapper `Region` type, which is interned,
|
||||||
|
/// rather than this type.
|
||||||
|
///
|
||||||
/// ## The Region lattice within a given function
|
/// ## The Region lattice within a given function
|
||||||
///
|
///
|
||||||
/// In general, the region lattice looks like
|
/// In general, the region lattice looks like
|
||||||
@ -1655,9 +1677,13 @@ impl<'tcx> PolyExistentialProjection<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Region utilities
|
/// Region utilities
|
||||||
impl RegionKind {
|
impl<'tcx> Region<'tcx> {
|
||||||
|
pub fn kind(self) -> RegionKind {
|
||||||
|
*self.0.0
|
||||||
|
}
|
||||||
|
|
||||||
/// Is this region named by the user?
|
/// Is this region named by the user?
|
||||||
pub fn has_name(&self) -> bool {
|
pub fn has_name(self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
RegionKind::ReEarlyBound(ebr) => ebr.has_name(),
|
RegionKind::ReEarlyBound(ebr) => ebr.has_name(),
|
||||||
RegionKind::ReLateBound(_, br) => br.kind.is_named(),
|
RegionKind::ReLateBound(_, br) => br.kind.is_named(),
|
||||||
@ -1671,24 +1697,39 @@ impl RegionKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_late_bound(&self) -> bool {
|
pub fn is_static(self) -> bool {
|
||||||
|
matches!(*self, ty::ReStatic)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn is_erased(self) -> bool {
|
||||||
|
matches!(*self, ty::ReErased)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn is_late_bound(self) -> bool {
|
||||||
matches!(*self, ty::ReLateBound(..))
|
matches!(*self, ty::ReLateBound(..))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_placeholder(&self) -> bool {
|
pub fn is_placeholder(self) -> bool {
|
||||||
matches!(*self, ty::RePlaceholder(..))
|
matches!(*self, ty::RePlaceholder(..))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn bound_at_or_above_binder(&self, index: ty::DebruijnIndex) -> bool {
|
pub fn is_empty(self) -> bool {
|
||||||
|
matches!(*self, ty::ReEmpty(..))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn bound_at_or_above_binder(self, index: ty::DebruijnIndex) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
ty::ReLateBound(debruijn, _) => debruijn >= index,
|
ty::ReLateBound(debruijn, _) => debruijn >= index,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn type_flags(&self) -> TypeFlags {
|
pub fn type_flags(self) -> TypeFlags {
|
||||||
let mut flags = TypeFlags::empty();
|
let mut flags = TypeFlags::empty();
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
@ -1746,8 +1787,8 @@ impl RegionKind {
|
|||||||
/// of the impl, and for all the other highlighted regions, it
|
/// of the impl, and for all the other highlighted regions, it
|
||||||
/// would return the `DefId` of the function. In other cases (not shown), this
|
/// would return the `DefId` of the function. In other cases (not shown), this
|
||||||
/// function might return the `DefId` of a closure.
|
/// function might return the `DefId` of a closure.
|
||||||
pub fn free_region_binding_scope(&self, tcx: TyCtxt<'_>) -> DefId {
|
pub fn free_region_binding_scope(self, tcx: TyCtxt<'_>) -> DefId {
|
||||||
match self {
|
match *self {
|
||||||
ty::ReEarlyBound(br) => tcx.parent(br.def_id).unwrap(),
|
ty::ReEarlyBound(br) => tcx.parent(br.def_id).unwrap(),
|
||||||
ty::ReFree(fr) => fr.scope,
|
ty::ReFree(fr) => fr.scope,
|
||||||
_ => bug!("free_region_binding_scope invoked on inappropriate region: {:?}", self),
|
_ => bug!("free_region_binding_scope invoked on inappropriate region: {:?}", self),
|
||||||
|
@ -26,6 +26,9 @@ use std::ops::ControlFlow;
|
|||||||
/// To reduce memory usage, a `GenericArg` is an interned pointer,
|
/// To reduce memory usage, a `GenericArg` is an interned pointer,
|
||||||
/// with the lowest 2 bits being reserved for a tag to
|
/// with the lowest 2 bits being reserved for a tag to
|
||||||
/// indicate the type (`Ty`, `Region`, or `Const`) it points to.
|
/// indicate the type (`Ty`, `Region`, or `Const`) it points to.
|
||||||
|
///
|
||||||
|
/// Note: the `PartialEq`, `Eq` and `Hash` derives are only valid because `Ty`,
|
||||||
|
/// `Region` and `Const` are all interned.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct GenericArg<'tcx> {
|
pub struct GenericArg<'tcx> {
|
||||||
ptr: NonZeroUsize,
|
ptr: NonZeroUsize,
|
||||||
@ -49,8 +52,8 @@ impl<'tcx> GenericArgKind<'tcx> {
|
|||||||
let (tag, ptr) = match self {
|
let (tag, ptr) = match self {
|
||||||
GenericArgKind::Lifetime(lt) => {
|
GenericArgKind::Lifetime(lt) => {
|
||||||
// Ensure we can use the tag bits.
|
// Ensure we can use the tag bits.
|
||||||
assert_eq!(mem::align_of_val(lt) & TAG_MASK, 0);
|
assert_eq!(mem::align_of_val(lt.0.0) & TAG_MASK, 0);
|
||||||
(REGION_TAG, lt as *const ty::RegionKind as usize)
|
(REGION_TAG, lt.0.0 as *const ty::RegionKind as usize)
|
||||||
}
|
}
|
||||||
GenericArgKind::Type(ty) => {
|
GenericArgKind::Type(ty) => {
|
||||||
// Ensure we can use the tag bits.
|
// Ensure we can use the tag bits.
|
||||||
@ -117,9 +120,9 @@ impl<'tcx> GenericArg<'tcx> {
|
|||||||
// and this is just going in the other direction.
|
// and this is just going in the other direction.
|
||||||
unsafe {
|
unsafe {
|
||||||
match ptr & TAG_MASK {
|
match ptr & TAG_MASK {
|
||||||
REGION_TAG => {
|
REGION_TAG => GenericArgKind::Lifetime(ty::Region(Interned::new_unchecked(
|
||||||
GenericArgKind::Lifetime(&*((ptr & !TAG_MASK) as *const ty::RegionKind))
|
&*((ptr & !TAG_MASK) as *const ty::RegionKind),
|
||||||
}
|
))),
|
||||||
TYPE_TAG => GenericArgKind::Type(Ty(Interned::new_unchecked(
|
TYPE_TAG => GenericArgKind::Type(Ty(Interned::new_unchecked(
|
||||||
&*((ptr & !TAG_MASK) as *const ty::TyS<'tcx>),
|
&*((ptr & !TAG_MASK) as *const ty::TyS<'tcx>),
|
||||||
))),
|
))),
|
||||||
|
@ -5,8 +5,9 @@ use crate::ty::fold::{FallibleTypeFolder, TypeFolder};
|
|||||||
use crate::ty::layout::IntegerExt;
|
use crate::ty::layout::IntegerExt;
|
||||||
use crate::ty::query::TyCtxtAt;
|
use crate::ty::query::TyCtxtAt;
|
||||||
use crate::ty::subst::{GenericArgKind, Subst, SubstsRef};
|
use crate::ty::subst::{GenericArgKind, Subst, SubstsRef};
|
||||||
use crate::ty::TyKind::*;
|
use crate::ty::{
|
||||||
use crate::ty::{self, DebruijnIndex, DefIdTree, List, Ty, TyCtxt, TypeFoldable};
|
self, DebruijnIndex, DefIdTree, List, ReEarlyBound, Region, Ty, TyCtxt, TyKind::*, TypeFoldable,
|
||||||
|
};
|
||||||
use rustc_apfloat::Float as _;
|
use rustc_apfloat::Float as _;
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_attr::{self as attr, SignedInt, UnsignedInt};
|
use rustc_attr::{self as attr, SignedInt, UnsignedInt};
|
||||||
@ -390,7 +391,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
let result = iter::zip(item_substs, impl_substs)
|
let result = iter::zip(item_substs, impl_substs)
|
||||||
.filter(|&(_, k)| {
|
.filter(|&(_, k)| {
|
||||||
match k.unpack() {
|
match k.unpack() {
|
||||||
GenericArgKind::Lifetime(&ty::RegionKind::ReEarlyBound(ref ebr)) => {
|
GenericArgKind::Lifetime(Region(Interned(ReEarlyBound(ref ebr), _))) => {
|
||||||
!impl_generics.region_param(ebr, self).pure_wrt_drop
|
!impl_generics.region_param(ebr, self).pure_wrt_drop
|
||||||
}
|
}
|
||||||
GenericArgKind::Type(Ty(Interned(
|
GenericArgKind::Type(Ty(Interned(
|
||||||
|
@ -397,7 +397,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
(Some((region, elem_ty, _)), _) | (None, Some((region, elem_ty, _))) => {
|
(Some((region, elem_ty, _)), _) | (None, Some((region, elem_ty, _))) => {
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
// make both a slice
|
// make both a slice
|
||||||
ty = tcx.mk_imm_ref(region, tcx.mk_slice(*elem_ty));
|
ty = tcx.mk_imm_ref(*region, tcx.mk_slice(*elem_ty));
|
||||||
if opt_ref_ty.is_some() {
|
if opt_ref_ty.is_some() {
|
||||||
let temp = self.temp(ty, source_info.span);
|
let temp = self.temp(ty, source_info.span);
|
||||||
self.cfg.push_assign(
|
self.cfg.push_assign(
|
||||||
|
@ -3,10 +3,11 @@
|
|||||||
|
|
||||||
use crate::MirPass;
|
use crate::MirPass;
|
||||||
use rustc_data_structures::fx::FxIndexMap;
|
use rustc_data_structures::fx::FxIndexMap;
|
||||||
|
use rustc_data_structures::intern::Interned;
|
||||||
use rustc_index::bit_set::BitSet;
|
use rustc_index::bit_set::BitSet;
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, ReErased, Region, TyCtxt};
|
||||||
|
|
||||||
const MAX_NUM_BLOCKS: usize = 800;
|
const MAX_NUM_BLOCKS: usize = 800;
|
||||||
const MAX_NUM_LOCALS: usize = 3000;
|
const MAX_NUM_LOCALS: usize = 3000;
|
||||||
@ -231,11 +232,15 @@ fn normalize_array_len_call<'tcx>(
|
|||||||
// current way of patching doesn't allow to work with `mut`
|
// current way of patching doesn't allow to work with `mut`
|
||||||
(
|
(
|
||||||
ty::Ref(
|
ty::Ref(
|
||||||
ty::RegionKind::ReErased,
|
Region(Interned(ReErased, _)),
|
||||||
operand_ty,
|
operand_ty,
|
||||||
Mutability::Not,
|
Mutability::Not,
|
||||||
),
|
),
|
||||||
ty::Ref(ty::RegionKind::ReErased, cast_ty, Mutability::Not),
|
ty::Ref(
|
||||||
|
Region(Interned(ReErased, _)),
|
||||||
|
cast_ty,
|
||||||
|
Mutability::Not,
|
||||||
|
),
|
||||||
) => {
|
) => {
|
||||||
match (operand_ty.kind(), cast_ty.kind()) {
|
match (operand_ty.kind(), cast_ty.kind()) {
|
||||||
// current way of patching doesn't allow to work with `mut`
|
// current way of patching doesn't allow to work with `mut`
|
||||||
|
@ -420,7 +420,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
|
|||||||
hir::Mutability::Not => "R",
|
hir::Mutability::Not => "R",
|
||||||
hir::Mutability::Mut => "Q",
|
hir::Mutability::Mut => "Q",
|
||||||
});
|
});
|
||||||
if *r != ty::ReErased {
|
if !r.is_erased() {
|
||||||
self = r.print(self)?;
|
self = r.print(self)?;
|
||||||
}
|
}
|
||||||
self = ty.print(self)?;
|
self = ty.print(self)?;
|
||||||
@ -811,7 +811,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
|
|||||||
) -> Result<Self::Path, Self::Error> {
|
) -> Result<Self::Path, Self::Error> {
|
||||||
// Don't print any regions if they're all erased.
|
// Don't print any regions if they're all erased.
|
||||||
let print_regions = args.iter().any(|arg| match arg.unpack() {
|
let print_regions = args.iter().any(|arg| match arg.unpack() {
|
||||||
GenericArgKind::Lifetime(r) => *r != ty::ReErased,
|
GenericArgKind::Lifetime(r) => !r.is_erased(),
|
||||||
_ => false,
|
_ => false,
|
||||||
});
|
});
|
||||||
let args = args.iter().cloned().filter(|arg| match arg.unpack() {
|
let args = args.iter().cloned().filter(|arg| match arg.unpack() {
|
||||||
|
@ -141,7 +141,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
|
|||||||
|
|
||||||
#[instrument(skip(self), level = "debug")]
|
#[instrument(skip(self), level = "debug")]
|
||||||
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
||||||
match r {
|
match *r {
|
||||||
// Ignore bound regions and `'static` regions that appear in the
|
// Ignore bound regions and `'static` regions that appear in the
|
||||||
// type, we only need to remap regions that reference lifetimes
|
// type, we only need to remap regions that reference lifetimes
|
||||||
// from the function declaraion.
|
// from the function declaraion.
|
||||||
|
@ -437,7 +437,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
|
|||||||
for (new_region, old_region) in
|
for (new_region, old_region) in
|
||||||
iter::zip(new_substs.regions(), old_substs.regions())
|
iter::zip(new_substs.regions(), old_substs.regions())
|
||||||
{
|
{
|
||||||
match (new_region, old_region) {
|
match (*new_region, *old_region) {
|
||||||
// If both predicates have an `ReLateBound` (a HRTB) in the
|
// If both predicates have an `ReLateBound` (a HRTB) in the
|
||||||
// same spot, we do nothing.
|
// same spot, we do nothing.
|
||||||
(
|
(
|
||||||
@ -880,8 +880,8 @@ impl<'a, 'tcx> TypeFolder<'tcx> for RegionReplacer<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
||||||
(match r {
|
(match *r {
|
||||||
ty::ReVar(vid) => self.vid_to_region.get(vid).cloned(),
|
ty::ReVar(vid) => self.vid_to_region.get(&vid).cloned(),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| r.super_fold_with(self))
|
.unwrap_or_else(|| r.super_fold_with(self))
|
||||||
|
@ -697,7 +697,7 @@ impl<'tcx> TypeFolder<'tcx> for PlaceholderReplacer<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fold_region(&mut self, r0: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
fn fold_region(&mut self, r0: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
||||||
let r1 = match r0 {
|
let r1 = match *r0 {
|
||||||
ty::ReVar(_) => self
|
ty::ReVar(_) => self
|
||||||
.infcx
|
.infcx
|
||||||
.inner
|
.inner
|
||||||
|
@ -451,7 +451,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'t
|
|||||||
fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::Lifetime<RustInterner<'tcx>> {
|
fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::Lifetime<RustInterner<'tcx>> {
|
||||||
use rustc_middle::ty::RegionKind::*;
|
use rustc_middle::ty::RegionKind::*;
|
||||||
|
|
||||||
match self {
|
match *self {
|
||||||
ReEarlyBound(_) => {
|
ReEarlyBound(_) => {
|
||||||
panic!("Should have already been substituted.");
|
panic!("Should have already been substituted.");
|
||||||
}
|
}
|
||||||
@ -915,8 +915,8 @@ impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn visit_region(&mut self, r: Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_region(&mut self, r: Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
match r {
|
match *r {
|
||||||
ty::ReLateBound(index, br) if *index == self.binder_index => match br.kind {
|
ty::ReLateBound(index, br) if index == self.binder_index => match br.kind {
|
||||||
ty::BoundRegionKind::BrNamed(def_id, _name) => {
|
ty::BoundRegionKind::BrNamed(def_id, _name) => {
|
||||||
if !self.named_parameters.iter().any(|d| *d == def_id) {
|
if !self.named_parameters.iter().any(|d| *d == def_id) {
|
||||||
self.named_parameters.push(def_id);
|
self.named_parameters.push(def_id);
|
||||||
@ -977,12 +977,12 @@ impl<'a, 'tcx> TypeFolder<'tcx> for NamedBoundVarSubstitutor<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
|
fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
|
||||||
match r {
|
match *r {
|
||||||
ty::ReLateBound(index, br) if *index == self.binder_index => match br.kind {
|
ty::ReLateBound(index, br) if index == self.binder_index => match br.kind {
|
||||||
ty::BrNamed(def_id, _name) => match self.named_parameters.get(&def_id) {
|
ty::BrNamed(def_id, _name) => match self.named_parameters.get(&def_id) {
|
||||||
Some(idx) => {
|
Some(idx) => {
|
||||||
let new_br = ty::BoundRegion { var: br.var, kind: ty::BrAnon(*idx) };
|
let new_br = ty::BoundRegion { var: br.var, kind: ty::BrAnon(*idx) };
|
||||||
return self.tcx.mk_region(RegionKind::ReLateBound(*index, new_br));
|
return self.tcx.mk_region(RegionKind::ReLateBound(index, new_br));
|
||||||
}
|
}
|
||||||
None => panic!("Missing `BrNamed`."),
|
None => panic!("Missing `BrNamed`."),
|
||||||
},
|
},
|
||||||
@ -1054,7 +1054,7 @@ impl<'tcx> TypeFolder<'tcx> for ParamsSubstitutor<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
|
fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
|
||||||
match r {
|
match *r {
|
||||||
// FIXME(chalk) - jackh726 - this currently isn't hit in any tests,
|
// FIXME(chalk) - jackh726 - this currently isn't hit in any tests,
|
||||||
// since canonicalization will already change these to canonical
|
// since canonicalization will already change these to canonical
|
||||||
// variables (ty::ReLateBound).
|
// variables (ty::ReLateBound).
|
||||||
@ -1144,7 +1144,7 @@ impl<'tcx> TypeVisitor<'tcx> for PlaceholdersCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn visit_region(&mut self, r: Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_region(&mut self, r: Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
match r {
|
match *r {
|
||||||
ty::RePlaceholder(p) if p.universe == self.universe_index => {
|
ty::RePlaceholder(p) if p.universe == self.universe_index => {
|
||||||
if let ty::BoundRegionKind::BrAnon(anon) = p.name {
|
if let ty::BoundRegionKind::BrAnon(anon) = p.name {
|
||||||
self.next_anon_region_placeholder = self.next_anon_region_placeholder.max(anon);
|
self.next_anon_region_placeholder = self.next_anon_region_placeholder.max(anon);
|
||||||
|
@ -90,8 +90,8 @@ impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
match r {
|
match *r {
|
||||||
ty::ReLateBound(index, br) if *index == self.binder_index => {
|
ty::ReLateBound(index, br) if index == self.binder_index => {
|
||||||
match self.vars.entry(br.var.as_u32()) {
|
match self.vars.entry(br.var.as_u32()) {
|
||||||
Entry::Vacant(entry) => {
|
Entry::Vacant(entry) => {
|
||||||
entry.insert(ty::BoundVariableKind::Region(br.kind));
|
entry.insert(ty::BoundVariableKind::Region(br.kind));
|
||||||
|
@ -410,7 +410,7 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Ty<'_>> {
|
|||||||
|
|
||||||
let self_ty = trait_ref.self_ty();
|
let self_ty = trait_ref.self_ty();
|
||||||
let self_ty_matches = match self_ty.kind() {
|
let self_ty_matches = match self_ty.kind() {
|
||||||
ty::Dynamic(ref data, ty::ReStatic) => data.principal().is_none(),
|
ty::Dynamic(ref data, re) if re.is_static() => data.principal().is_none(),
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2669,7 +2669,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||||||
|
|
||||||
// If any of the derived region bounds are 'static, that is always
|
// If any of the derived region bounds are 'static, that is always
|
||||||
// the best choice.
|
// the best choice.
|
||||||
if derived_region_bounds.iter().any(|&r| ty::ReStatic == *r) {
|
if derived_region_bounds.iter().any(|r| r.is_static()) {
|
||||||
return Some(tcx.lifetimes.re_static);
|
return Some(tcx.lifetimes.re_static);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,7 +269,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
autoref = Some(Adjustment {
|
autoref = Some(Adjustment {
|
||||||
kind: Adjust::Borrow(AutoBorrow::Ref(region, mutbl)),
|
kind: Adjust::Borrow(AutoBorrow::Ref(*region, mutbl)),
|
||||||
target: method.sig.inputs()[0],
|
target: method.sig.inputs()[0],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -369,7 +369,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
|||||||
.try_coerce(
|
.try_coerce(
|
||||||
self.expr,
|
self.expr,
|
||||||
fcx.tcx.mk_ref(
|
fcx.tcx.mk_ref(
|
||||||
&ty::RegionKind::ReErased,
|
fcx.tcx.lifetimes.re_erased,
|
||||||
TypeAndMut { ty: expr_ty, mutbl },
|
TypeAndMut { ty: expr_ty, mutbl },
|
||||||
),
|
),
|
||||||
self.cast_ty,
|
self.cast_ty,
|
||||||
@ -419,7 +419,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
|||||||
.try_coerce(
|
.try_coerce(
|
||||||
self.expr,
|
self.expr,
|
||||||
fcx.tcx.mk_ref(
|
fcx.tcx.mk_ref(
|
||||||
&ty::RegionKind::ReErased,
|
fcx.tcx.lifetimes.re_erased,
|
||||||
TypeAndMut { ty: self.expr_ty, mutbl },
|
TypeAndMut { ty: self.expr_ty, mutbl },
|
||||||
),
|
),
|
||||||
self.cast_ty,
|
self.cast_ty,
|
||||||
|
@ -17,7 +17,7 @@ use rustc_middle::ty::fold::TypeFoldable;
|
|||||||
use rustc_middle::ty::layout::MAX_SIMD_LANES;
|
use rustc_middle::ty::layout::MAX_SIMD_LANES;
|
||||||
use rustc_middle::ty::subst::GenericArgKind;
|
use rustc_middle::ty::subst::GenericArgKind;
|
||||||
use rustc_middle::ty::util::{Discr, IntTypeExt};
|
use rustc_middle::ty::util::{Discr, IntTypeExt};
|
||||||
use rustc_middle::ty::{self, OpaqueTypeKey, ParamEnv, RegionKind, Ty, TyCtxt};
|
use rustc_middle::ty::{self, OpaqueTypeKey, ParamEnv, Ty, TyCtxt};
|
||||||
use rustc_session::lint::builtin::{UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS};
|
use rustc_session::lint::builtin::{UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS};
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::{self, MultiSpan, Span};
|
use rustc_span::{self, MultiSpan, Span};
|
||||||
@ -269,7 +269,7 @@ pub(super) fn check_fn<'a, 'tcx>(
|
|||||||
ty::Adt(ref adt, _) => {
|
ty::Adt(ref adt, _) => {
|
||||||
adt.did == panic_info_did
|
adt.did == panic_info_did
|
||||||
&& mutbl == hir::Mutability::Not
|
&& mutbl == hir::Mutability::Not
|
||||||
&& *region != RegionKind::ReStatic
|
&& !region.is_static()
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
@ -469,8 +469,8 @@ pub(super) fn check_opaque_for_inheriting_lifetimes<'tcx>(
|
|||||||
|
|
||||||
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
debug!("FindParentLifetimeVisitor: r={:?}", r);
|
debug!("FindParentLifetimeVisitor: r={:?}", r);
|
||||||
if let RegionKind::ReEarlyBound(ty::EarlyBoundRegion { index, .. }) = r {
|
if let ty::ReEarlyBound(ty::EarlyBoundRegion { index, .. }) = *r {
|
||||||
if *index < self.0.parent_count as u32 {
|
if index < self.0.parent_count as u32 {
|
||||||
return ControlFlow::Break(FoundParentLifetime);
|
return ControlFlow::Break(FoundParentLifetime);
|
||||||
} else {
|
} else {
|
||||||
return ControlFlow::CONTINUE;
|
return ControlFlow::CONTINUE;
|
||||||
|
@ -472,7 +472,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
adjustments.push(Adjustment {
|
adjustments.push(Adjustment {
|
||||||
kind: Adjust::Borrow(AutoBorrow::Ref(r_borrow, mutbl)),
|
kind: Adjust::Borrow(AutoBorrow::Ref(*r_borrow, mutbl)),
|
||||||
target: ty,
|
target: ty,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -227,7 +227,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
if let ty::Ref(region, t_type, mutability) = self_ty.kind() {
|
if let ty::Ref(region, t_type, mutability) = self_ty.kind() {
|
||||||
let trait_type = self
|
let trait_type = self
|
||||||
.tcx
|
.tcx
|
||||||
.mk_ref(region, ty::TypeAndMut { ty: *t_type, mutbl: mutability.invert() });
|
.mk_ref(*region, ty::TypeAndMut { ty: *t_type, mutbl: mutability.invert() });
|
||||||
// We probe again to see if there might be a borrow mutability discrepancy.
|
// We probe again to see if there might be a borrow mutability discrepancy.
|
||||||
match self.lookup_probe(
|
match self.lookup_probe(
|
||||||
span,
|
span,
|
||||||
|
@ -1086,7 +1086,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
if let ty::Ref(region, t_type, mutability) = rcvr_ty.kind() {
|
if let ty::Ref(region, t_type, mutability) = rcvr_ty.kind() {
|
||||||
if needs_mut {
|
if needs_mut {
|
||||||
let trait_type = self.tcx.mk_ref(
|
let trait_type = self.tcx.mk_ref(
|
||||||
region,
|
*region,
|
||||||
ty::TypeAndMut { ty: *t_type, mutbl: mutability.invert() },
|
ty::TypeAndMut { ty: *t_type, mutbl: mutability.invert() },
|
||||||
);
|
);
|
||||||
err.note(&format!("you need `{}` instead of `{}`", trait_type, rcvr_ty));
|
err.note(&format!("you need `{}` instead of `{}`", trait_type, rcvr_ty));
|
||||||
@ -1462,8 +1462,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// just this list.
|
// just this list.
|
||||||
for (rcvr_ty, post) in &[
|
for (rcvr_ty, post) in &[
|
||||||
(rcvr_ty, ""),
|
(rcvr_ty, ""),
|
||||||
(self.tcx.mk_mut_ref(&ty::ReErased, rcvr_ty), "&mut "),
|
(self.tcx.mk_mut_ref(self.tcx.lifetimes.re_erased, rcvr_ty), "&mut "),
|
||||||
(self.tcx.mk_imm_ref(&ty::ReErased, rcvr_ty), "&"),
|
(self.tcx.mk_imm_ref(self.tcx.lifetimes.re_erased, rcvr_ty), "&"),
|
||||||
] {
|
] {
|
||||||
if let Ok(pick) = self.lookup_probe(
|
if let Ok(pick) = self.lookup_probe(
|
||||||
span,
|
span,
|
||||||
|
@ -221,7 +221,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
let autoref = Adjustment {
|
let autoref = Adjustment {
|
||||||
kind: Adjust::Borrow(AutoBorrow::Ref(region, mutbl)),
|
kind: Adjust::Borrow(AutoBorrow::Ref(*region, mutbl)),
|
||||||
target: method.sig.inputs()[0],
|
target: method.sig.inputs()[0],
|
||||||
};
|
};
|
||||||
self.apply_adjustments(lhs_expr, vec![autoref]);
|
self.apply_adjustments(lhs_expr, vec![autoref]);
|
||||||
@ -238,7 +238,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
let autoref = Adjustment {
|
let autoref = Adjustment {
|
||||||
kind: Adjust::Borrow(AutoBorrow::Ref(region, mutbl)),
|
kind: Adjust::Borrow(AutoBorrow::Ref(*region, mutbl)),
|
||||||
target: method.sig.inputs()[1],
|
target: method.sig.inputs()[1],
|
||||||
};
|
};
|
||||||
// HACK(eddyb) Bypass checks due to reborrows being in
|
// HACK(eddyb) Bypass checks due to reborrows being in
|
||||||
|
@ -31,7 +31,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
self.apply_adjustments(
|
self.apply_adjustments(
|
||||||
oprnd_expr,
|
oprnd_expr,
|
||||||
vec![Adjustment {
|
vec![Adjustment {
|
||||||
kind: Adjust::Borrow(AutoBorrow::Ref(region, AutoBorrowMutability::Not)),
|
kind: Adjust::Borrow(AutoBorrow::Ref(*region, AutoBorrowMutability::Not)),
|
||||||
target: method.sig.inputs()[0],
|
target: method.sig.inputs()[0],
|
||||||
}],
|
}],
|
||||||
);
|
);
|
||||||
@ -165,9 +165,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
let mut adjustments = self.adjust_steps(autoderef);
|
let mut adjustments = self.adjust_steps(autoderef);
|
||||||
if let ty::Ref(region, _, hir::Mutability::Not) = method.sig.inputs()[0].kind() {
|
if let ty::Ref(region, _, hir::Mutability::Not) = method.sig.inputs()[0].kind() {
|
||||||
adjustments.push(Adjustment {
|
adjustments.push(Adjustment {
|
||||||
kind: Adjust::Borrow(AutoBorrow::Ref(region, AutoBorrowMutability::Not)),
|
kind: Adjust::Borrow(AutoBorrow::Ref(*region, AutoBorrowMutability::Not)),
|
||||||
target: self.tcx.mk_ref(
|
target: self.tcx.mk_ref(
|
||||||
region,
|
*region,
|
||||||
ty::TypeAndMut { mutbl: hir::Mutability::Not, ty: adjusted_ty },
|
ty::TypeAndMut { mutbl: hir::Mutability::Not, ty: adjusted_ty },
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
@ -432,9 +432,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// not the case today.
|
// not the case today.
|
||||||
allow_two_phase_borrow: AllowTwoPhase::No,
|
allow_two_phase_borrow: AllowTwoPhase::No,
|
||||||
};
|
};
|
||||||
adjustment.kind = Adjust::Borrow(AutoBorrow::Ref(region, mutbl));
|
adjustment.kind = Adjust::Borrow(AutoBorrow::Ref(*region, mutbl));
|
||||||
adjustment.target =
|
adjustment.target = self
|
||||||
self.tcx.mk_ref(region, ty::TypeAndMut { ty: source, mutbl: mutbl.into() });
|
.tcx
|
||||||
|
.mk_ref(*region, ty::TypeAndMut { ty: source, mutbl: mutbl.into() });
|
||||||
}
|
}
|
||||||
source = adjustment.target;
|
source = adjustment.target;
|
||||||
}
|
}
|
||||||
|
@ -689,7 +689,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
|
|||||||
let rptr_ty = self.resolve_node_type(id);
|
let rptr_ty = self.resolve_node_type(id);
|
||||||
if let ty::Ref(r, _, _) = rptr_ty.kind() {
|
if let ty::Ref(r, _, _) = rptr_ty.kind() {
|
||||||
debug!("rptr_ty={}", rptr_ty);
|
debug!("rptr_ty={}", rptr_ty);
|
||||||
self.link_region(span, r, ty::BorrowKind::from_mutbl(mutbl), cmt_borrowed);
|
self.link_region(span, *r, ty::BorrowKind::from_mutbl(mutbl), cmt_borrowed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -966,7 +966,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
self.tcx,
|
self.tcx,
|
||||||
ty,
|
ty,
|
||||||
max_capture_info.capture_kind,
|
max_capture_info.capture_kind,
|
||||||
Some(&ty::ReErased),
|
Some(self.tcx.lifetimes.re_erased),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -997,7 +997,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
self.tcx,
|
self.tcx,
|
||||||
capture.place.ty(),
|
capture.place.ty(),
|
||||||
capture.info.capture_kind,
|
capture.info.capture_kind,
|
||||||
Some(&ty::ReErased),
|
Some(self.tcx.lifetimes.re_erased),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Checks if a capture implements any of the auto traits
|
// Checks if a capture implements any of the auto traits
|
||||||
|
@ -336,7 +336,7 @@ fn check_gat_where_clauses(
|
|||||||
// Ignore `'static` lifetimes for the purpose of this lint: it's
|
// Ignore `'static` lifetimes for the purpose of this lint: it's
|
||||||
// because we know it outlives everything and so doesn't give meaninful
|
// because we know it outlives everything and so doesn't give meaninful
|
||||||
// clues
|
// clues
|
||||||
if let ty::ReStatic = region {
|
if region.is_static() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (ty, ty_idx) in &types {
|
for (ty, ty_idx) in &types {
|
||||||
@ -381,14 +381,14 @@ fn check_gat_where_clauses(
|
|||||||
// Ignore `'static` lifetimes for the purpose of this lint: it's
|
// Ignore `'static` lifetimes for the purpose of this lint: it's
|
||||||
// because we know it outlives everything and so doesn't give meaninful
|
// because we know it outlives everything and so doesn't give meaninful
|
||||||
// clues
|
// clues
|
||||||
if let ty::ReStatic = region_a {
|
if region_a.is_static() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (region_b, region_b_idx) in ®ions {
|
for (region_b, region_b_idx) in ®ions {
|
||||||
if region_a == region_b {
|
if region_a == region_b {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let ty::ReStatic = region_b {
|
if region_b.is_static() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -569,7 +569,7 @@ fn resolve_regions_with_wf_tys<'tcx>(
|
|||||||
wf_tys: &FxHashSet<Ty<'tcx>>,
|
wf_tys: &FxHashSet<Ty<'tcx>>,
|
||||||
add_constraints: impl for<'a> FnOnce(
|
add_constraints: impl for<'a> FnOnce(
|
||||||
&'a InferCtxt<'a, 'tcx>,
|
&'a InferCtxt<'a, 'tcx>,
|
||||||
&'a Vec<(&'tcx ty::RegionKind, GenericKind<'tcx>)>,
|
&'a Vec<(ty::Region<'tcx>, GenericKind<'tcx>)>,
|
||||||
),
|
),
|
||||||
) -> bool {
|
) -> bool {
|
||||||
// Unfortunately, we have to use a new `InferCtxt` each call, because
|
// Unfortunately, we have to use a new `InferCtxt` each call, because
|
||||||
|
@ -751,7 +751,7 @@ impl<'tcx> TypeFolder<'tcx> for EraseEarlyRegions<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
||||||
if let ty::ReLateBound(..) = r { r } else { self.tcx.lifetimes.re_erased }
|
if r.is_late_bound() { r } else { self.tcx.lifetimes.re_erased }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ fn visit_implementation_of_dispatch_from_dyn<'tcx>(tcx: TyCtxt<'tcx>, impl_did:
|
|||||||
use ty::TyKind::*;
|
use ty::TyKind::*;
|
||||||
match (source.kind(), target.kind()) {
|
match (source.kind(), target.kind()) {
|
||||||
(&Ref(r_a, _, mutbl_a), Ref(r_b, _, mutbl_b))
|
(&Ref(r_a, _, mutbl_a), Ref(r_b, _, mutbl_b))
|
||||||
if infcx.at(&cause, param_env).eq(r_a, r_b).is_ok() && mutbl_a == *mutbl_b => {}
|
if infcx.at(&cause, param_env).eq(r_a, *r_b).is_ok() && mutbl_a == *mutbl_b => {}
|
||||||
(&RawPtr(tm_a), &RawPtr(tm_b)) if tm_a.mutbl == tm_b.mutbl => (),
|
(&RawPtr(tm_a), &RawPtr(tm_b)) if tm_a.mutbl == tm_b.mutbl => (),
|
||||||
(&Adt(def_a, substs_a), &Adt(def_b, substs_b))
|
(&Adt(def_a, substs_a), &Adt(def_b, substs_b))
|
||||||
if def_a.is_struct() && def_b.is_struct() =>
|
if def_a.is_struct() && def_b.is_struct() =>
|
||||||
|
@ -301,7 +301,7 @@ impl<'tcx> TypeVisitor<'tcx> for AreUniqueParamsVisitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
match r {
|
match *r {
|
||||||
ty::ReEarlyBound(p) => {
|
ty::ReEarlyBound(p) => {
|
||||||
if self.seen.insert(p.index) {
|
if self.seen.insert(p.index) {
|
||||||
ControlFlow::CONTINUE
|
ControlFlow::CONTINUE
|
||||||
|
@ -395,7 +395,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
|
|||||||
_: Option<&ty::GenericParamDef>,
|
_: Option<&ty::GenericParamDef>,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> &'tcx Const<'tcx> {
|
) -> &'tcx Const<'tcx> {
|
||||||
let ty = self.tcx.fold_regions(ty, &mut false, |r, _| match r {
|
let ty = self.tcx.fold_regions(ty, &mut false, |r, _| match *r {
|
||||||
ty::ReErased => self.tcx.lifetimes.re_static,
|
ty::ReErased => self.tcx.lifetimes.re_static,
|
||||||
_ => r,
|
_ => r,
|
||||||
});
|
});
|
||||||
@ -1878,7 +1878,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
|
|||||||
Some(ty) => {
|
Some(ty) => {
|
||||||
let fn_sig = tcx.typeck(def_id).liberated_fn_sigs()[hir_id];
|
let fn_sig = tcx.typeck(def_id).liberated_fn_sigs()[hir_id];
|
||||||
// Typeck doesn't expect erased regions to be returned from `type_of`.
|
// Typeck doesn't expect erased regions to be returned from `type_of`.
|
||||||
let fn_sig = tcx.fold_regions(fn_sig, &mut false, |r, _| match r {
|
let fn_sig = tcx.fold_regions(fn_sig, &mut false, |r, _| match *r {
|
||||||
ty::ReErased => tcx.lifetimes.re_static,
|
ty::ReErased => tcx.lifetimes.re_static,
|
||||||
_ => r,
|
_ => r,
|
||||||
});
|
});
|
||||||
|
@ -829,7 +829,7 @@ fn infer_placeholder_type<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Typeck doesn't expect erased regions to be returned from `type_of`.
|
// Typeck doesn't expect erased regions to be returned from `type_of`.
|
||||||
tcx.fold_regions(ty, &mut false, |r, _| match r {
|
tcx.fold_regions(ty, &mut false, |r, _| match *r {
|
||||||
ty::ReErased => tcx.lifetimes.re_static,
|
ty::ReErased => tcx.lifetimes.re_static,
|
||||||
_ => r,
|
_ => r,
|
||||||
})
|
})
|
||||||
|
@ -180,6 +180,6 @@ impl<'tcx> TypeFolder<'tcx> for EraseAllBoundRegions<'tcx> {
|
|||||||
self.tcx
|
self.tcx
|
||||||
}
|
}
|
||||||
fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
|
fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
|
||||||
if let ty::ReLateBound(..) = r { &ty::ReErased } else { r }
|
if r.is_late_bound() { self.tcx.lifetimes.re_erased } else { r }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -269,7 +269,7 @@ fn check_static_lifetimes<'tcx>(
|
|||||||
parent_substs: &Vec<GenericArg<'tcx>>,
|
parent_substs: &Vec<GenericArg<'tcx>>,
|
||||||
span: Span,
|
span: Span,
|
||||||
) {
|
) {
|
||||||
if tcx.any_free_region_meets(parent_substs, |r| *r == ty::ReStatic) {
|
if tcx.any_free_region_meets(parent_substs, |r| r.is_static()) {
|
||||||
tcx.sess.struct_span_err(span, "cannot specialize on `'static` lifetime").emit();
|
tcx.sess.struct_span_err(span, "cannot specialize on `'static` lifetime").emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,14 +105,14 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, (): ()) -> CratePredicatesMap<'_> {
|
|||||||
match kind1.unpack() {
|
match kind1.unpack() {
|
||||||
GenericArgKind::Type(ty1) => Some((
|
GenericArgKind::Type(ty1) => Some((
|
||||||
ty::Binder::dummy(ty::PredicateKind::TypeOutlives(
|
ty::Binder::dummy(ty::PredicateKind::TypeOutlives(
|
||||||
ty::OutlivesPredicate(ty1, region2),
|
ty::OutlivesPredicate(ty1, *region2),
|
||||||
))
|
))
|
||||||
.to_predicate(tcx),
|
.to_predicate(tcx),
|
||||||
span,
|
span,
|
||||||
)),
|
)),
|
||||||
GenericArgKind::Lifetime(region1) => Some((
|
GenericArgKind::Lifetime(region1) => Some((
|
||||||
ty::Binder::dummy(ty::PredicateKind::RegionOutlives(
|
ty::Binder::dummy(ty::PredicateKind::RegionOutlives(
|
||||||
ty::OutlivesPredicate(region1, region2),
|
ty::OutlivesPredicate(region1, *region2),
|
||||||
))
|
))
|
||||||
.to_predicate(tcx),
|
.to_predicate(tcx),
|
||||||
span,
|
span,
|
||||||
|
@ -133,7 +133,7 @@ pub fn insert_outlives_predicate<'tcx>(
|
|||||||
|
|
||||||
fn is_free_region(tcx: TyCtxt<'_>, region: Region<'_>) -> bool {
|
fn is_free_region(tcx: TyCtxt<'_>, region: Region<'_>) -> bool {
|
||||||
// First, screen for regions that might appear in a type header.
|
// First, screen for regions that might appear in a type header.
|
||||||
match region {
|
match *region {
|
||||||
// These correspond to `T: 'a` relationships:
|
// These correspond to `T: 'a` relationships:
|
||||||
//
|
//
|
||||||
// struct Foo<'a, T> {
|
// struct Foo<'a, T> {
|
||||||
|
@ -297,7 +297,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
|
|||||||
.get(name)
|
.get(name)
|
||||||
.unwrap_or(&empty)
|
.unwrap_or(&empty)
|
||||||
.iter()
|
.iter()
|
||||||
.map(|region| GenericBound::Outlives(Self::get_lifetime(region, names_map)))
|
.map(|region| GenericBound::Outlives(Self::get_lifetime(*region, names_map)))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if bounds.is_empty() {
|
if bounds.is_empty() {
|
||||||
|
@ -218,9 +218,9 @@ impl Clean<Constant> for hir::ConstArg {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clean<Option<Lifetime>> for ty::RegionKind {
|
impl Clean<Option<Lifetime>> for ty::Region<'_> {
|
||||||
fn clean(&self, _cx: &mut DocContext<'_>) -> Option<Lifetime> {
|
fn clean(&self, _cx: &mut DocContext<'_>) -> Option<Lifetime> {
|
||||||
match *self {
|
match **self {
|
||||||
ty::ReStatic => Some(Lifetime::statik()),
|
ty::ReStatic => Some(Lifetime::statik()),
|
||||||
ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrNamed(_, name), .. }) => {
|
ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrNamed(_, name), .. }) => {
|
||||||
Some(Lifetime(name))
|
Some(Lifetime(name))
|
||||||
@ -327,7 +327,7 @@ impl<'tcx> Clean<Option<WherePredicate>>
|
|||||||
fn clean(&self, cx: &mut DocContext<'_>) -> Option<WherePredicate> {
|
fn clean(&self, cx: &mut DocContext<'_>) -> Option<WherePredicate> {
|
||||||
let ty::OutlivesPredicate(a, b) = self;
|
let ty::OutlivesPredicate(a, b) = self;
|
||||||
|
|
||||||
if let (ty::ReEmpty(_), ty::ReEmpty(_)) = (a, b) {
|
if a.is_empty() && b.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,7 +342,7 @@ impl<'tcx> Clean<Option<WherePredicate>> for ty::OutlivesPredicate<Ty<'tcx>, ty:
|
|||||||
fn clean(&self, cx: &mut DocContext<'_>) -> Option<WherePredicate> {
|
fn clean(&self, cx: &mut DocContext<'_>) -> Option<WherePredicate> {
|
||||||
let ty::OutlivesPredicate(ty, lt) = self;
|
let ty::OutlivesPredicate(ty, lt) = self;
|
||||||
|
|
||||||
if let ty::ReEmpty(_) = lt {
|
if lt.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ fn external_generic_args(
|
|||||||
let args: Vec<_> = substs
|
let args: Vec<_> = substs
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|kind| match kind.unpack() {
|
.filter_map(|kind| match kind.unpack() {
|
||||||
GenericArgKind::Lifetime(lt) => match lt {
|
GenericArgKind::Lifetime(lt) => match *lt {
|
||||||
ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrAnon(_), .. }) => {
|
ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrAnon(_), .. }) => {
|
||||||
Some(GenericArg::Lifetime(Lifetime::elided()))
|
Some(GenericArg::Lifetime(Lifetime::elided()))
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
error[E0277]: the trait bound `for<'a> (): Trait2<'a>` is not satisfied
|
error[E0277]: the trait bound `for<'a> (): Trait2<'a>` is not satisfied
|
||||||
--> $DIR/issue-35570.rs:8:4
|
--> $DIR/issue-35570.rs:8:40
|
||||||
|
|
|
|
||||||
LL | fn _ice(param: Box<dyn for <'a> Trait1<<() as Trait2<'a>>::Ty>>) {
|
LL | fn _ice(param: Box<dyn for <'a> Trait1<<() as Trait2<'a>>::Ty>>) {
|
||||||
| ^^^^ the trait `for<'a> Trait2<'a>` is not implemented for `()`
|
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'a> Trait2<'a>` is not implemented for `()`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
error[E0277]: the trait bound `for<'z> T: Trait2<'y, 'z>` is not satisfied
|
error[E0277]: the trait bound `for<'z> T: Trait2<'y, 'z>` is not satisfied
|
||||||
--> $DIR/regions-implied-bounds-projection-gap-hr-1.rs:21:4
|
--> $DIR/regions-implied-bounds-projection-gap-hr-1.rs:21:49
|
||||||
|
|
|
|
||||||
LL | fn callee<'x, 'y, T>(t: &'x dyn for<'z> Trait1< <T as Trait2<'y, 'z>>::Foo >)
|
LL | fn callee<'x, 'y, T>(t: &'x dyn for<'z> Trait1< <T as Trait2<'y, 'z>>::Foo >)
|
||||||
| ^^^^^^ the trait `for<'z> Trait2<'y, 'z>` is not implemented for `T`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'z> Trait2<'y, 'z>` is not implemented for `T`
|
||||||
|
|
|
|
||||||
help: consider restricting type parameter `T`
|
help: consider restricting type parameter `T`
|
||||||
|
|
|
|
||||||
|
@ -73,7 +73,7 @@ pub(super) fn check<'tcx>(
|
|||||||
match cx.qpath_res(p, fun.hir_id) {
|
match cx.qpath_res(p, fun.hir_id) {
|
||||||
hir::def::Res::Def(hir::def::DefKind::Fn | hir::def::DefKind::AssocFn, def_id) => matches!(
|
hir::def::Res::Def(hir::def::DefKind::Fn | hir::def::DefKind::AssocFn, def_id) => matches!(
|
||||||
cx.tcx.fn_sig(def_id).output().skip_binder().kind(),
|
cx.tcx.fn_sig(def_id).output().skip_binder().kind(),
|
||||||
ty::Ref(ty::ReStatic, ..)
|
ty::Ref(re, ..) if re.is_static(),
|
||||||
),
|
),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ pub(super) fn check<'tcx>(
|
|||||||
.map_or(false, |method_id| {
|
.map_or(false, |method_id| {
|
||||||
matches!(
|
matches!(
|
||||||
cx.tcx.fn_sig(method_id).output().skip_binder().kind(),
|
cx.tcx.fn_sig(method_id).output().skip_binder().kind(),
|
||||||
ty::Ref(ty::ReStatic, ..)
|
ty::Ref(re, ..) if re.is_static()
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user