Skip to content

Commit b818ccc

Browse files
committed
Auto merge of #69746 - Dylan-DPC:rollup-wr6dvdk, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - #69697 (Add explanation for E0380) - #69698 (Use associated constants of integer types) - #69711 (Update macros.rs: fix documentation typo.) - #69713 (more clippy cleanups) - #69728 (Make link to `std::str` active) - #69732 (Clean E0382 and E0384 explanations) - #69736 (even more clippy cleanups) - #69742 (Fixed a typo) Failed merges: r? @ghost
2 parents 96bb8b3 + 80c8434 commit b818ccc

File tree

57 files changed

+128
-129
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+128
-129
lines changed

src/liballoc/string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ impl String {
407407
///
408408
/// assert_eq!(s.capacity(), cap);
409409
///
410-
/// // ...but this may make the vector reallocate
410+
/// // ...but this may make the string reallocate
411411
/// s.push('a');
412412
/// ```
413413
#[inline]

src/libcore/str/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
//! String manipulation.
44
//!
5-
//! For more details, see the `std::str` module.
5+
//! For more details, see the [`std::str`] module.
6+
//!
7+
//! [`std::str`]: ../../std/str/index.html
68
79
#![stable(feature = "rust1", since = "1.0.0")]
810

src/librustc/dep_graph/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ impl DepGraph {
524524
edge_list_indices.push((start, end));
525525
}
526526

527-
debug_assert!(edge_list_data.len() <= ::std::u32::MAX as usize);
527+
debug_assert!(edge_list_data.len() <= u32::MAX as usize);
528528
debug_assert_eq!(edge_list_data.len(), total_edge_count);
529529

530530
SerializedDepGraph { nodes, fingerprints, edge_list_indices, edge_list_data }

src/librustc/mir/interpret/allocation.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -818,9 +818,9 @@ impl UndefMask {
818818
// First set all bits except the first `bita`,
819819
// then unset the last `64 - bitb` bits.
820820
let range = if bitb == 0 {
821-
u64::max_value() << bita
821+
u64::MAX << bita
822822
} else {
823-
(u64::max_value() << bita) & (u64::max_value() >> (64 - bitb))
823+
(u64::MAX << bita) & (u64::MAX >> (64 - bitb))
824824
};
825825
if new_state {
826826
self.blocks[blocka] |= range;
@@ -832,21 +832,21 @@ impl UndefMask {
832832
// across block boundaries
833833
if new_state {
834834
// Set `bita..64` to `1`.
835-
self.blocks[blocka] |= u64::max_value() << bita;
835+
self.blocks[blocka] |= u64::MAX << bita;
836836
// Set `0..bitb` to `1`.
837837
if bitb != 0 {
838-
self.blocks[blockb] |= u64::max_value() >> (64 - bitb);
838+
self.blocks[blockb] |= u64::MAX >> (64 - bitb);
839839
}
840840
// Fill in all the other blocks (much faster than one bit at a time).
841841
for block in (blocka + 1)..blockb {
842-
self.blocks[block] = u64::max_value();
842+
self.blocks[block] = u64::MAX;
843843
}
844844
} else {
845845
// Set `bita..64` to `0`.
846-
self.blocks[blocka] &= !(u64::max_value() << bita);
846+
self.blocks[blocka] &= !(u64::MAX << bita);
847847
// Set `0..bitb` to `0`.
848848
if bitb != 0 {
849-
self.blocks[blockb] &= !(u64::max_value() >> (64 - bitb));
849+
self.blocks[blockb] &= !(u64::MAX >> (64 - bitb));
850850
}
851851
// Fill in all the other blocks (much faster than one bit at a time).
852852
for block in (blocka + 1)..blockb {

src/librustc/mir/interpret/pointer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ pub trait PointerArithmetic: layout::HasDataLayout {
7878
fn overflowing_signed_offset(&self, val: u64, i: i128) -> (u64, bool) {
7979
// FIXME: is it possible to over/underflow here?
8080
if i < 0 {
81-
// Trickery to ensure that `i64::min_value()` works fine: compute `n = -i`.
81+
// Trickery to ensure that `i64::MIN` works fine: compute `n = -i`.
8282
// This formula only works for true negative values; it overflows for zero!
83-
let n = u64::max_value() - (i as u64) + 1;
83+
let n = u64::MAX - (i as u64) + 1;
8484
let res = val.overflowing_sub(n);
8585
self.truncate_to_ptr(res)
8686
} else {

src/librustc/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ impl<'tcx> TerminatorKind<'tcx> {
11981198
t: BasicBlock,
11991199
f: BasicBlock,
12001200
) -> TerminatorKind<'tcx> {
1201-
static BOOL_SWITCH_FALSE: &'static [u128] = &[0];
1201+
static BOOL_SWITCH_FALSE: &[u128] = &[0];
12021202
TerminatorKind::SwitchInt {
12031203
discr: cond,
12041204
switch_ty: tcx.types.bool,

src/librustc/traits/structural_impls.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,9 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
415415
super::ReferenceOutlivesReferent(ty) => {
416416
tcx.lift(&ty).map(super::ReferenceOutlivesReferent)
417417
}
418-
super::ObjectTypeBound(ty, r) => tcx
419-
.lift(&ty)
420-
.and_then(|ty| tcx.lift(&r).and_then(|r| Some(super::ObjectTypeBound(ty, r)))),
418+
super::ObjectTypeBound(ty, r) => {
419+
tcx.lift(&ty).and_then(|ty| tcx.lift(&r).map(|r| super::ObjectTypeBound(ty, r)))
420+
}
421421
super::ObjectCastObligation(ty) => tcx.lift(&ty).map(super::ObjectCastObligation),
422422
super::Coercion { source, target } => {
423423
Some(super::Coercion { source: tcx.lift(&source)?, target: tcx.lift(&target)? })

src/librustc/ty/layout.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_span::DUMMY_SP;
77

88
use std::cmp;
99
use std::fmt;
10-
use std::i128;
1110
use std::iter;
1211
use std::mem;
1312
use std::ops::Bound;
@@ -1001,7 +1000,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
10011000
}
10021001
}
10031002

1004-
let (mut min, mut max) = (i128::max_value(), i128::min_value());
1003+
let (mut min, mut max) = (i128::MAX, i128::MIN);
10051004
let discr_type = def.repr.discr_type();
10061005
let bits = Integer::from_attr(self, discr_type).size().bits();
10071006
for (i, discr) in def.discriminants(tcx) {
@@ -1021,7 +1020,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
10211020
}
10221021
}
10231022
// We might have no inhabited variants, so pretend there's at least one.
1024-
if (min, max) == (i128::max_value(), i128::min_value()) {
1023+
if (min, max) == (i128::MAX, i128::MIN) {
10251024
min = 0;
10261025
max = 0;
10271026
}

src/librustc/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ pub trait PrettyPrinter<'tcx>:
920920
}
921921
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Uint(ui)) => {
922922
let bit_size = Integer::from_attr(&self.tcx(), UnsignedInt(*ui)).size();
923-
let max = truncate(u128::max_value(), bit_size);
923+
let max = truncate(u128::MAX, bit_size);
924924

925925
let ui_str = ui.name_str();
926926
if data == max {

src/librustc/ty/query/on_disk_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct AbsoluteBytePos(u32);
9292

9393
impl AbsoluteBytePos {
9494
fn new(pos: usize) -> AbsoluteBytePos {
95-
debug_assert!(pos <= ::std::u32::MAX as usize);
95+
debug_assert!(pos <= u32::MAX as usize);
9696
AbsoluteBytePos(pos as u32)
9797
}
9898

src/librustc/ty/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ fn signed_min(size: Size) -> i128 {
5050
}
5151

5252
fn signed_max(size: Size) -> i128 {
53-
i128::max_value() >> (128 - size.bits())
53+
i128::MAX >> (128 - size.bits())
5454
}
5555

5656
fn unsigned_max(size: Size) -> u128 {
57-
u128::max_value() >> (128 - size.bits())
57+
u128::MAX >> (128 - size.bits())
5858
}
5959

6060
fn int_size_and_signed<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> (Size, bool) {
@@ -77,7 +77,7 @@ impl<'tcx> Discr<'tcx> {
7777
let min = signed_min(size);
7878
let max = signed_max(size);
7979
let val = sign_extend(self.val, size) as i128;
80-
assert!(n < (i128::max_value() as u128));
80+
assert!(n < (i128::MAX as u128));
8181
let n = n as i128;
8282
let oflo = val > max - n;
8383
let val = if oflo { min + (n - (max - val) - 1) } else { val + n };

src/librustc_builtin_macros/format.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ impl<'a, 'b> Context<'a, 'b> {
284284
err.tool_only_span_suggestion(
285285
sp,
286286
&format!("use the `{}` trait", name),
287-
fmt.to_string(),
287+
(*fmt).to_string(),
288288
Applicability::MaybeIncorrect,
289289
);
290290
}
@@ -476,7 +476,7 @@ impl<'a, 'b> Context<'a, 'b> {
476476
match ty {
477477
Placeholder(_) => {
478478
// record every (position, type) combination only once
479-
let ref mut seen_ty = self.arg_unique_types[arg];
479+
let seen_ty = &mut self.arg_unique_types[arg];
480480
let i = seen_ty.iter().position(|x| *x == ty).unwrap_or_else(|| {
481481
let i = seen_ty.len();
482482
seen_ty.push(ty);
@@ -526,7 +526,7 @@ impl<'a, 'b> Context<'a, 'b> {
526526

527527
// Map the arguments
528528
for i in 0..args_len {
529-
let ref arg_types = self.arg_types[i];
529+
let arg_types = &self.arg_types[i];
530530
let arg_offsets = arg_types.iter().map(|offset| sofar + *offset).collect::<Vec<_>>();
531531
self.arg_index_map.push(arg_offsets);
532532
sofar += self.arg_unique_types[i].len();
@@ -597,7 +597,7 @@ impl<'a, 'b> Context<'a, 'b> {
597597
let arg_idx = match arg_index_consumed.get_mut(i) {
598598
None => 0, // error already emitted elsewhere
599599
Some(offset) => {
600-
let ref idx_map = self.arg_index_map[i];
600+
let idx_map = &self.arg_index_map[i];
601601
// unwrap_or branch: error already emitted elsewhere
602602
let arg_idx = *idx_map.get(*offset).unwrap_or(&0);
603603
*offset += 1;
@@ -721,7 +721,7 @@ impl<'a, 'b> Context<'a, 'b> {
721721
let name = names_pos[i];
722722
let span = self.ecx.with_def_site_ctxt(e.span);
723723
pats.push(self.ecx.pat_ident(span, name));
724-
for ref arg_ty in self.arg_unique_types[i].iter() {
724+
for arg_ty in self.arg_unique_types[i].iter() {
725725
locals.push(Context::format_arg(self.ecx, self.macsp, e.span, arg_ty, name));
726726
}
727727
heads.push(self.ecx.expr_addr_of(e.span, e));

src/librustc_builtin_macros/global_allocator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ impl AllocFnFactory<'_, '_> {
5757
fn allocator_fn(&self, method: &AllocatorMethod) -> Stmt {
5858
let mut abi_args = Vec::new();
5959
let mut i = 0;
60-
let ref mut mk = || {
60+
let mut mk = || {
6161
let name = self.cx.ident_of(&format!("arg{}", i), self.span);
6262
i += 1;
6363
name
6464
};
65-
let args = method.inputs.iter().map(|ty| self.arg_ty(ty, &mut abi_args, mk)).collect();
65+
let args = method.inputs.iter().map(|ty| self.arg_ty(ty, &mut abi_args, &mut mk)).collect();
6666
let result = self.call_allocator(method.name, args);
6767
let (output_ty, output_expr) = self.ret_ty(&method.output, result);
6868
let decl = self.cx.fn_decl(abi_args, ast::FnRetTy::Ty(output_ty));

src/librustc_builtin_macros/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ fn should_fail(i: &ast::Item) -> bool {
313313
fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
314314
match attr::find_by_name(&i.attrs, sym::should_panic) {
315315
Some(attr) => {
316-
let ref sd = cx.parse_sess.span_diagnostic;
316+
let sd = &cx.parse_sess.span_diagnostic;
317317

318318
match attr.meta_item_list() {
319319
// Handle #[should_panic(expected = "foo")]
@@ -378,7 +378,7 @@ fn test_type(cx: &ExtCtxt<'_>) -> TestType {
378378

379379
fn has_test_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool {
380380
let has_should_panic_attr = attr::contains_name(&i.attrs, sym::should_panic);
381-
let ref sd = cx.parse_sess.span_diagnostic;
381+
let sd = &cx.parse_sess.span_diagnostic;
382382
if let ast::ItemKind::Fn(_, ref sig, ref generics, _) = i.kind {
383383
if let ast::Unsafe::Yes(span) = sig.header.unsafety {
384384
sd.struct_span_err(i.span, "unsafe functions cannot be used for tests")

src/librustc_builtin_macros/test_harness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
326326
/// &[&test1, &test2]
327327
fn mk_tests_slice(cx: &TestCtxt<'_>, sp: Span) -> P<ast::Expr> {
328328
debug!("building test vector from {} tests", cx.test_cases.len());
329-
let ref ecx = cx.ext_cx;
329+
let ecx = &cx.ext_cx;
330330

331331
ecx.expr_vec_slice(
332332
sp,

src/librustc_codegen_llvm/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
6060
.chain(ia.inputs.iter().map(|s| s.to_string()))
6161
.chain(ext_constraints)
6262
.chain(clobbers)
63-
.chain(arch_clobbers.iter().map(|s| s.to_string()))
63+
.chain(arch_clobbers.iter().map(|s| (*s).to_string()))
6464
.collect::<Vec<String>>()
6565
.join(",");
6666

src/librustc_codegen_llvm/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ pub(crate) unsafe fn codegen(
725725
Err(_) => return 0,
726726
};
727727

728-
if let Err(_) = write!(cursor, "{:#}", demangled) {
728+
if write!(cursor, "{:#}", demangled).is_err() {
729729
// Possible only if provided buffer is not big enough
730730
return 0;
731731
}

src/librustc_codegen_llvm/context.rs

-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ pub unsafe fn create_module(
174174

175175
let llvm_data_layout = llvm::LLVMGetDataLayout(llmod);
176176
let llvm_data_layout = str::from_utf8(CStr::from_ptr(llvm_data_layout).to_bytes())
177-
.ok()
178177
.expect("got a non-UTF8 data-layout from LLVM");
179178

180179
// Unfortunately LLVM target specs change over time, and right now we

src/librustc_codegen_ssa/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
12571257
if main_thread_worker_state == MainThreadWorkerState::Idle {
12581258
if !queue_full_enough(work_items.len(), running, max_workers) {
12591259
// The queue is not full enough, codegen more items:
1260-
if let Err(_) = codegen_worker_send.send(Message::CodegenItem) {
1260+
if codegen_worker_send.send(Message::CodegenItem).is_err() {
12611261
panic!("Could not send Message::CodegenItem to main thread")
12621262
}
12631263
main_thread_worker_state = MainThreadWorkerState::Codegenning;
+12-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
Auto traits cannot have methods or associated items.
2-
For more information see the [opt-in builtin traits RFC][RFC 19].
1+
An auto trait was declared with a method or an associated item.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0380
6+
unsafe auto trait Trait {
7+
type Output; // error!
8+
}
9+
```
10+
11+
Auto traits cannot have methods or associated items. For more information see
12+
the [opt-in builtin traits RFC][RFC 19].
313

414
[RFC 19]: https://github.com/rust-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md

src/librustc_error_codes/error_codes/E0382.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
This error occurs when an attempt is made to use a variable after its contents
2-
have been moved elsewhere.
1+
A variable was used after its contents have been moved elsewhere.
32

43
Erroneous code example:
54

src/librustc_error_codes/error_codes/E0384.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This error occurs when an attempt is made to reassign an immutable variable.
1+
An immutable variable was reassigned.
22

33
Erroneous code example:
44

src/librustc_errors/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl CodeSuggestion {
163163
None => buf.push_str(&line[lo..]),
164164
}
165165
}
166-
if let None = hi_opt {
166+
if hi_opt.is_none() {
167167
buf.push('\n');
168168
}
169169
}

src/librustc_errors/registry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ impl Registry {
2727
if !self.long_descriptions.contains_key(code) {
2828
return Err(InvalidErrorCode);
2929
}
30-
Ok(self.long_descriptions.get(code).unwrap().clone())
30+
Ok(*self.long_descriptions.get(code).unwrap())
3131
}
3232
}

src/librustc_incremental/persist/dirty_clean.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,8 @@ impl DirtyCleanVisitor<'tcx> {
343343
&format!("clean/dirty auto-assertions not yet defined for {:?}", node),
344344
),
345345
};
346-
let labels = Labels::from_iter(labels.iter().flat_map(|s| s.iter().map(|l| l.to_string())));
346+
let labels =
347+
Labels::from_iter(labels.iter().flat_map(|s| s.iter().map(|l| (*l).to_string())));
347348
(name, labels)
348349
}
349350

src/librustc_infer/traits/auto_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
150150
// SelectionContext to return it back to us.
151151

152152
let (new_env, user_env) = match self.evaluate_predicates(
153-
&mut infcx,
153+
&infcx,
154154
trait_did,
155155
ty,
156156
orig_env,

src/librustc_infer/traits/select.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13411341
stack: &TraitObligationStack<'o, 'tcx>,
13421342
) -> Result<SelectionCandidateSet<'tcx>, SelectionError<'tcx>> {
13431343
let TraitObligationStack { obligation, .. } = *stack;
1344-
let ref obligation = Obligation {
1344+
let obligation = &Obligation {
13451345
param_env: obligation.param_env,
13461346
cause: obligation.cause.clone(),
13471347
recursion_depth: obligation.recursion_depth,

src/librustc_interface/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ pub(crate) fn check_attr_crate_type(attrs: &[ast::Attribute], lint_buffer: &mut
426426
for a in attrs.iter() {
427427
if a.check_name(sym::crate_type) {
428428
if let Some(n) = a.value_str() {
429-
if let Some(_) = categorize_crate_type(n) {
429+
if categorize_crate_type(n).is_some() {
430430
return;
431431
}
432432

0 commit comments

Comments
 (0)