Skip to content

Commit 8d3b1f9

Browse files
committed
Auto merge of rust-lang#12984 - bitfield:fix_doc_nits_c, r=Alexendoo
Fix doc nits More tender love and polish for the documentation and suggestion texts: adding formatting, links, full stops, tweaking wording for readability, changing 'which' to 'that' where appropriate, and other standard copyediting changes. changelog: Docs [ `await_holding_lock` ]: fix doc nits changelog: Docs [ `await_holding_refcell_ref` ]: fix doc nits changelog: Docs [ `await_holding_invalid_type` ]: fix doc nits changelog: Docs [ `cast_precision_loss` ]: fix doc nits changelog: Docs [ `cast_sign_loss` ]: fix doc nits changelog: Docs [ `cast_possible_truncation` ]: fix doc nits changelog: Docs [ `cast_possible_wrap` ]: fix doc nits changelog: Docs [ `cast_lossless` ]: fix doc nits changelog: Docs [ `unnecessary_cast` ]: fix doc nits changelog: Docs [ `cast_ptr_alignment` ]: fix doc nits changelog: Docs [ `fn_to_numeric_cast` ]: fix doc nits changelog: Docs [ `fn_to_numeric_cast_with_truncation` ]: fix doc nits changelog: Docs [ `fn_to_numeric_cast_any` ]: fix doc nits changelog: Docs [ `char_lit_as_u8` ]: fix doc nits changelog: Docs [ `ptr_as_ptr` ]: fix doc nits changelog: Docs [ `ptr_cast_constness` ]: fix doc nits changelog: Docs [ `as_ptr_cast_mut` ]: fix doc nits changelog: Docs [ `little_endian_bytes` ]: fix doc nits changelog: Docs [ `big_endian_bytes` ]: fix doc nits changelog: Docs [ `bind_instead_of_map` ]: fix doc nits changelog: Docs [ `same_name_method` ]: fix doc nits
2 parents b012421 + d23df74 commit 8d3b1f9

13 files changed

+197
-191
lines changed

clippy_lints/src/await_holding_invalid.rs

+25-21
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,25 @@ use rustc_span::{sym, Span};
1111

1212
declare_clippy_lint! {
1313
/// ### What it does
14-
/// Checks for calls to await while holding a non-async-aware MutexGuard.
14+
/// Checks for calls to `await` while holding a non-async-aware
15+
/// `MutexGuard`.
1516
///
1617
/// ### Why is this bad?
17-
/// The Mutex types found in std::sync and parking_lot
18-
/// are not designed to operate in an async context across await points.
18+
/// The Mutex types found in [`std::sync`][https://doc.rust-lang.org/stable/std/sync/] and
19+
/// [`parking_lot`](https://docs.rs/parking_lot/latest/parking_lot/) are
20+
/// not designed to operate in an async context across await points.
1921
///
20-
/// There are two potential solutions. One is to use an async-aware Mutex
21-
/// type. Many asynchronous foundation crates provide such a Mutex type. The
22-
/// other solution is to ensure the mutex is unlocked before calling await,
23-
/// either by introducing a scope or an explicit call to Drop::drop.
22+
/// There are two potential solutions. One is to use an async-aware `Mutex`
23+
/// type. Many asynchronous foundation crates provide such a `Mutex` type.
24+
/// The other solution is to ensure the mutex is unlocked before calling
25+
/// `await`, either by introducing a scope or an explicit call to
26+
/// [`Drop::drop`](https://doc.rust-lang.org/std/ops/trait.Drop.html).
2427
///
2528
/// ### Known problems
2629
/// Will report false positive for explicitly dropped guards
27-
/// ([#6446](https://github.com/rust-lang/rust-clippy/issues/6446)). A workaround for this is
28-
/// to wrap the `.lock()` call in a block instead of explicitly dropping the guard.
30+
/// ([#6446](https://github.com/rust-lang/rust-clippy/issues/6446)). A
31+
/// workaround for this is to wrap the `.lock()` call in a block instead of
32+
/// explicitly dropping the guard.
2933
///
3034
/// ### Example
3135
/// ```no_run
@@ -73,11 +77,11 @@ declare_clippy_lint! {
7377

7478
declare_clippy_lint! {
7579
/// ### What it does
76-
/// Checks for calls to await while holding a `RefCell` `Ref` or `RefMut`.
80+
/// Checks for calls to `await` while holding a `RefCell`, `Ref`, or `RefMut`.
7781
///
7882
/// ### Why is this bad?
7983
/// `RefCell` refs only check for exclusive mutable access
80-
/// at runtime. Holding onto a `RefCell` ref across an `await` suspension point
84+
/// at runtime. Holding a `RefCell` ref across an await suspension point
8185
/// risks panics from a mutable ref shared while other refs are outstanding.
8286
///
8387
/// ### Known problems
@@ -131,13 +135,13 @@ declare_clippy_lint! {
131135

132136
declare_clippy_lint! {
133137
/// ### What it does
134-
/// Allows users to configure types which should not be held across `await`
138+
/// Allows users to configure types which should not be held across await
135139
/// suspension points.
136140
///
137141
/// ### Why is this bad?
138-
/// There are some types which are perfectly "safe" to be used concurrently
139-
/// from a memory access perspective but will cause bugs at runtime if they
140-
/// are held in such a way.
142+
/// There are some types which are perfectly safe to use concurrently from
143+
/// a memory access perspective, but that will cause bugs at runtime if
144+
/// they are held in such a way.
141145
///
142146
/// ### Example
143147
///
@@ -228,15 +232,15 @@ impl AwaitHolding {
228232
cx,
229233
AWAIT_HOLDING_LOCK,
230234
ty_cause.source_info.span,
231-
"this `MutexGuard` is held across an `await` point",
235+
"this `MutexGuard` is held across an await point",
232236
|diag| {
233237
diag.help(
234238
"consider using an async-aware `Mutex` type or ensuring the \
235-
`MutexGuard` is dropped before calling await",
239+
`MutexGuard` is dropped before calling `await`",
236240
);
237241
diag.span_note(
238242
await_points(),
239-
"these are all the `await` points this lock is held through",
243+
"these are all the await points this lock is held through",
240244
);
241245
},
242246
);
@@ -245,12 +249,12 @@ impl AwaitHolding {
245249
cx,
246250
AWAIT_HOLDING_REFCELL_REF,
247251
ty_cause.source_info.span,
248-
"this `RefCell` reference is held across an `await` point",
252+
"this `RefCell` reference is held across an await point",
249253
|diag| {
250254
diag.help("ensure the reference is dropped before calling `await`");
251255
diag.span_note(
252256
await_points(),
253-
"these are all the `await` points this reference is held through",
257+
"these are all the await points this reference is held through",
254258
);
255259
},
256260
);
@@ -268,7 +272,7 @@ fn emit_invalid_type(cx: &LateContext<'_>, span: Span, disallowed: &DisallowedPa
268272
AWAIT_HOLDING_INVALID_TYPE,
269273
span,
270274
format!(
271-
"`{}` may not be held across an `await` point per `clippy.toml`",
275+
"`{}` may not be held across an await point per `clippy.toml`",
272276
disallowed.path()
273277
),
274278
|diag| {

clippy_lints/src/casts/mod.rs

+58-55
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use rustc_session::impl_lint_pass;
3232

3333
declare_clippy_lint! {
3434
/// ### What it does
35-
/// Checks for casts from any numerical to a float type where
35+
/// Checks for casts from any numeric type to a float type where
3636
/// the receiving type cannot store all values from the original type without
3737
/// rounding errors. This possible rounding is to be expected, so this lint is
3838
/// `Allow` by default.
@@ -58,14 +58,14 @@ declare_clippy_lint! {
5858

5959
declare_clippy_lint! {
6060
/// ### What it does
61-
/// Checks for casts from a signed to an unsigned numerical
61+
/// Checks for casts from a signed to an unsigned numeric
6262
/// type. In this case, negative values wrap around to large positive values,
63-
/// which can be quite surprising in practice. However, as the cast works as
63+
/// which can be quite surprising in practice. However, since the cast works as
6464
/// defined, this lint is `Allow` by default.
6565
///
6666
/// ### Why is this bad?
6767
/// Possibly surprising results. You can activate this lint
68-
/// as a one-time check to see where numerical wrapping can arise.
68+
/// as a one-time check to see where numeric wrapping can arise.
6969
///
7070
/// ### Example
7171
/// ```no_run
@@ -80,7 +80,7 @@ declare_clippy_lint! {
8080

8181
declare_clippy_lint! {
8282
/// ### What it does
83-
/// Checks for casts between numerical types that may
83+
/// Checks for casts between numeric types that may
8484
/// truncate large values. This is expected behavior, so the cast is `Allow` by
8585
/// default. It suggests user either explicitly ignore the lint,
8686
/// or use `try_from()` and handle the truncation, default, or panic explicitly.
@@ -120,17 +120,16 @@ declare_clippy_lint! {
120120
declare_clippy_lint! {
121121
/// ### What it does
122122
/// Checks for casts from an unsigned type to a signed type of
123-
/// the same size, or possibly smaller due to target dependent integers.
124-
/// Performing such a cast is a 'no-op' for the compiler, i.e., nothing is
125-
/// changed at the bit level, and the binary representation of the value is
123+
/// the same size, or possibly smaller due to target-dependent integers.
124+
/// Performing such a cast is a no-op for the compiler (that is, nothing is
125+
/// changed at the bit level), and the binary representation of the value is
126126
/// reinterpreted. This can cause wrapping if the value is too big
127127
/// for the target signed type. However, the cast works as defined, so this lint
128128
/// is `Allow` by default.
129129
///
130130
/// ### Why is this bad?
131131
/// While such a cast is not bad in itself, the results can
132-
/// be surprising when this is not the intended behavior, as demonstrated by the
133-
/// example below.
132+
/// be surprising when this is not the intended behavior:
134133
///
135134
/// ### Example
136135
/// ```no_run
@@ -144,16 +143,16 @@ declare_clippy_lint! {
144143

145144
declare_clippy_lint! {
146145
/// ### What it does
147-
/// Checks for casts between numerical types that may
148-
/// be replaced by safe conversion functions.
146+
/// Checks for casts between numeric types that can be replaced by safe
147+
/// conversion functions.
149148
///
150149
/// ### Why is this bad?
151-
/// Rust's `as` keyword will perform many kinds of
152-
/// conversions, including silently lossy conversions. Conversion functions such
153-
/// as `i32::from` will only perform lossless conversions. Using the conversion
154-
/// functions prevents conversions from turning into silent lossy conversions if
155-
/// the types of the input expressions ever change, and make it easier for
156-
/// people reading the code to know that the conversion is lossless.
150+
/// Rust's `as` keyword will perform many kinds of conversions, including
151+
/// silently lossy conversions. Conversion functions such as `i32::from`
152+
/// will only perform lossless conversions. Using the conversion functions
153+
/// prevents conversions from becoming silently lossy if the input types
154+
/// ever change, and makes it clear for people reading the code that the
155+
/// conversion is lossless.
157156
///
158157
/// ### Example
159158
/// ```no_run
@@ -177,19 +176,21 @@ declare_clippy_lint! {
177176

178177
declare_clippy_lint! {
179178
/// ### What it does
180-
/// Checks for casts to the same type, casts of int literals to integer types, casts of float
181-
/// literals to float types and casts between raw pointers without changing type or constness.
179+
/// Checks for casts to the same type, casts of int literals to integer
180+
/// types, casts of float literals to float types, and casts between raw
181+
/// pointers that don't change type or constness.
182182
///
183183
/// ### Why is this bad?
184184
/// It's just unnecessary.
185185
///
186186
/// ### Known problems
187-
/// When the expression on the left is a function call, the lint considers the return type to be
188-
/// a type alias if it's aliased through a `use` statement
189-
/// (like `use std::io::Result as IoResult`). It will not lint such cases.
187+
/// When the expression on the left is a function call, the lint considers
188+
/// the return type to be a type alias if it's aliased through a `use`
189+
/// statement (like `use std::io::Result as IoResult`). It will not lint
190+
/// such cases.
190191
///
191-
/// This check is also rather primitive. It will only work on primitive types without any
192-
/// intermediate references, raw pointers and trait objects may or may not work.
192+
/// This check will only work on primitive types without any intermediate
193+
/// references: raw pointers and trait objects may or may not work.
193194
///
194195
/// ### Example
195196
/// ```no_run
@@ -211,17 +212,17 @@ declare_clippy_lint! {
211212

212213
declare_clippy_lint! {
213214
/// ### What it does
214-
/// Checks for casts, using `as` or `pointer::cast`,
215-
/// from a less-strictly-aligned pointer to a more-strictly-aligned pointer
215+
/// Checks for casts, using `as` or `pointer::cast`, from a
216+
/// less strictly aligned pointer to a more strictly aligned pointer.
216217
///
217218
/// ### Why is this bad?
218-
/// Dereferencing the resulting pointer may be undefined
219-
/// behavior.
219+
/// Dereferencing the resulting pointer may be undefined behavior.
220220
///
221221
/// ### Known problems
222-
/// Using `std::ptr::read_unaligned` and `std::ptr::write_unaligned` or similar
223-
/// on the resulting pointer is fine. Is over-zealous: Casts with manual alignment checks or casts like
224-
/// u64-> u8 -> u16 can be fine. Miri is able to do a more in-depth analysis.
222+
/// Using [`std::ptr::read_unaligned`](https://doc.rust-lang.org/std/ptr/fn.read_unaligned.html) and [`std::ptr::write_unaligned`](https://doc.rust-lang.org/std/ptr/fn.write_unaligned.html) or
223+
/// similar on the resulting pointer is fine. Is over-zealous: casts with
224+
/// manual alignment checks or casts like `u64` -> `u8` -> `u16` can be
225+
/// fine. Miri is able to do a more in-depth analysis.
225226
///
226227
/// ### Example
227228
/// ```no_run
@@ -234,20 +235,21 @@ declare_clippy_lint! {
234235
#[clippy::version = "pre 1.29.0"]
235236
pub CAST_PTR_ALIGNMENT,
236237
pedantic,
237-
"cast from a pointer to a more-strictly-aligned pointer"
238+
"cast from a pointer to a more strictly aligned pointer"
238239
}
239240

240241
declare_clippy_lint! {
241242
/// ### What it does
242-
/// Checks for casts of function pointers to something other than usize
243+
/// Checks for casts of function pointers to something other than `usize`.
243244
///
244245
/// ### Why is this bad?
245-
/// Casting a function pointer to anything other than usize/isize is not portable across
246-
/// architectures, because you end up losing bits if the target type is too small or end up with a
247-
/// bunch of extra bits that waste space and add more instructions to the final binary than
248-
/// strictly necessary for the problem
246+
/// Casting a function pointer to anything other than `usize`/`isize` is
247+
/// not portable across architectures. If the target type is too small the
248+
/// address would be truncated, and target types larger than `usize` are
249+
/// unnecessary.
249250
///
250-
/// Casting to isize also doesn't make sense since there are no signed addresses.
251+
/// Casting to `isize` also doesn't make sense, since addresses are never
252+
/// signed.
251253
///
252254
/// ### Example
253255
/// ```no_run
@@ -263,17 +265,17 @@ declare_clippy_lint! {
263265
#[clippy::version = "pre 1.29.0"]
264266
pub FN_TO_NUMERIC_CAST,
265267
style,
266-
"casting a function pointer to a numeric type other than usize"
268+
"casting a function pointer to a numeric type other than `usize`"
267269
}
268270

269271
declare_clippy_lint! {
270272
/// ### What it does
271273
/// Checks for casts of a function pointer to a numeric type not wide enough to
272-
/// store address.
274+
/// store an address.
273275
///
274276
/// ### Why is this bad?
275277
/// Such a cast discards some bits of the function's address. If this is intended, it would be more
276-
/// clearly expressed by casting to usize first, then casting the usize to the intended type (with
278+
/// clearly expressed by casting to `usize` first, then casting the `usize` to the intended type (with
277279
/// a comment) to perform the truncation.
278280
///
279281
/// ### Example
@@ -306,7 +308,7 @@ declare_clippy_lint! {
306308
/// ### Why restrict this?
307309
/// Casting a function pointer to an integer can have surprising results and can occur
308310
/// accidentally if parentheses are omitted from a function call. If you aren't doing anything
309-
/// low-level with function pointers then you can opt-out of casting functions to integers in
311+
/// low-level with function pointers then you can opt out of casting functions to integers in
310312
/// order to avoid mistakes. Alternatively, you can use this lint to audit all uses of function
311313
/// pointer casts in your code.
312314
///
@@ -349,8 +351,8 @@ declare_clippy_lint! {
349351
/// ### Why is this bad?
350352
/// In general, casting values to smaller types is
351353
/// error-prone and should be avoided where possible. In the particular case of
352-
/// converting a character literal to u8, it is easy to avoid by just using a
353-
/// byte literal instead. As an added bonus, `b'a'` is even slightly shorter
354+
/// converting a character literal to `u8`, it is easy to avoid by just using a
355+
/// byte literal instead. As an added bonus, `b'a'` is also slightly shorter
354356
/// than `'a' as u8`.
355357
///
356358
/// ### Example
@@ -371,12 +373,13 @@ declare_clippy_lint! {
371373

372374
declare_clippy_lint! {
373375
/// ### What it does
374-
/// Checks for `as` casts between raw pointers without changing its mutability,
375-
/// namely `*const T` to `*const U` and `*mut T` to `*mut U`.
376+
/// Checks for `as` casts between raw pointers that don't change their
377+
/// constness, namely `*const T` to `*const U` and `*mut T` to `*mut U`.
376378
///
377379
/// ### Why is this bad?
378-
/// Though `as` casts between raw pointers are not terrible, `pointer::cast` is safer because
379-
/// it cannot accidentally change the pointer's mutability nor cast the pointer to other types like `usize`.
380+
/// Though `as` casts between raw pointers are not terrible,
381+
/// `pointer::cast` is safer because it cannot accidentally change the
382+
/// pointer's mutability, nor cast the pointer to other types like `usize`.
380383
///
381384
/// ### Example
382385
/// ```no_run
@@ -395,12 +398,12 @@ declare_clippy_lint! {
395398
#[clippy::version = "1.51.0"]
396399
pub PTR_AS_PTR,
397400
pedantic,
398-
"casting using `as` from and to raw pointers that doesn't change its mutability, where `pointer::cast` could take the place of `as`"
401+
"casting using `as` between raw pointers that doesn't change their constness, where `pointer::cast` could take the place of `as`"
399402
}
400403

401404
declare_clippy_lint! {
402405
/// ### What it does
403-
/// Checks for `as` casts between raw pointers which change its constness, namely `*const T` to
406+
/// Checks for `as` casts between raw pointers that change their constness, namely `*const T` to
404407
/// `*mut T` and `*mut T` to `*const T`.
405408
///
406409
/// ### Why is this bad?
@@ -423,12 +426,12 @@ declare_clippy_lint! {
423426
#[clippy::version = "1.72.0"]
424427
pub PTR_CAST_CONSTNESS,
425428
pedantic,
426-
"casting using `as` from and to raw pointers to change constness when specialized methods apply"
429+
"casting using `as` on raw pointers to change constness when specialized methods apply"
427430
}
428431

429432
declare_clippy_lint! {
430433
/// ### What it does
431-
/// Checks for casts from an enum type to an integral type which will definitely truncate the
434+
/// Checks for casts from an enum type to an integral type that will definitely truncate the
432435
/// value.
433436
///
434437
/// ### Why is this bad?
@@ -442,7 +445,7 @@ declare_clippy_lint! {
442445
#[clippy::version = "1.61.0"]
443446
pub CAST_ENUM_TRUNCATION,
444447
suspicious,
445-
"casts from an enum type to an integral type which will truncate the value"
448+
"casts from an enum type to an integral type that will truncate the value"
446449
}
447450

448451
declare_clippy_lint! {
@@ -621,7 +624,7 @@ declare_clippy_lint! {
621624

622625
declare_clippy_lint! {
623626
/// ### What it does
624-
/// Checks for the result of a `&self`-taking `as_ptr` being cast to a mutable pointer
627+
/// Checks for the result of a `&self`-taking `as_ptr` being cast to a mutable pointer.
625628
///
626629
/// ### Why is this bad?
627630
/// Since `as_ptr` takes a `&self`, the pointer won't have write permissions unless interior

clippy_lints/src/casts/ptr_as_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: &Msrv) {
9292
cx,
9393
PTR_AS_PTR,
9494
expr.span,
95-
"`as` casting between raw pointers without changing its mutability",
95+
"`as` casting between raw pointers without changing their constness",
9696
help,
9797
final_suggestion,
9898
app,

0 commit comments

Comments
 (0)