Skip to content

Commit d082ff4

Browse files
Rollup merge of #144478 - joshtriplett:doc-code-formatting-prep, r=Amanieu
Improve formatting of doc code blocks We don't currently apply automatic formatting to doc comment code blocks. As a result, it has built up various idiosyncracies, which make such automatic formatting difficult. Some of those idiosyncracies also make things harder for human readers or other tools. This PR makes a few improvements to doc code formatting, in the hopes of making future automatic formatting easier, as well as in many cases providing net readability improvements. I would suggest reading each commit separately, as each commit contains one class of changes.
2 parents cafd9fb + 1e2d587 commit d082ff4

File tree

23 files changed

+67
-52
lines changed

23 files changed

+67
-52
lines changed

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
417417
/// minimum values.
418418
///
419419
/// For example:
420-
/// ```
420+
/// ```ignore (illustrative)
421421
/// fn foo<'a, 'b>( /* ... */ ) where 'a: 'b { /* ... */ }
422422
/// ```
423423
/// would initialize two variables like so:

compiler/rustc_hir/src/def.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ impl DefKind {
360360
/// For example, everything prefixed with `/* Res */` in this example has
361361
/// an associated `Res`:
362362
///
363-
/// ```
363+
/// ```ignore (illustrative)
364364
/// fn str_to_string(s: & /* Res */ str) -> /* Res */ String {
365365
/// /* Res */ String::from(/* Res */ s)
366366
/// }
@@ -421,7 +421,7 @@ pub enum Res<Id = hir::HirId> {
421421
/// }
422422
///
423423
/// impl Foo for Bar {
424-
/// fn foo() -> Box<Self> { // SelfTyAlias
424+
/// fn foo() -> Box<Self /* SelfTyAlias */> {
425425
/// let _: Self; // SelfTyAlias
426426
///
427427
/// todo!()

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateParam<'tcx> {
425425
///
426426
/// trait Foo {
427427
/// fn bar() -> impl Deref<Target = impl Sized>;
428-
/// // ^- RPITIT #1 ^- RPITIT #2
428+
/// // ^- RPITIT #1 ^- RPITIT #2
429429
/// }
430430
///
431431
/// impl Foo for () {

compiler/rustc_hir_typeck/src/upvar.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,13 +2391,11 @@ fn migration_suggestion_for_2229(
23912391
/// let mut p = Point { x: 10, y: 10 };
23922392
///
23932393
/// let c = || {
2394-
/// p.x += 10;
2395-
/// // ^ E1 ^
2394+
/// p.x += 10; // E1
23962395
/// // ...
23972396
/// // More code
23982397
/// // ...
23992398
/// p.x += 10; // E2
2400-
/// // ^ E2 ^
24012399
/// };
24022400
/// ```
24032401
/// `CaptureKind` associated with both `E1` and `E2` will be ByRef(MutBorrow),

compiler/rustc_infer/src/infer/outlives/obligations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
//! fn bar<T>(a: T, b: impl for<'a> Fn(&'a T)) {}
3737
//! fn foo<T>(x: T) {
3838
//! bar(x, |y| { /* ... */})
39-
//! // ^ closure arg
39+
//! // ^ closure arg
4040
//! }
4141
//! ```
4242
//!

compiler/rustc_middle/src/hir/map.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,10 @@ impl<'tcx> TyCtxt<'tcx> {
533533
/// ```
534534
/// fn foo(x: usize) -> bool {
535535
/// if x == 1 {
536-
/// true // If `get_fn_id_for_return_block` gets passed the `id` corresponding
537-
/// } else { // to this, it will return `foo`'s `HirId`.
536+
/// // If `get_fn_id_for_return_block` gets passed the `id` corresponding to this, it
537+
/// // will return `foo`'s `HirId`.
538+
/// true
539+
/// } else {
538540
/// false
539541
/// }
540542
/// }
@@ -543,8 +545,10 @@ impl<'tcx> TyCtxt<'tcx> {
543545
/// ```compile_fail,E0308
544546
/// fn foo(x: usize) -> bool {
545547
/// loop {
546-
/// true // If `get_fn_id_for_return_block` gets passed the `id` corresponding
547-
/// } // to this, it will return `None`.
548+
/// // If `get_fn_id_for_return_block` gets passed the `id` corresponding to this, it
549+
/// // will return `None`.
550+
/// true
551+
/// }
548552
/// false
549553
/// }
550554
/// ```

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,8 @@ pub struct LocalDecl<'tcx> {
10171017
/// ```
10181018
/// fn foo(x: &str) {
10191019
/// #[allow(unused_mut)]
1020-
/// let mut x: u32 = { // <- one unused mut
1020+
/// let mut x: u32 = {
1021+
/// //^ one unused mut
10211022
/// let mut y: u32 = x.parse().unwrap();
10221023
/// y + 2
10231024
/// };

compiler/rustc_mir_build/src/builder/expr/as_operand.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
5757
/// ```
5858
/// #![feature(unsized_fn_params)]
5959
/// # use core::fmt::Debug;
60-
/// fn foo(_p: dyn Debug) { /* ... */ }
60+
/// fn foo(_p: dyn Debug) {
61+
/// /* ... */
62+
/// }
6163
///
6264
/// fn bar(box_p: Box<dyn Debug>) { foo(*box_p); }
6365
/// ```

compiler/rustc_mir_dataflow/src/impls/initialized.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ impl<'tcx> MaybePlacesSwitchIntData<'tcx> {
108108
///
109109
/// ```rust
110110
/// struct S;
111+
/// #[rustfmt::skip]
111112
/// fn foo(pred: bool) { // maybe-init:
112113
/// // {}
113114
/// let a = S; let mut b = S; let c; let d; // {a, b}
@@ -197,6 +198,7 @@ impl<'a, 'tcx> HasMoveData<'tcx> for MaybeInitializedPlaces<'a, 'tcx> {
197198
///
198199
/// ```rust
199200
/// struct S;
201+
/// #[rustfmt::skip]
200202
/// fn foo(pred: bool) { // maybe-uninit:
201203
/// // {a, b, c, d}
202204
/// let a = S; let mut b = S; let c; let d; // { c, d}
@@ -289,6 +291,7 @@ impl<'tcx> HasMoveData<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
289291
///
290292
/// ```rust
291293
/// struct S;
294+
/// #[rustfmt::skip]
292295
/// fn foo(pred: bool) { // ever-init:
293296
/// // { }
294297
/// let a = S; let mut b = S; let c; let d; // {a, b }

compiler/rustc_span/src/hygiene.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,9 @@ impl SyntaxContext {
768768
///
769769
/// ```rust
770770
/// #![feature(decl_macro)]
771-
/// mod foo { pub fn f() {} } // `f`'s `SyntaxContext` is empty.
771+
/// mod foo {
772+
/// pub fn f() {} // `f`'s `SyntaxContext` is empty.
773+
/// }
772774
/// m!(f);
773775
/// macro m($f:ident) {
774776
/// mod bar {

0 commit comments

Comments
 (0)