Skip to content

Commit

Permalink
Auto merge of rust-lang#94314 - matthiaskrgr:rollup-hmed8n7, r=matthi…
Browse files Browse the repository at this point in the history
…askrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#89887 (Change `char` type in debuginfo to DW_ATE_UTF)
 - rust-lang#94267 (Remove unused ordering derivations and bounds for `SimplifiedTypeGen`)
 - rust-lang#94270 (Miri: relax fn ptr check)
 - rust-lang#94273 (add matching doc to errorkind)
 - rust-lang#94283 (remove feature gate in control_flow examples)
 - rust-lang#94288 (Cleanup a few Decoder methods)
 - rust-lang#94292 (riscv32imc_esp_espidf: set max_atomic_width to 64)
 - rust-lang#94296 (:arrow_up: rust-analyzer)
 - rust-lang#94300 (Fix a typo in documentation of `array::IntoIter::new_unchecked`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Feb 24, 2022
2 parents e780264 + bdcdd1b commit 1204400
Show file tree
Hide file tree
Showing 21 changed files with 156 additions and 90 deletions.
3 changes: 1 addition & 2 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2418,8 +2418,7 @@ impl<S: Encoder> rustc_serialize::Encodable<S> for AttrId {
}

impl<D: Decoder> rustc_serialize::Decodable<D> for AttrId {
fn decode(d: &mut D) -> AttrId {
d.read_unit();
fn decode(_: &mut D) -> AttrId {
crate::attr::mk_attr_id()
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const DW_ATE_signed: c_uint = 0x05;
#[allow(non_upper_case_globals)]
const DW_ATE_unsigned: c_uint = 0x07;
#[allow(non_upper_case_globals)]
const DW_ATE_unsigned_char: c_uint = 0x08;
const DW_ATE_UTF: c_uint = 0x10;

pub const UNKNOWN_LINE_NUMBER: c_uint = 0;
pub const UNKNOWN_COLUMN_NUMBER: c_uint = 0;
Expand Down Expand Up @@ -933,7 +933,7 @@ fn basic_type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'l
ty::Never => ("!", DW_ATE_unsigned),
ty::Tuple(elements) if elements.is_empty() => ("()", DW_ATE_unsigned),
ty::Bool => ("bool", DW_ATE_boolean),
ty::Char => ("char", DW_ATE_unsigned_char),
ty::Char => ("char", DW_ATE_UTF),
ty::Int(int_ty) if cpp_like_debuginfo => (int_ty.msvc_basic_name(), DW_ATE_signed),
ty::Uint(uint_ty) if cpp_like_debuginfo => (uint_ty.msvc_basic_name(), DW_ATE_unsigned),
ty::Float(float_ty) if cpp_like_debuginfo => (float_ty.msvc_basic_name(), DW_ATE_float),
Expand Down
31 changes: 18 additions & 13 deletions compiler/rustc_const_eval/src/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,22 +567,27 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
}
ty::FnPtr(_sig) => {
let value = try_validation!(
self.ecx.read_immediate(value),
self.ecx.read_scalar(value).and_then(|v| v.check_init()),
self.path,
err_unsup!(ReadPointerAsBytes) => { "part of a pointer" } expected { "a proper pointer or integer value" },
err_ub!(InvalidUninitBytes(None)) => { "uninitialized bytes" } expected { "a proper pointer or integer value" },
);
// Make sure we print a `ScalarMaybeUninit` (and not an `ImmTy`) in the error
// message below.
let value = value.to_scalar_or_uninit();
let _fn = try_validation!(
value.check_init().and_then(|ptr| self.ecx.memory.get_fn(self.ecx.scalar_to_ptr(ptr))),
self.path,
err_ub!(DanglingIntPointer(..)) |
err_ub!(InvalidFunctionPointer(..)) |
err_ub!(InvalidUninitBytes(None)) =>
{ "{:x}", value } expected { "a function pointer" },
);
// FIXME: Check if the signature matches
let ptr = self.ecx.scalar_to_ptr(value);
// Ensure the pointer is non-null.
if self.ecx.memory.ptr_may_be_null(ptr) {
throw_validation_failure!(self.path, { "a potentially null function pointer" });
}
// If we check references recursively, also check that this points to a function.
if let Some(_) = self.ref_tracking {
let _fn = try_validation!(
self.ecx.memory.get_fn(ptr),
self.path,
err_ub!(DanglingIntPointer(..)) |
err_ub!(InvalidFunctionPointer(..)) =>
{ "{:x}", value } expected { "a function pointer" },
);
// FIXME: Check if the signature matches
}
Ok(true)
}
ty::Never => throw_validation_failure!(self.path, { "a value of the never type `!`" }),
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_data_structures/src/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ impl<E: rustc_serialize::Encoder> Encodable<E> for Fingerprint {
impl<D: rustc_serialize::Decoder> Decodable<D> for Fingerprint {
#[inline]
fn decode(d: &mut D) -> Self {
let mut bytes = [0u8; 16];
d.read_raw_bytes_into(&mut bytes);
Fingerprint::from_le_bytes(bytes)
Fingerprint::from_le_bytes(d.read_raw_bytes(16).try_into().unwrap())
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
}

#[inline]
pub fn read_raw_bytes(&mut self, len: usize) -> &'a [u8] {
pub fn read_raw_bytes(&mut self, len: usize) -> &[u8] {
self.opaque.read_raw_bytes(len)
}
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_middle/src/mir/predecessors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ impl<S: serialize::Encoder> serialize::Encodable<S> for PredecessorCache {

impl<D: serialize::Decoder> serialize::Decodable<D> for PredecessorCache {
#[inline]
fn decode(d: &mut D) -> Self {
let () = d.read_unit();
fn decode(_: &mut D) -> Self {
Self::new()
}
}
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_middle/src/ty/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,6 @@ macro_rules! implement_ty_decoder {

impl<$($typaram ),*> Decoder for $DecoderName<$($typaram),*> {
$crate::__impl_decoder_methods! {
read_unit -> ();

read_u128 -> u128;
read_u64 -> u64;
read_u32 -> u32;
Expand All @@ -485,12 +483,12 @@ macro_rules! implement_ty_decoder {
read_f64 -> f64;
read_f32 -> f32;
read_char -> char;
read_str -> Cow<'_, str>;
read_str -> &str;
}

#[inline]
fn read_raw_bytes_into(&mut self, bytes: &mut [u8]) {
self.opaque.read_raw_bytes_into(bytes)
fn read_raw_bytes(&mut self, len: usize) -> &[u8] {
self.opaque.read_raw_bytes(len)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_middle/src/ty/fast_reject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub type SimplifiedType = SimplifiedTypeGen<DefId>;
/// because we sometimes need to use SimplifiedTypeGen values as stable sorting
/// keys (in which case we use a DefPathHash as id-type) but in the general case
/// the non-stable but fast to construct DefId-version is the better choice.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, TyEncodable, TyDecodable)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
pub enum SimplifiedTypeGen<D>
where
D: Copy + Debug + Eq,
Expand Down Expand Up @@ -124,7 +124,7 @@ pub fn simplify_type(
}
}

impl<D: Copy + Debug + Ord + Eq> SimplifiedTypeGen<D> {
impl<D: Copy + Debug + Eq> SimplifiedTypeGen<D> {
pub fn def(self) -> Option<D> {
match self {
AdtSimplifiedType(d)
Expand All @@ -140,7 +140,7 @@ impl<D: Copy + Debug + Ord + Eq> SimplifiedTypeGen<D> {
pub fn map_def<U, F>(self, map: F) -> SimplifiedTypeGen<U>
where
F: Fn(D) -> U,
U: Copy + Debug + Ord + Eq,
U: Copy + Debug + Eq,
{
match self {
BoolSimplifiedType => BoolSimplifiedType,
Expand Down Expand Up @@ -171,7 +171,7 @@ impl<D: Copy + Debug + Ord + Eq> SimplifiedTypeGen<D> {

impl<'a, D> HashStable<StableHashingContext<'a>> for SimplifiedTypeGen<D>
where
D: Copy + Debug + Ord + Eq + HashStable<StableHashingContext<'a>>,
D: Copy + Debug + Eq + HashStable<StableHashingContext<'a>>,
{
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
mem::discriminant(self).hash_stable(hcx, hasher);
Expand Down
27 changes: 7 additions & 20 deletions compiler/rustc_serialize/src/opaque.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::leb128::{self, max_leb128_len};
use crate::serialize::{self, Encoder as _};
use std::borrow::Cow;
use crate::serialize::{self, Decoder as _, Encoder as _};
use std::convert::TryInto;
use std::fs::File;
use std::io::{self, Write};
Expand Down Expand Up @@ -549,25 +548,13 @@ impl<'a> Decoder<'a> {
pub fn advance(&mut self, bytes: usize) {
self.position += bytes;
}

#[inline]
pub fn read_raw_bytes(&mut self, bytes: usize) -> &'a [u8] {
let start = self.position;
self.position += bytes;
&self.data[start..self.position]
}
}

macro_rules! read_leb128 {
($dec:expr, $fun:ident) => {{ leb128::$fun($dec.data, &mut $dec.position) }};
}

impl<'a> serialize::Decoder for Decoder<'a> {
#[inline]
fn read_unit(&mut self) -> () {
()
}

#[inline]
fn read_u128(&mut self) -> u128 {
read_leb128!(self, read_u128_leb128)
Expand Down Expand Up @@ -663,22 +650,22 @@ impl<'a> serialize::Decoder for Decoder<'a> {
}

#[inline]
fn read_str(&mut self) -> Cow<'_, str> {
fn read_str(&mut self) -> &'a str {
let len = self.read_usize();
let sentinel = self.data[self.position + len];
assert!(sentinel == STR_SENTINEL);
let s = unsafe {
std::str::from_utf8_unchecked(&self.data[self.position..self.position + len])
};
self.position += len + 1;
Cow::Borrowed(s)
s
}

#[inline]
fn read_raw_bytes_into(&mut self, s: &mut [u8]) {
fn read_raw_bytes(&mut self, bytes: usize) -> &'a [u8] {
let start = self.position;
self.position += s.len();
s.copy_from_slice(&self.data[start..self.position]);
self.position += bytes;
&self.data[start..self.position]
}
}

Expand Down Expand Up @@ -746,10 +733,10 @@ impl<'a> serialize::Decodable<Decoder<'a>> for IntEncodedWithFixedSize {
fn decode(decoder: &mut Decoder<'a>) -> IntEncodedWithFixedSize {
let _start_pos = decoder.position();
let bytes = decoder.read_raw_bytes(IntEncodedWithFixedSize::ENCODED_SIZE);
let value = u64::from_le_bytes(bytes.try_into().unwrap());
let _end_pos = decoder.position();
debug_assert_eq!((_end_pos - _start_pos), IntEncodedWithFixedSize::ENCODED_SIZE);

let value = u64::from_le_bytes(bytes.try_into().unwrap());
IntEncodedWithFixedSize(value)
}
}
14 changes: 5 additions & 9 deletions compiler/rustc_serialize/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ pub trait Encoder {
// concise.
pub trait Decoder {
// Primitive types:
fn read_unit(&mut self) -> ();
fn read_usize(&mut self) -> usize;
fn read_u128(&mut self) -> u128;
fn read_u64(&mut self) -> u64;
Expand All @@ -198,8 +197,8 @@ pub trait Decoder {
fn read_f64(&mut self) -> f64;
fn read_f32(&mut self) -> f32;
fn read_char(&mut self) -> char;
fn read_str(&mut self) -> Cow<'_, str>;
fn read_raw_bytes_into(&mut self, s: &mut [u8]);
fn read_str(&mut self) -> &str;
fn read_raw_bytes(&mut self, len: usize) -> &[u8];
}

/// Trait for types that can be serialized
Expand Down Expand Up @@ -313,7 +312,7 @@ impl<S: Encoder> Encodable<S> for String {

impl<D: Decoder> Decodable<D> for String {
fn decode(d: &mut D) -> String {
d.read_str().into_owned()
d.read_str().to_owned()
}
}

Expand All @@ -324,9 +323,7 @@ impl<S: Encoder> Encodable<S> for () {
}

impl<D: Decoder> Decodable<D> for () {
fn decode(d: &mut D) -> () {
d.read_unit()
}
fn decode(_: &mut D) -> () {}
}

impl<S: Encoder, T> Encodable<S> for PhantomData<T> {
Expand All @@ -336,8 +333,7 @@ impl<S: Encoder, T> Encodable<S> for PhantomData<T> {
}

impl<D: Decoder, T> Decodable<D> for PhantomData<T> {
fn decode(d: &mut D) -> PhantomData<T> {
d.read_unit();
fn decode(_: &mut D) -> PhantomData<T> {
PhantomData
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_target/src/spec/riscv32imc_esp_espidf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ pub fn target() -> Target {
cpu: "generic-rv32".to_string(),

// While the RiscV32IMC architecture does not natively support atomics, ESP-IDF does support
// the __atomic* and __sync* GCC builtins, so setting `max_atomic_width` to `Some(32)`
// the __atomic* and __sync* GCC builtins, so setting `max_atomic_width` to `Some(64)`
// and `atomic_cas` to `true` will cause the compiler to emit libcalls to these builtins.
//
// Support for atomics is necessary for the Rust STD library, which is supported by the ESP-IDF framework.
max_atomic_width: Some(32),
max_atomic_width: Some(64),
atomic_cas: true,

features: "+m,+c".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/array/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<T, const N: usize> IntoIter<T, N> {
///
/// - The `buffer[initialized]` elements must all be initialized.
/// - The range must be canonical, with `initialized.start <= initialized.end`.
/// - The range must in in-bounds for the buffer, with `initialized.end <= N`.
/// - The range must be in-bounds for the buffer, with `initialized.end <= N`.
/// (Like how indexing `[0][100..100]` fails despite the range being empty.)
///
/// It's sound to have more elements initialized than mentioned, though that
Expand Down
2 changes: 0 additions & 2 deletions library/core/src/ops/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ impl<B, C> ControlFlow<B, C> {
/// # Examples
///
/// ```
/// #![feature(control_flow_enum)]
/// use std::ops::ControlFlow;
///
/// assert!(ControlFlow::<i32, String>::Break(3).is_break());
Expand All @@ -151,7 +150,6 @@ impl<B, C> ControlFlow<B, C> {
/// # Examples
///
/// ```
/// #![feature(control_flow_enum)]
/// use std::ops::ControlFlow;
///
/// assert!(!ControlFlow::<i32, String>::Break(3).is_continue());
Expand Down
13 changes: 13 additions & 0 deletions library/std/src/io/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@ struct Custom {
/// It is used with the [`io::Error`] type.
///
/// [`io::Error`]: Error
///
/// # Handling errors and matching on `ErrorKind`
///
/// In application code, use `match` for the `ErrorKind` values you are
/// expecting; use `_` to match "all other errors".
///
/// In comprehensive and thorough tests that want to verify that a test doesn't
/// return any known incorrect error kind, you may want to cut-and-paste the
/// current full list of errors from here into your test code, and then match
/// `_` as the correct case. This seems counterintuitive, but it will make your
/// tests more robust. In particular, if you want to verify that your code does
/// produce an unrecognized error kind, the robust solution is to check for all
/// the recognized error kinds and fail in those cases.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated)]
Expand Down
3 changes: 2 additions & 1 deletion src/test/debuginfo/basic-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
// cdb-check:b : false [Type: bool]
// cdb-command:dx i
// cdb-check:i : -1 [Type: [...]]
// The variable 'c' doesn't appear for some reason...
// cdb-command:dx c
// cdb-check:c : 0x61 'a' [Type: char32_t]
// cdb-command:dx i8
// cdb-check:i8 : 68 [Type: char]
// cdb-command:dx i16
Expand Down
3 changes: 1 addition & 2 deletions src/test/debuginfo/borrowed-basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
// gdb-check:$2 = -1

// gdb-command:print *char_ref
// gdbg-check:$3 = 97
// gdbr-check:$3 = 97 'a'
// gdb-check:$3 = 97

// gdb-command:print *i8_ref
// gdbg-check:$4 = 68 'D'
Expand Down
3 changes: 1 addition & 2 deletions src/test/debuginfo/borrowed-unique-basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
// gdb-check:$2 = -1

// gdb-command:print *char_ref
// gdbg-check:$3 = 97
// gdbr-check:$3 = 97 'a'
// gdb-check:$3 = 97

// gdb-command:print/d *i8_ref
// gdb-check:$4 = 68
Expand Down
Loading

0 comments on commit 1204400

Please sign in to comment.