Skip to content

Commit c4d51f3

Browse files
Rollup merge of rust-lang#156960 - oli-obk:push-rrmqnqvwtmsq, r=tiif
Some cleanups around passing extra lifetime params from the resolver to ast lowering No functional changes, mostly removing information that was never used at any step. Possibly interesting to @petrochenkov and @cjgillot I originally thought this was a necessary cleanup to be able to refactor our `extra_lifetime_params_map` handling, but it turns out that I can also just do rust-lang#156508 which removes all the ugly usage of that side table and makes it possible for that side table to be put into `PerOwnerResolverData`. The changes here still were an improvement on its own, thus this PR.
2 parents a9526f3 + 19a5af7 commit c4d51f3

7 files changed

Lines changed: 86 additions & 132 deletions

File tree

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,11 +1928,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
19281928

19291929
// Introduce extra lifetimes if late resolution tells us to.
19301930
let extra_lifetimes = self.resolver.extra_lifetime_params(parent_node_id);
1931-
params.extend(extra_lifetimes.into_iter().filter_map(|&(ident, node_id, res)| {
1931+
params.extend(extra_lifetimes.into_iter().map(|&(ident, node_id, kind)| {
19321932
self.lifetime_res_to_generic_param(
19331933
ident,
19341934
node_id,
1935-
res,
1935+
kind,
19361936
hir::GenericParamSource::Generics,
19371937
)
19381938
}));

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use rustc_hir::definitions::PerParentDisambiguatorState;
5555
use rustc_hir::lints::DelayedLint;
5656
use rustc_hir::{
5757
self as hir, AngleBrackets, ConstArg, GenericArg, HirId, ItemLocalMap, LifetimeSource,
58-
LifetimeSyntax, ParamName, Target, TraitCandidate, find_attr,
58+
LifetimeSyntax, MissingLifetimeKind, ParamName, Target, TraitCandidate, find_attr,
5959
};
6060
use rustc_index::{Idx, IndexSlice, IndexVec};
6161
use rustc_macros::extension;
@@ -310,7 +310,7 @@ impl<'tcx> ResolverAstLowering<'tcx> {
310310
///
311311
/// The extra lifetimes that appear from the parenthesized `Fn`-trait desugaring
312312
/// should appear at the enclosing `PolyTraitRef`.
313-
fn extra_lifetime_params(&self, id: NodeId) -> &[(Ident, NodeId, LifetimeRes)] {
313+
fn extra_lifetime_params(&self, id: NodeId) -> &[(Ident, NodeId, MissingLifetimeKind)] {
314314
self.extra_lifetime_params_map.get(&id).map_or(&[], |v| &v[..])
315315
}
316316

@@ -948,43 +948,30 @@ impl<'hir> LoweringContext<'_, 'hir> {
948948
&mut self,
949949
ident: Ident,
950950
node_id: NodeId,
951-
res: LifetimeRes,
951+
kind: MissingLifetimeKind,
952952
source: hir::GenericParamSource,
953-
) -> Option<hir::GenericParam<'hir>> {
954-
let (name, kind) = match res {
955-
LifetimeRes::Param { .. } => {
956-
(hir::ParamName::Plain(ident), hir::LifetimeParamKind::Explicit)
957-
}
958-
LifetimeRes::Fresh { param, kind, .. } => {
959-
// Late resolution delegates to us the creation of the `LocalDefId`.
960-
let _def_id = self.create_def(
961-
param,
962-
Some(kw::UnderscoreLifetime),
963-
DefKind::LifetimeParam,
964-
ident.span,
965-
);
966-
debug!(?_def_id);
953+
) -> hir::GenericParam<'hir> {
954+
// Late resolution delegates to us the creation of the `LocalDefId`.
955+
let _def_id = self.create_def(
956+
node_id,
957+
Some(kw::UnderscoreLifetime),
958+
DefKind::LifetimeParam,
959+
ident.span,
960+
);
961+
debug!(?_def_id);
967962

968-
(hir::ParamName::Fresh, hir::LifetimeParamKind::Elided(kind))
969-
}
970-
LifetimeRes::Static { .. } | LifetimeRes::Error(..) => return None,
971-
res => panic!(
972-
"Unexpected lifetime resolution {:?} for {:?} at {:?}",
973-
res, ident, ident.span
974-
),
975-
};
976963
let hir_id = self.lower_node_id(node_id);
977964
let def_id = self.local_def_id(node_id);
978-
Some(hir::GenericParam {
965+
hir::GenericParam {
979966
hir_id,
980967
def_id,
981-
name,
968+
name: hir::ParamName::Fresh,
982969
span: self.lower_span(ident.span),
983970
pure_wrt_drop: false,
984-
kind: hir::GenericParamKind::Lifetime { kind },
971+
kind: hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Elided(kind) },
985972
colon_span: None,
986973
source,
987-
})
974+
}
988975
}
989976

990977
/// Lowers a lifetime binder that defines `generic_params`, returning the corresponding HIR
@@ -1005,7 +992,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1005992
debug!(?extra_lifetimes);
1006993
let extra_lifetimes: Vec<_> = extra_lifetimes
1007994
.iter()
1008-
.filter_map(|&(ident, node_id, res)| {
995+
.map(|&(ident, node_id, res)| {
1009996
self.lifetime_res_to_generic_param(
1010997
ident,
1011998
node_id,

compiler/rustc_hir/src/def.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,8 +991,6 @@ pub enum LifetimeRes {
991991
///
992992
/// Creating the associated `LocalDefId` is the responsibility of lowering.
993993
param: NodeId,
994-
/// Id of the introducing place. See `Param`.
995-
binder: NodeId,
996994
/// Kind of elided lifetime
997995
kind: hir::MissingLifetimeKind,
998996
},

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,11 @@ use rustc_data_structures::stable_hash::{StableHash, StableHashCtxt, StableHashe
3737
use rustc_data_structures::steal::Steal;
3838
use rustc_data_structures::unord::{UnordMap, UnordSet};
3939
use rustc_errors::{Diag, ErrorGuaranteed, LintBuffer};
40-
use rustc_hir as hir;
4140
use rustc_hir::attrs::StrippedCfgItem;
4241
use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res};
4342
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap};
4443
use rustc_hir::definitions::PerParentDisambiguatorState;
45-
use rustc_hir::{LangItem, attrs as attr, find_attr};
44+
use rustc_hir::{self as hir, LangItem, MissingLifetimeKind, attrs as attr, find_attr};
4645
use rustc_index::IndexVec;
4746
use rustc_index::bit_set::BitMatrix;
4847
use rustc_macros::{
@@ -232,7 +231,7 @@ pub struct ResolverAstLowering<'tcx> {
232231
/// Resolutions for lifetimes.
233232
pub lifetimes_res_map: NodeMap<LifetimeRes>,
234233
/// Lifetime parameters that lowering will have to introduce.
235-
pub extra_lifetime_params_map: NodeMap<Vec<(Ident, ast::NodeId, LifetimeRes)>>,
234+
pub extra_lifetime_params_map: NodeMap<Vec<(Ident, ast::NodeId, MissingLifetimeKind)>>,
236235

237236
pub next_node_id: ast::NodeId,
238237

0 commit comments

Comments
 (0)