Skip to content

Commit 5e91c4e

Browse files
committed
Auto merge of #81165 - KodrAus:rollup-s7llxis, r=KodrAus
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
2 parents 66eb982 + 33d184b commit 5e91c4e

File tree

118 files changed

+2439
-366
lines changed

Some content is hidden

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

118 files changed

+2439
-366
lines changed

compiler/rustc_ast/src/attr/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ impl MetaItemKind {
526526
fn list_from_tokens(tokens: TokenStream) -> Option<MetaItemKind> {
527527
let mut tokens = tokens.into_trees().peekable();
528528
let mut result = Vec::new();
529-
while let Some(..) = tokens.peek() {
529+
while tokens.peek().is_some() {
530530
let item = NestedMetaItem::from_tokens(&mut tokens)?;
531531
result.push(item);
532532
match tokens.next() {

compiler/rustc_data_structures/src/steal.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@ impl<T> Steal<T> {
3030
Steal { value: RwLock::new(Some(value)) }
3131
}
3232

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

41+
#[track_caller]
4042
pub fn steal(&self) -> T {
4143
let value_ref = &mut *self.value.try_write().expect("stealing value which is locked");
4244
let value = value_ref.take();
43-
value.expect("attempt to read from stolen value")
45+
value.expect("attempt to steal from stolen value")
4446
}
4547
}
4648

compiler/rustc_middle/src/ty/cast.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ pub enum CastTy<'tcx> {
2222
/// Various types that are represented as ints and handled mostly
2323
/// in the same way, merged for easier matching.
2424
Int(IntTy),
25-
/// Floating-Point types
25+
/// Floating-point types.
2626
Float,
27-
/// Function Pointers
27+
/// Function pointers.
2828
FnPtr,
29-
/// Raw pointers
29+
/// Raw pointers.
3030
Ptr(ty::TypeAndMut<'tcx>),
3131
}
3232

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

4950
impl<'tcx> CastTy<'tcx> {
5051
/// Returns `Some` for integral/pointer casts.
51-
/// casts like unsizing casts will return `None`
52+
/// Casts like unsizing casts will return `None`.
5253
pub fn from_ty(t: Ty<'tcx>) -> Option<CastTy<'tcx>> {
5354
match *t.kind() {
5455
ty::Bool => Some(CastTy::Int(IntTy::Bool)),

compiler/rustc_middle/src/ty/codec.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use rustc_data_structures::fx::FxHashMap;
1818
use rustc_hir::def_id::{CrateNum, DefId};
1919
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
2020
use rustc_span::Span;
21-
use std::convert::{TryFrom, TryInto};
2221
use std::hash::Hash;
2322
use std::intrinsics;
2423
use std::marker::DiscriminantKind;
@@ -81,7 +80,8 @@ where
8180
E: TyEncoder<'tcx>,
8281
M: for<'b> Fn(&'b mut E) -> &'b mut FxHashMap<T, usize>,
8382
T: EncodableWithShorthand<'tcx, E>,
84-
<T::Variant as DiscriminantKind>::Discriminant: Ord + TryFrom<usize>,
83+
// The discriminant and shorthand must have the same size.
84+
T::Variant: DiscriminantKind<Discriminant = isize>,
8585
{
8686
let existing_shorthand = cache(encoder).get(value).copied();
8787
if let Some(shorthand) = existing_shorthand {
@@ -97,7 +97,7 @@ where
9797
// The shorthand encoding uses the same usize as the
9898
// discriminant, with an offset so they can't conflict.
9999
let discriminant = intrinsics::discriminant_value(variant);
100-
assert!(discriminant < SHORTHAND_OFFSET.try_into().ok().unwrap());
100+
assert!(SHORTHAND_OFFSET > discriminant as usize);
101101

102102
let shorthand = start + SHORTHAND_OFFSET;
103103

compiler/rustc_mir/src/shim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
165165
let mut body =
166166
new_body(source, blocks, local_decls_for_sig(&sig, span), sig.inputs().len(), span);
167167

168-
if let Some(..) = ty {
168+
if ty.is_some() {
169169
// The first argument (index 0), but add 1 for the return value.
170170
let dropee_ptr = Place::from(Local::new(1 + 0));
171171
if tcx.sess.opts.debugging_opts.mir_emit_retag {

compiler/rustc_mir/src/transform/const_prop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
139139
Default::default(),
140140
body.arg_count,
141141
Default::default(),
142-
tcx.def_span(def_id),
142+
body.span,
143143
body.generator_kind,
144144
);
145145

compiler/rustc_mir/src/transform/simplify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyCfg {
6161
}
6262

6363
fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
64-
debug!("SimplifyCfg({:?}) - simplifying {:?}", self.label, body);
64+
debug!("SimplifyCfg({:?}) - simplifying {:?}", self.label, body.source);
6565
simplify_cfg(body);
6666
}
6767
}

compiler/rustc_parse_format/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ fn find_skips_from_snippet(
736736

737737
fn find_skips(snippet: &str, is_raw: bool) -> Vec<usize> {
738738
let mut eat_ws = false;
739-
let mut s = snippet.chars().enumerate().peekable();
739+
let mut s = snippet.char_indices().peekable();
740740
let mut skips = vec![];
741741
while let Some((pos, c)) = s.next() {
742742
match (c, s.peek()) {

compiler/rustc_resolve/src/late/lifetimes.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -1398,12 +1398,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
13981398
fn lifetime_deletion_span(&self, name: Ident, generics: &hir::Generics<'_>) -> Option<Span> {
13991399
generics.params.iter().enumerate().find_map(|(i, param)| {
14001400
if param.name.ident() == name {
1401-
let mut in_band = false;
1402-
if let hir::GenericParamKind::Lifetime { kind } = param.kind {
1403-
if let hir::LifetimeParamKind::InBand = kind {
1404-
in_band = true;
1405-
}
1406-
}
1401+
let in_band = matches!(
1402+
param.kind,
1403+
hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::InBand }
1404+
);
14071405
if in_band {
14081406
Some(param.span)
14091407
} else if generics.params.len() == 1 {
@@ -1433,12 +1431,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14331431
lifetime: &hir::Lifetime,
14341432
) {
14351433
let name = lifetime.name.ident();
1436-
let mut remove_decl = None;
1437-
if let Some(parent_def_id) = self.tcx.parent(def_id) {
1438-
if let Some(generics) = self.tcx.hir().get_generics(parent_def_id) {
1439-
remove_decl = self.lifetime_deletion_span(name, generics);
1440-
}
1441-
}
1434+
let remove_decl = self
1435+
.tcx
1436+
.parent(def_id)
1437+
.and_then(|parent_def_id| self.tcx.hir().get_generics(parent_def_id))
1438+
.and_then(|generics| self.lifetime_deletion_span(name, generics));
14421439

14431440
let mut remove_use = None;
14441441
let mut elide_use = None;

library/core/src/cmp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ impl Ordering {
541541
/// assert_eq!(result, Ordering::Equal);
542542
///
543543
/// let x: (i64, i64, i64) = (1, 2, 7);
544-
/// let y: (i64, i64, i64) = (1, 5, 3);
544+
/// let y: (i64, i64, i64) = (1, 5, 3);
545545
/// let result = x.0.cmp(&y.0).then_with(|| x.1.cmp(&y.1)).then_with(|| x.2.cmp(&y.2));
546546
///
547547
/// assert_eq!(result, Ordering::Less);

src/test/ui/consts/const-eval/ub-wide-ptr.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ use std::mem;
88
// normalize-stderr-test "alloc\d+" -> "allocN"
99
// normalize-stderr-test "size \d+" -> "size N"
1010

11+
/// A newtype wrapper to prevent MIR generation from inserting reborrows that would affect the error
12+
/// message. Use this whenever the message is "any use of this value will cause an error" instead of
13+
/// "it is undefined behavior to use this value".
14+
#[repr(transparent)]
15+
struct W<T>(T);
16+
1117
#[repr(C)]
1218
union MaybeUninit<T: Copy> {
1319
uninit: (),
@@ -95,26 +101,22 @@ const RAW_SLICE_LENGTH_UNINIT: *const [u8] = unsafe {
95101

96102
// # trait object
97103
// bad trait object
98-
#[warn(const_err)]
99-
const TRAIT_OBJ_SHORT_VTABLE_1: &dyn Trait = unsafe { mem::transmute((&92u8, &3u8)) };
100-
//~^ WARN any use of this value will cause an error [const_err]
104+
const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) };
105+
//~^ ERROR it is undefined behavior to use this value
101106
// bad trait object
102-
#[warn(const_err)]
103-
const TRAIT_OBJ_SHORT_VTABLE_2: &dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) };
104-
//~^ WARN any use of this value will cause an error [const_err]
107+
const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) };
108+
//~^ ERROR it is undefined behavior to use this value
105109
// bad trait object
106-
#[warn(const_err)]
107-
const TRAIT_OBJ_INT_VTABLE: &dyn Trait = unsafe { mem::transmute((&92u8, 4usize)) };
108-
//~^ WARN any use of this value will cause an error [const_err]
110+
const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) };
111+
//~^ ERROR it is undefined behavior to use this value
109112
const TRAIT_OBJ_UNALIGNED_VTABLE: &dyn Trait = unsafe { mem::transmute((&92u8, &[0u8; 128])) };
110113
//~^ ERROR it is undefined behavior to use this value
111114
const TRAIT_OBJ_BAD_DROP_FN_NULL: &dyn Trait = unsafe { mem::transmute((&92u8, &[0usize; 8])) };
112115
//~^ ERROR it is undefined behavior to use this value
113116
const TRAIT_OBJ_BAD_DROP_FN_INT: &dyn Trait = unsafe { mem::transmute((&92u8, &[1usize; 8])) };
114117
//~^ ERROR it is undefined behavior to use this value
115-
#[warn(const_err)]
116-
const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: &dyn Trait = unsafe { mem::transmute((&92u8, &[&42u8; 8])) };
117-
//~^ WARN any use of this value will cause an error [const_err]
118+
const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) };
119+
//~^ ERROR it is undefined behavior to use this value
118120

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

0 commit comments

Comments
 (0)