diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2022-04-27 22:15:58 +0200 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2022-06-03 12:03:20 +0200 |
| commit | b1294e86bbbccda04da32584484bac4dc47bf0cc (patch) | |
| tree | 9ffda939269ecad790f9ac98092bdfcc1e89c0ac /src | |
| parent | 3a90bedb332d7d7eabfc1e98a1e3d96898579e1d (diff) | |
| download | rust-b1294e86bbbccda04da32584484bac4dc47bf0cc.tar.gz rust-b1294e86bbbccda04da32584484bac4dc47bf0cc.zip | |
Manipulate lifetimes by LocalDefId for region resolution.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 23 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/lifetimes.rs | 2 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/ptr.rs | 2 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_utils/src/hir_utils.rs | 8 |
4 files changed, 11 insertions, 24 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index c725cf93be2..f3070fb35f1 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -475,24 +475,14 @@ fn clean_generic_param<'tcx>( generics: Option<&hir::Generics<'tcx>>, param: &hir::GenericParam<'tcx>, ) -> GenericParamDef { + let did = cx.tcx.hir().local_def_id(param.hir_id); let (name, kind) = match param.kind { hir::GenericParamKind::Lifetime { .. } => { let outlives = if let Some(generics) = generics { generics - .predicates - .iter() - .flat_map(|pred| { - match pred { - hir::WherePredicate::RegionPredicate(rp) - if rp.lifetime.name == hir::LifetimeName::Param(param.name) - && !rp.in_where_clause => - { - rp.bounds - } - _ => &[], - } - .iter() - }) + .outlives_for_param(did) + .filter(|bp| !bp.in_where_clause) + .flat_map(|bp| bp.bounds) .map(|bound| match bound { hir::GenericBound::Outlives(lt) => lt.clean(cx), _ => panic!(), @@ -504,7 +494,6 @@ fn clean_generic_param<'tcx>( (param.name.ident().name, GenericParamDefKind::Lifetime { outlives }) } hir::GenericParamKind::Type { ref default, synthetic } => { - let did = cx.tcx.hir().local_def_id(param.hir_id); let bounds = if let Some(generics) = generics { generics .bounds_for_param(did) @@ -528,7 +517,7 @@ fn clean_generic_param<'tcx>( hir::GenericParamKind::Const { ty, default } => ( param.name.ident().name, GenericParamDefKind::Const { - did: cx.tcx.hir().local_def_id(param.hir_id).to_def_id(), + did: did.to_def_id(), ty: Box::new(ty.clean(cx)), default: default.map(|ct| { let def_id = cx.tcx.hir().local_def_id(ct.hir_id); @@ -1459,7 +1448,7 @@ impl<'tcx> Clean<'tcx, Type> for hir::Ty<'tcx> { // Turning `fn f(&'_ self)` into `fn f(&self)` isn't the worst thing in the world, though; // there's no case where it could cause the function to fail to compile. let elided = - l.is_elided() || matches!(l.name, LifetimeName::Param(ParamName::Fresh(_))); + l.is_elided() || matches!(l.name, LifetimeName::Param(_, ParamName::Fresh)); let lifetime = if elided { None } else { Some(l.clean(cx)) }; BorrowedRef { lifetime, mutability: m.mutbl, type_: box m.ty.clean(cx) } } diff --git a/src/tools/clippy/clippy_lints/src/lifetimes.rs b/src/tools/clippy/clippy_lints/src/lifetimes.rs index 51d5b510ab9..070c7e59142 100644 --- a/src/tools/clippy/clippy_lints/src/lifetimes.rs +++ b/src/tools/clippy/clippy_lints/src/lifetimes.rs @@ -371,7 +371,7 @@ impl<'a, 'tcx> RefVisitor<'a, 'tcx> { if let Some(ref lt) = *lifetime { if lt.name == LifetimeName::Static { self.lts.push(RefLt::Static); - } else if let LifetimeName::Param(ParamName::Fresh(_)) = lt.name { + } else if let LifetimeName::Param(_, ParamName::Fresh) = lt.name { // Fresh lifetimes generated should be ignored. } else if lt.is_elided() { self.lts.push(RefLt::Unnamed); diff --git a/src/tools/clippy/clippy_lints/src/ptr.rs b/src/tools/clippy/clippy_lints/src/ptr.rs index 548f7b2528b..0b96f6ff683 100644 --- a/src/tools/clippy/clippy_lints/src/ptr.rs +++ b/src/tools/clippy/clippy_lints/src/ptr.rs @@ -343,7 +343,7 @@ impl fmt::Display for RefPrefix { use fmt::Write; f.write_char('&')?; match self.lt { - LifetimeName::Param(ParamName::Plain(name)) => { + LifetimeName::Param(_, ParamName::Plain(name)) => { name.fmt(f)?; f.write_char(' ')?; }, diff --git a/src/tools/clippy/clippy_utils/src/hir_utils.rs b/src/tools/clippy/clippy_utils/src/hir_utils.rs index c440793b90e..fc1a4e1f602 100644 --- a/src/tools/clippy/clippy_utils/src/hir_utils.rs +++ b/src/tools/clippy/clippy_utils/src/hir_utils.rs @@ -902,16 +902,14 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { pub fn hash_lifetime(&mut self, lifetime: Lifetime) { std::mem::discriminant(&lifetime.name).hash(&mut self.s); - if let LifetimeName::Param(ref name) = lifetime.name { + if let LifetimeName::Param(param_id, ref name) = lifetime.name { std::mem::discriminant(name).hash(&mut self.s); + param_id.hash(&mut self.s); match name { ParamName::Plain(ref ident) => { ident.name.hash(&mut self.s); }, - ParamName::Fresh(ref size) => { - size.hash(&mut self.s); - }, - ParamName::Error => {}, + ParamName::Fresh | ParamName::Error => {}, } } } |
