Skip to content

Commit c0074d3

Browse files
authored
Unrolled build for rust-lang#127289
Rollup merge of rust-lang#127289 - aDotInTheVoid:rustdoc-json-lt, r=GuillaumeGomez rustdoc-json: Better representation of lifetime bounds in where clauses. As suggested [on zulip][1] (CC `@its-the-shrimp),` 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]: rust-lang#100961 (comment) r? `@GuillaumeGomez`
2 parents 486bc27 + 7e8aac5 commit c0074d3

File tree

6 files changed

+47
-8
lines changed

6 files changed

+47
-8
lines changed

src/librustdoc/clean/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ impl GenericBound {
12861286
}
12871287
}
12881288

1289-
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
1289+
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
12901290
pub(crate) struct Lifetime(pub Symbol);
12911291

12921292
impl Lifetime {

src/librustdoc/json/conversions.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_ast::ast;
1010
use rustc_attr::DeprecatedSince;
1111
use rustc_hir::{def::CtorKind, def::DefKind, def_id::DefId};
1212
use rustc_metadata::rendered_const;
13+
use rustc_middle::bug;
1314
use rustc_middle::ty::{self, TyCtxt};
1415
use rustc_span::symbol::sym;
1516
use rustc_span::{Pos, Symbol};
@@ -512,9 +513,15 @@ impl FromWithTcx<clean::WherePredicate> for WherePredicate {
512513
})
513514
.collect(),
514515
},
515-
RegionPredicate { lifetime, bounds } => WherePredicate::RegionPredicate {
516+
RegionPredicate { lifetime, bounds } => WherePredicate::LifetimePredicate {
516517
lifetime: convert_lifetime(lifetime),
517-
bounds: bounds.into_tcx(tcx),
518+
outlives: bounds
519+
.iter()
520+
.map(|bound| match bound {
521+
clean::GenericBound::Outlives(lt) => convert_lifetime(*lt),
522+
_ => bug!("found non-outlives-bound on lifetime predicate"),
523+
})
524+
.collect(),
518525
},
519526
EqPredicate { lhs, rhs } => {
520527
WherePredicate::EqPredicate { lhs: lhs.into_tcx(tcx), rhs: rhs.into_tcx(tcx) }

src/rustdoc-json-types/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
88
use std::path::PathBuf;
99

1010
/// rustdoc format-version.
11-
pub const FORMAT_VERSION: u32 = 30;
11+
pub const FORMAT_VERSION: u32 = 31;
1212

1313
/// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information
1414
/// about the language items in the local crate, as well as info about external items to allow
@@ -511,9 +511,9 @@ pub enum WherePredicate {
511511
/// ```
512512
generic_params: Vec<GenericParamDef>,
513513
},
514-
RegionPredicate {
514+
LifetimePredicate {
515515
lifetime: String,
516-
bounds: Vec<GenericBound>,
516+
outlives: Vec<String>,
517517
},
518518
EqPredicate {
519519
lhs: Type,

src/tools/jsondoclint/src/validator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ impl<'a> Validator<'a> {
374374
bounds.iter().for_each(|b| self.check_generic_bound(b));
375375
generic_params.iter().for_each(|gpd| self.check_generic_param_def(gpd));
376376
}
377-
WherePredicate::RegionPredicate { lifetime: _, bounds } => {
378-
bounds.iter().for_each(|b| self.check_generic_bound(b));
377+
WherePredicate::LifetimePredicate { lifetime: _, outlives: _ } => {
378+
// nop, all strings.
379379
}
380380
WherePredicate::EqPredicate { lhs, rhs } => {
381381
self.check_type(lhs);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// ignore-tidy-linelength
2+
3+
// @count '$.index[*][?(@.name=="outlives")].inner.function.generics.params[*]' 2
4+
// @is '$.index[*][?(@.name=="outlives")].inner.function.generics.params[0].name' \"\'a\"
5+
// @is '$.index[*][?(@.name=="outlives")].inner.function.generics.params[0].kind.lifetime.outlives' []
6+
// @is '$.index[*][?(@.name=="outlives")].inner.function.generics.params[1].name' '"T"'
7+
// @is '$.index[*][?(@.name=="outlives")].inner.function.generics.params[1].kind.type.bounds' '[{"outlives": "'\''a"}]'
8+
pub fn outlives<'a, T: 'a>() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// ignore-tidy-linelength
2+
3+
// @is '$.index[*][?(@.name=="on_lifetimes")].inner.function.generics.where_predicates' '[{"lifetime_predicate": {"lifetime": "'\''all", "outlives": ["'\''a", "'\''b", "'\''c"]}}]'
4+
pub fn on_lifetimes<'a, 'b, 'c, 'all>()
5+
where
6+
'all: 'a + 'b + 'c,
7+
{
8+
}
9+
10+
// @count '$.index[*][?(@.name=="on_trait")].inner.function.generics.params[*]' 2
11+
// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.params[0].name' \"\'a\"
12+
// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.params[0].kind.lifetime.outlives' []
13+
// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.params[1].name' '"T"'
14+
// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.params[1].kind.type.bounds' []
15+
// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.params[1].kind.type.bounds' []
16+
// @count '$.index[*][?(@.name=="on_trait")].inner.function.generics.where_predicates[*]' 1
17+
// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.where_predicates[0].bound_predicate.type.generic' '"T"'
18+
// @count '$.index[*][?(@.name=="on_trait")].inner.function.generics.where_predicates[0].bound_predicate.bounds[*]' 1
19+
// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.where_predicates[0].bound_predicate.bounds[0].outlives' \"\'a\"
20+
pub fn on_trait<'a, T>()
21+
where
22+
T: 'a,
23+
{
24+
}

0 commit comments

Comments
 (0)