Skip to content

Commit af8739b

Browse files
committed
Completely remove LifetimeScopeForPath.
1 parent a072900 commit af8739b

File tree

6 files changed

+7
-117
lines changed

6 files changed

+7
-117
lines changed

compiler/rustc_middle/src/middle/resolve_lifetime.rs

-13
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,6 @@ pub enum Region {
1616
Free(DefId, /* lifetime decl */ DefId),
1717
}
1818

19-
/// This is used in diagnostics to improve suggestions for missing generic arguments.
20-
/// It gives information on the type of lifetimes that are in scope for a particular `PathSegment`,
21-
/// so that we can e.g. suggest elided-lifetimes-in-paths of the form <'_, '_> e.g.
22-
#[derive(Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, HashStable)]
23-
pub enum LifetimeScopeForPath {
24-
/// Contains all lifetime names that are in scope and could possibly be used in generics
25-
/// arguments of path.
26-
NonElided,
27-
/// Information that allows us to suggest args of the form `<'_>` in case
28-
/// no generic arguments were provided for a path.
29-
Elided,
30-
}
31-
3219
/// A set containing, at most, one known element.
3320
/// If two distinct values are inserted into a set, then it
3421
/// becomes `Many`, which can be used to detect ambiguities.

compiler/rustc_middle/src/query/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1599,11 +1599,6 @@ rustc_queries! {
15991599
desc { "looking up late bound vars" }
16001600
}
16011601

1602-
query lifetime_scope_map(_: LocalDefId) -> Option<FxHashMap<ItemLocalId, LifetimeScopeForPath>> {
1603-
storage(ArenaCacheSelector<'tcx>)
1604-
desc { "finds the lifetime scope for an HirId of a PathSegment" }
1605-
}
1606-
16071602
query visibility(def_id: DefId) -> ty::Visibility {
16081603
desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
16091604
separate_provide_extern

compiler/rustc_middle/src/ty/context.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::hir::place::Place as HirPlace;
66
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
77
use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintLevelSource};
88
use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
9-
use crate::middle::resolve_lifetime::{self, LifetimeScopeForPath};
9+
use crate::middle::resolve_lifetime;
1010
use crate::middle::stability;
1111
use crate::mir::interpret::{self, Allocation, ConstAllocation, ConstValue, Scalar};
1212
use crate::mir::{
@@ -2821,10 +2821,6 @@ impl<'tcx> TyCtxt<'tcx> {
28212821
)
28222822
}
28232823

2824-
pub fn lifetime_scope(self, id: HirId) -> Option<&'tcx LifetimeScopeForPath> {
2825-
self.lifetime_scope_map(id.owner).as_ref().and_then(|map| map.get(&id.local_id))
2826-
}
2827-
28282824
/// Whether the `def_id` counts as const fn in the current crate, considering all active
28292825
/// feature gates
28302826
pub fn is_const_fn(self, def_id: DefId) -> bool {

compiler/rustc_middle/src/ty/query.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
66
use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
77
use crate::middle::lib_features::LibFeatures;
88
use crate::middle::privacy::AccessLevels;
9-
use crate::middle::resolve_lifetime::{
10-
LifetimeScopeForPath, ObjectLifetimeDefault, Region, ResolveLifetimes,
11-
};
9+
use crate::middle::resolve_lifetime::{ObjectLifetimeDefault, Region, ResolveLifetimes};
1210
use crate::middle::stability::{self, DeprecationEntry};
1311
use crate::mir;
1412
use crate::mir::interpret::GlobalId;

compiler/rustc_resolve/src/late/lifetimes.rs

+5-83
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
99
use crate::late::diagnostics::{ForLifetimeSpanType, MissingLifetimeSpot};
1010
use rustc_ast::walk_list;
11-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
11+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
1212
use rustc_errors::struct_span_err;
1313
use rustc_hir as hir;
1414
use rustc_hir::def::{DefKind, Res};
1515
use rustc_hir::def_id::{DefIdMap, LocalDefId};
16-
use rustc_hir::hir_id::ItemLocalId;
1716
use rustc_hir::intravisit::{self, Visitor};
1817
use rustc_hir::{GenericArg, GenericParam, LifetimeName, Node};
1918
use rustc_hir::{GenericParamKind, HirIdMap};
@@ -141,9 +140,6 @@ struct NamedRegionMap {
141140
// - trait refs
142141
// - bound types (like `T` in `for<'a> T<'a>: Foo`)
143142
late_bound_vars: HirIdMap<Vec<ty::BoundVariableKind>>,
144-
145-
// maps `PathSegment` `HirId`s to lifetime scopes.
146-
scope_for_path: Option<FxHashMap<LocalDefId, FxHashMap<ItemLocalId, LifetimeScopeForPath>>>,
147143
}
148144

149145
pub(crate) struct LifetimeContext<'a, 'tcx> {
@@ -353,10 +349,6 @@ pub fn provide(providers: &mut ty::query::Providers) {
353349
_ => None,
354350
},
355351
late_bound_vars_map: |tcx, id| resolve_lifetimes_for(tcx, id).late_bound_vars.get(&id),
356-
lifetime_scope_map: |tcx, id| {
357-
let item_id = item_for(tcx, id);
358-
do_resolve(tcx, item_id, false, true).scope_for_path.unwrap().remove(&id)
359-
},
360352

361353
..*providers
362354
};
@@ -397,29 +389,25 @@ fn resolve_lifetimes_trait_definition(
397389
tcx: TyCtxt<'_>,
398390
local_def_id: LocalDefId,
399391
) -> ResolveLifetimes {
400-
convert_named_region_map(do_resolve(tcx, local_def_id, true, false))
392+
convert_named_region_map(do_resolve(tcx, local_def_id, true))
401393
}
402394

403395
/// Computes the `ResolveLifetimes` map that contains data for an entire `Item`.
404396
/// You should not read the result of this query directly, but rather use
405397
/// `named_region_map`, `is_late_bound_map`, etc.
406398
#[tracing::instrument(level = "debug", skip(tcx))]
407399
fn resolve_lifetimes(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> ResolveLifetimes {
408-
convert_named_region_map(do_resolve(tcx, local_def_id, false, false))
400+
convert_named_region_map(do_resolve(tcx, local_def_id, false))
409401
}
410402

411403
fn do_resolve(
412404
tcx: TyCtxt<'_>,
413405
local_def_id: LocalDefId,
414406
trait_definition_only: bool,
415-
with_scope_for_path: bool,
416407
) -> NamedRegionMap {
417408
let item = tcx.hir().expect_item(local_def_id);
418-
let mut named_region_map = NamedRegionMap {
419-
defs: Default::default(),
420-
late_bound_vars: Default::default(),
421-
scope_for_path: with_scope_for_path.then(|| Default::default()),
422-
};
409+
let mut named_region_map =
410+
NamedRegionMap { defs: Default::default(), late_bound_vars: Default::default() };
423411
let mut visitor = LifetimeContext {
424412
tcx,
425413
map: &mut named_region_map,
@@ -515,24 +503,6 @@ fn late_region_as_bound_region<'tcx>(tcx: TyCtxt<'tcx>, region: &Region) -> ty::
515503
}
516504
}
517505

518-
#[tracing::instrument(level = "debug")]
519-
fn get_lifetime_scopes_for_path(mut scope: &Scope<'_>) -> LifetimeScopeForPath {
520-
loop {
521-
match scope {
522-
Scope::Elision { elide: Elide::Exact(_), .. } => return LifetimeScopeForPath::Elided,
523-
Scope::Root => return LifetimeScopeForPath::NonElided,
524-
Scope::Binder { s, .. }
525-
| Scope::Body { s, .. }
526-
| Scope::ObjectLifetimeDefault { s, .. }
527-
| Scope::Supertrait { s, .. }
528-
| Scope::TraitRefBoundary { s, .. }
529-
| Scope::Elision { s, .. } => {
530-
scope = s;
531-
}
532-
}
533-
}
534-
}
535-
536506
impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
537507
/// Returns the binders in scope and the type of `Binder` that should be created for a poly trait ref.
538508
fn poly_trait_ref_binder_info(&mut self) -> (Vec<ty::BoundVariableKind>, BinderScopeType) {
@@ -1172,51 +1142,13 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
11721142
}
11731143
}
11741144

1175-
fn visit_assoc_type_binding(&mut self, type_binding: &'tcx hir::TypeBinding<'_>) {
1176-
let scope = self.scope;
1177-
if let Some(scope_for_path) = self.map.scope_for_path.as_mut() {
1178-
// We add lifetime scope information for `Ident`s in associated type bindings and use
1179-
// the `HirId` of the type binding as the key in `LifetimeMap`
1180-
let lifetime_scope = get_lifetime_scopes_for_path(scope);
1181-
let map = scope_for_path.entry(type_binding.hir_id.owner).or_default();
1182-
map.insert(type_binding.hir_id.local_id, lifetime_scope);
1183-
}
1184-
hir::intravisit::walk_assoc_type_binding(self, type_binding);
1185-
}
1186-
11871145
fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, _: hir::HirId) {
11881146
for (i, segment) in path.segments.iter().enumerate() {
11891147
let depth = path.segments.len() - i - 1;
11901148
if let Some(ref args) = segment.args {
11911149
self.visit_segment_args(path.res, depth, args);
11921150
}
1193-
1194-
let scope = self.scope;
1195-
if let Some(scope_for_path) = self.map.scope_for_path.as_mut() {
1196-
// Add lifetime scope information to path segment. Note we cannot call `visit_path_segment`
1197-
// here because that call would yield to resolution problems due to `walk_path_segment`
1198-
// being called, which processes the path segments generic args, which we have already
1199-
// processed using `visit_segment_args`.
1200-
let lifetime_scope = get_lifetime_scopes_for_path(scope);
1201-
if let Some(hir_id) = segment.hir_id {
1202-
let map = scope_for_path.entry(hir_id.owner).or_default();
1203-
map.insert(hir_id.local_id, lifetime_scope);
1204-
}
1205-
}
1206-
}
1207-
}
1208-
1209-
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'tcx hir::PathSegment<'tcx>) {
1210-
let scope = self.scope;
1211-
if let Some(scope_for_path) = self.map.scope_for_path.as_mut() {
1212-
let lifetime_scope = get_lifetime_scopes_for_path(scope);
1213-
if let Some(hir_id) = path_segment.hir_id {
1214-
let map = scope_for_path.entry(hir_id.owner).or_default();
1215-
map.insert(hir_id.local_id, lifetime_scope);
1216-
}
12171151
}
1218-
1219-
intravisit::walk_path_segment(self, path_span, path_segment);
12201152
}
12211153

12221154
fn visit_fn_decl(&mut self, fd: &'tcx hir::FnDecl<'tcx>) {
@@ -2480,16 +2412,6 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
24802412
}
24812413
};
24822414

2483-
// If we specifically need the `scope_for_path` map, then we're in the
2484-
// diagnostic pass and we don't want to emit more errors.
2485-
if self.map.scope_for_path.is_some() {
2486-
self.tcx.sess.delay_span_bug(
2487-
rustc_span::DUMMY_SP,
2488-
"Encountered unexpected errors during diagnostics related part",
2489-
);
2490-
return;
2491-
}
2492-
24932415
let mut spans: Vec<_> = lifetime_refs.iter().map(|lt| lt.span).collect();
24942416
spans.sort();
24952417
let mut spans_dedup = spans.clone();

compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs

-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc_errors::{
55
};
66
use rustc_hir as hir;
77
use rustc_middle::hir::map::fn_sig;
8-
use rustc_middle::middle::resolve_lifetime::LifetimeScopeForPath;
98
use rustc_middle::ty::{self as ty, AssocItems, AssocKind, TyCtxt};
109
use rustc_session::Session;
1110
use rustc_span::def_id::DefId;
@@ -299,13 +298,6 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
299298
debug!(?path_hir_id);
300299

301300
if let Some(path_hir_id) = path_hir_id {
302-
// We first try to get lifetime name suggestions from scope or elision information.
303-
// If none is available we use the parameter definitions
304-
if let Some(LifetimeScopeForPath::Elided) = self.tcx.lifetime_scope(path_hir_id) {
305-
// Use suggestions of the form `<'_, '_>` in case lifetime can be elided
306-
return ["'_"].repeat(num_params_to_take).join(",");
307-
}
308-
309301
let mut ret = Vec::new();
310302
for (id, node) in self.tcx.hir().parent_iter(path_hir_id) {
311303
debug!(?id);

0 commit comments

Comments
 (0)