From da3b2ca95636eea18c62089bae5e7443ecf94c9a Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Tue, 22 Feb 2022 18:05:51 -0500 Subject: [PATCH 01/16] Provide raw &str access from Decoder --- compiler/rustc_serialize/src/opaque.rs | 5 ++--- compiler/rustc_serialize/src/serialize.rs | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_serialize/src/opaque.rs b/compiler/rustc_serialize/src/opaque.rs index 7a05d2b762a47..8e2c866cd386c 100644 --- a/compiler/rustc_serialize/src/opaque.rs +++ b/compiler/rustc_serialize/src/opaque.rs @@ -1,6 +1,5 @@ use crate::leb128::{self, max_leb128_len}; use crate::serialize::{self, Encoder as _}; -use std::borrow::Cow; use std::convert::TryInto; use std::fs::File; use std::io::{self, Write}; @@ -663,7 +662,7 @@ impl<'a> serialize::Decoder for Decoder<'a> { } #[inline] - fn read_str(&mut self) -> Cow<'_, str> { + fn read_str(&mut self) -> &str { let len = self.read_usize(); let sentinel = self.data[self.position + len]; assert!(sentinel == STR_SENTINEL); @@ -671,7 +670,7 @@ impl<'a> serialize::Decoder for Decoder<'a> { std::str::from_utf8_unchecked(&self.data[self.position..self.position + len]) }; self.position += len + 1; - Cow::Borrowed(s) + s } #[inline] diff --git a/compiler/rustc_serialize/src/serialize.rs b/compiler/rustc_serialize/src/serialize.rs index a012be2857e1e..fbbd13657ba54 100644 --- a/compiler/rustc_serialize/src/serialize.rs +++ b/compiler/rustc_serialize/src/serialize.rs @@ -198,7 +198,7 @@ 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_str(&mut self) -> &str; fn read_raw_bytes_into(&mut self, s: &mut [u8]); } @@ -313,7 +313,7 @@ impl Encodable for String { impl Decodable for String { fn decode(d: &mut D) -> String { - d.read_str().into_owned() + d.read_str().to_owned() } } From 2098ea6eba5ac7901b419841972c9bbffbf49a93 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Tue, 22 Feb 2022 18:11:59 -0500 Subject: [PATCH 02/16] Provide copy-free access to raw Decoder bytes --- .../rustc_data_structures/src/fingerprint.rs | 4 +--- compiler/rustc_metadata/src/rmeta/decoder.rs | 2 +- compiler/rustc_middle/src/ty/codec.rs | 6 +++--- compiler/rustc_serialize/src/opaque.rs | 19 ++++++------------- compiler/rustc_serialize/src/serialize.rs | 2 +- 5 files changed, 12 insertions(+), 21 deletions(-) diff --git a/compiler/rustc_data_structures/src/fingerprint.rs b/compiler/rustc_data_structures/src/fingerprint.rs index e931379dd3a70..c88f3e73cff37 100644 --- a/compiler/rustc_data_structures/src/fingerprint.rs +++ b/compiler/rustc_data_structures/src/fingerprint.rs @@ -153,9 +153,7 @@ impl Encodable for Fingerprint { impl Decodable 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()) } } diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 66968c9ba54ab..b715f6c3f1fc9 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -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) } } diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index ecd30ba441ff4..7a6cbea00d866 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -485,12 +485,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) } } } diff --git a/compiler/rustc_serialize/src/opaque.rs b/compiler/rustc_serialize/src/opaque.rs index 8e2c866cd386c..1a71ee9038bcb 100644 --- a/compiler/rustc_serialize/src/opaque.rs +++ b/compiler/rustc_serialize/src/opaque.rs @@ -1,5 +1,5 @@ use crate::leb128::{self, max_leb128_len}; -use crate::serialize::{self, Encoder as _}; +use crate::serialize::{self, Decoder as _, Encoder as _}; use std::convert::TryInto; use std::fs::File; use std::io::{self, Write}; @@ -548,13 +548,6 @@ 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 { @@ -662,7 +655,7 @@ impl<'a> serialize::Decoder for Decoder<'a> { } #[inline] - fn read_str(&mut self) -> &str { + fn read_str(&mut self) -> &'a str { let len = self.read_usize(); let sentinel = self.data[self.position + len]; assert!(sentinel == STR_SENTINEL); @@ -674,10 +667,10 @@ impl<'a> serialize::Decoder for Decoder<'a> { } #[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] } } @@ -745,10 +738,10 @@ impl<'a> serialize::Decodable> 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) } } diff --git a/compiler/rustc_serialize/src/serialize.rs b/compiler/rustc_serialize/src/serialize.rs index fbbd13657ba54..7b6dd8b60f800 100644 --- a/compiler/rustc_serialize/src/serialize.rs +++ b/compiler/rustc_serialize/src/serialize.rs @@ -199,7 +199,7 @@ pub trait Decoder { fn read_f32(&mut self) -> f32; fn read_char(&mut self) -> char; fn read_str(&mut self) -> &str; - fn read_raw_bytes_into(&mut self, s: &mut [u8]); + fn read_raw_bytes(&mut self, len: usize) -> &[u8]; } /// Trait for types that can be serialized From f1bcb0f3afb20e63f94bfff396f96027eecd0ad1 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Tue, 22 Feb 2022 18:14:51 -0500 Subject: [PATCH 03/16] Delete Decoder::read_unit --- compiler/rustc_ast/src/ast.rs | 3 +-- compiler/rustc_middle/src/mir/predecessors.rs | 3 +-- compiler/rustc_middle/src/ty/codec.rs | 2 -- compiler/rustc_serialize/src/opaque.rs | 5 ----- compiler/rustc_serialize/src/serialize.rs | 8 ++------ 5 files changed, 4 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index e9135b7163025..0449d715a5e1a 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2418,8 +2418,7 @@ impl rustc_serialize::Encodable for AttrId { } impl rustc_serialize::Decodable for AttrId { - fn decode(d: &mut D) -> AttrId { - d.read_unit(); + fn decode(_: &mut D) -> AttrId { crate::attr::mk_attr_id() } } diff --git a/compiler/rustc_middle/src/mir/predecessors.rs b/compiler/rustc_middle/src/mir/predecessors.rs index 2562baac91131..4fe2cde753290 100644 --- a/compiler/rustc_middle/src/mir/predecessors.rs +++ b/compiler/rustc_middle/src/mir/predecessors.rs @@ -63,8 +63,7 @@ impl serialize::Encodable for PredecessorCache { impl serialize::Decodable for PredecessorCache { #[inline] - fn decode(d: &mut D) -> Self { - let () = d.read_unit(); + fn decode(_: &mut D) -> Self { Self::new() } } diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 7a6cbea00d866..23fb7a49d9c8e 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -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; diff --git a/compiler/rustc_serialize/src/opaque.rs b/compiler/rustc_serialize/src/opaque.rs index 1a71ee9038bcb..5e5cbacbcff1a 100644 --- a/compiler/rustc_serialize/src/opaque.rs +++ b/compiler/rustc_serialize/src/opaque.rs @@ -555,11 +555,6 @@ macro_rules! read_leb128 { } 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) diff --git a/compiler/rustc_serialize/src/serialize.rs b/compiler/rustc_serialize/src/serialize.rs index 7b6dd8b60f800..42bf6ff2a9852 100644 --- a/compiler/rustc_serialize/src/serialize.rs +++ b/compiler/rustc_serialize/src/serialize.rs @@ -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; @@ -324,9 +323,7 @@ impl Encodable for () { } impl Decodable for () { - fn decode(d: &mut D) -> () { - d.read_unit() - } + fn decode(_: &mut D) -> () {} } impl Encodable for PhantomData { @@ -336,8 +333,7 @@ impl Encodable for PhantomData { } impl Decodable for PhantomData { - fn decode(d: &mut D) -> PhantomData { - d.read_unit(); + fn decode(_: &mut D) -> PhantomData { PhantomData } } From 49058142499b7112a4deaca030ad9f07a554182d Mon Sep 17 00:00:00 2001 From: Dylan DPC Date: Wed, 23 Feb 2022 03:22:23 +0100 Subject: [PATCH 04/16] add matching to errorkind --- library/std/src/io/error.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 1aa6d65788912..ba0b9f9f6fd44 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -141,6 +141,14 @@ 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, you may need to cut-and-paste the current list of +/// errors from here into your test code. #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[stable(feature = "rust1", since = "1.0.0")] #[allow(deprecated)] From 37cbc7d1202630b6a4077a16867c3065c94d6b7a Mon Sep 17 00:00:00 2001 From: Dylan DPC Date: Wed, 23 Feb 2022 03:28:27 +0100 Subject: [PATCH 05/16] add some more summary from pr discussion --- library/std/src/io/error.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index ba0b9f9f6fd44..e4961952d0be8 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -147,8 +147,10 @@ struct Custom { /// In application code, use `match` for the `ErrorKind` values you are expecting; use `_` to match /// "all other errors". /// -/// In comprehensive and thorough tests, you may need to cut-and-paste the current list of -/// errors from here into your test code. +/// 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 list of errors from here into your test code. 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)] From 057dc09eaea610c5a14d0908764696d9d416d544 Mon Sep 17 00:00:00 2001 From: Dylan DPC Date: Wed, 23 Feb 2022 03:29:02 +0100 Subject: [PATCH 06/16] add some more summary from pr discussion --- library/std/src/io/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index e4961952d0be8..6adf26a35a2a1 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -147,7 +147,7 @@ struct Custom { /// 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, +/// 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 list of errors from here into your test code. 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. From 516e965bfd6aabbbeeb82b540d595ef03ca891d9 Mon Sep 17 00:00:00 2001 From: pierwill Date: Tue, 22 Feb 2022 15:56:37 -0600 Subject: [PATCH 07/16] Remove unused ordering derivations and bounds for `SimplifiedTypeGen` --- compiler/rustc_middle/src/ty/fast_reject.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_middle/src/ty/fast_reject.rs b/compiler/rustc_middle/src/ty/fast_reject.rs index 983057bff95d6..3c1ac66e2d136 100644 --- a/compiler/rustc_middle/src/ty/fast_reject.rs +++ b/compiler/rustc_middle/src/ty/fast_reject.rs @@ -17,7 +17,7 @@ pub type SimplifiedType = SimplifiedTypeGen; /// 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 where D: Copy + Debug + Eq, @@ -124,7 +124,7 @@ pub fn simplify_type( } } -impl SimplifiedTypeGen { +impl SimplifiedTypeGen { pub fn def(self) -> Option { match self { AdtSimplifiedType(d) @@ -140,7 +140,7 @@ impl SimplifiedTypeGen { pub fn map_def(self, map: F) -> SimplifiedTypeGen where F: Fn(D) -> U, - U: Copy + Debug + Ord + Eq, + U: Copy + Debug + Eq, { match self { BoolSimplifiedType => BoolSimplifiedType, @@ -171,7 +171,7 @@ impl SimplifiedTypeGen { impl<'a, D> HashStable> for SimplifiedTypeGen where - D: Copy + Debug + Ord + Eq + HashStable>, + D: Copy + Debug + Eq + HashStable>, { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); From c40342420370225d7d7138cb5d19f84b3146a77d Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Wed, 23 Feb 2022 10:42:46 +0100 Subject: [PATCH 08/16] remove feature gate in control_flow examples --- library/core/src/ops/control_flow.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/library/core/src/ops/control_flow.rs b/library/core/src/ops/control_flow.rs index 10a24a545d329..e34e26746c0a5 100644 --- a/library/core/src/ops/control_flow.rs +++ b/library/core/src/ops/control_flow.rs @@ -134,7 +134,6 @@ impl ControlFlow { /// # Examples /// /// ``` - /// #![feature(control_flow_enum)] /// use std::ops::ControlFlow; /// /// assert!(ControlFlow::::Break(3).is_break()); @@ -151,7 +150,6 @@ impl ControlFlow { /// # Examples /// /// ``` - /// #![feature(control_flow_enum)] /// use std::ops::ControlFlow; /// /// assert!(!ControlFlow::::Break(3).is_continue()); From 65614e91ad847e3d2941e1308bb2b1d916eba25f Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Tue, 22 Feb 2022 10:44:56 +0000 Subject: [PATCH 09/16] riscv32imc_esp_espidf: set max_atomic_width to 64 --- compiler/rustc_target/src/spec/riscv32imc_esp_espidf.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_target/src/spec/riscv32imc_esp_espidf.rs b/compiler/rustc_target/src/spec/riscv32imc_esp_espidf.rs index fb084afe960de..d506e7f6aacbc 100644 --- a/compiler/rustc_target/src/spec/riscv32imc_esp_espidf.rs +++ b/compiler/rustc_target/src/spec/riscv32imc_esp_espidf.rs @@ -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(), From dbe0007a49ea46e1a187dc3d321b568a90bff0ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Wed, 23 Feb 2022 17:11:18 +0200 Subject: [PATCH 10/16] :arrow_up: rust-analyzer --- src/tools/rust-analyzer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/rust-analyzer b/src/tools/rust-analyzer index 02904e99acc3d..d6ed146a1caa4 160000 --- a/src/tools/rust-analyzer +++ b/src/tools/rust-analyzer @@ -1 +1 @@ -Subproject commit 02904e99acc3daf39b56ed18aa07e62aeb9492c5 +Subproject commit d6ed146a1caa41c65a831efbc80d79067c8f5955 From be454f056fc7637da6d1922c532d73831dc072db Mon Sep 17 00:00:00 2001 From: Arlo Siemsen Date: Thu, 14 Oct 2021 10:26:42 -0700 Subject: [PATCH 11/16] Change `char` type in debuginfo to DW_ATE_UTF Rust previously encoded the `char` type as DW_ATE_unsigned_char. The more appropriate encoding is DW_ATE_UTF. Clang uses this same debug encoding for char32_t. This fixes the display of `char` types in Windows debuggers as well as LLDB. --- compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs | 4 ++-- src/test/debuginfo/basic-types.rs | 3 ++- src/test/debuginfo/borrowed-basic.rs | 3 +-- src/test/debuginfo/borrowed-unique-basic.rs | 3 +-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index ef87b7b1a7e07..4ca92b3efe098 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -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; @@ -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), diff --git a/src/test/debuginfo/basic-types.rs b/src/test/debuginfo/basic-types.rs index c8879856b9670..07d33be2a071f 100644 --- a/src/test/debuginfo/basic-types.rs +++ b/src/test/debuginfo/basic-types.rs @@ -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 diff --git a/src/test/debuginfo/borrowed-basic.rs b/src/test/debuginfo/borrowed-basic.rs index c3868d46ba485..b4bb7c146d9df 100644 --- a/src/test/debuginfo/borrowed-basic.rs +++ b/src/test/debuginfo/borrowed-basic.rs @@ -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' diff --git a/src/test/debuginfo/borrowed-unique-basic.rs b/src/test/debuginfo/borrowed-unique-basic.rs index b39f24e029e31..f38cbc10dd3ac 100644 --- a/src/test/debuginfo/borrowed-unique-basic.rs +++ b/src/test/debuginfo/borrowed-unique-basic.rs @@ -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 From 715262f151b985be646f75ef4b22aefa371b7cd6 Mon Sep 17 00:00:00 2001 From: Waffle Maybe Date: Wed, 23 Feb 2022 21:10:04 +0300 Subject: [PATCH 12/16] Fix a typo in documentation of `array::IntoIter::new_unchecked` --- library/core/src/array/iter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index 72a634443e877..e5024c215be9c 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -93,7 +93,7 @@ impl IntoIter { /// /// - 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 From 182d335870265a102c0f6467db65b5e59bd97e24 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 22 Feb 2022 18:49:12 -0500 Subject: [PATCH 13/16] Miri: relax fn ptr check --- .../src/interpret/validity.rs | 31 ++++++----- .../consts/const-eval/ub-ref-ptr.32bit.stderr | 51 +++++++++++++++---- .../consts/const-eval/ub-ref-ptr.64bit.stderr | 51 +++++++++++++++---- src/test/ui/consts/const-eval/ub-ref-ptr.rs | 8 +++ 4 files changed, 110 insertions(+), 31 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index 54e29299e6c97..0bf86d52080ea 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -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 `!`" }), diff --git a/src/test/ui/consts/const-eval/ub-ref-ptr.32bit.stderr b/src/test/ui/consts/const-eval/ub-ref-ptr.32bit.stderr index c8ec7cc4875a5..bf4e2926d51c0 100644 --- a/src/test/ui/consts/const-eval/ub-ref-ptr.32bit.stderr +++ b/src/test/ui/consts/const-eval/ub-ref-ptr.32bit.stderr @@ -43,7 +43,7 @@ LL | const NULL_BOX: Box = unsafe { mem::transmute(0usize) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:30:1 + --> $DIR/ub-ref-ptr.rs:31:1 | LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc15, but expected initialized plain (non-pointer) bytes @@ -54,7 +54,7 @@ LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:33:1 + --> $DIR/ub-ref-ptr.rs:34:1 | LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .: encountered a pointer, but expected plain (non-pointer) bytes @@ -65,7 +65,7 @@ LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }]; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:36:1 + --> $DIR/ub-ref-ptr.rs:37:1 | LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .: encountered a pointer, but expected plain (non-pointer) bytes @@ -76,7 +76,7 @@ LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[us } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:39:1 + --> $DIR/ub-ref-ptr.rs:40:1 | LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a dangling reference (address 0x539 is unallocated) @@ -87,7 +87,7 @@ LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:42:1 + --> $DIR/ub-ref-ptr.rs:43:1 | LL | const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a dangling box (address 0x539 is unallocated) @@ -98,7 +98,7 @@ LL | const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:45:1 + --> $DIR/ub-ref-ptr.rs:46:1 | LL | const UNINIT_PTR: *const i32 = unsafe { MaybeUninit { uninit: () }.init }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized raw pointer @@ -109,16 +109,49 @@ LL | const UNINIT_PTR: *const i32 = unsafe { MaybeUninit { uninit: () }.init }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:47:1 + --> $DIR/ub-ref-ptr.rs:49:1 + | +LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a potentially null function pointer + | + = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. + = note: the raw bytes of the constant (size: 4, align: 4) { + 00 00 00 00 │ .... + } + +error[E0080]: it is undefined behavior to use this value + --> $DIR/ub-ref-ptr.rs:51:1 | LL | const UNINIT_FN_PTR: fn() = unsafe { MaybeUninit { uninit: () }.init }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes, but expected a function pointer + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes, but expected a proper pointer or integer value | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 4, align: 4) { __ __ __ __ │ ░░░░ } -error: aborting due to 11 previous errors +error[E0080]: it is undefined behavior to use this value + --> $DIR/ub-ref-ptr.rs:53:1 + | +LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0x0000000d, but expected a function pointer + | + = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. + = note: the raw bytes of the constant (size: 4, align: 4) { + 0d 00 00 00 │ .... + } + +error[E0080]: it is undefined behavior to use this value + --> $DIR/ub-ref-ptr.rs:55:1 + | +LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc41, but expected a function pointer + | + = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. + = note: the raw bytes of the constant (size: 4, align: 4) { + ╾─alloc41─╼ │ ╾──╼ + } + +error: aborting due to 14 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/ub-ref-ptr.64bit.stderr b/src/test/ui/consts/const-eval/ub-ref-ptr.64bit.stderr index 60a174ac5a7f6..ef25e279a0671 100644 --- a/src/test/ui/consts/const-eval/ub-ref-ptr.64bit.stderr +++ b/src/test/ui/consts/const-eval/ub-ref-ptr.64bit.stderr @@ -43,7 +43,7 @@ LL | const NULL_BOX: Box = unsafe { mem::transmute(0usize) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:30:1 + --> $DIR/ub-ref-ptr.rs:31:1 | LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc15, but expected initialized plain (non-pointer) bytes @@ -54,7 +54,7 @@ LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:33:1 + --> $DIR/ub-ref-ptr.rs:34:1 | LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .: encountered a pointer, but expected plain (non-pointer) bytes @@ -65,7 +65,7 @@ LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }]; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:36:1 + --> $DIR/ub-ref-ptr.rs:37:1 | LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .: encountered a pointer, but expected plain (non-pointer) bytes @@ -76,7 +76,7 @@ LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[us } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:39:1 + --> $DIR/ub-ref-ptr.rs:40:1 | LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a dangling reference (address 0x539 is unallocated) @@ -87,7 +87,7 @@ LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:42:1 + --> $DIR/ub-ref-ptr.rs:43:1 | LL | const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a dangling box (address 0x539 is unallocated) @@ -98,7 +98,7 @@ LL | const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:45:1 + --> $DIR/ub-ref-ptr.rs:46:1 | LL | const UNINIT_PTR: *const i32 = unsafe { MaybeUninit { uninit: () }.init }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized raw pointer @@ -109,16 +109,49 @@ LL | const UNINIT_PTR: *const i32 = unsafe { MaybeUninit { uninit: () }.init }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:47:1 + --> $DIR/ub-ref-ptr.rs:49:1 + | +LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a potentially null function pointer + | + = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. + = note: the raw bytes of the constant (size: 8, align: 8) { + 00 00 00 00 00 00 00 00 │ ........ + } + +error[E0080]: it is undefined behavior to use this value + --> $DIR/ub-ref-ptr.rs:51:1 | LL | const UNINIT_FN_PTR: fn() = unsafe { MaybeUninit { uninit: () }.init }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes, but expected a function pointer + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes, but expected a proper pointer or integer value | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 8) { __ __ __ __ __ __ __ __ │ ░░░░░░░░ } -error: aborting due to 11 previous errors +error[E0080]: it is undefined behavior to use this value + --> $DIR/ub-ref-ptr.rs:53:1 + | +LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0x000000000000000d, but expected a function pointer + | + = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. + = note: the raw bytes of the constant (size: 8, align: 8) { + 0d 00 00 00 00 00 00 00 │ ........ + } + +error[E0080]: it is undefined behavior to use this value + --> $DIR/ub-ref-ptr.rs:55:1 + | +LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc41, but expected a function pointer + | + = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. + = note: the raw bytes of the constant (size: 8, align: 8) { + ╾───────alloc41───────╼ │ ╾──────╼ + } + +error: aborting due to 14 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/ub-ref-ptr.rs b/src/test/ui/consts/const-eval/ub-ref-ptr.rs index 8857ae4caac83..1887cb24bf467 100644 --- a/src/test/ui/consts/const-eval/ub-ref-ptr.rs +++ b/src/test/ui/consts/const-eval/ub-ref-ptr.rs @@ -24,6 +24,7 @@ const NULL: &u16 = unsafe { mem::transmute(0usize) }; const NULL_BOX: Box = unsafe { mem::transmute(0usize) }; //~^ ERROR it is undefined behavior to use this value + // It is very important that we reject this: We do promote `&(4 * REF_AS_USIZE)`, // but that would fail to compile; so we ended up breaking user code that would // have worked fine had we not promoted. @@ -44,7 +45,14 @@ const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; const UNINIT_PTR: *const i32 = unsafe { MaybeUninit { uninit: () }.init }; //~^ ERROR it is undefined behavior to use this value + +const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) }; +//~^ ERROR it is undefined behavior to use this value const UNINIT_FN_PTR: fn() = unsafe { MaybeUninit { uninit: () }.init }; //~^ ERROR it is undefined behavior to use this value +const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; +//~^ ERROR it is undefined behavior to use this value +const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; +//~^ ERROR it is undefined behavior to use this value fn main() {} From c46d9f6c89fc50dd80fb502677bc8d04e8260ed3 Mon Sep 17 00:00:00 2001 From: Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> Date: Wed, 23 Feb 2022 23:18:42 +0100 Subject: [PATCH 14/16] Update library/std/src/io/error.rs Co-authored-by: Josh Triplett --- library/std/src/io/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 6adf26a35a2a1..3df3749d676e8 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -148,7 +148,7 @@ struct Custom { /// "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 list of errors from here into your test code. This seems counterintuitive, +/// 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)] From eb795c24fba3da62570e144b405d7df7cf8f9963 Mon Sep 17 00:00:00 2001 From: Dylan DPC Date: Thu, 24 Feb 2022 00:30:07 +0100 Subject: [PATCH 15/16] word wrpa --- library/std/src/io/error.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 3df3749d676e8..a69062ee2cac7 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -144,13 +144,16 @@ struct Custom { /// /// # 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 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. +/// 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)] From 3f4b039e33f2a6da6413bac416be97c1b0738ca8 Mon Sep 17 00:00:00 2001 From: Dylan DPC Date: Thu, 24 Feb 2022 00:37:06 +0100 Subject: [PATCH 16/16] word wrpa --- library/std/src/io/error.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index a69062ee2cac7..17e2b97545a94 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -144,13 +144,13 @@ struct Custom { /// /// # Handling errors and matching on `ErrorKind` /// -/// In application code, use `match` for the `ErrorKind` values you are +/// 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 +/// 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.