Skip to content

Commit 7150880

Browse files
committed
Improve and regularize comment placement in doc code
Because doc code does not get automatically formatted, some doc code has creative placements of comments that automatic formatting can't handle. Reformat those comments to make the resulting code support standard Rust formatting without breaking; this is generally an improvement to readability as well. Some comments are not indented to the prevailing indent, and are instead aligned under some bit of code. Indent them to the prevailing indent, and put spaces *inside* the comments to align them with code. Some comments span several lines of code (which aren't the line the comment is about) and expect alignment. Reformat them into one comment not broken up by unrelated intervening code. Some comments are placed on the same line as an opening brace, placing them effectively inside the subsequent block, such that formatting would typically format them like a line of that block. Move those comments to attach them to what they apply to. Some comments are placed on the same line as a one-line braced block, effectively attaching them to the closing brace, even though they're about the code inside the block. Reformat to make sure the comment will stay on the same line as the code it's commenting.
1 parent 3352dfc commit 7150880

File tree

17 files changed

+51
-40
lines changed

17 files changed

+51
-40
lines changed

compiler/rustc_hir/src/def.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ pub enum Res<Id = hir::HirId> {
417417
/// }
418418
///
419419
/// impl Foo for Bar {
420-
/// fn foo() -> Box<Self> { // SelfTyAlias
420+
/// fn foo() -> Box<Self /* SelfTyAlias */> {
421421
/// let _: Self; // SelfTyAlias
422422
///
423423
/// 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_span/src/hygiene.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,9 @@ impl SyntaxContext {
756756
///
757757
/// ```rust
758758
/// #![feature(decl_macro)]
759-
/// mod foo { pub fn f() {} } // `f`'s `SyntaxContext` is empty.
759+
/// mod foo {
760+
/// pub fn f() {} // `f`'s `SyntaxContext` is empty.
761+
/// }
760762
/// m!(f);
761763
/// macro m($f:ident) {
762764
/// mod bar {

compiler/rustc_thread_pool/src/scope/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,9 @@ impl<'scope> Scope<'scope> {
501501
/// let mut value_c = None;
502502
/// rayon::scope(|s| {
503503
/// s.spawn(|s1| {
504-
/// // ^ this is the same scope as `s`; this handle `s1`
505-
/// // is intended for use by the spawned task,
506-
/// // since scope handles cannot cross thread boundaries.
504+
/// // ^ this is the same scope as `s`; this handle `s1`
505+
/// // is intended for use by the spawned task,
506+
/// // since scope handles cannot cross thread boundaries.
507507
///
508508
/// value_a = Some(22);
509509
///

library/alloc/src/vec/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3778,8 +3778,8 @@ impl<T, A: Allocator> Vec<T, A> {
37783778
/// while i < vec.len() - end_items {
37793779
/// if some_predicate(&mut vec[i]) {
37803780
/// let val = vec.remove(i);
3781-
/// # extracted.push(val);
37823781
/// // your code here
3782+
/// # extracted.push(val);
37833783
/// } else {
37843784
/// i += 1;
37853785
/// }

0 commit comments

Comments
 (0)