Skip to content

Commit

Permalink
Auto merge of #81165 - KodrAus:rollup-s7llxis, r=KodrAus
Browse files Browse the repository at this point in the history
Rollup of 12 pull requests

Successful merges:

 - #81038 (Update Clippy)
 - #81071 (rustc_parse_format: Fix character indices in find_skips)
 - #81100 (prevent potential bug in `encode_with_shorthand`.)
 - #81105 (Initialize a few variables directly)
 - #81116 (ConstProp: Copy body span instead of querying it)
 - #81121 (Avoid logging the whole MIR body in SimplifyCfg)
 - #81123 (Update cmp.rs)
 - #81125 (Add track_caller to .steal())
 - #81128 (validation test: turn some const_err back into validation failures)
 - #81131 (Edit rustc_middle::ty::cast docs)
 - #81142 (Replace let Some(..) = with .is_some())
 - #81153 (Remove unused linkcheck exceptions)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jan 18, 2021
2 parents 66eb982 + 33d184b commit 5e91c4e
Show file tree
Hide file tree
Showing 118 changed files with 2,439 additions and 366 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ impl MetaItemKind {
fn list_from_tokens(tokens: TokenStream) -> Option<MetaItemKind> {
let mut tokens = tokens.into_trees().peekable();
let mut result = Vec::new();
while let Some(..) = tokens.peek() {
while tokens.peek().is_some() {
let item = NestedMetaItem::from_tokens(&mut tokens)?;
result.push(item);
match tokens.next() {
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_data_structures/src/steal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@ impl<T> Steal<T> {
Steal { value: RwLock::new(Some(value)) }
}

#[track_caller]
pub fn borrow(&self) -> MappedReadGuard<'_, T> {
ReadGuard::map(self.value.borrow(), |opt| match *opt {
None => panic!("attempted to read from stolen value"),
Some(ref v) => v,
})
}

#[track_caller]
pub fn steal(&self) -> T {
let value_ref = &mut *self.value.try_write().expect("stealing value which is locked");
let value = value_ref.take();
value.expect("attempt to read from stolen value")
value.expect("attempt to steal from stolen value")
}
}

Expand Down
11 changes: 6 additions & 5 deletions compiler/rustc_middle/src/ty/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ pub enum CastTy<'tcx> {
/// Various types that are represented as ints and handled mostly
/// in the same way, merged for easier matching.
Int(IntTy),
/// Floating-Point types
/// Floating-point types.
Float,
/// Function Pointers
/// Function pointers.
FnPtr,
/// Raw pointers
/// Raw pointers.
Ptr(ty::TypeAndMut<'tcx>),
}

/// Cast Kind. See RFC 401 (or librustc_typeck/check/cast.rs)
/// Cast Kind. See [RFC 401](https://rust-lang.github.io/rfcs/0401-coercions.html)
/// (or librustc_typeck/check/cast.rs).
#[derive(Copy, Clone, Debug, TyEncodable, TyDecodable, HashStable)]
pub enum CastKind {
CoercionCast,
Expand All @@ -48,7 +49,7 @@ pub enum CastKind {

impl<'tcx> CastTy<'tcx> {
/// Returns `Some` for integral/pointer casts.
/// casts like unsizing casts will return `None`
/// Casts like unsizing casts will return `None`.
pub fn from_ty(t: Ty<'tcx>) -> Option<CastTy<'tcx>> {
match *t.kind() {
ty::Bool => Some(CastTy::Int(IntTy::Bool)),
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/ty/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::{CrateNum, DefId};
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use rustc_span::Span;
use std::convert::{TryFrom, TryInto};
use std::hash::Hash;
use std::intrinsics;
use std::marker::DiscriminantKind;
Expand Down Expand Up @@ -81,7 +80,8 @@ where
E: TyEncoder<'tcx>,
M: for<'b> Fn(&'b mut E) -> &'b mut FxHashMap<T, usize>,
T: EncodableWithShorthand<'tcx, E>,
<T::Variant as DiscriminantKind>::Discriminant: Ord + TryFrom<usize>,
// The discriminant and shorthand must have the same size.
T::Variant: DiscriminantKind<Discriminant = isize>,
{
let existing_shorthand = cache(encoder).get(value).copied();
if let Some(shorthand) = existing_shorthand {
Expand All @@ -97,7 +97,7 @@ where
// The shorthand encoding uses the same usize as the
// discriminant, with an offset so they can't conflict.
let discriminant = intrinsics::discriminant_value(variant);
assert!(discriminant < SHORTHAND_OFFSET.try_into().ok().unwrap());
assert!(SHORTHAND_OFFSET > discriminant as usize);

let shorthand = start + SHORTHAND_OFFSET;

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
let mut body =
new_body(source, blocks, local_decls_for_sig(&sig, span), sig.inputs().len(), span);

if let Some(..) = ty {
if ty.is_some() {
// The first argument (index 0), but add 1 for the return value.
let dropee_ptr = Place::from(Local::new(1 + 0));
if tcx.sess.opts.debugging_opts.mir_emit_retag {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
Default::default(),
body.arg_count,
Default::default(),
tcx.def_span(def_id),
body.span,
body.generator_kind,
);

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyCfg {
}

fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
debug!("SimplifyCfg({:?}) - simplifying {:?}", self.label, body);
debug!("SimplifyCfg({:?}) - simplifying {:?}", self.label, body.source);
simplify_cfg(body);
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse_format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ fn find_skips_from_snippet(

fn find_skips(snippet: &str, is_raw: bool) -> Vec<usize> {
let mut eat_ws = false;
let mut s = snippet.chars().enumerate().peekable();
let mut s = snippet.char_indices().peekable();
let mut skips = vec![];
while let Some((pos, c)) = s.next() {
match (c, s.peek()) {
Expand Down
21 changes: 9 additions & 12 deletions compiler/rustc_resolve/src/late/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1398,12 +1398,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
fn lifetime_deletion_span(&self, name: Ident, generics: &hir::Generics<'_>) -> Option<Span> {
generics.params.iter().enumerate().find_map(|(i, param)| {
if param.name.ident() == name {
let mut in_band = false;
if let hir::GenericParamKind::Lifetime { kind } = param.kind {
if let hir::LifetimeParamKind::InBand = kind {
in_band = true;
}
}
let in_band = matches!(
param.kind,
hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::InBand }
);
if in_band {
Some(param.span)
} else if generics.params.len() == 1 {
Expand Down Expand Up @@ -1433,12 +1431,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
lifetime: &hir::Lifetime,
) {
let name = lifetime.name.ident();
let mut remove_decl = None;
if let Some(parent_def_id) = self.tcx.parent(def_id) {
if let Some(generics) = self.tcx.hir().get_generics(parent_def_id) {
remove_decl = self.lifetime_deletion_span(name, generics);
}
}
let remove_decl = self
.tcx
.parent(def_id)
.and_then(|parent_def_id| self.tcx.hir().get_generics(parent_def_id))
.and_then(|generics| self.lifetime_deletion_span(name, generics));

let mut remove_use = None;
let mut elide_use = None;
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ impl Ordering {
/// assert_eq!(result, Ordering::Equal);
///
/// let x: (i64, i64, i64) = (1, 2, 7);
/// let y: (i64, i64, i64) = (1, 5, 3);
/// let y: (i64, i64, i64) = (1, 5, 3);
/// let result = x.0.cmp(&y.0).then_with(|| x.1.cmp(&y.1)).then_with(|| x.2.cmp(&y.2));
///
/// assert_eq!(result, Ordering::Less);
Expand Down
26 changes: 14 additions & 12 deletions src/test/ui/consts/const-eval/ub-wide-ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ use std::mem;
// normalize-stderr-test "alloc\d+" -> "allocN"
// normalize-stderr-test "size \d+" -> "size N"

/// A newtype wrapper to prevent MIR generation from inserting reborrows that would affect the error
/// message. Use this whenever the message is "any use of this value will cause an error" instead of
/// "it is undefined behavior to use this value".
#[repr(transparent)]
struct W<T>(T);

#[repr(C)]
union MaybeUninit<T: Copy> {
uninit: (),
Expand Down Expand Up @@ -95,26 +101,22 @@ const RAW_SLICE_LENGTH_UNINIT: *const [u8] = unsafe {

// # trait object
// bad trait object
#[warn(const_err)]
const TRAIT_OBJ_SHORT_VTABLE_1: &dyn Trait = unsafe { mem::transmute((&92u8, &3u8)) };
//~^ WARN any use of this value will cause an error [const_err]
const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) };
//~^ ERROR it is undefined behavior to use this value
// bad trait object
#[warn(const_err)]
const TRAIT_OBJ_SHORT_VTABLE_2: &dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) };
//~^ WARN any use of this value will cause an error [const_err]
const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) };
//~^ ERROR it is undefined behavior to use this value
// bad trait object
#[warn(const_err)]
const TRAIT_OBJ_INT_VTABLE: &dyn Trait = unsafe { mem::transmute((&92u8, 4usize)) };
//~^ WARN any use of this value will cause an error [const_err]
const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) };
//~^ ERROR it is undefined behavior to use this value
const TRAIT_OBJ_UNALIGNED_VTABLE: &dyn Trait = unsafe { mem::transmute((&92u8, &[0u8; 128])) };
//~^ ERROR it is undefined behavior to use this value
const TRAIT_OBJ_BAD_DROP_FN_NULL: &dyn Trait = unsafe { mem::transmute((&92u8, &[0usize; 8])) };
//~^ ERROR it is undefined behavior to use this value
const TRAIT_OBJ_BAD_DROP_FN_INT: &dyn Trait = unsafe { mem::transmute((&92u8, &[1usize; 8])) };
//~^ ERROR it is undefined behavior to use this value
#[warn(const_err)]
const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: &dyn Trait = unsafe { mem::transmute((&92u8, &[&42u8; 8])) };
//~^ WARN any use of this value will cause an error [const_err]
const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) };
//~^ ERROR it is undefined behavior to use this value

// bad data *inside* the trait object
const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) };
Expand Down
Loading

0 comments on commit 5e91c4e

Please sign in to comment.