Skip to content

Commit

Permalink
Auto merge of #69746 - Dylan-DPC:rollup-wr6dvdk, r=Dylan-DPC
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Mar 5, 2020
2 parents 96bb8b3 + 80c8434 commit b818ccc
Show file tree
Hide file tree
Showing 57 changed files with 128 additions and 129 deletions.
2 changes: 1 addition & 1 deletion src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ impl String {
///
/// assert_eq!(s.capacity(), cap);
///
/// // ...but this may make the vector reallocate
/// // ...but this may make the string reallocate
/// s.push('a');
/// ```
#[inline]
Expand Down
4 changes: 3 additions & 1 deletion src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

//! String manipulation.
//!
//! For more details, see the `std::str` module.
//! For more details, see the [`std::str`] module.
//!
//! [`std::str`]: ../../std/str/index.html

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ impl DepGraph {
edge_list_indices.push((start, end));
}

debug_assert!(edge_list_data.len() <= ::std::u32::MAX as usize);
debug_assert!(edge_list_data.len() <= u32::MAX as usize);
debug_assert_eq!(edge_list_data.len(), total_edge_count);

SerializedDepGraph { nodes, fingerprints, edge_list_indices, edge_list_data }
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/mir/interpret/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,9 +818,9 @@ impl UndefMask {
// First set all bits except the first `bita`,
// then unset the last `64 - bitb` bits.
let range = if bitb == 0 {
u64::max_value() << bita
u64::MAX << bita
} else {
(u64::max_value() << bita) & (u64::max_value() >> (64 - bitb))
(u64::MAX << bita) & (u64::MAX >> (64 - bitb))
};
if new_state {
self.blocks[blocka] |= range;
Expand All @@ -832,21 +832,21 @@ impl UndefMask {
// across block boundaries
if new_state {
// Set `bita..64` to `1`.
self.blocks[blocka] |= u64::max_value() << bita;
self.blocks[blocka] |= u64::MAX << bita;
// Set `0..bitb` to `1`.
if bitb != 0 {
self.blocks[blockb] |= u64::max_value() >> (64 - bitb);
self.blocks[blockb] |= u64::MAX >> (64 - bitb);
}
// Fill in all the other blocks (much faster than one bit at a time).
for block in (blocka + 1)..blockb {
self.blocks[block] = u64::max_value();
self.blocks[block] = u64::MAX;
}
} else {
// Set `bita..64` to `0`.
self.blocks[blocka] &= !(u64::max_value() << bita);
self.blocks[blocka] &= !(u64::MAX << bita);
// Set `0..bitb` to `0`.
if bitb != 0 {
self.blocks[blockb] &= !(u64::max_value() >> (64 - bitb));
self.blocks[blockb] &= !(u64::MAX >> (64 - bitb));
}
// Fill in all the other blocks (much faster than one bit at a time).
for block in (blocka + 1)..blockb {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/mir/interpret/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ pub trait PointerArithmetic: layout::HasDataLayout {
fn overflowing_signed_offset(&self, val: u64, i: i128) -> (u64, bool) {
// FIXME: is it possible to over/underflow here?
if i < 0 {
// Trickery to ensure that `i64::min_value()` works fine: compute `n = -i`.
// Trickery to ensure that `i64::MIN` works fine: compute `n = -i`.
// This formula only works for true negative values; it overflows for zero!
let n = u64::max_value() - (i as u64) + 1;
let n = u64::MAX - (i as u64) + 1;
let res = val.overflowing_sub(n);
self.truncate_to_ptr(res)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ impl<'tcx> TerminatorKind<'tcx> {
t: BasicBlock,
f: BasicBlock,
) -> TerminatorKind<'tcx> {
static BOOL_SWITCH_FALSE: &'static [u128] = &[0];
static BOOL_SWITCH_FALSE: &[u128] = &[0];
TerminatorKind::SwitchInt {
discr: cond,
switch_ty: tcx.types.bool,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/traits/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
super::ReferenceOutlivesReferent(ty) => {
tcx.lift(&ty).map(super::ReferenceOutlivesReferent)
}
super::ObjectTypeBound(ty, r) => tcx
.lift(&ty)
.and_then(|ty| tcx.lift(&r).and_then(|r| Some(super::ObjectTypeBound(ty, r)))),
super::ObjectTypeBound(ty, r) => {
tcx.lift(&ty).and_then(|ty| tcx.lift(&r).map(|r| super::ObjectTypeBound(ty, r)))
}
super::ObjectCastObligation(ty) => tcx.lift(&ty).map(super::ObjectCastObligation),
super::Coercion { source, target } => {
Some(super::Coercion { source: tcx.lift(&source)?, target: tcx.lift(&target)? })
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use rustc_span::DUMMY_SP;

use std::cmp;
use std::fmt;
use std::i128;
use std::iter;
use std::mem;
use std::ops::Bound;
Expand Down Expand Up @@ -1001,7 +1000,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
}
}

let (mut min, mut max) = (i128::max_value(), i128::min_value());
let (mut min, mut max) = (i128::MAX, i128::MIN);
let discr_type = def.repr.discr_type();
let bits = Integer::from_attr(self, discr_type).size().bits();
for (i, discr) in def.discriminants(tcx) {
Expand All @@ -1021,7 +1020,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
}
}
// We might have no inhabited variants, so pretend there's at least one.
if (min, max) == (i128::max_value(), i128::min_value()) {
if (min, max) == (i128::MAX, i128::MIN) {
min = 0;
max = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ pub trait PrettyPrinter<'tcx>:
}
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Uint(ui)) => {
let bit_size = Integer::from_attr(&self.tcx(), UnsignedInt(*ui)).size();
let max = truncate(u128::max_value(), bit_size);
let max = truncate(u128::MAX, bit_size);

let ui_str = ui.name_str();
if data == max {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct AbsoluteBytePos(u32);

impl AbsoluteBytePos {
fn new(pos: usize) -> AbsoluteBytePos {
debug_assert!(pos <= ::std::u32::MAX as usize);
debug_assert!(pos <= u32::MAX as usize);
AbsoluteBytePos(pos as u32)
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ fn signed_min(size: Size) -> i128 {
}

fn signed_max(size: Size) -> i128 {
i128::max_value() >> (128 - size.bits())
i128::MAX >> (128 - size.bits())
}

fn unsigned_max(size: Size) -> u128 {
u128::max_value() >> (128 - size.bits())
u128::MAX >> (128 - size.bits())
}

fn int_size_and_signed<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> (Size, bool) {
Expand All @@ -77,7 +77,7 @@ impl<'tcx> Discr<'tcx> {
let min = signed_min(size);
let max = signed_max(size);
let val = sign_extend(self.val, size) as i128;
assert!(n < (i128::max_value() as u128));
assert!(n < (i128::MAX as u128));
let n = n as i128;
let oflo = val > max - n;
let val = if oflo { min + (n - (max - val) - 1) } else { val + n };
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_builtin_macros/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ impl<'a, 'b> Context<'a, 'b> {
err.tool_only_span_suggestion(
sp,
&format!("use the `{}` trait", name),
fmt.to_string(),
(*fmt).to_string(),
Applicability::MaybeIncorrect,
);
}
Expand Down Expand Up @@ -476,7 +476,7 @@ impl<'a, 'b> Context<'a, 'b> {
match ty {
Placeholder(_) => {
// record every (position, type) combination only once
let ref mut seen_ty = self.arg_unique_types[arg];
let seen_ty = &mut self.arg_unique_types[arg];
let i = seen_ty.iter().position(|x| *x == ty).unwrap_or_else(|| {
let i = seen_ty.len();
seen_ty.push(ty);
Expand Down Expand Up @@ -526,7 +526,7 @@ impl<'a, 'b> Context<'a, 'b> {

// Map the arguments
for i in 0..args_len {
let ref arg_types = self.arg_types[i];
let arg_types = &self.arg_types[i];
let arg_offsets = arg_types.iter().map(|offset| sofar + *offset).collect::<Vec<_>>();
self.arg_index_map.push(arg_offsets);
sofar += self.arg_unique_types[i].len();
Expand Down Expand Up @@ -597,7 +597,7 @@ impl<'a, 'b> Context<'a, 'b> {
let arg_idx = match arg_index_consumed.get_mut(i) {
None => 0, // error already emitted elsewhere
Some(offset) => {
let ref idx_map = self.arg_index_map[i];
let idx_map = &self.arg_index_map[i];
// unwrap_or branch: error already emitted elsewhere
let arg_idx = *idx_map.get(*offset).unwrap_or(&0);
*offset += 1;
Expand Down Expand Up @@ -721,7 +721,7 @@ impl<'a, 'b> Context<'a, 'b> {
let name = names_pos[i];
let span = self.ecx.with_def_site_ctxt(e.span);
pats.push(self.ecx.pat_ident(span, name));
for ref arg_ty in self.arg_unique_types[i].iter() {
for arg_ty in self.arg_unique_types[i].iter() {
locals.push(Context::format_arg(self.ecx, self.macsp, e.span, arg_ty, name));
}
heads.push(self.ecx.expr_addr_of(e.span, e));
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_builtin_macros/global_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ impl AllocFnFactory<'_, '_> {
fn allocator_fn(&self, method: &AllocatorMethod) -> Stmt {
let mut abi_args = Vec::new();
let mut i = 0;
let ref mut mk = || {
let mut mk = || {
let name = self.cx.ident_of(&format!("arg{}", i), self.span);
i += 1;
name
};
let args = method.inputs.iter().map(|ty| self.arg_ty(ty, &mut abi_args, mk)).collect();
let args = method.inputs.iter().map(|ty| self.arg_ty(ty, &mut abi_args, &mut mk)).collect();
let result = self.call_allocator(method.name, args);
let (output_ty, output_expr) = self.ret_ty(&method.output, result);
let decl = self.cx.fn_decl(abi_args, ast::FnRetTy::Ty(output_ty));
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_builtin_macros/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ fn should_fail(i: &ast::Item) -> bool {
fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
match attr::find_by_name(&i.attrs, sym::should_panic) {
Some(attr) => {
let ref sd = cx.parse_sess.span_diagnostic;
let sd = &cx.parse_sess.span_diagnostic;

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

fn has_test_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool {
let has_should_panic_attr = attr::contains_name(&i.attrs, sym::should_panic);
let ref sd = cx.parse_sess.span_diagnostic;
let sd = &cx.parse_sess.span_diagnostic;
if let ast::ItemKind::Fn(_, ref sig, ref generics, _) = i.kind {
if let ast::Unsafe::Yes(span) = sig.header.unsafety {
sd.struct_span_err(i.span, "unsafe functions cannot be used for tests")
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_builtin_macros/test_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
/// &[&test1, &test2]
fn mk_tests_slice(cx: &TestCtxt<'_>, sp: Span) -> P<ast::Expr> {
debug!("building test vector from {} tests", cx.test_cases.len());
let ref ecx = cx.ext_cx;
let ecx = &cx.ext_cx;

ecx.expr_vec_slice(
sp,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
.chain(ia.inputs.iter().map(|s| s.to_string()))
.chain(ext_constraints)
.chain(clobbers)
.chain(arch_clobbers.iter().map(|s| s.to_string()))
.chain(arch_clobbers.iter().map(|s| (*s).to_string()))
.collect::<Vec<String>>()
.join(",");

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ pub(crate) unsafe fn codegen(
Err(_) => return 0,
};

if let Err(_) = write!(cursor, "{:#}", demangled) {
if write!(cursor, "{:#}", demangled).is_err() {
// Possible only if provided buffer is not big enough
return 0;
}
Expand Down
1 change: 0 additions & 1 deletion src/librustc_codegen_llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ pub unsafe fn create_module(

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

// Unfortunately LLVM target specs change over time, and right now we
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
if main_thread_worker_state == MainThreadWorkerState::Idle {
if !queue_full_enough(work_items.len(), running, max_workers) {
// The queue is not full enough, codegen more items:
if let Err(_) = codegen_worker_send.send(Message::CodegenItem) {
if codegen_worker_send.send(Message::CodegenItem).is_err() {
panic!("Could not send Message::CodegenItem to main thread")
}
main_thread_worker_state = MainThreadWorkerState::Codegenning;
Expand Down
14 changes: 12 additions & 2 deletions src/librustc_error_codes/error_codes/E0380.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
Auto traits cannot have methods or associated items.
For more information see the [opt-in builtin traits RFC][RFC 19].
An auto trait was declared with a method or an associated item.

Erroneous code example:

```compile_fail,E0380
unsafe auto trait Trait {
type Output; // error!
}
```

Auto traits cannot have methods or associated items. For more information see
the [opt-in builtin traits RFC][RFC 19].

[RFC 19]: https://github.com/rust-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md
3 changes: 1 addition & 2 deletions src/librustc_error_codes/error_codes/E0382.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
This error occurs when an attempt is made to use a variable after its contents
have been moved elsewhere.
A variable was used after its contents have been moved elsewhere.

Erroneous code example:

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0384.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This error occurs when an attempt is made to reassign an immutable variable.
An immutable variable was reassigned.

Erroneous code example:

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl CodeSuggestion {
None => buf.push_str(&line[lo..]),
}
}
if let None = hi_opt {
if hi_opt.is_none() {
buf.push('\n');
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_errors/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ impl Registry {
if !self.long_descriptions.contains_key(code) {
return Err(InvalidErrorCode);
}
Ok(self.long_descriptions.get(code).unwrap().clone())
Ok(*self.long_descriptions.get(code).unwrap())
}
}
3 changes: 2 additions & 1 deletion src/librustc_incremental/persist/dirty_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ impl DirtyCleanVisitor<'tcx> {
&format!("clean/dirty auto-assertions not yet defined for {:?}", node),
),
};
let labels = Labels::from_iter(labels.iter().flat_map(|s| s.iter().map(|l| l.to_string())));
let labels =
Labels::from_iter(labels.iter().flat_map(|s| s.iter().map(|l| (*l).to_string())));
(name, labels)
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/traits/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
// SelectionContext to return it back to us.

let (new_env, user_env) = match self.evaluate_predicates(
&mut infcx,
&infcx,
trait_did,
ty,
orig_env,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
stack: &TraitObligationStack<'o, 'tcx>,
) -> Result<SelectionCandidateSet<'tcx>, SelectionError<'tcx>> {
let TraitObligationStack { obligation, .. } = *stack;
let ref obligation = Obligation {
let obligation = &Obligation {
param_env: obligation.param_env,
cause: obligation.cause.clone(),
recursion_depth: obligation.recursion_depth,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_interface/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ pub(crate) fn check_attr_crate_type(attrs: &[ast::Attribute], lint_buffer: &mut
for a in attrs.iter() {
if a.check_name(sym::crate_type) {
if let Some(n) = a.value_str() {
if let Some(_) = categorize_crate_type(n) {
if categorize_crate_type(n).is_some() {
return;
}

Expand Down
Loading

0 comments on commit b818ccc

Please sign in to comment.