|
8 | 8 |
|
9 | 9 | use crate::late::diagnostics::{ForLifetimeSpanType, MissingLifetimeSpot}; |
10 | 10 | use rustc_ast::walk_list; |
11 | | -use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet}; |
| 11 | +use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; |
12 | 12 | use rustc_errors::struct_span_err; |
13 | 13 | use rustc_hir as hir; |
14 | 14 | use rustc_hir::def::{DefKind, Res}; |
15 | 15 | use rustc_hir::def_id::{DefIdMap, LocalDefId}; |
16 | | -use rustc_hir::hir_id::ItemLocalId; |
17 | 16 | use rustc_hir::intravisit::{self, Visitor}; |
18 | 17 | use rustc_hir::{GenericArg, GenericParam, LifetimeName, Node}; |
19 | 18 | use rustc_hir::{GenericParamKind, HirIdMap}; |
@@ -141,9 +140,6 @@ struct NamedRegionMap { |
141 | 140 | // - trait refs |
142 | 141 | // - bound types (like `T` in `for<'a> T<'a>: Foo`) |
143 | 142 | 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>>>, |
147 | 143 | } |
148 | 144 |
|
149 | 145 | pub(crate) struct LifetimeContext<'a, 'tcx> { |
@@ -353,10 +349,6 @@ pub fn provide(providers: &mut ty::query::Providers) { |
353 | 349 | _ => None, |
354 | 350 | }, |
355 | 351 | 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 | | - }, |
360 | 352 |
|
361 | 353 | ..*providers |
362 | 354 | }; |
@@ -397,29 +389,25 @@ fn resolve_lifetimes_trait_definition( |
397 | 389 | tcx: TyCtxt<'_>, |
398 | 390 | local_def_id: LocalDefId, |
399 | 391 | ) -> 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)) |
401 | 393 | } |
402 | 394 |
|
403 | 395 | /// Computes the `ResolveLifetimes` map that contains data for an entire `Item`. |
404 | 396 | /// You should not read the result of this query directly, but rather use |
405 | 397 | /// `named_region_map`, `is_late_bound_map`, etc. |
406 | 398 | #[tracing::instrument(level = "debug", skip(tcx))] |
407 | 399 | 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)) |
409 | 401 | } |
410 | 402 |
|
411 | 403 | fn do_resolve( |
412 | 404 | tcx: TyCtxt<'_>, |
413 | 405 | local_def_id: LocalDefId, |
414 | 406 | trait_definition_only: bool, |
415 | | - with_scope_for_path: bool, |
416 | 407 | ) -> NamedRegionMap { |
417 | 408 | 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() }; |
423 | 411 | let mut visitor = LifetimeContext { |
424 | 412 | tcx, |
425 | 413 | map: &mut named_region_map, |
@@ -515,24 +503,6 @@ fn late_region_as_bound_region<'tcx>(tcx: TyCtxt<'tcx>, region: &Region) -> ty:: |
515 | 503 | } |
516 | 504 | } |
517 | 505 |
|
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 | | - |
536 | 506 | impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { |
537 | 507 | /// Returns the binders in scope and the type of `Binder` that should be created for a poly trait ref. |
538 | 508 | 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> { |
1172 | 1142 | } |
1173 | 1143 | } |
1174 | 1144 |
|
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 | | - |
1187 | 1145 | fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, _: hir::HirId) { |
1188 | 1146 | for (i, segment) in path.segments.iter().enumerate() { |
1189 | 1147 | let depth = path.segments.len() - i - 1; |
1190 | 1148 | if let Some(ref args) = segment.args { |
1191 | 1149 | self.visit_segment_args(path.res, depth, args); |
1192 | 1150 | } |
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 | | - } |
1217 | 1151 | } |
1218 | | - |
1219 | | - intravisit::walk_path_segment(self, path_span, path_segment); |
1220 | 1152 | } |
1221 | 1153 |
|
1222 | 1154 | fn visit_fn_decl(&mut self, fd: &'tcx hir::FnDecl<'tcx>) { |
@@ -2480,16 +2412,6 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { |
2480 | 2412 | } |
2481 | 2413 | }; |
2482 | 2414 |
|
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 | | - |
2493 | 2415 | let mut spans: Vec<_> = lifetime_refs.iter().map(|lt| lt.span).collect(); |
2494 | 2416 | spans.sort(); |
2495 | 2417 | let mut spans_dedup = spans.clone(); |
|
0 commit comments