diff --git a/src/doc/embedded-book b/src/doc/embedded-book index b2e1092bf67bd..b81ffb7a6f4c5 160000 --- a/src/doc/embedded-book +++ b/src/doc/embedded-book @@ -1 +1 @@ -Subproject commit b2e1092bf67bd4d7686c4553f186edbb7f5f92db +Subproject commit b81ffb7a6f4c5aaed92786e770e99db116aa4ebd diff --git a/src/doc/nomicon b/src/doc/nomicon index 3e6e1001dc6e0..9f797e65e6bcc 160000 --- a/src/doc/nomicon +++ b/src/doc/nomicon @@ -1 +1 @@ -Subproject commit 3e6e1001dc6e095dbd5c88005e80969f60e384e1 +Subproject commit 9f797e65e6bcc79419975b17aff8e21c9adc039f diff --git a/src/doc/reference b/src/doc/reference index 64239df6d1735..559e09caa9661 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit 64239df6d173562b9deb4f012e4c3e6e960c4754 +Subproject commit 559e09caa9661043744cf7af7bd88432d966f743 diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index 32facd5522ddb..db57f899ea2a5 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit 32facd5522ddbbf37baf01e4e4b6562bc55c071a +Subproject commit db57f899ea2a56a544c8d280cbf033438666273d diff --git a/src/librustc/dep_graph/graph.rs b/src/librustc/dep_graph/graph.rs index 33902fe913a9c..d5cde7034116c 100644 --- a/src/librustc/dep_graph/graph.rs +++ b/src/librustc/dep_graph/graph.rs @@ -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 } diff --git a/src/librustc/mir/interpret/allocation.rs b/src/librustc/mir/interpret/allocation.rs index d3efe62e8c153..c8d35db0adeb2 100644 --- a/src/librustc/mir/interpret/allocation.rs +++ b/src/librustc/mir/interpret/allocation.rs @@ -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; @@ -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 { diff --git a/src/librustc/mir/interpret/pointer.rs b/src/librustc/mir/interpret/pointer.rs index a4974fb541b6b..cc3c50b7899f3 100644 --- a/src/librustc/mir/interpret/pointer.rs +++ b/src/librustc/mir/interpret/pointer.rs @@ -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 { diff --git a/src/librustc/traits/structural_impls.rs b/src/librustc/traits/structural_impls.rs index f9c8b01571e04..63d7124ee91f9 100644 --- a/src/librustc/traits/structural_impls.rs +++ b/src/librustc/traits/structural_impls.rs @@ -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)? }) diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index f1b4b828c71fa..7a5a417919d50 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -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; @@ -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) { @@ -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; } diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index 3bf92552c8624..4829955cb70c4 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -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 { diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs index 109ac97fe6265..5e36e4df698ed 100644 --- a/src/librustc/ty/query/on_disk_cache.rs +++ b/src/librustc/ty/query/on_disk_cache.rs @@ -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) } diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index 7b1f821877baa..62d2b4ae20397 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -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) { @@ -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 }; diff --git a/src/librustc_codegen_llvm/back/write.rs b/src/librustc_codegen_llvm/back/write.rs index a215ef81bc9eb..0c243128104e7 100644 --- a/src/librustc_codegen_llvm/back/write.rs +++ b/src/librustc_codegen_llvm/back/write.rs @@ -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; } diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index 46f461b98c8de..3466363ac7972 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -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 diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs index 76728e9840616..b313bf57d4a9a 100644 --- a/src/librustc_codegen_ssa/back/write.rs +++ b/src/librustc_codegen_ssa/back/write.rs @@ -1257,7 +1257,7 @@ fn start_executing_work( 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; diff --git a/src/librustc_error_codes/error_codes/E0380.md b/src/librustc_error_codes/error_codes/E0380.md index fe5de56933963..638f0c8ecc65f 100644 --- a/src/librustc_error_codes/error_codes/E0380.md +++ b/src/librustc_error_codes/error_codes/E0380.md @@ -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 diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 5b00087de6fb7..f0e388a597b40 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -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'); } } diff --git a/src/librustc_errors/registry.rs b/src/librustc_errors/registry.rs index c92a9d04775d1..32700c6500bc8 100644 --- a/src/librustc_errors/registry.rs +++ b/src/librustc_errors/registry.rs @@ -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()) } } diff --git a/src/librustc_interface/util.rs b/src/librustc_interface/util.rs index 10a8c0a63f188..7866ddbd4ccd8 100644 --- a/src/librustc_interface/util.rs +++ b/src/librustc_interface/util.rs @@ -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; } diff --git a/src/librustc_lint/context.rs b/src/librustc_lint/context.rs index 29a6b8c693ff3..a6e8a0ab9301c 100644 --- a/src/librustc_lint/context.rs +++ b/src/librustc_lint/context.rs @@ -335,7 +335,7 @@ impl LintStore { lint_name.to_string() }; // If the lint was scoped with `tool::` check if the tool lint exists - if let Some(_) = tool_name { + if tool_name.is_some() { match self.by_name.get(&complete_name) { None => match self.lint_groups.get(&*complete_name) { None => return CheckLintNameResult::Tool(Err((None, String::new()))), diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index f4e1bce462f55..652de6c7b6fdf 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -1905,7 +1905,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // expressions evaluate through `as_temp` or `into` a return // slot or local, so to find all unsized rvalues it is enough // to check all temps, return slots and locals. - if let None = self.reported_errors.replace((ty, span)) { + if self.reported_errors.replace((ty, span)).is_none() { let mut diag = struct_span_err!( self.tcx().sess, span, diff --git a/src/librustc_mir/borrow_check/type_check/relate_tys.rs b/src/librustc_mir/borrow_check/type_check/relate_tys.rs index 31507a184d8f9..b0f048ff1a6fd 100644 --- a/src/librustc_mir/borrow_check/type_check/relate_tys.rs +++ b/src/librustc_mir/borrow_check/type_check/relate_tys.rs @@ -64,7 +64,7 @@ impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx> { } fn next_existential_region_var(&mut self, from_forall: bool) -> ty::Region<'tcx> { - if let Some(_) = &mut self.borrowck_context { + if self.borrowck_context.is_some() { let origin = NLLRegionVariableOrigin::Existential { from_forall }; self.infcx.next_nll_region_var(origin) } else { diff --git a/src/librustc_mir/dataflow/generic/engine.rs b/src/librustc_mir/dataflow/generic/engine.rs index 1487129f6c77c..8d800f2d0ba05 100644 --- a/src/librustc_mir/dataflow/generic/engine.rs +++ b/src/librustc_mir/dataflow/generic/engine.rs @@ -239,23 +239,26 @@ where } SwitchInt { ref targets, ref values, ref discr, .. } => { - // If this is a switch on an enum discriminant, a custom effect may be applied - // along each outgoing edge. - if let Some(place) = discr.place() { - let enum_def = switch_on_enum_discriminant(self.tcx, self.body, bb_data, place); - if let Some(enum_def) = enum_def { + let Engine { tcx, body, .. } = *self; + let enum_ = discr + .place() + .and_then(|discr| switch_on_enum_discriminant(tcx, body, bb_data, discr)); + match enum_ { + // If this is a switch on an enum discriminant, a custom effect may be applied + // along each outgoing edge. + Some((enum_place, enum_def)) => { self.propagate_bits_into_enum_discriminant_switch_successors( - in_out, bb, enum_def, place, dirty_list, &*values, &*targets, + in_out, bb, enum_def, enum_place, dirty_list, &*values, &*targets, ); - - return; } - } - // Otherwise, it's just a normal `SwitchInt`, and every successor sees the same - // exit state. - for target in targets.iter().copied() { - self.propagate_bits_into_entry_set_for(&in_out, target, dirty_list); + // Otherwise, it's just a normal `SwitchInt`, and every successor sees the same + // exit state. + None => { + for target in targets.iter().copied() { + self.propagate_bits_into_entry_set_for(&in_out, target, dirty_list); + } + } } } @@ -342,22 +345,27 @@ where } } -/// Look at the last statement of a block that ends with to see if it is an assignment of an enum -/// discriminant to the local that determines the target of a `SwitchInt` like so: -/// _42 = discriminant(..) +/// Inspect a `SwitchInt`-terminated basic block to see if the condition of that `SwitchInt` is +/// an enum discriminant. +/// +/// We expect such blocks to have a call to `discriminant` as their last statement like so: +/// _42 = discriminant(_1) /// SwitchInt(_42, ..) +/// +/// If the basic block matches this pattern, this function returns the place corresponding to the +/// enum (`_1` in the example above) as well as the `AdtDef` of that enum. fn switch_on_enum_discriminant( tcx: TyCtxt<'tcx>, - body: &mir::Body<'tcx>, - block: &mir::BasicBlockData<'tcx>, + body: &'mir mir::Body<'tcx>, + block: &'mir mir::BasicBlockData<'tcx>, switch_on: &mir::Place<'tcx>, -) -> Option<&'tcx ty::AdtDef> { +) -> Option<(&'mir mir::Place<'tcx>, &'tcx ty::AdtDef)> { match block.statements.last().map(|stmt| &stmt.kind) { Some(mir::StatementKind::Assign(box (lhs, mir::Rvalue::Discriminant(discriminated)))) if lhs == switch_on => { match &discriminated.ty(body, tcx).ty.kind { - ty::Adt(def, _) => Some(def), + ty::Adt(def, _) => Some((discriminated, def)), // `Rvalue::Discriminant` is also used to get the active yield point for a // generator, but we do not need edge-specific effects in that case. This may diff --git a/src/librustc_mir/dataflow/mod.rs b/src/librustc_mir/dataflow/mod.rs index 25463f31867df..b4e33b9502e69 100644 --- a/src/librustc_mir/dataflow/mod.rs +++ b/src/librustc_mir/dataflow/mod.rs @@ -16,7 +16,6 @@ use std::borrow::Borrow; use std::fmt; use std::io; use std::path::PathBuf; -use std::usize; pub use self::at_location::{FlowAtLocation, FlowsAtLocation}; pub(crate) use self::drop_flag_effects::*; diff --git a/src/librustc_mir/interpret/intrinsics.rs b/src/librustc_mir/interpret/intrinsics.rs index d63abdc356234..891afbf437f2b 100644 --- a/src/librustc_mir/interpret/intrinsics.rs +++ b/src/librustc_mir/interpret/intrinsics.rs @@ -203,7 +203,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { if is_add { // max unsigned Scalar::from_uint( - u128::max_value() >> (128 - num_bits), + u128::MAX >> (128 - num_bits), Size::from_bits(num_bits), ) } else { @@ -381,11 +381,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { dest: PlaceTy<'tcx, M::PointerTag>, ) -> InterpResult<'tcx> { // Performs an exact division, resulting in undefined behavior where - // `x % y != 0` or `y == 0` or `x == T::min_value() && y == -1`. + // `x % y != 0` or `y == 0` or `x == T::MIN && y == -1`. // First, check x % y != 0 (or if that computation overflows). let (res, overflow, _ty) = self.overflowing_binary_op(BinOp::Rem, a, b)?; if overflow || res.assert_bits(a.layout.size) != 0 { - // Then, check if `b` is -1, which is the "min_value / -1" case. + // Then, check if `b` is -1, which is the "MIN / -1" case. let minus1 = Scalar::from_int(-1, dest.layout.size); let b_scalar = b.to_scalar().unwrap(); if b_scalar == minus1 { diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index 6517ae5d0f30f..3c4a1857f9690 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -565,7 +565,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { // # Function pointers // (both global from `alloc_map` and local from `extra_fn_ptr_map`) - if let Some(_) = self.get_fn_alloc(id) { + if self.get_fn_alloc(id).is_some() { return if let AllocCheck::Dereferenceable = liveness { // The caller requested no function pointers. throw_unsup!(DerefFunctionPointer) diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index 731dcc6a25f14..4f99bfe8a852a 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -463,7 +463,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M let (lo, hi) = valid_range.clone().into_inner(); // Determine the allowed range // `max_hi` is as big as the size fits - let max_hi = u128::max_value() >> (128 - op.layout.size.bits()); + let max_hi = u128::MAX >> (128 - op.layout.size.bits()); assert!(hi <= max_hi); // We could also write `(hi + 1) % (max_hi + 1) == lo` but `max_hi + 1` overflows for `u128` if (lo == 0 && hi == max_hi) || (hi + 1 == lo) { diff --git a/src/librustc_parse/parser/attr.rs b/src/librustc_parse/parser/attr.rs index c5f8b2dd862a5..2dccb04f6cce1 100644 --- a/src/librustc_parse/parser/attr.rs +++ b/src/librustc_parse/parser/attr.rs @@ -37,7 +37,7 @@ impl<'a> Parser<'a> { let inner_parse_policy = InnerAttributeParsePolicy::NotPermitted { reason: inner_error_reason, saw_doc_comment: just_parsed_doc_comment, - prev_attr_sp: attrs.last().and_then(|a| Some(a.span)), + prev_attr_sp: attrs.last().map(|a| a.span), }; let attr = self.parse_attribute_with_inner_parse_policy(inner_parse_policy)?; attrs.push(attr); diff --git a/src/librustc_passes/entry.rs b/src/librustc_passes/entry.rs index f2239ad16eeb3..86596e205562e 100644 --- a/src/librustc_passes/entry.rs +++ b/src/librustc_passes/entry.rs @@ -196,7 +196,7 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) { // The file may be empty, which leads to the diagnostic machinery not emitting this // note. This is a relatively simple way to detect that case and emit a span-less // note instead. - if let Ok(_) = tcx.sess.source_map().lookup_line(sp.lo()) { + if tcx.sess.source_map().lookup_line(sp.lo()).is_ok() { err.set_span(sp); err.span_label(sp, ¬e); } else { diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index 817a276ff3e73..fd62c80293425 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -1086,7 +1086,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { for param in params { if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(param.span) { - if snippet.starts_with("&") && !snippet.starts_with("&'") { + if snippet.starts_with('&') && !snippet.starts_with("&'") { introduce_suggestion .push((param.span, format!("&'a {}", &snippet[1..]))); } else if snippet.starts_with("&'_ ") { @@ -1118,7 +1118,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { (1, Some(name), Some("'_")) => { suggest_existing(err, name.to_string()); } - (1, Some(name), Some(snippet)) if !snippet.ends_with(">") => { + (1, Some(name), Some(snippet)) if !snippet.ends_with('>') => { suggest_existing(err, format!("{}<{}>", snippet, name)); } (0, _, Some("&")) => { @@ -1127,7 +1127,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { (0, _, Some("'_")) => { suggest_new(err, "'a"); } - (0, _, Some(snippet)) if !snippet.ends_with(">") => { + (0, _, Some(snippet)) if !snippet.ends_with('>') => { suggest_new(err, &format!("{}<'a>", snippet)); } _ => { diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index a52cabd889477..58354c891a2b3 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -1551,21 +1551,18 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { let method_names = pcx.candidate_method_names(); pcx.allow_similar_names = false; - let applicable_close_candidates: Vec = - method_names - .iter() - .filter_map(|&method_name| { - pcx.reset(); - pcx.method_name = Some(method_name); - pcx.assemble_inherent_candidates(); - pcx.assemble_extension_candidates_for_traits_in_scope(hir::DUMMY_HIR_ID) - .map_or(None, |_| { - pcx.pick_core() - .and_then(|pick| pick.ok()) - .and_then(|pick| Some(pick.item)) - }) - }) - .collect(); + let applicable_close_candidates: Vec = method_names + .iter() + .filter_map(|&method_name| { + pcx.reset(); + pcx.method_name = Some(method_name); + pcx.assemble_inherent_candidates(); + pcx.assemble_extension_candidates_for_traits_in_scope(hir::DUMMY_HIR_ID) + .map_or(None, |_| { + pcx.pick_core().and_then(|pick| pick.ok()).map(|pick| pick.item) + }) + }) + .collect(); if applicable_close_candidates.is_empty() { Ok(None) diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 99e3d731d0d6f..21e3d24cc968b 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -121,9 +121,7 @@ pub fn external_generic_args( let args: Vec<_> = substs .iter() .filter_map(|kind| match kind.unpack() { - GenericArgKind::Lifetime(lt) => { - lt.clean(cx).and_then(|lt| Some(GenericArg::Lifetime(lt))) - } + GenericArgKind::Lifetime(lt) => lt.clean(cx).map(|lt| GenericArg::Lifetime(lt)), GenericArgKind::Type(_) if skip_self => { skip_self = false; None diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index ed007fe383c1d..788cc9866155c 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -296,7 +296,7 @@ impl<'a, I: Iterator>> Iterator for CodeBlocks<'_, 'a, I> { "" } )), - playground_button.as_ref().map(String::as_str), + playground_button.as_deref(), Some((s1.as_str(), s2)), )); Some(Event::Html(s.into())) @@ -315,7 +315,7 @@ impl<'a, I: Iterator>> Iterator for CodeBlocks<'_, 'a, I> { "" } )), - playground_button.as_ref().map(String::as_str), + playground_button.as_deref(), None, )); Some(Event::Html(s.into())) diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 9e1ac8754d9b0..7fd7de56f4615 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -185,7 +185,7 @@ macro_rules! eprintln { /// builds or when debugging in release mode is significantly faster. /// /// Note that the macro is intended as a debugging tool and therefore you -/// should avoid having uses of it in version control for longer periods. +/// should avoid having uses of it in version control for long periods. /// Use cases involving debug output that should be added to version control /// are better served by macros such as [`debug!`] from the [`log`] crate. /// diff --git a/src/test/mir-opt/no-drop-for-inactive-variant.rs b/src/test/mir-opt/no-drop-for-inactive-variant.rs new file mode 100644 index 0000000000000..cccfa2e1d41af --- /dev/null +++ b/src/test/mir-opt/no-drop-for-inactive-variant.rs @@ -0,0 +1,41 @@ +// Ensure that there are no drop terminators in `unwrap` (except the one along the cleanup +// path). + +fn unwrap(opt: Option) -> T { + match opt { + Some(x) => x, + None => panic!(), + } +} + +fn main() { + let _ = unwrap(Some(1i32)); +} + +// END RUST SOURCE +// START rustc.unwrap.SimplifyCfg-elaborate-drops.after.mir +// fn unwrap(_1: std::option::Option) -> T { +// ... +// bb0: { +// ... +// switchInt(move _2) -> [0isize: bb2, 1isize: bb4, otherwise: bb3]; +// } +// bb1 (cleanup): { +// resume; +// } +// bb2: { +// ... +// const std::rt::begin_panic::<&'static str>(const "explicit panic") -> bb5; +// } +// bb3: { +// unreachable; +// } +// bb4: { +// ... +// return; +// } +// bb5 (cleanup): { +// drop(_1) -> bb1; +// } +// } +// END rustc.unwrap.SimplifyCfg-elaborate-drops.after.mir