Completely remove LifetimeScopeForPath.
This commit is contained in:
parent
a07290047e
commit
af8739b96e
@ -16,19 +16,6 @@ pub enum Region {
|
||||
Free(DefId, /* lifetime decl */ DefId),
|
||||
}
|
||||
|
||||
/// This is used in diagnostics to improve suggestions for missing generic arguments.
|
||||
/// It gives information on the type of lifetimes that are in scope for a particular `PathSegment`,
|
||||
/// so that we can e.g. suggest elided-lifetimes-in-paths of the form <'_, '_> e.g.
|
||||
#[derive(Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, HashStable)]
|
||||
pub enum LifetimeScopeForPath {
|
||||
/// Contains all lifetime names that are in scope and could possibly be used in generics
|
||||
/// arguments of path.
|
||||
NonElided,
|
||||
/// Information that allows us to suggest args of the form `<'_>` in case
|
||||
/// no generic arguments were provided for a path.
|
||||
Elided,
|
||||
}
|
||||
|
||||
/// A set containing, at most, one known element.
|
||||
/// If two distinct values are inserted into a set, then it
|
||||
/// becomes `Many`, which can be used to detect ambiguities.
|
||||
|
@ -1599,11 +1599,6 @@
|
||||
desc { "looking up late bound vars" }
|
||||
}
|
||||
|
||||
query lifetime_scope_map(_: LocalDefId) -> Option<FxHashMap<ItemLocalId, LifetimeScopeForPath>> {
|
||||
storage(ArenaCacheSelector<'tcx>)
|
||||
desc { "finds the lifetime scope for an HirId of a PathSegment" }
|
||||
}
|
||||
|
||||
query visibility(def_id: DefId) -> ty::Visibility {
|
||||
desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
|
||||
separate_provide_extern
|
||||
|
@ -6,7 +6,7 @@
|
||||
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
|
||||
use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintLevelSource};
|
||||
use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
|
||||
use crate::middle::resolve_lifetime::{self, LifetimeScopeForPath};
|
||||
use crate::middle::resolve_lifetime;
|
||||
use crate::middle::stability;
|
||||
use crate::mir::interpret::{self, Allocation, ConstAllocation, ConstValue, Scalar};
|
||||
use crate::mir::{
|
||||
@ -2821,10 +2821,6 @@ pub fn late_bound_vars(self, id: HirId) -> &'tcx List<ty::BoundVariableKind> {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn lifetime_scope(self, id: HirId) -> Option<&'tcx LifetimeScopeForPath> {
|
||||
self.lifetime_scope_map(id.owner).as_ref().and_then(|map| map.get(&id.local_id))
|
||||
}
|
||||
|
||||
/// Whether the `def_id` counts as const fn in the current crate, considering all active
|
||||
/// feature gates
|
||||
pub fn is_const_fn(self, def_id: DefId) -> bool {
|
||||
|
@ -6,9 +6,7 @@
|
||||
use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
|
||||
use crate::middle::lib_features::LibFeatures;
|
||||
use crate::middle::privacy::AccessLevels;
|
||||
use crate::middle::resolve_lifetime::{
|
||||
LifetimeScopeForPath, ObjectLifetimeDefault, Region, ResolveLifetimes,
|
||||
};
|
||||
use crate::middle::resolve_lifetime::{ObjectLifetimeDefault, Region, ResolveLifetimes};
|
||||
use crate::middle::stability::{self, DeprecationEntry};
|
||||
use crate::mir;
|
||||
use crate::mir::interpret::GlobalId;
|
||||
|
@ -8,12 +8,11 @@
|
||||
|
||||
use crate::late::diagnostics::{ForLifetimeSpanType, MissingLifetimeSpot};
|
||||
use rustc_ast::walk_list;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
|
||||
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
|
||||
use rustc_errors::struct_span_err;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{DefIdMap, LocalDefId};
|
||||
use rustc_hir::hir_id::ItemLocalId;
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::{GenericArg, GenericParam, LifetimeName, Node};
|
||||
use rustc_hir::{GenericParamKind, HirIdMap};
|
||||
@ -141,9 +140,6 @@ struct NamedRegionMap {
|
||||
// - trait refs
|
||||
// - bound types (like `T` in `for<'a> T<'a>: Foo`)
|
||||
late_bound_vars: HirIdMap<Vec<ty::BoundVariableKind>>,
|
||||
|
||||
// maps `PathSegment` `HirId`s to lifetime scopes.
|
||||
scope_for_path: Option<FxHashMap<LocalDefId, FxHashMap<ItemLocalId, LifetimeScopeForPath>>>,
|
||||
}
|
||||
|
||||
pub(crate) struct LifetimeContext<'a, 'tcx> {
|
||||
@ -353,10 +349,6 @@ pub fn provide(providers: &mut ty::query::Providers) {
|
||||
_ => None,
|
||||
},
|
||||
late_bound_vars_map: |tcx, id| resolve_lifetimes_for(tcx, id).late_bound_vars.get(&id),
|
||||
lifetime_scope_map: |tcx, id| {
|
||||
let item_id = item_for(tcx, id);
|
||||
do_resolve(tcx, item_id, false, true).scope_for_path.unwrap().remove(&id)
|
||||
},
|
||||
|
||||
..*providers
|
||||
};
|
||||
@ -397,7 +389,7 @@ fn resolve_lifetimes_trait_definition(
|
||||
tcx: TyCtxt<'_>,
|
||||
local_def_id: LocalDefId,
|
||||
) -> ResolveLifetimes {
|
||||
convert_named_region_map(do_resolve(tcx, local_def_id, true, false))
|
||||
convert_named_region_map(do_resolve(tcx, local_def_id, true))
|
||||
}
|
||||
|
||||
/// Computes the `ResolveLifetimes` map that contains data for an entire `Item`.
|
||||
@ -405,21 +397,17 @@ fn resolve_lifetimes_trait_definition(
|
||||
/// `named_region_map`, `is_late_bound_map`, etc.
|
||||
#[tracing::instrument(level = "debug", skip(tcx))]
|
||||
fn resolve_lifetimes(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> ResolveLifetimes {
|
||||
convert_named_region_map(do_resolve(tcx, local_def_id, false, false))
|
||||
convert_named_region_map(do_resolve(tcx, local_def_id, false))
|
||||
}
|
||||
|
||||
fn do_resolve(
|
||||
tcx: TyCtxt<'_>,
|
||||
local_def_id: LocalDefId,
|
||||
trait_definition_only: bool,
|
||||
with_scope_for_path: bool,
|
||||
) -> NamedRegionMap {
|
||||
let item = tcx.hir().expect_item(local_def_id);
|
||||
let mut named_region_map = NamedRegionMap {
|
||||
defs: Default::default(),
|
||||
late_bound_vars: Default::default(),
|
||||
scope_for_path: with_scope_for_path.then(|| Default::default()),
|
||||
};
|
||||
let mut named_region_map =
|
||||
NamedRegionMap { defs: Default::default(), late_bound_vars: Default::default() };
|
||||
let mut visitor = LifetimeContext {
|
||||
tcx,
|
||||
map: &mut named_region_map,
|
||||
@ -515,24 +503,6 @@ fn late_region_as_bound_region<'tcx>(tcx: TyCtxt<'tcx>, region: &Region) -> ty::
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug")]
|
||||
fn get_lifetime_scopes_for_path(mut scope: &Scope<'_>) -> LifetimeScopeForPath {
|
||||
loop {
|
||||
match scope {
|
||||
Scope::Elision { elide: Elide::Exact(_), .. } => return LifetimeScopeForPath::Elided,
|
||||
Scope::Root => return LifetimeScopeForPath::NonElided,
|
||||
Scope::Binder { s, .. }
|
||||
| Scope::Body { s, .. }
|
||||
| Scope::ObjectLifetimeDefault { s, .. }
|
||||
| Scope::Supertrait { s, .. }
|
||||
| Scope::TraitRefBoundary { s, .. }
|
||||
| Scope::Elision { s, .. } => {
|
||||
scope = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||
/// Returns the binders in scope and the type of `Binder` that should be created for a poly trait ref.
|
||||
fn poly_trait_ref_binder_info(&mut self) -> (Vec<ty::BoundVariableKind>, BinderScopeType) {
|
||||
@ -1172,53 +1142,15 @@ fn visit_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime) {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_assoc_type_binding(&mut self, type_binding: &'tcx hir::TypeBinding<'_>) {
|
||||
let scope = self.scope;
|
||||
if let Some(scope_for_path) = self.map.scope_for_path.as_mut() {
|
||||
// We add lifetime scope information for `Ident`s in associated type bindings and use
|
||||
// the `HirId` of the type binding as the key in `LifetimeMap`
|
||||
let lifetime_scope = get_lifetime_scopes_for_path(scope);
|
||||
let map = scope_for_path.entry(type_binding.hir_id.owner).or_default();
|
||||
map.insert(type_binding.hir_id.local_id, lifetime_scope);
|
||||
}
|
||||
hir::intravisit::walk_assoc_type_binding(self, type_binding);
|
||||
}
|
||||
|
||||
fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, _: hir::HirId) {
|
||||
for (i, segment) in path.segments.iter().enumerate() {
|
||||
let depth = path.segments.len() - i - 1;
|
||||
if let Some(ref args) = segment.args {
|
||||
self.visit_segment_args(path.res, depth, args);
|
||||
}
|
||||
|
||||
let scope = self.scope;
|
||||
if let Some(scope_for_path) = self.map.scope_for_path.as_mut() {
|
||||
// Add lifetime scope information to path segment. Note we cannot call `visit_path_segment`
|
||||
// here because that call would yield to resolution problems due to `walk_path_segment`
|
||||
// being called, which processes the path segments generic args, which we have already
|
||||
// processed using `visit_segment_args`.
|
||||
let lifetime_scope = get_lifetime_scopes_for_path(scope);
|
||||
if let Some(hir_id) = segment.hir_id {
|
||||
let map = scope_for_path.entry(hir_id.owner).or_default();
|
||||
map.insert(hir_id.local_id, lifetime_scope);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'tcx hir::PathSegment<'tcx>) {
|
||||
let scope = self.scope;
|
||||
if let Some(scope_for_path) = self.map.scope_for_path.as_mut() {
|
||||
let lifetime_scope = get_lifetime_scopes_for_path(scope);
|
||||
if let Some(hir_id) = path_segment.hir_id {
|
||||
let map = scope_for_path.entry(hir_id.owner).or_default();
|
||||
map.insert(hir_id.local_id, lifetime_scope);
|
||||
}
|
||||
}
|
||||
|
||||
intravisit::walk_path_segment(self, path_span, path_segment);
|
||||
}
|
||||
|
||||
fn visit_fn_decl(&mut self, fd: &'tcx hir::FnDecl<'tcx>) {
|
||||
let output = match fd.output {
|
||||
hir::FnRetTy::DefaultReturn(_) => None,
|
||||
@ -2480,16 +2412,6 @@ fn resolve_elided_lifetimes(&mut self, lifetime_refs: &[&'tcx hir::Lifetime]) {
|
||||
}
|
||||
};
|
||||
|
||||
// If we specifically need the `scope_for_path` map, then we're in the
|
||||
// diagnostic pass and we don't want to emit more errors.
|
||||
if self.map.scope_for_path.is_some() {
|
||||
self.tcx.sess.delay_span_bug(
|
||||
rustc_span::DUMMY_SP,
|
||||
"Encountered unexpected errors during diagnostics related part",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let mut spans: Vec<_> = lifetime_refs.iter().map(|lt| lt.span).collect();
|
||||
spans.sort();
|
||||
let mut spans_dedup = spans.clone();
|
||||
|
@ -5,7 +5,6 @@
|
||||
};
|
||||
use rustc_hir as hir;
|
||||
use rustc_middle::hir::map::fn_sig;
|
||||
use rustc_middle::middle::resolve_lifetime::LifetimeScopeForPath;
|
||||
use rustc_middle::ty::{self as ty, AssocItems, AssocKind, TyCtxt};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::def_id::DefId;
|
||||
@ -299,13 +298,6 @@ fn get_lifetime_args_suggestions_from_param_names(
|
||||
debug!(?path_hir_id);
|
||||
|
||||
if let Some(path_hir_id) = path_hir_id {
|
||||
// We first try to get lifetime name suggestions from scope or elision information.
|
||||
// If none is available we use the parameter definitions
|
||||
if let Some(LifetimeScopeForPath::Elided) = self.tcx.lifetime_scope(path_hir_id) {
|
||||
// Use suggestions of the form `<'_, '_>` in case lifetime can be elided
|
||||
return ["'_"].repeat(num_params_to_take).join(",");
|
||||
}
|
||||
|
||||
let mut ret = Vec::new();
|
||||
for (id, node) in self.tcx.hir().parent_iter(path_hir_id) {
|
||||
debug!(?id);
|
||||
|
Loading…
Reference in New Issue
Block a user