diff options
author | Alona Enraght-Moony <code@alona.page> | 2024-07-03 19:57:15 +0000 |
---|---|---|
committer | Alona Enraght-Moony <code@alona.page> | 2024-07-03 20:00:56 +0000 |
commit | 7e8aac553e756b0eb03fe98e1a65ffc47836ec51 (patch) | |
tree | 074fd4ae0a4fb8eea22d2c6f006fcba916d319e3 /src | |
parent | c872a1418a4be3ea84a8d5232238b60d35339ba9 (diff) |
rustdoc-json: Better representation of lifetime bounds in where clauses.
As suggested [on zulip][1], there's no need to use `GenericBound` here,
as the only bound a lifetime can have is that it outlives other
lifetimes.
While we're making breaking changes here, I also renamed it from using
"region" to "lifetime", as this is more user-aligned. See [this
comment][2] for details.
[1]: https://rust-lang.zulipchat.com/#narrow/stream/266220-t-rustdoc/topic/.60ItemEnum.3A.3AOpaqueTy.60/near/448871430
[2]: https://github.com/rust-lang/rust/issues/100961#issuecomment-2206565556
Diffstat (limited to 'src')
-rw-r--r-- | src/librustdoc/clean/types.rs | 2 | ||||
-rw-r--r-- | src/librustdoc/json/conversions.rs | 11 | ||||
-rw-r--r-- | src/rustdoc-json-types/lib.rs | 6 | ||||
-rw-r--r-- | src/tools/jsondoclint/src/validator.rs | 4 |
4 files changed, 15 insertions, 8 deletions
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 9050a1c1207..6aa3da2719a 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1286,7 +1286,7 @@ impl GenericBound { } } -#[derive(Clone, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] pub(crate) struct Lifetime(pub Symbol); impl Lifetime { diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index b965ab019cc..5111e363c52 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -10,6 +10,7 @@ use rustc_ast::ast; use rustc_attr::DeprecatedSince; use rustc_hir::{def::CtorKind, def::DefKind, def_id::DefId}; use rustc_metadata::rendered_const; +use rustc_middle::bug; use rustc_middle::ty::{self, TyCtxt}; use rustc_span::symbol::sym; use rustc_span::{Pos, Symbol}; @@ -512,9 +513,15 @@ impl FromWithTcx<clean::WherePredicate> for WherePredicate { }) .collect(), }, - RegionPredicate { lifetime, bounds } => WherePredicate::RegionPredicate { + RegionPredicate { lifetime, bounds } => WherePredicate::LifetimePredicate { lifetime: convert_lifetime(lifetime), - bounds: bounds.into_tcx(tcx), + outlives: bounds + .iter() + .map(|bound| match bound { + clean::GenericBound::Outlives(lt) => convert_lifetime(*lt), + _ => bug!("found non-outlives-bound on lifetime predicate"), + }) + .collect(), }, EqPredicate { lhs, rhs } => { WherePredicate::EqPredicate { lhs: lhs.into_tcx(tcx), rhs: rhs.into_tcx(tcx) } diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 68030493e9c..89115d4d7d6 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use std::path::PathBuf; /// rustdoc format-version. -pub const FORMAT_VERSION: u32 = 30; +pub const FORMAT_VERSION: u32 = 31; /// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information /// about the language items in the local crate, as well as info about external items to allow @@ -511,9 +511,9 @@ pub enum WherePredicate { /// ``` generic_params: Vec<GenericParamDef>, }, - RegionPredicate { + LifetimePredicate { lifetime: String, - bounds: Vec<GenericBound>, + outlives: Vec<String>, }, EqPredicate { lhs: Type, diff --git a/src/tools/jsondoclint/src/validator.rs b/src/tools/jsondoclint/src/validator.rs index 1713a4d812c..cd011dce784 100644 --- a/src/tools/jsondoclint/src/validator.rs +++ b/src/tools/jsondoclint/src/validator.rs @@ -374,8 +374,8 @@ impl<'a> Validator<'a> { bounds.iter().for_each(|b| self.check_generic_bound(b)); generic_params.iter().for_each(|gpd| self.check_generic_param_def(gpd)); } - WherePredicate::RegionPredicate { lifetime: _, bounds } => { - bounds.iter().for_each(|b| self.check_generic_bound(b)); + WherePredicate::LifetimePredicate { lifetime: _, outlives: _ } => { + // nop, all strings. } WherePredicate::EqPredicate { lhs, rhs } => { self.check_type(lhs); |