Skip to content

Commit 6e86aa1

Browse files
committed
Adapt librustdoc to 2024 edition lifetieme capture rules
Get rid of the `Captures` hack
1 parent 00523bf commit 6e86aa1

File tree

9 files changed

+270
-429
lines changed

9 files changed

+270
-429
lines changed

compiler/rustc_data_structures/src/captures.rs

-8
This file was deleted.

compiler/rustc_data_structures/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ pub use rustc_index::static_assert_size;
4848
pub mod aligned;
4949
pub mod base_n;
5050
pub mod binary_search_util;
51-
pub mod captures;
5251
pub mod fingerprint;
5352
pub mod flat_map_in_place;
5453
pub mod flock;

src/librustdoc/clean/types.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ pub(crate) struct Attributes {
11501150
}
11511151

11521152
impl Attributes {
1153-
pub(crate) fn lists(&self, name: Symbol) -> impl Iterator<Item = ast::MetaItemInner> + '_ {
1153+
pub(crate) fn lists(&self, name: Symbol) -> impl Iterator<Item = ast::MetaItemInner> {
11541154
hir_attr_lists(&self.other_attrs[..], name)
11551155
}
11561156

@@ -1864,7 +1864,7 @@ impl PrimitiveType {
18641864
.copied()
18651865
}
18661866

1867-
pub(crate) fn all_impls(tcx: TyCtxt<'_>) -> impl Iterator<Item = DefId> + '_ {
1867+
pub(crate) fn all_impls(tcx: TyCtxt<'_>) -> impl Iterator<Item = DefId> {
18681868
Self::simplified_types()
18691869
.values()
18701870
.flatten()
@@ -2259,7 +2259,7 @@ impl GenericArgs {
22592259
GenericArgs::Parenthesized { inputs, output } => inputs.is_empty() && output.is_none(),
22602260
}
22612261
}
2262-
pub(crate) fn constraints<'a>(&'a self) -> Box<dyn Iterator<Item = AssocItemConstraint> + 'a> {
2262+
pub(crate) fn constraints(&self) -> Box<dyn Iterator<Item = AssocItemConstraint> + '_> {
22632263
match self {
22642264
GenericArgs::AngleBracketed { constraints, .. } => {
22652265
Box::new(constraints.iter().cloned())

src/librustdoc/clean/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
330330
return Symbol::intern("()");
331331
}
332332
PatKind::Slice(begin, mid, end) => {
333-
fn print_pat<'a>(pat: &'a Pat<'a>, wild: bool) -> impl Display + 'a {
333+
fn print_pat(pat: &Pat<'_>, wild: bool) -> impl Display {
334334
fmt::from_fn(move |f| {
335335
if wild {
336336
f.write_str("..")?;

src/librustdoc/html/format.rs

+45-99
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use std::iter::{self, once};
1515
use itertools::Either;
1616
use rustc_abi::ExternAbi;
1717
use rustc_attr_parsing::{ConstStability, StabilityLevel, StableSince};
18-
use rustc_data_structures::captures::Captures;
1918
use rustc_data_structures::fx::FxHashSet;
2019
use rustc_hir as hir;
2120
use rustc_hir::def::DefKind;
@@ -41,10 +40,10 @@ pub(crate) fn write_str(s: &mut String, f: fmt::Arguments<'_>) {
4140
s.write_fmt(f).unwrap();
4241
}
4342

44-
pub(crate) fn print_generic_bounds<'a, 'tcx: 'a>(
45-
bounds: &'a [clean::GenericBound],
46-
cx: &'a Context<'tcx>,
47-
) -> impl Display + 'a + Captures<'tcx> {
43+
pub(crate) fn print_generic_bounds(
44+
bounds: &[clean::GenericBound],
45+
cx: &Context<'_>,
46+
) -> impl Display {
4847
fmt::from_fn(move |f| {
4948
let mut bounds_dup = FxHashSet::default();
5049

@@ -57,10 +56,7 @@ pub(crate) fn print_generic_bounds<'a, 'tcx: 'a>(
5756
}
5857

5958
impl clean::GenericParamDef {
60-
pub(crate) fn print<'a, 'tcx: 'a>(
61-
&'a self,
62-
cx: &'a Context<'tcx>,
63-
) -> impl Display + 'a + Captures<'tcx> {
59+
pub(crate) fn print(&self, cx: &Context<'_>) -> impl Display {
6460
fmt::from_fn(move |f| match &self.kind {
6561
clean::GenericParamDefKind::Lifetime { outlives } => {
6662
write!(f, "{}", self.name)?;
@@ -107,10 +103,7 @@ impl clean::GenericParamDef {
107103
}
108104

109105
impl clean::Generics {
110-
pub(crate) fn print<'a, 'tcx: 'a>(
111-
&'a self,
112-
cx: &'a Context<'tcx>,
113-
) -> impl Display + 'a + Captures<'tcx> {
106+
pub(crate) fn print(&self, cx: &Context<'_>) -> impl Display {
114107
fmt::from_fn(move |f| {
115108
let mut real_params = self.params.iter().filter(|p| !p.is_synthetic_param()).peekable();
116109
if real_params.peek().is_none() {
@@ -134,10 +127,7 @@ pub(crate) enum Ending {
134127
NoNewline,
135128
}
136129

137-
fn print_where_predicate<'a, 'tcx: 'a>(
138-
predicate: &'a clean::WherePredicate,
139-
cx: &'a Context<'tcx>,
140-
) -> impl Display + 'a + Captures<'tcx> {
130+
fn print_where_predicate(predicate: &clean::WherePredicate, cx: &Context<'_>) -> impl Display {
141131
fmt::from_fn(move |f| {
142132
match predicate {
143133
clean::WherePredicate::BoundPredicate { ty, bounds, bound_params } => {
@@ -173,12 +163,12 @@ fn print_where_predicate<'a, 'tcx: 'a>(
173163
/// * The Generics from which to emit a where-clause.
174164
/// * The number of spaces to indent each line with.
175165
/// * Whether the where-clause needs to add a comma and newline after the last bound.
176-
pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
177-
gens: &'a clean::Generics,
178-
cx: &'a Context<'tcx>,
166+
pub(crate) fn print_where_clause(
167+
gens: &clean::Generics,
168+
cx: &Context<'_>,
179169
indent: usize,
180170
ending: Ending,
181-
) -> Option<impl Display + 'a + Captures<'tcx>> {
171+
) -> Option<impl Display> {
182172
if gens.where_predicates.is_empty() {
183173
return None;
184174
}
@@ -250,13 +240,13 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
250240
}
251241

252242
impl clean::Lifetime {
253-
pub(crate) fn print(&self) -> impl Display + '_ {
243+
pub(crate) fn print(&self) -> impl Display {
254244
self.0.as_str()
255245
}
256246
}
257247

258248
impl clean::ConstantKind {
259-
pub(crate) fn print(&self, tcx: TyCtxt<'_>) -> impl Display + '_ {
249+
pub(crate) fn print(&self, tcx: TyCtxt<'_>) -> impl Display {
260250
let expr = self.expr(tcx);
261251
fmt::from_fn(move |f| {
262252
if f.alternate() { f.write_str(&expr) } else { write!(f, "{}", Escape(&expr)) }
@@ -265,7 +255,7 @@ impl clean::ConstantKind {
265255
}
266256

267257
impl clean::PolyTrait {
268-
fn print<'a, 'tcx: 'a>(&'a self, cx: &'a Context<'tcx>) -> impl Display + 'a + Captures<'tcx> {
258+
fn print(&self, cx: &Context<'_>) -> impl Display {
269259
fmt::from_fn(move |f| {
270260
print_higher_ranked_params_with_space(&self.generic_params, cx, "for").fmt(f)?;
271261
self.trait_.print(cx).fmt(f)
@@ -274,10 +264,7 @@ impl clean::PolyTrait {
274264
}
275265

276266
impl clean::GenericBound {
277-
pub(crate) fn print<'a, 'tcx: 'a>(
278-
&'a self,
279-
cx: &'a Context<'tcx>,
280-
) -> impl Display + 'a + Captures<'tcx> {
267+
pub(crate) fn print(&self, cx: &Context<'_>) -> impl Display {
281268
fmt::from_fn(move |f| match self {
282269
clean::GenericBound::Outlives(lt) => write!(f, "{}", lt.print()),
283270
clean::GenericBound::TraitBound(ty, modifiers) => {
@@ -304,7 +291,7 @@ impl clean::GenericBound {
304291
}
305292

306293
impl clean::GenericArgs {
307-
fn print<'a, 'tcx: 'a>(&'a self, cx: &'a Context<'tcx>) -> impl Display + 'a + Captures<'tcx> {
294+
fn print(&self, cx: &Context<'_>) -> impl Display {
308295
fmt::from_fn(move |f| {
309296
match self {
310297
clean::GenericArgs::AngleBracketed { args, constraints } => {
@@ -809,11 +796,11 @@ fn primitive_link_fragment(
809796
Ok(())
810797
}
811798

812-
fn tybounds<'a, 'tcx: 'a>(
813-
bounds: &'a [clean::PolyTrait],
814-
lt: &'a Option<clean::Lifetime>,
815-
cx: &'a Context<'tcx>,
816-
) -> impl Display + 'a + Captures<'tcx> {
799+
fn tybounds(
800+
bounds: &[clean::PolyTrait],
801+
lt: &Option<clean::Lifetime>,
802+
cx: &Context<'_>,
803+
) -> impl Display {
817804
fmt::from_fn(move |f| {
818805
bounds.iter().map(|bound| bound.print(cx)).joined(" + ", f)?;
819806
if let Some(lt) = lt {
@@ -825,11 +812,11 @@ fn tybounds<'a, 'tcx: 'a>(
825812
})
826813
}
827814

828-
fn print_higher_ranked_params_with_space<'a, 'tcx: 'a>(
829-
params: &'a [clean::GenericParamDef],
830-
cx: &'a Context<'tcx>,
815+
fn print_higher_ranked_params_with_space(
816+
params: &[clean::GenericParamDef],
817+
cx: &Context<'_>,
831818
keyword: &'static str,
832-
) -> impl Display + 'a + Captures<'tcx> {
819+
) -> impl Display {
833820
fmt::from_fn(move |f| {
834821
if !params.is_empty() {
835822
f.write_str(keyword)?;
@@ -841,11 +828,7 @@ fn print_higher_ranked_params_with_space<'a, 'tcx: 'a>(
841828
})
842829
}
843830

844-
pub(crate) fn anchor<'a: 'cx, 'cx>(
845-
did: DefId,
846-
text: Symbol,
847-
cx: &'cx Context<'a>,
848-
) -> impl Display + Captures<'a> + 'cx {
831+
pub(crate) fn anchor(did: DefId, text: Symbol, cx: &Context<'_>) -> impl Display {
849832
fmt::from_fn(move |f| {
850833
let parts = href(did, cx);
851834
if let Ok((url, short_ty, fqp)) = parts {
@@ -1121,29 +1104,19 @@ fn fmt_type(
11211104
}
11221105

11231106
impl clean::Type {
1124-
pub(crate) fn print<'b, 'a: 'b, 'tcx: 'a>(
1125-
&'a self,
1126-
cx: &'a Context<'tcx>,
1127-
) -> impl Display + 'b + Captures<'tcx> {
1107+
pub(crate) fn print(&self, cx: &Context<'_>) -> impl Display {
11281108
fmt::from_fn(move |f| fmt_type(self, f, false, cx))
11291109
}
11301110
}
11311111

11321112
impl clean::Path {
1133-
pub(crate) fn print<'b, 'a: 'b, 'tcx: 'a>(
1134-
&'a self,
1135-
cx: &'a Context<'tcx>,
1136-
) -> impl Display + 'b + Captures<'tcx> {
1113+
pub(crate) fn print(&self, cx: &Context<'_>) -> impl Display {
11371114
fmt::from_fn(move |f| resolved_path(f, self.def_id(), self, false, false, cx))
11381115
}
11391116
}
11401117

11411118
impl clean::Impl {
1142-
pub(crate) fn print<'a, 'tcx: 'a>(
1143-
&'a self,
1144-
use_absolute: bool,
1145-
cx: &'a Context<'tcx>,
1146-
) -> impl Display + 'a + Captures<'tcx> {
1119+
pub(crate) fn print(&self, use_absolute: bool, cx: &Context<'_>) -> impl Display {
11471120
fmt::from_fn(move |f| {
11481121
f.write_str("impl")?;
11491122
self.generics.print(cx).fmt(f)?;
@@ -1182,12 +1155,12 @@ impl clean::Impl {
11821155
print_where_clause(&self.generics, cx, 0, Ending::Newline).maybe_display().fmt(f)
11831156
})
11841157
}
1185-
fn print_type<'a, 'tcx: 'a>(
1158+
fn print_type(
11861159
&self,
11871160
type_: &clean::Type,
11881161
f: &mut fmt::Formatter<'_>,
11891162
use_absolute: bool,
1190-
cx: &'a Context<'tcx>,
1163+
cx: &Context<'_>,
11911164
) -> Result<(), fmt::Error> {
11921165
if let clean::Type::Tuple(types) = type_
11931166
&& let [clean::Type::Generic(name)] = &types[..]
@@ -1258,10 +1231,7 @@ impl clean::Impl {
12581231
}
12591232

12601233
impl clean::Arguments {
1261-
pub(crate) fn print<'a, 'tcx: 'a>(
1262-
&'a self,
1263-
cx: &'a Context<'tcx>,
1264-
) -> impl Display + 'a + Captures<'tcx> {
1234+
pub(crate) fn print(&self, cx: &Context<'_>) -> impl Display {
12651235
fmt::from_fn(move |f| {
12661236
self.values
12671237
.iter()
@@ -1301,10 +1271,7 @@ impl Display for Indent {
13011271
}
13021272

13031273
impl clean::FnDecl {
1304-
pub(crate) fn print<'b, 'a: 'b, 'tcx: 'a>(
1305-
&'a self,
1306-
cx: &'a Context<'tcx>,
1307-
) -> impl Display + 'b + Captures<'tcx> {
1274+
pub(crate) fn print(&self, cx: &Context<'_>) -> impl Display {
13081275
fmt::from_fn(move |f| {
13091276
let ellipsis = if self.c_variadic { ", ..." } else { "" };
13101277
if f.alternate() {
@@ -1333,12 +1300,12 @@ impl clean::FnDecl {
13331300
/// are preserved.
13341301
/// * `indent`: The number of spaces to indent each successive line with, if line-wrapping is
13351302
/// necessary.
1336-
pub(crate) fn full_print<'a, 'tcx: 'a>(
1337-
&'a self,
1303+
pub(crate) fn full_print(
1304+
&self,
13381305
header_len: usize,
13391306
indent: usize,
1340-
cx: &'a Context<'tcx>,
1341-
) -> impl Display + 'a + Captures<'tcx> {
1307+
cx: &Context<'_>,
1308+
) -> impl Display {
13421309
fmt::from_fn(move |f| {
13431310
// First, generate the text form of the declaration, with no line wrapping, and count the bytes.
13441311
let mut counter = WriteCounter(0);
@@ -1420,10 +1387,7 @@ impl clean::FnDecl {
14201387
self.print_output(cx).fmt(f)
14211388
}
14221389

1423-
fn print_output<'a, 'tcx: 'a>(
1424-
&'a self,
1425-
cx: &'a Context<'tcx>,
1426-
) -> impl Display + 'a + Captures<'tcx> {
1390+
fn print_output(&self, cx: &Context<'_>) -> impl Display {
14271391
fmt::from_fn(move |f| match &self.output {
14281392
clean::Tuple(tys) if tys.is_empty() => Ok(()),
14291393
ty if f.alternate() => {
@@ -1434,10 +1398,7 @@ impl clean::FnDecl {
14341398
}
14351399
}
14361400

1437-
pub(crate) fn visibility_print_with_space<'a, 'tcx: 'a>(
1438-
item: &clean::Item,
1439-
cx: &'a Context<'tcx>,
1440-
) -> impl Display + 'a + Captures<'tcx> {
1401+
pub(crate) fn visibility_print_with_space(item: &clean::Item, cx: &Context<'_>) -> impl Display {
14411402
use std::fmt::Write as _;
14421403
let vis: Cow<'static, str> = match item.visibility(cx.tcx()) {
14431404
None => "".into(),
@@ -1546,10 +1507,7 @@ pub(crate) fn print_constness_with_space(
15461507
}
15471508

15481509
impl clean::Import {
1549-
pub(crate) fn print<'a, 'tcx: 'a>(
1550-
&'a self,
1551-
cx: &'a Context<'tcx>,
1552-
) -> impl Display + 'a + Captures<'tcx> {
1510+
pub(crate) fn print(&self, cx: &Context<'_>) -> impl Display {
15531511
fmt::from_fn(move |f| match self.kind {
15541512
clean::ImportKind::Simple(name) => {
15551513
if name == self.source.path.last() {
@@ -1570,10 +1528,7 @@ impl clean::Import {
15701528
}
15711529

15721530
impl clean::ImportSource {
1573-
pub(crate) fn print<'a, 'tcx: 'a>(
1574-
&'a self,
1575-
cx: &'a Context<'tcx>,
1576-
) -> impl Display + 'a + Captures<'tcx> {
1531+
pub(crate) fn print(&self, cx: &Context<'_>) -> impl Display {
15771532
fmt::from_fn(move |f| match self.did {
15781533
Some(did) => resolved_path(f, did, &self.path, true, false, cx),
15791534
_ => {
@@ -1593,10 +1548,7 @@ impl clean::ImportSource {
15931548
}
15941549

15951550
impl clean::AssocItemConstraint {
1596-
pub(crate) fn print<'a, 'tcx: 'a>(
1597-
&'a self,
1598-
cx: &'a Context<'tcx>,
1599-
) -> impl Display + 'a + Captures<'tcx> {
1551+
pub(crate) fn print(&self, cx: &Context<'_>) -> impl Display {
16001552
fmt::from_fn(move |f| {
16011553
f.write_str(self.assoc.name.as_str())?;
16021554
self.assoc.args.print(cx).fmt(f)?;
@@ -1627,15 +1579,12 @@ pub(crate) fn print_abi_with_space(abi: ExternAbi) -> impl Display {
16271579
})
16281580
}
16291581

1630-
pub(crate) fn print_default_space<'a>(v: bool) -> &'a str {
1582+
pub(crate) fn print_default_space(v: bool) -> &'static str {
16311583
if v { "default " } else { "" }
16321584
}
16331585

16341586
impl clean::GenericArg {
1635-
pub(crate) fn print<'a, 'tcx: 'a>(
1636-
&'a self,
1637-
cx: &'a Context<'tcx>,
1638-
) -> impl Display + 'a + Captures<'tcx> {
1587+
pub(crate) fn print(&self, cx: &Context<'_>) -> impl Display {
16391588
fmt::from_fn(move |f| match self {
16401589
clean::GenericArg::Lifetime(lt) => lt.print().fmt(f),
16411590
clean::GenericArg::Type(ty) => ty.print(cx).fmt(f),
@@ -1646,10 +1595,7 @@ impl clean::GenericArg {
16461595
}
16471596

16481597
impl clean::Term {
1649-
pub(crate) fn print<'a, 'tcx: 'a>(
1650-
&'a self,
1651-
cx: &'a Context<'tcx>,
1652-
) -> impl Display + 'a + Captures<'tcx> {
1598+
pub(crate) fn print(&self, cx: &Context<'_>) -> impl Display {
16531599
fmt::from_fn(move |f| match self {
16541600
clean::Term::Type(ty) => ty.print(cx).fmt(f),
16551601
clean::Term::Constant(ct) => ct.print(cx.tcx()).fmt(f),

0 commit comments

Comments
 (0)