|
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> { |
@@ -362,10 +358,6 @@ pub fn provide(providers: &mut ty::query::Providers) { |
362 | 358 | _ => None, |
363 | 359 | }, |
364 | 360 | late_bound_vars_map: |tcx, id| resolve_lifetimes_for(tcx, id).late_bound_vars.get(&id), |
365 | | - lifetime_scope_map: |tcx, id| { |
366 | | - let item_id = item_for(tcx, id); |
367 | | - do_resolve(tcx, item_id, false, true).scope_for_path.unwrap().remove(&id) |
368 | | - }, |
369 | 361 |
|
370 | 362 | ..*providers |
371 | 363 | }; |
@@ -406,29 +398,25 @@ fn resolve_lifetimes_trait_definition( |
406 | 398 | tcx: TyCtxt<'_>, |
407 | 399 | local_def_id: LocalDefId, |
408 | 400 | ) -> ResolveLifetimes { |
409 | | - convert_named_region_map(do_resolve(tcx, local_def_id, true, false)) |
| 401 | + convert_named_region_map(do_resolve(tcx, local_def_id, true)) |
410 | 402 | } |
411 | 403 |
|
412 | 404 | /// Computes the `ResolveLifetimes` map that contains data for an entire `Item`. |
413 | 405 | /// You should not read the result of this query directly, but rather use |
414 | 406 | /// `named_region_map`, `is_late_bound_map`, etc. |
415 | 407 | #[tracing::instrument(level = "debug", skip(tcx))] |
416 | 408 | fn resolve_lifetimes(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> ResolveLifetimes { |
417 | | - convert_named_region_map(do_resolve(tcx, local_def_id, false, false)) |
| 409 | + convert_named_region_map(do_resolve(tcx, local_def_id, false)) |
418 | 410 | } |
419 | 411 |
|
420 | 412 | fn do_resolve( |
421 | 413 | tcx: TyCtxt<'_>, |
422 | 414 | local_def_id: LocalDefId, |
423 | 415 | trait_definition_only: bool, |
424 | | - with_scope_for_path: bool, |
425 | 416 | ) -> NamedRegionMap { |
426 | 417 | let item = tcx.hir().expect_item(local_def_id); |
427 | | - let mut named_region_map = NamedRegionMap { |
428 | | - defs: Default::default(), |
429 | | - late_bound_vars: Default::default(), |
430 | | - scope_for_path: with_scope_for_path.then(|| Default::default()), |
431 | | - }; |
| 418 | + let mut named_region_map = |
| 419 | + NamedRegionMap { defs: Default::default(), late_bound_vars: Default::default() }; |
432 | 420 | let mut visitor = LifetimeContext { |
433 | 421 | tcx, |
434 | 422 | map: &mut named_region_map, |
@@ -524,38 +512,6 @@ fn late_region_as_bound_region<'tcx>(tcx: TyCtxt<'tcx>, region: &Region) -> ty:: |
524 | 512 | } |
525 | 513 | } |
526 | 514 |
|
527 | | -#[tracing::instrument(level = "debug")] |
528 | | -fn get_lifetime_scopes_for_path(mut scope: &Scope<'_>) -> LifetimeScopeForPath { |
529 | | - let mut available_lifetimes = vec![]; |
530 | | - loop { |
531 | | - match scope { |
532 | | - Scope::Binder { lifetimes, s, .. } => { |
533 | | - available_lifetimes.extend(lifetimes.keys()); |
534 | | - scope = s; |
535 | | - } |
536 | | - Scope::Body { s, .. } => { |
537 | | - scope = s; |
538 | | - } |
539 | | - Scope::Elision { elide, s } => { |
540 | | - if let Elide::Exact(_) = elide { |
541 | | - return LifetimeScopeForPath::Elided; |
542 | | - } else { |
543 | | - scope = s; |
544 | | - } |
545 | | - } |
546 | | - Scope::ObjectLifetimeDefault { s, .. } => { |
547 | | - scope = s; |
548 | | - } |
549 | | - Scope::Root => { |
550 | | - return LifetimeScopeForPath::NonElided(available_lifetimes); |
551 | | - } |
552 | | - Scope::Supertrait { s, .. } | Scope::TraitRefBoundary { s, .. } => { |
553 | | - scope = s; |
554 | | - } |
555 | | - } |
556 | | - } |
557 | | -} |
558 | | - |
559 | 515 | impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { |
560 | 516 | /// Returns the binders in scope and the type of `Binder` that should be created for a poly trait ref. |
561 | 517 | fn poly_trait_ref_binder_info(&mut self) -> (Vec<ty::BoundVariableKind>, BinderScopeType) { |
@@ -1202,53 +1158,15 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { |
1202 | 1158 | } |
1203 | 1159 | } |
1204 | 1160 |
|
1205 | | - fn visit_assoc_type_binding(&mut self, type_binding: &'tcx hir::TypeBinding<'_>) { |
1206 | | - let scope = self.scope; |
1207 | | - if let Some(scope_for_path) = self.map.scope_for_path.as_mut() { |
1208 | | - // We add lifetime scope information for `Ident`s in associated type bindings and use |
1209 | | - // the `HirId` of the type binding as the key in `LifetimeMap` |
1210 | | - let lifetime_scope = get_lifetime_scopes_for_path(scope); |
1211 | | - let map = scope_for_path.entry(type_binding.hir_id.owner).or_default(); |
1212 | | - map.insert(type_binding.hir_id.local_id, lifetime_scope); |
1213 | | - } |
1214 | | - hir::intravisit::walk_assoc_type_binding(self, type_binding); |
1215 | | - } |
1216 | | - |
1217 | 1161 | fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, _: hir::HirId) { |
1218 | 1162 | for (i, segment) in path.segments.iter().enumerate() { |
1219 | 1163 | let depth = path.segments.len() - i - 1; |
1220 | 1164 | if let Some(ref args) = segment.args { |
1221 | 1165 | self.visit_segment_args(path.res, depth, args); |
1222 | 1166 | } |
1223 | | - |
1224 | | - let scope = self.scope; |
1225 | | - if let Some(scope_for_path) = self.map.scope_for_path.as_mut() { |
1226 | | - // Add lifetime scope information to path segment. Note we cannot call `visit_path_segment` |
1227 | | - // here because that call would yield to resolution problems due to `walk_path_segment` |
1228 | | - // being called, which processes the path segments generic args, which we have already |
1229 | | - // processed using `visit_segment_args`. |
1230 | | - let lifetime_scope = get_lifetime_scopes_for_path(scope); |
1231 | | - if let Some(hir_id) = segment.hir_id { |
1232 | | - let map = scope_for_path.entry(hir_id.owner).or_default(); |
1233 | | - map.insert(hir_id.local_id, lifetime_scope); |
1234 | | - } |
1235 | | - } |
1236 | 1167 | } |
1237 | 1168 | } |
1238 | 1169 |
|
1239 | | - fn visit_path_segment(&mut self, path_span: Span, path_segment: &'tcx hir::PathSegment<'tcx>) { |
1240 | | - let scope = self.scope; |
1241 | | - if let Some(scope_for_path) = self.map.scope_for_path.as_mut() { |
1242 | | - let lifetime_scope = get_lifetime_scopes_for_path(scope); |
1243 | | - if let Some(hir_id) = path_segment.hir_id { |
1244 | | - let map = scope_for_path.entry(hir_id.owner).or_default(); |
1245 | | - map.insert(hir_id.local_id, lifetime_scope); |
1246 | | - } |
1247 | | - } |
1248 | | - |
1249 | | - intravisit::walk_path_segment(self, path_span, path_segment); |
1250 | | - } |
1251 | | - |
1252 | 1170 | fn visit_fn_decl(&mut self, fd: &'tcx hir::FnDecl<'tcx>) { |
1253 | 1171 | let output = match fd.output { |
1254 | 1172 | hir::FnRetTy::DefaultReturn(_) => None, |
@@ -2227,6 +2145,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { |
2227 | 2145 |
|
2228 | 2146 | // Foreign functions, `fn(...) -> R` and `Trait(...) -> R` (both types and bounds). |
2229 | 2147 | Node::ForeignItem(_) | Node::Ty(_) | Node::TraitRef(_) => None, |
| 2148 | + |
| 2149 | + Node::TypeBinding(_) if let Node::TraitRef(_) = self.tcx.hir().get(self.tcx.hir().get_parent_node(parent)) => None, |
| 2150 | + |
2230 | 2151 | // Everything else (only closures?) doesn't |
2231 | 2152 | // actually enjoy elision in return types. |
2232 | 2153 | _ => { |
@@ -2548,16 +2469,6 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { |
2548 | 2469 | } |
2549 | 2470 | }; |
2550 | 2471 |
|
2551 | | - // If we specifically need the `scope_for_path` map, then we're in the |
2552 | | - // diagnostic pass and we don't want to emit more errors. |
2553 | | - if self.map.scope_for_path.is_some() { |
2554 | | - self.tcx.sess.delay_span_bug( |
2555 | | - rustc_span::DUMMY_SP, |
2556 | | - "Encountered unexpected errors during diagnostics related part", |
2557 | | - ); |
2558 | | - return; |
2559 | | - } |
2560 | | - |
2561 | 2472 | let mut spans: Vec<_> = lifetime_refs.iter().map(|lt| lt.span).collect(); |
2562 | 2473 | spans.sort(); |
2563 | 2474 | let mut spans_dedup = spans.clone(); |
|
0 commit comments