Adapt librustdoc
to 2024 edition lifetieme capture rules · rust-lang/rust@7d263b0 (original) (raw)
`@@ -15,7 +15,6 @@ use std::iter::{self, once};
`
15
15
`use itertools::Either;
`
16
16
`use rustc_abi::ExternAbi;
`
17
17
`use rustc_attr_parsing::{ConstStability, StabilityLevel, StableSince};
`
18
``
`-
use rustc_data_structures::captures::Captures;
`
19
18
`use rustc_data_structures::fx::FxHashSet;
`
20
19
`use rustc_hir as hir;
`
21
20
`use rustc_hir::def::DefKind;
`
`@@ -41,10 +40,10 @@ pub(crate) fn write_str(s: &mut String, f: fmt::Arguments<'_>) {
`
41
40
` s.write_fmt(f).unwrap();
`
42
41
`}
`
43
42
``
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 {
`
48
47
` fmt::from_fn(move |f| {
`
49
48
`let mut bounds_dup = FxHashSet::default();
`
50
49
``
`@@ -57,10 +56,7 @@ pub(crate) fn print_generic_bounds<'a, 'tcx: 'a>(
`
57
56
`}
`
58
57
``
59
58
`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 {
`
64
60
` fmt::from_fn(move |f| match &self.kind {
`
65
61
` clean::GenericParamDefKind::Lifetime { outlives } => {
`
66
62
`write!(f, "{}", self.name)?;
`
`@@ -107,10 +103,7 @@ impl clean::GenericParamDef {
`
107
103
`}
`
108
104
``
109
105
`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 {
`
114
107
` fmt::from_fn(move |f| {
`
115
108
`let mut real_params = self.params.iter().filter(|p| !p.is_synthetic_param()).peekable();
`
116
109
`if real_params.peek().is_none() {
`
`@@ -134,10 +127,7 @@ pub(crate) enum Ending {
`
134
127
`NoNewline,
`
135
128
`}
`
136
129
``
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 {
`
141
131
` fmt::from_fn(move |f| {
`
142
132
`match predicate {
`
143
133
` clean::WherePredicate::BoundPredicate { ty, bounds, bound_params } => {
`
`@@ -173,12 +163,12 @@ fn print_where_predicate<'a, 'tcx: 'a>(
`
173
163
`/// * The Generics from which to emit a where-clause.
`
174
164
`/// * The number of spaces to indent each line with.
`
175
165
`/// * 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<'_>,
`
179
169
`indent: usize,
`
180
170
`ending: Ending,
`
181
``
`-
) -> impl Display + 'a + Captures<'tcx> {
`
``
171
`+
) -> impl Display {
`
182
172
` fmt::from_fn(move |f| {
`
183
173
`if gens.where_predicates.is_empty() {
`
184
174
`return Ok(());
`
`@@ -250,13 +240,13 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
`
250
240
`}
`
251
241
``
252
242
`impl clean::Lifetime {
`
253
``
`-
pub(crate) fn print(&self) -> impl Display + '_ {
`
``
243
`+
pub(crate) fn print(&self) -> impl Display {
`
254
244
`self.0.as_str()
`
255
245
`}
`
256
246
`}
`
257
247
``
258
248
`impl clean::ConstantKind {
`
259
``
`-
pub(crate) fn print(&self, tcx: TyCtxt<'>) -> impl Display + ' {
`
``
249
`+
pub(crate) fn print(&self, tcx: TyCtxt<'_>) -> impl Display {
`
260
250
`let expr = self.expr(tcx);
`
261
251
` fmt::from_fn(move |f| {
`
262
252
`if f.alternate() { f.write_str(&expr) } else { write!(f, "{}", Escape(&expr)) }
`
`@@ -265,7 +255,7 @@ impl clean::ConstantKind {
`
265
255
`}
`
266
256
``
267
257
`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 {
`
269
259
` fmt::from_fn(move |f| {
`
270
260
`print_higher_ranked_params_with_space(&self.generic_params, cx, "for").fmt(f)?;
`
271
261
`self.trait_.print(cx).fmt(f)
`
`@@ -274,10 +264,7 @@ impl clean::PolyTrait {
`
274
264
`}
`
275
265
``
276
266
`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 {
`
281
268
` fmt::from_fn(move |f| match self {
`
282
269
` clean::GenericBound::Outlives(lt) => write!(f, "{}", lt.print()),
`
283
270
` clean::GenericBound::TraitBound(ty, modifiers) => {
`
`@@ -304,7 +291,7 @@ impl clean::GenericBound {
`
304
291
`}
`
305
292
``
306
293
`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 {
`
308
295
` fmt::from_fn(move |f| {
`
309
296
`match self {
`
310
297
` clean::GenericArgs::AngleBracketed { args, constraints } => {
`
`@@ -809,11 +796,11 @@ fn primitive_link_fragment(
`
809
796
`Ok(())
`
810
797
`}
`
811
798
``
812
``
`-
fn tybounds<'a, 'tcx: 'a>(
`
813
``
`-
bounds: &'a [clean::PolyTrait],
`
814
``
`-
lt: &'a Optionclean::Lifetime,
`
815
``
`-
cx: &'a Context<'tcx>,
`
816
``
`-
) -> impl Display + 'a + Captures<'tcx> {
`
``
799
`+
fn tybounds(
`
``
800
`+
bounds: &[clean::PolyTrait],
`
``
801
`+
lt: &Optionclean::Lifetime,
`
``
802
`+
cx: &Context<'_>,
`
``
803
`+
) -> impl Display {
`
817
804
` fmt::from_fn(move |f| {
`
818
805
` bounds.iter().map(|bound| bound.print(cx)).joined(" + ", f)?;
`
819
806
`if let Some(lt) = lt {
`
`@@ -825,11 +812,11 @@ fn tybounds<'a, 'tcx: 'a>(
`
825
812
`})
`
826
813
`}
`
827
814
``
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<'_>,
`
831
818
`keyword: &'static str,
`
832
``
`-
) -> impl Display + 'a + Captures<'tcx> {
`
``
819
`+
) -> impl Display {
`
833
820
` fmt::from_fn(move |f| {
`
834
821
`if !params.is_empty() {
`
835
822
` f.write_str(keyword)?;
`
`@@ -841,11 +828,7 @@ fn print_higher_ranked_params_with_space<'a, 'tcx: 'a>(
`
841
828
`})
`
842
829
`}
`
843
830
``
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 {
`
849
832
` fmt::from_fn(move |f| {
`
850
833
`let parts = href(did, cx);
`
851
834
`if let Ok((url, short_ty, fqp)) = parts {
`
`@@ -1121,29 +1104,19 @@ fn fmt_type(
`
1121
1104
`}
`
1122
1105
``
1123
1106
`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 {
`
1128
1108
` fmt::from_fn(move |f| fmt_type(self, f, false, cx))
`
1129
1109
`}
`
1130
1110
`}
`
1131
1111
``
1132
1112
`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 {
`
1137
1114
` fmt::from_fn(move |f| resolved_path(f, self.def_id(), self, false, false, cx))
`
1138
1115
`}
`
1139
1116
`}
`
1140
1117
``
1141
1118
`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 {
`
1147
1120
` fmt::from_fn(move |f| {
`
1148
1121
` f.write_str("impl")?;
`
1149
1122
`self.generics.print(cx).fmt(f)?;
`
`@@ -1182,12 +1155,12 @@ impl clean::Impl {
`
1182
1155
`print_where_clause(&self.generics, cx, 0, Ending::Newline).fmt(f)
`
1183
1156
`})
`
1184
1157
`}
`
1185
``
`-
fn print_type<'a, 'tcx: 'a>(
`
``
1158
`+
fn print_type(
`
1186
1159
`&self,
`
1187
1160
`type_: &clean::Type,
`
1188
1161
`f: &mut fmt::Formatter<'_>,
`
1189
1162
`use_absolute: bool,
`
1190
``
`-
cx: &'a Context<'tcx>,
`
``
1163
`+
cx: &Context<'_>,
`
1191
1164
`) -> Result<(), fmt::Error> {
`
1192
1165
`if let clean::Type::Tuple(types) = type_
`
1193
1166
` && let [clean::Type::Generic(name)] = &types[..]
`
`@@ -1258,10 +1231,7 @@ impl clean::Impl {
`
1258
1231
`}
`
1259
1232
``
1260
1233
`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 {
`
1265
1235
` fmt::from_fn(move |f| {
`
1266
1236
`self.values
`
1267
1237
`.iter()
`
`@@ -1301,10 +1271,7 @@ impl Display for Indent {
`
1301
1271
`}
`
1302
1272
``
1303
1273
`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 {
`
1308
1275
` fmt::from_fn(move |f| {
`
1309
1276
`let ellipsis = if self.c_variadic { ", ..." } else { "" };
`
1310
1277
`if f.alternate() {
`
`@@ -1333,12 +1300,12 @@ impl clean::FnDecl {
`
1333
1300
`/// are preserved.
`
1334
1301
`` /// * indent
: The number of spaces to indent each successive line with, if line-wrapping is
``
1335
1302
`/// necessary.
`
1336
``
`-
pub(crate) fn full_print<'a, 'tcx: 'a>(
`
1337
``
`-
&'a self,
`
``
1303
`+
pub(crate) fn full_print(
`
``
1304
`+
&self,
`
1338
1305
`header_len: usize,
`
1339
1306
`indent: usize,
`
1340
``
`-
cx: &'a Context<'tcx>,
`
1341
``
`-
) -> impl Display + 'a + Captures<'tcx> {
`
``
1307
`+
cx: &Context<'_>,
`
``
1308
`+
) -> impl Display {
`
1342
1309
` fmt::from_fn(move |f| {
`
1343
1310
`// First, generate the text form of the declaration, with no line wrapping, and count the bytes.
`
1344
1311
`let mut counter = WriteCounter(0);
`
`@@ -1420,10 +1387,7 @@ impl clean::FnDecl {
`
1420
1387
`self.print_output(cx).fmt(f)
`
1421
1388
`}
`
1422
1389
``
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 {
`
1427
1391
` fmt::from_fn(move |f| match &self.output {
`
1428
1392
` clean::Tuple(tys) if tys.is_empty() => Ok(()),
`
1429
1393
` ty if f.alternate() => {
`
`@@ -1434,10 +1398,7 @@ impl clean::FnDecl {
`
1434
1398
`}
`
1435
1399
`}
`
1436
1400
``
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 {
`
1441
1402
`use std::fmt::Write as _;
`
1442
1403
`let vis: Cow<'static, str> = match item.visibility(cx.tcx()) {
`
1443
1404
`None => "".into(),
`
`@@ -1546,10 +1507,7 @@ pub(crate) fn print_constness_with_space(
`
1546
1507
`}
`
1547
1508
``
1548
1509
`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 {
`
1553
1511
` fmt::from_fn(move |f| match self.kind {
`
1554
1512
` clean::ImportKind::Simple(name) => {
`
1555
1513
`if name == self.source.path.last() {
`
`@@ -1570,10 +1528,7 @@ impl clean::Import {
`
1570
1528
`}
`
1571
1529
``
1572
1530
`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 {
`
1577
1532
` fmt::from_fn(move |f| match self.did {
`
1578
1533
`Some(did) => resolved_path(f, did, &self.path, true, false, cx),
`
1579
1534
` _ => {
`
`@@ -1593,10 +1548,7 @@ impl clean::ImportSource {
`
1593
1548
`}
`
1594
1549
``
1595
1550
`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 {
`
1600
1552
` fmt::from_fn(move |f| {
`
1601
1553
` f.write_str(self.assoc.name.as_str())?;
`
1602
1554
`self.assoc.args.print(cx).fmt(f)?;
`
`@@ -1627,15 +1579,12 @@ pub(crate) fn print_abi_with_space(abi: ExternAbi) -> impl Display {
`
1627
1579
`})
`
1628
1580
`}
`
1629
1581
``
1630
``
`-
pub(crate) fn print_default_space<'a>(v: bool) -> &'a str {
`
``
1582
`+
pub(crate) fn print_default_space(v: bool) -> &'static str {
`
1631
1583
`if v { "default " } else { "" }
`
1632
1584
`}
`
1633
1585
``
1634
1586
`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 {
`
1639
1588
` fmt::from_fn(move |f| match self {
`
1640
1589
` clean::GenericArg::Lifetime(lt) => lt.print().fmt(f),
`
1641
1590
` clean::GenericArg::Type(ty) => ty.print(cx).fmt(f),
`
`@@ -1646,10 +1595,7 @@ impl clean::GenericArg {
`
1646
1595
`}
`
1647
1596
``
1648
1597
`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 {
`
1653
1599
` fmt::from_fn(move |f| match self {
`
1654
1600
` clean::Term::Type(ty) => ty.print(cx).fmt(f),
`
1655
1601
` clean::Term::Constant(ct) => ct.print(cx.tcx()).fmt(f),
`