Skip to content

Commit d03b3db

Browse files
committed
Rustfmt-compatible formatting for code snippets in rustc_builtin_macros
1 parent dd91aba commit d03b3db

File tree

1 file changed

+64
-40
lines changed
  • compiler/rustc_builtin_macros/src/deriving/generic

1 file changed

+64
-40
lines changed

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+64-40
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737
//! following snippet
3838
//!
3939
//! ```rust
40-
//! # #![allow(dead_code)]
41-
//! struct A { x : i32 }
40+
//! struct A {
41+
//! x: i32,
42+
//! }
4243
//!
4344
//! struct B(i32);
4445
//!
@@ -74,6 +75,7 @@
7475
//! trait PartialEq {
7576
//! fn eq(&self, other: &Self) -> bool;
7677
//! }
78+
//!
7779
//! impl PartialEq for i32 {
7880
//! fn eq(&self, other: &i32) -> bool {
7981
//! *self == *other
@@ -90,22 +92,22 @@
9092
//!
9193
//! ```text
9294
//! Struct(vec![FieldInfo {
93-
//! span: <span of x>
94-
//! name: Some(<ident of x>),
95-
//! self_: <expr for &self.x>,
96-
//! other: vec![<expr for &other.x]
97-
//! }])
95+
//! span: <span of x>,
96+
//! name: Some(<ident of x>),
97+
//! self_: <expr for &self.x>,
98+
//! other: vec![<expr for &other.x>],
99+
//! }])
98100
//! ```
99101
//!
100102
//! For the `B` impl, called with `B(a)` and `B(b)`,
101103
//!
102104
//! ```text
103105
//! Struct(vec![FieldInfo {
104-
//! span: <span of `i32`>,
105-
//! name: None,
106-
//! self_: <expr for &a>
107-
//! other: vec![<expr for &b>]
108-
//! }])
106+
//! span: <span of i32>,
107+
//! name: None,
108+
//! self_: <expr for &a>,
109+
//! other: vec![<expr for &b>],
110+
//! }])
109111
//! ```
110112
//!
111113
//! ## Enums
@@ -114,33 +116,42 @@
114116
//! == C0(b)`, the SubstructureFields is
115117
//!
116118
//! ```text
117-
//! EnumMatching(0, <ast::Variant for C0>,
118-
//! vec![FieldInfo {
119-
//! span: <span of i32>
120-
//! name: None,
121-
//! self_: <expr for &a>,
122-
//! other: vec![<expr for &b>]
123-
//! }])
119+
//! EnumMatching(
120+
//! 0,
121+
//! <ast::Variant for C0>,
122+
//! vec![FieldInfo {
123+
//! span: <span of i32>,
124+
//! name: None,
125+
//! self_: <expr for &a>,
126+
//! other: vec![<expr for &b>],
127+
//! }],
128+
//! )
124129
//! ```
125130
//!
126131
//! For `C1 {x}` and `C1 {x}`,
127132
//!
128133
//! ```text
129-
//! EnumMatching(1, <ast::Variant for C1>,
130-
//! vec![FieldInfo {
131-
//! span: <span of x>
132-
//! name: Some(<ident of x>),
133-
//! self_: <expr for &self.x>,
134-
//! other: vec![<expr for &other.x>]
135-
//! }])
134+
//! EnumMatching(
135+
//! 1,
136+
//! <ast::Variant for C1>,
137+
//! vec![FieldInfo {
138+
//! span: <span of x>,
139+
//! name: Some(<ident of x>),
140+
//! self_: <expr for &self.x>,
141+
//! other: vec![<expr for &other.x>],
142+
//! }],
143+
//! )
136144
//! ```
137145
//!
138146
//! For the tags,
139147
//!
140148
//! ```text
141149
//! EnumTag(
142-
//! &[<ident of self tag>, <ident of other tag>], <expr to combine with>)
150+
//! &[<ident of self tag>, <ident of other tag>],
151+
//! <expr to combine with>,
152+
//! )
143153
//! ```
154+
//!
144155
//! Note that this setup doesn't allow for the brute-force "match every variant
145156
//! against every other variant" approach, which is bad because it produces a
146157
//! quadratic amount of code (see #15375).
@@ -154,9 +165,13 @@
154165
//!
155166
//! StaticStruct(<ast::VariantData of B>, Unnamed(vec![<span of x>]))
156167
//!
157-
//! StaticEnum(<ast::EnumDef of C>,
158-
//! vec![(<ident of C0>, <span of C0>, Unnamed(vec![<span of i32>])),
159-
//! (<ident of C1>, <span of C1>, Named(vec![(<ident of x>, <span of x>)]))])
168+
//! StaticEnum(
169+
//! <ast::EnumDef of C>,
170+
//! vec![
171+
//! (<ident of C0>, <span of C0>, Unnamed(vec![<span of i32>])),
172+
//! (<ident of C1>, <span of C1>, Named(vec![(<ident of x>, <span of x>)])),
173+
//! ],
174+
//! )
160175
//! ```
161176
162177
pub use StaticFields::*;
@@ -522,7 +537,10 @@ impl<'a> TraitDef<'a> {
522537
/// Given that we are deriving a trait `DerivedTrait` for a type like:
523538
///
524539
/// ```ignore (only-for-syntax-highlight)
525-
/// struct Struct<'a, ..., 'z, A, B: DeclaredTrait, C, ..., Z> where C: WhereTrait {
540+
/// struct Struct<'a, ..., 'z, A, B: DeclaredTrait, C, ..., Z>
541+
/// where
542+
/// C: WhereTrait,
543+
/// {
526544
/// a: A,
527545
/// b: B::Item,
528546
/// b1: <B as DeclaredTrait>::Item,
@@ -535,12 +553,13 @@ impl<'a> TraitDef<'a> {
535553
/// create an impl like:
536554
///
537555
/// ```ignore (only-for-syntax-highlight)
538-
/// impl<'a, ..., 'z, A, B: DeclaredTrait, C, ... Z> where
539-
/// C: WhereTrait,
556+
/// impl<'a, ..., 'z, A, B: DeclaredTrait, C, ..., Z>
557+
/// where
558+
/// C: WhereTrait,
540559
/// A: DerivedTrait + B1 + ... + BN,
541560
/// B: DerivedTrait + B1 + ... + BN,
542561
/// C: DerivedTrait + B1 + ... + BN,
543-
/// B::Item: DerivedTrait + B1 + ... + BN,
562+
/// B::Item: DerivedTrait + B1 + ... + BN,
544563
/// <C as WhereTrait>::Item: DerivedTrait + B1 + ... + BN,
545564
/// ...
546565
/// {
@@ -1026,6 +1045,7 @@ impl<'a> MethodDef<'a> {
10261045
}
10271046

10281047
/// The normal case uses field access.
1048+
///
10291049
/// ```
10301050
/// #[derive(PartialEq)]
10311051
/// # struct Dummy;
@@ -1038,10 +1058,12 @@ impl<'a> MethodDef<'a> {
10381058
/// }
10391059
/// }
10401060
/// ```
1061+
///
10411062
/// But if the struct is `repr(packed)`, we can't use something like
10421063
/// `&self.x` because that might cause an unaligned ref. So for any trait
10431064
/// method that takes a reference, we use a local block to force a copy.
10441065
/// This requires that the field impl `Copy`.
1066+
///
10451067
/// ```rust,ignore (example)
10461068
/// # struct A { x: u8, y: u8 }
10471069
/// impl PartialEq for A {
@@ -1053,7 +1075,7 @@ impl<'a> MethodDef<'a> {
10531075
/// impl Hash for A {
10541076
/// fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
10551077
/// ::core::hash::Hash::hash(&{ self.x }, state);
1056-
/// ::core::hash::Hash::hash(&{ self.y }, state)
1078+
/// ::core::hash::Hash::hash(&{ self.y }, state);
10571079
/// }
10581080
/// }
10591081
/// ```
@@ -1107,7 +1129,9 @@ impl<'a> MethodDef<'a> {
11071129
/// A2(i32)
11081130
/// }
11091131
/// ```
1132+
///
11101133
/// is equivalent to:
1134+
///
11111135
/// ```
11121136
/// #![feature(core_intrinsics)]
11131137
/// enum A {
@@ -1119,15 +1143,15 @@ impl<'a> MethodDef<'a> {
11191143
/// fn eq(&self, other: &A) -> bool {
11201144
/// let __self_tag = ::core::intrinsics::discriminant_value(self);
11211145
/// let __arg1_tag = ::core::intrinsics::discriminant_value(other);
1122-
/// __self_tag == __arg1_tag &&
1123-
/// match (self, other) {
1124-
/// (A::A2(__self_0), A::A2(__arg1_0)) =>
1125-
/// *__self_0 == *__arg1_0,
1146+
/// __self_tag == __arg1_tag
1147+
/// && match (self, other) {
1148+
/// (A::A2(__self_0), A::A2(__arg1_0)) => *__self_0 == *__arg1_0,
11261149
/// _ => true,
11271150
/// }
11281151
/// }
11291152
/// }
11301153
/// ```
1154+
///
11311155
/// Creates a tag check combined with a match for a tuple of all
11321156
/// `selflike_args`, with an arm for each variant with fields, possibly an
11331157
/// arm for each fieldless variant (if `unify_fieldless_variants` is not
@@ -1349,7 +1373,7 @@ impl<'a> MethodDef<'a> {
13491373
// (Variant1, Variant1, ...) => Body1
13501374
// (Variant2, Variant2, ...) => Body2,
13511375
// ...
1352-
// _ => ::core::intrinsics::unreachable()
1376+
// _ => ::core::intrinsics::unreachable(),
13531377
// }
13541378
let get_match_expr = |mut selflike_args: ThinVec<P<Expr>>| {
13551379
let match_arg = if selflike_args.len() == 1 {

0 commit comments

Comments
 (0)