From 9208c08a771199e49aa1bff0e80354124eddbe5f Mon Sep 17 00:00:00 2001 From: Alan Egerton Date: Wed, 8 Jun 2022 12:08:00 +0100 Subject: [PATCH 001/103] Use liballoc's specialised in-place vec collection liballoc already specialises in-place vector collection, so manually reimplementing it in `IdFunctor::try_map_id` was superfluous. --- compiler/rustc_data_structures/src/functor.rs | 36 ++----------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/compiler/rustc_data_structures/src/functor.rs b/compiler/rustc_data_structures/src/functor.rs index a3d3f988344c6..84cb417dd8936 100644 --- a/compiler/rustc_data_structures/src/functor.rs +++ b/compiler/rustc_data_structures/src/functor.rs @@ -34,43 +34,11 @@ impl IdFunctor for Vec { type Inner = T; #[inline] - fn try_map_id(self, mut f: F) -> Result + fn try_map_id(self, f: F) -> Result where F: FnMut(Self::Inner) -> Result, { - struct HoleVec { - vec: Vec>, - hole: Option, - } - - impl Drop for HoleVec { - fn drop(&mut self) { - unsafe { - for (index, slot) in self.vec.iter_mut().enumerate() { - if self.hole != Some(index) { - mem::ManuallyDrop::drop(slot); - } - } - } - } - } - - unsafe { - let (ptr, length, capacity) = self.into_raw_parts(); - let vec = Vec::from_raw_parts(ptr.cast(), length, capacity); - let mut hole_vec = HoleVec { vec, hole: None }; - - for (index, slot) in hole_vec.vec.iter_mut().enumerate() { - hole_vec.hole = Some(index); - let original = mem::ManuallyDrop::take(slot); - let mapped = f(original)?; - *slot = mem::ManuallyDrop::new(mapped); - hole_vec.hole = None; - } - - mem::forget(hole_vec); - Ok(Vec::from_raw_parts(ptr, length, capacity)) - } + self.into_iter().map(f).collect() } } From a02ec4cf1817b6ec7f154e11521cb76507cd4a3c Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Wed, 12 Oct 2022 18:39:22 +0200 Subject: [PATCH 002/103] remove HRTB from `[T]::is_sorted_by{,_key}` --- library/core/src/slice/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 56133f346ae9e..e874b57636894 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -3724,9 +3724,9 @@ impl [T] { /// [`is_sorted`]: slice::is_sorted #[unstable(feature = "is_sorted", reason = "new API", issue = "53485")] #[must_use] - pub fn is_sorted_by(&self, mut compare: F) -> bool + pub fn is_sorted_by<'a, F>(&'a self, mut compare: F) -> bool where - F: FnMut(&T, &T) -> Option, + F: FnMut(&'a T, &'a T) -> Option, { self.iter().is_sorted_by(|a, b| compare(*a, *b)) } @@ -3750,9 +3750,9 @@ impl [T] { #[inline] #[unstable(feature = "is_sorted", reason = "new API", issue = "53485")] #[must_use] - pub fn is_sorted_by_key(&self, f: F) -> bool + pub fn is_sorted_by_key<'a, F, K>(&'a self, f: F) -> bool where - F: FnMut(&T) -> K, + F: FnMut(&'a T) -> K, K: PartialOrd, { self.iter().is_sorted_by_key(f) From f3d7b39cdf483ae543757fbef369c166650e66f2 Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Wed, 12 Oct 2022 18:54:14 +0200 Subject: [PATCH 003/103] add regression test --- .../slice_is_sorted_by_borrow.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/test/ui/array-slice-vec/slice_is_sorted_by_borrow.rs diff --git a/src/test/ui/array-slice-vec/slice_is_sorted_by_borrow.rs b/src/test/ui/array-slice-vec/slice_is_sorted_by_borrow.rs new file mode 100644 index 0000000000000..073280d0fab1f --- /dev/null +++ b/src/test/ui/array-slice-vec/slice_is_sorted_by_borrow.rs @@ -0,0 +1,20 @@ +// check-pass +// regression test for https://github.com/rust-lang/rust/issues/53485#issuecomment-885393452 + +#![feature(is_sorted)] + +struct A { + name: String, +} + +fn main() { + let a = &[ + A { + name: "1".to_string(), + }, + A { + name: "2".to_string(), + }, + ]; + assert!(a.is_sorted_by_key(|a| a.name.as_str())); +} From c5ad97da258bb47cba2f888cee73b0f4b5289d58 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sun, 16 Oct 2022 14:53:21 +0100 Subject: [PATCH 004/103] Use IsTerminal in rustc_errors --- Cargo.lock | 1 - compiler/rustc_errors/Cargo.toml | 1 - compiler/rustc_errors/src/emitter.rs | 6 +++--- compiler/rustc_errors/src/lib.rs | 1 + 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d5acab8139c98..6c0bb32dec71e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3452,7 +3452,6 @@ name = "rustc_errors" version = "0.0.0" dependencies = [ "annotate-snippets", - "atty", "rustc_ast", "rustc_ast_pretty", "rustc_data_structures", diff --git a/compiler/rustc_errors/Cargo.toml b/compiler/rustc_errors/Cargo.toml index 7803a0792e12c..eb560a68b5697 100644 --- a/compiler/rustc_errors/Cargo.toml +++ b/compiler/rustc_errors/Cargo.toml @@ -18,7 +18,6 @@ rustc_target = { path = "../rustc_target" } rustc_hir = { path = "../rustc_hir" } rustc_lint_defs = { path = "../rustc_lint_defs" } unicode-width = "0.1.4" -atty = "0.2" termcolor = "1.0" annotate-snippets = "0.9" termize = "0.1.1" diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index cd6413bc3ec62..12a93fbedf900 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -28,8 +28,8 @@ use rustc_error_messages::FluentArgs; use rustc_span::hygiene::{ExpnKind, MacroKind}; use std::borrow::Cow; use std::cmp::{max, min, Reverse}; -use std::io; use std::io::prelude::*; +use std::io::{self, IsTerminal}; use std::iter; use std::path::Path; use termcolor::{Ansi, BufferWriter, ColorChoice, ColorSpec, StandardStream}; @@ -619,14 +619,14 @@ impl ColorConfig { fn to_color_choice(self) -> ColorChoice { match self { ColorConfig::Always => { - if atty::is(atty::Stream::Stderr) { + if io::stderr().is_terminal() { ColorChoice::Always } else { ColorChoice::AlwaysAnsi } } ColorConfig::Never => ColorChoice::Never, - ColorConfig::Auto if atty::is(atty::Stream::Stderr) => ColorChoice::Auto, + ColorConfig::Auto if io::stderr().is_terminal() => ColorChoice::Auto, ColorConfig::Auto => ColorChoice::Never, } } diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 9fafbe4bd407e..814dba10484eb 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -5,6 +5,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(drain_filter)] #![feature(if_let_guard)] +#![feature(is_terminal)] #![feature(adt_const_params)] #![feature(let_chains)] #![feature(never_type)] From 34f61dd56718261548f58e9cd6bb9c4146825a1e Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sun, 16 Oct 2022 14:55:18 +0100 Subject: [PATCH 005/103] Use IsTerminal in rustc_driver --- compiler/rustc_driver/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 7d5604fcabcc9..d1d590d2d08dd 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -5,6 +5,7 @@ //! This API is completely unstable and subject to change. #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] +#![feature(is_terminal)] #![feature(once_cell)] #![recursion_limit = "256"] #![allow(rustc::potential_query_instability)] @@ -26,7 +27,6 @@ use rustc_feature::find_gated_cfg; use rustc_interface::util::{self, collect_crate_types, get_codegen_backend}; use rustc_interface::{interface, Queries}; use rustc_lint::LintStore; -use rustc_log::stdout_isatty; use rustc_metadata::locator; use rustc_save_analysis as save; use rustc_save_analysis::DumpHandler; @@ -47,7 +47,7 @@ use std::default::Default; use std::env; use std::ffi::OsString; use std::fs; -use std::io::{self, Read, Write}; +use std::io::{self, IsTerminal, Read, Write}; use std::panic::{self, catch_unwind}; use std::path::PathBuf; use std::process::{self, Command, Stdio}; @@ -538,7 +538,7 @@ fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) { } text.push('\n'); } - if stdout_isatty() { + if io::stdout().is_terminal() { show_content_with_pager(&text); } else { print!("{}", text); From d60ba29b10e2c4741bbd8701c74b85c09b70e03d Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sun, 16 Oct 2022 14:55:44 +0100 Subject: [PATCH 006/103] Use IsTerminal in rustc_log --- Cargo.lock | 1 - compiler/rustc_log/Cargo.toml | 1 - compiler/rustc_log/src/lib.rs | 7 ++++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6c0bb32dec71e..bf5ff830acc47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3724,7 +3724,6 @@ dependencies = [ name = "rustc_log" version = "0.0.0" dependencies = [ - "atty", "rustc_span", "tracing", "tracing-subscriber", diff --git a/compiler/rustc_log/Cargo.toml b/compiler/rustc_log/Cargo.toml index 1b2cde605556d..3c50827c1abc3 100644 --- a/compiler/rustc_log/Cargo.toml +++ b/compiler/rustc_log/Cargo.toml @@ -4,7 +4,6 @@ version = "0.0.0" edition = "2021" [dependencies] -atty = "0.2" tracing = "0.1.28" tracing-subscriber = { version = "0.3.3", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] } tracing-tree = "0.2.0" diff --git a/compiler/rustc_log/src/lib.rs b/compiler/rustc_log/src/lib.rs index 458f5e87baeac..ddf29c488c933 100644 --- a/compiler/rustc_log/src/lib.rs +++ b/compiler/rustc_log/src/lib.rs @@ -40,10 +40,11 @@ #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] +#![feature(is_terminal)] use std::env::{self, VarError}; use std::fmt::{self, Display}; -use std::io; +use std::io::{self, IsTerminal}; use tracing_subscriber::filter::{Directive, EnvFilter, LevelFilter}; use tracing_subscriber::layer::SubscriberExt; @@ -93,11 +94,11 @@ pub fn init_env_logger(env: &str) -> Result<(), Error> { } pub fn stdout_isatty() -> bool { - atty::is(atty::Stream::Stdout) + io::stdout().is_terminal() } pub fn stderr_isatty() -> bool { - atty::is(atty::Stream::Stderr) + io::stderr().is_terminal() } #[derive(Debug)] From e3d44dd4bdd901d284ec47a29e0bb7d825f9786b Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sun, 16 Oct 2022 14:56:03 +0100 Subject: [PATCH 007/103] Use IsTerminal in librustdoc --- Cargo.lock | 1 - src/librustdoc/Cargo.toml | 1 - src/librustdoc/lib.rs | 5 +++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bf5ff830acc47..6630b6479dc48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4272,7 +4272,6 @@ version = "0.0.0" dependencies = [ "arrayvec", "askama", - "atty", "expect-test", "itertools", "minifier", diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml index 7bc35c7d5516f..63ccee14caa9d 100644 --- a/src/librustdoc/Cargo.toml +++ b/src/librustdoc/Cargo.toml @@ -9,7 +9,6 @@ path = "lib.rs" [dependencies] arrayvec = { version = "0.7", default-features = false } askama = { version = "0.11", default-features = false, features = ["config"] } -atty = "0.2" itertools = "0.10.1" minifier = "0.2.2" once_cell = "1.10.0" diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index ef01b854e5a69..7276b9ce0ee7d 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -8,6 +8,7 @@ #![feature(box_patterns)] #![feature(control_flow_enum)] #![feature(drain_filter)] +#![feature(is_terminal)] #![feature(let_chains)] #![feature(test)] #![feature(never_type)] @@ -69,7 +70,7 @@ extern crate jemalloc_sys; use std::default::Default; use std::env::{self, VarError}; -use std::io; +use std::io::{self, IsTerminal}; use std::process; use rustc_driver::abort_on_err; @@ -180,7 +181,7 @@ fn init_logging() { let color_logs = match std::env::var("RUSTDOC_LOG_COLOR").as_deref() { Ok("always") => true, Ok("never") => false, - Ok("auto") | Err(VarError::NotPresent) => atty::is(atty::Stream::Stdout), + Ok("auto") | Err(VarError::NotPresent) => io::stdout().is_terminal(), Ok(value) => early_error( ErrorOutputType::default(), &format!("invalid log color value '{}': expected one of always, never, or auto", value), From a3c3f722b7e71d5c9985ba318c700b697fd2c106 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Sat, 22 Oct 2022 03:03:48 +0300 Subject: [PATCH 008/103] Fix mod_inv termination for the last iteration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On usize=u64 platforms, the 4th iteration would overflow the `mod_gate` back to 0. Similarly for usize=u32 platforms, the 3rd iteration would overflow much the same way. I tested various approaches to resolving this, including approaches with `saturating_mul` and `widening_mul` to a double usize. Turns out LLVM likes `mul_with_overflow` the best. In fact now, that LLVM can see the iteration count is limited, it will happily unroll the loop into a nice linear sequence. You will also notice that the code around the loop got simplified somewhat. Now that LLVM is handling the loop nicely, there isn’t any more reasons to manually unroll the first iteration out of the loop (though looking at the code today I’m not sure all that complexity was necessary in the first place). Fixes #103361 --- library/core/src/ptr/mod.rs | 54 +++++++++++++++++++------------------ library/core/tests/ptr.rs | 12 +++++++++ 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index 8e2bad35993df..8a9bcf38b906c 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -1571,8 +1571,8 @@ pub(crate) unsafe fn align_offset(p: *const T, a: usize) -> usize { // FIXME(#75598): Direct use of these intrinsics improves codegen significantly at opt-level <= // 1, where the method versions of these operations are not inlined. use intrinsics::{ - cttz_nonzero, exact_div, unchecked_rem, unchecked_shl, unchecked_shr, unchecked_sub, - wrapping_add, wrapping_mul, wrapping_sub, + cttz_nonzero, exact_div, mul_with_overflow, unchecked_rem, unchecked_shl, unchecked_shr, + unchecked_sub, wrapping_add, wrapping_mul, wrapping_sub, }; /// Calculate multiplicative modular inverse of `x` modulo `m`. @@ -1592,36 +1592,38 @@ pub(crate) unsafe fn align_offset(p: *const T, a: usize) -> usize { const INV_TABLE_MOD_16: [u8; 8] = [1, 11, 13, 7, 9, 3, 5, 15]; /// Modulo for which the `INV_TABLE_MOD_16` is intended. const INV_TABLE_MOD: usize = 16; - /// INV_TABLE_MOD² - const INV_TABLE_MOD_SQUARED: usize = INV_TABLE_MOD * INV_TABLE_MOD; - let table_inverse = INV_TABLE_MOD_16[(x & (INV_TABLE_MOD - 1)) >> 1] as usize; // SAFETY: `m` is required to be a power-of-two, hence non-zero. let m_minus_one = unsafe { unchecked_sub(m, 1) }; - if m <= INV_TABLE_MOD { - table_inverse & m_minus_one - } else { - // We iterate "up" using the following formula: - // - // $$ xy ≡ 1 (mod 2ⁿ) → xy (2 - xy) ≡ 1 (mod 2²ⁿ) $$ + let mut inverse = INV_TABLE_MOD_16[(x & (INV_TABLE_MOD - 1)) >> 1] as usize; + let mut mod_gate = INV_TABLE_MOD; + // We iterate "up" using the following formula: + // + // $$ xy ≡ 1 (mod 2ⁿ) → xy (2 - xy) ≡ 1 (mod 2²ⁿ) $$ + // + // This application needs to be applied at least until `2²ⁿ ≥ m`, at which point we can + // finally reduce the computation to our desired `m` by taking `inverse mod m`. + // + // This computation is `O(log log m)`, which is to say, that on 64-bit machines this loop + // will always finish in at most 4 iterations. + loop { + // y = y * (2 - xy) mod n // - // until 2²ⁿ ≥ m. Then we can reduce to our desired `m` by taking the result `mod m`. - let mut inverse = table_inverse; - let mut going_mod = INV_TABLE_MOD_SQUARED; - loop { - // y = y * (2 - xy) mod n - // - // Note, that we use wrapping operations here intentionally – the original formula - // uses e.g., subtraction `mod n`. It is entirely fine to do them `mod - // usize::MAX` instead, because we take the result `mod n` at the end - // anyway. - inverse = wrapping_mul(inverse, wrapping_sub(2usize, wrapping_mul(x, inverse))); - if going_mod >= m { - return inverse & m_minus_one; - } - going_mod = wrapping_mul(going_mod, going_mod); + // Note, that we use wrapping operations here intentionally – the original formula + // uses e.g., subtraction `mod n`. It is entirely fine to do them `mod + // usize::MAX` instead, because we take the result `mod n` at the end + // anyway. + if mod_gate >= m { + break; + } + inverse = wrapping_mul(inverse, wrapping_sub(2usize, wrapping_mul(x, inverse))); + let (new_gate, overflow) = mul_with_overflow(mod_gate, mod_gate); + if overflow { + break; } + mod_gate = new_gate; } + inverse & m_minus_one } let addr = p.addr(); diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index 97a369810056d..0977980ba47bf 100644 --- a/library/core/tests/ptr.rs +++ b/library/core/tests/ptr.rs @@ -455,6 +455,18 @@ fn align_offset_various_strides() { assert!(!x); } +#[test] +fn align_offset_issue_103361() { + #[cfg(target_pointer_width = "64")] + const SIZE: usize = 1 << 47; + #[cfg(target_pointer_width = "32")] + const SIZE: usize = 1 << 30; + #[cfg(target_pointer_width = "16")] + const SIZE: usize = 1 << 13; + struct HugeSize([u8; SIZE - 1]); + let _ = (SIZE as *const HugeSize).align_offset(SIZE); +} + #[test] fn offset_from() { let mut a = [0; 5]; From 3b16c0467677dcd3b7f46c028446343dd699c4ba Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 23 Oct 2022 17:02:50 -0700 Subject: [PATCH 009/103] `unchecked_{shl|shr}` should use `u32` as the RHS --- library/core/src/lib.rs | 1 + library/core/src/num/int_macros.rs | 16 ++++--- library/core/src/num/mod.rs | 1 + library/core/src/num/uint_macros.rs | 16 ++++--- src/test/codegen/unchecked_shifts.rs | 65 ++++++++++++++++++++++++++++ 5 files changed, 87 insertions(+), 12 deletions(-) create mode 100644 src/test/codegen/unchecked_shifts.rs diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 9cbfbbb9f399c..357a2ea6775cf 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -130,6 +130,7 @@ #![feature(const_pin)] #![feature(const_ptr_sub_ptr)] #![feature(const_replace)] +#![feature(const_result_drop)] #![feature(const_ptr_as_ref)] #![feature(const_ptr_is_null)] #![feature(const_ptr_read)] diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 81f050cb283d4..451484df99f23 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -757,10 +757,11 @@ macro_rules! int_impl { #[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")] #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - pub const unsafe fn unchecked_shl(self, rhs: Self) -> Self { + pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self { // SAFETY: the caller must uphold the safety contract for // `unchecked_shl`. - unsafe { intrinsics::unchecked_shl(self, rhs) } + // Any legal shift amount is losslessly representable in the self type. + unsafe { intrinsics::unchecked_shl(self, rhs.try_into().ok().unwrap_unchecked()) } } /// Checked shift right. Computes `self >> rhs`, returning `None` if `rhs` is @@ -804,10 +805,11 @@ macro_rules! int_impl { #[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")] #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - pub const unsafe fn unchecked_shr(self, rhs: Self) -> Self { + pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self { // SAFETY: the caller must uphold the safety contract for // `unchecked_shr`. - unsafe { intrinsics::unchecked_shr(self, rhs) } + // Any legal shift amount is losslessly representable in the self type. + unsafe { intrinsics::unchecked_shr(self, rhs.try_into().ok().unwrap_unchecked()) } } /// Checked absolute value. Computes `self.abs()`, returning `None` if @@ -1354,11 +1356,12 @@ macro_rules! int_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] + #[rustc_allow_const_fn_unstable(const_inherent_unchecked_arith)] pub const fn wrapping_shl(self, rhs: u32) -> Self { // SAFETY: the masking by the bitsize of the type ensures that we do not shift // out of bounds unsafe { - intrinsics::unchecked_shl(self, (rhs & ($BITS - 1)) as $SelfT) + self.unchecked_shl(rhs & ($BITS - 1)) } } @@ -1383,11 +1386,12 @@ macro_rules! int_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] + #[rustc_allow_const_fn_unstable(const_inherent_unchecked_arith)] pub const fn wrapping_shr(self, rhs: u32) -> Self { // SAFETY: the masking by the bitsize of the type ensures that we do not shift // out of bounds unsafe { - intrinsics::unchecked_shr(self, (rhs & ($BITS - 1)) as $SelfT) + self.unchecked_shr(rhs & ($BITS - 1)) } } diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 311c5fa5b6834..b2328b001de90 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -3,6 +3,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use crate::ascii; +use crate::convert::TryInto; use crate::error::Error; use crate::intrinsics; use crate::mem; diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 93f65c5c7aaf3..1b728af79d99b 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -901,10 +901,11 @@ macro_rules! uint_impl { #[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")] #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - pub const unsafe fn unchecked_shl(self, rhs: Self) -> Self { + pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self { // SAFETY: the caller must uphold the safety contract for // `unchecked_shl`. - unsafe { intrinsics::unchecked_shl(self, rhs) } + // Any legal shift amount is losslessly representable in the self type. + unsafe { intrinsics::unchecked_shl(self, rhs.try_into().ok().unwrap_unchecked()) } } /// Checked shift right. Computes `self >> rhs`, returning `None` @@ -948,10 +949,11 @@ macro_rules! uint_impl { #[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")] #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - pub const unsafe fn unchecked_shr(self, rhs: Self) -> Self { + pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self { // SAFETY: the caller must uphold the safety contract for // `unchecked_shr`. - unsafe { intrinsics::unchecked_shr(self, rhs) } + // Any legal shift amount is losslessly representable in the self type. + unsafe { intrinsics::unchecked_shr(self, rhs.try_into().ok().unwrap_unchecked()) } } /// Checked exponentiation. Computes `self.pow(exp)`, returning `None` if @@ -1367,11 +1369,12 @@ macro_rules! uint_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] + #[rustc_allow_const_fn_unstable(const_inherent_unchecked_arith)] pub const fn wrapping_shl(self, rhs: u32) -> Self { // SAFETY: the masking by the bitsize of the type ensures that we do not shift // out of bounds unsafe { - intrinsics::unchecked_shl(self, (rhs & ($BITS - 1)) as $SelfT) + self.unchecked_shl(rhs & ($BITS - 1)) } } @@ -1399,11 +1402,12 @@ macro_rules! uint_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] + #[rustc_allow_const_fn_unstable(const_inherent_unchecked_arith)] pub const fn wrapping_shr(self, rhs: u32) -> Self { // SAFETY: the masking by the bitsize of the type ensures that we do not shift // out of bounds unsafe { - intrinsics::unchecked_shr(self, (rhs & ($BITS - 1)) as $SelfT) + self.unchecked_shr(rhs & ($BITS - 1)) } } diff --git a/src/test/codegen/unchecked_shifts.rs b/src/test/codegen/unchecked_shifts.rs new file mode 100644 index 0000000000000..d67d3a88000d8 --- /dev/null +++ b/src/test/codegen/unchecked_shifts.rs @@ -0,0 +1,65 @@ +// compile-flags: -O +// min-llvm-version: 15.0 (LLVM 13 in CI does this differently from submodule LLVM) + +#![crate_type = "lib"] +#![feature(unchecked_math)] + +// CHECK-LABEL: @unchecked_shl_unsigned_same +#[no_mangle] +pub unsafe fn unchecked_shl_unsigned_same(a: u32, b: u32) -> u32 { + // CHECK-NOT: and i32 + // CHECK: shl i32 %a, %b + // CHECK-NOT: and i32 + a.unchecked_shl(b) +} + +// CHECK-LABEL: @unchecked_shl_unsigned_smaller +#[no_mangle] +pub unsafe fn unchecked_shl_unsigned_smaller(a: u16, b: u32) -> u16 { + // This uses -DAG to avoid failing on irrelevant reorderings, + // like emitting the truncation earlier. + + // CHECK-DAG: %[[INRANGE:.+]] = icmp ult i32 %b, 65536 + // CHECK-DAG: tail call void @llvm.assume(i1 %[[INRANGE]]) + // CHECK-DAG: %[[TRUNC:.+]] = trunc i32 %b to i16 + // CHECK-DAG: shl i16 %a, %[[TRUNC]] + a.unchecked_shl(b) +} + +// CHECK-LABEL: @unchecked_shl_unsigned_bigger +#[no_mangle] +pub unsafe fn unchecked_shl_unsigned_bigger(a: u64, b: u32) -> u64 { + // CHECK: %[[EXT:.+]] = zext i32 %b to i64 + // CHECK: shl i64 %a, %[[EXT]] + a.unchecked_shl(b) +} + +// CHECK-LABEL: @unchecked_shr_signed_same +#[no_mangle] +pub unsafe fn unchecked_shr_signed_same(a: i32, b: u32) -> i32 { + // CHECK-NOT: and i32 + // CHECK: ashr i32 %a, %b + // CHECK-NOT: and i32 + a.unchecked_shr(b) +} + +// CHECK-LABEL: @unchecked_shr_signed_smaller +#[no_mangle] +pub unsafe fn unchecked_shr_signed_smaller(a: i16, b: u32) -> i16 { + // This uses -DAG to avoid failing on irrelevant reorderings, + // like emitting the truncation earlier. + + // CHECK-DAG: %[[INRANGE:.+]] = icmp ult i32 %b, 32768 + // CHECK-DAG: tail call void @llvm.assume(i1 %[[INRANGE]]) + // CHECK-DAG: %[[TRUNC:.+]] = trunc i32 %b to i16 + // CHECK-DAG: ashr i16 %a, %[[TRUNC]] + a.unchecked_shr(b) +} + +// CHECK-LABEL: @unchecked_shr_signed_bigger +#[no_mangle] +pub unsafe fn unchecked_shr_signed_bigger(a: i64, b: u32) -> i64 { + // CHECK: %[[EXT:.+]] = zext i32 %b to i64 + // CHECK: ashr i64 %a, %[[EXT]] + a.unchecked_shr(b) +} From 6c54745784b03e614a7a152ef010c05207156c2a Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 28 Oct 2022 23:05:22 +0400 Subject: [PATCH 010/103] Make `pointer::with_metadata_of` const (+simplify implementation) --- library/core/src/ptr/const_ptr.rs | 11 +++-------- library/core/src/ptr/mut_ptr.rs | 15 +++------------ 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index ed16c5f051f7b..56246ccfa8ae9 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -79,19 +79,14 @@ impl *const T { /// } /// ``` #[unstable(feature = "set_ptr_value", issue = "75091")] + #[rustc_const_unstable(feature = "set_ptr_value", issue = "75091")] #[must_use = "returns a new pointer rather than modifying its argument"] #[inline] - pub fn with_metadata_of(self, mut val: *const U) -> *const U + pub const fn with_metadata_of(self, meta: *const U) -> *const U where U: ?Sized, { - let target = &mut val as *mut *const U as *mut *const u8; - // SAFETY: In case of a thin pointer, this operations is identical - // to a simple assignment. In case of a fat pointer, with the current - // fat pointer layout implementation, the first field of such a - // pointer is always the data pointer, which is likewise assigned. - unsafe { *target = self as *const u8 }; - val + from_raw_parts::(self as *const (), metadata(meta)) } /// Changes constness without changing the type. diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 6764002bcd434..ddbe69d97f260 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -78,23 +78,14 @@ impl *mut T { /// } /// ``` #[unstable(feature = "set_ptr_value", issue = "75091")] + #[rustc_const_unstable(feature = "set_ptr_value", issue = "75091")] #[must_use = "returns a new pointer rather than modifying its argument"] #[inline] - pub fn with_metadata_of(self, val: *const U) -> *mut U + pub const fn with_metadata_of(self, meta: *const U) -> *mut U where U: ?Sized, { - // Prepare in the type system that we will replace the pointer value with a mutable - // pointer, taking the mutable provenance from the `self` pointer. - let mut val = val as *mut U; - // Pointer to the pointer value within the value. - let target = &mut val as *mut *mut U as *mut *mut u8; - // SAFETY: In case of a thin pointer, this operations is identical - // to a simple assignment. In case of a fat pointer, with the current - // fat pointer layout implementation, the first field of such a - // pointer is always the data pointer, which is likewise assigned. - unsafe { *target = self as *mut u8 }; - val + from_raw_parts_mut::(self as *mut (), metadata(meta)) } /// Changes constness without changing the type. From d3b51926f81cd15740d5a06172a2697bee1d6dfc Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 28 Oct 2022 23:06:29 +0400 Subject: [PATCH 011/103] Simplify implementation of various pointer methods --- library/core/src/lib.rs | 1 + library/core/src/ptr/const_ptr.rs | 18 +++++++----------- library/core/src/ptr/mut_ptr.rs | 21 +++++++-------------- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 659409557c910..a68d8b55e3094 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -154,6 +154,7 @@ #![feature(maybe_uninit_uninit_array)] #![feature(ptr_alignment_type)] #![feature(ptr_metadata)] +#![feature(set_ptr_value)] #![feature(slice_ptr_get)] #![feature(slice_split_at_unchecked)] #![feature(str_internals)] diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 56246ccfa8ae9..85e2b425c4046 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -473,8 +473,7 @@ impl *const T { #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn byte_offset(self, count: isize) -> Self { // SAFETY: the caller must uphold the safety contract for `offset`. - let this = unsafe { self.cast::().offset(count).cast::<()>() }; - from_raw_parts::(this, metadata(self)) + unsafe { self.cast::().offset(count).with_metadata_of(self) } } /// Calculates the offset from a pointer using wrapping arithmetic. @@ -554,7 +553,7 @@ impl *const T { #[unstable(feature = "pointer_byte_offsets", issue = "96283")] #[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")] pub const fn wrapping_byte_offset(self, count: isize) -> Self { - from_raw_parts::(self.cast::().wrapping_offset(count).cast::<()>(), metadata(self)) + self.cast::().wrapping_offset(count).with_metadata_of(self) } /// Masks out bits of the pointer according to a mask. @@ -567,8 +566,7 @@ impl *const T { #[must_use = "returns a new pointer rather than modifying its argument"] #[inline(always)] pub fn mask(self, mask: usize) -> *const T { - let this = intrinsics::ptr_mask(self.cast::<()>(), mask); - from_raw_parts::(this, metadata(self)) + intrinsics::ptr_mask(self.cast::<()>(), mask).with_metadata_of(self) } /// Calculates the distance between two pointers. The returned value is in @@ -906,8 +904,7 @@ impl *const T { #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn byte_add(self, count: usize) -> Self { // SAFETY: the caller must uphold the safety contract for `add`. - let this = unsafe { self.cast::().add(count).cast::<()>() }; - from_raw_parts::(this, metadata(self)) + unsafe { self.cast::().add(count).with_metadata_of(self) } } /// Calculates the offset from a pointer (convenience for @@ -993,8 +990,7 @@ impl *const T { #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn byte_sub(self, count: usize) -> Self { // SAFETY: the caller must uphold the safety contract for `sub`. - let this = unsafe { self.cast::().sub(count).cast::<()>() }; - from_raw_parts::(this, metadata(self)) + unsafe { self.cast::().sub(count).with_metadata_of(self) } } /// Calculates the offset from a pointer using wrapping arithmetic. @@ -1074,7 +1070,7 @@ impl *const T { #[unstable(feature = "pointer_byte_offsets", issue = "96283")] #[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")] pub const fn wrapping_byte_add(self, count: usize) -> Self { - from_raw_parts::(self.cast::().wrapping_add(count).cast::<()>(), metadata(self)) + self.cast::().wrapping_add(count).with_metadata_of(self) } /// Calculates the offset from a pointer using wrapping arithmetic. @@ -1154,7 +1150,7 @@ impl *const T { #[unstable(feature = "pointer_byte_offsets", issue = "96283")] #[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")] pub const fn wrapping_byte_sub(self, count: usize) -> Self { - from_raw_parts::(self.cast::().wrapping_sub(count).cast::<()>(), metadata(self)) + self.cast::().wrapping_sub(count).with_metadata_of(self) } /// Reads the value from `self` without moving it. This leaves the diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index ddbe69d97f260..cff41e3654280 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -487,8 +487,7 @@ impl *mut T { #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn byte_offset(self, count: isize) -> Self { // SAFETY: the caller must uphold the safety contract for `offset`. - let this = unsafe { self.cast::().offset(count).cast::<()>() }; - from_raw_parts_mut::(this, metadata(self)) + unsafe { self.cast::().offset(count).with_metadata_of(self) } } /// Calculates the offset from a pointer using wrapping arithmetic. @@ -567,10 +566,7 @@ impl *mut T { #[unstable(feature = "pointer_byte_offsets", issue = "96283")] #[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")] pub const fn wrapping_byte_offset(self, count: isize) -> Self { - from_raw_parts_mut::( - self.cast::().wrapping_offset(count).cast::<()>(), - metadata(self), - ) + self.cast::().wrapping_offset(count).with_metadata_of(self) } /// Masks out bits of the pointer according to a mask. @@ -583,8 +579,7 @@ impl *mut T { #[must_use = "returns a new pointer rather than modifying its argument"] #[inline(always)] pub fn mask(self, mask: usize) -> *mut T { - let this = intrinsics::ptr_mask(self.cast::<()>(), mask) as *mut (); - from_raw_parts_mut::(this, metadata(self)) + intrinsics::ptr_mask(self.cast::<()>(), mask).cast_mut().with_metadata_of(self) } /// Returns `None` if the pointer is null, or else returns a unique reference to @@ -1011,8 +1006,7 @@ impl *mut T { #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn byte_add(self, count: usize) -> Self { // SAFETY: the caller must uphold the safety contract for `add`. - let this = unsafe { self.cast::().add(count).cast::<()>() }; - from_raw_parts_mut::(this, metadata(self)) + unsafe { self.cast::().add(count).with_metadata_of(self) } } /// Calculates the offset from a pointer (convenience for @@ -1098,8 +1092,7 @@ impl *mut T { #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn byte_sub(self, count: usize) -> Self { // SAFETY: the caller must uphold the safety contract for `sub`. - let this = unsafe { self.cast::().sub(count).cast::<()>() }; - from_raw_parts_mut::(this, metadata(self)) + unsafe { self.cast::().sub(count).with_metadata_of(self) } } /// Calculates the offset from a pointer using wrapping arithmetic. @@ -1179,7 +1172,7 @@ impl *mut T { #[unstable(feature = "pointer_byte_offsets", issue = "96283")] #[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")] pub const fn wrapping_byte_add(self, count: usize) -> Self { - from_raw_parts_mut::(self.cast::().wrapping_add(count).cast::<()>(), metadata(self)) + self.cast::().wrapping_add(count).with_metadata_of(self) } /// Calculates the offset from a pointer using wrapping arithmetic. @@ -1259,7 +1252,7 @@ impl *mut T { #[unstable(feature = "pointer_byte_offsets", issue = "96283")] #[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")] pub const fn wrapping_byte_sub(self, count: usize) -> Self { - from_raw_parts_mut::(self.cast::().wrapping_sub(count).cast::<()>(), metadata(self)) + self.cast::().wrapping_sub(count).with_metadata_of(self) } /// Reads the value from `self` without moving it. This leaves the From 7c602360364ac21ee17d5fd81dc142ecb67b56a5 Mon Sep 17 00:00:00 2001 From: Arlo Siemsen Date: Fri, 4 Nov 2022 13:24:57 -0700 Subject: [PATCH 012/103] Fix build of thumbv7a-pc-windows-msvc --- library/panic_unwind/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/panic_unwind/src/lib.rs b/library/panic_unwind/src/lib.rs index 1eb4f378904a9..7e7180a38e2f2 100644 --- a/library/panic_unwind/src/lib.rs +++ b/library/panic_unwind/src/lib.rs @@ -42,7 +42,8 @@ cfg_if::cfg_if! { // L4Re is unix family but does not yet support unwinding. #[path = "dummy.rs"] mod real_imp; - } else if #[cfg(target_env = "msvc")] { + } else if #[cfg(all(target_env = "msvc", not(target_arch = "arm")))] { + // LLVM does not support unwinding on 32 bit ARM msvc (thumbv7a-pc-windows-msvc) #[path = "seh.rs"] mod real_imp; } else if #[cfg(any( From 9f0a8620bd7d325e6d42417b08daff3e55cb88f6 Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Sat, 5 Nov 2022 14:36:38 +0530 Subject: [PATCH 013/103] Improve generating Custom entry function This commit is aimed at making compiler generated entry functions (Basically just C `main` right now) more generic so other targets can do similar things for custom entry. This was initially implemented as part of https://github.com/rust-lang/rust/pull/100316. Currently, this moves the entry function name and Call convention to the target spec. Signed-off-by: Ayush Singh --- compiler/rustc_codegen_llvm/src/abi.rs | 40 +++++++++++-------- compiler/rustc_codegen_llvm/src/context.rs | 10 ++++- compiler/rustc_codegen_llvm/src/declare.rs | 22 ++++++++++ .../src/back/symbol_export.rs | 3 +- compiler/rustc_target/src/abi/call/mod.rs | 28 +++++++++++++ compiler/rustc_target/src/json.rs | 25 ++++++++++++ compiler/rustc_target/src/spec/mod.rs | 27 +++++++++++++ 7 files changed, 135 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index d478efc863a9e..a6fd2a7de6bd0 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -398,23 +398,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { } fn llvm_cconv(&self) -> llvm::CallConv { - match self.conv { - Conv::C | Conv::Rust | Conv::CCmseNonSecureCall => llvm::CCallConv, - Conv::RustCold => llvm::ColdCallConv, - Conv::AmdGpuKernel => llvm::AmdGpuKernel, - Conv::AvrInterrupt => llvm::AvrInterrupt, - Conv::AvrNonBlockingInterrupt => llvm::AvrNonBlockingInterrupt, - Conv::ArmAapcs => llvm::ArmAapcsCallConv, - Conv::Msp430Intr => llvm::Msp430Intr, - Conv::PtxKernel => llvm::PtxKernel, - Conv::X86Fastcall => llvm::X86FastcallCallConv, - Conv::X86Intr => llvm::X86_Intr, - Conv::X86Stdcall => llvm::X86StdcallCallConv, - Conv::X86ThisCall => llvm::X86_ThisCall, - Conv::X86VectorCall => llvm::X86_VectorCall, - Conv::X86_64SysV => llvm::X86_64_SysV, - Conv::X86_64Win64 => llvm::X86_64_Win64, - } + self.conv.into() } fn apply_attrs_llfn(&self, cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value) { @@ -596,3 +580,25 @@ impl<'tcx> AbiBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> { llvm::get_param(self.llfn(), index as c_uint) } } + +impl From for llvm::CallConv { + fn from(conv: Conv) -> Self { + match conv { + Conv::C | Conv::Rust | Conv::CCmseNonSecureCall => llvm::CCallConv, + Conv::RustCold => llvm::ColdCallConv, + Conv::AmdGpuKernel => llvm::AmdGpuKernel, + Conv::AvrInterrupt => llvm::AvrInterrupt, + Conv::AvrNonBlockingInterrupt => llvm::AvrNonBlockingInterrupt, + Conv::ArmAapcs => llvm::ArmAapcsCallConv, + Conv::Msp430Intr => llvm::Msp430Intr, + Conv::PtxKernel => llvm::PtxKernel, + Conv::X86Fastcall => llvm::X86FastcallCallConv, + Conv::X86Intr => llvm::X86_Intr, + Conv::X86Stdcall => llvm::X86StdcallCallConv, + Conv::X86ThisCall => llvm::X86_ThisCall, + Conv::X86VectorCall => llvm::X86_VectorCall, + Conv::X86_64SysV => llvm::X86_64_SysV, + Conv::X86_64Win64 => llvm::X86_64_Win64, + } + } +} diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 79ddfd884dfac..f3ef618fff544 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -570,8 +570,14 @@ impl<'ll, 'tcx> MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> { } fn declare_c_main(&self, fn_type: Self::Type) -> Option { - if self.get_declared_value("main").is_none() { - Some(self.declare_cfn("main", llvm::UnnamedAddr::Global, fn_type)) + let entry_name = self.sess().target.entry_name.as_ref(); + if self.get_declared_value(entry_name).is_none() { + Some(self.declare_entry_fn( + entry_name, + self.sess().target.entry_abi.into(), + llvm::UnnamedAddr::Global, + fn_type, + )) } else { // If the symbol already exists, it is an error: for example, the user wrote // #[no_mangle] extern "C" fn main(..) {..} diff --git a/compiler/rustc_codegen_llvm/src/declare.rs b/compiler/rustc_codegen_llvm/src/declare.rs index f79ef11720df9..dc21a02cec44a 100644 --- a/compiler/rustc_codegen_llvm/src/declare.rs +++ b/compiler/rustc_codegen_llvm/src/declare.rs @@ -90,6 +90,28 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { declare_raw_fn(self, name, llvm::CCallConv, unnamed, visibility, fn_type) } + /// Declare an entry Function + /// + /// The ABI of this function can change depending on the target (although for now the same as + /// `declare_cfn`) + /// + /// If there’s a value with the same name already declared, the function will + /// update the declaration and return existing Value instead. + pub fn declare_entry_fn( + &self, + name: &str, + callconv: llvm::CallConv, + unnamed: llvm::UnnamedAddr, + fn_type: &'ll Type, + ) -> &'ll Value { + let visibility = if self.tcx.sess.target.default_hidden_visibility { + llvm::Visibility::Hidden + } else { + llvm::Visibility::Default + }; + declare_raw_fn(self, name, callconv, unnamed, visibility, fn_type) + } + /// Declare a Rust function. /// /// If there’s a value with the same name already declared, the function will diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index 752f6b1ef40c9..22f534d909ab6 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -180,7 +180,8 @@ fn exported_symbols_provider_local<'tcx>( .collect(); if tcx.entry_fn(()).is_some() { - let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, "main")); + let exported_symbol = + ExportedSymbol::NoDefId(SymbolName::new(tcx, tcx.sess.target.entry_name.as_ref())); symbols.push(( exported_symbol, diff --git a/compiler/rustc_target/src/abi/call/mod.rs b/compiler/rustc_target/src/abi/call/mod.rs index 9e5f0e4d158b2..c622bd36b00c3 100644 --- a/compiler/rustc_target/src/abi/call/mod.rs +++ b/compiler/rustc_target/src/abi/call/mod.rs @@ -3,6 +3,7 @@ use crate::abi::{HasDataLayout, TyAbiInterface, TyAndLayout}; use crate::spec::{self, HasTargetSpec}; use rustc_span::Symbol; use std::fmt; +use std::str::FromStr; mod aarch64; mod amdgpu; @@ -735,6 +736,33 @@ impl<'a, Ty> FnAbi<'a, Ty> { } } +impl FromStr for Conv { + type Err = String; + + fn from_str(s: &str) -> Result { + match s { + "C" => Ok(Conv::C), + "Rust" => Ok(Conv::Rust), + "RustCold" => Ok(Conv::Rust), + "ArmAapcs" => Ok(Conv::ArmAapcs), + "CCmseNonSecureCall" => Ok(Conv::CCmseNonSecureCall), + "Msp430Intr" => Ok(Conv::Msp430Intr), + "PtxKernel" => Ok(Conv::PtxKernel), + "X86Fastcall" => Ok(Conv::X86Fastcall), + "X86Intr" => Ok(Conv::X86Intr), + "X86Stdcall" => Ok(Conv::X86Stdcall), + "X86ThisCall" => Ok(Conv::X86ThisCall), + "X86VectorCall" => Ok(Conv::X86VectorCall), + "X86_64SysV" => Ok(Conv::X86_64SysV), + "X86_64Win64" => Ok(Conv::X86_64Win64), + "AmdGpuKernel" => Ok(Conv::AmdGpuKernel), + "AvrInterrupt" => Ok(Conv::AvrInterrupt), + "AvrNonBlockingInterrupt" => Ok(Conv::AvrNonBlockingInterrupt), + _ => Err(format!("'{}' is not a valid value for entry function call convetion.", s)), + } + } +} + // Some types are used a lot. Make sure they don't unintentionally get bigger. #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] mod size_asserts { diff --git a/compiler/rustc_target/src/json.rs b/compiler/rustc_target/src/json.rs index b5d9263521228..75bb76a9de087 100644 --- a/compiler/rustc_target/src/json.rs +++ b/compiler/rustc_target/src/json.rs @@ -89,3 +89,28 @@ impl ToJson for Option { } } } + +impl ToJson for crate::abi::call::Conv { + fn to_json(&self) -> Json { + let s = match self { + Self::C => "C", + Self::Rust => "Rust", + Self::RustCold => "RustCold", + Self::ArmAapcs => "ArmAapcs", + Self::CCmseNonSecureCall => "CCmseNonSecureCall", + Self::Msp430Intr => "Msp430Intr", + Self::PtxKernel => "PtxKernel", + Self::X86Fastcall => "X86Fastcall", + Self::X86Intr => "X86Intr", + Self::X86Stdcall => "X86Stdcall", + Self::X86ThisCall => "X86ThisCall", + Self::X86VectorCall => "X86VectorCall", + Self::X86_64SysV => "X86_64SysV", + Self::X86_64Win64 => "X86_64Win64", + Self::AmdGpuKernel => "AmdGpuKernel", + Self::AvrInterrupt => "AvrInterrupt", + Self::AvrNonBlockingInterrupt => "AvrNonBlockingInterrupt", + }; + Json::String(s.to_owned()) + } +} diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 72b088d663b1f..617de46a55aa4 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -34,6 +34,7 @@ //! the target's settings, though `target-feature` and `link-args` will *add* //! to the list specified by the target, rather than replace. +use crate::abi::call::Conv; use crate::abi::Endian; use crate::json::{Json, ToJson}; use crate::spec::abi::{lookup as lookup_abi, Abi}; @@ -1668,6 +1669,14 @@ pub struct TargetOptions { /// Whether the target supports stack canary checks. `true` by default, /// since this is most common among tier 1 and tier 2 targets. pub supports_stack_protector: bool, + + // The name of entry function. + // Default value is "main" + pub entry_name: StaticCow, + + // The ABI of entry function. + // Default value is `Conv::C`, i.e. C call convention + pub entry_abi: Conv, } /// Add arguments for the given flavor and also for its "twin" flavors @@ -1884,6 +1893,8 @@ impl Default for TargetOptions { c_enum_min_bits: 32, generate_arange_section: true, supports_stack_protector: true, + entry_name: "main".into(), + entry_abi: Conv::C, } } } @@ -2401,6 +2412,18 @@ impl Target { } } } ); + ($key_name:ident, Conv) => ( { + let name = (stringify!($key_name)).replace("_", "-"); + obj.remove(&name).and_then(|o| o.as_str().and_then(|s| { + match Conv::from_str(s) { + Ok(c) => { + base.$key_name = c; + Some(Ok(())) + } + Err(e) => Some(Err(e)) + } + })).unwrap_or(Ok(())) + } ); } if let Some(j) = obj.remove("target-endian") { @@ -2520,6 +2543,8 @@ impl Target { key!(c_enum_min_bits, u64); key!(generate_arange_section, bool); key!(supports_stack_protector, bool); + key!(entry_name); + key!(entry_abi, Conv)?; if base.is_builtin { // This can cause unfortunate ICEs later down the line. @@ -2770,6 +2795,8 @@ impl ToJson for Target { target_option_val!(c_enum_min_bits); target_option_val!(generate_arange_section); target_option_val!(supports_stack_protector); + target_option_val!(entry_name); + target_option_val!(entry_abi); if let Some(abi) = self.default_adjusted_cabi { d.insert("default-adjusted-cabi".into(), Abi::name(abi).to_json()); From 0af211af67536f0bd0b86ed5d812b0782d232023 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 22 Oct 2022 03:41:09 +0000 Subject: [PATCH 014/103] Don't allow implement CoerceUnsized into dyn-star --- .../src/traits/select/candidate_assembly.rs | 2 +- src/test/ui/dyn-star/unsize-into-ref-dyn-star.rs | 9 +++++++++ src/test/ui/dyn-star/unsize-into-ref-dyn-star.stderr | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/dyn-star/unsize-into-ref-dyn-star.rs create mode 100644 src/test/ui/dyn-star/unsize-into-ref-dyn-star.stderr diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 3671a0d87df57..dd9bb8ca5f90e 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -840,7 +840,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } // `T` -> `Trait` - (_, &ty::Dynamic(..)) => { + (_, &ty::Dynamic(_, _, ty::Dyn)) => { candidates.vec.push(BuiltinUnsizeCandidate); } diff --git a/src/test/ui/dyn-star/unsize-into-ref-dyn-star.rs b/src/test/ui/dyn-star/unsize-into-ref-dyn-star.rs new file mode 100644 index 0000000000000..1e8cafe1561e8 --- /dev/null +++ b/src/test/ui/dyn-star/unsize-into-ref-dyn-star.rs @@ -0,0 +1,9 @@ +#![feature(dyn_star)] +#![allow(incomplete_features)] + +use std::fmt::Debug; + +fn main() { + let i = 42 as &dyn* Debug; + //~^ ERROR non-primitive cast: `i32` as `&dyn* Debug` +} diff --git a/src/test/ui/dyn-star/unsize-into-ref-dyn-star.stderr b/src/test/ui/dyn-star/unsize-into-ref-dyn-star.stderr new file mode 100644 index 0000000000000..f6444a60a4654 --- /dev/null +++ b/src/test/ui/dyn-star/unsize-into-ref-dyn-star.stderr @@ -0,0 +1,9 @@ +error[E0605]: non-primitive cast: `i32` as `&dyn* Debug` + --> $DIR/unsize-into-ref-dyn-star.rs:7:13 + | +LL | let i = 42 as &dyn* Debug; + | ^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0605`. From 6e6c49e7ced47224ecf1a9d14f63f9481fc24cce Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 10 Nov 2022 23:36:20 +0000 Subject: [PATCH 015/103] Don't CoerceUnsized dyn* to dyn* --- .../src/traits/select/candidate_assembly.rs | 2 +- .../src/traits/select/confirmation.rs | 2 +- .../dyn-star/dont-unsize-coerce-dyn-star.rs | 26 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/dyn-star/dont-unsize-coerce-dyn-star.rs diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index dd9bb8ca5f90e..1f912894ccc96 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -779,7 +779,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { match (source.kind(), target.kind()) { // Trait+Kx+'a -> Trait+Ky+'b (upcasts). - (&ty::Dynamic(ref data_a, ..), &ty::Dynamic(ref data_b, ..)) => { + (&ty::Dynamic(ref data_a, _, ty::Dyn), &ty::Dynamic(ref data_b, _, ty::Dyn)) => { // Upcast coercions permit several things: // // 1. Dropping auto traits, e.g., `Foo + Send` to `Foo` diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 28b4bae7cbecf..f132fbc2e4065 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -1145,7 +1145,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { })); } - _ => bug!(), + _ => bug!("source: {source}, target: {target}"), }; Ok(ImplSourceBuiltinData { nested }) diff --git a/src/test/ui/dyn-star/dont-unsize-coerce-dyn-star.rs b/src/test/ui/dyn-star/dont-unsize-coerce-dyn-star.rs new file mode 100644 index 0000000000000..b4ff8a222866a --- /dev/null +++ b/src/test/ui/dyn-star/dont-unsize-coerce-dyn-star.rs @@ -0,0 +1,26 @@ +// check-pass + +#![feature(dyn_star)] +#![allow(incomplete_features)] + +trait AddOne { + fn add1(&mut self) -> usize; +} + +impl AddOne for usize { + fn add1(&mut self) -> usize { + *self += 1; + *self + } +} + +fn add_one(i: &mut (dyn* AddOne + '_)) -> usize { + i.add1() +} + +fn main() { + let mut x = 42usize as dyn* AddOne; + + println!("{}", add_one(&mut x)); + println!("{}", add_one(&mut x)); +} From 4f978dbaf91e7029792dd1f7e14a851ee040aabb Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 10 Nov 2022 23:49:42 +0000 Subject: [PATCH 016/103] Unbreak upcasting --- .../src/traits/select/candidate_assembly.rs | 4 +++- .../rustc_trait_selection/src/traits/select/confirmation.rs | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 1f912894ccc96..b2f010e674e57 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -779,7 +779,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { match (source.kind(), target.kind()) { // Trait+Kx+'a -> Trait+Ky+'b (upcasts). - (&ty::Dynamic(ref data_a, _, ty::Dyn), &ty::Dynamic(ref data_b, _, ty::Dyn)) => { + (&ty::Dynamic(ref data_a, _, dyn_a), &ty::Dynamic(ref data_b, _, dyn_b)) + if dyn_a == dyn_b => + { // Upcast coercions permit several things: // // 1. Dropping auto traits, e.g., `Foo + Send` to `Foo` diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index f132fbc2e4065..16960146473c8 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -919,7 +919,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let mut nested = vec![]; match (source.kind(), target.kind()) { // Trait+Kx+'a -> Trait+Ky+'b (auto traits and lifetime subtyping). - (&ty::Dynamic(ref data_a, r_a, ty::Dyn), &ty::Dynamic(ref data_b, r_b, ty::Dyn)) => { + (&ty::Dynamic(ref data_a, r_a, dyn_a), &ty::Dynamic(ref data_b, r_b, dyn_b)) + if dyn_a == dyn_b => + { // See `assemble_candidates_for_unsizing` for more info. // We already checked the compatibility of auto traits within `assemble_candidates_for_unsizing`. let iter = data_a @@ -938,7 +940,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .map(ty::Binder::dummy), ); let existential_predicates = tcx.mk_poly_existential_predicates(iter); - let source_trait = tcx.mk_dynamic(existential_predicates, r_b, ty::Dyn); + let source_trait = tcx.mk_dynamic(existential_predicates, r_b, dyn_a); // Require that the traits involved in this upcast are **equal**; // only the **lifetime bound** is changed. From 654a4e81a5fcb399ca0a51100e7e6ba27169a3a8 Mon Sep 17 00:00:00 2001 From: ozkanonur Date: Sat, 12 Nov 2022 16:34:43 +0300 Subject: [PATCH 017/103] check if current stage is target build stage r=ozkanonur Signed-off-by: ozkanonur --- src/bootstrap/compile.rs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 18e780a108d5a..61630518c197b 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -1122,13 +1122,18 @@ impl Step for Sysroot { fn run(self, builder: &Builder<'_>) -> Interned { let compiler = self.compiler; let host_dir = builder.out.join(&compiler.host.triple); - let sysroot = if compiler.stage == 0 { - host_dir.join("stage0-sysroot") - } else if builder.download_rustc() { - host_dir.join("ci-rustc-sysroot") - } else { - host_dir.join(format!("stage{}", compiler.stage)) + + let sysroot_dir = |stage| { + if stage == 0 { + host_dir.join("stage0-sysroot") + } else if builder.download_rustc() && compiler.stage != builder.top_stage { + host_dir.join("ci-rustc-sysroot") + } else { + host_dir.join(format!("stage{}", stage)) + } }; + let sysroot = sysroot_dir(compiler.stage); + let _ = fs::remove_dir_all(&sysroot); t!(fs::create_dir_all(&sysroot)); @@ -1139,9 +1144,15 @@ impl Step for Sysroot { "Cross-compiling is not yet supported with `download-rustc`", ); - // #102002, cleanup stage1 and stage0-sysroot folders when using download-rustc so people don't use old versions of the toolchain by accident. - let _ = fs::remove_dir_all(host_dir.join("stage1")); - let _ = fs::remove_dir_all(host_dir.join("stage0-sysroot")); + // #102002, cleanup old toolchain folders when using download-rustc so people don't use them by accident. + for stage in 0..=2 { + if stage != compiler.stage { + let dir = sysroot_dir(stage); + if !dir.ends_with("ci-rustc-sysroot") { + let _ = fs::remove_dir_all(dir); + } + } + } // Copy the compiler into the correct sysroot. let ci_rustc_dir = From 269ce369fee929cf72a75ddbd4f640fd544756d3 Mon Sep 17 00:00:00 2001 From: "Rajput, Rajat" Date: Mon, 5 Sep 2022 10:34:38 +0530 Subject: [PATCH 018/103] migrating rustc_resolve to SessionDiagnostic. work in progress. start implement binding_shadows migrate till self-in-generic-param-default use braces in fluent message as suggested by @compiler-errors. to fix lock file issue reported by CI migrate 'unreachable label' error run formatter name the variables correctly in fluent file SessionDiagnostic -> Diagnostic test "pattern/pat-tuple-field-count-cross.rs" passed test "resolve/bad-env-capture2.rs" passed test "enum/enum-in-scope.rs" and other depended on "resolve_binding_shadows_something_unacceptable" should be passed now. fix crash errors while running test-suite. there might be more. then_some(..) suits better here. all tests passed convert TraitImpl and InvalidAsm. TraitImpl is buggy yet. will fix after receiving help from Zulip migrate "Ralative-2018" migrate "ancestor only" migrate "expected found" migrate "Indeterminate" migrate "module only" revert to the older implementation for now. since this is failing at the moment. follow the convension for fluent variable order the diag attribute as suggested in review comment fix merge error. migrate trait-impl-duplicate make the changes compatible with "Flatten diagnostic slug modules #103345" fix merge remove commented code merge issues fix review comments fix tests --- Cargo.lock | 1 + .../locales/en-US/resolve.ftl | 211 +++++++ compiler/rustc_error_messages/src/lib.rs | 1 + compiler/rustc_errors/src/diagnostic_impls.rs | 6 + compiler/rustc_resolve/Cargo.toml | 1 + compiler/rustc_resolve/src/diagnostics.rs | 544 ++++++------------ compiler/rustc_resolve/src/errors.rs | 474 +++++++++++++++ compiler/rustc_resolve/src/late.rs | 9 +- compiler/rustc_resolve/src/lib.rs | 1 + 9 files changed, 885 insertions(+), 363 deletions(-) create mode 100644 compiler/rustc_error_messages/locales/en-US/resolve.ftl create mode 100644 compiler/rustc_resolve/src/errors.rs diff --git a/Cargo.lock b/Cargo.lock index c105d04c1f440..80df452d37feb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4047,6 +4047,7 @@ dependencies = [ "rustc_feature", "rustc_hir", "rustc_index", + "rustc_macros", "rustc_metadata", "rustc_middle", "rustc_query_system", diff --git a/compiler/rustc_error_messages/locales/en-US/resolve.ftl b/compiler/rustc_error_messages/locales/en-US/resolve.ftl new file mode 100644 index 0000000000000..817bb83ed786a --- /dev/null +++ b/compiler/rustc_error_messages/locales/en-US/resolve.ftl @@ -0,0 +1,211 @@ +resolve_parent_module_reset_for_binding = + parent module is reset for binding + +resolve_ampersand_used_without_explicit_lifetime_name = + `&` without an explicit lifetime name cannot be used here + .note = explicit lifetime name needed here + +resolve_underscore_lifetime_name_cannot_be_used_here = + `'_` cannot be used here + .note = `'_` is a reserved lifetime name + +resolve_crate_may_not_be_imported = + `$crate` may not be imported + +resolve_crate_root_imports_must_be_named_explicitly = + crate root imports need to be explicitly named: `use crate as name;` + +resolve_generic_params_from_outer_function = + can't use generic parameters from outer function + .label = use of generic parameter from outer function + .suggestion = try using a local generic parameter instead + +resolve_self_type_implicitly_declared_by_impl = + `Self` type implicitly declared here, by this `impl` + +resolve_cannot_use_self_type_here = + can't use `Self` here + +resolve_use_a_type_here_instead = + use a type here instead + +resolve_type_param_from_outer_fn = + type parameter from outer function + +resolve_const_param_from_outer_fn = + const parameter from outer function + +resolve_try_using_local_generic_parameter = + try using a local generic parameter instead + +resolve_try_adding_local_generic_param_on_method = + try adding a local generic parameter in this method instead + +resolve_help_try_using_local_generic_param = + try using a local generic paramter instead + +resolve_name_is_already_used_as_generic_parameter = + the name `{$name}` is already used for a generic parameter in this item's generic parameters + .label = already used + .first_use_of_name = first use of `{$name}` + +resolve_method_not_member_of_trait = + method `{$method}` is not a member of trait `{$trait_}` + .label = not a member of trait `{$trait_}` + +resolve_associated_fn_with_similar_name_exists = + there is an associated function with a similar name + +resolve_type_not_member_of_trait = + type `{$type_}` is not a member of trait `{$trait_}` + .label = not a member of trait `{$trait_}` + +resolve_associated_type_with_similar_name_exists = + there is an associated type with a similar name + +resolve_const_not_member_of_trait = + const `{$const_}` is not a member of trait `{$trait_}` + .label = not a member of trait `{$trait_}` + +resolve_associated_const_with_similar_name_exists = + there is an associated constant with a similar name + +resolve_variable_bound_with_different_mode = + variable `{$variable_name}` is bound inconsistently across alternatives separated by `|` + .label = bound in different ways + .first_binding_span = first binding + +resolve_ident_bound_more_than_once_in_parameter_list = + identifier `{$identifier}` is bound more than once in this parameter list + .label = used as parameter more than once + +resolve_ident_bound_more_than_once_in_same_pattern = + identifier `{$identifier}` is bound more than once in the same pattern + .label = used in a pattern more than once + +resolve_undeclared_label = + use of undeclared label `{$name}` + .label = undeclared label `{$name}` + +resolve_label_with_similar_name_reachable = + a label with a similar name is reachable + +resolve_try_using_similarly_named_label = + try using similarly named label + +resolve_unreachable_label_with_similar_name_exists = + a label with a similar name exists but is unreachable + +resolve_self_import_can_only_appear_once_in_the_list = + `self` import can only appear once in an import list + .label = can only appear once in an import list + +resolve_self_import_only_in_import_list_with_non_empty_prefix = + `self` import can only appear in an import list with a non-empty prefix + .label = can only appear in an import list with a non-empty prefix + +resolve_cannot_capture_dynamic_environment_in_fn_item = + can't capture dynamic environment in a fn item + .help = use the `|| {"{"} ... {"}"}` closure form instead + +resolve_attempt_to_use_non_constant_value_in_constant = + attempt to use a non-constant value in a constant + +resolve_attempt_to_use_non_constant_value_in_constant_with_suggestion = + consider using `{$suggestion}` instead of `{$current}` + +resolve_attempt_to_use_non_constant_value_in_constant_label_with_suggestion = + non-constant value + +resolve_attempt_to_use_non_constant_value_in_constant_without_suggestion = + this would need to be a `{$suggestion}` + +resolve_self_imports_only_allowed_within = + `self` imports are only allowed within a {"{"} {"}"} list + +resolve_self_imports_only_allowed_within_suggestion = + consider importing the module directly + +resolve_self_imports_only_allowed_within_multipart_suggestion = + alternatively, use the multi-path `use` syntax to import `self` + +resolve_binding_shadows_something_unacceptable = + {$shadowing_binding}s cannot shadow {$shadowed_binding}s + .label = cannot be named the same as {$article} {$shadowed_binding} + .label_shadowed_binding = the {$shadowed_binding} `{$name}` is {$participle} here + +resolve_binding_shadows_something_unacceptable_suggestion = + try specify the pattern arguments + +resolve_forward_declared_generic_param = + generic parameters with a default cannot use forward declared identifiers + .label = defaulted generic parameters cannot be forward declared + +resolve_param_in_ty_of_const_param = + the type of const parameters must not depend on other generic parameters + .label = the type must not depend on the parameter `{$name}` + +resolve_self_in_generic_param_default = + generic parameters cannot use `Self` in their defaults + .label = `Self` in generic parameter default + +resolve_param_in_non_trivial_anon_const = + generic parameters may not be used in const operations + .label = cannot perform const operation using `{$name}` + +resolve_param_in_non_trivial_anon_const_help = + use `#![feature(generic_const_exprs)]` to allow generic const expressions + +resolve_param_in_non_trivial_anon_const_sub_type = + type parameters may not be used in const expressions + +resolve_param_in_non_trivial_anon_const_sub_non_type = + const parameters may only be used as standalone arguments, i.e. `{$name}` + +resolve_unreachable_label = + use of unreachable label `{$name}` + .label = unreachable label `{$name}` + .label_definition_span = unreachable label defined here + .note = labels are unreachable through functions, closures, async blocks and modules + +resolve_unreachable_label_suggestion_use_similarly_named = + try using similarly named label + +resolve_unreachable_label_similar_name_reachable = + a label with a similar name is reachable + +resolve_unreachable_label_similar_name_unreachable = + a label with a similar name exists but is also unreachable + +resolve_trait_impl_mismatch = + item `{$name}` is an associated {$kind}, which doesn't match its trait `{$trait_path}` + .label = does not match trait + .label_trait_item = item in trait + +resolve_invalid_asm_sym = + invalid `sym` operand + .label = is a local variable + .help = `sym` operands must refer to either a function or a static + +resolve_trait_impl_duplicate = + duplicate definitions with name `{$name}`: + .label = duplicate definition + .old_span_label = previous definition here + .trait_item_span = item in trait + +resolve_relative_2018 = + relative paths are not supported in visibilities in 2018 edition or later + .suggestion = try + +resolve_ancestor_only = + visibilities can only be restricted to ancestor modules + +resolve_expected_found = + expected module, found {$res} `{$path_str}` + .label = not a module + +resolve_indeterminate = + cannot determine resolution for the visibility + +resolve_module_only = + visibility must resolve to a module diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs index 0b1b75471a661..9c71f0906b5ec 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -63,6 +63,7 @@ fluent_messages! { plugin_impl => "../locales/en-US/plugin_impl.ftl", privacy => "../locales/en-US/privacy.ftl", query_system => "../locales/en-US/query_system.ftl", + resolve => "../locales/en-US/resolve.ftl", save_analysis => "../locales/en-US/save_analysis.ftl", session => "../locales/en-US/session.ftl", symbol_mangling => "../locales/en-US/symbol_mangling.ftl", diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs index c6035705e39fa..ee68344805f4c 100644 --- a/compiler/rustc_errors/src/diagnostic_impls.rs +++ b/compiler/rustc_errors/src/diagnostic_impls.rs @@ -211,6 +211,12 @@ impl IntoDiagnosticArg for DiagnosticSymbolList { } } +impl IntoDiagnosticArg for hir::def::Res { + fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + DiagnosticArgValue::Str(Cow::Borrowed(self.descr())) + } +} + impl IntoDiagnostic<'_, !> for TargetDataLayoutErrors<'_> { fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> { let mut diag; diff --git a/compiler/rustc_resolve/Cargo.toml b/compiler/rustc_resolve/Cargo.toml index d66db1d7a0dd5..8f14efd6b8315 100644 --- a/compiler/rustc_resolve/Cargo.toml +++ b/compiler/rustc_resolve/Cargo.toml @@ -19,6 +19,7 @@ rustc_expand = { path = "../rustc_expand" } rustc_feature = { path = "../rustc_feature" } rustc_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } +rustc_macros = { path = "../rustc_macros" } rustc_metadata = { path = "../rustc_metadata" } rustc_query_system = { path = "../rustc_query_system" } rustc_session = { path = "../rustc_session" } diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index a12918b297990..a95607656ffca 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -26,6 +26,7 @@ use rustc_span::source_map::SourceMap; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{BytePos, Span, SyntaxContext}; +use crate::errors as errs; use crate::imports::{Import, ImportKind, ImportResolver}; use crate::late::{PatternSource, Rib}; use crate::path_names_to_string; @@ -597,78 +598,41 @@ impl<'a> Resolver<'a> { err } - ResolutionError::NameAlreadyUsedInParameterList(name, first_use_span) => { - let mut err = struct_span_err!( - self.session, - span, - E0403, - "the name `{}` is already used for a generic \ - parameter in this item's generic parameters", - name, - ); - err.span_label(span, "already used"); - err.span_label(first_use_span, format!("first use of `{}`", name)); - err - } + ResolutionError::NameAlreadyUsedInParameterList(name, first_use_span) => self + .session + .create_err(errs::NameAlreadyUsedInParameterList { span, first_use_span, name }), ResolutionError::MethodNotMemberOfTrait(method, trait_, candidate) => { - let mut err = struct_span_err!( - self.session, + self.session.create_err(errs::MethodNotMemberOfTrait { span, - E0407, - "method `{}` is not a member of trait `{}`", method, - trait_ - ); - err.span_label(span, format!("not a member of trait `{}`", trait_)); - if let Some(candidate) = candidate { - err.span_suggestion( - method.span, - "there is an associated function with a similar name", - candidate.to_ident_string(), - Applicability::MaybeIncorrect, - ); - } - err + trait_, + sub: candidate.map(|c| errs::AssociatedFnWithSimilarNameExists { + span: method.span, + candidate: c, + }), + }) } ResolutionError::TypeNotMemberOfTrait(type_, trait_, candidate) => { - let mut err = struct_span_err!( - self.session, + self.session.create_err(errs::TypeNotMemberOfTrait { span, - E0437, - "type `{}` is not a member of trait `{}`", type_, - trait_ - ); - err.span_label(span, format!("not a member of trait `{}`", trait_)); - if let Some(candidate) = candidate { - err.span_suggestion( - type_.span, - "there is an associated type with a similar name", - candidate.to_ident_string(), - Applicability::MaybeIncorrect, - ); - } - err + trait_, + sub: candidate.map(|c| errs::AssociatedTypeWithSimilarNameExists { + span: type_.span, + candidate: c, + }), + }) } ResolutionError::ConstNotMemberOfTrait(const_, trait_, candidate) => { - let mut err = struct_span_err!( - self.session, + self.session.create_err(errs::ConstNotMemberOfTrait { span, - E0438, - "const `{}` is not a member of trait `{}`", const_, - trait_ - ); - err.span_label(span, format!("not a member of trait `{}`", trait_)); - if let Some(candidate) = candidate { - err.span_suggestion( - const_.span, - "there is an associated constant with a similar name", - candidate.to_ident_string(), - Applicability::MaybeIncorrect, - ); - } - err + trait_, + sub: candidate.map(|c| errs::AssociatedConstWithSimilarNameExists { + span: const_.span, + candidate: c, + }), + }) } ResolutionError::VariableNotBoundInPattern(binding_error, parent_scope) => { let BindingError { name, target, origin, could_be_path } = binding_error; @@ -730,128 +694,78 @@ impl<'a> Resolver<'a> { err } ResolutionError::VariableBoundWithDifferentMode(variable_name, first_binding_span) => { - let mut err = struct_span_err!( - self.session, - span, - E0409, - "variable `{}` is bound inconsistently across alternatives separated by `|`", - variable_name - ); - err.span_label(span, "bound in different ways"); - err.span_label(first_binding_span, "first binding"); - err - } - ResolutionError::IdentifierBoundMoreThanOnceInParameterList(identifier) => { - let mut err = struct_span_err!( - self.session, - span, - E0415, - "identifier `{}` is bound more than once in this parameter list", - identifier - ); - err.span_label(span, "used as parameter more than once"); - err - } - ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(identifier) => { - let mut err = struct_span_err!( - self.session, + self.session.create_err(errs::VariableBoundWithDifferentMode { span, - E0416, - "identifier `{}` is bound more than once in the same pattern", - identifier - ); - err.span_label(span, "used in a pattern more than once"); - err - } + first_binding_span, + variable_name, + }) + } + ResolutionError::IdentifierBoundMoreThanOnceInParameterList(identifier) => self + .session + .create_err(errs::IdentifierBoundMoreThanOnceInParameterList { span, identifier }), + ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(identifier) => self + .session + .create_err(errs::IdentifierBoundMoreThanOnceInSamePattern { span, identifier }), ResolutionError::UndeclaredLabel { name, suggestion } => { - let mut err = struct_span_err!( - self.session, - span, - E0426, - "use of undeclared label `{}`", - name - ); - - err.span_label(span, format!("undeclared label `{}`", name)); - - match suggestion { + let ((sub_reachable, sub_reachable_suggestion), sub_unreachable) = match suggestion + { // A reachable label with a similar name exists. - Some((ident, true)) => { - err.span_label(ident.span, "a label with a similar name is reachable"); - err.span_suggestion( - span, - "try using similarly named label", - ident.name, - Applicability::MaybeIncorrect, - ); - } + Some((ident, true)) => ( + ( + Some(errs::LabelWithSimilarNameReachable(ident.span)), + Some(errs::TryUsingSimilarlyNamedLabel { + span, + ident_name: ident.name, + }), + ), + None, + ), // An unreachable label with a similar name exists. - Some((ident, false)) => { - err.span_label( - ident.span, - "a label with a similar name exists but is unreachable", - ); - } + Some((ident, false)) => ( + (None, None), + Some(errs::UnreachableLabelWithSimilarNameExists { + ident_span: ident.span, + }), + ), // No similarly-named labels exist. - None => (), - } - - err + None => ((None, None), None), + }; + self.session.create_err(errs::UndeclaredLabel { + span, + name, + sub_reachable, + sub_reachable_suggestion, + sub_unreachable, + }) } ResolutionError::SelfImportsOnlyAllowedWithin { root, span_with_rename } => { - let mut err = struct_span_err!( - self.session, - span, - E0429, - "{}", - "`self` imports are only allowed within a { } list" - ); - // None of the suggestions below would help with a case like `use self`. - if !root { + let (suggestion, mpart_suggestion) = if root { + (None, None) + } else { // use foo::bar::self -> foo::bar // use foo::bar::self as abc -> foo::bar as abc - err.span_suggestion( - span, - "consider importing the module directly", - "", - Applicability::MachineApplicable, - ); + let suggestion = errs::SelfImportsOnlyAllowedWithinSuggestion { span }; // use foo::bar::self -> foo::bar::{self} // use foo::bar::self as abc -> foo::bar::{self as abc} - let braces = vec![ - (span_with_rename.shrink_to_lo(), "{".to_string()), - (span_with_rename.shrink_to_hi(), "}".to_string()), - ]; - err.multipart_suggestion( - "alternatively, use the multi-path `use` syntax to import `self`", - braces, - Applicability::MachineApplicable, - ); - } - err + let mpart_suggestion = errs::SelfImportsOnlyAllowedWithinMultipartSuggestion { + multipart_start: span_with_rename.shrink_to_lo(), + multipart_end: span_with_rename.shrink_to_hi(), + }; + (Some(suggestion), Some(mpart_suggestion)) + }; + self.session.create_err(errs::SelfImportsOnlyAllowedWithin { + span, + suggestion, + mpart_suggestion, + }) } ResolutionError::SelfImportCanOnlyAppearOnceInTheList => { - let mut err = struct_span_err!( - self.session, - span, - E0430, - "`self` import can only appear once in an import list" - ); - err.span_label(span, "can only appear once in an import list"); - err + self.session.create_err(errs::SelfImportCanOnlyAppearOnceInTheList { span }) } ResolutionError::SelfImportOnlyInImportListWithNonEmptyPrefix => { - let mut err = struct_span_err!( - self.session, - span, - E0431, - "`self` import can only appear in an import list with \ - a non-empty prefix" - ); - err.span_label(span, "can only appear in an import list with a non-empty prefix"); - err + self.session.create_err(errs::SelfImportOnlyInImportListWithNonEmptyPrefix { span }) } ResolutionError::FailedToResolve { label, suggestion } => { let mut err = @@ -869,23 +783,9 @@ impl<'a> Resolver<'a> { err } ResolutionError::CannotCaptureDynamicEnvironmentInFnItem => { - let mut err = struct_span_err!( - self.session, - span, - E0434, - "{}", - "can't capture dynamic environment in a fn item" - ); - err.help("use the `|| { ... }` closure form instead"); - err + self.session.create_err(errs::CannotCaptureDynamicEnvironmentInFnItem { span }) } - ResolutionError::AttemptToUseNonConstantValueInConstant(ident, sugg, current) => { - let mut err = struct_span_err!( - self.session, - span, - E0435, - "attempt to use a non-constant value in a constant" - ); + ResolutionError::AttemptToUseNonConstantValueInConstant(ident, suggestion, current) => { // let foo =... // ^^^ given this Span // ------- get this Span to have an applicable suggestion @@ -899,23 +799,34 @@ impl<'a> Resolver<'a> { .source_map() .span_extend_to_prev_str(ident.span, current, true, false); - match sp { + let ((with, with_label), without) = match sp { Some(sp) if !self.session.source_map().is_multiline(sp) => { let sp = sp.with_lo(BytePos(sp.lo().0 - (current.len() as u32))); - err.span_suggestion( - sp, - &format!("consider using `{}` instead of `{}`", sugg, current), - format!("{} {}", sugg, ident), - Applicability::MaybeIncorrect, - ); - err.span_label(span, "non-constant value"); - } - _ => { - err.span_label(ident.span, &format!("this would need to be a `{}`", sugg)); + ( + (Some(errs::AttemptToUseNonConstantValueInConstantWithSuggestion { + span: sp, + ident, + suggestion, + current, + }), Some(errs::AttemptToUseNonConstantValueInConstantLabelWithSuggestion {span})), + None, + ) } - } + _ => ( + (None, None), + Some(errs::AttemptToUseNonConstantValueInConstantWithoutSuggestion { + ident_span: ident.span, + suggestion, + }), + ), + }; - err + self.session.create_err(errs::AttemptToUseNonConstantValueInConstant { + span, + with, + with_label, + without, + }) } ResolutionError::BindingShadowsSomethingUnacceptable { shadowing_binding, @@ -924,135 +835,80 @@ impl<'a> Resolver<'a> { article, shadowed_binding, shadowed_binding_span, - } => { - let shadowed_binding_descr = shadowed_binding.descr(); - let mut err = struct_span_err!( - self.session, - span, - E0530, - "{}s cannot shadow {}s", - shadowing_binding.descr(), - shadowed_binding_descr, - ); - err.span_label( - span, - format!("cannot be named the same as {} {}", article, shadowed_binding_descr), - ); - match (shadowing_binding, shadowed_binding) { + } => self.session.create_err(errs::BindingShadowsSomethingUnacceptable { + span, + shadowing_binding, + shadowed_binding, + article, + sub_suggestion: match (shadowing_binding, shadowed_binding) { ( PatternSource::Match, Res::Def(DefKind::Ctor(CtorOf::Variant | CtorOf::Struct, CtorKind::Fn), _), - ) => { - err.span_suggestion( - span, - "try specify the pattern arguments", - format!("{}(..)", name), - Applicability::Unspecified, - ); - } - _ => (), - } - let msg = - format!("the {} `{}` is {} here", shadowed_binding_descr, name, participle); - err.span_label(shadowed_binding_span, msg); - err - } + ) => Some(errs::BindingShadowsSomethingUnacceptableSuggestion { span, name }), + _ => None, + }, + shadowed_binding_span, + participle, + name, + }), ResolutionError::ForwardDeclaredGenericParam => { - let mut err = struct_span_err!( - self.session, - span, - E0128, - "generic parameters with a default cannot use \ - forward declared identifiers" - ); - err.span_label(span, "defaulted generic parameters cannot be forward declared"); - err + self.session.create_err(errs::ForwardDeclaredGenericParam { span }) } ResolutionError::ParamInTyOfConstParam(name) => { - let mut err = struct_span_err!( - self.session, - span, - E0770, - "the type of const parameters must not depend on other generic parameters" - ); - err.span_label( - span, - format!("the type must not depend on the parameter `{}`", name), - ); - err + self.session.create_err(errs::ParamInTyOfConstParam { span, name }) } ResolutionError::ParamInNonTrivialAnonConst { name, is_type } => { - let mut err = self.session.struct_span_err( + self.session.create_err(errs::ParamInNonTrivialAnonConst { span, - "generic parameters may not be used in const operations", - ); - err.span_label(span, &format!("cannot perform const operation using `{}`", name)); - - if is_type { - err.note("type parameters may not be used in const expressions"); - } else { - err.help(&format!( - "const parameters may only be used as standalone arguments, i.e. `{}`", - name - )); - } - - if self.session.is_nightly_build() { - err.help( - "use `#![feature(generic_const_exprs)]` to allow generic const expressions", - ); - } - - err + name, + sub_is_type: if is_type { + errs::ParamInNonTrivialAnonConstIsType::AType + } else { + errs::ParamInNonTrivialAnonConstIsType::NotAType { name } + }, + help: self + .session + .is_nightly_build() + .then_some(errs::ParamInNonTrivialAnonConstHelp), + }) } ResolutionError::SelfInGenericParamDefault => { - let mut err = struct_span_err!( - self.session, - span, - E0735, - "generic parameters cannot use `Self` in their defaults" - ); - err.span_label(span, "`Self` in generic parameter default"); - err + self.session.create_err(errs::SelfInGenericParamDefault { span }) } ResolutionError::UnreachableLabel { name, definition_span, suggestion } => { - let mut err = struct_span_err!( - self.session, + let ((sub_suggestion_label, sub_suggestion), sub_unreachable_label) = + match suggestion { + // A reachable label with a similar name exists. + Some((ident, true)) => ( + ( + Some(errs::UnreachableLabelSubLabel { ident_span: ident.span }), + Some(errs::UnreachableLabelSubSuggestion { + span, + // intentionally taking 'ident.name' instead of 'ident' itself, as this + // could be used in suggestion context + ident_name: ident.name, + }), + ), + None, + ), + // An unreachable label with a similar name exists. + Some((ident, false)) => ( + (None, None), + Some(errs::UnreachableLabelSubLabelUnreachable { + ident_span: ident.span, + }), + ), + // No similarly-named labels exist. + None => ((None, None), None), + }; + self.session.create_err(errs::UnreachableLabel { span, - E0767, - "use of unreachable label `{}`", name, - ); - - err.span_label(definition_span, "unreachable label defined here"); - err.span_label(span, format!("unreachable label `{}`", name)); - err.note( - "labels are unreachable through functions, closures, async blocks and modules", - ); - - match suggestion { - // A reachable label with a similar name exists. - Some((ident, true)) => { - err.span_label(ident.span, "a label with a similar name is reachable"); - err.span_suggestion( - span, - "try using similarly named label", - ident.name, - Applicability::MaybeIncorrect, - ); - } - // An unreachable label with a similar name exists. - Some((ident, false)) => { - err.span_label( - ident.span, - "a label with a similar name exists but is also unreachable", - ); - } - // No similarly-named labels exist. - None => (), - } - - err + definition_span, + sub_suggestion, + sub_suggestion_label, + sub_unreachable_label, + }) } ResolutionError::TraitImplMismatch { name, @@ -1073,25 +929,10 @@ impl<'a> Resolver<'a> { err.span_label(trait_item_span, "item in trait"); err } - ResolutionError::TraitImplDuplicate { name, trait_item_span, old_span } => { - let mut err = struct_span_err!( - self.session, - span, - E0201, - "duplicate definitions with name `{}`:", - name, - ); - err.span_label(old_span, "previous definition here"); - err.span_label(trait_item_span, "item in trait"); - err.span_label(span, "duplicate definition"); - err - } - ResolutionError::InvalidAsmSym => { - let mut err = self.session.struct_span_err(span, "invalid `sym` operand"); - err.span_label(span, "is a local variable"); - err.help("`sym` operands must refer to either a function or a static"); - err - } + ResolutionError::TraitImplDuplicate { name, trait_item_span, old_span } => self + .session + .create_err(errs::TraitImplDuplicate { span, name, trait_item_span, old_span }), + ResolutionError::InvalidAsmSym => self.session.create_err(errs::InvalidAsmSym { span }), } } @@ -1101,48 +942,27 @@ impl<'a> Resolver<'a> { ) -> ErrorGuaranteed { match vis_resolution_error { VisResolutionError::Relative2018(span, path) => { - let mut err = self.session.struct_span_err( + self.session.create_err(errs::Relative2018 { span, - "relative paths are not supported in visibilities in 2018 edition or later", - ); - err.span_suggestion( - path.span, - "try", - format!("crate::{}", pprust::path_to_string(&path)), - Applicability::MaybeIncorrect, - ); - err + path_span: path.span, + // intentionally converting to String, as the text would also be used as + // in suggestion context + path_str: pprust::path_to_string(&path), + }) + } + VisResolutionError::AncestorOnly(span) => { + self.session.create_err(errs::AncestorOnly(span)) } - VisResolutionError::AncestorOnly(span) => struct_span_err!( - self.session, - span, - E0742, - "visibilities can only be restricted to ancestor modules" - ), VisResolutionError::FailedToResolve(span, label, suggestion) => { self.into_struct_error(span, ResolutionError::FailedToResolve { label, suggestion }) } VisResolutionError::ExpectedFound(span, path_str, res) => { - let mut err = struct_span_err!( - self.session, - span, - E0577, - "expected module, found {} `{}`", - res.descr(), - path_str - ); - err.span_label(span, "not a module"); - err + self.session.create_err(errs::ExpectedFound { span, res, path_str }) } - VisResolutionError::Indeterminate(span) => struct_span_err!( - self.session, - span, - E0578, - "cannot determine resolution for the visibility" - ), - VisResolutionError::ModuleOnly(span) => { - self.session.struct_span_err(span, "visibility must resolve to a module") + VisResolutionError::Indeterminate(span) => { + self.session.create_err(errs::Indeterminate(span)) } + VisResolutionError::ModuleOnly(span) => self.session.create_err(errs::ModuleOnly(span)), } .emit() } diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs new file mode 100644 index 0000000000000..2c442774667b2 --- /dev/null +++ b/compiler/rustc_resolve/src/errors.rs @@ -0,0 +1,474 @@ +use rustc_macros::{Diagnostic, Subdiagnostic}; +use rustc_span::{ + symbol::{Ident, Symbol}, + Span, +}; + +use crate::{late::PatternSource, Res}; + +#[derive(Diagnostic)] +#[diag(resolve_parent_module_reset_for_binding, code = "E0637")] +pub(crate) struct ParentModuleResetForBinding; + +#[derive(Diagnostic)] +#[diag(resolve_ampersand_used_without_explicit_lifetime_name, code = "E0637")] +#[note] +pub(crate) struct AmpersandUsedWithoutExplicitLifetimeName(#[primary_span] pub(crate) Span); + +#[derive(Diagnostic)] +#[diag(resolve_underscore_lifetime_name_cannot_be_used_here, code = "E0637")] +#[note] +pub(crate) struct UnderscoreLifetimeNameCannotBeUsedHere(#[primary_span] pub(crate) Span); + +#[derive(Diagnostic)] +#[diag(resolve_crate_may_not_be_imported)] +pub(crate) struct CrateMayNotBeImprted(#[primary_span] pub(crate) Span); + +#[derive(Diagnostic)] +#[diag(resolve_crate_root_imports_must_be_named_explicitly)] +pub(crate) struct CrateRootNamesMustBeNamedExplicitly(#[primary_span] pub(crate) Span); + +#[derive(Diagnostic)] +#[diag(resolve_crate_root_imports_must_be_named_explicitly)] +pub(crate) struct ResolutionError(#[primary_span] pub(crate) Span); + +#[derive(Diagnostic)] +#[diag(resolve_name_is_already_used_as_generic_parameter, code = "E0403")] +pub(crate) struct NameAlreadyUsedInParameterList { + #[primary_span] + #[label] + pub(crate) span: Span, + #[label(first_use_of_name)] + pub(crate) first_use_span: Span, + pub(crate) name: Symbol, +} + +#[derive(Diagnostic)] +#[diag(resolve_method_not_member_of_trait, code = "E0407")] +pub(crate) struct MethodNotMemberOfTrait { + #[primary_span] + #[label] + pub(crate) span: Span, + pub(crate) method: Ident, + pub(crate) trait_: String, + #[subdiagnostic] + pub(crate) sub: Option, +} + +#[derive(Subdiagnostic)] +#[suggestion( + resolve_associated_fn_with_similar_name_exists, + code = "{candidate}", + applicability = "maybe-incorrect" +)] +pub(crate) struct AssociatedFnWithSimilarNameExists { + #[primary_span] + pub(crate) span: Span, + pub(crate) candidate: Symbol, +} + +#[derive(Diagnostic)] +#[diag(resolve_type_not_member_of_trait, code = "E0437")] +pub(crate) struct TypeNotMemberOfTrait { + #[primary_span] + #[label] + pub(crate) span: Span, + pub(crate) type_: Ident, + pub(crate) trait_: String, + #[subdiagnostic] + pub(crate) sub: Option, +} + +#[derive(Subdiagnostic)] +#[suggestion( + resolve_associated_type_with_similar_name_exists, + code = "{candidate}", + applicability = "maybe-incorrect" +)] +pub(crate) struct AssociatedTypeWithSimilarNameExists { + #[primary_span] + pub(crate) span: Span, + pub(crate) candidate: Symbol, +} + +#[derive(Diagnostic)] +#[diag(resolve_const_not_member_of_trait, code = "E0438")] +pub(crate) struct ConstNotMemberOfTrait { + #[primary_span] + #[label] + pub(crate) span: Span, + pub(crate) const_: Ident, + pub(crate) trait_: String, + #[subdiagnostic] + pub(crate) sub: Option, +} + +#[derive(Subdiagnostic)] +#[suggestion( + resolve_associated_const_with_similar_name_exists, + code = "{candidate}", + applicability = "maybe-incorrect" +)] +pub(crate) struct AssociatedConstWithSimilarNameExists { + #[primary_span] + pub(crate) span: Span, + pub(crate) candidate: Symbol, +} + +#[derive(Diagnostic)] +#[diag(resolve_variable_bound_with_different_mode, code = "E0409")] +pub(crate) struct VariableBoundWithDifferentMode { + #[primary_span] + #[label] + pub(crate) span: Span, + #[label(first_binding_span)] + pub(crate) first_binding_span: Span, + pub(crate) variable_name: Symbol, +} + +#[derive(Diagnostic)] +#[diag(resolve_ident_bound_more_than_once_in_parameter_list, code = "E0415")] +pub(crate) struct IdentifierBoundMoreThanOnceInParameterList { + #[primary_span] + #[label] + pub(crate) span: Span, + pub(crate) identifier: Symbol, +} + +#[derive(Diagnostic)] +#[diag(resolve_ident_bound_more_than_once_in_same_pattern, code = "E0416")] +pub(crate) struct IdentifierBoundMoreThanOnceInSamePattern { + #[primary_span] + #[label] + pub(crate) span: Span, + pub(crate) identifier: Symbol, +} + +#[derive(Diagnostic)] +#[diag(resolve_undeclared_label, code = "E0426")] +pub(crate) struct UndeclaredLabel { + #[primary_span] + #[label] + pub(crate) span: Span, + pub(crate) name: Symbol, + #[subdiagnostic] + pub(crate) sub_reachable: Option, + #[subdiagnostic] + pub(crate) sub_reachable_suggestion: Option, + #[subdiagnostic] + pub(crate) sub_unreachable: Option, +} + +#[derive(Subdiagnostic)] +#[label(resolve_label_with_similar_name_reachable)] +pub(crate) struct LabelWithSimilarNameReachable(#[primary_span] pub(crate) Span); + +#[derive(Subdiagnostic)] +#[suggestion( + resolve_try_using_similarly_named_label, + code = "{ident_name}", + applicability = "maybe-incorrect" +)] +pub(crate) struct TryUsingSimilarlyNamedLabel { + #[primary_span] + pub(crate) span: Span, + pub(crate) ident_name: Symbol, +} + +#[derive(Subdiagnostic)] +#[label(resolve_unreachable_label_with_similar_name_exists)] +pub(crate) struct UnreachableLabelWithSimilarNameExists { + #[primary_span] + pub(crate) ident_span: Span, +} + +#[derive(Diagnostic)] +#[diag(resolve_self_import_can_only_appear_once_in_the_list, code = "E0430")] +pub(crate) struct SelfImportCanOnlyAppearOnceInTheList { + #[primary_span] + #[label] + pub(crate) span: Span, +} + +#[derive(Diagnostic)] +#[diag(resolve_self_import_only_in_import_list_with_non_empty_prefix, code = "E0431")] +pub(crate) struct SelfImportOnlyInImportListWithNonEmptyPrefix { + #[primary_span] + #[label] + pub(crate) span: Span, +} + +#[derive(Diagnostic)] +#[diag(resolve_cannot_capture_dynamic_environment_in_fn_item, code = "E0434")] +#[help] +pub(crate) struct CannotCaptureDynamicEnvironmentInFnItem { + #[primary_span] + pub(crate) span: Span, +} + +#[derive(Diagnostic)] +#[diag(resolve_attempt_to_use_non_constant_value_in_constant, code = "E0435")] +pub(crate) struct AttemptToUseNonConstantValueInConstant<'a> { + #[primary_span] + pub(crate) span: Span, + #[subdiagnostic] + pub(crate) with: Option>, + #[subdiagnostic] + pub(crate) with_label: Option, + #[subdiagnostic] + pub(crate) without: Option>, +} + +#[derive(Subdiagnostic)] +#[suggestion( + resolve_attempt_to_use_non_constant_value_in_constant_with_suggestion, + code = "{suggestion} {ident}", + applicability = "maybe-incorrect" +)] +pub(crate) struct AttemptToUseNonConstantValueInConstantWithSuggestion<'a> { + #[primary_span] + pub(crate) span: Span, + pub(crate) ident: Ident, + pub(crate) suggestion: &'a str, + pub(crate) current: &'a str, +} + +#[derive(Subdiagnostic)] +#[label(resolve_attempt_to_use_non_constant_value_in_constant_label_with_suggestion)] +pub(crate) struct AttemptToUseNonConstantValueInConstantLabelWithSuggestion { + #[primary_span] + pub(crate) span: Span, +} + +#[derive(Subdiagnostic)] +#[label(resolve_attempt_to_use_non_constant_value_in_constant_without_suggestion)] +pub(crate) struct AttemptToUseNonConstantValueInConstantWithoutSuggestion<'a> { + #[primary_span] + pub(crate) ident_span: Span, + pub(crate) suggestion: &'a str, +} + +#[derive(Diagnostic)] +#[diag(resolve_self_imports_only_allowed_within, code = "E0429")] +pub(crate) struct SelfImportsOnlyAllowedWithin { + #[primary_span] + pub(crate) span: Span, + #[subdiagnostic] + pub(crate) suggestion: Option, + #[subdiagnostic] + pub(crate) mpart_suggestion: Option, +} + +#[derive(Subdiagnostic)] +#[suggestion( + resolve_self_imports_only_allowed_within_suggestion, + code = "", + applicability = "machine-applicable" +)] +pub(crate) struct SelfImportsOnlyAllowedWithinSuggestion { + #[primary_span] + pub(crate) span: Span, +} + +#[derive(Subdiagnostic)] +#[multipart_suggestion( + resolve_self_imports_only_allowed_within_multipart_suggestion, + applicability = "machine-applicable" +)] +pub(crate) struct SelfImportsOnlyAllowedWithinMultipartSuggestion { + #[suggestion_part(code = "{{")] + pub(crate) multipart_start: Span, + #[suggestion_part(code = "}}")] + pub(crate) multipart_end: Span, +} + +#[derive(Diagnostic)] +#[diag(resolve_binding_shadows_something_unacceptable, code = "E0530")] +pub(crate) struct BindingShadowsSomethingUnacceptable<'a> { + #[primary_span] + #[label] + pub(crate) span: Span, + pub(crate) shadowing_binding: PatternSource, + pub(crate) shadowed_binding: Res, + pub(crate) article: &'a str, + #[subdiagnostic] + pub(crate) sub_suggestion: Option, + #[label(label_shadowed_binding)] + pub(crate) shadowed_binding_span: Span, + pub(crate) participle: &'a str, + pub(crate) name: Symbol, +} + +#[derive(Subdiagnostic)] +#[suggestion( + resolve_binding_shadows_something_unacceptable_suggestion, + code = "{name}(..)", + applicability = "unspecified" +)] +pub(crate) struct BindingShadowsSomethingUnacceptableSuggestion { + #[primary_span] + pub(crate) span: Span, + pub(crate) name: Symbol, +} + +#[derive(Diagnostic)] +#[diag(resolve_forward_declared_generic_param, code = "E0128")] +pub(crate) struct ForwardDeclaredGenericParam { + #[primary_span] + #[label] + pub(crate) span: Span, +} + +#[derive(Diagnostic)] +#[diag(resolve_param_in_ty_of_const_param, code = "E0770")] +pub(crate) struct ParamInTyOfConstParam { + #[primary_span] + #[label] + pub(crate) span: Span, + pub(crate) name: Symbol, +} + +#[derive(Diagnostic)] +#[diag(resolve_self_in_generic_param_default, code = "E0735")] +pub(crate) struct SelfInGenericParamDefault { + #[primary_span] + #[label] + pub(crate) span: Span, +} + +#[derive(Diagnostic)] +#[diag(resolve_param_in_non_trivial_anon_const)] +pub(crate) struct ParamInNonTrivialAnonConst { + #[primary_span] + #[label] + pub(crate) span: Span, + pub(crate) name: Symbol, + #[subdiagnostic] + pub(crate) sub_is_type: ParamInNonTrivialAnonConstIsType, + #[subdiagnostic] + pub(crate) help: Option, +} + +#[derive(Subdiagnostic)] +#[help(resolve_param_in_non_trivial_anon_const_help)] +pub(crate) struct ParamInNonTrivialAnonConstHelp; + +#[derive(Subdiagnostic)] +pub(crate) enum ParamInNonTrivialAnonConstIsType { + #[note(resolve_param_in_non_trivial_anon_const_sub_type)] + AType, + #[help(resolve_param_in_non_trivial_anon_const_sub_non_type)] + NotAType { name: Symbol }, +} + +#[derive(Diagnostic)] +#[diag(resolve_unreachable_label, code = "E0767")] +#[note] +pub(crate) struct UnreachableLabel { + #[primary_span] + #[label] + pub(crate) span: Span, + pub(crate) name: Symbol, + #[label(label_definition_span)] + pub(crate) definition_span: Span, + #[subdiagnostic] + pub(crate) sub_suggestion: Option, + #[subdiagnostic] + pub(crate) sub_suggestion_label: Option, + #[subdiagnostic] + pub(crate) sub_unreachable_label: Option, +} + +#[derive(Subdiagnostic)] +#[suggestion( + resolve_unreachable_label_suggestion_use_similarly_named, + code = "{ident_name}", + applicability = "maybe-incorrect" +)] +pub(crate) struct UnreachableLabelSubSuggestion { + #[primary_span] + pub(crate) span: Span, + pub(crate) ident_name: Symbol, +} + +#[derive(Subdiagnostic)] +#[label(resolve_unreachable_label_similar_name_reachable)] +pub(crate) struct UnreachableLabelSubLabel { + #[primary_span] + pub(crate) ident_span: Span, +} + +#[derive(Subdiagnostic)] +#[label(resolve_unreachable_label_similar_name_unreachable)] +pub(crate) struct UnreachableLabelSubLabelUnreachable { + #[primary_span] + pub(crate) ident_span: Span, +} + +#[derive(Diagnostic)] +#[diag(resolve_trait_impl_mismatch, code = "{code}")] +pub(crate) struct TraitImplMismatch { + #[primary_span] + #[label] + pub(crate) span: Span, + pub(crate) name: Symbol, + pub(crate) kind: String, + #[label(label_trait_item)] + pub(crate) trait_item_span: Span, + pub(crate) trait_path: String, + pub(crate) code: String, +} + +#[derive(Diagnostic)] +#[diag(resolve_invalid_asm_sym)] +#[help] +pub(crate) struct InvalidAsmSym { + #[primary_span] + #[label] + pub(crate) span: Span, +} + +#[derive(Diagnostic)] +#[diag(resolve_trait_impl_duplicate, code = "E0201")] +pub(crate) struct TraitImplDuplicate { + #[primary_span] + #[label] + pub(crate) span: Span, + #[label(old_span_label)] + pub(crate) old_span: Span, + #[label(trait_item_span)] + pub(crate) trait_item_span: Span, + pub(crate) name: Symbol, +} + +#[derive(Diagnostic)] +#[diag(resolve_relative_2018)] +pub(crate) struct Relative2018 { + #[primary_span] + pub(crate) span: Span, + #[suggestion(code = "crate::{path_str}", applicability = "maybe-incorrect")] + pub(crate) path_span: Span, + pub(crate) path_str: String, +} + +#[derive(Diagnostic)] +#[diag(resolve_ancestor_only, code = "E0742")] +pub(crate) struct AncestorOnly(#[primary_span] pub(crate) Span); + +#[derive(Diagnostic)] +#[diag(resolve_expected_found, code = "E0577")] +pub(crate) struct ExpectedFound { + #[primary_span] + #[label] + pub(crate) span: Span, + pub(crate) res: Res, + pub(crate) path_str: String, +} + +#[derive(Diagnostic)] +#[diag(resolve_indeterminate, code = "E0578")] +pub(crate) struct Indeterminate(#[primary_span] pub(crate) Span); + +#[derive(Diagnostic)] +#[diag(resolve_module_only)] +pub(crate) struct ModuleOnly(#[primary_span] pub(crate) Span); diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index ede67813883d6..809d40479a30f 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -16,7 +16,7 @@ use rustc_ast::ptr::P; use rustc_ast::visit::{self, AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor}; use rustc_ast::*; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; -use rustc_errors::DiagnosticId; +use rustc_errors::{DiagnosticArgValue, DiagnosticId, IntoDiagnosticArg}; use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::{self, CtorKind, DefKind, LifetimeRes, PartialRes, PerNS}; use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, LOCAL_CRATE}; @@ -31,6 +31,7 @@ use smallvec::{smallvec, SmallVec}; use rustc_span::source_map::{respan, Spanned}; use std::assert_matches::debug_assert_matches; +use std::borrow::Cow; use std::collections::{hash_map::Entry, BTreeSet}; use std::mem::{replace, swap, take}; @@ -78,6 +79,12 @@ impl PatternSource { } } +impl IntoDiagnosticArg for PatternSource { + fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + DiagnosticArgValue::Str(Cow::Borrowed(self.descr())) + } +} + /// Denotes whether the context for the set of already bound bindings is a `Product` /// or `Or` context. This is used in e.g., `fresh_binding` and `resolve_pattern_inner`. /// See those functions for more information. diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index a1ff477c6fefb..b133a4d50e9cf 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -73,6 +73,7 @@ mod check_unused; mod def_collector; mod diagnostics; mod effective_visibilities; +mod errors; mod ident; mod imports; mod late; From 5008a317ce8e508c390ed12bff281f307313376e Mon Sep 17 00:00:00 2001 From: Joy <51241057+maniwani@users.noreply.github.com> Date: Wed, 26 Oct 2022 11:43:18 -0700 Subject: [PATCH 019/103] Fix non-associativity of `Instant` math on `aarch64-apple-darwin` targets --- library/std/src/sys/unix/time.rs | 18 +++++++++++++++--- library/std/src/time/tests.rs | 8 ++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/library/std/src/sys/unix/time.rs b/library/std/src/sys/unix/time.rs index cca9c67670161..b65566740b50c 100644 --- a/library/std/src/sys/unix/time.rs +++ b/library/std/src/sys/unix/time.rs @@ -149,7 +149,11 @@ impl From for Timespec { } } -#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))] +#[cfg(any( + all(target_os = "macos", not(target_arch = "aarch64")), + target_os = "ios", + target_os = "watchos" +))] mod inner { use crate::sync::atomic::{AtomicU64, Ordering}; use crate::sys::cvt; @@ -265,7 +269,11 @@ mod inner { } } -#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "watchos")))] +#[cfg(not(any( + all(target_os = "macos", not(target_arch = "aarch64")), + target_os = "ios", + target_os = "watchos" +)))] mod inner { use crate::fmt; use crate::mem::MaybeUninit; @@ -281,7 +289,11 @@ mod inner { impl Instant { pub fn now() -> Instant { - Instant { t: Timespec::now(libc::CLOCK_MONOTONIC) } + #[cfg(target_os = "macos")] + const clock_id: clock_t = libc::CLOCK_UPTIME_RAW; + #[cfg(not(target_os = "macos"))] + const clock_id: clock_t = libc::CLOCK_MONOTONIC; + Instant { t: Timespec::now(clock_id) } } pub fn checked_sub_instant(&self, other: &Instant) -> Option { diff --git a/library/std/src/time/tests.rs b/library/std/src/time/tests.rs index 6229556c85fee..2e64ae59aff24 100644 --- a/library/std/src/time/tests.rs +++ b/library/std/src/time/tests.rs @@ -88,6 +88,14 @@ fn instant_math_is_associative() { // Changing the order of instant math shouldn't change the results, // especially when the expression reduces to X + identity. assert_eq!((now + offset) - now, (now - now) + offset); + + // On any platform, `Instant` should have the same resolution as `Duration` (e.g. 1 nanosecond) + // or better. Otherwise, math will be non-associative (see #91417). + let now = Instant::now(); + let provided_offset = Duration::from_nanos(1); + let later = now + provided_offset; + let measured_offset = later - now; + assert_eq!(measured_offset, provided_offset); } #[test] From 015ab659c2fcdf2f3a3fdaa6dc44455b9d0c2f3e Mon Sep 17 00:00:00 2001 From: Cameron <51241057+maniwani@users.noreply.github.com> Date: Sun, 13 Nov 2022 12:33:21 -0800 Subject: [PATCH 020/103] just use `libc::clockid_t` --- library/std/src/sys/unix/time.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/library/std/src/sys/unix/time.rs b/library/std/src/sys/unix/time.rs index b65566740b50c..c3fac44a42d2d 100644 --- a/library/std/src/sys/unix/time.rs +++ b/library/std/src/sys/unix/time.rs @@ -290,9 +290,9 @@ mod inner { impl Instant { pub fn now() -> Instant { #[cfg(target_os = "macos")] - const clock_id: clock_t = libc::CLOCK_UPTIME_RAW; + const clock_id: libc::clockid_t = libc::CLOCK_UPTIME_RAW; #[cfg(not(target_os = "macos"))] - const clock_id: clock_t = libc::CLOCK_MONOTONIC; + const clock_id: libc::clockid_t = libc::CLOCK_MONOTONIC; Instant { t: Timespec::now(clock_id) } } @@ -324,13 +324,8 @@ mod inner { } } - #[cfg(not(any(target_os = "dragonfly", target_os = "espidf", target_os = "horizon")))] - pub type clock_t = libc::c_int; - #[cfg(any(target_os = "dragonfly", target_os = "espidf", target_os = "horizon"))] - pub type clock_t = libc::c_ulong; - impl Timespec { - pub fn now(clock: clock_t) -> Timespec { + pub fn now(clock: libc::clockid_t) -> Timespec { // Try to use 64-bit time in preparation for Y2038. #[cfg(all(target_os = "linux", target_env = "gnu", target_pointer_width = "32"))] { From f4f515973ecc689029b64759ff43dbba0e207be2 Mon Sep 17 00:00:00 2001 From: Cameron <51241057+maniwani@users.noreply.github.com> Date: Mon, 14 Nov 2022 09:17:21 -0800 Subject: [PATCH 021/103] macos, aarch64, and not(miri) --- library/std/src/sys/unix/time.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/unix/time.rs b/library/std/src/sys/unix/time.rs index c3fac44a42d2d..ffcc507d2a763 100644 --- a/library/std/src/sys/unix/time.rs +++ b/library/std/src/sys/unix/time.rs @@ -150,7 +150,7 @@ impl From for Timespec { } #[cfg(any( - all(target_os = "macos", not(target_arch = "aarch64")), + all(target_os = "macos", any(not(target_arch = "aarch64"), miri)), target_os = "ios", target_os = "watchos" ))] @@ -270,7 +270,7 @@ mod inner { } #[cfg(not(any( - all(target_os = "macos", not(target_arch = "aarch64")), + all(target_os = "macos", any(not(target_arch = "aarch64"), miri)), target_os = "ios", target_os = "watchos" )))] From 74c9a6c6df5a9fb1a3dc8099f773301e4fc3cdb4 Mon Sep 17 00:00:00 2001 From: yukang Date: Tue, 15 Nov 2022 08:53:17 +0800 Subject: [PATCH 022/103] fix #103381, Detect incorrect chaining of if and if let conditions --- .../locales/en-US/parser.ftl | 3 + compiler/rustc_parse/src/errors.rs | 8 +++ compiler/rustc_parse/src/parser/expr.rs | 15 ++++- src/test/ui/parser/issue-103381.fixed | 59 +++++++++++++++++++ src/test/ui/parser/issue-103381.rs | 59 +++++++++++++++++++ src/test/ui/parser/issue-103381.stderr | 50 ++++++++++++++++ 6 files changed, 192 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/parser/issue-103381.fixed create mode 100644 src/test/ui/parser/issue-103381.rs create mode 100644 src/test/ui/parser/issue-103381.stderr diff --git a/compiler/rustc_error_messages/locales/en-US/parser.ftl b/compiler/rustc_error_messages/locales/en-US/parser.ftl index 815e8f4d3567e..62018de4a8cea 100644 --- a/compiler/rustc_error_messages/locales/en-US/parser.ftl +++ b/compiler/rustc_error_messages/locales/en-US/parser.ftl @@ -54,6 +54,9 @@ parser_invalid_logical_operator = `{$incorrect}` is not a logical operator parser_tilde_is_not_unary_operator = `~` cannot be used as a unary operator .suggestion = use `!` to perform bitwise not +parser_unexpected_if_with_if = unexpected `if` in the condition expression + .suggestion = remove the `if` + parser_unexpected_token_after_not = unexpected {$negated_desc} after identifier parser_unexpected_token_after_not_bitwise = use `!` to perform bitwise not parser_unexpected_token_after_not_logical = use `!` to perform logical negation diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index a39398950a533..e3177ac8760a5 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -1301,3 +1301,11 @@ pub(crate) struct FnPtrWithGenericsSugg { pub arity: usize, pub for_param_list_exists: bool, } + +#[derive(Diagnostic)] +#[diag(parser_unexpected_if_with_if)] +pub(crate) struct UnexpectedIfWithIf( + #[primary_span] + #[suggestion(applicability = "machine-applicable", code = " ", style = "verbose")] + pub Span, +); diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index b072573af23f0..9dc0fb8631235 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -24,8 +24,8 @@ use crate::errors::{ NoFieldsForFnCall, NotAsNegationOperator, NotAsNegationOperatorSub, OctalFloatLiteralNotSupported, OuterAttributeNotAllowedOnIfElse, ParenthesesWithStructFields, RequireColonAfterLabeledExpression, ShiftInterpretedAsGeneric, StructLiteralNotAllowedHere, - StructLiteralNotAllowedHereSugg, TildeAsUnaryOperator, UnexpectedTokenAfterLabel, - UnexpectedTokenAfterLabelSugg, WrapExpressionInParentheses, + StructLiteralNotAllowedHereSugg, TildeAsUnaryOperator, UnexpectedIfWithIf, + UnexpectedTokenAfterLabel, UnexpectedTokenAfterLabelSugg, WrapExpressionInParentheses, }; use crate::maybe_recover_from_interpolated_ty_qpath; @@ -2279,6 +2279,7 @@ impl<'a> Parser<'a> { if let Some(block) = recover_block_from_condition(self) { block } else { + self.error_on_extra_if(&cond)?; // Parse block, which will always fail, but we can add a nice note to the error self.parse_block().map_err(|mut err| { err.span_note( @@ -2415,6 +2416,16 @@ impl<'a> Parser<'a> { }); } + fn error_on_extra_if(&mut self, cond: &P) -> PResult<'a, ()> { + if let ExprKind::Binary(Spanned { span: binop_span, node: binop}, _, right) = &cond.kind && + let BinOpKind::And = binop && + let ExprKind::If(cond, ..) = &right.kind { + Err(self.sess.create_err(UnexpectedIfWithIf(binop_span.shrink_to_hi().to(cond.span.shrink_to_lo())))) + } else { + Ok(()) + } + } + /// Parses `for in ` (`for` token already eaten). fn parse_for_expr(&mut self, opt_label: Option::B::C`/`::B::C` can /// only legally refer to associated constants. - Path(Option, Path), + Path(Option>, Path), /// A tuple pattern (`(a, b)`). Tuple(Vec>), @@ -1272,6 +1272,18 @@ impl Expr { } } +#[derive(Clone, Encodable, Decodable, Debug)] +pub struct Closure { + pub binder: ClosureBinder, + pub capture_clause: CaptureBy, + pub asyncness: Async, + pub movability: Movability, + pub fn_decl: P, + pub body: P, + /// The span of the argument block `|...|`. + pub fn_decl_span: Span, +} + /// Limit types of a range (inclusive or exclusive) #[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug)] pub enum RangeLimits { @@ -1281,6 +1293,20 @@ pub enum RangeLimits { Closed, } +/// A method call (e.g. `x.foo::(a, b, c)`). +#[derive(Clone, Encodable, Decodable, Debug)] +pub struct MethodCall { + /// The method name and its generic arguments, e.g. `foo::`. + pub seg: PathSegment, + /// The receiver, e.g. `x`. + pub receiver: P, + /// The arguments, e.g. `a, b, c`. + pub args: Vec>, + /// The span of the function, without the dot and receiver e.g. `foo::(a, b, c)`. + pub span: Span, +} + #[derive(Clone, Encodable, Decodable, Debug)] pub enum StructRest { /// `..x`. @@ -1293,7 +1319,7 @@ pub enum StructRest { #[derive(Clone, Encodable, Decodable, Debug)] pub struct StructExpr { - pub qself: Option, + pub qself: Option>, pub path: Path, pub fields: Vec, pub rest: StructRest, @@ -1314,17 +1340,8 @@ pub enum ExprKind { /// This also represents calling the constructor of /// tuple-like ADTs such as tuple structs and enum variants. Call(P, Vec>), - /// A method call (`x.foo::<'static, Bar, Baz>(a, b, c, d)`) - /// - /// The `PathSegment` represents the method name and its generic arguments - /// (within the angle brackets). - /// The standalone `Expr` is the receiver expression. - /// The vector of `Expr` is the arguments. - /// `x.foo::(a, b, c, d)` is represented as - /// `ExprKind::MethodCall(PathSegment { foo, [Bar, Baz] }, x, [a, b, c, d])`. - /// This `Span` is the span of the function, without the dot and receiver - /// (e.g. `foo(a, b)` in `x.foo(a, b)` - MethodCall(PathSegment, P, Vec>, Span), + /// A method call (e.g. `x.foo::(a, b, c)`). + MethodCall(Box), /// A tuple (e.g., `(a, b, c, d)`). Tup(Vec>), /// A binary operation (e.g., `a + b`, `a * b`). @@ -1363,9 +1380,7 @@ pub enum ExprKind { /// A `match` block. Match(P, Vec), /// A closure (e.g., `move |a, b, c| a + b + c`). - /// - /// The final span is the span of the argument block `|...|`. - Closure(ClosureBinder, CaptureBy, Async, Movability, P, P, Span), + Closure(Box), /// A block (`'label: { ... }`). Block(P, Option
"); for variant in e.variants() { let id = cx.derive_id(format!("{}.{}", ItemType::Variant, variant.name.unwrap())); write!( w, - "

\ - \ - {name}", + "
\ + ", id = id, - name = variant.name.unwrap() ); - if let clean::VariantItem(clean::Variant::Tuple(ref s)) = *variant.kind { - w.write_str("("); - print_tuple_struct_fields(w, cx, s); - w.write_str(")"); - } - w.write_str(""); - render_stability_since_raw( + render_stability_since_raw_with_extra( w, variant.stable_since(tcx), variant.const_stability(tcx), it.stable_since(tcx), it.const_stable_since(tcx), + " rightside", ); - w.write_str("

"); + write!(w, "

{name}", name = variant.name.unwrap()); + if let clean::VariantItem(clean::Variant::Tuple(ref s)) = *variant.kind { + w.write_str("("); + print_tuple_struct_fields(w, cx, s); + w.write_str(")"); + } + w.write_str("

"); use crate::clean::Variant; @@ -1324,7 +1324,7 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean:: write!( w, "
\ - \ + \ \ {f}: {t}\ ", @@ -1343,6 +1343,7 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean:: document(w, cx, variant, Some(it), HeadingOffset::H4); } + write!(w, "
"); } let def_id = it.item_id.expect_def_id(); render_assoc_items(w, cx, it, def_id, AssocItemRender::All); diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 9b1cac85cfd58..27ffd7682e9d8 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -709,8 +709,6 @@ a { } .small-section-header { - display: flex; - justify-content: space-between; position: relative; } @@ -718,7 +716,7 @@ a { display: initial; } -.impl:hover > .anchor, .trait-impl:hover > .anchor { +.impl:hover > .anchor, .trait-impl:hover > .anchor, .variant:hover > .anchor { display: inline-block; position: absolute; } @@ -1235,12 +1233,6 @@ a.test-arrow:hover { font-size: 1.25rem; } -h3.variant { - font-weight: 600; - font-size: 1.125rem; - margin-bottom: 10px; -} - .sub-variant h4 { font-size: 1rem; font-weight: 400; @@ -1909,6 +1901,7 @@ in storage.js } } +.variant, .implementors-toggle > summary, .impl, #implementors-list > .docblock, @@ -1920,6 +1913,7 @@ in storage.js margin-bottom: 0.75em; } +.variants > .docblock, .impl-items > .rustdoc-toggle[open]:not(:last-child), .methods > .rustdoc-toggle[open]:not(:last-child), .implementors-toggle[open]:not(:last-child) { From 616f34e3c3068b0d39c969cb91695d3ea6e3a71c Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 17 Nov 2022 15:35:36 -0700 Subject: [PATCH 046/103] rustdoc: update tests for enum variant margin tweak --- src/test/rustdoc-gui/enum-variants.goml | 5 +++++ src/test/rustdoc/issue-88600.rs | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 src/test/rustdoc-gui/enum-variants.goml diff --git a/src/test/rustdoc-gui/enum-variants.goml b/src/test/rustdoc-gui/enum-variants.goml new file mode 100644 index 0000000000000..230abb236bd64 --- /dev/null +++ b/src/test/rustdoc-gui/enum-variants.goml @@ -0,0 +1,5 @@ +// Verifies that there is non-zero margin on variants and their docblocks. +goto: "file://" + |DOC_PATH| + "/test_docs/enum.WhoLetTheDogOut.html" + +assert-css: (".variants > .variant", {"margin": "0px 0px 12px"}) +assert-css: (".variants > .docblock", {"margin": "0px 0px 32px 24px"}) diff --git a/src/test/rustdoc/issue-88600.rs b/src/test/rustdoc/issue-88600.rs index fc63ed343bda2..db0d102b74184 100644 --- a/src/test/rustdoc/issue-88600.rs +++ b/src/test/rustdoc/issue-88600.rs @@ -8,22 +8,22 @@ pub struct S; // @has issue_88600/enum.FooEnum.html pub enum FooEnum { - // @has - '//*[@id="variant.HiddenTupleItem"]//code' 'HiddenTupleItem(_)' + // @has - '//*[@id="variant.HiddenTupleItem"]//h3' 'HiddenTupleItem(_)' // @count - '//*[@id="variant.HiddenTupleItem.field.0"]' 0 HiddenTupleItem(#[doc(hidden)] H), - // @has - '//*[@id="variant.MultipleHidden"]//code' 'MultipleHidden(_, _)' + // @has - '//*[@id="variant.MultipleHidden"]//h3' 'MultipleHidden(_, _)' // @count - '//*[@id="variant.MultipleHidden.field.0"]' 0 // @count - '//*[@id="variant.MultipleHidden.field.1"]' 0 MultipleHidden(#[doc(hidden)] H, #[doc(hidden)] H), - // @has - '//*[@id="variant.MixedHiddenFirst"]//code' 'MixedHiddenFirst(_, S)' + // @has - '//*[@id="variant.MixedHiddenFirst"]//h3' 'MixedHiddenFirst(_, S)' // @count - '//*[@id="variant.MixedHiddenFirst.field.0"]' 0 // @has - '//*[@id="variant.MixedHiddenFirst.field.1"]' '1: S' MixedHiddenFirst(#[doc(hidden)] H, /** dox */ S), - // @has - '//*[@id="variant.MixedHiddenLast"]//code' 'MixedHiddenLast(S, _)' + // @has - '//*[@id="variant.MixedHiddenLast"]//h3' 'MixedHiddenLast(S, _)' // @has - '//*[@id="variant.MixedHiddenLast.field.0"]' '0: S' // @count - '//*[@id="variant.MixedHiddenLast.field.1"]' 0 MixedHiddenLast(/** dox */ S, #[doc(hidden)] H), - // @has - '//*[@id="variant.HiddenStruct"]//code' 'HiddenStruct' + // @has - '//*[@id="variant.HiddenStruct"]//h3' 'HiddenStruct' // @count - '//*[@id="variant.HiddenStruct.field.h"]' 0 // @has - '//*[@id="variant.HiddenStruct.field.s"]' 's: S' HiddenStruct { From e3036df0032bb6726408a9f6705acaf38e55d59f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Fri, 18 Nov 2022 10:30:47 +0100 Subject: [PATCH 047/103] couple of clippy::perf fixes --- compiler/rustc_expand/src/base.rs | 2 +- compiler/rustc_lint/src/unused.rs | 4 ++-- compiler/rustc_macros/src/diagnostics/utils.rs | 2 +- compiler/rustc_middle/src/ty/print/pretty.rs | 4 +--- compiler/rustc_mir_dataflow/src/value_analysis.rs | 2 +- compiler/rustc_parse/src/parser/diagnostics.rs | 4 ++-- compiler/rustc_passes/src/check_attr.rs | 2 +- compiler/rustc_passes/src/dead.rs | 2 +- src/librustdoc/config.rs | 4 ++-- src/librustdoc/html/static_files.rs | 2 +- src/tools/miropt-test-tools/src/lib.rs | 2 +- 11 files changed, 14 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 95fff929d46fe..04fe6c4007e94 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -1436,7 +1436,7 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &ParseSess) -> bool { let crate_matches = if c.starts_with("allsorts-rental") { true } else { - let mut version = c.trim_start_matches("rental-").split("."); + let mut version = c.trim_start_matches("rental-").split('.'); version.next() == Some("0") && version.next() == Some("5") && version diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index ff0fb9bae9232..bd6fe3c0dd862 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -584,7 +584,7 @@ trait UnusedDelimLint { let sm = cx.sess().source_map(); let lo_replace = if keep_space.0 && - let Ok(snip) = sm.span_to_prev_source(lo) && !snip.ends_with(" ") { + let Ok(snip) = sm.span_to_prev_source(lo) && !snip.ends_with(' ') { " ".to_string() } else { "".to_string() @@ -592,7 +592,7 @@ trait UnusedDelimLint { let hi_replace = if keep_space.1 && - let Ok(snip) = sm.span_to_next_source(hi) && !snip.starts_with(" ") { + let Ok(snip) = sm.span_to_next_source(hi) && !snip.starts_with(' ') { " ".to_string() } else { "".to_string() diff --git a/compiler/rustc_macros/src/diagnostics/utils.rs b/compiler/rustc_macros/src/diagnostics/utils.rs index ba06f61299f37..dff088b9bdfa6 100644 --- a/compiler/rustc_macros/src/diagnostics/utils.rs +++ b/compiler/rustc_macros/src/diagnostics/utils.rs @@ -830,5 +830,5 @@ pub(super) fn should_generate_set_arg(field: &Field) -> bool { } pub(super) fn is_doc_comment(attr: &Attribute) -> bool { - attr.path.segments.last().unwrap().ident.to_string() == "doc" + attr.path.segments.last().unwrap().ident == "doc" } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 48e803597b02e..93d6850560d7c 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2194,11 +2194,9 @@ impl<'tcx> FmtPrinter<'_, 'tcx> { define_scoped_cx!(self); - let possible_names = - ('a'..='z').rev().map(|s| Symbol::intern(&format!("'{s}"))).collect::>(); + let possible_names = ('a'..='z').rev().map(|s| Symbol::intern(&format!("'{s}"))); let mut available_names = possible_names - .into_iter() .filter(|name| !self.used_region_names.contains(&name)) .collect::>(); debug!(?available_names); diff --git a/compiler/rustc_mir_dataflow/src/value_analysis.rs b/compiler/rustc_mir_dataflow/src/value_analysis.rs index db4b0a3deda9d..cc69a1bb02db1 100644 --- a/compiler/rustc_mir_dataflow/src/value_analysis.rs +++ b/compiler/rustc_mir_dataflow/src/value_analysis.rs @@ -899,7 +899,7 @@ fn debug_with_context_rec( let info_elem = map.places[child].proj_elem.unwrap(); let child_place_str = match info_elem { TrackElem::Field(field) => { - if place_str.starts_with("*") { + if place_str.starts_with('*') { format!("({}).{}", place_str, field.index()) } else { format!("{}.{}", place_str, field.index()) diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 0bbe073fe2af4..62b6bdcf05153 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -1657,14 +1657,14 @@ impl<'a> Parser<'a> { let left = begin_par_sp; let right = self.prev_token.span; let left_snippet = if let Ok(snip) = sm.span_to_prev_source(left) && - !snip.ends_with(" ") { + !snip.ends_with(' ') { " ".to_string() } else { "".to_string() }; let right_snippet = if let Ok(snip) = sm.span_to_next_source(right) && - !snip.starts_with(" ") { + !snip.starts_with(' ') { " ".to_string() } else { "".to_string() diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 6b8cd0713732d..acb9bd8e78a4a 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -353,7 +353,7 @@ impl CheckAttrVisitor<'_> { attr.span, OnlyHasEffectOn { attr_name: attr.name_or_empty(), - target_name: allowed_target.name().replace(" ", "_"), + target_name: allowed_target.name().replace(' ', "_"), }, ); } diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index d4722234a8f1e..5d0224c35f364 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -772,7 +772,7 @@ impl<'tcx> DeadVisitor<'tcx> { self.tcx.emit_spanned_lint( lint, tcx.hir().local_def_id_to_hir_id(first_id), - MultiSpan::from_spans(spans.clone()), + MultiSpan::from_spans(spans), diag, ); } diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 789dd398be50d..e0cdb86d9d1dc 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -418,7 +418,7 @@ impl Options { ) { Ok(p) => p, Err(e) => { - diag.struct_err(&e.to_string()).emit(); + diag.struct_err(e).emit(); return Err(1); } }; @@ -561,7 +561,7 @@ impl Options { ) { Ok(p) => p, Err(e) => { - diag.struct_err(&e.to_string()).emit(); + diag.struct_err(e).emit(); return Err(1); } }; diff --git a/src/librustdoc/html/static_files.rs b/src/librustdoc/html/static_files.rs index b4d4150cddbb8..1f87f95563ad5 100644 --- a/src/librustdoc/html/static_files.rs +++ b/src/librustdoc/html/static_files.rs @@ -58,7 +58,7 @@ pub(crate) fn suffix_path(filename: &str, suffix: &str) -> PathBuf { } pub(crate) fn static_filename(filename: &str, contents: &[u8]) -> PathBuf { - let filename = filename.rsplit("/").next().unwrap(); + let filename = filename.rsplit('/').next().unwrap(); suffix_path(filename, &static_suffix(contents)) } diff --git a/src/tools/miropt-test-tools/src/lib.rs b/src/tools/miropt-test-tools/src/lib.rs index 96819d3547b29..cfba7d583b138 100644 --- a/src/tools/miropt-test-tools/src/lib.rs +++ b/src/tools/miropt-test-tools/src/lib.rs @@ -11,7 +11,7 @@ pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec< let test_file_contents = fs::read_to_string(&testfile).unwrap(); let test_dir = testfile.parent().unwrap(); - let test_crate = testfile.file_stem().unwrap().to_str().unwrap().replace("-", "_"); + let test_crate = testfile.file_stem().unwrap().to_str().unwrap().replace('-', "_"); let bit_width = if test_file_contents.lines().any(|l| l == "// EMIT_MIR_FOR_EACH_BIT_WIDTH") { format!(".{}bit", bit_width) From 27019f10ae18d0a839648d05e422d9b0337908c2 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Fri, 18 Nov 2022 10:38:51 +0000 Subject: [PATCH 048/103] Remove Vec/Rc storage reuse opt --- library/alloc/src/rc.rs | 59 ++++--------------------------------- library/alloc/src/sync.rs | 60 ++++---------------------------------- library/alloc/tests/arc.rs | 15 ---------- library/alloc/tests/rc.rs | 15 ---------- 4 files changed, 12 insertions(+), 137 deletions(-) diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index f3cbfe27b3eed..5f307069d8076 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -1441,48 +1441,6 @@ impl Rc<[T]> { } } - /// Create an `Rc<[T]>` by reusing the underlying memory - /// of a `Vec`. This will return the vector if the existing allocation - /// is not large enough. - #[cfg(not(no_global_oom_handling))] - fn try_from_vec_in_place(mut v: Vec) -> Result, Vec> { - let layout_elements = Layout::array::(v.len()).unwrap(); - let layout_allocation = Layout::array::(v.capacity()).unwrap(); - let layout_rcbox = rcbox_layout_for_value_layout(layout_elements); - let mut ptr = NonNull::new(v.as_mut_ptr()).expect("`Vec` stores `NonNull`"); - if layout_rcbox.size() > layout_allocation.size() - || layout_rcbox.align() > layout_allocation.align() - { - // Can't fit - calling `grow` would involve `realloc` - // (which copies the elements), followed by copying again. - return Err(v); - } - if layout_rcbox.size() < layout_allocation.size() - || layout_rcbox.align() < layout_allocation.align() - { - // We need to shrink the allocation so that it fits - // https://doc.rust-lang.org/nightly/std/alloc/trait.Allocator.html#memory-fitting - // SAFETY: - // - Vec allocates by requesting `Layout::array::(capacity)`, so this capacity matches - // - `layout_rcbox` is smaller - // If this fails, the ownership has not been transferred - if let Ok(p) = unsafe { Global.shrink(ptr.cast(), layout_allocation, layout_rcbox) } { - ptr = p.cast(); - } else { - return Err(v); - } - } - // Make sure the vec's memory isn't deallocated now - let v = mem::ManuallyDrop::new(v); - let ptr: *mut RcBox<[T]> = ptr::slice_from_raw_parts_mut(ptr.as_ptr(), v.len()) as _; - unsafe { - ptr::copy(ptr.cast::(), &mut (*ptr).value as *mut [T] as *mut T, v.len()); - ptr::write(&mut (*ptr).strong, Cell::new(1)); - ptr::write(&mut (*ptr).weak, Cell::new(1)); - Ok(Self::from_ptr(ptr)) - } - } - /// Constructs an `Rc<[T]>` from an iterator known to be of a certain size. /// /// Behavior is undefined should the size be wrong. @@ -2008,17 +1966,12 @@ impl From> for Rc<[T]> { /// assert_eq!(vec![1, 2, 3], *shared); /// ``` #[inline] - fn from(v: Vec) -> Rc<[T]> { - match Rc::try_from_vec_in_place(v) { - Ok(rc) => rc, - Err(mut v) => { - unsafe { - let rc = Rc::copy_from_slice(&v); - // Allow the Vec to free its memory, but not destroy its contents - v.set_len(0); - rc - } - } + fn from(mut v: Vec) -> Rc<[T]> { + unsafe { + let rc = Rc::copy_from_slice(&v); + // Allow the Vec to free its memory, but not destroy its contents + v.set_len(0); + rc } } } diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 37e07eb5998b3..b69f6b0311234 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -1261,49 +1261,6 @@ impl Arc<[T]> { } } - /// Create an `Arc<[T]>` by reusing the underlying memory - /// of a `Vec`. This will return the vector if the existing allocation - /// is not large enough. - #[cfg(not(no_global_oom_handling))] - fn try_from_vec_in_place(mut v: Vec) -> Result, Vec> { - let layout_elements = Layout::array::(v.len()).unwrap(); - let layout_allocation = Layout::array::(v.capacity()).unwrap(); - let layout_arcinner = arcinner_layout_for_value_layout(layout_elements); - let mut ptr = NonNull::new(v.as_mut_ptr()).expect("`Vec` stores `NonNull`"); - if layout_arcinner.size() > layout_allocation.size() - || layout_arcinner.align() > layout_allocation.align() - { - // Can't fit - calling `grow` would involve `realloc` - // (which copies the elements), followed by copying again. - return Err(v); - } - if layout_arcinner.size() < layout_allocation.size() - || layout_arcinner.align() < layout_allocation.align() - { - // We need to shrink the allocation so that it fits - // https://doc.rust-lang.org/nightly/std/alloc/trait.Allocator.html#memory-fitting - // SAFETY: - // - Vec allocates by requesting `Layout::array::(capacity)`, so this capacity matches - // - `layout_arcinner` is smaller - // If this fails, the ownership has not been transferred - if let Ok(p) = unsafe { Global.shrink(ptr.cast(), layout_allocation, layout_arcinner) } - { - ptr = p.cast(); - } else { - return Err(v); - } - } - // Make sure the vec's memory isn't deallocated now - let v = mem::ManuallyDrop::new(v); - let ptr: *mut ArcInner<[T]> = ptr::slice_from_raw_parts_mut(ptr.as_ptr(), v.len()) as _; - unsafe { - ptr::copy(ptr.cast::(), &mut (*ptr).data as *mut [T] as *mut T, v.len()); - ptr::write(&mut (*ptr).strong, atomic::AtomicUsize::new(1)); - ptr::write(&mut (*ptr).weak, atomic::AtomicUsize::new(1)); - Ok(Self::from_ptr(ptr)) - } - } - /// Constructs an `Arc<[T]>` from an iterator known to be of a certain size. /// /// Behavior is undefined should the size be wrong. @@ -2615,17 +2572,12 @@ impl From> for Arc<[T]> { /// assert_eq!(&[1, 2, 3], &shared[..]); /// ``` #[inline] - fn from(v: Vec) -> Arc<[T]> { - match Arc::try_from_vec_in_place(v) { - Ok(rc) => rc, - Err(mut v) => { - unsafe { - let rc = Arc::copy_from_slice(&v); - // Allow the Vec to free its memory, but not destroy its contents - v.set_len(0); - rc - } - } + fn from(mut v: Vec) -> Arc<[T]> { + unsafe { + let rc = Arc::copy_from_slice(&v); + // Allow the Vec to free its memory, but not destroy its contents + v.set_len(0); + rc } } } diff --git a/library/alloc/tests/arc.rs b/library/alloc/tests/arc.rs index eb379e4d6a10f..ce40b5c9b0a0d 100644 --- a/library/alloc/tests/arc.rs +++ b/library/alloc/tests/arc.rs @@ -210,18 +210,3 @@ fn weak_may_dangle() { // `val` dropped here while still borrowed // borrow might be used here, when `val` is dropped and runs the `Drop` code for type `std::sync::Weak` } - -#[test] -fn arc_from_vec_opt() { - let mut v = Vec::with_capacity(64); - v.push(0usize); - let addr = v.as_ptr().cast::(); - let arc: Arc<[_]> = v.into(); - unsafe { - assert_eq!( - arc.as_ptr().cast::().offset_from(addr), - (std::mem::size_of::() * 2) as isize, - "Vector allocation not reused" - ); - } -} diff --git a/library/alloc/tests/rc.rs b/library/alloc/tests/rc.rs index 1d5f3c5200648..efb39a609665b 100644 --- a/library/alloc/tests/rc.rs +++ b/library/alloc/tests/rc.rs @@ -206,18 +206,3 @@ fn weak_may_dangle() { // `val` dropped here while still borrowed // borrow might be used here, when `val` is dropped and runs the `Drop` code for type `std::rc::Weak` } - -#[test] -fn rc_from_vec_opt() { - let mut v = Vec::with_capacity(64); - v.push(0usize); - let addr = v.as_ptr().cast::(); - let rc: Rc<[_]> = v.into(); - unsafe { - assert_eq!( - rc.as_ptr().cast::().offset_from(addr), - (std::mem::size_of::() * 2) as isize, - "Vector allocation not reused" - ); - } -} From b8a5b02102113198dde2011fd16192ef98c45227 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 18 Nov 2022 13:36:18 +0100 Subject: [PATCH 049/103] Don't focus on notable trait parent when hiding it --- src/librustdoc/html/static/js/main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 874f130d7e23c..67eff9497e121 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -910,7 +910,6 @@ function loadCss(cssUrl) { function hideNotable() { if (window.CURRENT_NOTABLE_ELEMENT) { if (window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE) { - window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.focus(); window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE = false; } const body = document.getElementsByTagName("body")[0]; From c1ec8ff14d491642d8c8ae5a9f3c94db4eda9f26 Mon Sep 17 00:00:00 2001 From: Boxy Date: Thu, 17 Nov 2022 20:45:11 +0000 Subject: [PATCH 050/103] dont unchecked create `ErrorGuaranteed` in `BorrowckErrors` --- compiler/rustc_borrowck/src/lib.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 4a4887f19702f..c9daed3ab00be 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -192,13 +192,13 @@ fn do_mir_borrowck<'tcx>( } } - let mut errors = error::BorrowckErrors::new(); + let mut errors = error::BorrowckErrors::new(infcx.tcx); // Gather the upvars of a closure, if any. let tables = tcx.typeck_opt_const_arg(def); - if let Some(ErrorGuaranteed { .. }) = tables.tainted_by_errors { + if let Some(e) = tables.tainted_by_errors { infcx.set_tainted_by_errors(); - errors.set_tainted_by_errors(); + errors.set_tainted_by_errors(e); } let upvars: Vec<_> = tables .closure_min_captures_flattened(def.did) @@ -2260,6 +2260,7 @@ mod error { use super::*; pub struct BorrowckErrors<'tcx> { + tcx: TyCtxt<'tcx>, /// This field keeps track of move errors that are to be reported for given move indices. /// /// There are situations where many errors can be reported for a single move out (see #53807) @@ -2282,19 +2283,20 @@ mod error { tainted_by_errors: Option, } - impl BorrowckErrors<'_> { - pub fn new() -> Self { + impl<'tcx> BorrowckErrors<'tcx> { + pub fn new(tcx: TyCtxt<'tcx>) -> Self { BorrowckErrors { + tcx, buffered_move_errors: BTreeMap::new(), buffered: Default::default(), tainted_by_errors: None, } } - // FIXME(eddyb) this is a suboptimal API because `tainted_by_errors` is - // set before any emission actually happens (weakening the guarantee). pub fn buffer_error(&mut self, t: DiagnosticBuilder<'_, ErrorGuaranteed>) { - self.tainted_by_errors = Some(ErrorGuaranteed::unchecked_claim_error_was_emitted()); + self.tainted_by_errors = Some( + self.tcx.sess.delay_span_bug(t.span.clone(), "diagnostic buffered but not emitted"), + ); t.buffer(&mut self.buffered); } @@ -2302,8 +2304,8 @@ mod error { t.buffer(&mut self.buffered); } - pub fn set_tainted_by_errors(&mut self) { - self.tainted_by_errors = Some(ErrorGuaranteed::unchecked_claim_error_was_emitted()); + pub fn set_tainted_by_errors(&mut self, e: ErrorGuaranteed) { + self.tainted_by_errors = Some(e); } } From 9c510048fdd9b78bda5084d56fffb69da677d967 Mon Sep 17 00:00:00 2001 From: Boxy Date: Thu, 17 Nov 2022 20:57:45 +0000 Subject: [PATCH 051/103] `InferCtxt::is_tainted_by_errors` returns `ErrorGuaranteed` --- compiler/rustc_borrowck/src/lib.rs | 2 +- .../src/region_infer/opaque_types.rs | 4 ++-- compiler/rustc_hir_typeck/src/fallback.rs | 2 +- .../rustc_hir_typeck/src/fn_ctxt/_impl.rs | 6 ++--- compiler/rustc_hir_typeck/src/lib.rs | 2 +- .../src/mem_categorization.rs | 2 +- compiler/rustc_hir_typeck/src/writeback.rs | 6 ++--- compiler/rustc_infer/src/infer/mod.rs | 14 +++++++----- .../src/traits/error_reporting/mod.rs | 22 +++++++++---------- .../src/traits/select/mod.rs | 8 +++---- 10 files changed, 33 insertions(+), 35 deletions(-) diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index c9daed3ab00be..1591048d65702 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -19,7 +19,7 @@ extern crate tracing; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::graph::dominators::Dominators; use rustc_data_structures::vec_map::VecMap; -use rustc_errors::{Diagnostic, DiagnosticBuilder, ErrorGuaranteed}; +use rustc_errors::{Diagnostic, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; use rustc_index::bit_set::ChunkedBitSet; diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs index b2db77944fd1e..b1060d9505c0b 100644 --- a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs @@ -219,8 +219,8 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> { instantiated_ty: OpaqueHiddenType<'tcx>, origin: OpaqueTyOrigin, ) -> Ty<'tcx> { - if self.is_tainted_by_errors() { - return self.tcx.ty_error(); + if let Some(e) = self.is_tainted_by_errors() { + return self.tcx.ty_error_with_guaranteed(e); } let definition_ty = instantiated_ty diff --git a/compiler/rustc_hir_typeck/src/fallback.rs b/compiler/rustc_hir_typeck/src/fallback.rs index 5d44092a5f68e..653c841290d02 100644 --- a/compiler/rustc_hir_typeck/src/fallback.rs +++ b/compiler/rustc_hir_typeck/src/fallback.rs @@ -104,7 +104,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> { // type, `?T` is not considered unsolved, but `?I` is. The // same is true for float variables.) let fallback = match ty.kind() { - _ if self.is_tainted_by_errors() => self.tcx.ty_error(), + _ if let Some(e) = self.is_tainted_by_errors() => self.tcx.ty_error_with_guaranteed(e), ty::Infer(ty::IntVar(_)) => self.tcx.types.i32, ty::Infer(ty::FloatVar(_)) => self.tcx.types.f64, _ => match diverging_fallback.get(&ty) { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index c826a886ca641..86e7f818d5498 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -528,7 +528,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn node_ty(&self, id: hir::HirId) -> Ty<'tcx> { match self.typeck_results.borrow().node_types().get(id) { Some(&t) => t, - None if self.is_tainted_by_errors() => self.tcx.ty_error(), + None if let Some(e) = self.is_tainted_by_errors() => self.tcx.ty_error_with_guaranteed(e), None => { bug!( "no type for node {}: {} in fcx {}", @@ -543,7 +543,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn node_ty_opt(&self, id: hir::HirId) -> Option> { match self.typeck_results.borrow().node_types().get(id) { Some(&t) => Some(t), - None if self.is_tainted_by_errors() => Some(self.tcx.ty_error()), + None if let Some(e) = self.is_tainted_by_errors() => Some(self.tcx.ty_error_with_guaranteed(e)), None => None, } } @@ -1440,7 +1440,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if !ty.is_ty_var() { ty } else { - if !self.is_tainted_by_errors() { + if let None = self.is_tainted_by_errors() { self.err_ctxt() .emit_inference_failure_err((**self).body_id, sp, ty.into(), E0282, true) .emit(); diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 6fd609aeaa060..56d8ce2a5c66d 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -344,7 +344,7 @@ fn typeck_with_fallback<'tcx>( fcx.select_all_obligations_or_error(); - if !fcx.infcx.is_tainted_by_errors() { + if let None = fcx.infcx.is_tainted_by_errors() { fcx.check_transmutes(); } diff --git a/compiler/rustc_hir_typeck/src/mem_categorization.rs b/compiler/rustc_hir_typeck/src/mem_categorization.rs index 362f1c3430041..495502da40670 100644 --- a/compiler/rustc_hir_typeck/src/mem_categorization.rs +++ b/compiler/rustc_hir_typeck/src/mem_categorization.rs @@ -133,7 +133,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { } fn is_tainted_by_errors(&self) -> bool { - self.infcx.is_tainted_by_errors() + self.infcx.is_tainted_by_errors().is_some() } fn resolve_type_vars_or_error( diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index 2eca40d678a84..d3b704a672bee 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -83,10 +83,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { wbcx.typeck_results.treat_byte_string_as_slice = mem::take(&mut self.typeck_results.borrow_mut().treat_byte_string_as_slice); - if self.is_tainted_by_errors() { - // FIXME(eddyb) keep track of `ErrorGuaranteed` from where the error was emitted. - wbcx.typeck_results.tainted_by_errors = - Some(ErrorGuaranteed::unchecked_claim_error_was_emitted()); + if let Some(e) = self.is_tainted_by_errors() { + wbcx.typeck_results.tainted_by_errors = Some(e); } debug!("writeback: typeck results for {:?} are {:#?}", item_def_id, wbcx.typeck_results); diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index fd3b3e4d59fa6..f966c7bb776d7 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -1208,7 +1208,7 @@ impl<'tcx> InferCtxt<'tcx> { /// reporting errors that often occur as a result of earlier /// errors, but where it's hard to be 100% sure (e.g., unresolved /// inference variables, regionck errors). - pub fn is_tainted_by_errors(&self) -> bool { + pub fn is_tainted_by_errors(&self) -> Option { debug!( "is_tainted_by_errors(err_count={}, err_count_on_creation={}, \ tainted_by_errors={})", @@ -1218,9 +1218,13 @@ impl<'tcx> InferCtxt<'tcx> { ); if self.tcx.sess.err_count() > self.err_count_on_creation { - return true; // errors reported since this infcx was made + // errors reported since this infcx was made + return Some(self.tcx.sess.delay_span_bug( + DUMMY_SP, + "`tcx.sess.error_count()` incorrectly returned non zero value", + )); } - self.tainted_by_errors.get().is_some() + self.tainted_by_errors.get() } /// Set the "tainted by errors" flag to true. We call this when we @@ -1270,7 +1274,7 @@ impl<'tcx> InferCtxt<'tcx> { let mut inner = self.inner.borrow_mut(); let inner = &mut *inner; assert!( - self.is_tainted_by_errors() || inner.region_obligations.is_empty(), + self.is_tainted_by_errors().is_some() || inner.region_obligations.is_empty(), "region_obligations not empty: {:#?}", inner.region_obligations ); @@ -1707,7 +1711,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { ) { let errors = self.resolve_regions(outlives_env); - if !self.is_tainted_by_errors() { + if let None = self.is_tainted_by_errors() { // As a heuristic, just skip reporting region errors // altogether if other errors have been reported while // this infcx was in use. This is totally hokey but diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index f087afa20baca..c96c1f78146b8 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -2060,7 +2060,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // check upstream for type errors and don't add the obligations to // begin with in those cases. if self.tcx.lang_items().sized_trait() == Some(trait_ref.def_id()) { - if !self.is_tainted_by_errors() { + if let None = self.is_tainted_by_errors() { self.emit_inference_failure_err( body_id, span, @@ -2115,16 +2115,14 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { if impls.len() > 1 && impls.len() < 5 && has_non_region_infer { self.annotate_source_of_ambiguity(&mut err, &impls, predicate); } else { - if self.is_tainted_by_errors() { - err.delay_as_bug(); + if self.is_tainted_by_errors().is_some() { return; } err.note(&format!("cannot satisfy `{}`", predicate)); } } _ => { - if self.is_tainted_by_errors() { - err.delay_as_bug(); + if self.is_tainted_by_errors().is_some() { return; } err.note(&format!("cannot satisfy `{}`", predicate)); @@ -2226,7 +2224,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ] = path.segments && data.trait_ref.def_id == *trait_id && self.tcx.trait_of_item(*item_id) == Some(*trait_id) - && !self.is_tainted_by_errors() + && let None = self.is_tainted_by_errors() { let (verb, noun) = match self.tcx.associated_item(item_id).kind { ty::AssocKind::Const => ("refer to the", "constant"), @@ -2295,7 +2293,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // with error messages. if arg.references_error() || self.tcx.sess.has_errors().is_some() - || self.is_tainted_by_errors() + || self.is_tainted_by_errors().is_some() { return; } @@ -2306,7 +2304,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ty::PredicateKind::Subtype(data) => { if data.references_error() || self.tcx.sess.has_errors().is_some() - || self.is_tainted_by_errors() + || self.is_tainted_by_errors().is_some() { // no need to overload user in such cases return; @@ -2317,7 +2315,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { self.emit_inference_failure_err(body_id, span, a.into(), ErrorCode::E0282, true) } ty::PredicateKind::Projection(data) => { - if predicate.references_error() || self.is_tainted_by_errors() { + if predicate.references_error() || self.is_tainted_by_errors().is_some() { return; } let subst = data @@ -2351,7 +2349,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } ty::PredicateKind::ConstEvaluatable(data) => { - if predicate.references_error() || self.is_tainted_by_errors() { + if predicate.references_error() || self.is_tainted_by_errors().is_some() { return; } let subst = data.walk().find(|g| g.is_non_region_infer()); @@ -2378,7 +2376,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } } _ => { - if self.tcx.sess.has_errors().is_some() || self.is_tainted_by_errors() { + if self.tcx.sess.has_errors().is_some() || self.is_tainted_by_errors().is_some() { return; } let mut err = struct_span_err!( @@ -2422,7 +2420,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { post.sort(); post.dedup(); - if self.is_tainted_by_errors() + if self.is_tainted_by_errors().is_some() && (crate_names.len() == 1 && spans.len() == 0 && ["`core`", "`alloc`", "`std`"].contains(&crate_names[0].as_str()) diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index c369c5de52bb1..8a2bfb5351fd9 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -33,7 +33,7 @@ use crate::traits::ProjectionCacheKey; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_data_structures::stack::ensure_sufficient_stack; -use rustc_errors::{Diagnostic, ErrorGuaranteed}; +use rustc_errors::Diagnostic; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_infer::infer::LateBoundRegionConversionTime; @@ -1089,10 +1089,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { if !self.infcx.tcx.recursion_limit().value_within_limit(depth) { match self.query_mode { TraitQueryMode::Standard => { - if self.infcx.is_tainted_by_errors() { - return Err(OverflowError::Error( - ErrorGuaranteed::unchecked_claim_error_was_emitted(), - )); + if let Some(e) = self.infcx.is_tainted_by_errors() { + return Err(OverflowError::Error(e)); } self.infcx.err_ctxt().report_overflow_error(error_obligation, true); } From 95a267bb345dcb13b52a66e322d730414996e439 Mon Sep 17 00:00:00 2001 From: Boxy Date: Thu, 17 Nov 2022 21:03:06 +0000 Subject: [PATCH 052/103] make `replaced_with_error` store `ErrorGuaranteed` --- compiler/rustc_hir_typeck/src/writeback.rs | 33 +++++++++++----------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index d3b704a672bee..a620a05aca202 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -672,10 +672,9 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { // We may have introduced e.g. `ty::Error`, if inference failed, make sure // to mark the `TypeckResults` as tainted in that case, so that downstream // users of the typeck results don't produce extra errors, or worse, ICEs. - if resolver.replaced_with_error { + if let Some(e) = resolver.replaced_with_error { // FIXME(eddyb) keep track of `ErrorGuaranteed` from where the error was emitted. - self.typeck_results.tainted_by_errors = - Some(ErrorGuaranteed::unchecked_claim_error_was_emitted()); + self.typeck_results.tainted_by_errors = Some(e); } x @@ -706,8 +705,8 @@ struct Resolver<'cx, 'tcx> { span: &'cx dyn Locatable, body: &'tcx hir::Body<'tcx>, - /// Set to `true` if any `Ty` or `ty::Const` had to be replaced with an `Error`. - replaced_with_error: bool, + /// Set to `Some` if any `Ty` or `ty::Const` had to be replaced with an `Error`. + replaced_with_error: Option, } impl<'cx, 'tcx> Resolver<'cx, 'tcx> { @@ -716,12 +715,14 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> { span: &'cx dyn Locatable, body: &'tcx hir::Body<'tcx>, ) -> Resolver<'cx, 'tcx> { - Resolver { tcx: fcx.tcx, infcx: fcx, span, body, replaced_with_error: false } + Resolver { tcx: fcx.tcx, infcx: fcx, span, body, replaced_with_error: None } } - fn report_error(&self, p: impl Into>) { - if !self.tcx.sess.has_errors().is_some() { - self.infcx + fn report_error(&self, p: impl Into>) -> ErrorGuaranteed { + match self.tcx.sess.has_errors() { + Some(e) => e, + None => self + .infcx .err_ctxt() .emit_inference_failure_err( Some(self.body.id()), @@ -730,7 +731,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> { E0282, false, ) - .emit(); + .emit(), } } } @@ -771,9 +772,9 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Resolver<'cx, 'tcx> { } Err(_) => { debug!("Resolver::fold_ty: input type `{:?}` not fully resolvable", t); - self.report_error(t); - self.replaced_with_error = true; - self.tcx().ty_error() + let e = self.report_error(t); + self.replaced_with_error = Some(e); + self.tcx().ty_error_with_guaranteed(e) } } } @@ -788,9 +789,9 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Resolver<'cx, 'tcx> { Ok(ct) => self.tcx.erase_regions(ct), Err(_) => { debug!("Resolver::fold_const: input const `{:?}` not fully resolvable", ct); - self.report_error(ct); - self.replaced_with_error = true; - self.tcx().const_error(ct.ty()) + let e = self.report_error(ct); + self.replaced_with_error = Some(e); + self.tcx().const_error_with_guaranteed(ct.ty(), e) } } } From 3fca95a5976aa89612869203f7ffe857d689b033 Mon Sep 17 00:00:00 2001 From: Boxy Date: Thu, 17 Nov 2022 21:09:59 +0000 Subject: [PATCH 053/103] `track_errors` use a delay_span_bug --- compiler/rustc_session/src/session.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 103521983578b..d602acec53e32 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -562,7 +562,10 @@ impl Session { if self.err_count() == old_count { Ok(result) } else { - Err(ErrorGuaranteed::unchecked_claim_error_was_emitted()) + Err(self.delay_span_bug( + rustc_span::DUMMY_SP, + "`self.err_count()` changed but an error was not emitted", + )) } } #[allow(rustc::untranslatable_diagnostic)] From 1c48039a873f331a4591a499f71161b5c8997af1 Mon Sep 17 00:00:00 2001 From: Boxy Date: Fri, 18 Nov 2022 10:25:32 +0000 Subject: [PATCH 054/103] rename `is_tainted_by_errors` --- compiler/rustc_borrowck/src/lib.rs | 10 ++++++--- .../src/region_infer/opaque_types.rs | 2 +- compiler/rustc_hir_typeck/src/fallback.rs | 2 +- .../rustc_hir_typeck/src/fn_ctxt/_impl.rs | 6 ++--- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 1 + compiler/rustc_hir_typeck/src/lib.rs | 2 +- .../src/mem_categorization.rs | 2 +- compiler/rustc_hir_typeck/src/writeback.rs | 3 +-- compiler/rustc_infer/src/infer/mod.rs | 20 ++++++++++------- .../src/traits/error_reporting/mod.rs | 22 ++++++++++--------- .../src/traits/select/mod.rs | 2 +- src/test/ui/issues/issue-52262.rs | 1 - src/test/ui/issues/issue-52262.stderr | 2 +- 13 files changed, 42 insertions(+), 33 deletions(-) diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 1591048d65702..e8b9796631432 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -2294,9 +2294,13 @@ mod error { } pub fn buffer_error(&mut self, t: DiagnosticBuilder<'_, ErrorGuaranteed>) { - self.tainted_by_errors = Some( - self.tcx.sess.delay_span_bug(t.span.clone(), "diagnostic buffered but not emitted"), - ); + if let None = self.tainted_by_errors { + self.tainted_by_errors = Some( + self.tcx + .sess + .delay_span_bug(t.span.clone(), "diagnostic buffered but not emitted"), + ) + } t.buffer(&mut self.buffered); } diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs index b1060d9505c0b..b9885952a893c 100644 --- a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs @@ -219,7 +219,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> { instantiated_ty: OpaqueHiddenType<'tcx>, origin: OpaqueTyOrigin, ) -> Ty<'tcx> { - if let Some(e) = self.is_tainted_by_errors() { + if let Some(e) = self.tainted_by_errors() { return self.tcx.ty_error_with_guaranteed(e); } diff --git a/compiler/rustc_hir_typeck/src/fallback.rs b/compiler/rustc_hir_typeck/src/fallback.rs index 653c841290d02..ac6b0924ab572 100644 --- a/compiler/rustc_hir_typeck/src/fallback.rs +++ b/compiler/rustc_hir_typeck/src/fallback.rs @@ -104,7 +104,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> { // type, `?T` is not considered unsolved, but `?I` is. The // same is true for float variables.) let fallback = match ty.kind() { - _ if let Some(e) = self.is_tainted_by_errors() => self.tcx.ty_error_with_guaranteed(e), + _ if let Some(e) = self.tainted_by_errors() => self.tcx.ty_error_with_guaranteed(e), ty::Infer(ty::IntVar(_)) => self.tcx.types.i32, ty::Infer(ty::FloatVar(_)) => self.tcx.types.f64, _ => match diverging_fallback.get(&ty) { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 86e7f818d5498..0d9189b12f6fd 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -528,7 +528,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn node_ty(&self, id: hir::HirId) -> Ty<'tcx> { match self.typeck_results.borrow().node_types().get(id) { Some(&t) => t, - None if let Some(e) = self.is_tainted_by_errors() => self.tcx.ty_error_with_guaranteed(e), + None if let Some(e) = self.tainted_by_errors() => self.tcx.ty_error_with_guaranteed(e), None => { bug!( "no type for node {}: {} in fcx {}", @@ -543,7 +543,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn node_ty_opt(&self, id: hir::HirId) -> Option> { match self.typeck_results.borrow().node_types().get(id) { Some(&t) => Some(t), - None if let Some(e) = self.is_tainted_by_errors() => Some(self.tcx.ty_error_with_guaranteed(e)), + None if let Some(e) = self.tainted_by_errors() => Some(self.tcx.ty_error_with_guaranteed(e)), None => None, } } @@ -1440,7 +1440,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if !ty.is_ty_var() { ty } else { - if let None = self.is_tainted_by_errors() { + if let None = self.tainted_by_errors() { self.err_ctxt() .emit_inference_failure_err((**self).body_id, sp, ty.into(), E0282, true) .emit(); diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index c3833b4872d99..6847b03f431db 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -73,6 +73,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ty = self.typeck_results.borrow().expr_ty_adjusted(expr); let ty = self.resolve_vars_if_possible(ty); if ty.has_non_region_infer() { + assert!(self.tainted_by_errors().is_some()); self.tcx.ty_error() } else { self.tcx.erase_regions(ty) diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 56d8ce2a5c66d..51cc2e7882de1 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -344,7 +344,7 @@ fn typeck_with_fallback<'tcx>( fcx.select_all_obligations_or_error(); - if let None = fcx.infcx.is_tainted_by_errors() { + if let None = fcx.infcx.tainted_by_errors() { fcx.check_transmutes(); } diff --git a/compiler/rustc_hir_typeck/src/mem_categorization.rs b/compiler/rustc_hir_typeck/src/mem_categorization.rs index 495502da40670..0b5dc946c1def 100644 --- a/compiler/rustc_hir_typeck/src/mem_categorization.rs +++ b/compiler/rustc_hir_typeck/src/mem_categorization.rs @@ -133,7 +133,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { } fn is_tainted_by_errors(&self) -> bool { - self.infcx.is_tainted_by_errors().is_some() + self.infcx.tainted_by_errors().is_some() } fn resolve_type_vars_or_error( diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index a620a05aca202..6c2ee35fa50da 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -83,7 +83,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { wbcx.typeck_results.treat_byte_string_as_slice = mem::take(&mut self.typeck_results.borrow_mut().treat_byte_string_as_slice); - if let Some(e) = self.is_tainted_by_errors() { + if let Some(e) = self.tainted_by_errors() { wbcx.typeck_results.tainted_by_errors = Some(e); } @@ -673,7 +673,6 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { // to mark the `TypeckResults` as tainted in that case, so that downstream // users of the typeck results don't produce extra errors, or worse, ICEs. if let Some(e) = resolver.replaced_with_error { - // FIXME(eddyb) keep track of `ErrorGuaranteed` from where the error was emitted. self.typeck_results.tainted_by_errors = Some(e); } diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index f966c7bb776d7..aa6fed136110b 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -1208,7 +1208,8 @@ impl<'tcx> InferCtxt<'tcx> { /// reporting errors that often occur as a result of earlier /// errors, but where it's hard to be 100% sure (e.g., unresolved /// inference variables, regionck errors). - pub fn is_tainted_by_errors(&self) -> Option { + #[must_use = "this method does not have any side effects"] + pub fn tainted_by_errors(&self) -> Option { debug!( "is_tainted_by_errors(err_count={}, err_count_on_creation={}, \ tainted_by_errors={})", @@ -1217,14 +1218,17 @@ impl<'tcx> InferCtxt<'tcx> { self.tainted_by_errors.get().is_some() ); + if let Some(e) = self.tainted_by_errors.get() { + return Some(e); + } + if self.tcx.sess.err_count() > self.err_count_on_creation { // errors reported since this infcx was made - return Some(self.tcx.sess.delay_span_bug( - DUMMY_SP, - "`tcx.sess.error_count()` incorrectly returned non zero value", - )); + self.set_tainted_by_errors(); + return self.tainted_by_errors.get(); } - self.tainted_by_errors.get() + + None } /// Set the "tainted by errors" flag to true. We call this when we @@ -1274,7 +1278,7 @@ impl<'tcx> InferCtxt<'tcx> { let mut inner = self.inner.borrow_mut(); let inner = &mut *inner; assert!( - self.is_tainted_by_errors().is_some() || inner.region_obligations.is_empty(), + self.tainted_by_errors().is_some() || inner.region_obligations.is_empty(), "region_obligations not empty: {:#?}", inner.region_obligations ); @@ -1711,7 +1715,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { ) { let errors = self.resolve_regions(outlives_env); - if let None = self.is_tainted_by_errors() { + if let None = self.tainted_by_errors() { // As a heuristic, just skip reporting region errors // altogether if other errors have been reported while // this infcx was in use. This is totally hokey but diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index c96c1f78146b8..b84a1c447fffc 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -2060,7 +2060,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // check upstream for type errors and don't add the obligations to // begin with in those cases. if self.tcx.lang_items().sized_trait() == Some(trait_ref.def_id()) { - if let None = self.is_tainted_by_errors() { + if let None = self.tainted_by_errors() { self.emit_inference_failure_err( body_id, span, @@ -2115,14 +2115,16 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { if impls.len() > 1 && impls.len() < 5 && has_non_region_infer { self.annotate_source_of_ambiguity(&mut err, &impls, predicate); } else { - if self.is_tainted_by_errors().is_some() { + if self.tainted_by_errors().is_some() { + err.cancel(); return; } err.note(&format!("cannot satisfy `{}`", predicate)); } } _ => { - if self.is_tainted_by_errors().is_some() { + if self.tainted_by_errors().is_some() { + err.cancel(); return; } err.note(&format!("cannot satisfy `{}`", predicate)); @@ -2224,7 +2226,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ] = path.segments && data.trait_ref.def_id == *trait_id && self.tcx.trait_of_item(*item_id) == Some(*trait_id) - && let None = self.is_tainted_by_errors() + && let None = self.tainted_by_errors() { let (verb, noun) = match self.tcx.associated_item(item_id).kind { ty::AssocKind::Const => ("refer to the", "constant"), @@ -2293,7 +2295,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // with error messages. if arg.references_error() || self.tcx.sess.has_errors().is_some() - || self.is_tainted_by_errors().is_some() + || self.tainted_by_errors().is_some() { return; } @@ -2304,7 +2306,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ty::PredicateKind::Subtype(data) => { if data.references_error() || self.tcx.sess.has_errors().is_some() - || self.is_tainted_by_errors().is_some() + || self.tainted_by_errors().is_some() { // no need to overload user in such cases return; @@ -2315,7 +2317,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { self.emit_inference_failure_err(body_id, span, a.into(), ErrorCode::E0282, true) } ty::PredicateKind::Projection(data) => { - if predicate.references_error() || self.is_tainted_by_errors().is_some() { + if predicate.references_error() || self.tainted_by_errors().is_some() { return; } let subst = data @@ -2349,7 +2351,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } ty::PredicateKind::ConstEvaluatable(data) => { - if predicate.references_error() || self.is_tainted_by_errors().is_some() { + if predicate.references_error() || self.tainted_by_errors().is_some() { return; } let subst = data.walk().find(|g| g.is_non_region_infer()); @@ -2376,7 +2378,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } } _ => { - if self.tcx.sess.has_errors().is_some() || self.is_tainted_by_errors().is_some() { + if self.tcx.sess.has_errors().is_some() || self.tainted_by_errors().is_some() { return; } let mut err = struct_span_err!( @@ -2420,7 +2422,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { post.sort(); post.dedup(); - if self.is_tainted_by_errors().is_some() + if self.tainted_by_errors().is_some() && (crate_names.len() == 1 && spans.len() == 0 && ["`core`", "`alloc`", "`std`"].contains(&crate_names[0].as_str()) diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 8a2bfb5351fd9..b05942353a343 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1089,7 +1089,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { if !self.infcx.tcx.recursion_limit().value_within_limit(depth) { match self.query_mode { TraitQueryMode::Standard => { - if let Some(e) = self.infcx.is_tainted_by_errors() { + if let Some(e) = self.infcx.tainted_by_errors() { return Err(OverflowError::Error(e)); } self.infcx.err_ctxt().report_overflow_error(error_obligation, true); diff --git a/src/test/ui/issues/issue-52262.rs b/src/test/ui/issues/issue-52262.rs index 2195b89555791..547643f0d6e20 100644 --- a/src/test/ui/issues/issue-52262.rs +++ b/src/test/ui/issues/issue-52262.rs @@ -1,4 +1,3 @@ -// compile-flags:-Ztreat-err-as-bug=5 #[derive(Debug)] enum MyError { NotFound { key: Vec }, diff --git a/src/test/ui/issues/issue-52262.stderr b/src/test/ui/issues/issue-52262.stderr index c0bde4b2321f1..ef41f078b8037 100644 --- a/src/test/ui/issues/issue-52262.stderr +++ b/src/test/ui/issues/issue-52262.stderr @@ -1,5 +1,5 @@ error[E0507]: cannot move out of `*key` which is behind a shared reference - --> $DIR/issue-52262.rs:16:35 + --> $DIR/issue-52262.rs:15:35 | LL | String::from_utf8(*key).unwrap() | ^^^^ move occurs because `*key` has type `Vec`, which does not implement the `Copy` trait From 9ed348376fcdc49beb20cbd64760d2a923b76312 Mon Sep 17 00:00:00 2001 From: Boxy Date: Fri, 18 Nov 2022 11:30:21 +0000 Subject: [PATCH 055/103] require an `ErrorGuaranteed` to taint infcx with errors --- compiler/rustc_borrowck/src/lib.rs | 2 +- compiler/rustc_borrowck/src/nll.rs | 5 +- .../rustc_hir_analysis/src/astconv/mod.rs | 10 ++-- compiler/rustc_hir_analysis/src/collect.rs | 2 +- compiler/rustc_hir_typeck/src/coercion.rs | 4 +- compiler/rustc_hir_typeck/src/demand.rs | 5 +- compiler/rustc_hir_typeck/src/expr.rs | 16 ++++-- .../rustc_hir_typeck/src/fn_ctxt/_impl.rs | 8 +-- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 9 +++- compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs | 5 +- compiler/rustc_hir_typeck/src/lib.rs | 11 ++-- compiler/rustc_hir_typeck/src/pat.rs | 50 ++++++++++--------- compiler/rustc_infer/src/infer/mod.rs | 15 +++--- compiler/rustc_infer/src/infer/sub.rs | 6 +-- .../src/traits/error_reporting/mod.rs | 5 +- 15 files changed, 94 insertions(+), 59 deletions(-) diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index e8b9796631432..163170a1d1aa0 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -197,7 +197,7 @@ fn do_mir_borrowck<'tcx>( // Gather the upvars of a closure, if any. let tables = tcx.typeck_opt_const_arg(def); if let Some(e) = tables.tainted_by_errors { - infcx.set_tainted_by_errors(); + infcx.set_tainted_by_errors(e); errors.set_tainted_by_errors(e); } let upvars: Vec<_> = tables diff --git a/compiler/rustc_borrowck/src/nll.rs b/compiler/rustc_borrowck/src/nll.rs index f8856b56d140b..4a12e1b1b92e0 100644 --- a/compiler/rustc_borrowck/src/nll.rs +++ b/compiler/rustc_borrowck/src/nll.rs @@ -303,7 +303,10 @@ pub(crate) fn compute_regions<'cx, 'tcx>( if !nll_errors.is_empty() { // Suppress unhelpful extra errors in `infer_opaque_types`. - infcx.set_tainted_by_errors(); + infcx.set_tainted_by_errors(infcx.tcx.sess.delay_span_bug( + body.span, + "`compute_regions` tainted `infcx` with errors but did not emit any errors", + )); } let remapped_opaque_tys = regioncx.infer_opaque_types(&infcx, opaque_type_values); diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 16c40cf1299cb..83b95fe0e911e 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -115,7 +115,7 @@ pub trait AstConv<'tcx> { /// (e.g., resolve) that is translated into a ty-error. This is /// used to help suppress derived errors typeck might otherwise /// report. - fn set_tainted_by_errors(&self); + fn set_tainted_by_errors(&self, e: ErrorGuaranteed); fn record_ty(&self, hir_id: hir::HirId, ty: Ty<'tcx>, span: Span); } @@ -2620,8 +2620,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } } Res::Err => { - self.set_tainted_by_errors(); - self.tcx().ty_error() + let e = self + .tcx() + .sess + .delay_span_bug(path.span, "path with `Res:Err` but no error emitted"); + self.set_tainted_by_errors(e); + self.tcx().ty_error_with_guaranteed(e) } _ => span_bug!(span, "unexpected resolution: {:?}", path.res), } diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 2f64a88f03afe..a738ee4a14887 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -518,7 +518,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> { ty } - fn set_tainted_by_errors(&self) { + fn set_tainted_by_errors(&self, _: ErrorGuaranteed) { // There's no obvious place to track this, so just let it go. } diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 174b43313825e..fc05cbf276e0e 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -1544,7 +1544,9 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { // Mark that we've failed to coerce the types here to suppress // any superfluous errors we might encounter while trying to // emit or provide suggestions on how to fix the initial error. - fcx.set_tainted_by_errors(); + fcx.set_tainted_by_errors( + fcx.tcx.sess.delay_span_bug(cause.span, "coercion error but no error emitted"), + ); let (expected, found) = if label_expression_as_expected { // In the case where this is a "forced unit", like // `break`, we want to call the `()` "expected" diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index 9ca7730daa68d..5a34ab401749f 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -154,7 +154,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Err(e) => e, }; - self.set_tainted_by_errors(); + self.set_tainted_by_errors(self.tcx.sess.delay_span_bug( + expr.span, + "`TypeError` when attempting coercion but no error emitted", + )); let expr = expr.peel_drop_temps(); let cause = self.misc(expr.span); let expr_ty = self.resolve_vars_with_obligations(checked_ty); diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 13a03b33de815..752d2e0ff7858 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -527,12 +527,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.resolve_ty_and_res_fully_qualified_call(qpath, expr.hir_id, expr.span); let ty = match res { Res::Err => { - self.set_tainted_by_errors(); - tcx.ty_error() + let e = + self.tcx.sess.delay_span_bug(qpath.span(), "`Res::Err` but no error emitted"); + self.set_tainted_by_errors(e); + tcx.ty_error_with_guaranteed(e) } Res::Def(DefKind::Ctor(_, CtorKind::Fictive), _) => { - report_unexpected_variant_res(tcx, res, qpath, expr.span); - tcx.ty_error() + let e = report_unexpected_variant_res(tcx, res, qpath, expr.span); + tcx.ty_error_with_guaranteed(e) } _ => self.instantiate_value_path(segs, opt_ty, res, expr.span, expr.hir_id).0, }; @@ -1962,7 +1964,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expr_span: Span, ) { if variant.is_recovered() { - self.set_tainted_by_errors(); + self.set_tainted_by_errors( + self.tcx + .sess + .delay_span_bug(expr_span, "parser recovered but no error was emitted"), + ); return; } let mut err = self.err_ctxt().type_error_struct_with_diag( diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 0d9189b12f6fd..c2a5c5b6c1b3c 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -140,8 +140,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { debug!("write_ty({:?}, {:?}) in fcx {}", id, self.resolve_vars_if_possible(ty), self.tag()); self.typeck_results.borrow_mut().node_types_mut().insert(id, ty); - if ty.references_error() { - self.set_tainted_by_errors(); + if let Err(e) = ty.error_reported() { + self.set_tainted_by_errors(e); } } @@ -1148,9 +1148,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { explicit_late_bound = ExplicitLateBound::Yes; } - if let Err(GenericArgCountMismatch { reported: Some(_), .. }) = arg_count.correct { + if let Err(GenericArgCountMismatch { reported: Some(e), .. }) = arg_count.correct { infer_args_for_err.insert(index); - self.set_tainted_by_errors(); // See issue #53251. + self.set_tainted_by_errors(e); // See issue #53251. } } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 6847b03f431db..91063b43d6161 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -512,8 +512,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { tys.into_iter().any(|ty| ty.references_error() || ty.is_ty_var()) } - self.set_tainted_by_errors(); let tcx = self.tcx; + // FIXME: taint after emitting errors and pass through an `ErrorGuaranteed` + self.set_tainted_by_errors( + tcx.sess.delay_span_bug(call_span, "no errors reported for args"), + ); // Get the argument span in the context of the call span so that // suggestions and labels are (more) correct when an arg is a @@ -1208,7 +1211,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let (def, ty) = self.finish_resolving_struct_path(qpath, path_span, hir_id); let variant = match def { Res::Err => { - self.set_tainted_by_errors(); + self.set_tainted_by_errors( + self.tcx.sess.delay_span_bug(path_span, "`Res::Err` but no error emitted"), + ); return None; } Res::Def(DefKind::Variant, _) => match ty.kind() { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs index d5e4b6de581c3..177d521d2804c 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs @@ -4,6 +4,7 @@ mod checks; mod suggestions; pub use _impl::*; +use rustc_errors::ErrorGuaranteed; pub use suggestions::*; use crate::coercion::DynamicCoerceMany; @@ -289,8 +290,8 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { } } - fn set_tainted_by_errors(&self) { - self.infcx.set_tainted_by_errors() + fn set_tainted_by_errors(&self, e: ErrorGuaranteed) { + self.infcx.set_tainted_by_errors(e) } fn record_ty(&self, hir_id: hir::HirId, ty: Ty<'tcx>, _span: Span) { diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 51cc2e7882de1..334d6d0aa6c20 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -53,7 +53,7 @@ use crate::check::check_fn; use crate::coercion::DynamicCoerceMany; use crate::gather_locals::GatherLocalsVisitor; use rustc_data_structures::unord::UnordSet; -use rustc_errors::{struct_span_err, MultiSpan}; +use rustc_errors::{struct_span_err, ErrorGuaranteed, MultiSpan}; use rustc_hir as hir; use rustc_hir::def::Res; use rustc_hir::intravisit::Visitor; @@ -428,7 +428,12 @@ impl<'tcx> EnclosingBreakables<'tcx> { } } -fn report_unexpected_variant_res(tcx: TyCtxt<'_>, res: Res, qpath: &hir::QPath<'_>, span: Span) { +fn report_unexpected_variant_res( + tcx: TyCtxt<'_>, + res: Res, + qpath: &hir::QPath<'_>, + span: Span, +) -> ErrorGuaranteed { struct_span_err!( tcx.sess, span, @@ -437,7 +442,7 @@ fn report_unexpected_variant_res(tcx: TyCtxt<'_>, res: Res, qpath: &hir::QPath<' res.descr(), rustc_hir_pretty::qpath_to_string(qpath), ) - .emit(); + .emit() } /// Controls whether the arguments are tupled. This is used for the call diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index eb10f3e2c107f..a62d43561302b 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -839,12 +839,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let (res, opt_ty, segments) = path_resolution; match res { Res::Err => { - self.set_tainted_by_errors(); - return tcx.ty_error(); + let e = tcx.sess.delay_span_bug(qpath.span(), "`Res::Err` but no error emitted"); + self.set_tainted_by_errors(e); + return tcx.ty_error_with_guaranteed(e); } Res::Def(DefKind::AssocFn | DefKind::Ctor(_, CtorKind::Fictive | CtorKind::Fn), _) => { - report_unexpected_variant_res(tcx, res, qpath, pat.span); - return tcx.ty_error(); + let e = report_unexpected_variant_res(tcx, res, qpath, pat.span); + return tcx.ty_error_with_guaranteed(e); } Res::SelfCtor(..) | Res::Def( @@ -985,9 +986,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ti: TopInfo<'tcx>, ) -> Ty<'tcx> { let tcx = self.tcx; - let on_error = || { + let on_error = |e| { for pat in subpats { - self.check_pat(pat, tcx.ty_error(), def_bm, ti); + self.check_pat(pat, tcx.ty_error_with_guaranteed(e), def_bm, ti); } }; let report_unexpected_res = |res: Res| { @@ -1014,36 +1015,39 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err.span_label(pat.span, "not a tuple variant or struct"); } } - err.emit(); - on_error(); + let e = err.emit(); + on_error(e); + e }; // Resolve the path and check the definition for errors. let (res, opt_ty, segments) = self.resolve_ty_and_res_fully_qualified_call(qpath, pat.hir_id, pat.span); if res == Res::Err { - self.set_tainted_by_errors(); - on_error(); - return self.tcx.ty_error(); + let e = tcx.sess.delay_span_bug(pat.span, "`Res:Err` but no error emitted"); + self.set_tainted_by_errors(e); + on_error(e); + return tcx.ty_error_with_guaranteed(e); } // Type-check the path. let (pat_ty, res) = self.instantiate_value_path(segments, opt_ty, res, pat.span, pat.hir_id); if !pat_ty.is_fn() { - report_unexpected_res(res); - return tcx.ty_error(); + let e = report_unexpected_res(res); + return tcx.ty_error_with_guaranteed(e); } let variant = match res { Res::Err => { - self.set_tainted_by_errors(); - on_error(); - return tcx.ty_error(); + let e = tcx.sess.delay_span_bug(pat.span, "`Res::Err` but no error emitted"); + self.set_tainted_by_errors(e); + on_error(e); + return tcx.ty_error_with_guaranteed(e); } Res::Def(DefKind::AssocConst | DefKind::AssocFn, _) => { - report_unexpected_res(res); - return tcx.ty_error(); + let e = report_unexpected_res(res); + return tcx.ty_error_with_guaranteed(e); } Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) => tcx.expect_variant_res(res), _ => bug!("unexpected pattern resolution: {:?}", res), @@ -1082,9 +1086,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } else { // Pattern has wrong number of fields. - self.e0023(pat.span, res, qpath, subpats, &variant.fields, expected, had_err); - on_error(); - return tcx.ty_error(); + let e = self.e0023(pat.span, res, qpath, subpats, &variant.fields, expected, had_err); + on_error(e); + return tcx.ty_error_with_guaranteed(e); } pat_ty } @@ -1098,7 +1102,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fields: &'tcx [ty::FieldDef], expected: Ty<'tcx>, had_err: bool, - ) { + ) -> ErrorGuaranteed { let subpats_ending = pluralize!(subpats.len()); let fields_ending = pluralize!(fields.len()); @@ -1245,7 +1249,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - err.emit(); + err.emit() } fn check_pat_tuple( diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index aa6fed136110b..b9ed6b28c220d 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -34,7 +34,7 @@ pub use rustc_middle::ty::IntVarValue; use rustc_middle::ty::{self, GenericParamDefKind, InferConst, Ty, TyCtxt}; use rustc_middle::ty::{ConstVid, FloatVid, IntVid, TyVid}; use rustc_span::symbol::Symbol; -use rustc_span::{Span, DUMMY_SP}; +use rustc_span::Span; use std::cell::{Cell, RefCell}; use std::fmt; @@ -1224,8 +1224,9 @@ impl<'tcx> InferCtxt<'tcx> { if self.tcx.sess.err_count() > self.err_count_on_creation { // errors reported since this infcx was made - self.set_tainted_by_errors(); - return self.tainted_by_errors.get(); + let e = self.tcx.sess.has_errors().unwrap(); + self.set_tainted_by_errors(e); + return Some(e); } None @@ -1233,11 +1234,9 @@ impl<'tcx> InferCtxt<'tcx> { /// Set the "tainted by errors" flag to true. We call this when we /// observe an error from a prior pass. - pub fn set_tainted_by_errors(&self) { - debug!("set_tainted_by_errors()"); - self.tainted_by_errors.set(Some( - self.tcx.sess.delay_span_bug(DUMMY_SP, "`InferCtxt` incorrectly tainted by errors"), - )); + pub fn set_tainted_by_errors(&self, e: ErrorGuaranteed) { + debug!("set_tainted_by_errors(ErrorGuaranteed)"); + self.tainted_by_errors.set(Some(e)); } pub fn skip_region_resolution(&self) { diff --git a/compiler/rustc_infer/src/infer/sub.rs b/compiler/rustc_infer/src/infer/sub.rs index 8c8445a4d9eb8..bd3c5780b891b 100644 --- a/compiler/rustc_infer/src/infer/sub.rs +++ b/compiler/rustc_infer/src/infer/sub.rs @@ -116,9 +116,9 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> { Ok(a) } - (&ty::Error(_), _) | (_, &ty::Error(_)) => { - infcx.set_tainted_by_errors(); - Ok(self.tcx().ty_error()) + (&ty::Error(e), _) | (_, &ty::Error(e)) => { + infcx.set_tainted_by_errors(e); + Ok(self.tcx().ty_error_with_guaranteed(e)) } (&ty::Opaque(a_def_id, _), &ty::Opaque(b_def_id, _)) if a_def_id == b_def_id => { diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index b84a1c447fffc..ad0785d3817e1 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -532,9 +532,12 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { root_obligation: &PredicateObligation<'tcx>, error: &SelectionError<'tcx>, ) { - self.set_tainted_by_errors(); let tcx = self.tcx; let mut span = obligation.cause.span; + // FIXME: statically guarantee this by tainting after the diagnostic is emitted + self.set_tainted_by_errors( + tcx.sess.delay_span_bug(span, "`report_selection_error` did not emit an error"), + ); let mut err = match *error { SelectionError::Unimplemented => { From 45a09a4683f551d96f7e5b16a125c26003beffaf Mon Sep 17 00:00:00 2001 From: Boxy Date: Fri, 18 Nov 2022 13:45:42 +0000 Subject: [PATCH 056/103] review comments 2 electric boogalo --- compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs | 8 ++++---- compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index c2a5c5b6c1b3c..b85a23257286b 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -1440,12 +1440,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if !ty.is_ty_var() { ty } else { - if let None = self.tainted_by_errors() { + let e = self.tainted_by_errors().unwrap_or_else(|| { self.err_ctxt() .emit_inference_failure_err((**self).body_id, sp, ty.into(), E0282, true) - .emit(); - } - let err = self.tcx.ty_error(); + .emit() + }); + let err = self.tcx.ty_error_with_guaranteed(e); self.demand_suptype(sp, err, ty); err } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 91063b43d6161..a31ab9c8b23b8 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -73,7 +73,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ty = self.typeck_results.borrow().expr_ty_adjusted(expr); let ty = self.resolve_vars_if_possible(ty); if ty.has_non_region_infer() { - assert!(self.tainted_by_errors().is_some()); self.tcx.ty_error() } else { self.tcx.erase_regions(ty) From 4e504c712d67077173e28f0a1b0ecef4d6cdd31d Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 18 Nov 2022 14:51:24 +0100 Subject: [PATCH 057/103] deduplicate tests --- src/test/ui/coherence/issue-100191-2.rs | 12 ----------- src/test/ui/coherence/issue-100191.rs | 21 ------------------- ...3037.stderr => issue-43037.current.stderr} | 2 +- .../issue-43037.negative.stderr} | 2 +- src/test/ui/specialization/issue-43037.rs | 2 ++ ...5814.stderr => issue-45814.current.stderr} | 2 +- .../issue-45814.negative.stderr} | 4 ++-- src/test/ui/specialization/issue-45814.rs | 3 ++- 8 files changed, 9 insertions(+), 39 deletions(-) delete mode 100644 src/test/ui/coherence/issue-100191-2.rs delete mode 100644 src/test/ui/coherence/issue-100191.rs rename src/test/ui/specialization/{issue-43037.stderr => issue-43037.current.stderr} (94%) rename src/test/ui/{coherence/issue-100191.stderr => specialization/issue-43037.negative.stderr} (94%) rename src/test/ui/specialization/{issue-45814.stderr => issue-45814.current.stderr} (94%) rename src/test/ui/{coherence/issue-100191-2.stderr => specialization/issue-45814.negative.stderr} (81%) diff --git a/src/test/ui/coherence/issue-100191-2.rs b/src/test/ui/coherence/issue-100191-2.rs deleted file mode 100644 index 1c8316f87fa07..0000000000000 --- a/src/test/ui/coherence/issue-100191-2.rs +++ /dev/null @@ -1,12 +0,0 @@ -//~ ERROR overflow evaluating the requirement `T: Trait<_>` - -#![feature(specialization, with_negative_coherence)] -#![allow(incomplete_features)] - -pub trait Trait {} - -default impl Trait for U {} - -impl Trait<::Item> for T {} - -fn main() {} diff --git a/src/test/ui/coherence/issue-100191.rs b/src/test/ui/coherence/issue-100191.rs deleted file mode 100644 index e8597fde54d3b..0000000000000 --- a/src/test/ui/coherence/issue-100191.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![crate_type = "lib"] -#![feature(specialization, with_negative_coherence)] -#![allow(incomplete_features)] - -trait X {} -trait Y: X {} -trait Z { - type Assoc: Y; -} -struct A(T); - -impl Y for T where T: X {} -impl Z for A { - type Assoc = T; -} - -// this impl is invalid, but causes an ICE anyway -impl From< as Z>::Assoc> for T {} -//~^ ERROR type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) - -fn main() {} diff --git a/src/test/ui/specialization/issue-43037.stderr b/src/test/ui/specialization/issue-43037.current.stderr similarity index 94% rename from src/test/ui/specialization/issue-43037.stderr rename to src/test/ui/specialization/issue-43037.current.stderr index 4249cd8947716..26db9d7c99749 100644 --- a/src/test/ui/specialization/issue-43037.stderr +++ b/src/test/ui/specialization/issue-43037.current.stderr @@ -1,5 +1,5 @@ error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/issue-43037.rs:17:6 + --> $DIR/issue-43037.rs:19:6 | LL | impl From< as Z>::Assoc> for T {} | ^ type parameter `T` must be used as the type parameter for some local type diff --git a/src/test/ui/coherence/issue-100191.stderr b/src/test/ui/specialization/issue-43037.negative.stderr similarity index 94% rename from src/test/ui/coherence/issue-100191.stderr rename to src/test/ui/specialization/issue-43037.negative.stderr index 1adb0f1e4fa7b..26db9d7c99749 100644 --- a/src/test/ui/coherence/issue-100191.stderr +++ b/src/test/ui/specialization/issue-43037.negative.stderr @@ -1,5 +1,5 @@ error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/issue-100191.rs:18:6 + --> $DIR/issue-43037.rs:19:6 | LL | impl From< as Z>::Assoc> for T {} | ^ type parameter `T` must be used as the type parameter for some local type diff --git a/src/test/ui/specialization/issue-43037.rs b/src/test/ui/specialization/issue-43037.rs index c49119f9c095b..a1e3f998b2370 100644 --- a/src/test/ui/specialization/issue-43037.rs +++ b/src/test/ui/specialization/issue-43037.rs @@ -1,4 +1,6 @@ +// revisions: current negative #![feature(specialization)] +#![cfg_attr(negative, feature(with_negative_coherence))] #![allow(incomplete_features)] trait X {} diff --git a/src/test/ui/specialization/issue-45814.stderr b/src/test/ui/specialization/issue-45814.current.stderr similarity index 94% rename from src/test/ui/specialization/issue-45814.stderr rename to src/test/ui/specialization/issue-45814.current.stderr index 419345addc2fc..5013559b80ea9 100644 --- a/src/test/ui/specialization/issue-45814.stderr +++ b/src/test/ui/specialization/issue-45814.current.stderr @@ -2,7 +2,7 @@ error[E0275]: overflow evaluating the requirement `T: Trait<_>` | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_45814`) note: required for `T` to implement `Trait<_>` - --> $DIR/issue-45814.rs:8:20 + --> $DIR/issue-45814.rs:9:20 | LL | default impl Trait for U {} | ^^^^^^^^ ^ diff --git a/src/test/ui/coherence/issue-100191-2.stderr b/src/test/ui/specialization/issue-45814.negative.stderr similarity index 81% rename from src/test/ui/coherence/issue-100191-2.stderr rename to src/test/ui/specialization/issue-45814.negative.stderr index d50c220bcfd48..5013559b80ea9 100644 --- a/src/test/ui/coherence/issue-100191-2.stderr +++ b/src/test/ui/specialization/issue-45814.negative.stderr @@ -1,8 +1,8 @@ error[E0275]: overflow evaluating the requirement `T: Trait<_>` | - = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_100191_2`) + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_45814`) note: required for `T` to implement `Trait<_>` - --> $DIR/issue-100191-2.rs:8:20 + --> $DIR/issue-45814.rs:9:20 | LL | default impl Trait for U {} | ^^^^^^^^ ^ diff --git a/src/test/ui/specialization/issue-45814.rs b/src/test/ui/specialization/issue-45814.rs index 8ee5d3e2e58da..fce236390c2b0 100644 --- a/src/test/ui/specialization/issue-45814.rs +++ b/src/test/ui/specialization/issue-45814.rs @@ -1,6 +1,7 @@ //~ ERROR overflow evaluating the requirement `T: Trait<_>` - +// revisions: current negative #![feature(specialization)] +#![cfg_attr(negative, feature(with_negative_coherence))] #![allow(incomplete_features)] pub trait Trait {} From d49c10ac62c6f781b05bb2136b63bdf7a4608439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 15 Nov 2022 17:38:39 -0800 Subject: [PATCH 058/103] Make "long type" printing type aware Instead of simple string cutting, use a custom printer to hide parts of long printed types. --- compiler/rustc_middle/src/ty/instance.rs | 57 ++++++++++++------- compiler/rustc_middle/src/ty/mod.rs | 2 +- compiler/rustc_middle/src/ty/print/pretty.rs | 19 ++++++- compiler/rustc_monomorphize/src/collector.rs | 23 +++----- .../ui/infinite/infinite-instantiation.stderr | 2 +- src/test/ui/issues/issue-22638.stderr | 1 - .../issue-37311.stderr | 2 +- src/test/ui/issues/issue-67552.stderr | 2 +- src/test/ui/issues/issue-8727.stderr | 2 +- src/test/ui/recursion/recursion.stderr | 2 +- src/test/ui/type_length_limit.rs | 11 +++- src/test/ui/type_length_limit.stderr | 15 +---- 12 files changed, 78 insertions(+), 60 deletions(-) diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index ae0f158ede99a..a792d2694b3b9 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -276,28 +276,45 @@ impl<'tcx> InstanceDef<'tcx> { } } -impl<'tcx> fmt::Display for Instance<'tcx> { +fn fmt_instance( + f: &mut fmt::Formatter<'_>, + instance: &Instance<'_>, + type_length: rustc_session::Limit, +) -> fmt::Result { + ty::tls::with(|tcx| { + let substs = tcx.lift(instance.substs).expect("could not lift for printing"); + + let s = FmtPrinter::new_with_limit(tcx, Namespace::ValueNS, type_length) + .print_def_path(instance.def_id(), substs)? + .into_buffer(); + f.write_str(&s) + })?; + + match instance.def { + InstanceDef::Item(_) => Ok(()), + InstanceDef::VTableShim(_) => write!(f, " - shim(vtable)"), + InstanceDef::ReifyShim(_) => write!(f, " - shim(reify)"), + InstanceDef::Intrinsic(_) => write!(f, " - intrinsic"), + InstanceDef::Virtual(_, num) => write!(f, " - virtual#{}", num), + InstanceDef::FnPtrShim(_, ty) => write!(f, " - shim({})", ty), + InstanceDef::ClosureOnceShim { .. } => write!(f, " - shim"), + InstanceDef::DropGlue(_, None) => write!(f, " - shim(None)"), + InstanceDef::DropGlue(_, Some(ty)) => write!(f, " - shim(Some({}))", ty), + InstanceDef::CloneShim(_, ty) => write!(f, " - shim({})", ty), + } +} + +pub struct ShortInstance<'a, 'tcx>(pub &'a Instance<'tcx>, pub usize); + +impl<'a, 'tcx> fmt::Display for ShortInstance<'a, 'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - ty::tls::with(|tcx| { - let substs = tcx.lift(self.substs).expect("could not lift for printing"); - let s = FmtPrinter::new(tcx, Namespace::ValueNS) - .print_def_path(self.def_id(), substs)? - .into_buffer(); - f.write_str(&s) - })?; + fmt_instance(f, self.0, rustc_session::Limit(self.1)) + } +} - match self.def { - InstanceDef::Item(_) => Ok(()), - InstanceDef::VTableShim(_) => write!(f, " - shim(vtable)"), - InstanceDef::ReifyShim(_) => write!(f, " - shim(reify)"), - InstanceDef::Intrinsic(_) => write!(f, " - intrinsic"), - InstanceDef::Virtual(_, num) => write!(f, " - virtual#{}", num), - InstanceDef::FnPtrShim(_, ty) => write!(f, " - shim({})", ty), - InstanceDef::ClosureOnceShim { .. } => write!(f, " - shim"), - InstanceDef::DropGlue(_, None) => write!(f, " - shim(None)"), - InstanceDef::DropGlue(_, Some(ty)) => write!(f, " - shim(Some({}))", ty), - InstanceDef::CloneShim(_, ty) => write!(f, " - shim({})", ty), - } +impl<'tcx> fmt::Display for Instance<'tcx> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + ty::tls::with(|tcx| fmt_instance(f, self, tcx.type_length_limit())) } } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index f9a762261e2ce..a770c6a2e99be 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -84,7 +84,7 @@ pub use self::context::{ GeneratorInteriorTypeCause, GlobalCtxt, Lift, OnDiskCache, TyCtxt, TypeckResults, UserType, UserTypeAnnotationIndex, }; -pub use self::instance::{Instance, InstanceDef}; +pub use self::instance::{Instance, InstanceDef, ShortInstance}; pub use self::list::List; pub use self::parameterized::ParameterizedOverTcx; pub use self::rvalue_scopes::RvalueScopes; diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 48e803597b02e..faa57b437d947 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -13,6 +13,7 @@ use rustc_hir::def_id::{DefId, DefIdSet, CRATE_DEF_ID, LOCAL_CRATE}; use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData}; use rustc_session::config::TrimmedDefPaths; use rustc_session::cstore::{ExternCrate, ExternCrateSource}; +use rustc_session::Limit; use rustc_span::symbol::{kw, Ident, Symbol}; use rustc_target::abi::Size; use rustc_target::spec::abi::Abi; @@ -1583,6 +1584,8 @@ pub struct FmtPrinterData<'a, 'tcx> { region_index: usize, binder_depth: usize, printed_type_count: usize, + type_length_limit: Limit, + truncated: bool, pub region_highlight_mode: RegionHighlightMode<'tcx>, @@ -1605,6 +1608,10 @@ impl DerefMut for FmtPrinter<'_, '_> { impl<'a, 'tcx> FmtPrinter<'a, 'tcx> { pub fn new(tcx: TyCtxt<'tcx>, ns: Namespace) -> Self { + Self::new_with_limit(tcx, ns, tcx.type_length_limit()) + } + + pub fn new_with_limit(tcx: TyCtxt<'tcx>, ns: Namespace, type_length_limit: Limit) -> Self { FmtPrinter(Box::new(FmtPrinterData { tcx, // Estimated reasonable capacity to allocate upfront based on a few @@ -1617,6 +1624,8 @@ impl<'a, 'tcx> FmtPrinter<'a, 'tcx> { region_index: 0, binder_depth: 0, printed_type_count: 0, + type_length_limit, + truncated: false, region_highlight_mode: RegionHighlightMode::new(tcx), ty_infer_name_resolver: None, const_infer_name_resolver: None, @@ -1751,12 +1760,16 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> { } fn print_type(mut self, ty: Ty<'tcx>) -> Result { - let type_length_limit = self.tcx.type_length_limit(); - if type_length_limit.value_within_limit(self.printed_type_count) { + if self.type_length_limit.value_within_limit(self.printed_type_count) { self.printed_type_count += 1; self.pretty_print_type(ty) } else { - write!(self, "...")?; + self.truncated = true; + if let ty::Adt(_, substs) = ty.kind() && substs.len() > 0 { + write!(self, "...")?; + } else { + write!(self, "_")?; + } Ok(self) } } diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index cdf8011d4f5ab..d74893bf0f0e3 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -197,7 +197,6 @@ use rustc_session::lint::builtin::LARGE_ASSIGNMENTS; use rustc_session::Limit; use rustc_span::source_map::{dummy_spanned, respan, Span, Spanned, DUMMY_SP}; use rustc_target::abi::Size; -use std::iter; use std::ops::Range; use std::path::PathBuf; @@ -541,29 +540,23 @@ fn collect_items_rec<'tcx>( } /// Format instance name that is already known to be too long for rustc. -/// Show only the first and last 32 characters to avoid blasting +/// Show only the first 2 types if it is longer than 32 characters to avoid blasting /// the user's terminal with thousands of lines of type-name. /// /// If the type name is longer than before+after, it will be written to a file. fn shrunk_instance_name<'tcx>( tcx: TyCtxt<'tcx>, instance: &Instance<'tcx>, - before: usize, - after: usize, ) -> (String, Option) { let s = instance.to_string(); // Only use the shrunk version if it's really shorter. // This also avoids the case where before and after slices overlap. - if s.chars().nth(before + after + 1).is_some() { - // An iterator of all byte positions including the end of the string. - let positions = || s.char_indices().map(|(i, _)| i).chain(iter::once(s.len())); - - let shrunk = format!( - "{before}...{after}", - before = &s[..positions().nth(before).unwrap_or(s.len())], - after = &s[positions().rev().nth(after).unwrap_or(0)..], - ); + if s.chars().nth(33).is_some() { + let shrunk = format!("{}", ty::ShortInstance(instance, 4)); + if shrunk == s { + return (s, None); + } let path = tcx.output_filenames(()).temp_path_ext("long-type.txt", None); let written_to_path = std::fs::write(&path, s).ok().map(|_| path); @@ -599,7 +592,7 @@ fn check_recursion_limit<'tcx>( if !recursion_limit.value_within_limit(adjusted_recursion_depth) { let def_span = tcx.def_span(def_id); let def_path_str = tcx.def_path_str(def_id); - let (shrunk, written_to_path) = shrunk_instance_name(tcx, &instance, 32, 32); + let (shrunk, written_to_path) = shrunk_instance_name(tcx, &instance); let mut path = PathBuf::new(); let was_written = if written_to_path.is_some() { path = written_to_path.unwrap(); @@ -641,7 +634,7 @@ fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) { // // Bail out in these cases to avoid that bad user experience. if !tcx.type_length_limit().value_within_limit(type_length) { - let (shrunk, written_to_path) = shrunk_instance_name(tcx, &instance, 32, 32); + let (shrunk, written_to_path) = shrunk_instance_name(tcx, &instance); let span = tcx.def_span(instance.def_id()); let mut path = PathBuf::new(); let was_written = if written_to_path.is_some() { diff --git a/src/test/ui/infinite/infinite-instantiation.stderr b/src/test/ui/infinite/infinite-instantiation.stderr index 52f5781349e16..951e0f5870d7d 100644 --- a/src/test/ui/infinite/infinite-instantiation.stderr +++ b/src/test/ui/infinite/infinite-instantiation.stderr @@ -1,4 +1,4 @@ -error: reached the recursion limit while instantiating `function::>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` +error: reached the recursion limit while instantiating `function::>>>>>` --> $DIR/infinite-instantiation.rs:22:9 | LL | function(counter - 1, t.to_option()); diff --git a/src/test/ui/issues/issue-22638.stderr b/src/test/ui/issues/issue-22638.stderr index 1354ec8e899c0..1caa4221f2501 100644 --- a/src/test/ui/issues/issue-22638.stderr +++ b/src/test/ui/issues/issue-22638.stderr @@ -9,7 +9,6 @@ note: `A::matches` defined here | LL | pub fn matches(&self, f: &F) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-22638/issue-22638.long-type.txt' error: aborting due to previous error diff --git a/src/test/ui/issues/issue-37311-type-length-limit/issue-37311.stderr b/src/test/ui/issues/issue-37311-type-length-limit/issue-37311.stderr index 93aeb89469d4a..6ce4c498f152a 100644 --- a/src/test/ui/issues/issue-37311-type-length-limit/issue-37311.stderr +++ b/src/test/ui/issues/issue-37311-type-length-limit/issue-37311.stderr @@ -1,4 +1,4 @@ -error: reached the recursion limit while instantiating `<(&(&(&(&(&(&(&(&(&(&(&(&(&(&(&(.....), ...), ...) as Foo>::recurse` +error: reached the recursion limit while instantiating `<(&(&(_, _), _), _) as Foo>::recurse` --> $DIR/issue-37311.rs:17:9 | LL | (self, self).recurse(); diff --git a/src/test/ui/issues/issue-67552.stderr b/src/test/ui/issues/issue-67552.stderr index 2968be7c71fb5..c19c26587b983 100644 --- a/src/test/ui/issues/issue-67552.stderr +++ b/src/test/ui/issues/issue-67552.stderr @@ -1,4 +1,4 @@ -error: reached the recursion limit while instantiating `rec::<&mut &mut &mut &mut &mut &... &mut &mut &mut &mut &mut Empty>` +error: reached the recursion limit while instantiating `rec::<&mut &mut &mut &mut &mut _>` --> $DIR/issue-67552.rs:29:9 | LL | rec(identity(&mut it)) diff --git a/src/test/ui/issues/issue-8727.stderr b/src/test/ui/issues/issue-8727.stderr index 5e1fdad60cb8a..22332b357231b 100644 --- a/src/test/ui/issues/issue-8727.stderr +++ b/src/test/ui/issues/issue-8727.stderr @@ -9,7 +9,7 @@ LL | generic::>(); = help: a `loop` may express intention better if this is on purpose = note: `#[warn(unconditional_recursion)]` on by default -error: reached the recursion limit while instantiating `generic::>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` +error: reached the recursion limit while instantiating `generic::>>>>>` --> $DIR/issue-8727.rs:8:5 | LL | generic::>(); diff --git a/src/test/ui/recursion/recursion.stderr b/src/test/ui/recursion/recursion.stderr index d2844d0e6d9f0..cf08095372b07 100644 --- a/src/test/ui/recursion/recursion.stderr +++ b/src/test/ui/recursion/recursion.stderr @@ -1,4 +1,4 @@ -error: reached the recursion limit while instantiating `test::>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` +error: reached the recursion limit while instantiating `test::>>>>>` --> $DIR/recursion.rs:18:11 | LL | _ => {test (n-1, i+1, Cons {head:2*i+1, tail:first}, Cons{head:i*i, tail:second})} diff --git a/src/test/ui/type_length_limit.rs b/src/test/ui/type_length_limit.rs index ce6fdf811213f..b3c12747414ed 100644 --- a/src/test/ui/type_length_limit.rs +++ b/src/test/ui/type_length_limit.rs @@ -7,7 +7,7 @@ // The exact type depends on optimizations, so disable them. #![allow(dead_code)] -#![type_length_limit="4"] +#![type_length_limit="8"] macro_rules! link { ($id:ident, $t:ty) => { @@ -15,14 +15,19 @@ macro_rules! link { } } +link! { A1, B1 } +link! { B1, C1 } +link! { C1, D1 } +link! { D1, E1 } +link! { E1, A } link! { A, B } link! { B, C } link! { C, D } link! { D, E } link! { E, F } -link! { F, G } +link! { F, G, Option> } -pub struct G; +pub struct G(std::marker::PhantomData::<(T, K)>); fn main() { drop::>(None); diff --git a/src/test/ui/type_length_limit.stderr b/src/test/ui/type_length_limit.stderr index 84ac48b1e77b4..10ada6760ebe8 100644 --- a/src/test/ui/type_length_limit.stderr +++ b/src/test/ui/type_length_limit.stderr @@ -1,20 +1,11 @@ -error: reached the type-length limit while instantiating `std::mem::drop::>` +error: reached the type-length limit while instantiating `std::mem::drop::>` --> $SRC_DIR/core/src/mem/mod.rs:LL:COL | LL | pub fn drop(_x: T) {} | ^^^^^^^^^^^^^^^^^^^^^ | - = help: consider adding a `#![type_length_limit="8"]` attribute to your crate + = help: consider adding a `#![type_length_limit="10"]` attribute to your crate = note: the full type name has been written to '$TEST_BUILD_DIR/type_length_limit/type_length_limit.long-type.txt' -error: reached the type-length limit while instantiating `<[closure@std::rt::lang_start<()...e<()>>::call_once - shim(vtable)` - --> $SRC_DIR/core/src/ops/function.rs:LL:COL - | -LL | extern "rust-call" fn call_once(self, args: Args) -> Self::Output; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider adding a `#![type_length_limit="8"]` attribute to your crate - = note: the full type name has been written to '$TEST_BUILD_DIR/type_length_limit/type_length_limit.long-type.txt' - -error: aborting due to 2 previous errors +error: aborting due to previous error From 787e633d1ae4df5718450c1d2b721aa87a1b7d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 16 Nov 2022 19:09:57 -0800 Subject: [PATCH 059/103] On overflow errors, do not print out long types --- compiler/rustc_middle/src/ty/error.rs | 37 +++++++++++++++++++ .../src/traits/error_reporting/suggestions.rs | 28 ++++++++++++-- src/test/ui/error-codes/E0275.rs | 1 + src/test/ui/error-codes/E0275.stderr | 7 ++-- src/test/ui/issues/issue-20413.rs | 1 + src/test/ui/issues/issue-20413.stderr | 33 ++++++++++------- src/test/ui/recursion/issue-83150.rs | 3 +- src/test/ui/recursion/issue-83150.stderr | 7 ++-- .../traits/issue-91949-hangs-on-recursion.rs | 1 + .../issue-91949-hangs-on-recursion.stderr | 5 ++- 10 files changed, 96 insertions(+), 27 deletions(-) diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index dc13374f992eb..36261e7a1f374 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -12,7 +12,12 @@ use rustc_span::{BytePos, Span}; use rustc_target::spec::abi; use std::borrow::Cow; +use std::collections::hash_map::DefaultHasher; use std::fmt; +use std::hash::{Hash, Hasher}; +use std::path::PathBuf; + +use super::print::PrettyPrinter; #[derive(Clone, Copy, Debug, PartialEq, Eq, TypeFoldable, TypeVisitable, Lift)] pub struct ExpectedFound { @@ -985,6 +990,38 @@ fn foo(&self) -> Self::T { String::new() } false } + pub fn short_ty_string(self, ty: Ty<'tcx>) -> Result { + let length_limit = 50; + let type_limit = 4; + let regular = FmtPrinter::new(self, hir::def::Namespace::TypeNS) + .pretty_print_type(ty) + .expect("could not write to `String`") + .into_buffer(); + if regular.len() <= length_limit { + return Ok(regular); + } + let short = FmtPrinter::new_with_limit( + self, + hir::def::Namespace::TypeNS, + rustc_session::Limit(type_limit), + ) + .pretty_print_type(ty) + .expect("could not write to `String`") + .into_buffer(); + if regular == short { + return Ok(regular); + } + // Multiple types might be shortened in a single error, ensure we create a file for each. + let mut s = DefaultHasher::new(); + ty.hash(&mut s); + let hash = s.finish(); + let path = self.output_filenames(()).temp_path_ext(&format!("long-type-{hash}.txt"), None); + match std::fs::write(&path, ®ular) { + Ok(_) => Err((short, path)), + Err(_) => Ok(regular), + } + } + fn format_generic_args(self, args: &[ty::GenericArg<'tcx>]) -> String { FmtPrinter::new(self, hir::def::Namespace::TypeNS) .path_generic_args(Ok, args) diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index b8609077036f4..89a4136096773 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -2733,9 +2733,13 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { self.resolve_vars_if_possible(data.derived.parent_trait_pred); parent_trait_pred.remap_constness_diag(param_env); let parent_def_id = parent_trait_pred.def_id(); + let (self_ty, file) = + match self.tcx.short_ty_string(parent_trait_pred.skip_binder().self_ty()) { + Ok(self_ty) => (self_ty, None), + Err((self_ty, file)) => (self_ty, Some(file)), + }; let msg = format!( - "required for `{}` to implement `{}`", - parent_trait_pred.skip_binder().self_ty(), + "required for `{self_ty}` to implement `{}`", parent_trait_pred.print_modifiers_and_trait_path() ); let mut is_auto_trait = false; @@ -2764,6 +2768,12 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { _ => err.note(&msg), }; + if let Some(file) = file { + err.note(&format!( + "the full type name has been written to '{}'", + file.display(), + )); + } let mut parent_predicate = parent_trait_pred; let mut data = &data.derived; let mut count = 0; @@ -2804,11 +2814,21 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { count, pluralize!(count) )); + let (self_ty, file) = + match self.tcx.short_ty_string(parent_trait_pred.skip_binder().self_ty()) { + Ok(self_ty) => (self_ty, None), + Err((self_ty, file)) => (self_ty, Some(file)), + }; err.note(&format!( - "required for `{}` to implement `{}`", - parent_trait_pred.skip_binder().self_ty(), + "required for `{self_ty}` to implement `{}`", parent_trait_pred.print_modifiers_and_trait_path() )); + if let Some(file) = file { + err.note(&format!( + "the full type name has been written to '{}'", + file.display(), + )); + } } // #74711: avoid a stack overflow ensure_sufficient_stack(|| { diff --git a/src/test/ui/error-codes/E0275.rs b/src/test/ui/error-codes/E0275.rs index 28a9676f03e39..95d7f85f10546 100644 --- a/src/test/ui/error-codes/E0275.rs +++ b/src/test/ui/error-codes/E0275.rs @@ -1,3 +1,4 @@ +// normalize-stderr-test: "long-type-\d+" -> "long-type-hash" trait Foo {} struct Bar(T); diff --git a/src/test/ui/error-codes/E0275.stderr b/src/test/ui/error-codes/E0275.stderr index 87cfaa489c6aa..0cb54f2966621 100644 --- a/src/test/ui/error-codes/E0275.stderr +++ b/src/test/ui/error-codes/E0275.stderr @@ -1,15 +1,16 @@ error[E0275]: overflow evaluating the requirement `Bar>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>: Foo` - --> $DIR/E0275.rs:5:33 + --> $DIR/E0275.rs:6:33 | LL | impl Foo for T where Bar: Foo {} | ^^^ | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`E0275`) -note: required for `Bar>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` to implement `Foo` - --> $DIR/E0275.rs:5:9 +note: required for `Bar>>>>>` to implement `Foo` + --> $DIR/E0275.rs:6:9 | LL | impl Foo for T where Bar: Foo {} | ^^^ ^ + = note: the full type name has been written to '$TEST_BUILD_DIR/error-codes/E0275/E0275.long-type-hash.txt' = note: 127 redundant requirements hidden = note: required for `Bar` to implement `Foo` diff --git a/src/test/ui/issues/issue-20413.rs b/src/test/ui/issues/issue-20413.rs index 138a235e675e3..4de22f0c9177d 100644 --- a/src/test/ui/issues/issue-20413.rs +++ b/src/test/ui/issues/issue-20413.rs @@ -1,3 +1,4 @@ +// normalize-stderr-test: "long-type-\d+" -> "long-type-hash" trait Foo { fn answer(self); } diff --git a/src/test/ui/issues/issue-20413.stderr b/src/test/ui/issues/issue-20413.stderr index 2db60b641eea5..dbaaf7a7746e1 100644 --- a/src/test/ui/issues/issue-20413.stderr +++ b/src/test/ui/issues/issue-20413.stderr @@ -1,5 +1,5 @@ error[E0392]: parameter `T` is never used - --> $DIR/issue-20413.rs:5:15 + --> $DIR/issue-20413.rs:6:15 | LL | struct NoData; | ^ unused parameter @@ -8,57 +8,62 @@ LL | struct NoData; = help: if you intended `T` to be a const parameter, use `const T: usize` instead error[E0275]: overflow evaluating the requirement `NoData>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>: Foo` - --> $DIR/issue-20413.rs:8:36 + --> $DIR/issue-20413.rs:9:36 | LL | impl Foo for T where NoData: Foo { | ^^^ | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_20413`) -note: required for `NoData>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` to implement `Foo` - --> $DIR/issue-20413.rs:8:9 +note: required for `NoData>>>>>` to implement `Foo` + --> $DIR/issue-20413.rs:9:9 | LL | impl Foo for T where NoData: Foo { | ^^^ ^ + = note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-20413/issue-20413.long-type-hash.txt' = note: 127 redundant requirements hidden = note: required for `NoData` to implement `Foo` error[E0275]: overflow evaluating the requirement `EvenLessData>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>: Baz` - --> $DIR/issue-20413.rs:27:42 + --> $DIR/issue-20413.rs:28:42 | LL | impl Bar for T where EvenLessData: Baz { | ^^^ | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_20413`) -note: required for `AlmostNoData>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` to implement `Bar` - --> $DIR/issue-20413.rs:27:9 +note: required for `AlmostNoData>>>>>` to implement `Bar` + --> $DIR/issue-20413.rs:28:9 | LL | impl Bar for T where EvenLessData: Baz { | ^^^ ^ -note: required for `EvenLessData>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` to implement `Baz` - --> $DIR/issue-20413.rs:34:9 + = note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-20413/issue-20413.long-type-hash.txt' +note: required for `EvenLessData>>>>>` to implement `Baz` + --> $DIR/issue-20413.rs:35:9 | LL | impl Baz for T where AlmostNoData: Bar { | ^^^ ^ + = note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-20413/issue-20413.long-type-hash.txt' = note: 126 redundant requirements hidden = note: required for `EvenLessData` to implement `Baz` error[E0275]: overflow evaluating the requirement `AlmostNoData>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>: Bar` - --> $DIR/issue-20413.rs:34:42 + --> $DIR/issue-20413.rs:35:42 | LL | impl Baz for T where AlmostNoData: Bar { | ^^^ | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_20413`) -note: required for `EvenLessData>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` to implement `Baz` - --> $DIR/issue-20413.rs:34:9 +note: required for `EvenLessData>>>>>` to implement `Baz` + --> $DIR/issue-20413.rs:35:9 | LL | impl Baz for T where AlmostNoData: Bar { | ^^^ ^ -note: required for `AlmostNoData>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` to implement `Bar` - --> $DIR/issue-20413.rs:27:9 + = note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-20413/issue-20413.long-type-hash.txt' +note: required for `AlmostNoData>>>>>` to implement `Bar` + --> $DIR/issue-20413.rs:28:9 | LL | impl Bar for T where EvenLessData: Baz { | ^^^ ^ + = note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-20413/issue-20413.long-type-hash.txt' = note: 126 redundant requirements hidden = note: required for `AlmostNoData` to implement `Bar` diff --git a/src/test/ui/recursion/issue-83150.rs b/src/test/ui/recursion/issue-83150.rs index e647f0ff4fb8b..38353d161c133 100644 --- a/src/test/ui/recursion/issue-83150.rs +++ b/src/test/ui/recursion/issue-83150.rs @@ -1,6 +1,7 @@ // build-fail // compile-flags: -Copt-level=0 -//~^^ ERROR overflow evaluating the requirement +// normalize-stderr-test: "long-type-\d+" -> "long-type-hash" +//~^^^ ERROR overflow evaluating the requirement fn main() { let mut iter = 0u8..1; diff --git a/src/test/ui/recursion/issue-83150.stderr b/src/test/ui/recursion/issue-83150.stderr index 59fba5af00e12..98c17b1e2614b 100644 --- a/src/test/ui/recursion/issue-83150.stderr +++ b/src/test/ui/recursion/issue-83150.stderr @@ -1,5 +1,5 @@ warning: function cannot return without recursing - --> $DIR/issue-83150.rs:10:1 + --> $DIR/issue-83150.rs:11:1 | LL | fn func>(iter: &mut T) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing @@ -12,9 +12,10 @@ LL | func(&mut iter.map(|x| x + 1)) error[E0275]: overflow evaluating the requirement ` as Iterator>::Item` | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_83150`) - = note: required for `Map<&mut std::ops::Range, [closure@$DIR/issue-83150.rs:11:24: 11:27]>` to implement `Iterator` + = note: required for `Map<&mut std::ops::Range, [closure@$DIR/issue-83150.rs:12:24: 12:27]>` to implement `Iterator` = note: 64 redundant requirements hidden - = note: required for `&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut std::ops::Range, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>` to implement `Iterator` + = note: required for `&mut Map<&mut Map<&mut Map<_, _>, _>, _>` to implement `Iterator` + = note: the full type name has been written to '$TEST_BUILD_DIR/recursion/issue-83150/issue-83150.long-type-hash.txt' error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/traits/issue-91949-hangs-on-recursion.rs b/src/test/ui/traits/issue-91949-hangs-on-recursion.rs index 499a64f281699..6474b2b38e1c0 100644 --- a/src/test/ui/traits/issue-91949-hangs-on-recursion.rs +++ b/src/test/ui/traits/issue-91949-hangs-on-recursion.rs @@ -2,6 +2,7 @@ // compile-flags: -Zinline-mir=no // error-pattern: overflow evaluating the requirement `(): Sized` // error-pattern: function cannot return without recursing +// normalize-stderr-test: "long-type-\d+" -> "long-type-hash" // Regression test for #91949. // This hanged *forever* on 1.56, fixed by #90423. diff --git a/src/test/ui/traits/issue-91949-hangs-on-recursion.stderr b/src/test/ui/traits/issue-91949-hangs-on-recursion.stderr index 61b6d4b08bb6a..e4d01b4d389f9 100644 --- a/src/test/ui/traits/issue-91949-hangs-on-recursion.stderr +++ b/src/test/ui/traits/issue-91949-hangs-on-recursion.stderr @@ -1,5 +1,5 @@ warning: function cannot return without recursing - --> $DIR/issue-91949-hangs-on-recursion.rs:22:1 + --> $DIR/issue-91949-hangs-on-recursion.rs:23:1 | LL | / fn recurse(elements: T) -> Vec LL | | where @@ -17,7 +17,8 @@ error[E0275]: overflow evaluating the requirement `(): Sized` = help: consider increasing the recursion limit by adding a `#![recursion_limit = "512"]` attribute to your crate (`issue_91949_hangs_on_recursion`) = note: required for `std::iter::Empty<()>` to implement `Iterator` = note: 171 redundant requirements hidden - = note: required for `IteratorOfWrapped<(), Map>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>, [closure@$DIR/issue-91949-hangs-on-recursion.rs:26:45: 26:48]>>` to implement `Iterator` + = note: required for `IteratorOfWrapped<(), Map>, _>>` to implement `Iterator` + = note: the full type name has been written to '$TEST_BUILD_DIR/traits/issue-91949-hangs-on-recursion/issue-91949-hangs-on-recursion.long-type-hash.txt' error: aborting due to previous error; 1 warning emitted From 4ed1376490dbc80a204ca8ff4cabf9667a7e141d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 16 Nov 2022 19:33:45 -0800 Subject: [PATCH 060/103] On E0275 do not print out the full type in the msg When printing requirement overflow errors, do not print out the full type name when it is longer than 50 characters long. --- .../src/traits/error_reporting/mod.rs | 27 ++++++++++++++++--- .../src/traits/select/mod.rs | 21 ++++++++++++--- src/test/ui/error-codes/E0275.stderr | 2 +- src/test/ui/issues/issue-20413.stderr | 6 ++--- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index f087afa20baca..39efff211ad84 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -22,6 +22,7 @@ use rustc_errors::{ MultiSpan, Style, }; use rustc_hir as hir; +use rustc_hir::def::Namespace; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::Visitor; use rustc_hir::GenericParam; @@ -34,6 +35,7 @@ use rustc_middle::traits::select::OverflowError; use rustc_middle::ty::abstract_const::NotConstEvaluatable; use rustc_middle::ty::error::ExpectedFound; use rustc_middle::ty::fold::{TypeFolder, TypeSuperFoldable}; +use rustc_middle::ty::print::{FmtPrinter, Print}; use rustc_middle::ty::{ self, SubtypePredicate, ToPolyTraitRef, ToPredicate, TraitRef, Ty, TyCtxt, TypeFoldable, TypeVisitable, @@ -109,7 +111,10 @@ pub trait TypeErrCtxtExt<'tcx> { suggest_increasing_limit: bool, ) -> ! where - T: fmt::Display + TypeFoldable<'tcx>; + T: fmt::Display + + TypeFoldable<'tcx> + + Print<'tcx, FmtPrinter<'tcx, 'tcx>, Output = FmtPrinter<'tcx, 'tcx>>, + >>::Error: std::fmt::Debug; fn suggest_new_overflow_limit(&self, err: &mut Diagnostic); @@ -468,15 +473,31 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { suggest_increasing_limit: bool, ) -> ! where - T: fmt::Display + TypeFoldable<'tcx>, + T: fmt::Display + + TypeFoldable<'tcx> + + Print<'tcx, FmtPrinter<'tcx, 'tcx>, Output = FmtPrinter<'tcx, 'tcx>>, + >>::Error: std::fmt::Debug, { let predicate = self.resolve_vars_if_possible(obligation.predicate.clone()); + let mut pred_str = predicate.to_string(); + if pred_str.len() > 50 { + // We don't need to save the type to a file, we will be talking about this type already + // in a separate note when we explain the obligation, so it will be available that way. + pred_str = predicate + .print(FmtPrinter::new_with_limit( + self.tcx, + Namespace::TypeNS, + rustc_session::Limit(6), + )) + .unwrap() + .into_buffer(); + } let mut err = struct_span_err!( self.tcx.sess, obligation.cause.span, E0275, "overflow evaluating the requirement `{}`", - predicate + pred_str, ); if suggest_increasing_limit { diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index c369c5de52bb1..c9966fc4363ab 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -42,6 +42,7 @@ use rustc_middle::mir::interpret::ErrorHandled; use rustc_middle::ty::abstract_const::NotConstEvaluatable; use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams}; use rustc_middle::ty::fold::BottomUpFolder; +use rustc_middle::ty::print::{FmtPrinter, Print}; use rustc_middle::ty::relate::TypeRelation; use rustc_middle::ty::SubstsRef; use rustc_middle::ty::{self, EarlyBinder, PolyProjectionPredicate, ToPolyTraitRef, ToPredicate}; @@ -1081,11 +1082,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { it.for_each(|o| o.recursion_depth = cmp::max(min_depth, o.recursion_depth) + 1); } - fn check_recursion_depth>( + fn check_recursion_depth( &self, depth: usize, error_obligation: &Obligation<'tcx, T>, - ) -> Result<(), OverflowError> { + ) -> Result<(), OverflowError> + where + T: fmt::Display + + TypeFoldable<'tcx> + + Print<'tcx, FmtPrinter<'tcx, 'tcx>, Output = FmtPrinter<'tcx, 'tcx>>, + >>::Error: std::fmt::Debug, + { if !self.infcx.tcx.recursion_limit().value_within_limit(depth) { match self.query_mode { TraitQueryMode::Standard => { @@ -1109,11 +1116,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { /// The weird return type of this function allows it to be used with the `try` (`?`) /// operator within certain functions. #[inline(always)] - fn check_recursion_limit, V: Display + TypeFoldable<'tcx>>( + fn check_recursion_limit, V>( &self, obligation: &Obligation<'tcx, T>, error_obligation: &Obligation<'tcx, V>, - ) -> Result<(), OverflowError> { + ) -> Result<(), OverflowError> + where + V: fmt::Display + + TypeFoldable<'tcx> + + Print<'tcx, FmtPrinter<'tcx, 'tcx>, Output = FmtPrinter<'tcx, 'tcx>>, + >>::Error: std::fmt::Debug, + { self.check_recursion_depth(obligation.recursion_depth, error_obligation) } diff --git a/src/test/ui/error-codes/E0275.stderr b/src/test/ui/error-codes/E0275.stderr index 0cb54f2966621..49a4d984af9eb 100644 --- a/src/test/ui/error-codes/E0275.stderr +++ b/src/test/ui/error-codes/E0275.stderr @@ -1,4 +1,4 @@ -error[E0275]: overflow evaluating the requirement `Bar>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>: Foo` +error[E0275]: overflow evaluating the requirement `Bar>>>>>>: Foo` --> $DIR/E0275.rs:6:33 | LL | impl Foo for T where Bar: Foo {} diff --git a/src/test/ui/issues/issue-20413.stderr b/src/test/ui/issues/issue-20413.stderr index dbaaf7a7746e1..91509ceace8cb 100644 --- a/src/test/ui/issues/issue-20413.stderr +++ b/src/test/ui/issues/issue-20413.stderr @@ -7,7 +7,7 @@ LL | struct NoData; = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` = help: if you intended `T` to be a const parameter, use `const T: usize` instead -error[E0275]: overflow evaluating the requirement `NoData>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>: Foo` +error[E0275]: overflow evaluating the requirement `NoData>>>>>>: Foo` --> $DIR/issue-20413.rs:9:36 | LL | impl Foo for T where NoData: Foo { @@ -23,7 +23,7 @@ LL | impl Foo for T where NoData: Foo { = note: 127 redundant requirements hidden = note: required for `NoData` to implement `Foo` -error[E0275]: overflow evaluating the requirement `EvenLessData>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>: Baz` +error[E0275]: overflow evaluating the requirement `EvenLessData>>>>>>: Baz` --> $DIR/issue-20413.rs:28:42 | LL | impl Bar for T where EvenLessData: Baz { @@ -45,7 +45,7 @@ LL | impl Baz for T where AlmostNoData: Bar { = note: 126 redundant requirements hidden = note: required for `EvenLessData` to implement `Baz` -error[E0275]: overflow evaluating the requirement `AlmostNoData>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>: Bar` +error[E0275]: overflow evaluating the requirement `AlmostNoData>>>>>>: Bar` --> $DIR/issue-20413.rs:35:42 | LL | impl Baz for T where AlmostNoData: Bar { From 3debf5006aa9d6810e4691fa03c6660ab998bae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 16 Nov 2022 20:07:15 -0800 Subject: [PATCH 061/103] Only use `...` instead of `_` for type elision `_` might confuse people into believing that the type isn't known, while `...` is not used anywhere else for types and is not valid syntax, making it more likely to convey the right understanding. --- compiler/rustc_middle/src/ty/print/pretty.rs | 6 +----- .../issues/issue-37311-type-length-limit/issue-37311.stderr | 2 +- src/test/ui/issues/issue-67552.stderr | 2 +- src/test/ui/recursion/issue-83150.stderr | 2 +- src/test/ui/traits/issue-91949-hangs-on-recursion.stderr | 2 +- src/test/ui/type_length_limit.stderr | 2 +- 6 files changed, 6 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index faa57b437d947..f17dc1cedbbc2 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1765,11 +1765,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> { self.pretty_print_type(ty) } else { self.truncated = true; - if let ty::Adt(_, substs) = ty.kind() && substs.len() > 0 { - write!(self, "...")?; - } else { - write!(self, "_")?; - } + write!(self, "...")?; Ok(self) } } diff --git a/src/test/ui/issues/issue-37311-type-length-limit/issue-37311.stderr b/src/test/ui/issues/issue-37311-type-length-limit/issue-37311.stderr index 6ce4c498f152a..5b8299fe839d7 100644 --- a/src/test/ui/issues/issue-37311-type-length-limit/issue-37311.stderr +++ b/src/test/ui/issues/issue-37311-type-length-limit/issue-37311.stderr @@ -1,4 +1,4 @@ -error: reached the recursion limit while instantiating `<(&(&(_, _), _), _) as Foo>::recurse` +error: reached the recursion limit while instantiating `<(&(&(..., ...), ...), ...) as Foo>::recurse` --> $DIR/issue-37311.rs:17:9 | LL | (self, self).recurse(); diff --git a/src/test/ui/issues/issue-67552.stderr b/src/test/ui/issues/issue-67552.stderr index c19c26587b983..4746f918bf8dd 100644 --- a/src/test/ui/issues/issue-67552.stderr +++ b/src/test/ui/issues/issue-67552.stderr @@ -1,4 +1,4 @@ -error: reached the recursion limit while instantiating `rec::<&mut &mut &mut &mut &mut _>` +error: reached the recursion limit while instantiating `rec::<&mut &mut &mut &mut &mut ...>` --> $DIR/issue-67552.rs:29:9 | LL | rec(identity(&mut it)) diff --git a/src/test/ui/recursion/issue-83150.stderr b/src/test/ui/recursion/issue-83150.stderr index 98c17b1e2614b..a67bfd018a2b5 100644 --- a/src/test/ui/recursion/issue-83150.stderr +++ b/src/test/ui/recursion/issue-83150.stderr @@ -14,7 +14,7 @@ error[E0275]: overflow evaluating the requirement ` as Itera = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_83150`) = note: required for `Map<&mut std::ops::Range, [closure@$DIR/issue-83150.rs:12:24: 12:27]>` to implement `Iterator` = note: 64 redundant requirements hidden - = note: required for `&mut Map<&mut Map<&mut Map<_, _>, _>, _>` to implement `Iterator` + = note: required for `&mut Map<&mut Map<&mut Map<..., ...>, ...>, ...>` to implement `Iterator` = note: the full type name has been written to '$TEST_BUILD_DIR/recursion/issue-83150/issue-83150.long-type-hash.txt' error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/traits/issue-91949-hangs-on-recursion.stderr b/src/test/ui/traits/issue-91949-hangs-on-recursion.stderr index e4d01b4d389f9..a74d2524996a1 100644 --- a/src/test/ui/traits/issue-91949-hangs-on-recursion.stderr +++ b/src/test/ui/traits/issue-91949-hangs-on-recursion.stderr @@ -17,7 +17,7 @@ error[E0275]: overflow evaluating the requirement `(): Sized` = help: consider increasing the recursion limit by adding a `#![recursion_limit = "512"]` attribute to your crate (`issue_91949_hangs_on_recursion`) = note: required for `std::iter::Empty<()>` to implement `Iterator` = note: 171 redundant requirements hidden - = note: required for `IteratorOfWrapped<(), Map>, _>>` to implement `Iterator` + = note: required for `IteratorOfWrapped<(), Map>, ...>>` to implement `Iterator` = note: the full type name has been written to '$TEST_BUILD_DIR/traits/issue-91949-hangs-on-recursion/issue-91949-hangs-on-recursion.long-type-hash.txt' error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/type_length_limit.stderr b/src/test/ui/type_length_limit.stderr index 10ada6760ebe8..ff48746690223 100644 --- a/src/test/ui/type_length_limit.stderr +++ b/src/test/ui/type_length_limit.stderr @@ -1,4 +1,4 @@ -error: reached the type-length limit while instantiating `std::mem::drop::>` +error: reached the type-length limit while instantiating `std::mem::drop::>` --> $SRC_DIR/core/src/mem/mod.rs:LL:COL | LL | pub fn drop(_x: T) {} From bcb2655a9a3af867c3e48a332870acc36d92df88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 17 Nov 2022 09:24:46 -0800 Subject: [PATCH 062/103] review comment --- compiler/rustc_middle/src/ty/error.rs | 10 +++++----- .../src/traits/error_reporting/suggestions.rs | 10 ++-------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index 36261e7a1f374..d6044ceb0cafc 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -990,7 +990,7 @@ fn foo(&self) -> Self::T { String::new() } false } - pub fn short_ty_string(self, ty: Ty<'tcx>) -> Result { + pub fn short_ty_string(self, ty: Ty<'tcx>) -> (String, Option) { let length_limit = 50; let type_limit = 4; let regular = FmtPrinter::new(self, hir::def::Namespace::TypeNS) @@ -998,7 +998,7 @@ fn foo(&self) -> Self::T { String::new() } .expect("could not write to `String`") .into_buffer(); if regular.len() <= length_limit { - return Ok(regular); + return (regular, None); } let short = FmtPrinter::new_with_limit( self, @@ -1009,7 +1009,7 @@ fn foo(&self) -> Self::T { String::new() } .expect("could not write to `String`") .into_buffer(); if regular == short { - return Ok(regular); + return (regular, None); } // Multiple types might be shortened in a single error, ensure we create a file for each. let mut s = DefaultHasher::new(); @@ -1017,8 +1017,8 @@ fn foo(&self) -> Self::T { String::new() } let hash = s.finish(); let path = self.output_filenames(()).temp_path_ext(&format!("long-type-{hash}.txt"), None); match std::fs::write(&path, ®ular) { - Ok(_) => Err((short, path)), - Err(_) => Ok(regular), + Ok(_) => (short, Some(path)), + Err(_) => (regular, None), } } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 89a4136096773..757977ac5d508 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -2734,10 +2734,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { parent_trait_pred.remap_constness_diag(param_env); let parent_def_id = parent_trait_pred.def_id(); let (self_ty, file) = - match self.tcx.short_ty_string(parent_trait_pred.skip_binder().self_ty()) { - Ok(self_ty) => (self_ty, None), - Err((self_ty, file)) => (self_ty, Some(file)), - }; + self.tcx.short_ty_string(parent_trait_pred.skip_binder().self_ty()); let msg = format!( "required for `{self_ty}` to implement `{}`", parent_trait_pred.print_modifiers_and_trait_path() @@ -2815,10 +2812,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { pluralize!(count) )); let (self_ty, file) = - match self.tcx.short_ty_string(parent_trait_pred.skip_binder().self_ty()) { - Ok(self_ty) => (self_ty, None), - Err((self_ty, file)) => (self_ty, Some(file)), - }; + self.tcx.short_ty_string(parent_trait_pred.skip_binder().self_ty()); err.note(&format!( "required for `{self_ty}` to implement `{}`", parent_trait_pred.print_modifiers_and_trait_path() From df7ecbcb1116915cb4557dccc5a4839a13fbf5b0 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 18 Nov 2022 10:39:26 -0700 Subject: [PATCH 063/103] diagnostics: only show one suggestion for method -> assoc fn Fixes #102354 --- .../rustc_hir_typeck/src/method/suggest.rs | 41 ++++++++++--------- src/test/ui/suggestions/issue-102354.stderr | 13 ++---- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index e2c5edd0e8833..4ac4914bd4479 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -114,7 +114,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let report_candidates = |span: Span, err: &mut Diagnostic, sources: &mut Vec, - sugg_span: Span| { + sugg_span: Option| { sources.sort(); sources.dedup(); // Dynamic limit to avoid hiding just one candidate, which is silly. @@ -175,7 +175,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } else { err.note(¬e_str); } - if let Some(trait_ref) = self.tcx.impl_trait_ref(impl_did) { + if let Some(sugg_span) = sugg_span + && let Some(trait_ref) = self.tcx.impl_trait_ref(impl_did) { let path = self.tcx.def_path_str(trait_ref.def_id); let ty = match item.kind { @@ -224,20 +225,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err.span_note(item_span, msg); None }; - let path = self.tcx.def_path_str(trait_did); - print_disambiguation_help( - item_name, - args, - err, - path, - rcvr_ty, - item.kind, - item.def_id, - sugg_span, - idx, - self.tcx.sess.source_map(), - item.fn_has_self_parameter, - ); + if let Some(sugg_span) = sugg_span { + let path = self.tcx.def_path_str(trait_did); + print_disambiguation_help( + item_name, + args, + err, + path, + rcvr_ty, + item.kind, + item.def_id, + sugg_span, + idx, + self.tcx.sess.source_map(), + item.fn_has_self_parameter, + ); + } } } } @@ -407,9 +410,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { sugg_span, ); - report_candidates(span, &mut err, &mut static_candidates, sugg_span); + report_candidates(span, &mut err, &mut static_candidates, None); } else if static_candidates.len() > 1 { - report_candidates(span, &mut err, &mut static_candidates, sugg_span); + report_candidates(span, &mut err, &mut static_candidates, Some(sugg_span)); } let mut bound_spans = vec![]; @@ -1015,7 +1018,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); err.span_label(item_name.span, format!("multiple `{}` found", item_name)); - report_candidates(span, &mut err, &mut sources, sugg_span); + report_candidates(span, &mut err, &mut sources, Some(sugg_span)); err.emit(); } diff --git a/src/test/ui/suggestions/issue-102354.stderr b/src/test/ui/suggestions/issue-102354.stderr index b17c4dc5dfb50..08d4b99559031 100644 --- a/src/test/ui/suggestions/issue-102354.stderr +++ b/src/test/ui/suggestions/issue-102354.stderr @@ -2,7 +2,10 @@ error[E0599]: no method named `func` found for type `i32` in the current scope --> $DIR/issue-102354.rs:9:7 | LL | x.func(); - | ^^^^ this is an associated function, not a method + | --^^^^-- + | | | + | | this is an associated function, not a method + | help: use associated function syntax instead: `i32::func()` | = note: found the following associated functions; to be used as methods, functions must have a `self` parameter note: the candidate is defined in the trait `Trait` @@ -10,14 +13,6 @@ note: the candidate is defined in the trait `Trait` | LL | fn func() {} | ^^^^^^^^^ -help: use associated function syntax instead - | -LL | i32::func(); - | ~~~~~~~~~~~ -help: disambiguate the associated function for the candidate - | -LL | ::func(x); - | ~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to previous error From b8a92c1dd66c46a5150d2b899294d682683d87e2 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 24 Oct 2022 19:39:19 +0000 Subject: [PATCH 064/103] Revert "Normalize opaques with escaping bound vars" This reverts commit 43119d643857efc366bfca527ac2dadfc3f2e906. --- compiler/rustc_trait_selection/src/traits/project.rs | 2 +- compiler/rustc_trait_selection/src/traits/query/normalize.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index ede6cd607b7fe..528b98cf4a1c0 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -508,7 +508,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { // This is really important. While we *can* handle this, this has // severe performance implications for large opaque types with // late-bound regions. See `issue-88862` benchmark. - ty::Opaque(def_id, substs) => { + ty::Opaque(def_id, substs) if !substs.has_escaping_bound_vars() => { // Only normalize `impl Trait` outside of type inference, usually in codegen. match self.param_env.reveal() { Reveal::UserFacing => ty.super_fold_with(self), diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index f5c98558a2525..a875ea1578dcb 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -198,7 +198,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { // This is really important. While we *can* handle this, this has // severe performance implications for large opaque types with // late-bound regions. See `issue-88862` benchmark. - ty::Opaque(def_id, substs) => { + ty::Opaque(def_id, substs) if !substs.has_escaping_bound_vars() => { // Only normalize `impl Trait` outside of type inference, usually in codegen. match self.param_env.reveal() { Reveal::UserFacing => ty.try_super_fold_with(self), From c286ad985c5116c1ff76a9d04dcb0a3fdf4af8e2 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 25 Oct 2022 02:11:24 +0000 Subject: [PATCH 065/103] Add test --- .../ui/impl-trait/normalize-tait-in-const.rs | 39 +++++++++++++++++++ .../impl-trait/normalize-tait-in-const.stderr | 8 ++++ 2 files changed, 47 insertions(+) create mode 100644 src/test/ui/impl-trait/normalize-tait-in-const.rs create mode 100644 src/test/ui/impl-trait/normalize-tait-in-const.stderr diff --git a/src/test/ui/impl-trait/normalize-tait-in-const.rs b/src/test/ui/impl-trait/normalize-tait-in-const.rs new file mode 100644 index 0000000000000..020bcbb8396c9 --- /dev/null +++ b/src/test/ui/impl-trait/normalize-tait-in-const.rs @@ -0,0 +1,39 @@ +// known-bug: #103507 +// failure-status: 101 +// normalize-stderr-test "note: .*\n\n" -> "" +// normalize-stderr-test "thread 'rustc' panicked.*\n" -> "" +// rustc-env:RUST_BACKTRACE=0 + +#![feature(type_alias_impl_trait)] +#![feature(const_trait_impl)] +#![feature(const_refs_to_cell)] +#![feature(inline_const)] + +use std::marker::Destruct; + +trait T { + type Item; +} + +type Alias<'a> = impl T; + +struct S; +impl<'a> T for &'a S { + type Item = &'a (); +} + +const fn filter_positive<'a>() -> &'a Alias<'a> { + &&S +} + +const fn with_positive Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { + fun(filter_positive()); +} + +const fn foo(_: &Alias<'_>) {} + +const BAR: () = { + with_positive(foo); +}; + +fn main() {} diff --git a/src/test/ui/impl-trait/normalize-tait-in-const.stderr b/src/test/ui/impl-trait/normalize-tait-in-const.stderr new file mode 100644 index 0000000000000..b9fc8726ffc0b --- /dev/null +++ b/src/test/ui/impl-trait/normalize-tait-in-const.stderr @@ -0,0 +1,8 @@ +error: internal compiler error: compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:198:90: Failed to normalize fn(&'a Alias<'b>) {foo} as std::ops::FnOnce<(&&S,)>>::Output, maybe try to call `try_normalize_erasing_regions` instead + +query stack during panic: +#0 [eval_to_allocation_raw] const-evaluating + checking `BAR` +#1 [eval_to_const_value_raw] simplifying constant for the type system `BAR` +end of query stack +error: aborting due to previous error + From 6ae4e5e2d48e1a968c121c03b9aec84fc3a58b3e Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 18 Nov 2022 18:06:32 +0000 Subject: [PATCH 066/103] Delete miri test --- .../miri/tests/pass/issues/issue-miri-2433.rs | 24 ------------------- 1 file changed, 24 deletions(-) delete mode 100644 src/tools/miri/tests/pass/issues/issue-miri-2433.rs diff --git a/src/tools/miri/tests/pass/issues/issue-miri-2433.rs b/src/tools/miri/tests/pass/issues/issue-miri-2433.rs deleted file mode 100644 index a8281d30bac4a..0000000000000 --- a/src/tools/miri/tests/pass/issues/issue-miri-2433.rs +++ /dev/null @@ -1,24 +0,0 @@ -#![feature(type_alias_impl_trait)] - -trait T { - type Item; -} - -type Alias<'a> = impl T; - -struct S; -impl<'a> T for &'a S { - type Item = &'a (); -} - -fn filter_positive<'a>() -> Alias<'a> { - &S -} - -fn with_positive(fun: impl Fn(Alias<'_>)) { - fun(filter_positive()); -} - -fn main() { - with_positive(|_| ()); -} From da3c5397a614f790f0daaf61bfdc692b36719e01 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 12 Nov 2022 22:27:18 +0000 Subject: [PATCH 067/103] Enforce that dyn* casts are actually pointer-sized --- compiler/rustc_hir/src/lang_items.rs | 2 ++ compiler/rustc_hir_typeck/src/coercion.rs | 33 ++++++++++++++----- compiler/rustc_span/src/symbol.rs | 1 + .../src/traits/select/candidate_assembly.rs | 27 +++++++++++++++ library/core/src/marker.rs | 9 +++++ .../check-size-at-cast-polymorphic-bad.rs | 15 +++++++++ .../check-size-at-cast-polymorphic-bad.stderr | 15 +++++++++ .../check-size-at-cast-polymorphic.rs | 16 +++++++++ src/test/ui/dyn-star/check-size-at-cast.rs | 10 ++++++ .../ui/dyn-star/check-size-at-cast.stderr | 11 +++++++ 10 files changed, 131 insertions(+), 8 deletions(-) create mode 100644 src/test/ui/dyn-star/check-size-at-cast-polymorphic-bad.rs create mode 100644 src/test/ui/dyn-star/check-size-at-cast-polymorphic-bad.stderr create mode 100644 src/test/ui/dyn-star/check-size-at-cast-polymorphic.rs create mode 100644 src/test/ui/dyn-star/check-size-at-cast.rs create mode 100644 src/test/ui/dyn-star/check-size-at-cast.stderr diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index a55224d10972a..a748af6577448 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -270,6 +270,8 @@ language_item_table! { TryTraitBranch, sym::branch, branch_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; TryTraitFromYeet, sym::from_yeet, from_yeet_fn, Target::Fn, GenericRequirement::None; + PointerSized, sym::pointer_sized, pointer_sized, Target::Trait, GenericRequirement::Exact(0); + PollReady, sym::Ready, poll_ready_variant, Target::Variant, GenericRequirement::None; PollPending, sym::Pending, poll_pending_variant, Target::Variant, GenericRequirement::None; diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 174b43313825e..c1e4ab600f34f 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -775,7 +775,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { // Check the obligations of the cast -- for example, when casting // `usize` to `dyn* Clone + 'static`: - let obligations = predicates + let mut obligations: Vec<_> = predicates .iter() .map(|predicate| { // For each existential predicate (e.g., `?Self: Clone`) substitute @@ -785,16 +785,33 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { let predicate = predicate.with_self_ty(self.tcx, a); Obligation::new(self.tcx, self.cause.clone(), self.param_env, predicate) }) - // Enforce the region bound (e.g., `usize: 'static`, in our example). - .chain([Obligation::new( + .chain([ + // Enforce the region bound (e.g., `usize: 'static`, in our example). + Obligation::new( + self.tcx, + self.cause.clone(), + self.param_env, + ty::Binder::dummy(ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate( + a, b_region, + ))), + ), + ]) + .collect(); + + // Enforce that the type is `usize`/pointer-sized. For now, only those + // can be coerced to `dyn*`, except for `dyn* -> dyn*` upcasts. + if !a.is_dyn_star() { + obligations.push(Obligation::new( self.tcx, self.cause.clone(), self.param_env, - self.tcx.mk_predicate(ty::Binder::dummy(ty::PredicateKind::TypeOutlives( - ty::OutlivesPredicate(a, b_region), - ))), - )]) - .collect(); + ty::Binder::dummy(ty::TraitRef::new( + self.tcx.require_lang_item(hir::LangItem::PointerSized, Some(self.cause.span)), + self.tcx.mk_substs_trait(a, &[]), + )) + .to_poly_trait_predicate(), + )); + } Ok(InferOk { value: (vec![Adjustment { kind: Adjust::DynStar, target: b }], b), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 02848bcffb298..199b2d32b9d4c 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1067,6 +1067,7 @@ symbols! { plugins, pointee_trait, pointer, + pointer_sized, poll, position, post_dash_lto: "post-lto", diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 3995ea58db16c..c77f035d6b97f 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -304,6 +304,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { self.assemble_candidates_for_transmutability(obligation, &mut candidates); } else if lang_items.tuple_trait() == Some(def_id) { self.assemble_candidate_for_tuple(obligation, &mut candidates); + } else if lang_items.pointer_sized() == Some(def_id) { + self.assemble_candidate_for_ptr_sized(obligation, &mut candidates); } else { if lang_items.clone_trait() == Some(def_id) { // Same builtin conditions as `Copy`, i.e., every type which has builtin support @@ -1047,4 +1049,29 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ty::Placeholder(_) => {} } } + + fn assemble_candidate_for_ptr_sized( + &mut self, + obligation: &TraitObligation<'tcx>, + candidates: &mut SelectionCandidateSet<'tcx>, + ) { + // The regions of a type don't affect the size of the type + let self_ty = self + .tcx() + .erase_regions(self.tcx().erase_late_bound_regions(obligation.predicate.self_ty())); + + // But if there are inference variables, we have to wait until it's resolved. + if self_ty.has_non_region_infer() { + candidates.ambiguous = true; + return; + } + + let usize_layout = + self.tcx().layout_of(ty::ParamEnv::empty().and(self.tcx().types.usize)).unwrap().layout; + if let Ok(layout) = self.tcx().layout_of(obligation.param_env.and(self_ty)) + && layout.layout.size().bytes() == usize_layout.size().bytes() + { + candidates.vec.push(BuiltinCandidate { has_nested: false }); + } + } } diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 3eff6033f8da9..42c3428019769 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -809,6 +809,15 @@ pub trait Destruct {} #[cfg_attr(not(bootstrap), rustc_deny_explicit_impl)] pub trait Tuple {} +/// A marker for things +#[unstable(feature = "pointer_sized_trait", issue = "none")] +#[cfg_attr(not(bootstrap), lang = "pointer_sized")] +#[rustc_on_unimplemented( + message = "`{Self}` needs to be a pointer-sized type", + label = "`{Self}` needs to be a pointer-sized type" +)] +pub trait PointerSized {} + /// Implementations of `Copy` for primitive types. /// /// Implementations that cannot be described in Rust diff --git a/src/test/ui/dyn-star/check-size-at-cast-polymorphic-bad.rs b/src/test/ui/dyn-star/check-size-at-cast-polymorphic-bad.rs new file mode 100644 index 0000000000000..e19e36cc7d7b5 --- /dev/null +++ b/src/test/ui/dyn-star/check-size-at-cast-polymorphic-bad.rs @@ -0,0 +1,15 @@ +#![feature(dyn_star)] +#![allow(incomplete_features)] + +use std::fmt::Debug; + +fn dyn_debug(_: (dyn* Debug + '_)) { + +} + +fn polymorphic(t: &T) { + dyn_debug(t); + //~^ ERROR `&T` needs to be a pointer-sized type +} + +fn main() {} diff --git a/src/test/ui/dyn-star/check-size-at-cast-polymorphic-bad.stderr b/src/test/ui/dyn-star/check-size-at-cast-polymorphic-bad.stderr new file mode 100644 index 0000000000000..53ccbe43dcc9e --- /dev/null +++ b/src/test/ui/dyn-star/check-size-at-cast-polymorphic-bad.stderr @@ -0,0 +1,15 @@ +error[E0277]: `&T` needs to be a pointer-sized type + --> $DIR/check-size-at-cast-polymorphic-bad.rs:11:15 + | +LL | dyn_debug(t); + | ^ `&T` needs to be a pointer-sized type + | + = help: the trait `PointerSized` is not implemented for `&T` +help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement + | +LL | fn polymorphic(t: &T) where &T: PointerSized { + | ++++++++++++++++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/dyn-star/check-size-at-cast-polymorphic.rs b/src/test/ui/dyn-star/check-size-at-cast-polymorphic.rs new file mode 100644 index 0000000000000..5c0a3d256f607 --- /dev/null +++ b/src/test/ui/dyn-star/check-size-at-cast-polymorphic.rs @@ -0,0 +1,16 @@ +// check-pass + +#![feature(dyn_star)] +#![allow(incomplete_features)] + +use std::fmt::Debug; + +fn dyn_debug(_: (dyn* Debug + '_)) { + +} + +fn polymorphic(t: &T) { + dyn_debug(t); +} + +fn main() {} diff --git a/src/test/ui/dyn-star/check-size-at-cast.rs b/src/test/ui/dyn-star/check-size-at-cast.rs new file mode 100644 index 0000000000000..1f22f79836154 --- /dev/null +++ b/src/test/ui/dyn-star/check-size-at-cast.rs @@ -0,0 +1,10 @@ +#![feature(dyn_star)] +#![allow(incomplete_features)] + +use std::fmt::Debug; + +fn main() { + let i = [1, 2, 3, 4] as dyn* Debug; + //~^ ERROR `[i32; 4]` needs to be a pointer-sized type + dbg!(i); +} diff --git a/src/test/ui/dyn-star/check-size-at-cast.stderr b/src/test/ui/dyn-star/check-size-at-cast.stderr new file mode 100644 index 0000000000000..af2a1ccf71c6d --- /dev/null +++ b/src/test/ui/dyn-star/check-size-at-cast.stderr @@ -0,0 +1,11 @@ +error[E0277]: `[i32; 4]` needs to be a pointer-sized type + --> $DIR/check-size-at-cast.rs:7:13 + | +LL | let i = [1, 2, 3, 4] as dyn* Debug; + | ^^^^^^^^^^^^ `[i32; 4]` needs to be a pointer-sized type + | + = help: the trait `PointerSized` is not implemented for `[i32; 4]` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. From b3da04aa52d6e36d7db8666db9aeeaec316f1cc9 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 15 Nov 2022 22:26:28 +0000 Subject: [PATCH 068/103] Check both align and size in PointerSized --- .../src/traits/select/candidate_assembly.rs | 3 ++- src/test/ui/dyn-star/align.normal.stderr | 11 ++++++++++ .../ui/dyn-star/align.over_aligned.stderr | 20 +++++++++++++++++++ src/test/ui/dyn-star/align.rs | 17 ++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/dyn-star/align.normal.stderr create mode 100644 src/test/ui/dyn-star/align.over_aligned.stderr create mode 100644 src/test/ui/dyn-star/align.rs diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index c77f035d6b97f..4c6bb39d17b30 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -1069,7 +1069,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let usize_layout = self.tcx().layout_of(ty::ParamEnv::empty().and(self.tcx().types.usize)).unwrap().layout; if let Ok(layout) = self.tcx().layout_of(obligation.param_env.and(self_ty)) - && layout.layout.size().bytes() == usize_layout.size().bytes() + && layout.layout.size() == usize_layout.size() + && layout.layout.align() == usize_layout.align() { candidates.vec.push(BuiltinCandidate { has_nested: false }); } diff --git a/src/test/ui/dyn-star/align.normal.stderr b/src/test/ui/dyn-star/align.normal.stderr new file mode 100644 index 0000000000000..983d7bf6e7e9c --- /dev/null +++ b/src/test/ui/dyn-star/align.normal.stderr @@ -0,0 +1,11 @@ +warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/align.rs:4:12 + | +LL | #![feature(dyn_star)] + | ^^^^^^^^ + | + = note: see issue #91611 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted + diff --git a/src/test/ui/dyn-star/align.over_aligned.stderr b/src/test/ui/dyn-star/align.over_aligned.stderr new file mode 100644 index 0000000000000..6b6fc55d8053e --- /dev/null +++ b/src/test/ui/dyn-star/align.over_aligned.stderr @@ -0,0 +1,20 @@ +warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/align.rs:4:12 + | +LL | #![feature(dyn_star)] + | ^^^^^^^^ + | + = note: see issue #91611 for more information + = note: `#[warn(incomplete_features)]` on by default + +error[E0277]: `AlignedUsize` needs to be a pointer-sized type + --> $DIR/align.rs:15:13 + | +LL | let x = AlignedUsize(12) as dyn* Debug; + | ^^^^^^^^^^^^^^^^ `AlignedUsize` needs to be a pointer-sized type + | + = help: the trait `PointerSized` is not implemented for `AlignedUsize` + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/dyn-star/align.rs b/src/test/ui/dyn-star/align.rs new file mode 100644 index 0000000000000..fb41a05a0660b --- /dev/null +++ b/src/test/ui/dyn-star/align.rs @@ -0,0 +1,17 @@ +// revisions: normal over_aligned +//[normal] check-pass + +#![feature(dyn_star)] +//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes + +use std::fmt::Debug; + +#[cfg_attr(over_aligned, repr(C, align(1024)))] +#[cfg_attr(not(over_aligned), repr(C))] +#[derive(Debug)] +struct AlignedUsize(usize); + +fn main() { + let x = AlignedUsize(12) as dyn* Debug; + //[over_aligned]~^ ERROR `AlignedUsize` needs to be a pointer-sized type +} From 39e076a2e7df1407a58efa74bd46de60c7883941 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 16 Nov 2022 04:29:41 +0000 Subject: [PATCH 069/103] Only enforce ABI-mandated align, not preferred align is compatible --- .../src/traits/select/candidate_assembly.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 4c6bb39d17b30..e5b9ca67b1be6 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -1070,7 +1070,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { self.tcx().layout_of(ty::ParamEnv::empty().and(self.tcx().types.usize)).unwrap().layout; if let Ok(layout) = self.tcx().layout_of(obligation.param_env.and(self_ty)) && layout.layout.size() == usize_layout.size() - && layout.layout.align() == usize_layout.align() + && layout.layout.align().abi == usize_layout.align().abi { candidates.vec.push(BuiltinCandidate { has_nested: false }); } From 35f8962ceee84fe330e95a5ac1efd8f62888ce51 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Fri, 18 Nov 2022 21:35:07 +0000 Subject: [PATCH 070/103] Update cargo 3 commits in 16b097879b6f117c8ae698aab054c87f26ff325e..eb5d35917b2395194593c9ca70c3778f60c1573b 2022-11-14 23:28:16 +0000 to 2022-11-17 22:08:43 +0000 - Fix several tests that are waiting 60 seconds for publishing to time out (rust-lang/cargo#11388) - Implement RFC 3139: alternative registry authentication support (rust-lang/cargo#10592) - Fix cargo install --index when used with registry.default (rust-lang/cargo#11302) --- Cargo.lock | 18 ++++++++++++++---- src/tools/cargo | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e1359b9e9e402..974fdf8db773b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -307,6 +307,7 @@ dependencies = [ "glob", "hex 0.4.2", "home", + "http-auth", "humantime 2.0.1", "ignore", "im-rc", @@ -349,11 +350,11 @@ dependencies = [ [[package]] name = "cargo-credential" -version = "0.1.0" +version = "0.2.0" [[package]] name = "cargo-credential-1password" -version = "0.1.0" +version = "0.2.0" dependencies = [ "cargo-credential", "serde", @@ -362,7 +363,7 @@ dependencies = [ [[package]] name = "cargo-credential-macos-keychain" -version = "0.1.0" +version = "0.2.0" dependencies = [ "cargo-credential", "security-framework", @@ -370,7 +371,7 @@ dependencies = [ [[package]] name = "cargo-credential-wincred" -version = "0.1.0" +version = "0.2.0" dependencies = [ "cargo-credential", "winapi", @@ -1692,6 +1693,15 @@ dependencies = [ "syn", ] +[[package]] +name = "http-auth" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0b40b39d66c28829a0cf4d09f7e139ff8201f7500a5083732848ed3b4b4d850" +dependencies = [ + "memchr", +] + [[package]] name = "humantime" version = "1.3.0" diff --git a/src/tools/cargo b/src/tools/cargo index 16b097879b6f1..eb5d35917b239 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 16b097879b6f117c8ae698aab054c87f26ff325e +Subproject commit eb5d35917b2395194593c9ca70c3778f60c1573b From 42d3bda08c0c65c455d8349031f42f074ad42b28 Mon Sep 17 00:00:00 2001 From: Charles Lew Date: Sat, 5 Nov 2022 13:09:13 +0800 Subject: [PATCH 071/103] Add `rustc_baked_icu_data` crate. --- compiler/rustc_baked_icu_data/Cargo.toml | 9 + compiler/rustc_baked_icu_data/src/data/any.rs | 18 + .../src/data/list/and_v1.rs | 1160 +++++++++++++++++ .../rustc_baked_icu_data/src/data/list/mod.rs | 2 + compiler/rustc_baked_icu_data/src/data/mod.rs | 25 + compiler/rustc_baked_icu_data/src/lib.rs | 17 + src/tools/tidy/src/deps.rs | 12 + 7 files changed, 1243 insertions(+) create mode 100644 compiler/rustc_baked_icu_data/Cargo.toml create mode 100644 compiler/rustc_baked_icu_data/src/data/any.rs create mode 100644 compiler/rustc_baked_icu_data/src/data/list/and_v1.rs create mode 100644 compiler/rustc_baked_icu_data/src/data/list/mod.rs create mode 100644 compiler/rustc_baked_icu_data/src/data/mod.rs create mode 100644 compiler/rustc_baked_icu_data/src/lib.rs diff --git a/compiler/rustc_baked_icu_data/Cargo.toml b/compiler/rustc_baked_icu_data/Cargo.toml new file mode 100644 index 0000000000000..c4b49e939e91c --- /dev/null +++ b/compiler/rustc_baked_icu_data/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "rustc_baked_icu_data" +version = "0.0.0" +edition = "2021" + +[dependencies] +icu_list = "1.0.0" +icu_provider = "1.0.1" +litemap = "0.6.0" diff --git a/compiler/rustc_baked_icu_data/src/data/any.rs b/compiler/rustc_baked_icu_data/src/data/any.rs new file mode 100644 index 0000000000000..be5be6e03b85e --- /dev/null +++ b/compiler/rustc_baked_icu_data/src/data/any.rs @@ -0,0 +1,18 @@ +// @generated +impl AnyProvider for BakedDataProvider { + fn load_any(&self, key: DataKey, req: DataRequest) -> Result { + const ANDLISTV1MARKER: ::icu_provider::DataKeyHash = + ::icu_list::provider::AndListV1Marker::KEY.hashed(); + #[allow(clippy::match_single_binding)] + match key.hashed() { + ANDLISTV1MARKER => list::and_v1::DATA + .get_by(|k| req.locale.strict_cmp(k.as_bytes()).reverse()) + .copied() + .map(AnyPayload::from_static_ref) + .ok_or(DataErrorKind::MissingLocale), + _ => Err(DataErrorKind::MissingDataKey), + } + .map_err(|e| e.with_req(key, req)) + .map(|payload| AnyResponse { payload: Some(payload), metadata: Default::default() }) + } +} diff --git a/compiler/rustc_baked_icu_data/src/data/list/and_v1.rs b/compiler/rustc_baked_icu_data/src/data/list/and_v1.rs new file mode 100644 index 0000000000000..aefaa2cc9c939 --- /dev/null +++ b/compiler/rustc_baked_icu_data/src/data/list/and_v1.rs @@ -0,0 +1,1160 @@ +// @generated +type DataStruct = <::icu_list::provider::AndListV1Marker as ::icu_provider::DataMarker>::Yokeable; +pub static DATA: litemap::LiteMap<&str, &DataStruct, &[(&str, &DataStruct)]> = + litemap::LiteMap::from_sorted_store_unchecked(&[ + ("en", EN), + ("es", ES), + ("fr", FR), + ("it", IT), + ("ja", JA), + ("pt", PT), + ("ru", RU), + ("tr", TR), + ("und", UND), + ("zh-Hans", ZH_HANS), + ("zh-Hant", ZH_HANT), + ]); +static EN: &DataStruct = &::icu_list::provider::ListFormatterPatternsV1([ + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", and ", 6u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" and ", 5u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", & ", 4u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" & ", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, +]); +static ES: &DataStruct = &::icu_list::provider::ListFormatterPatternsV1([ + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" y ", 3u8) + }, + special_case: Some(::icu_list::provider::SpecialCasePattern { + condition: unsafe { + ::icu_list::provider::StringMatcher::from_dfa_bytes_unchecked(&[ + 114u8, 117u8, 115u8, 116u8, 45u8, 114u8, 101u8, 103u8, 101u8, 120u8, 45u8, + 97u8, 117u8, 116u8, 111u8, 109u8, 97u8, 116u8, 97u8, 45u8, 100u8, 102u8, 97u8, + 45u8, 115u8, 112u8, 97u8, 114u8, 115u8, 101u8, 0u8, 0u8, 255u8, 254u8, 0u8, + 0u8, 2u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 14u8, 0u8, 0u8, 0u8, 1u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 2u8, 2u8, 2u8, 3u8, 4u8, 4u8, 5u8, 6u8, 7u8, 7u8, 7u8, 7u8, + 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, + 7u8, 7u8, 7u8, 8u8, 9u8, 9u8, 9u8, 10u8, 11u8, 11u8, 12u8, 13u8, 14u8, 14u8, + 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, + 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, + 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 16u8, 16u8, 16u8, + 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, + 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, + 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, + 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 18u8, 18u8, 19u8, 19u8, 19u8, 19u8, 19u8, + 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, + 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 20u8, + 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 22u8, + 23u8, 23u8, 24u8, 25u8, 25u8, 25u8, 26u8, 27u8, 27u8, 27u8, 27u8, 27u8, 27u8, + 27u8, 27u8, 27u8, 27u8, 27u8, 40u8, 1u8, 0u8, 0u8, 1u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 1u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 128u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 5u8, + 0u8, 5u8, 5u8, 6u8, 6u8, 12u8, 12u8, 13u8, 13u8, 0u8, 0u8, 83u8, 0u8, 0u8, 0u8, + 68u8, 0u8, 0u8, 0u8, 83u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 2u8, 0u8, 0u8, 27u8, 0u8, 0u8, 18u8, 0u8, 0u8, 0u8, 18u8, 0u8, 0u8, + 0u8, 0u8, 3u8, 0u8, 6u8, 6u8, 13u8, 13u8, 0u8, 0u8, 104u8, 0u8, 0u8, 0u8, + 104u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 14u8, 0u8, 0u8, 0u8, 2u8, 2u8, + 4u8, 7u8, 9u8, 9u8, 11u8, 14u8, 19u8, 19u8, 20u8, 20u8, 21u8, 21u8, 22u8, 22u8, + 23u8, 23u8, 24u8, 24u8, 25u8, 25u8, 26u8, 26u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, + 68u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, + 0u8, 191u8, 0u8, 0u8, 0u8, 206u8, 0u8, 0u8, 0u8, 221u8, 0u8, 0u8, 0u8, 236u8, + 0u8, 0u8, 0u8, 221u8, 0u8, 0u8, 0u8, 251u8, 0u8, 0u8, 0u8, 10u8, 1u8, 0u8, 0u8, + 25u8, 1u8, 0u8, 0u8, 18u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 17u8, 0u8, 0u8, + 68u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 17u8, 17u8, 0u8, 0u8, + 191u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 17u8, 0u8, 0u8, + 191u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 16u8, 0u8, 0u8, + 191u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 16u8, 17u8, 0u8, 0u8, + 221u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 17u8, 0u8, 0u8, + 221u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 15u8, 0u8, 0u8, + 221u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 4u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 35u8, + 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 9u8, 0u8, 0u8, 0u8, 18u8, 0u8, 0u8, 0u8, + 18u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, + 0u8, 35u8, 0u8, 0u8, 0u8, + ]) + }, + pattern: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" e ", 3u8) + }, + }), + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" y ", 3u8) + }, + special_case: Some(::icu_list::provider::SpecialCasePattern { + condition: unsafe { + ::icu_list::provider::StringMatcher::from_dfa_bytes_unchecked(&[ + 114u8, 117u8, 115u8, 116u8, 45u8, 114u8, 101u8, 103u8, 101u8, 120u8, 45u8, + 97u8, 117u8, 116u8, 111u8, 109u8, 97u8, 116u8, 97u8, 45u8, 100u8, 102u8, 97u8, + 45u8, 115u8, 112u8, 97u8, 114u8, 115u8, 101u8, 0u8, 0u8, 255u8, 254u8, 0u8, + 0u8, 2u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 14u8, 0u8, 0u8, 0u8, 1u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 2u8, 2u8, 2u8, 3u8, 4u8, 4u8, 5u8, 6u8, 7u8, 7u8, 7u8, 7u8, + 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, + 7u8, 7u8, 7u8, 8u8, 9u8, 9u8, 9u8, 10u8, 11u8, 11u8, 12u8, 13u8, 14u8, 14u8, + 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, + 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, + 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 16u8, 16u8, 16u8, + 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, + 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, + 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, + 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 18u8, 18u8, 19u8, 19u8, 19u8, 19u8, 19u8, + 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, + 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 20u8, + 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 22u8, + 23u8, 23u8, 24u8, 25u8, 25u8, 25u8, 26u8, 27u8, 27u8, 27u8, 27u8, 27u8, 27u8, + 27u8, 27u8, 27u8, 27u8, 27u8, 40u8, 1u8, 0u8, 0u8, 1u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 1u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 128u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 5u8, + 0u8, 5u8, 5u8, 6u8, 6u8, 12u8, 12u8, 13u8, 13u8, 0u8, 0u8, 83u8, 0u8, 0u8, 0u8, + 68u8, 0u8, 0u8, 0u8, 83u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 2u8, 0u8, 0u8, 27u8, 0u8, 0u8, 18u8, 0u8, 0u8, 0u8, 18u8, 0u8, 0u8, + 0u8, 0u8, 3u8, 0u8, 6u8, 6u8, 13u8, 13u8, 0u8, 0u8, 104u8, 0u8, 0u8, 0u8, + 104u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 14u8, 0u8, 0u8, 0u8, 2u8, 2u8, + 4u8, 7u8, 9u8, 9u8, 11u8, 14u8, 19u8, 19u8, 20u8, 20u8, 21u8, 21u8, 22u8, 22u8, + 23u8, 23u8, 24u8, 24u8, 25u8, 25u8, 26u8, 26u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, + 68u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, + 0u8, 191u8, 0u8, 0u8, 0u8, 206u8, 0u8, 0u8, 0u8, 221u8, 0u8, 0u8, 0u8, 236u8, + 0u8, 0u8, 0u8, 221u8, 0u8, 0u8, 0u8, 251u8, 0u8, 0u8, 0u8, 10u8, 1u8, 0u8, 0u8, + 25u8, 1u8, 0u8, 0u8, 18u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 17u8, 0u8, 0u8, + 68u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 17u8, 17u8, 0u8, 0u8, + 191u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 17u8, 0u8, 0u8, + 191u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 16u8, 0u8, 0u8, + 191u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 16u8, 17u8, 0u8, 0u8, + 221u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 17u8, 0u8, 0u8, + 221u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 15u8, 0u8, 0u8, + 221u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 4u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 35u8, + 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 9u8, 0u8, 0u8, 0u8, 18u8, 0u8, 0u8, 0u8, + 18u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, + 0u8, 35u8, 0u8, 0u8, 0u8, + ]) + }, + pattern: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" e ", 3u8) + }, + }), + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" y ", 3u8) + }, + special_case: Some(::icu_list::provider::SpecialCasePattern { + condition: unsafe { + ::icu_list::provider::StringMatcher::from_dfa_bytes_unchecked(&[ + 114u8, 117u8, 115u8, 116u8, 45u8, 114u8, 101u8, 103u8, 101u8, 120u8, 45u8, + 97u8, 117u8, 116u8, 111u8, 109u8, 97u8, 116u8, 97u8, 45u8, 100u8, 102u8, 97u8, + 45u8, 115u8, 112u8, 97u8, 114u8, 115u8, 101u8, 0u8, 0u8, 255u8, 254u8, 0u8, + 0u8, 2u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 14u8, 0u8, 0u8, 0u8, 1u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 2u8, 2u8, 2u8, 3u8, 4u8, 4u8, 5u8, 6u8, 7u8, 7u8, 7u8, 7u8, + 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, + 7u8, 7u8, 7u8, 8u8, 9u8, 9u8, 9u8, 10u8, 11u8, 11u8, 12u8, 13u8, 14u8, 14u8, + 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, + 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, + 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 16u8, 16u8, 16u8, + 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, + 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, + 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, + 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 18u8, 18u8, 19u8, 19u8, 19u8, 19u8, 19u8, + 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, + 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 20u8, + 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 22u8, + 23u8, 23u8, 24u8, 25u8, 25u8, 25u8, 26u8, 27u8, 27u8, 27u8, 27u8, 27u8, 27u8, + 27u8, 27u8, 27u8, 27u8, 27u8, 40u8, 1u8, 0u8, 0u8, 1u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 1u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 128u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 5u8, + 0u8, 5u8, 5u8, 6u8, 6u8, 12u8, 12u8, 13u8, 13u8, 0u8, 0u8, 83u8, 0u8, 0u8, 0u8, + 68u8, 0u8, 0u8, 0u8, 83u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 2u8, 0u8, 0u8, 27u8, 0u8, 0u8, 18u8, 0u8, 0u8, 0u8, 18u8, 0u8, 0u8, + 0u8, 0u8, 3u8, 0u8, 6u8, 6u8, 13u8, 13u8, 0u8, 0u8, 104u8, 0u8, 0u8, 0u8, + 104u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 14u8, 0u8, 0u8, 0u8, 2u8, 2u8, + 4u8, 7u8, 9u8, 9u8, 11u8, 14u8, 19u8, 19u8, 20u8, 20u8, 21u8, 21u8, 22u8, 22u8, + 23u8, 23u8, 24u8, 24u8, 25u8, 25u8, 26u8, 26u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, + 68u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, + 0u8, 191u8, 0u8, 0u8, 0u8, 206u8, 0u8, 0u8, 0u8, 221u8, 0u8, 0u8, 0u8, 236u8, + 0u8, 0u8, 0u8, 221u8, 0u8, 0u8, 0u8, 251u8, 0u8, 0u8, 0u8, 10u8, 1u8, 0u8, 0u8, + 25u8, 1u8, 0u8, 0u8, 18u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 17u8, 0u8, 0u8, + 68u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 17u8, 17u8, 0u8, 0u8, + 191u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 17u8, 0u8, 0u8, + 191u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 16u8, 0u8, 0u8, + 191u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 16u8, 17u8, 0u8, 0u8, + 221u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 17u8, 0u8, 0u8, + 221u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 15u8, 0u8, 0u8, + 221u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 4u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 35u8, + 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 9u8, 0u8, 0u8, 0u8, 18u8, 0u8, 0u8, 0u8, + 18u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, + 0u8, 35u8, 0u8, 0u8, 0u8, + ]) + }, + pattern: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" e ", 3u8) + }, + }), + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" y ", 3u8) + }, + special_case: Some(::icu_list::provider::SpecialCasePattern { + condition: unsafe { + ::icu_list::provider::StringMatcher::from_dfa_bytes_unchecked(&[ + 114u8, 117u8, 115u8, 116u8, 45u8, 114u8, 101u8, 103u8, 101u8, 120u8, 45u8, + 97u8, 117u8, 116u8, 111u8, 109u8, 97u8, 116u8, 97u8, 45u8, 100u8, 102u8, 97u8, + 45u8, 115u8, 112u8, 97u8, 114u8, 115u8, 101u8, 0u8, 0u8, 255u8, 254u8, 0u8, + 0u8, 2u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 14u8, 0u8, 0u8, 0u8, 1u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 2u8, 2u8, 2u8, 3u8, 4u8, 4u8, 5u8, 6u8, 7u8, 7u8, 7u8, 7u8, + 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, + 7u8, 7u8, 7u8, 8u8, 9u8, 9u8, 9u8, 10u8, 11u8, 11u8, 12u8, 13u8, 14u8, 14u8, + 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, + 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, + 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 16u8, 16u8, 16u8, + 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, + 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, + 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, + 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 18u8, 18u8, 19u8, 19u8, 19u8, 19u8, 19u8, + 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, + 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 20u8, + 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 22u8, + 23u8, 23u8, 24u8, 25u8, 25u8, 25u8, 26u8, 27u8, 27u8, 27u8, 27u8, 27u8, 27u8, + 27u8, 27u8, 27u8, 27u8, 27u8, 40u8, 1u8, 0u8, 0u8, 1u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 1u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 128u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 5u8, + 0u8, 5u8, 5u8, 6u8, 6u8, 12u8, 12u8, 13u8, 13u8, 0u8, 0u8, 83u8, 0u8, 0u8, 0u8, + 68u8, 0u8, 0u8, 0u8, 83u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 2u8, 0u8, 0u8, 27u8, 0u8, 0u8, 18u8, 0u8, 0u8, 0u8, 18u8, 0u8, 0u8, + 0u8, 0u8, 3u8, 0u8, 6u8, 6u8, 13u8, 13u8, 0u8, 0u8, 104u8, 0u8, 0u8, 0u8, + 104u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 14u8, 0u8, 0u8, 0u8, 2u8, 2u8, + 4u8, 7u8, 9u8, 9u8, 11u8, 14u8, 19u8, 19u8, 20u8, 20u8, 21u8, 21u8, 22u8, 22u8, + 23u8, 23u8, 24u8, 24u8, 25u8, 25u8, 26u8, 26u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, + 68u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, + 0u8, 191u8, 0u8, 0u8, 0u8, 206u8, 0u8, 0u8, 0u8, 221u8, 0u8, 0u8, 0u8, 236u8, + 0u8, 0u8, 0u8, 221u8, 0u8, 0u8, 0u8, 251u8, 0u8, 0u8, 0u8, 10u8, 1u8, 0u8, 0u8, + 25u8, 1u8, 0u8, 0u8, 18u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 17u8, 0u8, 0u8, + 68u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 17u8, 17u8, 0u8, 0u8, + 191u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 17u8, 0u8, 0u8, + 191u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 16u8, 0u8, 0u8, + 191u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 16u8, 17u8, 0u8, 0u8, + 221u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 17u8, 0u8, 0u8, + 221u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 15u8, 0u8, 0u8, + 221u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 4u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 35u8, + 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 9u8, 0u8, 0u8, 0u8, 18u8, 0u8, 0u8, 0u8, + 18u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, + 0u8, 35u8, 0u8, 0u8, 0u8, + ]) + }, + pattern: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" e ", 3u8) + }, + }), + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" y ", 3u8) + }, + special_case: Some(::icu_list::provider::SpecialCasePattern { + condition: unsafe { + ::icu_list::provider::StringMatcher::from_dfa_bytes_unchecked(&[ + 114u8, 117u8, 115u8, 116u8, 45u8, 114u8, 101u8, 103u8, 101u8, 120u8, 45u8, + 97u8, 117u8, 116u8, 111u8, 109u8, 97u8, 116u8, 97u8, 45u8, 100u8, 102u8, 97u8, + 45u8, 115u8, 112u8, 97u8, 114u8, 115u8, 101u8, 0u8, 0u8, 255u8, 254u8, 0u8, + 0u8, 2u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 14u8, 0u8, 0u8, 0u8, 1u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 2u8, 2u8, 2u8, 3u8, 4u8, 4u8, 5u8, 6u8, 7u8, 7u8, 7u8, 7u8, + 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, + 7u8, 7u8, 7u8, 8u8, 9u8, 9u8, 9u8, 10u8, 11u8, 11u8, 12u8, 13u8, 14u8, 14u8, + 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, + 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, + 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 16u8, 16u8, 16u8, + 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, + 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, + 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, + 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 18u8, 18u8, 19u8, 19u8, 19u8, 19u8, 19u8, + 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, + 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 20u8, + 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 22u8, + 23u8, 23u8, 24u8, 25u8, 25u8, 25u8, 26u8, 27u8, 27u8, 27u8, 27u8, 27u8, 27u8, + 27u8, 27u8, 27u8, 27u8, 27u8, 40u8, 1u8, 0u8, 0u8, 1u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 1u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 128u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 5u8, + 0u8, 5u8, 5u8, 6u8, 6u8, 12u8, 12u8, 13u8, 13u8, 0u8, 0u8, 83u8, 0u8, 0u8, 0u8, + 68u8, 0u8, 0u8, 0u8, 83u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 2u8, 0u8, 0u8, 27u8, 0u8, 0u8, 18u8, 0u8, 0u8, 0u8, 18u8, 0u8, 0u8, + 0u8, 0u8, 3u8, 0u8, 6u8, 6u8, 13u8, 13u8, 0u8, 0u8, 104u8, 0u8, 0u8, 0u8, + 104u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 14u8, 0u8, 0u8, 0u8, 2u8, 2u8, + 4u8, 7u8, 9u8, 9u8, 11u8, 14u8, 19u8, 19u8, 20u8, 20u8, 21u8, 21u8, 22u8, 22u8, + 23u8, 23u8, 24u8, 24u8, 25u8, 25u8, 26u8, 26u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, + 68u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, + 0u8, 191u8, 0u8, 0u8, 0u8, 206u8, 0u8, 0u8, 0u8, 221u8, 0u8, 0u8, 0u8, 236u8, + 0u8, 0u8, 0u8, 221u8, 0u8, 0u8, 0u8, 251u8, 0u8, 0u8, 0u8, 10u8, 1u8, 0u8, 0u8, + 25u8, 1u8, 0u8, 0u8, 18u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 17u8, 0u8, 0u8, + 68u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 17u8, 17u8, 0u8, 0u8, + 191u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 17u8, 0u8, 0u8, + 191u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 16u8, 0u8, 0u8, + 191u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 16u8, 17u8, 0u8, 0u8, + 221u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 17u8, 0u8, 0u8, + 221u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 15u8, 0u8, 0u8, + 221u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 4u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 35u8, + 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 9u8, 0u8, 0u8, 0u8, 18u8, 0u8, 0u8, 0u8, + 18u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, + 0u8, 35u8, 0u8, 0u8, 0u8, + ]) + }, + pattern: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" e ", 3u8) + }, + }), + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" y ", 3u8) + }, + special_case: Some(::icu_list::provider::SpecialCasePattern { + condition: unsafe { + ::icu_list::provider::StringMatcher::from_dfa_bytes_unchecked(&[ + 114u8, 117u8, 115u8, 116u8, 45u8, 114u8, 101u8, 103u8, 101u8, 120u8, 45u8, + 97u8, 117u8, 116u8, 111u8, 109u8, 97u8, 116u8, 97u8, 45u8, 100u8, 102u8, 97u8, + 45u8, 115u8, 112u8, 97u8, 114u8, 115u8, 101u8, 0u8, 0u8, 255u8, 254u8, 0u8, + 0u8, 2u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 14u8, 0u8, 0u8, 0u8, 1u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 2u8, 2u8, 2u8, 3u8, 4u8, 4u8, 5u8, 6u8, 7u8, 7u8, 7u8, 7u8, + 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, 7u8, + 7u8, 7u8, 7u8, 8u8, 9u8, 9u8, 9u8, 10u8, 11u8, 11u8, 12u8, 13u8, 14u8, 14u8, + 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, + 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 14u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, + 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 15u8, 16u8, 16u8, 16u8, + 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, 16u8, + 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, + 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, + 17u8, 17u8, 17u8, 17u8, 17u8, 17u8, 18u8, 18u8, 19u8, 19u8, 19u8, 19u8, 19u8, + 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, + 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 19u8, 20u8, + 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 21u8, 22u8, + 23u8, 23u8, 24u8, 25u8, 25u8, 25u8, 26u8, 27u8, 27u8, 27u8, 27u8, 27u8, 27u8, + 27u8, 27u8, 27u8, 27u8, 27u8, 40u8, 1u8, 0u8, 0u8, 1u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 1u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 128u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 5u8, + 0u8, 5u8, 5u8, 6u8, 6u8, 12u8, 12u8, 13u8, 13u8, 0u8, 0u8, 83u8, 0u8, 0u8, 0u8, + 68u8, 0u8, 0u8, 0u8, 83u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 2u8, 0u8, 0u8, 27u8, 0u8, 0u8, 18u8, 0u8, 0u8, 0u8, 18u8, 0u8, 0u8, + 0u8, 0u8, 3u8, 0u8, 6u8, 6u8, 13u8, 13u8, 0u8, 0u8, 104u8, 0u8, 0u8, 0u8, + 104u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 14u8, 0u8, 0u8, 0u8, 2u8, 2u8, + 4u8, 7u8, 9u8, 9u8, 11u8, 14u8, 19u8, 19u8, 20u8, 20u8, 21u8, 21u8, 22u8, 22u8, + 23u8, 23u8, 24u8, 24u8, 25u8, 25u8, 26u8, 26u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, + 68u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, 0u8, 68u8, 0u8, 0u8, + 0u8, 191u8, 0u8, 0u8, 0u8, 206u8, 0u8, 0u8, 0u8, 221u8, 0u8, 0u8, 0u8, 236u8, + 0u8, 0u8, 0u8, 221u8, 0u8, 0u8, 0u8, 251u8, 0u8, 0u8, 0u8, 10u8, 1u8, 0u8, 0u8, + 25u8, 1u8, 0u8, 0u8, 18u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 17u8, 0u8, 0u8, + 68u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 17u8, 17u8, 0u8, 0u8, + 191u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 17u8, 0u8, 0u8, + 191u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 16u8, 0u8, 0u8, + 191u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 16u8, 17u8, 0u8, 0u8, + 221u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 17u8, 0u8, 0u8, + 221u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 15u8, 15u8, 0u8, 0u8, + 221u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 4u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 35u8, + 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, 0u8, 9u8, 0u8, 0u8, 0u8, 18u8, 0u8, 0u8, 0u8, + 18u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 35u8, 0u8, 0u8, + 0u8, 35u8, 0u8, 0u8, 0u8, + ]) + }, + pattern: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" e ", 3u8) + }, + }), + }, +]); +static FR: &DataStruct = &::icu_list::provider::ListFormatterPatternsV1([ + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" et ", 4u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" et ", 4u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" et ", 4u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" et ", 4u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, +]); +static IT: &DataStruct = &::icu_list::provider::ListFormatterPatternsV1([ + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" e ", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" e ", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" e ", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" e ", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" e ", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" e ", 3u8) + }, + special_case: None, + }, +]); +static JA: &DataStruct = &::icu_list::provider::ListFormatterPatternsV1([ + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, +]); +static PT: &DataStruct = &::icu_list::provider::ListFormatterPatternsV1([ + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" e ", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" e ", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" e ", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" e ", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, +]); +static RU: &DataStruct = &::icu_list::provider::ListFormatterPatternsV1([ + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" и ", 4u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" и ", 4u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" и ", 4u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" и ", 4u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, +]); +static TR: &DataStruct = &::icu_list::provider::ListFormatterPatternsV1([ + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" ve ", 4u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" ve ", 4u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" ve ", 4u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(" ve ", 4u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, +]); +static UND: &DataStruct = &::icu_list::provider::ListFormatterPatternsV1([ + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked(", ", 2u8) + }, + special_case: None, + }, +]); +static ZH_HANS: &DataStruct = &::icu_list::provider::ListFormatterPatternsV1([ + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("和", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("和", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("和", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("和", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, +]); +static ZH_HANT: &DataStruct = &::icu_list::provider::ListFormatterPatternsV1([ + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("和", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("和", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("和", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("和", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("和", 3u8) + }, + special_case: None, + }, + ::icu_list::provider::ConditionalListJoinerPattern { + default: unsafe { + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("和", 3u8) + }, + special_case: None, + }, +]); diff --git a/compiler/rustc_baked_icu_data/src/data/list/mod.rs b/compiler/rustc_baked_icu_data/src/data/list/mod.rs new file mode 100644 index 0000000000000..931822513cc06 --- /dev/null +++ b/compiler/rustc_baked_icu_data/src/data/list/mod.rs @@ -0,0 +1,2 @@ +// @generated +pub mod and_v1; diff --git a/compiler/rustc_baked_icu_data/src/data/mod.rs b/compiler/rustc_baked_icu_data/src/data/mod.rs new file mode 100644 index 0000000000000..8ffacffaf4998 --- /dev/null +++ b/compiler/rustc_baked_icu_data/src/data/mod.rs @@ -0,0 +1,25 @@ +// @generated +mod list; +/// This data provider was programmatically generated by [`icu_datagen`]( +/// https://unicode-org.github.io/icu4x-docs/doc/icu_datagen/enum.Out.html#variant.Module). +#[non_exhaustive] +pub struct BakedDataProvider; +use ::icu_provider::prelude::*; +impl DataProvider<::icu_list::provider::AndListV1Marker> for BakedDataProvider { + fn load( + &self, + req: DataRequest, + ) -> Result, DataError> { + Ok(DataResponse { + metadata: Default::default(), + payload: Some(DataPayload::from_owned(zerofrom::ZeroFrom::zero_from( + *list::and_v1::DATA + .get_by(|k| req.locale.strict_cmp(k.as_bytes()).reverse()) + .ok_or_else(|| { + DataErrorKind::MissingLocale + .with_req(::icu_list::provider::AndListV1Marker::KEY, req) + })?, + ))), + }) + } +} diff --git a/compiler/rustc_baked_icu_data/src/lib.rs b/compiler/rustc_baked_icu_data/src/lib.rs new file mode 100644 index 0000000000000..0eff969e14a3c --- /dev/null +++ b/compiler/rustc_baked_icu_data/src/lib.rs @@ -0,0 +1,17 @@ +//! Baked ICU data for eager translation support. +//! +#![allow(elided_lifetimes_in_paths)] + +// generated with: +// ```text +// icu4x-datagen -W --pretty --fingerprint --use-separate-crates --cldr-tag latest --icuexport-tag latest \ +// --format mod -l en es fr it ja pt ru tr zh-Hans zh-Hant -k list/and@1 -o src/data +// ``` + +mod data; + +pub use data::BakedDataProvider; + +pub fn baked_data_provider() -> BakedDataProvider { + data::BakedDataProvider +} diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index f1f5a1941579b..76d278667f5a9 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -133,6 +133,10 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "hashbrown", "hermit-abi", "humantime", + "icu_list", + "icu_locid", + "icu_provider", + "icu_provider_macros", "if_chain", "indexmap", "instant", @@ -145,6 +149,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "libc", "libloading", "libz-sys", + "litemap", "lock_api", "log", "matchers", @@ -253,9 +258,16 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "winapi-i686-pc-windows-gnu", "winapi-util", "winapi-x86_64-pc-windows-gnu", + "writeable", // this is a false-positive: it's only used by rustfmt, but because it's enabled through a // feature, tidy thinks it's used by rustc as well. "yansi-term", + "yoke", + "yoke-derive", + "zerofrom", + "zerofrom-derive", + "zerovec", + "zerovec-derive", ]; const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[ From a775004322df90a564c58e702364c10e6f0192a4 Mon Sep 17 00:00:00 2001 From: Charles Lew Date: Sun, 6 Nov 2022 14:43:25 +0800 Subject: [PATCH 072/103] Migrate diagnostics list output to use icu list formatter. --- Cargo.lock | 176 +++++++++++++++++- compiler/rustc_baked_icu_data/Cargo.toml | 1 + compiler/rustc_baked_icu_data/src/lib.rs | 26 ++- compiler/rustc_error_messages/Cargo.toml | 5 + compiler/rustc_error_messages/src/lib.rs | 92 ++++++++- compiler/rustc_errors/src/diagnostic.rs | 3 + compiler/rustc_errors/src/diagnostic_impls.rs | 21 +-- 7 files changed, 296 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e1359b9e9e402..c9a6a40d04b81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -211,7 +211,7 @@ checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" dependencies = [ "lazy_static", "memchr", - "regex-automata", + "regex-automata 0.1.10", ] [[package]] @@ -1707,6 +1707,73 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c1ad908cc71012b7bea4d0c53ba96a8cba9962f048fa68d143376143d863b7a" +[[package]] +name = "icu_list" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c40218275f081c4493f190357c5395647b06734c2dc3dcb41cc099a0f60168b1" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider", + "regex-automata 0.2.0", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34b3de5d99a0e275fe6193b9586dbf37364daebc0d39c89b5cf8376a53b789e8" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_provider" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f911086e3c521a8a824d4f8bfd87769645ced2f07ff913b521c0d793be07100" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_adapters" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "980c71d8a91b246ebbb97847178a4b816eea39d1d550c70ee566384555bb6545" +dependencies = [ + "icu_locid", + "icu_provider", + "tinystr", + "yoke", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38cf6f5b65cf81f0b4298da647101acbfe6ae0e25263f92bd7a22597e9d6d606" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "idna" version = "0.2.0" @@ -2034,6 +2101,12 @@ dependencies = [ "walkdir", ] +[[package]] +name = "litemap" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f34a3f4798fac63fb48cf277eefa38f94d3443baff555bb98e4f56bc9092368e" + [[package]] name = "lld-wrapper" version = "0.1.0" @@ -2100,7 +2173,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" dependencies = [ - "regex-automata", + "regex-automata 0.1.10", ] [[package]] @@ -2927,6 +3000,15 @@ dependencies = [ "regex-syntax", ] +[[package]] +name = "regex-automata" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9368763f5a9b804326f3af749e16f9abf378d227bcdee7634b13d8f17793782" +dependencies = [ + "memchr", +] + [[package]] name = "regex-syntax" version = "0.6.26" @@ -3202,6 +3284,16 @@ dependencies = [ "rustc_span", ] +[[package]] +name = "rustc_baked_icu_data" +version = "0.0.0" +dependencies = [ + "icu_list", + "icu_locid", + "icu_provider", + "litemap", +] + [[package]] name = "rustc_borrowck" version = "0.0.0" @@ -3422,13 +3514,18 @@ version = "0.0.0" dependencies = [ "fluent-bundle", "fluent-syntax", + "icu_list", + "icu_locid", + "icu_provider_adapters", "intl-memoizer", + "rustc_baked_icu_data", "rustc_data_structures", "rustc_macros", "rustc_serialize", "rustc_span", "tracing", "unic-langid", + "writeable", ] [[package]] @@ -4934,6 +5031,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8aeafdfd935e4a7fe16a91ab711fa52d54df84f9c8f7ca5837a9d1d902ef4c2" dependencies = [ "displaydoc", + "zerovec", ] [[package]] @@ -5546,6 +5644,12 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" +[[package]] +name = "writeable" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8e6ab4f5da1b24daf2c590cfac801bacb27b15b4f050e84eb60149ea726f06b" + [[package]] name = "xattr" version = "0.2.2" @@ -5598,3 +5702,71 @@ checksum = "fe5c30ade05e61656247b2e334a031dfd0cc466fadef865bdcdea8d537951bf1" dependencies = [ "winapi", ] + +[[package]] +name = "yoke" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fe1d55ca72c32d573bfbd5cb2f0ca65a497854c44762957a6d3da96041a5184" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1346e4cd025ae818b88566eac7eb65ab33a994ea55f355c86889af2e7e56b14e" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerofrom" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79e9355fccf72b04b7deaa99ce7a0f6630530acf34045391b74460fcd714de54" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e8aa86add9ddbd2409c1ed01e033cd457d79b1b1229b64922c25095c595e829" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerovec" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d919a74c17749ccb17beaf6405562e413cd94e98ba52ca1e64bbe7eefbd8b8" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "490e5f878c2856225e884c35927e7ea6db3c24cdb7229b72542c7526ad7ed49e" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] diff --git a/compiler/rustc_baked_icu_data/Cargo.toml b/compiler/rustc_baked_icu_data/Cargo.toml index c4b49e939e91c..6fe7ab8ea0da1 100644 --- a/compiler/rustc_baked_icu_data/Cargo.toml +++ b/compiler/rustc_baked_icu_data/Cargo.toml @@ -5,5 +5,6 @@ edition = "2021" [dependencies] icu_list = "1.0.0" +icu_locid = "1.0.0" icu_provider = "1.0.1" litemap = "0.6.0" diff --git a/compiler/rustc_baked_icu_data/src/lib.rs b/compiler/rustc_baked_icu_data/src/lib.rs index 0eff969e14a3c..76c9bc97346f5 100644 --- a/compiler/rustc_baked_icu_data/src/lib.rs +++ b/compiler/rustc_baked_icu_data/src/lib.rs @@ -2,16 +2,30 @@ //! #![allow(elided_lifetimes_in_paths)] -// generated with: -// ```text -// icu4x-datagen -W --pretty --fingerprint --use-separate-crates --cldr-tag latest --icuexport-tag latest \ -// --format mod -l en es fr it ja pt ru tr zh-Hans zh-Hant -k list/and@1 -o src/data -// ``` +/* generated with: +```text +icu4x-datagen -W --pretty --fingerprint --use-separate-crates --cldr-tag latest --icuexport-tag latest \ +--format mod -l en es fr it ja pt ru tr zh-Hans zh-Hant -k list/and@1 -o src/data +``` +*/ mod data; pub use data::BakedDataProvider; -pub fn baked_data_provider() -> BakedDataProvider { +pub const fn baked_data_provider() -> BakedDataProvider { data::BakedDataProvider } + +pub mod supported_locales { + pub const EN: icu_locid::Locale = icu_locid::locale!("en"); + pub const ES: icu_locid::Locale = icu_locid::locale!("es"); + pub const FR: icu_locid::Locale = icu_locid::locale!("fr"); + pub const IT: icu_locid::Locale = icu_locid::locale!("it"); + pub const JA: icu_locid::Locale = icu_locid::locale!("ja"); + pub const PT: icu_locid::Locale = icu_locid::locale!("pt"); + pub const RU: icu_locid::Locale = icu_locid::locale!("ru"); + pub const TR: icu_locid::Locale = icu_locid::locale!("tr"); + pub const ZH_HANS: icu_locid::Locale = icu_locid::locale!("zh-Hans"); + pub const ZH_HANT: icu_locid::Locale = icu_locid::locale!("zh-Hant"); +} diff --git a/compiler/rustc_error_messages/Cargo.toml b/compiler/rustc_error_messages/Cargo.toml index 9945f337995d3..bb6edfb090325 100644 --- a/compiler/rustc_error_messages/Cargo.toml +++ b/compiler/rustc_error_messages/Cargo.toml @@ -9,9 +9,14 @@ edition = "2021" fluent-bundle = "0.15.2" fluent-syntax = "0.11" intl-memoizer = "0.5.1" +rustc_baked_icu_data = { path = "../rustc_baked_icu_data" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_serialize = { path = "../rustc_serialize" } rustc_span = { path = "../rustc_span" } rustc_macros = { path = "../rustc_macros" } tracing = "0.1" unic-langid = { version = "0.9.0", features = ["macros"] } +icu_list = "1.0.0" +writeable = "0.5.0" +icu_locid = "1.0.0" +icu_provider_adapters = "1.0.0" diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs index 0b1b75471a661..d026f5c8daf30 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -10,6 +10,7 @@ extern crate tracing; use fluent_bundle::FluentResource; use fluent_syntax::parser::ParserError; +use icu_provider_adapters::fallback::{LocaleFallbackProvider, LocaleFallbacker}; use rustc_data_structures::sync::Lrc; use rustc_macros::{fluent_messages, Decodable, Encodable}; use rustc_span::Span; @@ -30,8 +31,7 @@ use intl_memoizer::concurrent::IntlLangMemoizer; #[cfg(not(parallel_compiler))] use intl_memoizer::IntlLangMemoizer; -pub use fluent_bundle::{self, FluentArgs, FluentError, FluentValue}; - +pub use fluent_bundle::{self, types::FluentType, FluentArgs, FluentError, FluentValue}; pub use unic_langid::{langid, LanguageIdentifier}; // Generates `DEFAULT_LOCALE_RESOURCES` static and `fluent_generated` module. @@ -541,3 +541,91 @@ impl From> for MultiSpan { MultiSpan::from_spans(spans) } } + +fn icu_locale_from_unic_langid(lang: LanguageIdentifier) -> Option { + icu_locid::Locale::try_from_bytes(lang.to_string().as_bytes()).ok() +} + +pub fn fluent_value_from_str_list_sep_by_and<'source>( + l: Vec>, +) -> FluentValue<'source> { + // Fluent requires 'static value here for its AnyEq usages. + #[derive(Clone, PartialEq, Debug)] + struct FluentStrListSepByAnd(Vec); + + impl FluentType for FluentStrListSepByAnd { + fn duplicate(&self) -> Box { + Box::new(self.clone()) + } + + fn as_string(&self, intls: &intl_memoizer::IntlLangMemoizer) -> Cow<'static, str> { + let result = intls + .with_try_get::((), |list_formatter| { + list_formatter.format_to_string(self.0.iter()) + }) + .unwrap(); + Cow::Owned(result) + } + + #[cfg(not(parallel_compiler))] + fn as_string_threadsafe( + &self, + _intls: &intl_memoizer::concurrent::IntlLangMemoizer, + ) -> Cow<'static, str> { + unreachable!("`as_string_threadsafe` is not used in non-parallel rustc") + } + + #[cfg(parallel_compiler)] + fn as_string_threadsafe( + &self, + intls: &intl_memoizer::concurrent::IntlLangMemoizer, + ) -> Cow<'static, str> { + let result = intls + .with_try_get::((), |list_formatter| { + list_formatter.format_to_string(self.0.iter()) + }) + .unwrap(); + Cow::Owned(result) + } + } + + struct MemoizableListFormatter(icu_list::ListFormatter); + + impl std::ops::Deref for MemoizableListFormatter { + type Target = icu_list::ListFormatter; + fn deref(&self) -> &Self::Target { + &self.0 + } + } + + impl intl_memoizer::Memoizable for MemoizableListFormatter { + type Args = (); + type Error = (); + + fn construct(lang: LanguageIdentifier, _args: Self::Args) -> Result + where + Self: Sized, + { + let baked_data_provider = rustc_baked_icu_data::baked_data_provider(); + let locale_fallbacker = LocaleFallbacker::try_new_unstable(&baked_data_provider); + let data_provider = LocaleFallbackProvider::new_with_fallbacker( + &baked_data_provider, + locale_fallbacker, + ); + let locale = icu_locale_from_unic_langid(lang) + .unwrap_or_else(|| rustc_baked_icu_data::supported_locales::EN); + let list_formatter = icu_list::ListFormatter::try_new_and_with_length_unstable( + &data_provider, + &locale.into(), + icu_list::ListLength::Wide, + ) + .expect("Failed to create list formatter"); + + Ok(MemoizableListFormatter(list_formatter)) + } + } + + let l = l.into_iter().map(|x| x.into_owned()).collect(); + + FluentValue::Custom(Box::new(FluentStrListSepByAnd(l))) +} diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 66c986977eccb..2c1d0037aa64f 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -4,6 +4,7 @@ use crate::{ SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle, }; use rustc_data_structures::fx::FxHashMap; +use rustc_error_messages::fluent_value_from_str_list_sep_by_and; use rustc_error_messages::FluentValue; use rustc_lint_defs::{Applicability, LintExpectationId}; use rustc_span::edition::LATEST_STABLE_EDITION; @@ -34,6 +35,7 @@ pub type DiagnosticArgName<'source> = Cow<'source, str>; pub enum DiagnosticArgValue<'source> { Str(Cow<'source, str>), Number(usize), + StrListSepByAnd(Vec>), } /// Converts a value of a type into a `DiagnosticArg` (typically a field of an `IntoDiagnostic` @@ -58,6 +60,7 @@ impl<'source> Into> for DiagnosticArgValue<'source> { match self { DiagnosticArgValue::Str(s) => From::from(s), DiagnosticArgValue::Number(n) => From::from(n), + DiagnosticArgValue::StrListSepByAnd(l) => fluent_value_from_str_list_sep_by_and(l), } } } diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs index c6035705e39fa..6716339eaa48f 100644 --- a/compiler/rustc_errors/src/diagnostic_impls.rs +++ b/compiler/rustc_errors/src/diagnostic_impls.rs @@ -11,7 +11,6 @@ use rustc_target::abi::TargetDataLayoutErrors; use rustc_target::spec::{PanicStrategy, SplitDebuginfo, StackProtector, TargetTriple}; use std::borrow::Cow; use std::fmt; -use std::fmt::Write; use std::num::ParseIntError; use std::path::{Path, PathBuf}; use std::process::ExitStatus; @@ -191,23 +190,9 @@ impl From> for DiagnosticSymbolList { impl IntoDiagnosticArg for DiagnosticSymbolList { fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { - // FIXME: replace the logic here with a real list formatter - let symbols = match &self.0[..] { - [symbol] => format!("`{symbol}`"), - [symbol, last] => { - format!("`{symbol}` and `{last}`",) - } - [symbols @ .., last] => { - let mut result = String::new(); - for symbol in symbols { - write!(result, "`{symbol}`, ").unwrap(); - } - write!(result, "and `{last}`").unwrap(); - result - } - [] => unreachable!(), - }; - DiagnosticArgValue::Str(Cow::Owned(symbols)) + DiagnosticArgValue::StrListSepByAnd( + self.0.into_iter().map(|sym| Cow::Owned(format!("`{sym}`"))).collect(), + ) } } From bde2f9857b478c3863fd8b0bdbc3ff667dac8f41 Mon Sep 17 00:00:00 2001 From: Charles Lew Date: Sun, 6 Nov 2022 14:58:22 +0800 Subject: [PATCH 073/103] Import icu locale fallback data --- Cargo.lock | 2 + compiler/rustc_baked_icu_data/Cargo.toml | 2 + compiler/rustc_baked_icu_data/src/data/any.rs | 24 + .../src/data/fallback/likelysubtags_v1.rs | 733 ++++++++++++++++++ .../src/data/fallback/mod.rs | 4 + .../src/data/fallback/parents_v1.rs | 207 +++++ .../src/data/fallback/supplement/co_v1.rs | 41 + .../src/data/fallback/supplement/mod.rs | 2 + compiler/rustc_baked_icu_data/src/data/mod.rs | 65 ++ compiler/rustc_baked_icu_data/src/lib.rs | 20 +- compiler/rustc_error_messages/src/lib.rs | 23 +- src/tools/tidy/src/deps.rs | 1 + 12 files changed, 1111 insertions(+), 13 deletions(-) create mode 100644 compiler/rustc_baked_icu_data/src/data/fallback/likelysubtags_v1.rs create mode 100644 compiler/rustc_baked_icu_data/src/data/fallback/mod.rs create mode 100644 compiler/rustc_baked_icu_data/src/data/fallback/parents_v1.rs create mode 100644 compiler/rustc_baked_icu_data/src/data/fallback/supplement/co_v1.rs create mode 100644 compiler/rustc_baked_icu_data/src/data/fallback/supplement/mod.rs diff --git a/Cargo.lock b/Cargo.lock index c9a6a40d04b81..fbd81d833814c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3291,7 +3291,9 @@ dependencies = [ "icu_list", "icu_locid", "icu_provider", + "icu_provider_adapters", "litemap", + "zerovec", ] [[package]] diff --git a/compiler/rustc_baked_icu_data/Cargo.toml b/compiler/rustc_baked_icu_data/Cargo.toml index 6fe7ab8ea0da1..6486491d07739 100644 --- a/compiler/rustc_baked_icu_data/Cargo.toml +++ b/compiler/rustc_baked_icu_data/Cargo.toml @@ -7,4 +7,6 @@ edition = "2021" icu_list = "1.0.0" icu_locid = "1.0.0" icu_provider = "1.0.1" +icu_provider_adapters = "1.0.0" litemap = "0.6.0" +zerovec = "0.9.0" diff --git a/compiler/rustc_baked_icu_data/src/data/any.rs b/compiler/rustc_baked_icu_data/src/data/any.rs index be5be6e03b85e..e8e99be93f2c5 100644 --- a/compiler/rustc_baked_icu_data/src/data/any.rs +++ b/compiler/rustc_baked_icu_data/src/data/any.rs @@ -3,6 +3,15 @@ impl AnyProvider for BakedDataProvider { fn load_any(&self, key: DataKey, req: DataRequest) -> Result { const ANDLISTV1MARKER: ::icu_provider::DataKeyHash = ::icu_list::provider::AndListV1Marker::KEY.hashed(); + const COLLATIONFALLBACKSUPPLEMENTV1MARKER: ::icu_provider::DataKeyHash = + ::icu_provider_adapters::fallback::provider::CollationFallbackSupplementV1Marker::KEY + .hashed(); + const LOCALEFALLBACKLIKELYSUBTAGSV1MARKER: ::icu_provider::DataKeyHash = + ::icu_provider_adapters::fallback::provider::LocaleFallbackLikelySubtagsV1Marker::KEY + .hashed(); + const LOCALEFALLBACKPARENTSV1MARKER: ::icu_provider::DataKeyHash = + ::icu_provider_adapters::fallback::provider::LocaleFallbackParentsV1Marker::KEY + .hashed(); #[allow(clippy::match_single_binding)] match key.hashed() { ANDLISTV1MARKER => list::and_v1::DATA @@ -10,6 +19,21 @@ impl AnyProvider for BakedDataProvider { .copied() .map(AnyPayload::from_static_ref) .ok_or(DataErrorKind::MissingLocale), + COLLATIONFALLBACKSUPPLEMENTV1MARKER => fallback::supplement::co_v1::DATA + .get_by(|k| req.locale.strict_cmp(k.as_bytes()).reverse()) + .copied() + .map(AnyPayload::from_static_ref) + .ok_or(DataErrorKind::MissingLocale), + LOCALEFALLBACKLIKELYSUBTAGSV1MARKER => fallback::likelysubtags_v1::DATA + .get_by(|k| req.locale.strict_cmp(k.as_bytes()).reverse()) + .copied() + .map(AnyPayload::from_static_ref) + .ok_or(DataErrorKind::MissingLocale), + LOCALEFALLBACKPARENTSV1MARKER => fallback::parents_v1::DATA + .get_by(|k| req.locale.strict_cmp(k.as_bytes()).reverse()) + .copied() + .map(AnyPayload::from_static_ref) + .ok_or(DataErrorKind::MissingLocale), _ => Err(DataErrorKind::MissingDataKey), } .map_err(|e| e.with_req(key, req)) diff --git a/compiler/rustc_baked_icu_data/src/data/fallback/likelysubtags_v1.rs b/compiler/rustc_baked_icu_data/src/data/fallback/likelysubtags_v1.rs new file mode 100644 index 0000000000000..0a90c832e8c79 --- /dev/null +++ b/compiler/rustc_baked_icu_data/src/data/fallback/likelysubtags_v1.rs @@ -0,0 +1,733 @@ +// @generated +type DataStruct = < :: icu_provider_adapters :: fallback :: provider :: LocaleFallbackLikelySubtagsV1Marker as :: icu_provider :: DataMarker > :: Yokeable ; +pub static DATA: litemap::LiteMap<&str, &DataStruct, &[(&str, &DataStruct)]> = + litemap::LiteMap::from_sorted_store_unchecked(&[("und", UND)]); +static UND: &DataStruct = + &::icu_provider_adapters::fallback::provider::LocaleFallbackLikelySubtagsV1 { + l2s: unsafe { + #[allow(unused_unsafe)] + ::zerovec::ZeroMap::from_parts_unchecked( + unsafe { + ::zerovec::ZeroVec::from_bytes_unchecked(&[ + 97u8, 98u8, 0u8, 97u8, 98u8, 113u8, 97u8, 100u8, 112u8, 97u8, 100u8, 121u8, + 97u8, 101u8, 0u8, 97u8, 101u8, 98u8, 97u8, 104u8, 111u8, 97u8, 106u8, + 116u8, 97u8, 107u8, 107u8, 97u8, 108u8, 116u8, 97u8, 109u8, 0u8, 97u8, + 112u8, 99u8, 97u8, 112u8, 100u8, 97u8, 114u8, 0u8, 97u8, 114u8, 99u8, 97u8, + 114u8, 113u8, 97u8, 114u8, 115u8, 97u8, 114u8, 121u8, 97u8, 114u8, 122u8, + 97u8, 115u8, 0u8, 97u8, 115u8, 101u8, 97u8, 118u8, 0u8, 97u8, 118u8, 108u8, + 97u8, 119u8, 97u8, 98u8, 97u8, 0u8, 98u8, 97u8, 108u8, 98u8, 97u8, 112u8, + 98u8, 97u8, 120u8, 98u8, 99u8, 113u8, 98u8, 101u8, 0u8, 98u8, 101u8, 106u8, + 98u8, 102u8, 113u8, 98u8, 102u8, 116u8, 98u8, 102u8, 121u8, 98u8, 103u8, + 0u8, 98u8, 103u8, 99u8, 98u8, 103u8, 110u8, 98u8, 103u8, 120u8, 98u8, + 104u8, 98u8, 98u8, 104u8, 105u8, 98u8, 104u8, 111u8, 98u8, 106u8, 105u8, + 98u8, 106u8, 106u8, 98u8, 108u8, 116u8, 98u8, 110u8, 0u8, 98u8, 111u8, 0u8, + 98u8, 112u8, 121u8, 98u8, 113u8, 105u8, 98u8, 114u8, 97u8, 98u8, 114u8, + 104u8, 98u8, 114u8, 120u8, 98u8, 115u8, 113u8, 98u8, 115u8, 116u8, 98u8, + 116u8, 118u8, 98u8, 117u8, 97u8, 98u8, 121u8, 110u8, 99u8, 99u8, 112u8, + 99u8, 101u8, 0u8, 99u8, 104u8, 109u8, 99u8, 104u8, 114u8, 99u8, 106u8, + 97u8, 99u8, 106u8, 109u8, 99u8, 107u8, 98u8, 99u8, 109u8, 103u8, 99u8, + 111u8, 112u8, 99u8, 114u8, 0u8, 99u8, 114u8, 104u8, 99u8, 114u8, 107u8, + 99u8, 114u8, 108u8, 99u8, 115u8, 119u8, 99u8, 116u8, 100u8, 99u8, 117u8, + 0u8, 99u8, 118u8, 0u8, 100u8, 97u8, 114u8, 100u8, 99u8, 99u8, 100u8, 103u8, + 108u8, 100u8, 109u8, 102u8, 100u8, 111u8, 105u8, 100u8, 114u8, 104u8, + 100u8, 114u8, 115u8, 100u8, 116u8, 121u8, 100u8, 118u8, 0u8, 100u8, 122u8, + 0u8, 101u8, 103u8, 121u8, 101u8, 107u8, 121u8, 101u8, 108u8, 0u8, 101u8, + 115u8, 103u8, 101u8, 116u8, 116u8, 102u8, 97u8, 0u8, 102u8, 105u8, 97u8, + 102u8, 117u8, 98u8, 103u8, 97u8, 110u8, 103u8, 98u8, 109u8, 103u8, 98u8, + 122u8, 103u8, 101u8, 122u8, 103u8, 103u8, 110u8, 103u8, 106u8, 107u8, + 103u8, 106u8, 117u8, 103u8, 108u8, 107u8, 103u8, 109u8, 118u8, 103u8, + 111u8, 102u8, 103u8, 111u8, 109u8, 103u8, 111u8, 110u8, 103u8, 111u8, + 116u8, 103u8, 114u8, 99u8, 103u8, 114u8, 116u8, 103u8, 117u8, 0u8, 103u8, + 118u8, 114u8, 103u8, 119u8, 99u8, 103u8, 119u8, 116u8, 104u8, 97u8, 107u8, + 104u8, 97u8, 122u8, 104u8, 100u8, 121u8, 104u8, 101u8, 0u8, 104u8, 105u8, + 0u8, 104u8, 108u8, 117u8, 104u8, 109u8, 100u8, 104u8, 110u8, 100u8, 104u8, + 110u8, 101u8, 104u8, 110u8, 106u8, 104u8, 110u8, 111u8, 104u8, 111u8, 99u8, + 104u8, 111u8, 106u8, 104u8, 115u8, 110u8, 104u8, 121u8, 0u8, 105u8, 105u8, + 0u8, 105u8, 110u8, 104u8, 105u8, 117u8, 0u8, 105u8, 119u8, 0u8, 106u8, + 97u8, 0u8, 106u8, 105u8, 0u8, 106u8, 109u8, 108u8, 107u8, 97u8, 0u8, 107u8, + 97u8, 97u8, 107u8, 97u8, 119u8, 107u8, 98u8, 100u8, 107u8, 98u8, 121u8, + 107u8, 100u8, 116u8, 107u8, 102u8, 114u8, 107u8, 102u8, 121u8, 107u8, + 104u8, 98u8, 107u8, 104u8, 110u8, 107u8, 104u8, 116u8, 107u8, 104u8, 119u8, + 107u8, 106u8, 103u8, 107u8, 107u8, 0u8, 107u8, 109u8, 0u8, 107u8, 110u8, + 0u8, 107u8, 111u8, 0u8, 107u8, 111u8, 105u8, 107u8, 111u8, 107u8, 107u8, + 113u8, 121u8, 107u8, 114u8, 99u8, 107u8, 114u8, 117u8, 107u8, 115u8, 0u8, + 107u8, 116u8, 98u8, 107u8, 117u8, 109u8, 107u8, 118u8, 0u8, 107u8, 118u8, + 120u8, 107u8, 120u8, 99u8, 107u8, 120u8, 108u8, 107u8, 120u8, 109u8, 107u8, + 120u8, 112u8, 107u8, 121u8, 0u8, 107u8, 122u8, 104u8, 108u8, 97u8, 98u8, + 108u8, 97u8, 100u8, 108u8, 97u8, 104u8, 108u8, 98u8, 101u8, 108u8, 99u8, + 112u8, 108u8, 101u8, 112u8, 108u8, 101u8, 122u8, 108u8, 105u8, 102u8, + 108u8, 105u8, 115u8, 108u8, 107u8, 105u8, 108u8, 109u8, 110u8, 108u8, + 111u8, 0u8, 108u8, 114u8, 99u8, 108u8, 117u8, 122u8, 108u8, 119u8, 108u8, + 108u8, 122u8, 104u8, 109u8, 97u8, 103u8, 109u8, 97u8, 105u8, 109u8, 100u8, + 101u8, 109u8, 100u8, 102u8, 109u8, 100u8, 120u8, 109u8, 102u8, 97u8, 109u8, + 103u8, 112u8, 109u8, 107u8, 0u8, 109u8, 107u8, 105u8, 109u8, 108u8, 0u8, + 109u8, 110u8, 0u8, 109u8, 110u8, 105u8, 109u8, 110u8, 119u8, 109u8, 114u8, + 0u8, 109u8, 114u8, 100u8, 109u8, 114u8, 106u8, 109u8, 114u8, 111u8, 109u8, + 116u8, 114u8, 109u8, 118u8, 121u8, 109u8, 119u8, 114u8, 109u8, 119u8, + 119u8, 109u8, 121u8, 0u8, 109u8, 121u8, 109u8, 109u8, 121u8, 118u8, 109u8, + 121u8, 122u8, 109u8, 122u8, 110u8, 110u8, 97u8, 110u8, 110u8, 101u8, 0u8, + 110u8, 101u8, 119u8, 110u8, 110u8, 112u8, 110u8, 111u8, 100u8, 110u8, + 111u8, 101u8, 110u8, 111u8, 110u8, 110u8, 113u8, 111u8, 110u8, 115u8, + 107u8, 110u8, 115u8, 116u8, 111u8, 106u8, 0u8, 111u8, 106u8, 115u8, 111u8, + 114u8, 0u8, 111u8, 114u8, 117u8, 111u8, 115u8, 0u8, 111u8, 115u8, 97u8, + 111u8, 116u8, 97u8, 111u8, 116u8, 107u8, 111u8, 117u8, 105u8, 112u8, 97u8, + 0u8, 112u8, 97u8, 108u8, 112u8, 101u8, 111u8, 112u8, 104u8, 108u8, 112u8, + 104u8, 110u8, 112u8, 107u8, 97u8, 112u8, 110u8, 116u8, 112u8, 112u8, 97u8, + 112u8, 114u8, 97u8, 112u8, 114u8, 100u8, 112u8, 115u8, 0u8, 114u8, 97u8, + 106u8, 114u8, 104u8, 103u8, 114u8, 105u8, 102u8, 114u8, 106u8, 115u8, + 114u8, 107u8, 116u8, 114u8, 109u8, 116u8, 114u8, 117u8, 0u8, 114u8, 117u8, + 101u8, 114u8, 121u8, 117u8, 115u8, 97u8, 0u8, 115u8, 97u8, 104u8, 115u8, + 97u8, 116u8, 115u8, 97u8, 122u8, 115u8, 99u8, 107u8, 115u8, 99u8, 108u8, + 115u8, 100u8, 0u8, 115u8, 100u8, 104u8, 115u8, 103u8, 97u8, 115u8, 103u8, + 119u8, 115u8, 104u8, 105u8, 115u8, 104u8, 110u8, 115u8, 104u8, 117u8, + 115u8, 105u8, 0u8, 115u8, 107u8, 114u8, 115u8, 109u8, 112u8, 115u8, 111u8, + 103u8, 115u8, 111u8, 117u8, 115u8, 114u8, 0u8, 115u8, 114u8, 98u8, 115u8, + 114u8, 120u8, 115u8, 119u8, 98u8, 115u8, 119u8, 118u8, 115u8, 121u8, 108u8, + 115u8, 121u8, 114u8, 116u8, 97u8, 0u8, 116u8, 97u8, 106u8, 116u8, 99u8, + 121u8, 116u8, 100u8, 100u8, 116u8, 100u8, 103u8, 116u8, 100u8, 104u8, + 116u8, 101u8, 0u8, 116u8, 103u8, 0u8, 116u8, 104u8, 0u8, 116u8, 104u8, + 108u8, 116u8, 104u8, 113u8, 116u8, 104u8, 114u8, 116u8, 105u8, 0u8, 116u8, + 105u8, 103u8, 116u8, 107u8, 116u8, 116u8, 114u8, 119u8, 116u8, 115u8, + 100u8, 116u8, 115u8, 102u8, 116u8, 115u8, 106u8, 116u8, 116u8, 0u8, 116u8, + 116u8, 115u8, 116u8, 120u8, 103u8, 116u8, 120u8, 111u8, 116u8, 121u8, + 118u8, 117u8, 100u8, 105u8, 117u8, 100u8, 109u8, 117u8, 103u8, 0u8, 117u8, + 103u8, 97u8, 117u8, 107u8, 0u8, 117u8, 110u8, 114u8, 117u8, 110u8, 120u8, + 117u8, 114u8, 0u8, 118u8, 97u8, 105u8, 119u8, 97u8, 108u8, 119u8, 98u8, + 113u8, 119u8, 98u8, 114u8, 119u8, 110u8, 105u8, 119u8, 115u8, 103u8, 119u8, + 116u8, 109u8, 119u8, 117u8, 117u8, 120u8, 99u8, 111u8, 120u8, 99u8, 114u8, + 120u8, 108u8, 99u8, 120u8, 108u8, 100u8, 120u8, 109u8, 102u8, 120u8, 109u8, + 110u8, 120u8, 109u8, 114u8, 120u8, 110u8, 97u8, 120u8, 110u8, 114u8, 120u8, + 112u8, 114u8, 120u8, 115u8, 97u8, 120u8, 115u8, 114u8, 121u8, 105u8, 0u8, + 121u8, 117u8, 101u8, 122u8, 100u8, 106u8, 122u8, 103u8, 104u8, 122u8, + 104u8, 0u8, 122u8, 104u8, 120u8, 122u8, 107u8, 116u8, + ]) + }, + unsafe { + ::zerovec::ZeroVec::from_bytes_unchecked(&[ + 67u8, 121u8, 114u8, 108u8, 67u8, 121u8, 114u8, 108u8, 84u8, 105u8, 98u8, + 116u8, 67u8, 121u8, 114u8, 108u8, 65u8, 118u8, 115u8, 116u8, 65u8, 114u8, + 97u8, 98u8, 65u8, 104u8, 111u8, 109u8, 65u8, 114u8, 97u8, 98u8, 88u8, + 115u8, 117u8, 120u8, 67u8, 121u8, 114u8, 108u8, 69u8, 116u8, 104u8, 105u8, + 65u8, 114u8, 97u8, 98u8, 65u8, 114u8, 97u8, 98u8, 65u8, 114u8, 97u8, 98u8, + 65u8, 114u8, 109u8, 105u8, 65u8, 114u8, 97u8, 98u8, 65u8, 114u8, 97u8, + 98u8, 65u8, 114u8, 97u8, 98u8, 65u8, 114u8, 97u8, 98u8, 66u8, 101u8, 110u8, + 103u8, 83u8, 103u8, 110u8, 119u8, 67u8, 121u8, 114u8, 108u8, 65u8, 114u8, + 97u8, 98u8, 68u8, 101u8, 118u8, 97u8, 67u8, 121u8, 114u8, 108u8, 65u8, + 114u8, 97u8, 98u8, 68u8, 101u8, 118u8, 97u8, 66u8, 97u8, 109u8, 117u8, + 69u8, 116u8, 104u8, 105u8, 67u8, 121u8, 114u8, 108u8, 65u8, 114u8, 97u8, + 98u8, 84u8, 97u8, 109u8, 108u8, 65u8, 114u8, 97u8, 98u8, 68u8, 101u8, + 118u8, 97u8, 67u8, 121u8, 114u8, 108u8, 68u8, 101u8, 118u8, 97u8, 65u8, + 114u8, 97u8, 98u8, 71u8, 114u8, 101u8, 107u8, 68u8, 101u8, 118u8, 97u8, + 68u8, 101u8, 118u8, 97u8, 68u8, 101u8, 118u8, 97u8, 69u8, 116u8, 104u8, + 105u8, 68u8, 101u8, 118u8, 97u8, 84u8, 97u8, 118u8, 116u8, 66u8, 101u8, + 110u8, 103u8, 84u8, 105u8, 98u8, 116u8, 66u8, 101u8, 110u8, 103u8, 65u8, + 114u8, 97u8, 98u8, 68u8, 101u8, 118u8, 97u8, 65u8, 114u8, 97u8, 98u8, 68u8, + 101u8, 118u8, 97u8, 66u8, 97u8, 115u8, 115u8, 69u8, 116u8, 104u8, 105u8, + 68u8, 101u8, 118u8, 97u8, 67u8, 121u8, 114u8, 108u8, 69u8, 116u8, 104u8, + 105u8, 67u8, 97u8, 107u8, 109u8, 67u8, 121u8, 114u8, 108u8, 67u8, 121u8, + 114u8, 108u8, 67u8, 104u8, 101u8, 114u8, 65u8, 114u8, 97u8, 98u8, 67u8, + 104u8, 97u8, 109u8, 65u8, 114u8, 97u8, 98u8, 83u8, 111u8, 121u8, 111u8, + 67u8, 111u8, 112u8, 116u8, 67u8, 97u8, 110u8, 115u8, 67u8, 121u8, 114u8, + 108u8, 67u8, 97u8, 110u8, 115u8, 67u8, 97u8, 110u8, 115u8, 67u8, 97u8, + 110u8, 115u8, 80u8, 97u8, 117u8, 99u8, 67u8, 121u8, 114u8, 108u8, 67u8, + 121u8, 114u8, 108u8, 67u8, 121u8, 114u8, 108u8, 65u8, 114u8, 97u8, 98u8, + 65u8, 114u8, 97u8, 98u8, 77u8, 101u8, 100u8, 102u8, 68u8, 101u8, 118u8, + 97u8, 77u8, 111u8, 110u8, 103u8, 69u8, 116u8, 104u8, 105u8, 68u8, 101u8, + 118u8, 97u8, 84u8, 104u8, 97u8, 97u8, 84u8, 105u8, 98u8, 116u8, 69u8, + 103u8, 121u8, 112u8, 75u8, 97u8, 108u8, 105u8, 71u8, 114u8, 101u8, 107u8, + 71u8, 111u8, 110u8, 109u8, 73u8, 116u8, 97u8, 108u8, 65u8, 114u8, 97u8, + 98u8, 65u8, 114u8, 97u8, 98u8, 65u8, 114u8, 97u8, 98u8, 72u8, 97u8, 110u8, + 115u8, 68u8, 101u8, 118u8, 97u8, 65u8, 114u8, 97u8, 98u8, 69u8, 116u8, + 104u8, 105u8, 68u8, 101u8, 118u8, 97u8, 65u8, 114u8, 97u8, 98u8, 65u8, + 114u8, 97u8, 98u8, 65u8, 114u8, 97u8, 98u8, 69u8, 116u8, 104u8, 105u8, + 69u8, 116u8, 104u8, 105u8, 68u8, 101u8, 118u8, 97u8, 84u8, 101u8, 108u8, + 117u8, 71u8, 111u8, 116u8, 104u8, 67u8, 112u8, 114u8, 116u8, 66u8, 101u8, + 110u8, 103u8, 71u8, 117u8, 106u8, 114u8, 68u8, 101u8, 118u8, 97u8, 65u8, + 114u8, 97u8, 98u8, 65u8, 114u8, 97u8, 98u8, 72u8, 97u8, 110u8, 115u8, 65u8, + 114u8, 97u8, 98u8, 69u8, 116u8, 104u8, 105u8, 72u8, 101u8, 98u8, 114u8, + 68u8, 101u8, 118u8, 97u8, 72u8, 108u8, 117u8, 119u8, 80u8, 108u8, 114u8, + 100u8, 65u8, 114u8, 97u8, 98u8, 68u8, 101u8, 118u8, 97u8, 72u8, 109u8, + 110u8, 112u8, 65u8, 114u8, 97u8, 98u8, 68u8, 101u8, 118u8, 97u8, 68u8, + 101u8, 118u8, 97u8, 72u8, 97u8, 110u8, 115u8, 65u8, 114u8, 109u8, 110u8, + 89u8, 105u8, 105u8, 105u8, 67u8, 121u8, 114u8, 108u8, 67u8, 97u8, 110u8, + 115u8, 72u8, 101u8, 98u8, 114u8, 74u8, 112u8, 97u8, 110u8, 72u8, 101u8, + 98u8, 114u8, 68u8, 101u8, 118u8, 97u8, 71u8, 101u8, 111u8, 114u8, 67u8, + 121u8, 114u8, 108u8, 75u8, 97u8, 119u8, 105u8, 67u8, 121u8, 114u8, 108u8, + 65u8, 114u8, 97u8, 98u8, 84u8, 104u8, 97u8, 105u8, 68u8, 101u8, 118u8, + 97u8, 68u8, 101u8, 118u8, 97u8, 84u8, 97u8, 108u8, 117u8, 68u8, 101u8, + 118u8, 97u8, 77u8, 121u8, 109u8, 114u8, 65u8, 114u8, 97u8, 98u8, 76u8, + 97u8, 111u8, 111u8, 67u8, 121u8, 114u8, 108u8, 75u8, 104u8, 109u8, 114u8, + 75u8, 110u8, 100u8, 97u8, 75u8, 111u8, 114u8, 101u8, 67u8, 121u8, 114u8, + 108u8, 68u8, 101u8, 118u8, 97u8, 69u8, 116u8, 104u8, 105u8, 67u8, 121u8, + 114u8, 108u8, 68u8, 101u8, 118u8, 97u8, 65u8, 114u8, 97u8, 98u8, 69u8, + 116u8, 104u8, 105u8, 67u8, 121u8, 114u8, 108u8, 67u8, 121u8, 114u8, 108u8, + 65u8, 114u8, 97u8, 98u8, 69u8, 116u8, 104u8, 105u8, 68u8, 101u8, 118u8, + 97u8, 84u8, 104u8, 97u8, 105u8, 65u8, 114u8, 97u8, 98u8, 67u8, 121u8, + 114u8, 108u8, 65u8, 114u8, 97u8, 98u8, 76u8, 105u8, 110u8, 97u8, 72u8, + 101u8, 98u8, 114u8, 65u8, 114u8, 97u8, 98u8, 67u8, 121u8, 114u8, 108u8, + 84u8, 104u8, 97u8, 105u8, 76u8, 101u8, 112u8, 99u8, 67u8, 121u8, 114u8, + 108u8, 68u8, 101u8, 118u8, 97u8, 76u8, 105u8, 115u8, 117u8, 65u8, 114u8, + 97u8, 98u8, 84u8, 101u8, 108u8, 117u8, 76u8, 97u8, 111u8, 111u8, 65u8, + 114u8, 97u8, 98u8, 65u8, 114u8, 97u8, 98u8, 84u8, 104u8, 97u8, 105u8, 72u8, + 97u8, 110u8, 115u8, 68u8, 101u8, 118u8, 97u8, 68u8, 101u8, 118u8, 97u8, + 65u8, 114u8, 97u8, 98u8, 67u8, 121u8, 114u8, 108u8, 69u8, 116u8, 104u8, + 105u8, 65u8, 114u8, 97u8, 98u8, 68u8, 101u8, 118u8, 97u8, 67u8, 121u8, + 114u8, 108u8, 65u8, 114u8, 97u8, 98u8, 77u8, 108u8, 121u8, 109u8, 67u8, + 121u8, 114u8, 108u8, 66u8, 101u8, 110u8, 103u8, 77u8, 121u8, 109u8, 114u8, + 68u8, 101u8, 118u8, 97u8, 68u8, 101u8, 118u8, 97u8, 67u8, 121u8, 114u8, + 108u8, 77u8, 114u8, 111u8, 111u8, 68u8, 101u8, 118u8, 97u8, 65u8, 114u8, + 97u8, 98u8, 68u8, 101u8, 118u8, 97u8, 72u8, 109u8, 110u8, 112u8, 77u8, + 121u8, 109u8, 114u8, 69u8, 116u8, 104u8, 105u8, 67u8, 121u8, 114u8, 108u8, + 77u8, 97u8, 110u8, 100u8, 65u8, 114u8, 97u8, 98u8, 72u8, 97u8, 110u8, + 115u8, 68u8, 101u8, 118u8, 97u8, 68u8, 101u8, 118u8, 97u8, 87u8, 99u8, + 104u8, 111u8, 76u8, 97u8, 110u8, 97u8, 68u8, 101u8, 118u8, 97u8, 82u8, + 117u8, 110u8, 114u8, 78u8, 107u8, 111u8, 111u8, 67u8, 97u8, 110u8, 115u8, + 84u8, 110u8, 115u8, 97u8, 67u8, 97u8, 110u8, 115u8, 67u8, 97u8, 110u8, + 115u8, 79u8, 114u8, 121u8, 97u8, 65u8, 114u8, 97u8, 98u8, 67u8, 121u8, + 114u8, 108u8, 79u8, 115u8, 103u8, 101u8, 65u8, 114u8, 97u8, 98u8, 79u8, + 114u8, 107u8, 104u8, 79u8, 117u8, 103u8, 114u8, 71u8, 117u8, 114u8, 117u8, + 80u8, 104u8, 108u8, 105u8, 88u8, 112u8, 101u8, 111u8, 65u8, 114u8, 97u8, + 98u8, 80u8, 104u8, 110u8, 120u8, 66u8, 114u8, 97u8, 104u8, 71u8, 114u8, + 101u8, 107u8, 68u8, 101u8, 118u8, 97u8, 75u8, 104u8, 97u8, 114u8, 65u8, + 114u8, 97u8, 98u8, 65u8, 114u8, 97u8, 98u8, 68u8, 101u8, 118u8, 97u8, 82u8, + 111u8, 104u8, 103u8, 84u8, 102u8, 110u8, 103u8, 68u8, 101u8, 118u8, 97u8, + 66u8, 101u8, 110u8, 103u8, 65u8, 114u8, 97u8, 98u8, 67u8, 121u8, 114u8, + 108u8, 67u8, 121u8, 114u8, 108u8, 75u8, 97u8, 110u8, 97u8, 68u8, 101u8, + 118u8, 97u8, 67u8, 121u8, 114u8, 108u8, 79u8, 108u8, 99u8, 107u8, 83u8, + 97u8, 117u8, 114u8, 68u8, 101u8, 118u8, 97u8, 65u8, 114u8, 97u8, 98u8, + 65u8, 114u8, 97u8, 98u8, 65u8, 114u8, 97u8, 98u8, 79u8, 103u8, 97u8, 109u8, + 69u8, 116u8, 104u8, 105u8, 84u8, 102u8, 110u8, 103u8, 77u8, 121u8, 109u8, + 114u8, 65u8, 114u8, 97u8, 98u8, 83u8, 105u8, 110u8, 104u8, 65u8, 114u8, + 97u8, 98u8, 83u8, 97u8, 109u8, 114u8, 83u8, 111u8, 103u8, 100u8, 84u8, + 104u8, 97u8, 105u8, 67u8, 121u8, 114u8, 108u8, 83u8, 111u8, 114u8, 97u8, + 68u8, 101u8, 118u8, 97u8, 65u8, 114u8, 97u8, 98u8, 68u8, 101u8, 118u8, + 97u8, 66u8, 101u8, 110u8, 103u8, 83u8, 121u8, 114u8, 99u8, 84u8, 97u8, + 109u8, 108u8, 68u8, 101u8, 118u8, 97u8, 75u8, 110u8, 100u8, 97u8, 84u8, + 97u8, 108u8, 101u8, 68u8, 101u8, 118u8, 97u8, 68u8, 101u8, 118u8, 97u8, + 84u8, 101u8, 108u8, 117u8, 67u8, 121u8, 114u8, 108u8, 84u8, 104u8, 97u8, + 105u8, 68u8, 101u8, 118u8, 97u8, 68u8, 101u8, 118u8, 97u8, 68u8, 101u8, + 118u8, 97u8, 69u8, 116u8, 104u8, 105u8, 69u8, 116u8, 104u8, 105u8, 68u8, + 101u8, 118u8, 97u8, 65u8, 114u8, 97u8, 98u8, 71u8, 114u8, 101u8, 107u8, + 68u8, 101u8, 118u8, 97u8, 84u8, 105u8, 98u8, 116u8, 67u8, 121u8, 114u8, + 108u8, 84u8, 104u8, 97u8, 105u8, 84u8, 97u8, 110u8, 103u8, 84u8, 111u8, + 116u8, 111u8, 67u8, 121u8, 114u8, 108u8, 65u8, 103u8, 104u8, 98u8, 67u8, + 121u8, 114u8, 108u8, 65u8, 114u8, 97u8, 98u8, 85u8, 103u8, 97u8, 114u8, + 67u8, 121u8, 114u8, 108u8, 66u8, 101u8, 110u8, 103u8, 66u8, 101u8, 110u8, + 103u8, 65u8, 114u8, 97u8, 98u8, 86u8, 97u8, 105u8, 105u8, 69u8, 116u8, + 104u8, 105u8, 84u8, 101u8, 108u8, 117u8, 68u8, 101u8, 118u8, 97u8, 65u8, + 114u8, 97u8, 98u8, 71u8, 111u8, 110u8, 103u8, 68u8, 101u8, 118u8, 97u8, + 72u8, 97u8, 110u8, 115u8, 67u8, 104u8, 114u8, 115u8, 67u8, 97u8, 114u8, + 105u8, 76u8, 121u8, 99u8, 105u8, 76u8, 121u8, 100u8, 105u8, 71u8, 101u8, + 111u8, 114u8, 77u8, 97u8, 110u8, 105u8, 77u8, 101u8, 114u8, 99u8, 78u8, + 97u8, 114u8, 98u8, 68u8, 101u8, 118u8, 97u8, 80u8, 114u8, 116u8, 105u8, + 83u8, 97u8, 114u8, 98u8, 68u8, 101u8, 118u8, 97u8, 72u8, 101u8, 98u8, + 114u8, 72u8, 97u8, 110u8, 116u8, 65u8, 114u8, 97u8, 98u8, 84u8, 102u8, + 110u8, 103u8, 72u8, 97u8, 110u8, 115u8, 78u8, 115u8, 104u8, 117u8, 75u8, + 105u8, 116u8, 115u8, + ]) + }, + ) + }, + lr2s: unsafe { + #[allow(unused_unsafe)] + ::zerovec::ZeroMap2d::from_parts_unchecked( + unsafe { + ::zerovec::ZeroVec::from_bytes_unchecked(&[ + 97u8, 122u8, 0u8, 104u8, 97u8, 0u8, 107u8, 107u8, 0u8, 107u8, 117u8, 0u8, + 107u8, 121u8, 0u8, 109u8, 97u8, 110u8, 109u8, 110u8, 0u8, 109u8, 115u8, + 0u8, 112u8, 97u8, 0u8, 114u8, 105u8, 102u8, 115u8, 100u8, 0u8, 115u8, + 114u8, 0u8, 116u8, 103u8, 0u8, 117u8, 103u8, 0u8, 117u8, 110u8, 114u8, + 117u8, 122u8, 0u8, 121u8, 117u8, 101u8, 122u8, 104u8, 0u8, + ]) + }, + unsafe { + ::zerovec::ZeroVec::from_bytes_unchecked(&[ + 3u8, 0u8, 0u8, 0u8, 5u8, 0u8, 0u8, 0u8, 9u8, 0u8, 0u8, 0u8, 10u8, 0u8, 0u8, + 0u8, 12u8, 0u8, 0u8, 0u8, 13u8, 0u8, 0u8, 0u8, 14u8, 0u8, 0u8, 0u8, 15u8, + 0u8, 0u8, 0u8, 16u8, 0u8, 0u8, 0u8, 17u8, 0u8, 0u8, 0u8, 18u8, 0u8, 0u8, + 0u8, 22u8, 0u8, 0u8, 0u8, 23u8, 0u8, 0u8, 0u8, 25u8, 0u8, 0u8, 0u8, 26u8, + 0u8, 0u8, 0u8, 28u8, 0u8, 0u8, 0u8, 29u8, 0u8, 0u8, 0u8, 44u8, 0u8, 0u8, + 0u8, + ]) + }, + unsafe { + ::zerovec::ZeroVec::from_bytes_unchecked(&[ + 73u8, 81u8, 0u8, 73u8, 82u8, 0u8, 82u8, 85u8, 0u8, 67u8, 77u8, 0u8, 83u8, + 68u8, 0u8, 65u8, 70u8, 0u8, 67u8, 78u8, 0u8, 73u8, 82u8, 0u8, 77u8, 78u8, + 0u8, 76u8, 66u8, 0u8, 67u8, 78u8, 0u8, 84u8, 82u8, 0u8, 71u8, 78u8, 0u8, + 67u8, 78u8, 0u8, 67u8, 67u8, 0u8, 80u8, 75u8, 0u8, 78u8, 76u8, 0u8, 73u8, + 78u8, 0u8, 77u8, 69u8, 0u8, 82u8, 79u8, 0u8, 82u8, 85u8, 0u8, 84u8, 82u8, + 0u8, 80u8, 75u8, 0u8, 75u8, 90u8, 0u8, 77u8, 78u8, 0u8, 78u8, 80u8, 0u8, + 65u8, 70u8, 0u8, 67u8, 78u8, 0u8, 67u8, 78u8, 0u8, 65u8, 85u8, 0u8, 66u8, + 78u8, 0u8, 71u8, 66u8, 0u8, 71u8, 70u8, 0u8, 72u8, 75u8, 0u8, 73u8, 68u8, + 0u8, 77u8, 79u8, 0u8, 80u8, 65u8, 0u8, 80u8, 70u8, 0u8, 80u8, 72u8, 0u8, + 83u8, 82u8, 0u8, 84u8, 72u8, 0u8, 84u8, 87u8, 0u8, 85u8, 83u8, 0u8, 86u8, + 78u8, 0u8, + ]) + }, + unsafe { + ::zerovec::ZeroVec::from_bytes_unchecked(&[ + 65u8, 114u8, 97u8, 98u8, 65u8, 114u8, 97u8, 98u8, 67u8, 121u8, 114u8, + 108u8, 65u8, 114u8, 97u8, 98u8, 65u8, 114u8, 97u8, 98u8, 65u8, 114u8, 97u8, + 98u8, 65u8, 114u8, 97u8, 98u8, 65u8, 114u8, 97u8, 98u8, 65u8, 114u8, 97u8, + 98u8, 65u8, 114u8, 97u8, 98u8, 65u8, 114u8, 97u8, 98u8, 76u8, 97u8, 116u8, + 110u8, 78u8, 107u8, 111u8, 111u8, 77u8, 111u8, 110u8, 103u8, 65u8, 114u8, + 97u8, 98u8, 65u8, 114u8, 97u8, 98u8, 76u8, 97u8, 116u8, 110u8, 68u8, 101u8, + 118u8, 97u8, 76u8, 97u8, 116u8, 110u8, 76u8, 97u8, 116u8, 110u8, 76u8, + 97u8, 116u8, 110u8, 76u8, 97u8, 116u8, 110u8, 65u8, 114u8, 97u8, 98u8, + 67u8, 121u8, 114u8, 108u8, 67u8, 121u8, 114u8, 108u8, 68u8, 101u8, 118u8, + 97u8, 65u8, 114u8, 97u8, 98u8, 67u8, 121u8, 114u8, 108u8, 72u8, 97u8, + 110u8, 115u8, 72u8, 97u8, 110u8, 116u8, 72u8, 97u8, 110u8, 116u8, 72u8, + 97u8, 110u8, 116u8, 72u8, 97u8, 110u8, 116u8, 72u8, 97u8, 110u8, 116u8, + 72u8, 97u8, 110u8, 116u8, 72u8, 97u8, 110u8, 116u8, 72u8, 97u8, 110u8, + 116u8, 72u8, 97u8, 110u8, 116u8, 72u8, 97u8, 110u8, 116u8, 72u8, 97u8, + 110u8, 116u8, 72u8, 97u8, 110u8, 116u8, 72u8, 97u8, 110u8, 116u8, 72u8, + 97u8, 110u8, 116u8, 72u8, 97u8, 110u8, 116u8, + ]) + }, + ) + }, + l2r: unsafe { + #[allow(unused_unsafe)] + ::zerovec::ZeroMap::from_parts_unchecked( + unsafe { + ::zerovec::ZeroVec::from_bytes_unchecked(&[ + 97u8, 97u8, 0u8, 97u8, 98u8, 0u8, 97u8, 98u8, 114u8, 97u8, 99u8, 101u8, + 97u8, 99u8, 104u8, 97u8, 100u8, 97u8, 97u8, 100u8, 112u8, 97u8, 100u8, + 121u8, 97u8, 101u8, 0u8, 97u8, 101u8, 98u8, 97u8, 102u8, 0u8, 97u8, 103u8, + 113u8, 97u8, 104u8, 111u8, 97u8, 106u8, 116u8, 97u8, 107u8, 0u8, 97u8, + 107u8, 107u8, 97u8, 108u8, 110u8, 97u8, 108u8, 116u8, 97u8, 109u8, 0u8, + 97u8, 109u8, 111u8, 97u8, 110u8, 0u8, 97u8, 110u8, 110u8, 97u8, 111u8, + 122u8, 97u8, 112u8, 100u8, 97u8, 114u8, 0u8, 97u8, 114u8, 99u8, 97u8, + 114u8, 110u8, 97u8, 114u8, 111u8, 97u8, 114u8, 113u8, 97u8, 114u8, 115u8, + 97u8, 114u8, 121u8, 97u8, 114u8, 122u8, 97u8, 115u8, 0u8, 97u8, 115u8, + 97u8, 97u8, 115u8, 101u8, 97u8, 115u8, 116u8, 97u8, 116u8, 106u8, 97u8, + 118u8, 0u8, 97u8, 119u8, 97u8, 97u8, 121u8, 0u8, 97u8, 122u8, 0u8, 98u8, + 97u8, 0u8, 98u8, 97u8, 108u8, 98u8, 97u8, 110u8, 98u8, 97u8, 112u8, 98u8, + 97u8, 114u8, 98u8, 97u8, 115u8, 98u8, 97u8, 120u8, 98u8, 98u8, 99u8, 98u8, + 98u8, 106u8, 98u8, 99u8, 105u8, 98u8, 101u8, 0u8, 98u8, 101u8, 106u8, 98u8, + 101u8, 109u8, 98u8, 101u8, 119u8, 98u8, 101u8, 122u8, 98u8, 102u8, 100u8, + 98u8, 102u8, 113u8, 98u8, 102u8, 116u8, 98u8, 102u8, 121u8, 98u8, 103u8, + 0u8, 98u8, 103u8, 99u8, 98u8, 103u8, 110u8, 98u8, 103u8, 120u8, 98u8, + 104u8, 98u8, 98u8, 104u8, 105u8, 98u8, 104u8, 111u8, 98u8, 105u8, 0u8, + 98u8, 105u8, 107u8, 98u8, 105u8, 110u8, 98u8, 106u8, 106u8, 98u8, 106u8, + 110u8, 98u8, 106u8, 116u8, 98u8, 107u8, 109u8, 98u8, 107u8, 117u8, 98u8, + 108u8, 97u8, 98u8, 108u8, 103u8, 98u8, 108u8, 116u8, 98u8, 109u8, 0u8, + 98u8, 109u8, 113u8, 98u8, 110u8, 0u8, 98u8, 111u8, 0u8, 98u8, 112u8, 121u8, + 98u8, 113u8, 105u8, 98u8, 113u8, 118u8, 98u8, 114u8, 0u8, 98u8, 114u8, + 97u8, 98u8, 114u8, 104u8, 98u8, 114u8, 120u8, 98u8, 115u8, 0u8, 98u8, + 115u8, 113u8, 98u8, 115u8, 115u8, 98u8, 116u8, 111u8, 98u8, 116u8, 118u8, + 98u8, 117u8, 97u8, 98u8, 117u8, 99u8, 98u8, 117u8, 103u8, 98u8, 117u8, + 109u8, 98u8, 118u8, 98u8, 98u8, 121u8, 110u8, 98u8, 121u8, 118u8, 98u8, + 122u8, 101u8, 99u8, 97u8, 0u8, 99u8, 97u8, 100u8, 99u8, 99u8, 104u8, 99u8, + 99u8, 112u8, 99u8, 101u8, 0u8, 99u8, 101u8, 98u8, 99u8, 103u8, 103u8, 99u8, + 104u8, 0u8, 99u8, 104u8, 107u8, 99u8, 104u8, 109u8, 99u8, 104u8, 111u8, + 99u8, 104u8, 112u8, 99u8, 104u8, 114u8, 99u8, 105u8, 99u8, 99u8, 106u8, + 97u8, 99u8, 106u8, 109u8, 99u8, 107u8, 98u8, 99u8, 108u8, 99u8, 99u8, + 109u8, 103u8, 99u8, 111u8, 0u8, 99u8, 111u8, 112u8, 99u8, 112u8, 115u8, + 99u8, 114u8, 0u8, 99u8, 114u8, 103u8, 99u8, 114u8, 104u8, 99u8, 114u8, + 107u8, 99u8, 114u8, 108u8, 99u8, 114u8, 115u8, 99u8, 115u8, 0u8, 99u8, + 115u8, 98u8, 99u8, 115u8, 119u8, 99u8, 116u8, 100u8, 99u8, 117u8, 0u8, + 99u8, 118u8, 0u8, 99u8, 121u8, 0u8, 100u8, 97u8, 0u8, 100u8, 97u8, 102u8, + 100u8, 97u8, 107u8, 100u8, 97u8, 114u8, 100u8, 97u8, 118u8, 100u8, 99u8, + 99u8, 100u8, 101u8, 0u8, 100u8, 101u8, 110u8, 100u8, 103u8, 114u8, 100u8, + 106u8, 101u8, 100u8, 109u8, 102u8, 100u8, 110u8, 106u8, 100u8, 111u8, + 105u8, 100u8, 114u8, 104u8, 100u8, 115u8, 98u8, 100u8, 116u8, 109u8, 100u8, + 116u8, 112u8, 100u8, 116u8, 121u8, 100u8, 117u8, 97u8, 100u8, 118u8, 0u8, + 100u8, 121u8, 111u8, 100u8, 121u8, 117u8, 100u8, 122u8, 0u8, 101u8, 98u8, + 117u8, 101u8, 101u8, 0u8, 101u8, 102u8, 105u8, 101u8, 103u8, 108u8, 101u8, + 103u8, 121u8, 101u8, 107u8, 121u8, 101u8, 108u8, 0u8, 101u8, 110u8, 0u8, + 101u8, 111u8, 0u8, 101u8, 115u8, 0u8, 101u8, 115u8, 103u8, 101u8, 115u8, + 117u8, 101u8, 116u8, 0u8, 101u8, 116u8, 116u8, 101u8, 117u8, 0u8, 101u8, + 119u8, 111u8, 101u8, 120u8, 116u8, 102u8, 97u8, 0u8, 102u8, 97u8, 110u8, + 102u8, 102u8, 0u8, 102u8, 102u8, 109u8, 102u8, 105u8, 0u8, 102u8, 105u8, + 97u8, 102u8, 105u8, 108u8, 102u8, 105u8, 116u8, 102u8, 106u8, 0u8, 102u8, + 111u8, 0u8, 102u8, 111u8, 110u8, 102u8, 114u8, 0u8, 102u8, 114u8, 99u8, + 102u8, 114u8, 112u8, 102u8, 114u8, 114u8, 102u8, 114u8, 115u8, 102u8, + 117u8, 98u8, 102u8, 117u8, 100u8, 102u8, 117u8, 102u8, 102u8, 117u8, 113u8, + 102u8, 117u8, 114u8, 102u8, 117u8, 118u8, 102u8, 118u8, 114u8, 102u8, + 121u8, 0u8, 103u8, 97u8, 0u8, 103u8, 97u8, 97u8, 103u8, 97u8, 103u8, 103u8, + 97u8, 110u8, 103u8, 97u8, 121u8, 103u8, 98u8, 109u8, 103u8, 98u8, 122u8, + 103u8, 99u8, 114u8, 103u8, 100u8, 0u8, 103u8, 101u8, 122u8, 103u8, 103u8, + 110u8, 103u8, 105u8, 108u8, 103u8, 106u8, 107u8, 103u8, 106u8, 117u8, + 103u8, 108u8, 0u8, 103u8, 108u8, 107u8, 103u8, 110u8, 0u8, 103u8, 111u8, + 109u8, 103u8, 111u8, 110u8, 103u8, 111u8, 114u8, 103u8, 111u8, 115u8, + 103u8, 111u8, 116u8, 103u8, 114u8, 99u8, 103u8, 114u8, 116u8, 103u8, 115u8, + 119u8, 103u8, 117u8, 0u8, 103u8, 117u8, 98u8, 103u8, 117u8, 99u8, 103u8, + 117u8, 114u8, 103u8, 117u8, 122u8, 103u8, 118u8, 0u8, 103u8, 118u8, 114u8, + 103u8, 119u8, 105u8, 104u8, 97u8, 0u8, 104u8, 97u8, 107u8, 104u8, 97u8, + 119u8, 104u8, 97u8, 122u8, 104u8, 101u8, 0u8, 104u8, 105u8, 0u8, 104u8, + 105u8, 102u8, 104u8, 105u8, 108u8, 104u8, 108u8, 117u8, 104u8, 109u8, + 100u8, 104u8, 110u8, 100u8, 104u8, 110u8, 101u8, 104u8, 110u8, 106u8, + 104u8, 110u8, 110u8, 104u8, 110u8, 111u8, 104u8, 111u8, 0u8, 104u8, 111u8, + 99u8, 104u8, 111u8, 106u8, 104u8, 114u8, 0u8, 104u8, 115u8, 98u8, 104u8, + 115u8, 110u8, 104u8, 116u8, 0u8, 104u8, 117u8, 0u8, 104u8, 117u8, 114u8, + 104u8, 121u8, 0u8, 104u8, 122u8, 0u8, 105u8, 97u8, 0u8, 105u8, 98u8, 97u8, + 105u8, 98u8, 98u8, 105u8, 100u8, 0u8, 105u8, 102u8, 101u8, 105u8, 103u8, + 0u8, 105u8, 105u8, 0u8, 105u8, 107u8, 0u8, 105u8, 108u8, 111u8, 105u8, + 110u8, 0u8, 105u8, 110u8, 104u8, 105u8, 111u8, 0u8, 105u8, 115u8, 0u8, + 105u8, 116u8, 0u8, 105u8, 117u8, 0u8, 105u8, 119u8, 0u8, 105u8, 122u8, + 104u8, 106u8, 97u8, 0u8, 106u8, 97u8, 109u8, 106u8, 98u8, 111u8, 106u8, + 103u8, 111u8, 106u8, 105u8, 0u8, 106u8, 109u8, 99u8, 106u8, 109u8, 108u8, + 106u8, 117u8, 116u8, 106u8, 118u8, 0u8, 106u8, 119u8, 0u8, 107u8, 97u8, + 0u8, 107u8, 97u8, 97u8, 107u8, 97u8, 98u8, 107u8, 97u8, 99u8, 107u8, 97u8, + 106u8, 107u8, 97u8, 109u8, 107u8, 97u8, 111u8, 107u8, 97u8, 119u8, 107u8, + 98u8, 100u8, 107u8, 98u8, 121u8, 107u8, 99u8, 103u8, 107u8, 99u8, 107u8, + 107u8, 100u8, 101u8, 107u8, 100u8, 104u8, 107u8, 100u8, 116u8, 107u8, + 101u8, 97u8, 107u8, 101u8, 110u8, 107u8, 102u8, 111u8, 107u8, 102u8, 114u8, + 107u8, 102u8, 121u8, 107u8, 103u8, 0u8, 107u8, 103u8, 101u8, 107u8, 103u8, + 112u8, 107u8, 104u8, 97u8, 107u8, 104u8, 98u8, 107u8, 104u8, 110u8, 107u8, + 104u8, 113u8, 107u8, 104u8, 116u8, 107u8, 104u8, 119u8, 107u8, 105u8, 0u8, + 107u8, 105u8, 117u8, 107u8, 106u8, 0u8, 107u8, 106u8, 103u8, 107u8, 107u8, + 0u8, 107u8, 107u8, 106u8, 107u8, 108u8, 0u8, 107u8, 108u8, 110u8, 107u8, + 109u8, 0u8, 107u8, 109u8, 98u8, 107u8, 110u8, 0u8, 107u8, 110u8, 102u8, + 107u8, 111u8, 0u8, 107u8, 111u8, 105u8, 107u8, 111u8, 107u8, 107u8, 111u8, + 115u8, 107u8, 112u8, 101u8, 107u8, 114u8, 99u8, 107u8, 114u8, 105u8, 107u8, + 114u8, 106u8, 107u8, 114u8, 108u8, 107u8, 114u8, 117u8, 107u8, 115u8, 0u8, + 107u8, 115u8, 98u8, 107u8, 115u8, 102u8, 107u8, 115u8, 104u8, 107u8, 116u8, + 114u8, 107u8, 117u8, 0u8, 107u8, 117u8, 109u8, 107u8, 118u8, 0u8, 107u8, + 118u8, 114u8, 107u8, 118u8, 120u8, 107u8, 119u8, 0u8, 107u8, 119u8, 107u8, + 107u8, 120u8, 108u8, 107u8, 120u8, 109u8, 107u8, 120u8, 112u8, 107u8, + 121u8, 0u8, 107u8, 122u8, 106u8, 107u8, 122u8, 116u8, 108u8, 97u8, 0u8, + 108u8, 97u8, 98u8, 108u8, 97u8, 100u8, 108u8, 97u8, 103u8, 108u8, 97u8, + 104u8, 108u8, 97u8, 106u8, 108u8, 98u8, 0u8, 108u8, 98u8, 101u8, 108u8, + 98u8, 119u8, 108u8, 99u8, 112u8, 108u8, 101u8, 112u8, 108u8, 101u8, 122u8, + 108u8, 103u8, 0u8, 108u8, 105u8, 0u8, 108u8, 105u8, 102u8, 108u8, 105u8, + 106u8, 108u8, 105u8, 108u8, 108u8, 105u8, 115u8, 108u8, 106u8, 112u8, + 108u8, 107u8, 105u8, 108u8, 107u8, 116u8, 108u8, 109u8, 110u8, 108u8, + 109u8, 111u8, 108u8, 110u8, 0u8, 108u8, 111u8, 0u8, 108u8, 111u8, 108u8, + 108u8, 111u8, 122u8, 108u8, 114u8, 99u8, 108u8, 116u8, 0u8, 108u8, 116u8, + 103u8, 108u8, 117u8, 0u8, 108u8, 117u8, 97u8, 108u8, 117u8, 111u8, 108u8, + 117u8, 121u8, 108u8, 117u8, 122u8, 108u8, 118u8, 0u8, 108u8, 119u8, 108u8, + 108u8, 122u8, 104u8, 108u8, 122u8, 122u8, 109u8, 97u8, 100u8, 109u8, 97u8, + 102u8, 109u8, 97u8, 103u8, 109u8, 97u8, 105u8, 109u8, 97u8, 107u8, 109u8, + 97u8, 110u8, 109u8, 97u8, 115u8, 109u8, 97u8, 122u8, 109u8, 100u8, 102u8, + 109u8, 100u8, 104u8, 109u8, 100u8, 114u8, 109u8, 101u8, 110u8, 109u8, + 101u8, 114u8, 109u8, 102u8, 97u8, 109u8, 102u8, 101u8, 109u8, 103u8, 0u8, + 109u8, 103u8, 104u8, 109u8, 103u8, 111u8, 109u8, 103u8, 112u8, 109u8, + 103u8, 121u8, 109u8, 104u8, 0u8, 109u8, 105u8, 0u8, 109u8, 105u8, 99u8, + 109u8, 105u8, 110u8, 109u8, 107u8, 0u8, 109u8, 108u8, 0u8, 109u8, 108u8, + 115u8, 109u8, 110u8, 0u8, 109u8, 110u8, 105u8, 109u8, 110u8, 119u8, 109u8, + 111u8, 0u8, 109u8, 111u8, 101u8, 109u8, 111u8, 104u8, 109u8, 111u8, 115u8, + 109u8, 114u8, 0u8, 109u8, 114u8, 100u8, 109u8, 114u8, 106u8, 109u8, 114u8, + 111u8, 109u8, 115u8, 0u8, 109u8, 116u8, 0u8, 109u8, 116u8, 114u8, 109u8, + 117u8, 97u8, 109u8, 117u8, 115u8, 109u8, 118u8, 121u8, 109u8, 119u8, 107u8, + 109u8, 119u8, 114u8, 109u8, 119u8, 118u8, 109u8, 119u8, 119u8, 109u8, + 120u8, 99u8, 109u8, 121u8, 0u8, 109u8, 121u8, 118u8, 109u8, 121u8, 120u8, + 109u8, 121u8, 122u8, 109u8, 122u8, 110u8, 110u8, 97u8, 0u8, 110u8, 97u8, + 110u8, 110u8, 97u8, 112u8, 110u8, 97u8, 113u8, 110u8, 98u8, 0u8, 110u8, + 99u8, 104u8, 110u8, 100u8, 0u8, 110u8, 100u8, 99u8, 110u8, 100u8, 115u8, + 110u8, 101u8, 0u8, 110u8, 101u8, 119u8, 110u8, 103u8, 0u8, 110u8, 103u8, + 108u8, 110u8, 104u8, 101u8, 110u8, 104u8, 119u8, 110u8, 105u8, 106u8, + 110u8, 105u8, 117u8, 110u8, 106u8, 111u8, 110u8, 108u8, 0u8, 110u8, 109u8, + 103u8, 110u8, 110u8, 0u8, 110u8, 110u8, 104u8, 110u8, 110u8, 112u8, 110u8, + 111u8, 0u8, 110u8, 111u8, 100u8, 110u8, 111u8, 101u8, 110u8, 111u8, 110u8, + 110u8, 113u8, 111u8, 110u8, 114u8, 0u8, 110u8, 115u8, 107u8, 110u8, 115u8, + 111u8, 110u8, 115u8, 116u8, 110u8, 117u8, 115u8, 110u8, 118u8, 0u8, 110u8, + 120u8, 113u8, 110u8, 121u8, 0u8, 110u8, 121u8, 109u8, 110u8, 121u8, 110u8, + 110u8, 122u8, 105u8, 111u8, 99u8, 0u8, 111u8, 106u8, 0u8, 111u8, 106u8, + 115u8, 111u8, 107u8, 97u8, 111u8, 109u8, 0u8, 111u8, 114u8, 0u8, 111u8, + 115u8, 0u8, 111u8, 115u8, 97u8, 111u8, 116u8, 107u8, 111u8, 117u8, 105u8, + 112u8, 97u8, 0u8, 112u8, 97u8, 103u8, 112u8, 97u8, 108u8, 112u8, 97u8, + 109u8, 112u8, 97u8, 112u8, 112u8, 97u8, 117u8, 112u8, 99u8, 100u8, 112u8, + 99u8, 109u8, 112u8, 100u8, 99u8, 112u8, 100u8, 116u8, 112u8, 101u8, 111u8, + 112u8, 102u8, 108u8, 112u8, 104u8, 110u8, 112u8, 105u8, 115u8, 112u8, + 107u8, 97u8, 112u8, 107u8, 111u8, 112u8, 108u8, 0u8, 112u8, 109u8, 115u8, + 112u8, 110u8, 116u8, 112u8, 111u8, 110u8, 112u8, 112u8, 97u8, 112u8, 113u8, + 109u8, 112u8, 114u8, 97u8, 112u8, 114u8, 100u8, 112u8, 114u8, 103u8, 112u8, + 115u8, 0u8, 112u8, 116u8, 0u8, 112u8, 117u8, 117u8, 113u8, 117u8, 0u8, + 113u8, 117u8, 99u8, 113u8, 117u8, 103u8, 114u8, 97u8, 106u8, 114u8, 99u8, + 102u8, 114u8, 101u8, 106u8, 114u8, 103u8, 110u8, 114u8, 104u8, 103u8, + 114u8, 105u8, 97u8, 114u8, 105u8, 102u8, 114u8, 106u8, 115u8, 114u8, 107u8, + 116u8, 114u8, 109u8, 0u8, 114u8, 109u8, 102u8, 114u8, 109u8, 111u8, 114u8, + 109u8, 116u8, 114u8, 109u8, 117u8, 114u8, 110u8, 0u8, 114u8, 110u8, 103u8, + 114u8, 111u8, 0u8, 114u8, 111u8, 98u8, 114u8, 111u8, 102u8, 114u8, 116u8, + 109u8, 114u8, 117u8, 0u8, 114u8, 117u8, 101u8, 114u8, 117u8, 103u8, 114u8, + 119u8, 0u8, 114u8, 119u8, 107u8, 114u8, 121u8, 117u8, 115u8, 97u8, 0u8, + 115u8, 97u8, 102u8, 115u8, 97u8, 104u8, 115u8, 97u8, 113u8, 115u8, 97u8, + 115u8, 115u8, 97u8, 116u8, 115u8, 97u8, 118u8, 115u8, 97u8, 122u8, 115u8, + 98u8, 112u8, 115u8, 99u8, 0u8, 115u8, 99u8, 107u8, 115u8, 99u8, 110u8, + 115u8, 99u8, 111u8, 115u8, 100u8, 0u8, 115u8, 100u8, 99u8, 115u8, 100u8, + 104u8, 115u8, 101u8, 0u8, 115u8, 101u8, 102u8, 115u8, 101u8, 104u8, 115u8, + 101u8, 105u8, 115u8, 101u8, 115u8, 115u8, 103u8, 0u8, 115u8, 103u8, 97u8, + 115u8, 103u8, 115u8, 115u8, 104u8, 105u8, 115u8, 104u8, 110u8, 115u8, + 105u8, 0u8, 115u8, 105u8, 100u8, 115u8, 107u8, 0u8, 115u8, 107u8, 114u8, + 115u8, 108u8, 0u8, 115u8, 108u8, 105u8, 115u8, 108u8, 121u8, 115u8, 109u8, + 0u8, 115u8, 109u8, 97u8, 115u8, 109u8, 100u8, 115u8, 109u8, 106u8, 115u8, + 109u8, 110u8, 115u8, 109u8, 112u8, 115u8, 109u8, 115u8, 115u8, 110u8, 0u8, + 115u8, 110u8, 98u8, 115u8, 110u8, 107u8, 115u8, 111u8, 0u8, 115u8, 111u8, + 103u8, 115u8, 111u8, 117u8, 115u8, 113u8, 0u8, 115u8, 114u8, 0u8, 115u8, + 114u8, 98u8, 115u8, 114u8, 110u8, 115u8, 114u8, 114u8, 115u8, 114u8, 120u8, + 115u8, 115u8, 0u8, 115u8, 115u8, 121u8, 115u8, 116u8, 0u8, 115u8, 116u8, + 113u8, 115u8, 117u8, 0u8, 115u8, 117u8, 107u8, 115u8, 117u8, 115u8, 115u8, + 118u8, 0u8, 115u8, 119u8, 0u8, 115u8, 119u8, 98u8, 115u8, 119u8, 99u8, + 115u8, 119u8, 103u8, 115u8, 119u8, 118u8, 115u8, 120u8, 110u8, 115u8, + 121u8, 108u8, 115u8, 121u8, 114u8, 115u8, 122u8, 108u8, 116u8, 97u8, 0u8, + 116u8, 97u8, 106u8, 116u8, 98u8, 119u8, 116u8, 99u8, 121u8, 116u8, 100u8, + 100u8, 116u8, 100u8, 103u8, 116u8, 100u8, 104u8, 116u8, 100u8, 117u8, + 116u8, 101u8, 0u8, 116u8, 101u8, 109u8, 116u8, 101u8, 111u8, 116u8, 101u8, + 116u8, 116u8, 103u8, 0u8, 116u8, 104u8, 0u8, 116u8, 104u8, 108u8, 116u8, + 104u8, 113u8, 116u8, 104u8, 114u8, 116u8, 105u8, 0u8, 116u8, 105u8, 103u8, + 116u8, 105u8, 118u8, 116u8, 107u8, 0u8, 116u8, 107u8, 108u8, 116u8, 107u8, + 114u8, 116u8, 107u8, 116u8, 116u8, 108u8, 0u8, 116u8, 108u8, 121u8, 116u8, + 109u8, 104u8, 116u8, 110u8, 0u8, 116u8, 111u8, 0u8, 116u8, 111u8, 103u8, + 116u8, 111u8, 107u8, 116u8, 112u8, 105u8, 116u8, 114u8, 0u8, 116u8, 114u8, + 117u8, 116u8, 114u8, 118u8, 116u8, 114u8, 119u8, 116u8, 115u8, 0u8, 116u8, + 115u8, 100u8, 116u8, 115u8, 102u8, 116u8, 115u8, 103u8, 116u8, 115u8, + 106u8, 116u8, 116u8, 0u8, 116u8, 116u8, 106u8, 116u8, 116u8, 115u8, 116u8, + 116u8, 116u8, 116u8, 117u8, 109u8, 116u8, 118u8, 108u8, 116u8, 119u8, + 113u8, 116u8, 120u8, 103u8, 116u8, 120u8, 111u8, 116u8, 121u8, 0u8, 116u8, + 121u8, 118u8, 116u8, 122u8, 109u8, 117u8, 100u8, 105u8, 117u8, 100u8, + 109u8, 117u8, 103u8, 0u8, 117u8, 103u8, 97u8, 117u8, 107u8, 0u8, 117u8, + 108u8, 105u8, 117u8, 109u8, 98u8, 117u8, 110u8, 114u8, 117u8, 110u8, 120u8, + 117u8, 114u8, 0u8, 117u8, 122u8, 0u8, 118u8, 97u8, 105u8, 118u8, 101u8, + 0u8, 118u8, 101u8, 99u8, 118u8, 101u8, 112u8, 118u8, 105u8, 0u8, 118u8, + 105u8, 99u8, 118u8, 108u8, 115u8, 118u8, 109u8, 102u8, 118u8, 109u8, 119u8, + 118u8, 111u8, 0u8, 118u8, 111u8, 116u8, 118u8, 114u8, 111u8, 118u8, 117u8, + 110u8, 119u8, 97u8, 0u8, 119u8, 97u8, 101u8, 119u8, 97u8, 108u8, 119u8, + 97u8, 114u8, 119u8, 98u8, 112u8, 119u8, 98u8, 113u8, 119u8, 98u8, 114u8, + 119u8, 108u8, 115u8, 119u8, 110u8, 105u8, 119u8, 111u8, 0u8, 119u8, 115u8, + 103u8, 119u8, 116u8, 109u8, 119u8, 117u8, 117u8, 120u8, 97u8, 118u8, 120u8, + 99u8, 111u8, 120u8, 99u8, 114u8, 120u8, 104u8, 0u8, 120u8, 108u8, 99u8, + 120u8, 108u8, 100u8, 120u8, 109u8, 102u8, 120u8, 109u8, 110u8, 120u8, + 109u8, 114u8, 120u8, 110u8, 97u8, 120u8, 110u8, 114u8, 120u8, 111u8, 103u8, + 120u8, 112u8, 114u8, 120u8, 115u8, 97u8, 120u8, 115u8, 114u8, 121u8, 97u8, + 111u8, 121u8, 97u8, 112u8, 121u8, 97u8, 118u8, 121u8, 98u8, 98u8, 121u8, + 105u8, 0u8, 121u8, 111u8, 0u8, 121u8, 114u8, 108u8, 121u8, 117u8, 97u8, + 121u8, 117u8, 101u8, 122u8, 97u8, 0u8, 122u8, 97u8, 103u8, 122u8, 100u8, + 106u8, 122u8, 101u8, 97u8, 122u8, 103u8, 104u8, 122u8, 104u8, 0u8, 122u8, + 104u8, 120u8, 122u8, 107u8, 116u8, 122u8, 108u8, 109u8, 122u8, 109u8, + 105u8, 122u8, 117u8, 0u8, 122u8, 122u8, 97u8, + ]) + }, + unsafe { + ::zerovec::ZeroVec::from_bytes_unchecked(&[ + 69u8, 84u8, 0u8, 71u8, 69u8, 0u8, 71u8, 72u8, 0u8, 73u8, 68u8, 0u8, 85u8, + 71u8, 0u8, 71u8, 72u8, 0u8, 66u8, 84u8, 0u8, 82u8, 85u8, 0u8, 73u8, 82u8, + 0u8, 84u8, 78u8, 0u8, 90u8, 65u8, 0u8, 67u8, 77u8, 0u8, 73u8, 78u8, 0u8, + 84u8, 78u8, 0u8, 71u8, 72u8, 0u8, 73u8, 81u8, 0u8, 88u8, 75u8, 0u8, 82u8, + 85u8, 0u8, 69u8, 84u8, 0u8, 78u8, 71u8, 0u8, 69u8, 83u8, 0u8, 78u8, 71u8, + 0u8, 73u8, 68u8, 0u8, 84u8, 71u8, 0u8, 69u8, 71u8, 0u8, 73u8, 82u8, 0u8, + 67u8, 76u8, 0u8, 66u8, 79u8, 0u8, 68u8, 90u8, 0u8, 83u8, 65u8, 0u8, 77u8, + 65u8, 0u8, 69u8, 71u8, 0u8, 73u8, 78u8, 0u8, 84u8, 90u8, 0u8, 85u8, 83u8, + 0u8, 69u8, 83u8, 0u8, 67u8, 65u8, 0u8, 82u8, 85u8, 0u8, 73u8, 78u8, 0u8, + 66u8, 79u8, 0u8, 65u8, 90u8, 0u8, 82u8, 85u8, 0u8, 80u8, 75u8, 0u8, 73u8, + 68u8, 0u8, 78u8, 80u8, 0u8, 65u8, 84u8, 0u8, 67u8, 77u8, 0u8, 67u8, 77u8, + 0u8, 73u8, 68u8, 0u8, 67u8, 77u8, 0u8, 67u8, 73u8, 0u8, 66u8, 89u8, 0u8, + 83u8, 68u8, 0u8, 90u8, 77u8, 0u8, 73u8, 68u8, 0u8, 84u8, 90u8, 0u8, 67u8, + 77u8, 0u8, 73u8, 78u8, 0u8, 80u8, 75u8, 0u8, 73u8, 78u8, 0u8, 66u8, 71u8, + 0u8, 73u8, 78u8, 0u8, 80u8, 75u8, 0u8, 84u8, 82u8, 0u8, 73u8, 78u8, 0u8, + 73u8, 78u8, 0u8, 73u8, 78u8, 0u8, 86u8, 85u8, 0u8, 80u8, 72u8, 0u8, 78u8, + 71u8, 0u8, 73u8, 78u8, 0u8, 73u8, 68u8, 0u8, 83u8, 78u8, 0u8, 67u8, 77u8, + 0u8, 80u8, 72u8, 0u8, 67u8, 65u8, 0u8, 77u8, 89u8, 0u8, 86u8, 78u8, 0u8, + 77u8, 76u8, 0u8, 77u8, 76u8, 0u8, 66u8, 68u8, 0u8, 67u8, 78u8, 0u8, 73u8, + 78u8, 0u8, 73u8, 82u8, 0u8, 67u8, 73u8, 0u8, 70u8, 82u8, 0u8, 73u8, 78u8, + 0u8, 80u8, 75u8, 0u8, 73u8, 78u8, 0u8, 66u8, 65u8, 0u8, 76u8, 82u8, 0u8, + 67u8, 77u8, 0u8, 80u8, 72u8, 0u8, 80u8, 75u8, 0u8, 82u8, 85u8, 0u8, 89u8, + 84u8, 0u8, 73u8, 68u8, 0u8, 67u8, 77u8, 0u8, 71u8, 81u8, 0u8, 69u8, 82u8, + 0u8, 67u8, 77u8, 0u8, 77u8, 76u8, 0u8, 69u8, 83u8, 0u8, 85u8, 83u8, 0u8, + 78u8, 71u8, 0u8, 66u8, 68u8, 0u8, 82u8, 85u8, 0u8, 80u8, 72u8, 0u8, 85u8, + 71u8, 0u8, 71u8, 85u8, 0u8, 70u8, 77u8, 0u8, 82u8, 85u8, 0u8, 85u8, 83u8, + 0u8, 67u8, 65u8, 0u8, 85u8, 83u8, 0u8, 85u8, 83u8, 0u8, 75u8, 72u8, 0u8, + 86u8, 78u8, 0u8, 73u8, 81u8, 0u8, 67u8, 65u8, 0u8, 77u8, 78u8, 0u8, 70u8, + 82u8, 0u8, 69u8, 71u8, 0u8, 80u8, 72u8, 0u8, 67u8, 65u8, 0u8, 67u8, 65u8, + 0u8, 85u8, 65u8, 0u8, 67u8, 65u8, 0u8, 67u8, 65u8, 0u8, 83u8, 67u8, 0u8, + 67u8, 90u8, 0u8, 80u8, 76u8, 0u8, 67u8, 65u8, 0u8, 77u8, 77u8, 0u8, 82u8, + 85u8, 0u8, 82u8, 85u8, 0u8, 71u8, 66u8, 0u8, 68u8, 75u8, 0u8, 67u8, 73u8, + 0u8, 85u8, 83u8, 0u8, 82u8, 85u8, 0u8, 75u8, 69u8, 0u8, 73u8, 78u8, 0u8, + 68u8, 69u8, 0u8, 67u8, 65u8, 0u8, 67u8, 65u8, 0u8, 78u8, 69u8, 0u8, 78u8, + 71u8, 0u8, 67u8, 73u8, 0u8, 73u8, 78u8, 0u8, 67u8, 78u8, 0u8, 68u8, 69u8, + 0u8, 77u8, 76u8, 0u8, 77u8, 89u8, 0u8, 78u8, 80u8, 0u8, 67u8, 77u8, 0u8, + 77u8, 86u8, 0u8, 83u8, 78u8, 0u8, 66u8, 70u8, 0u8, 66u8, 84u8, 0u8, 75u8, + 69u8, 0u8, 71u8, 72u8, 0u8, 78u8, 71u8, 0u8, 73u8, 84u8, 0u8, 69u8, 71u8, + 0u8, 77u8, 77u8, 0u8, 71u8, 82u8, 0u8, 85u8, 83u8, 0u8, 48u8, 48u8, 49u8, + 69u8, 83u8, 0u8, 73u8, 78u8, 0u8, 85u8, 83u8, 0u8, 69u8, 69u8, 0u8, 73u8, + 84u8, 0u8, 69u8, 83u8, 0u8, 67u8, 77u8, 0u8, 69u8, 83u8, 0u8, 73u8, 82u8, + 0u8, 71u8, 81u8, 0u8, 83u8, 78u8, 0u8, 77u8, 76u8, 0u8, 70u8, 73u8, 0u8, + 83u8, 68u8, 0u8, 80u8, 72u8, 0u8, 83u8, 69u8, 0u8, 70u8, 74u8, 0u8, 70u8, + 79u8, 0u8, 66u8, 74u8, 0u8, 70u8, 82u8, 0u8, 85u8, 83u8, 0u8, 70u8, 82u8, + 0u8, 68u8, 69u8, 0u8, 68u8, 69u8, 0u8, 67u8, 77u8, 0u8, 87u8, 70u8, 0u8, + 71u8, 78u8, 0u8, 78u8, 69u8, 0u8, 73u8, 84u8, 0u8, 78u8, 71u8, 0u8, 83u8, + 68u8, 0u8, 78u8, 76u8, 0u8, 73u8, 69u8, 0u8, 71u8, 72u8, 0u8, 77u8, 68u8, + 0u8, 67u8, 78u8, 0u8, 73u8, 68u8, 0u8, 73u8, 78u8, 0u8, 73u8, 82u8, 0u8, + 71u8, 70u8, 0u8, 71u8, 66u8, 0u8, 69u8, 84u8, 0u8, 78u8, 80u8, 0u8, 75u8, + 73u8, 0u8, 80u8, 75u8, 0u8, 80u8, 75u8, 0u8, 69u8, 83u8, 0u8, 73u8, 82u8, + 0u8, 80u8, 89u8, 0u8, 73u8, 78u8, 0u8, 73u8, 78u8, 0u8, 73u8, 68u8, 0u8, + 78u8, 76u8, 0u8, 85u8, 65u8, 0u8, 67u8, 89u8, 0u8, 73u8, 78u8, 0u8, 67u8, + 72u8, 0u8, 73u8, 78u8, 0u8, 66u8, 82u8, 0u8, 67u8, 79u8, 0u8, 71u8, 72u8, + 0u8, 75u8, 69u8, 0u8, 73u8, 77u8, 0u8, 78u8, 80u8, 0u8, 67u8, 65u8, 0u8, + 78u8, 71u8, 0u8, 67u8, 78u8, 0u8, 85u8, 83u8, 0u8, 65u8, 70u8, 0u8, 73u8, + 76u8, 0u8, 73u8, 78u8, 0u8, 70u8, 74u8, 0u8, 80u8, 72u8, 0u8, 84u8, 82u8, + 0u8, 67u8, 78u8, 0u8, 80u8, 75u8, 0u8, 73u8, 78u8, 0u8, 85u8, 83u8, 0u8, + 80u8, 72u8, 0u8, 80u8, 75u8, 0u8, 80u8, 71u8, 0u8, 73u8, 78u8, 0u8, 73u8, + 78u8, 0u8, 72u8, 82u8, 0u8, 68u8, 69u8, 0u8, 67u8, 78u8, 0u8, 72u8, 84u8, + 0u8, 72u8, 85u8, 0u8, 67u8, 65u8, 0u8, 65u8, 77u8, 0u8, 78u8, 65u8, 0u8, + 48u8, 48u8, 49u8, 77u8, 89u8, 0u8, 78u8, 71u8, 0u8, 73u8, 68u8, 0u8, 84u8, + 71u8, 0u8, 78u8, 71u8, 0u8, 67u8, 78u8, 0u8, 85u8, 83u8, 0u8, 80u8, 72u8, + 0u8, 73u8, 68u8, 0u8, 82u8, 85u8, 0u8, 48u8, 48u8, 49u8, 73u8, 83u8, 0u8, + 73u8, 84u8, 0u8, 67u8, 65u8, 0u8, 73u8, 76u8, 0u8, 82u8, 85u8, 0u8, 74u8, + 80u8, 0u8, 74u8, 77u8, 0u8, 48u8, 48u8, 49u8, 67u8, 77u8, 0u8, 85u8, 65u8, + 0u8, 84u8, 90u8, 0u8, 78u8, 80u8, 0u8, 68u8, 75u8, 0u8, 73u8, 68u8, 0u8, + 73u8, 68u8, 0u8, 71u8, 69u8, 0u8, 85u8, 90u8, 0u8, 68u8, 90u8, 0u8, 77u8, + 77u8, 0u8, 78u8, 71u8, 0u8, 75u8, 69u8, 0u8, 77u8, 76u8, 0u8, 73u8, 68u8, + 0u8, 82u8, 85u8, 0u8, 78u8, 69u8, 0u8, 78u8, 71u8, 0u8, 90u8, 87u8, 0u8, + 84u8, 90u8, 0u8, 84u8, 71u8, 0u8, 84u8, 72u8, 0u8, 67u8, 86u8, 0u8, 67u8, + 77u8, 0u8, 67u8, 73u8, 0u8, 73u8, 78u8, 0u8, 73u8, 78u8, 0u8, 67u8, 68u8, + 0u8, 73u8, 68u8, 0u8, 66u8, 82u8, 0u8, 73u8, 78u8, 0u8, 67u8, 78u8, 0u8, + 73u8, 78u8, 0u8, 77u8, 76u8, 0u8, 73u8, 78u8, 0u8, 80u8, 75u8, 0u8, 75u8, + 69u8, 0u8, 84u8, 82u8, 0u8, 78u8, 65u8, 0u8, 76u8, 65u8, 0u8, 75u8, 90u8, + 0u8, 67u8, 77u8, 0u8, 71u8, 76u8, 0u8, 75u8, 69u8, 0u8, 75u8, 72u8, 0u8, + 65u8, 79u8, 0u8, 73u8, 78u8, 0u8, 71u8, 87u8, 0u8, 75u8, 82u8, 0u8, 82u8, + 85u8, 0u8, 73u8, 78u8, 0u8, 70u8, 77u8, 0u8, 76u8, 82u8, 0u8, 82u8, 85u8, + 0u8, 83u8, 76u8, 0u8, 80u8, 72u8, 0u8, 82u8, 85u8, 0u8, 73u8, 78u8, 0u8, + 73u8, 78u8, 0u8, 84u8, 90u8, 0u8, 67u8, 77u8, 0u8, 68u8, 69u8, 0u8, 77u8, + 89u8, 0u8, 84u8, 82u8, 0u8, 82u8, 85u8, 0u8, 82u8, 85u8, 0u8, 73u8, 68u8, + 0u8, 80u8, 75u8, 0u8, 71u8, 66u8, 0u8, 67u8, 65u8, 0u8, 73u8, 78u8, 0u8, + 84u8, 72u8, 0u8, 80u8, 75u8, 0u8, 75u8, 71u8, 0u8, 77u8, 89u8, 0u8, 77u8, + 89u8, 0u8, 86u8, 65u8, 0u8, 71u8, 82u8, 0u8, 73u8, 76u8, 0u8, 84u8, 90u8, + 0u8, 80u8, 75u8, 0u8, 85u8, 71u8, 0u8, 76u8, 85u8, 0u8, 82u8, 85u8, 0u8, + 73u8, 68u8, 0u8, 67u8, 78u8, 0u8, 73u8, 78u8, 0u8, 82u8, 85u8, 0u8, 85u8, + 71u8, 0u8, 78u8, 76u8, 0u8, 78u8, 80u8, 0u8, 73u8, 84u8, 0u8, 67u8, 65u8, + 0u8, 67u8, 78u8, 0u8, 73u8, 68u8, 0u8, 73u8, 82u8, 0u8, 85u8, 83u8, 0u8, + 73u8, 78u8, 0u8, 73u8, 84u8, 0u8, 67u8, 68u8, 0u8, 76u8, 65u8, 0u8, 67u8, + 68u8, 0u8, 90u8, 77u8, 0u8, 73u8, 82u8, 0u8, 76u8, 84u8, 0u8, 76u8, 86u8, + 0u8, 67u8, 68u8, 0u8, 67u8, 68u8, 0u8, 75u8, 69u8, 0u8, 75u8, 69u8, 0u8, + 73u8, 82u8, 0u8, 76u8, 86u8, 0u8, 84u8, 72u8, 0u8, 67u8, 78u8, 0u8, 84u8, + 82u8, 0u8, 73u8, 68u8, 0u8, 67u8, 77u8, 0u8, 73u8, 78u8, 0u8, 73u8, 78u8, + 0u8, 73u8, 68u8, 0u8, 71u8, 77u8, 0u8, 75u8, 69u8, 0u8, 77u8, 88u8, 0u8, + 82u8, 85u8, 0u8, 80u8, 72u8, 0u8, 73u8, 68u8, 0u8, 83u8, 76u8, 0u8, 75u8, + 69u8, 0u8, 84u8, 72u8, 0u8, 77u8, 85u8, 0u8, 77u8, 71u8, 0u8, 77u8, 90u8, + 0u8, 67u8, 77u8, 0u8, 78u8, 80u8, 0u8, 84u8, 90u8, 0u8, 77u8, 72u8, 0u8, + 78u8, 90u8, 0u8, 67u8, 65u8, 0u8, 73u8, 68u8, 0u8, 77u8, 75u8, 0u8, 73u8, + 78u8, 0u8, 83u8, 68u8, 0u8, 77u8, 78u8, 0u8, 73u8, 78u8, 0u8, 77u8, 77u8, + 0u8, 82u8, 79u8, 0u8, 67u8, 65u8, 0u8, 67u8, 65u8, 0u8, 66u8, 70u8, 0u8, + 73u8, 78u8, 0u8, 78u8, 80u8, 0u8, 82u8, 85u8, 0u8, 66u8, 68u8, 0u8, 77u8, + 89u8, 0u8, 77u8, 84u8, 0u8, 73u8, 78u8, 0u8, 67u8, 77u8, 0u8, 85u8, 83u8, + 0u8, 80u8, 75u8, 0u8, 77u8, 76u8, 0u8, 73u8, 78u8, 0u8, 73u8, 68u8, 0u8, + 85u8, 83u8, 0u8, 90u8, 87u8, 0u8, 77u8, 77u8, 0u8, 82u8, 85u8, 0u8, 85u8, + 71u8, 0u8, 73u8, 82u8, 0u8, 73u8, 82u8, 0u8, 78u8, 82u8, 0u8, 67u8, 78u8, + 0u8, 73u8, 84u8, 0u8, 78u8, 65u8, 0u8, 78u8, 79u8, 0u8, 77u8, 88u8, 0u8, + 90u8, 87u8, 0u8, 77u8, 90u8, 0u8, 68u8, 69u8, 0u8, 78u8, 80u8, 0u8, 78u8, + 80u8, 0u8, 78u8, 65u8, 0u8, 77u8, 90u8, 0u8, 77u8, 88u8, 0u8, 77u8, 88u8, + 0u8, 73u8, 68u8, 0u8, 78u8, 85u8, 0u8, 73u8, 78u8, 0u8, 78u8, 76u8, 0u8, + 67u8, 77u8, 0u8, 78u8, 79u8, 0u8, 67u8, 77u8, 0u8, 73u8, 78u8, 0u8, 78u8, + 79u8, 0u8, 84u8, 72u8, 0u8, 73u8, 78u8, 0u8, 83u8, 69u8, 0u8, 71u8, 78u8, + 0u8, 90u8, 65u8, 0u8, 67u8, 65u8, 0u8, 90u8, 65u8, 0u8, 73u8, 78u8, 0u8, + 83u8, 83u8, 0u8, 85u8, 83u8, 0u8, 67u8, 78u8, 0u8, 77u8, 87u8, 0u8, 84u8, + 90u8, 0u8, 85u8, 71u8, 0u8, 71u8, 72u8, 0u8, 70u8, 82u8, 0u8, 67u8, 65u8, + 0u8, 67u8, 65u8, 0u8, 67u8, 65u8, 0u8, 69u8, 84u8, 0u8, 73u8, 78u8, 0u8, + 71u8, 69u8, 0u8, 85u8, 83u8, 0u8, 77u8, 78u8, 0u8, 49u8, 52u8, 51u8, 73u8, + 78u8, 0u8, 80u8, 72u8, 0u8, 73u8, 82u8, 0u8, 80u8, 72u8, 0u8, 65u8, 87u8, + 0u8, 80u8, 87u8, 0u8, 70u8, 82u8, 0u8, 78u8, 71u8, 0u8, 85u8, 83u8, 0u8, + 67u8, 65u8, 0u8, 73u8, 82u8, 0u8, 68u8, 69u8, 0u8, 76u8, 66u8, 0u8, 83u8, + 66u8, 0u8, 73u8, 78u8, 0u8, 75u8, 69u8, 0u8, 80u8, 76u8, 0u8, 73u8, 84u8, + 0u8, 71u8, 82u8, 0u8, 70u8, 77u8, 0u8, 73u8, 78u8, 0u8, 67u8, 65u8, 0u8, + 80u8, 75u8, 0u8, 73u8, 82u8, 0u8, 48u8, 48u8, 49u8, 65u8, 70u8, 0u8, 66u8, + 82u8, 0u8, 71u8, 65u8, 0u8, 80u8, 69u8, 0u8, 71u8, 84u8, 0u8, 69u8, 67u8, + 0u8, 73u8, 78u8, 0u8, 82u8, 69u8, 0u8, 73u8, 68u8, 0u8, 73u8, 84u8, 0u8, + 77u8, 77u8, 0u8, 73u8, 78u8, 0u8, 77u8, 65u8, 0u8, 78u8, 80u8, 0u8, 66u8, + 68u8, 0u8, 67u8, 72u8, 0u8, 70u8, 73u8, 0u8, 67u8, 72u8, 0u8, 73u8, 82u8, + 0u8, 83u8, 69u8, 0u8, 66u8, 73u8, 0u8, 77u8, 90u8, 0u8, 82u8, 79u8, 0u8, + 73u8, 68u8, 0u8, 84u8, 90u8, 0u8, 70u8, 74u8, 0u8, 82u8, 85u8, 0u8, 85u8, + 65u8, 0u8, 83u8, 66u8, 0u8, 82u8, 87u8, 0u8, 84u8, 90u8, 0u8, 74u8, 80u8, + 0u8, 73u8, 78u8, 0u8, 71u8, 72u8, 0u8, 82u8, 85u8, 0u8, 75u8, 69u8, 0u8, + 73u8, 68u8, 0u8, 73u8, 78u8, 0u8, 83u8, 78u8, 0u8, 73u8, 78u8, 0u8, 84u8, + 90u8, 0u8, 73u8, 84u8, 0u8, 73u8, 78u8, 0u8, 73u8, 84u8, 0u8, 71u8, 66u8, + 0u8, 80u8, 75u8, 0u8, 73u8, 84u8, 0u8, 73u8, 82u8, 0u8, 78u8, 79u8, 0u8, + 67u8, 73u8, 0u8, 77u8, 90u8, 0u8, 77u8, 88u8, 0u8, 77u8, 76u8, 0u8, 67u8, + 70u8, 0u8, 73u8, 69u8, 0u8, 76u8, 84u8, 0u8, 77u8, 65u8, 0u8, 77u8, 77u8, + 0u8, 76u8, 75u8, 0u8, 69u8, 84u8, 0u8, 83u8, 75u8, 0u8, 80u8, 75u8, 0u8, + 83u8, 73u8, 0u8, 80u8, 76u8, 0u8, 73u8, 68u8, 0u8, 87u8, 83u8, 0u8, 83u8, + 69u8, 0u8, 65u8, 79u8, 0u8, 83u8, 69u8, 0u8, 70u8, 73u8, 0u8, 73u8, 76u8, + 0u8, 70u8, 73u8, 0u8, 90u8, 87u8, 0u8, 77u8, 89u8, 0u8, 77u8, 76u8, 0u8, + 83u8, 79u8, 0u8, 85u8, 90u8, 0u8, 84u8, 72u8, 0u8, 65u8, 76u8, 0u8, 82u8, + 83u8, 0u8, 73u8, 78u8, 0u8, 83u8, 82u8, 0u8, 83u8, 78u8, 0u8, 73u8, 78u8, + 0u8, 90u8, 65u8, 0u8, 69u8, 82u8, 0u8, 90u8, 65u8, 0u8, 68u8, 69u8, 0u8, + 73u8, 68u8, 0u8, 84u8, 90u8, 0u8, 71u8, 78u8, 0u8, 83u8, 69u8, 0u8, 84u8, + 90u8, 0u8, 89u8, 84u8, 0u8, 67u8, 68u8, 0u8, 68u8, 69u8, 0u8, 73u8, 78u8, + 0u8, 73u8, 68u8, 0u8, 66u8, 68u8, 0u8, 73u8, 81u8, 0u8, 80u8, 76u8, 0u8, + 73u8, 78u8, 0u8, 78u8, 80u8, 0u8, 80u8, 72u8, 0u8, 73u8, 78u8, 0u8, 67u8, + 78u8, 0u8, 78u8, 80u8, 0u8, 78u8, 80u8, 0u8, 77u8, 89u8, 0u8, 73u8, 78u8, + 0u8, 83u8, 76u8, 0u8, 85u8, 71u8, 0u8, 84u8, 76u8, 0u8, 84u8, 74u8, 0u8, + 84u8, 72u8, 0u8, 78u8, 80u8, 0u8, 78u8, 80u8, 0u8, 78u8, 80u8, 0u8, 69u8, + 84u8, 0u8, 69u8, 82u8, 0u8, 78u8, 71u8, 0u8, 84u8, 77u8, 0u8, 84u8, 75u8, + 0u8, 65u8, 90u8, 0u8, 78u8, 80u8, 0u8, 80u8, 72u8, 0u8, 65u8, 90u8, 0u8, + 78u8, 69u8, 0u8, 90u8, 65u8, 0u8, 84u8, 79u8, 0u8, 77u8, 87u8, 0u8, 48u8, + 48u8, 49u8, 80u8, 71u8, 0u8, 84u8, 82u8, 0u8, 84u8, 82u8, 0u8, 84u8, 87u8, + 0u8, 80u8, 75u8, 0u8, 90u8, 65u8, 0u8, 71u8, 82u8, 0u8, 78u8, 80u8, 0u8, + 80u8, 72u8, 0u8, 66u8, 84u8, 0u8, 82u8, 85u8, 0u8, 85u8, 71u8, 0u8, 84u8, + 72u8, 0u8, 65u8, 90u8, 0u8, 77u8, 87u8, 0u8, 84u8, 86u8, 0u8, 78u8, 69u8, + 0u8, 67u8, 78u8, 0u8, 73u8, 78u8, 0u8, 80u8, 70u8, 0u8, 82u8, 85u8, 0u8, + 77u8, 65u8, 0u8, 82u8, 85u8, 0u8, 82u8, 85u8, 0u8, 67u8, 78u8, 0u8, 83u8, + 89u8, 0u8, 85u8, 65u8, 0u8, 70u8, 77u8, 0u8, 65u8, 79u8, 0u8, 73u8, 78u8, + 0u8, 73u8, 78u8, 0u8, 80u8, 75u8, 0u8, 85u8, 90u8, 0u8, 76u8, 82u8, 0u8, + 90u8, 65u8, 0u8, 73u8, 84u8, 0u8, 82u8, 85u8, 0u8, 86u8, 78u8, 0u8, 83u8, + 88u8, 0u8, 66u8, 69u8, 0u8, 68u8, 69u8, 0u8, 77u8, 90u8, 0u8, 48u8, 48u8, + 49u8, 82u8, 85u8, 0u8, 69u8, 69u8, 0u8, 84u8, 90u8, 0u8, 66u8, 69u8, 0u8, + 67u8, 72u8, 0u8, 69u8, 84u8, 0u8, 80u8, 72u8, 0u8, 65u8, 85u8, 0u8, 73u8, + 78u8, 0u8, 73u8, 78u8, 0u8, 87u8, 70u8, 0u8, 75u8, 77u8, 0u8, 83u8, 78u8, + 0u8, 73u8, 78u8, 0u8, 73u8, 78u8, 0u8, 67u8, 78u8, 0u8, 66u8, 82u8, 0u8, + 85u8, 90u8, 0u8, 84u8, 82u8, 0u8, 90u8, 65u8, 0u8, 84u8, 82u8, 0u8, 84u8, + 82u8, 0u8, 71u8, 69u8, 0u8, 67u8, 78u8, 0u8, 83u8, 68u8, 0u8, 83u8, 65u8, + 0u8, 73u8, 78u8, 0u8, 85u8, 71u8, 0u8, 73u8, 82u8, 0u8, 89u8, 69u8, 0u8, + 78u8, 80u8, 0u8, 77u8, 90u8, 0u8, 70u8, 77u8, 0u8, 67u8, 77u8, 0u8, 67u8, + 77u8, 0u8, 48u8, 48u8, 49u8, 78u8, 71u8, 0u8, 66u8, 82u8, 0u8, 77u8, 88u8, + 0u8, 72u8, 75u8, 0u8, 67u8, 78u8, 0u8, 83u8, 68u8, 0u8, 75u8, 77u8, 0u8, + 78u8, 76u8, 0u8, 77u8, 65u8, 0u8, 67u8, 78u8, 0u8, 67u8, 78u8, 0u8, 67u8, + 78u8, 0u8, 84u8, 71u8, 0u8, 77u8, 89u8, 0u8, 90u8, 65u8, 0u8, 84u8, 82u8, + 0u8, + ]) + }, + ) + }, + ls2r: unsafe { + #[allow(unused_unsafe)] + ::zerovec::ZeroMap2d::from_parts_unchecked( + unsafe { + ::zerovec::ZeroVec::from_bytes_unchecked(&[ + 97u8, 114u8, 99u8, 97u8, 122u8, 0u8, 99u8, 117u8, 0u8, 101u8, 110u8, 0u8, + 102u8, 102u8, 0u8, 103u8, 114u8, 99u8, 107u8, 107u8, 0u8, 107u8, 117u8, + 0u8, 107u8, 121u8, 0u8, 108u8, 105u8, 102u8, 109u8, 97u8, 110u8, 109u8, + 110u8, 0u8, 112u8, 97u8, 0u8, 112u8, 97u8, 108u8, 115u8, 100u8, 0u8, 116u8, + 103u8, 0u8, 117u8, 103u8, 0u8, 117u8, 110u8, 114u8, 117u8, 122u8, 0u8, + 121u8, 117u8, 101u8, 122u8, 104u8, 0u8, + ]) + }, + unsafe { + ::zerovec::ZeroVec::from_bytes_unchecked(&[ + 2u8, 0u8, 0u8, 0u8, 3u8, 0u8, 0u8, 0u8, 4u8, 0u8, 0u8, 0u8, 5u8, 0u8, 0u8, + 0u8, 6u8, 0u8, 0u8, 0u8, 7u8, 0u8, 0u8, 0u8, 8u8, 0u8, 0u8, 0u8, 10u8, 0u8, + 0u8, 0u8, 12u8, 0u8, 0u8, 0u8, 13u8, 0u8, 0u8, 0u8, 14u8, 0u8, 0u8, 0u8, + 15u8, 0u8, 0u8, 0u8, 16u8, 0u8, 0u8, 0u8, 17u8, 0u8, 0u8, 0u8, 20u8, 0u8, + 0u8, 0u8, 21u8, 0u8, 0u8, 0u8, 22u8, 0u8, 0u8, 0u8, 23u8, 0u8, 0u8, 0u8, + 24u8, 0u8, 0u8, 0u8, 25u8, 0u8, 0u8, 0u8, 28u8, 0u8, 0u8, 0u8, + ]) + }, + unsafe { + ::zerovec::ZeroVec::from_bytes_unchecked(&[ + 78u8, 98u8, 97u8, 116u8, 80u8, 97u8, 108u8, 109u8, 65u8, 114u8, 97u8, 98u8, + 71u8, 108u8, 97u8, 103u8, 83u8, 104u8, 97u8, 119u8, 65u8, 100u8, 108u8, + 109u8, 76u8, 105u8, 110u8, 98u8, 65u8, 114u8, 97u8, 98u8, 65u8, 114u8, + 97u8, 98u8, 89u8, 101u8, 122u8, 105u8, 65u8, 114u8, 97u8, 98u8, 76u8, 97u8, + 116u8, 110u8, 76u8, 105u8, 109u8, 98u8, 78u8, 107u8, 111u8, 111u8, 77u8, + 111u8, 110u8, 103u8, 65u8, 114u8, 97u8, 98u8, 80u8, 104u8, 108u8, 112u8, + 68u8, 101u8, 118u8, 97u8, 75u8, 104u8, 111u8, 106u8, 83u8, 105u8, 110u8, + 100u8, 65u8, 114u8, 97u8, 98u8, 67u8, 121u8, 114u8, 108u8, 68u8, 101u8, + 118u8, 97u8, 65u8, 114u8, 97u8, 98u8, 72u8, 97u8, 110u8, 115u8, 66u8, + 111u8, 112u8, 111u8, 72u8, 97u8, 110u8, 98u8, 72u8, 97u8, 110u8, 116u8, + ]) + }, + unsafe { + ::zerovec::ZeroVec::from_bytes_unchecked(&[ + 74u8, 79u8, 0u8, 83u8, 89u8, 0u8, 73u8, 82u8, 0u8, 66u8, 71u8, 0u8, 71u8, + 66u8, 0u8, 71u8, 78u8, 0u8, 71u8, 82u8, 0u8, 67u8, 78u8, 0u8, 73u8, 81u8, + 0u8, 71u8, 69u8, 0u8, 67u8, 78u8, 0u8, 84u8, 82u8, 0u8, 73u8, 78u8, 0u8, + 71u8, 78u8, 0u8, 67u8, 78u8, 0u8, 80u8, 75u8, 0u8, 67u8, 78u8, 0u8, 73u8, + 78u8, 0u8, 73u8, 78u8, 0u8, 73u8, 78u8, 0u8, 80u8, 75u8, 0u8, 75u8, 90u8, + 0u8, 78u8, 80u8, 0u8, 65u8, 70u8, 0u8, 67u8, 78u8, 0u8, 84u8, 87u8, 0u8, + 84u8, 87u8, 0u8, 84u8, 87u8, 0u8, + ]) + }, + ) + }, + }; diff --git a/compiler/rustc_baked_icu_data/src/data/fallback/mod.rs b/compiler/rustc_baked_icu_data/src/data/fallback/mod.rs new file mode 100644 index 0000000000000..a485a5af64ca5 --- /dev/null +++ b/compiler/rustc_baked_icu_data/src/data/fallback/mod.rs @@ -0,0 +1,4 @@ +// @generated +pub mod likelysubtags_v1; +pub mod parents_v1; +pub mod supplement; diff --git a/compiler/rustc_baked_icu_data/src/data/fallback/parents_v1.rs b/compiler/rustc_baked_icu_data/src/data/fallback/parents_v1.rs new file mode 100644 index 0000000000000..f07b4b80649ef --- /dev/null +++ b/compiler/rustc_baked_icu_data/src/data/fallback/parents_v1.rs @@ -0,0 +1,207 @@ +// @generated +type DataStruct = < :: icu_provider_adapters :: fallback :: provider :: LocaleFallbackParentsV1Marker as :: icu_provider :: DataMarker > :: Yokeable ; +pub static DATA: litemap::LiteMap<&str, &DataStruct, &[(&str, &DataStruct)]> = + litemap::LiteMap::from_sorted_store_unchecked(&[("und", UND)]); +static UND: &DataStruct = &::icu_provider_adapters::fallback::provider::LocaleFallbackParentsV1 { + parents: unsafe { + #[allow(unused_unsafe)] + ::zerovec::ZeroMap::from_parts_unchecked( + unsafe { + ::zerovec::VarZeroVec::from_bytes_unchecked(&[ + 131u8, 0u8, 0u8, 0u8, 0u8, 0u8, 6u8, 0u8, 11u8, 0u8, 16u8, 0u8, 21u8, 0u8, + 26u8, 0u8, 31u8, 0u8, 36u8, 0u8, 41u8, 0u8, 46u8, 0u8, 51u8, 0u8, 56u8, 0u8, + 61u8, 0u8, 66u8, 0u8, 71u8, 0u8, 76u8, 0u8, 81u8, 0u8, 86u8, 0u8, 91u8, 0u8, + 96u8, 0u8, 101u8, 0u8, 106u8, 0u8, 111u8, 0u8, 116u8, 0u8, 121u8, 0u8, 126u8, + 0u8, 131u8, 0u8, 136u8, 0u8, 141u8, 0u8, 146u8, 0u8, 151u8, 0u8, 156u8, 0u8, + 161u8, 0u8, 166u8, 0u8, 171u8, 0u8, 176u8, 0u8, 181u8, 0u8, 186u8, 0u8, 191u8, + 0u8, 196u8, 0u8, 201u8, 0u8, 206u8, 0u8, 211u8, 0u8, 216u8, 0u8, 221u8, 0u8, + 226u8, 0u8, 231u8, 0u8, 236u8, 0u8, 241u8, 0u8, 246u8, 0u8, 251u8, 0u8, 0u8, + 1u8, 5u8, 1u8, 10u8, 1u8, 15u8, 1u8, 20u8, 1u8, 25u8, 1u8, 30u8, 1u8, 35u8, + 1u8, 40u8, 1u8, 45u8, 1u8, 50u8, 1u8, 55u8, 1u8, 60u8, 1u8, 65u8, 1u8, 70u8, + 1u8, 75u8, 1u8, 80u8, 1u8, 85u8, 1u8, 90u8, 1u8, 95u8, 1u8, 100u8, 1u8, 105u8, + 1u8, 110u8, 1u8, 115u8, 1u8, 120u8, 1u8, 125u8, 1u8, 130u8, 1u8, 135u8, 1u8, + 140u8, 1u8, 145u8, 1u8, 150u8, 1u8, 155u8, 1u8, 160u8, 1u8, 165u8, 1u8, 170u8, + 1u8, 175u8, 1u8, 180u8, 1u8, 185u8, 1u8, 190u8, 1u8, 195u8, 1u8, 200u8, 1u8, + 205u8, 1u8, 210u8, 1u8, 215u8, 1u8, 220u8, 1u8, 225u8, 1u8, 230u8, 1u8, 235u8, + 1u8, 240u8, 1u8, 245u8, 1u8, 250u8, 1u8, 255u8, 1u8, 4u8, 2u8, 9u8, 2u8, 14u8, + 2u8, 19u8, 2u8, 24u8, 2u8, 29u8, 2u8, 34u8, 2u8, 39u8, 2u8, 44u8, 2u8, 49u8, + 2u8, 54u8, 2u8, 59u8, 2u8, 64u8, 2u8, 71u8, 2u8, 73u8, 2u8, 75u8, 2u8, 77u8, + 2u8, 82u8, 2u8, 87u8, 2u8, 92u8, 2u8, 97u8, 2u8, 102u8, 2u8, 107u8, 2u8, 112u8, + 2u8, 117u8, 2u8, 122u8, 2u8, 127u8, 2u8, 132u8, 2u8, 101u8, 110u8, 45u8, 49u8, + 53u8, 48u8, 101u8, 110u8, 45u8, 65u8, 71u8, 101u8, 110u8, 45u8, 65u8, 73u8, + 101u8, 110u8, 45u8, 65u8, 84u8, 101u8, 110u8, 45u8, 65u8, 85u8, 101u8, 110u8, + 45u8, 66u8, 66u8, 101u8, 110u8, 45u8, 66u8, 69u8, 101u8, 110u8, 45u8, 66u8, + 77u8, 101u8, 110u8, 45u8, 66u8, 83u8, 101u8, 110u8, 45u8, 66u8, 87u8, 101u8, + 110u8, 45u8, 66u8, 90u8, 101u8, 110u8, 45u8, 67u8, 67u8, 101u8, 110u8, 45u8, + 67u8, 72u8, 101u8, 110u8, 45u8, 67u8, 75u8, 101u8, 110u8, 45u8, 67u8, 77u8, + 101u8, 110u8, 45u8, 67u8, 88u8, 101u8, 110u8, 45u8, 67u8, 89u8, 101u8, 110u8, + 45u8, 68u8, 69u8, 101u8, 110u8, 45u8, 68u8, 71u8, 101u8, 110u8, 45u8, 68u8, + 75u8, 101u8, 110u8, 45u8, 68u8, 77u8, 101u8, 110u8, 45u8, 69u8, 82u8, 101u8, + 110u8, 45u8, 70u8, 73u8, 101u8, 110u8, 45u8, 70u8, 74u8, 101u8, 110u8, 45u8, + 70u8, 75u8, 101u8, 110u8, 45u8, 70u8, 77u8, 101u8, 110u8, 45u8, 71u8, 66u8, + 101u8, 110u8, 45u8, 71u8, 68u8, 101u8, 110u8, 45u8, 71u8, 71u8, 101u8, 110u8, + 45u8, 71u8, 72u8, 101u8, 110u8, 45u8, 71u8, 73u8, 101u8, 110u8, 45u8, 71u8, + 77u8, 101u8, 110u8, 45u8, 71u8, 89u8, 101u8, 110u8, 45u8, 72u8, 75u8, 101u8, + 110u8, 45u8, 73u8, 69u8, 101u8, 110u8, 45u8, 73u8, 76u8, 101u8, 110u8, 45u8, + 73u8, 77u8, 101u8, 110u8, 45u8, 73u8, 78u8, 101u8, 110u8, 45u8, 73u8, 79u8, + 101u8, 110u8, 45u8, 74u8, 69u8, 101u8, 110u8, 45u8, 74u8, 77u8, 101u8, 110u8, + 45u8, 75u8, 69u8, 101u8, 110u8, 45u8, 75u8, 73u8, 101u8, 110u8, 45u8, 75u8, + 78u8, 101u8, 110u8, 45u8, 75u8, 89u8, 101u8, 110u8, 45u8, 76u8, 67u8, 101u8, + 110u8, 45u8, 76u8, 82u8, 101u8, 110u8, 45u8, 76u8, 83u8, 101u8, 110u8, 45u8, + 77u8, 71u8, 101u8, 110u8, 45u8, 77u8, 79u8, 101u8, 110u8, 45u8, 77u8, 83u8, + 101u8, 110u8, 45u8, 77u8, 84u8, 101u8, 110u8, 45u8, 77u8, 85u8, 101u8, 110u8, + 45u8, 77u8, 86u8, 101u8, 110u8, 45u8, 77u8, 87u8, 101u8, 110u8, 45u8, 77u8, + 89u8, 101u8, 110u8, 45u8, 78u8, 65u8, 101u8, 110u8, 45u8, 78u8, 70u8, 101u8, + 110u8, 45u8, 78u8, 71u8, 101u8, 110u8, 45u8, 78u8, 76u8, 101u8, 110u8, 45u8, + 78u8, 82u8, 101u8, 110u8, 45u8, 78u8, 85u8, 101u8, 110u8, 45u8, 78u8, 90u8, + 101u8, 110u8, 45u8, 80u8, 71u8, 101u8, 110u8, 45u8, 80u8, 75u8, 101u8, 110u8, + 45u8, 80u8, 78u8, 101u8, 110u8, 45u8, 80u8, 87u8, 101u8, 110u8, 45u8, 82u8, + 87u8, 101u8, 110u8, 45u8, 83u8, 66u8, 101u8, 110u8, 45u8, 83u8, 67u8, 101u8, + 110u8, 45u8, 83u8, 68u8, 101u8, 110u8, 45u8, 83u8, 69u8, 101u8, 110u8, 45u8, + 83u8, 71u8, 101u8, 110u8, 45u8, 83u8, 72u8, 101u8, 110u8, 45u8, 83u8, 73u8, + 101u8, 110u8, 45u8, 83u8, 76u8, 101u8, 110u8, 45u8, 83u8, 83u8, 101u8, 110u8, + 45u8, 83u8, 88u8, 101u8, 110u8, 45u8, 83u8, 90u8, 101u8, 110u8, 45u8, 84u8, + 67u8, 101u8, 110u8, 45u8, 84u8, 75u8, 101u8, 110u8, 45u8, 84u8, 79u8, 101u8, + 110u8, 45u8, 84u8, 84u8, 101u8, 110u8, 45u8, 84u8, 86u8, 101u8, 110u8, 45u8, + 84u8, 90u8, 101u8, 110u8, 45u8, 85u8, 71u8, 101u8, 110u8, 45u8, 86u8, 67u8, + 101u8, 110u8, 45u8, 86u8, 71u8, 101u8, 110u8, 45u8, 86u8, 85u8, 101u8, 110u8, + 45u8, 87u8, 83u8, 101u8, 110u8, 45u8, 90u8, 65u8, 101u8, 110u8, 45u8, 90u8, + 77u8, 101u8, 110u8, 45u8, 90u8, 87u8, 101u8, 115u8, 45u8, 65u8, 82u8, 101u8, + 115u8, 45u8, 66u8, 79u8, 101u8, 115u8, 45u8, 66u8, 82u8, 101u8, 115u8, 45u8, + 66u8, 90u8, 101u8, 115u8, 45u8, 67u8, 76u8, 101u8, 115u8, 45u8, 67u8, 79u8, + 101u8, 115u8, 45u8, 67u8, 82u8, 101u8, 115u8, 45u8, 67u8, 85u8, 101u8, 115u8, + 45u8, 68u8, 79u8, 101u8, 115u8, 45u8, 69u8, 67u8, 101u8, 115u8, 45u8, 71u8, + 84u8, 101u8, 115u8, 45u8, 72u8, 78u8, 101u8, 115u8, 45u8, 77u8, 88u8, 101u8, + 115u8, 45u8, 78u8, 73u8, 101u8, 115u8, 45u8, 80u8, 65u8, 101u8, 115u8, 45u8, + 80u8, 69u8, 101u8, 115u8, 45u8, 80u8, 82u8, 101u8, 115u8, 45u8, 80u8, 89u8, + 101u8, 115u8, 45u8, 83u8, 86u8, 101u8, 115u8, 45u8, 85u8, 83u8, 101u8, 115u8, + 45u8, 85u8, 89u8, 101u8, 115u8, 45u8, 86u8, 69u8, 104u8, 105u8, 45u8, 76u8, + 97u8, 116u8, 110u8, 104u8, 116u8, 110u8, 98u8, 110u8, 110u8, 112u8, 116u8, + 45u8, 65u8, 79u8, 112u8, 116u8, 45u8, 67u8, 72u8, 112u8, 116u8, 45u8, 67u8, + 86u8, 112u8, 116u8, 45u8, 70u8, 82u8, 112u8, 116u8, 45u8, 71u8, 81u8, 112u8, + 116u8, 45u8, 71u8, 87u8, 112u8, 116u8, 45u8, 76u8, 85u8, 112u8, 116u8, 45u8, + 77u8, 79u8, 112u8, 116u8, 45u8, 77u8, 90u8, 112u8, 116u8, 45u8, 83u8, 84u8, + 112u8, 116u8, 45u8, 84u8, 76u8, 122u8, 104u8, 45u8, 72u8, 97u8, 110u8, 116u8, + 45u8, 77u8, 79u8, + ]) + }, + unsafe { + ::zerovec::ZeroVec::from_bytes_unchecked(&[ + 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, + 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 49u8, 53u8, 48u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, + 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 49u8, 53u8, + 48u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, + 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, + 49u8, 53u8, 48u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, + 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, + 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 49u8, 53u8, 48u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, + 49u8, 53u8, 48u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, + 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, + 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 49u8, 53u8, 48u8, 101u8, 110u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, + 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, + 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, + 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, + 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, + 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, + 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, + 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, + 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, + 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, + 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, + 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, + 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, + 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, + 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, + 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 49u8, 53u8, 48u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, + 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, + 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, + 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, + 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, + 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, + 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 49u8, 53u8, 48u8, 101u8, 110u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 1u8, 49u8, 53u8, 48u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, + 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, + 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, + 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, + 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, + 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, + 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, + 48u8, 48u8, 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, + 49u8, 101u8, 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, + 110u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 48u8, 48u8, 49u8, 101u8, 115u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 52u8, 49u8, 57u8, 101u8, 115u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 52u8, 49u8, 57u8, 101u8, 115u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 1u8, 52u8, 49u8, 57u8, 101u8, 115u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, + 52u8, 49u8, 57u8, 101u8, 115u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 52u8, 49u8, + 57u8, 101u8, 115u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 52u8, 49u8, 57u8, 101u8, + 115u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 52u8, 49u8, 57u8, 101u8, 115u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 52u8, 49u8, 57u8, 101u8, 115u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 52u8, 49u8, 57u8, 101u8, 115u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 1u8, 52u8, 49u8, 57u8, 101u8, 115u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, + 52u8, 49u8, 57u8, 101u8, 115u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 52u8, 49u8, + 57u8, 101u8, 115u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 52u8, 49u8, 57u8, 101u8, + 115u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 52u8, 49u8, 57u8, 101u8, 115u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 52u8, 49u8, 57u8, 101u8, 115u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 52u8, 49u8, 57u8, 101u8, 115u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 1u8, 52u8, 49u8, 57u8, 101u8, 115u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, + 52u8, 49u8, 57u8, 101u8, 115u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 52u8, 49u8, + 57u8, 101u8, 115u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 52u8, 49u8, 57u8, 101u8, + 115u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 52u8, 49u8, 57u8, 101u8, 115u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 52u8, 49u8, 57u8, 101u8, 110u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 1u8, 73u8, 78u8, 0u8, 102u8, 114u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 1u8, 72u8, 84u8, 0u8, 110u8, 111u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 110u8, 111u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 112u8, 116u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 80u8, 84u8, 0u8, 112u8, 116u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 80u8, 84u8, 0u8, 112u8, 116u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 1u8, 80u8, 84u8, 0u8, 112u8, 116u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 1u8, 80u8, 84u8, 0u8, 112u8, 116u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 1u8, 80u8, 84u8, 0u8, 112u8, 116u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 80u8, + 84u8, 0u8, 112u8, 116u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 80u8, 84u8, 0u8, + 112u8, 116u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 80u8, 84u8, 0u8, 112u8, 116u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 80u8, 84u8, 0u8, 112u8, 116u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 1u8, 80u8, 84u8, 0u8, 112u8, 116u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 1u8, 80u8, 84u8, 0u8, 122u8, 104u8, 0u8, 1u8, 72u8, 97u8, 110u8, + 116u8, 1u8, 72u8, 75u8, 0u8, + ]) + }, + ) + }, +}; diff --git a/compiler/rustc_baked_icu_data/src/data/fallback/supplement/co_v1.rs b/compiler/rustc_baked_icu_data/src/data/fallback/supplement/co_v1.rs new file mode 100644 index 0000000000000..7df33c12e3d5a --- /dev/null +++ b/compiler/rustc_baked_icu_data/src/data/fallback/supplement/co_v1.rs @@ -0,0 +1,41 @@ +// @generated +type DataStruct = < :: icu_provider_adapters :: fallback :: provider :: CollationFallbackSupplementV1Marker as :: icu_provider :: DataMarker > :: Yokeable ; +pub static DATA: litemap::LiteMap<&str, &DataStruct, &[(&str, &DataStruct)]> = + litemap::LiteMap::from_sorted_store_unchecked(&[("und", UND)]); +static UND: &DataStruct = + &::icu_provider_adapters::fallback::provider::LocaleFallbackSupplementV1 { + parents: unsafe { + #[allow(unused_unsafe)] + ::zerovec::ZeroMap::from_parts_unchecked( + unsafe { + ::zerovec::VarZeroVec::from_bytes_unchecked(&[ + 1u8, 0u8, 0u8, 0u8, 0u8, 0u8, 121u8, 117u8, 101u8, + ]) + }, + unsafe { + ::zerovec::ZeroVec::from_bytes_unchecked(&[ + 122u8, 104u8, 0u8, 1u8, 72u8, 97u8, 110u8, 116u8, 0u8, 0u8, 0u8, 0u8, + ]) + }, + ) + }, + unicode_extension_defaults: unsafe { + #[allow(unused_unsafe)] + ::zerovec::ZeroMap2d::from_parts_unchecked( + unsafe { ::zerovec::ZeroVec::from_bytes_unchecked(&[99u8, 111u8]) }, + unsafe { ::zerovec::ZeroVec::from_bytes_unchecked(&[2u8, 0u8, 0u8, 0u8]) }, + unsafe { + ::zerovec::VarZeroVec::from_bytes_unchecked(&[ + 2u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 122u8, 104u8, 122u8, 104u8, 45u8, + 72u8, 97u8, 110u8, 116u8, + ]) + }, + unsafe { + ::zerovec::VarZeroVec::from_bytes_unchecked(&[ + 2u8, 0u8, 0u8, 0u8, 0u8, 0u8, 6u8, 0u8, 112u8, 105u8, 110u8, 121u8, 105u8, + 110u8, 115u8, 116u8, 114u8, 111u8, 107u8, 101u8, + ]) + }, + ) + }, + }; diff --git a/compiler/rustc_baked_icu_data/src/data/fallback/supplement/mod.rs b/compiler/rustc_baked_icu_data/src/data/fallback/supplement/mod.rs new file mode 100644 index 0000000000000..62957134f0755 --- /dev/null +++ b/compiler/rustc_baked_icu_data/src/data/fallback/supplement/mod.rs @@ -0,0 +1,2 @@ +// @generated +pub mod co_v1; diff --git a/compiler/rustc_baked_icu_data/src/data/mod.rs b/compiler/rustc_baked_icu_data/src/data/mod.rs index 8ffacffaf4998..a6a71c79cd1ba 100644 --- a/compiler/rustc_baked_icu_data/src/data/mod.rs +++ b/compiler/rustc_baked_icu_data/src/data/mod.rs @@ -1,4 +1,5 @@ // @generated +mod fallback; mod list; /// This data provider was programmatically generated by [`icu_datagen`]( /// https://unicode-org.github.io/icu4x-docs/doc/icu_datagen/enum.Out.html#variant.Module). @@ -23,3 +24,67 @@ impl DataProvider<::icu_list::provider::AndListV1Marker> for BakedDataProvider { }) } } +impl DataProvider<::icu_provider_adapters::fallback::provider::CollationFallbackSupplementV1Marker> + for BakedDataProvider +{ + fn load( + &self, + req: DataRequest, + ) -> Result< + DataResponse< + ::icu_provider_adapters::fallback::provider::CollationFallbackSupplementV1Marker, + >, + DataError, + > { + Ok(DataResponse { + metadata: Default::default(), + payload: Some(DataPayload::from_owned(zerofrom::ZeroFrom::zero_from( + *fallback::supplement::co_v1::DATA.get_by(|k| req.locale.strict_cmp(k.as_bytes()).reverse()).ok_or_else(|| { + DataErrorKind::MissingLocale.with_req(::icu_provider_adapters::fallback::provider::CollationFallbackSupplementV1Marker::KEY, req) + })?, + ))), + }) + } +} +impl DataProvider<::icu_provider_adapters::fallback::provider::LocaleFallbackLikelySubtagsV1Marker> + for BakedDataProvider +{ + fn load( + &self, + req: DataRequest, + ) -> Result< + DataResponse< + ::icu_provider_adapters::fallback::provider::LocaleFallbackLikelySubtagsV1Marker, + >, + DataError, + > { + Ok(DataResponse { + metadata: Default::default(), + payload: Some(DataPayload::from_owned(zerofrom::ZeroFrom::zero_from( + *fallback::likelysubtags_v1::DATA.get_by(|k| req.locale.strict_cmp(k.as_bytes()).reverse()).ok_or_else(|| { + DataErrorKind::MissingLocale.with_req(::icu_provider_adapters::fallback::provider::LocaleFallbackLikelySubtagsV1Marker::KEY, req) + })?, + ))), + }) + } +} +impl DataProvider<::icu_provider_adapters::fallback::provider::LocaleFallbackParentsV1Marker> + for BakedDataProvider +{ + fn load( + &self, + req: DataRequest, + ) -> Result< + DataResponse<::icu_provider_adapters::fallback::provider::LocaleFallbackParentsV1Marker>, + DataError, + > { + Ok(DataResponse { + metadata: Default::default(), + payload: Some(DataPayload::from_owned(zerofrom::ZeroFrom::zero_from( + *fallback::parents_v1::DATA.get_by(|k| req.locale.strict_cmp(k.as_bytes()).reverse()).ok_or_else(|| { + DataErrorKind::MissingLocale.with_req(::icu_provider_adapters::fallback::provider::LocaleFallbackParentsV1Marker::KEY, req) + })?, + ))), + }) + } +} diff --git a/compiler/rustc_baked_icu_data/src/lib.rs b/compiler/rustc_baked_icu_data/src/lib.rs index 76c9bc97346f5..b76ee6cae06ec 100644 --- a/compiler/rustc_baked_icu_data/src/lib.rs +++ b/compiler/rustc_baked_icu_data/src/lib.rs @@ -5,11 +5,27 @@ /* generated with: ```text icu4x-datagen -W --pretty --fingerprint --use-separate-crates --cldr-tag latest --icuexport-tag latest \ ---format mod -l en es fr it ja pt ru tr zh-Hans zh-Hant -k list/and@1 -o src/data +--format mod -l en es fr it ja pt ru tr zh-Hans zh-Hant -k list/and@1 fallback/likelysubtags@1 fallback/parents@1 fallback/supplement/co@1 \ +-o src/data ``` */ -mod data; +// FIXME: Workaround https://github.com/unicode-org/icu4x/issues/2815 +mod data { + /* + use super::data::BakedDataProvider; + use icu_provider::{ + AnyPayload, AnyProvider, AnyResponse, DataError, DataErrorKind, DataKey, DataRequest, + KeyedDataMarker, + }; + + use crate::data::fallback; + use crate::data::list; + */ + + include!("data/mod.rs"); + include!("data/any.rs"); +} pub use data::BakedDataProvider; diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs index d026f5c8daf30..91331498ce32e 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -607,19 +607,20 @@ pub fn fluent_value_from_str_list_sep_by_and<'source>( Self: Sized, { let baked_data_provider = rustc_baked_icu_data::baked_data_provider(); - let locale_fallbacker = LocaleFallbacker::try_new_unstable(&baked_data_provider); - let data_provider = LocaleFallbackProvider::new_with_fallbacker( - &baked_data_provider, - locale_fallbacker, - ); + let locale_fallbacker = + LocaleFallbacker::try_new_with_any_provider(&baked_data_provider) + .expect("Failed to create fallback provider"); + let data_provider = + LocaleFallbackProvider::new_with_fallbacker(baked_data_provider, locale_fallbacker); let locale = icu_locale_from_unic_langid(lang) .unwrap_or_else(|| rustc_baked_icu_data::supported_locales::EN); - let list_formatter = icu_list::ListFormatter::try_new_and_with_length_unstable( - &data_provider, - &locale.into(), - icu_list::ListLength::Wide, - ) - .expect("Failed to create list formatter"); + let list_formatter = + icu_list::ListFormatter::try_new_and_with_length_with_any_provider( + &data_provider, + &locale.into(), + icu_list::ListLength::Wide, + ) + .expect("Failed to create list formatter"); Ok(MemoizableListFormatter(list_formatter)) } diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 76d278667f5a9..8155ec9dd27e2 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -136,6 +136,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "icu_list", "icu_locid", "icu_provider", + "icu_provider_adapters", "icu_provider_macros", "if_chain", "indexmap", From d15b020278fc97ec978af94159e5b0f70e14c6ed Mon Sep 17 00:00:00 2001 From: Charles Lew Date: Mon, 7 Nov 2022 01:25:48 +0800 Subject: [PATCH 074/103] Enable icu sync feature for parallel compiler --- compiler/rustc_baked_icu_data/Cargo.toml | 3 +++ compiler/rustc_error_messages/Cargo.toml | 3 +++ compiler/rustc_errors/Cargo.toml | 3 +++ compiler/rustc_interface/Cargo.toml | 2 +- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_baked_icu_data/Cargo.toml b/compiler/rustc_baked_icu_data/Cargo.toml index 6486491d07739..3477306dbfc95 100644 --- a/compiler/rustc_baked_icu_data/Cargo.toml +++ b/compiler/rustc_baked_icu_data/Cargo.toml @@ -10,3 +10,6 @@ icu_provider = "1.0.1" icu_provider_adapters = "1.0.0" litemap = "0.6.0" zerovec = "0.9.0" + +[features] +rustc_use_parallel_compiler = ['icu_provider/sync'] diff --git a/compiler/rustc_error_messages/Cargo.toml b/compiler/rustc_error_messages/Cargo.toml index bb6edfb090325..0c705d2ecf5ff 100644 --- a/compiler/rustc_error_messages/Cargo.toml +++ b/compiler/rustc_error_messages/Cargo.toml @@ -20,3 +20,6 @@ icu_list = "1.0.0" writeable = "0.5.0" icu_locid = "1.0.0" icu_provider_adapters = "1.0.0" + +[features] +rustc_use_parallel_compiler = ['rustc_baked_icu_data/rustc_use_parallel_compiler'] diff --git a/compiler/rustc_errors/Cargo.toml b/compiler/rustc_errors/Cargo.toml index 7803a0792e12c..c21d5d9d74e67 100644 --- a/compiler/rustc_errors/Cargo.toml +++ b/compiler/rustc_errors/Cargo.toml @@ -27,3 +27,6 @@ serde_json = "1.0.59" [target.'cfg(windows)'.dependencies] winapi = { version = "0.3", features = [ "handleapi", "synchapi", "winbase" ] } + +[features] +rustc_use_parallel_compiler = ['rustc_error_messages/rustc_use_parallel_compiler'] diff --git a/compiler/rustc_interface/Cargo.toml b/compiler/rustc_interface/Cargo.toml index 2e526733df974..e67dec31dcee3 100644 --- a/compiler/rustc_interface/Cargo.toml +++ b/compiler/rustc_interface/Cargo.toml @@ -53,4 +53,4 @@ rustc_target = { path = "../rustc_target" } [features] llvm = ['rustc_codegen_llvm'] -rustc_use_parallel_compiler = ['rayon', 'rustc-rayon-core', 'rustc_query_impl/rustc_use_parallel_compiler'] +rustc_use_parallel_compiler = ['rayon', 'rustc-rayon-core', 'rustc_query_impl/rustc_use_parallel_compiler', 'rustc_errors/rustc_use_parallel_compiler'] From 707c035e006b7ed6e81081628a27cb6d6211bf06 Mon Sep 17 00:00:00 2001 From: Charles Lew Date: Mon, 7 Nov 2022 01:34:22 +0800 Subject: [PATCH 075/103] Include `zh` locale in icu data --- .../rustc_baked_icu_data/src/data/list/and_v1.rs | 15 ++++++++------- compiler/rustc_baked_icu_data/src/lib.rs | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_baked_icu_data/src/data/list/and_v1.rs b/compiler/rustc_baked_icu_data/src/data/list/and_v1.rs index aefaa2cc9c939..9cae549e118d5 100644 --- a/compiler/rustc_baked_icu_data/src/data/list/and_v1.rs +++ b/compiler/rustc_baked_icu_data/src/data/list/and_v1.rs @@ -11,7 +11,8 @@ pub static DATA: litemap::LiteMap<&str, &DataStruct, &[(&str, &DataStruct)]> = ("ru", RU), ("tr", TR), ("und", UND), - ("zh-Hans", ZH_HANS), + ("zh", ZH_ZH_HANS), + ("zh-Hans", ZH_ZH_HANS), ("zh-Hant", ZH_HANT), ]); static EN: &DataStruct = &::icu_list::provider::ListFormatterPatternsV1([ @@ -1010,7 +1011,7 @@ static UND: &DataStruct = &::icu_list::provider::ListFormatterPatternsV1([ special_case: None, }, ]); -static ZH_HANS: &DataStruct = &::icu_list::provider::ListFormatterPatternsV1([ +static ZH_HANT: &DataStruct = &::icu_list::provider::ListFormatterPatternsV1([ ::icu_list::provider::ConditionalListJoinerPattern { default: unsafe { ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) @@ -1073,18 +1074,18 @@ static ZH_HANS: &DataStruct = &::icu_list::provider::ListFormatterPatternsV1([ }, ::icu_list::provider::ConditionalListJoinerPattern { default: unsafe { - ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("和", 3u8) }, special_case: None, }, ::icu_list::provider::ConditionalListJoinerPattern { default: unsafe { - ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("和", 3u8) }, special_case: None, }, ]); -static ZH_HANT: &DataStruct = &::icu_list::provider::ListFormatterPatternsV1([ +static ZH_ZH_HANS: &DataStruct = &::icu_list::provider::ListFormatterPatternsV1([ ::icu_list::provider::ConditionalListJoinerPattern { default: unsafe { ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) @@ -1147,13 +1148,13 @@ static ZH_HANT: &DataStruct = &::icu_list::provider::ListFormatterPatternsV1([ }, ::icu_list::provider::ConditionalListJoinerPattern { default: unsafe { - ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("和", 3u8) + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) }, special_case: None, }, ::icu_list::provider::ConditionalListJoinerPattern { default: unsafe { - ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("和", 3u8) + ::icu_list::provider::ListJoinerPattern::from_parts_unchecked("、", 3u8) }, special_case: None, }, diff --git a/compiler/rustc_baked_icu_data/src/lib.rs b/compiler/rustc_baked_icu_data/src/lib.rs index b76ee6cae06ec..2109a7a780b11 100644 --- a/compiler/rustc_baked_icu_data/src/lib.rs +++ b/compiler/rustc_baked_icu_data/src/lib.rs @@ -5,7 +5,7 @@ /* generated with: ```text icu4x-datagen -W --pretty --fingerprint --use-separate-crates --cldr-tag latest --icuexport-tag latest \ ---format mod -l en es fr it ja pt ru tr zh-Hans zh-Hant -k list/and@1 fallback/likelysubtags@1 fallback/parents@1 fallback/supplement/co@1 \ +--format mod -l en es fr it ja pt ru tr zh zh-Hans zh-Hant -k list/and@1 fallback/likelysubtags@1 fallback/parents@1 fallback/supplement/co@1 \ -o src/data ``` */ From b21e0b82c5245bb8329564bc328703bd03536dd2 Mon Sep 17 00:00:00 2001 From: Charles Lew Date: Sat, 12 Nov 2022 18:50:57 +0800 Subject: [PATCH 076/103] Fix compilation issue after rebase --- compiler/rustc_errors/src/diagnostic.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 2c1d0037aa64f..7d5e4723a6d88 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -51,6 +51,9 @@ impl<'source> IntoDiagnosticArg for DiagnosticArgValue<'source> { match self { DiagnosticArgValue::Str(s) => DiagnosticArgValue::Str(Cow::Owned(s.into_owned())), DiagnosticArgValue::Number(n) => DiagnosticArgValue::Number(n), + DiagnosticArgValue::StrListSepByAnd(l) => DiagnosticArgValue::StrListSepByAnd( + l.into_iter().map(|s| Cow::Owned(s.into_owned())).collect(), + ), } } } From b22cb90e0a1c228e3705dc546dd9be7da049dd88 Mon Sep 17 00:00:00 2001 From: Charles Lew Date: Wed, 16 Nov 2022 02:37:00 +0800 Subject: [PATCH 077/103] Update crate documentation of `rustc_baked_icu_data` crate --- compiler/rustc_baked_icu_data/src/lib.rs | 41 ++++++++++++------------ 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/compiler/rustc_baked_icu_data/src/lib.rs b/compiler/rustc_baked_icu_data/src/lib.rs index 2109a7a780b11..4651e03f77166 100644 --- a/compiler/rustc_baked_icu_data/src/lib.rs +++ b/compiler/rustc_baked_icu_data/src/lib.rs @@ -1,28 +1,27 @@ -//! Baked ICU data for eager translation support. +//! This crate contains pre-baked ICU4X data, generated by `icu4x-datagen`. The tool +//! fetches locale data from CLDR and transforms them into const code in statics that +//! ICU4X can load, via databake. `lib.rs` in this crate is manually written, but all +//! other code is generated. //! +//! This crate can be regenerated when there's a new CLDR version, though that is unlikely +//! to result in changes in most cases (currently this only covers list formatting data, which +//! is rather stable). It may need to be regenerated when updating ICU4X versions, especially +//! across major versions, in case it fails to compile after an update. +//! +//! It must be regenerated when adding new locales to Rust, or if Rust's usage of ICU4X +//! grows to need more kinds of data. +//! +//! To regenerate the data, run this command: +//! +//! ```text +//! icu4x-datagen -W --pretty --fingerprint --use-separate-crates \ +//! --format mod -l en es fr it ja pt ru tr zh zh-Hans zh-Hant \ +//! -k list/and@1 fallback/likelysubtags@1 fallback/parents@1 fallback/supplement/co@1 \ +//! --cldr-tag latest --icuexport-tag latest -o src/data +//! ``` #![allow(elided_lifetimes_in_paths)] -/* generated with: -```text -icu4x-datagen -W --pretty --fingerprint --use-separate-crates --cldr-tag latest --icuexport-tag latest \ ---format mod -l en es fr it ja pt ru tr zh zh-Hans zh-Hant -k list/and@1 fallback/likelysubtags@1 fallback/parents@1 fallback/supplement/co@1 \ --o src/data -``` -*/ - -// FIXME: Workaround https://github.com/unicode-org/icu4x/issues/2815 mod data { - /* - use super::data::BakedDataProvider; - use icu_provider::{ - AnyPayload, AnyProvider, AnyResponse, DataError, DataErrorKind, DataKey, DataRequest, - KeyedDataMarker, - }; - - use crate::data::fallback; - use crate::data::list; - */ - include!("data/mod.rs"); include!("data/any.rs"); } From 2721e407373711d59906dd5114bb14bf405c2e9e Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 18 Nov 2022 14:46:52 -0800 Subject: [PATCH 078/103] Fix lockfile --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index fbd81d833814c..337d520979534 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -222,7 +222,7 @@ checksum = "fca0852af221f458706eb0725c03e4ed6c46af9ac98e6a689d5e634215d594dd" dependencies = [ "memchr", "once_cell", - "regex-automata", + "regex-automata 0.1.10", "serde", ] From 59c856c071d3cdb5bd8d0d5b49c49be15f72d82a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 19 Nov 2022 00:25:21 +0100 Subject: [PATCH 079/103] Fix invalid focus when blurring notable traits popover --- src/librustdoc/html/static/js/main.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 67eff9497e121..75b3dce2eda86 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -795,7 +795,7 @@ function loadCss(cssUrl) { // This means when the window is resized, we need to redo the layout. const base = window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE; const force_visible = base.NOTABLE_FORCE_VISIBLE; - hideNotable(); + hideNotable(false); if (force_visible) { showNotable(base); base.NOTABLE_FORCE_VISIBLE = true; @@ -846,7 +846,7 @@ function loadCss(cssUrl) { // Make this function idempotent. return; } - hideNotable(); + hideNotable(false); const ty = e.getAttribute("data-ty"); const wrapper = document.createElement("div"); wrapper.innerHTML = "
" + window.NOTABLE_TRAITS[ty] + "
"; @@ -883,7 +883,7 @@ function loadCss(cssUrl) { return; } if (!e.NOTABLE_FORCE_VISIBLE && !elemIsInParent(event.relatedTarget, e)) { - hideNotable(); + hideNotable(true); } }; } @@ -903,13 +903,16 @@ function loadCss(cssUrl) { // To work around this, make sure the click finishes being dispatched before // hiding the popover. Since `hideNotable()` is idempotent, this makes Safari behave // consistently with the other two. - setTimeout(hideNotable, 0); + setTimeout(() => hideNotable(false), 0); } } - function hideNotable() { + function hideNotable(focus) { if (window.CURRENT_NOTABLE_ELEMENT) { if (window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE) { + if (focus) { + window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.focus(); + } window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE = false; } const body = document.getElementsByTagName("body")[0]; @@ -922,7 +925,7 @@ function loadCss(cssUrl) { e.onclick = function() { this.NOTABLE_FORCE_VISIBLE = this.NOTABLE_FORCE_VISIBLE ? false : true; if (window.CURRENT_NOTABLE_ELEMENT && !this.NOTABLE_FORCE_VISIBLE) { - hideNotable(); + hideNotable(true); } else { showNotable(this); window.CURRENT_NOTABLE_ELEMENT.setAttribute("tabindex", "0"); @@ -945,7 +948,7 @@ function loadCss(cssUrl) { } if (!this.NOTABLE_FORCE_VISIBLE && !elemIsInParent(event.relatedTarget, window.CURRENT_NOTABLE_ELEMENT)) { - hideNotable(); + hideNotable(true); } }; }); @@ -1056,7 +1059,7 @@ function loadCss(cssUrl) { onEachLazy(document.querySelectorAll(".search-form .popover"), elem => { elem.style.display = "none"; }); - hideNotable(); + hideNotable(false); }; /** From 87f81b0a9c5fc578c6dfb2f0c3de9e888700e280 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 19 Nov 2022 00:25:37 +0100 Subject: [PATCH 080/103] Extend GUI test to check notable traits blur behaviour --- src/test/rustdoc-gui/notable-trait.goml | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/rustdoc-gui/notable-trait.goml b/src/test/rustdoc-gui/notable-trait.goml index 4c3943d885830..aab3b11433e93 100644 --- a/src/test/rustdoc-gui/notable-trait.goml +++ b/src/test/rustdoc-gui/notable-trait.goml @@ -219,3 +219,33 @@ press-key: "Tab" press-key: "Tab" press-key: "Tab" assert-count: ("//*[@class='notable popover']", 0) +assert: "#method\.create_an_iterator_from_read .notable-traits:focus" + +// Now we check that the focus isn't given back to the wrong item when opening +// another popover. +store-window-property: (scroll, "scrollY") +click: "#method\.create_an_iterator_from_read .fnname" +// We ensure that the scroll position changed. +assert-window-property-false: {"scrollY": |scroll|} +// Store the new position. +store-window-property: (scroll, "scrollY") +click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" +wait-for: "//*[@class='notable popover']" +click: "#settings-menu a" +click: ".search-input" +// We ensure we didn't come back to the previous focused item. +assert-window-property-false: {"scrollY": |scroll|} + +// Same but with Escape handling. +store-window-property: (scroll, "scrollY") +click: "#method\.create_an_iterator_from_read .fnname" +// We ensure that the scroll position changed. +assert-window-property-false: {"scrollY": |scroll|} +// Store the new position. +store-window-property: (scroll, "scrollY") +click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" +wait-for: "//*[@class='notable popover']" +click: "#settings-menu a" +press-key: "Escape" +// We ensure we didn't come back to the previous focused item. +assert-window-property-false: {"scrollY": |scroll|} From 5ed8dca7212c25a5557dc249037ec0c8b271c7b6 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 19 Nov 2022 00:27:37 +0100 Subject: [PATCH 081/103] Update browser-ui-test version to 0.13.2 --- .../docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version b/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version index ed0d9e9902b99..3f8dcd03d2db1 100644 --- a/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version +++ b/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version @@ -1 +1 @@ -0.13.1 \ No newline at end of file +0.13.2 \ No newline at end of file From f13c4f4d6a4f0bb042839613bc92e9d3cfd9c308 Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Fri, 7 Oct 2022 20:57:34 +0200 Subject: [PATCH 082/103] constify `exact_div` intrinsic --- compiler/rustc_const_eval/src/interpret/intrinsics.rs | 5 +++++ library/core/src/intrinsics.rs | 1 + library/core/src/lib.rs | 1 + src/tools/miri/src/shims/intrinsics/mod.rs | 5 ----- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index 6fc2407b77803..7940efcd2b11f 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -243,6 +243,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let discr_val = self.read_discriminant(&place.into())?.0; self.write_scalar(discr_val, dest)?; } + sym::exact_div => { + let l = self.read_immediate(&args[0])?; + let r = self.read_immediate(&args[1])?; + self.exact_div(&l, &r, dest)?; + } sym::unchecked_shl | sym::unchecked_shr | sym::unchecked_add diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 819ccf5a3e9e7..7ed7d767f2fb5 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -1851,6 +1851,7 @@ extern "rust-intrinsic" { /// `x % y != 0` or `y == 0` or `x == T::MIN && y == -1` /// /// This intrinsic does not have a stable counterpart. + #[rustc_const_unstable(feature = "const_exact_div", issue = "none")] pub fn exact_div(x: T, y: T) -> T; /// Performs an unchecked division, resulting in undefined behavior diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 7191bbb93447c..33b969c249a2f 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -109,6 +109,7 @@ #![feature(const_cmp)] #![feature(const_discriminant)] #![feature(const_eval_select)] +#![feature(const_exact_div)] #![feature(const_float_bits_conv)] #![feature(const_float_classify)] #![feature(const_fmt_arguments_new)] diff --git a/src/tools/miri/src/shims/intrinsics/mod.rs b/src/tools/miri/src/shims/intrinsics/mod.rs index 6004e2078ad4f..5ea82adb9c69c 100644 --- a/src/tools/miri/src/shims/intrinsics/mod.rs +++ b/src/tools/miri/src/shims/intrinsics/mod.rs @@ -368,11 +368,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { } // Other - "exact_div" => { - let [num, denom] = check_arg_count(args)?; - this.exact_div(&this.read_immediate(num)?, &this.read_immediate(denom)?, dest)?; - } - "breakpoint" => { let [] = check_arg_count(args)?; // normally this would raise a SIGTRAP, which aborts if no debugger is connected From f770fecfe1cf3415675ac6165a200dff564bd00f Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Thu, 20 Oct 2022 20:15:37 +0200 Subject: [PATCH 083/103] unify inherent impls of `CompileTimeEvalContext` --- .../src/const_eval/machine.rs | 90 +++++++++---------- 1 file changed, 44 insertions(+), 46 deletions(-) diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 35d58d2f638bf..66d6014946cec 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -23,52 +23,6 @@ use crate::interpret::{ use super::error::*; -impl<'mir, 'tcx> InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>> { - /// "Intercept" a function call to a panic-related function - /// because we have something special to do for it. - /// If this returns successfully (`Ok`), the function should just be evaluated normally. - fn hook_special_const_fn( - &mut self, - instance: ty::Instance<'tcx>, - args: &[OpTy<'tcx>], - ) -> InterpResult<'tcx, Option>> { - // All `#[rustc_do_not_const_check]` functions should be hooked here. - let def_id = instance.def_id(); - - if Some(def_id) == self.tcx.lang_items().panic_display() - || Some(def_id) == self.tcx.lang_items().begin_panic_fn() - { - // &str or &&str - assert!(args.len() == 1); - - let mut msg_place = self.deref_operand(&args[0])?; - while msg_place.layout.ty.is_ref() { - msg_place = self.deref_operand(&msg_place.into())?; - } - - let msg = Symbol::intern(self.read_str(&msg_place)?); - let span = self.find_closest_untracked_caller_location(); - let (file, line, col) = self.location_triple_for_span(span); - return Err(ConstEvalErrKind::Panic { msg, file, line, col }.into()); - } else if Some(def_id) == self.tcx.lang_items().panic_fmt() { - // For panic_fmt, call const_panic_fmt instead. - if let Some(const_panic_fmt) = self.tcx.lang_items().const_panic_fmt() { - return Ok(Some( - ty::Instance::resolve( - *self.tcx, - ty::ParamEnv::reveal_all(), - const_panic_fmt, - self.tcx.intern_substs(&[]), - ) - .unwrap() - .unwrap(), - )); - } - } - Ok(None) - } -} - /// Extra machine state for CTFE, and the Machine instance pub struct CompileTimeInterpreter<'mir, 'tcx> { /// For now, the number of terminators that can be evaluated before we throw a resource @@ -191,6 +145,50 @@ impl interpret::MayLeak for ! { } impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> { + /// "Intercept" a function call to a panic-related function + /// because we have something special to do for it. + /// If this returns successfully (`Ok`), the function should just be evaluated normally. + fn hook_special_const_fn( + &mut self, + instance: ty::Instance<'tcx>, + args: &[OpTy<'tcx>], + ) -> InterpResult<'tcx, Option>> { + // All `#[rustc_do_not_const_check]` functions should be hooked here. + let def_id = instance.def_id(); + + if Some(def_id) == self.tcx.lang_items().panic_display() + || Some(def_id) == self.tcx.lang_items().begin_panic_fn() + { + // &str or &&str + assert!(args.len() == 1); + + let mut msg_place = self.deref_operand(&args[0])?; + while msg_place.layout.ty.is_ref() { + msg_place = self.deref_operand(&msg_place.into())?; + } + + let msg = Symbol::intern(self.read_str(&msg_place)?); + let span = self.find_closest_untracked_caller_location(); + let (file, line, col) = self.location_triple_for_span(span); + return Err(ConstEvalErrKind::Panic { msg, file, line, col }.into()); + } else if Some(def_id) == self.tcx.lang_items().panic_fmt() { + // For panic_fmt, call const_panic_fmt instead. + if let Some(const_panic_fmt) = self.tcx.lang_items().const_panic_fmt() { + return Ok(Some( + ty::Instance::resolve( + *self.tcx, + ty::ParamEnv::reveal_all(), + const_panic_fmt, + self.tcx.intern_substs(&[]), + ) + .unwrap() + .unwrap(), + )); + } + } + Ok(None) + } + /// See documentation on the `ptr_guaranteed_cmp` intrinsic. fn guaranteed_cmp(&mut self, a: Scalar, b: Scalar) -> InterpResult<'tcx, u8> { Ok(match (a, b) { From 211743b2c88e40f43b7e2174bc19920c05b08936 Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Fri, 7 Oct 2022 22:23:34 +0200 Subject: [PATCH 084/103] make const `align_offset` useful --- .../src/const_eval/machine.rs | 129 ++++++++++++++---- library/core/src/ptr/const_ptr.rs | 15 ++ library/core/src/ptr/mod.rs | 21 ++- library/core/src/ptr/mut_ptr.rs | 15 ++ 4 files changed, 152 insertions(+), 28 deletions(-) diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 66d6014946cec..97d168ceb01a6 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -1,8 +1,11 @@ use rustc_hir::def::DefKind; use rustc_middle::mir; +use rustc_middle::mir::interpret::PointerArithmetic; +use rustc_middle::ty::layout::FnAbiOf; use rustc_middle::ty::{self, Ty, TyCtxt}; use std::borrow::Borrow; use std::hash::Hash; +use std::ops::ControlFlow; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::fx::IndexEntry; @@ -17,8 +20,8 @@ use rustc_target::abi::{Align, Size}; use rustc_target::spec::abi::Abi as CallAbi; use crate::interpret::{ - self, compile_time_machine, AllocId, ConstAllocation, Frame, ImmTy, InterpCx, InterpResult, - OpTy, PlaceTy, Pointer, Scalar, StackPopUnwind, + self, compile_time_machine, AllocId, ConstAllocation, FnVal, Frame, ImmTy, InterpCx, + InterpResult, OpTy, PlaceTy, Pointer, Scalar, StackPopUnwind, }; use super::error::*; @@ -145,15 +148,19 @@ impl interpret::MayLeak for ! { } impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> { - /// "Intercept" a function call to a panic-related function - /// because we have something special to do for it. - /// If this returns successfully (`Ok`), the function should just be evaluated normally. + /// "Intercept" a function call, because we have something special to do for it. + /// All `#[rustc_do_not_const_check]` functions should be hooked here. + /// If this returns `Some` function, which may be `instance` or a different function with + /// compatible arguments, then evaluation should continue with that function. + /// If this returns `None`, the function call has been handled and the function has returned. fn hook_special_const_fn( &mut self, instance: ty::Instance<'tcx>, + _abi: CallAbi, args: &[OpTy<'tcx>], + dest: &PlaceTy<'tcx>, + ret: Option, ) -> InterpResult<'tcx, Option>> { - // All `#[rustc_do_not_const_check]` functions should be hooked here. let def_id = instance.def_id(); if Some(def_id) == self.tcx.lang_items().panic_display() @@ -173,20 +180,91 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> { return Err(ConstEvalErrKind::Panic { msg, file, line, col }.into()); } else if Some(def_id) == self.tcx.lang_items().panic_fmt() { // For panic_fmt, call const_panic_fmt instead. - if let Some(const_panic_fmt) = self.tcx.lang_items().const_panic_fmt() { - return Ok(Some( - ty::Instance::resolve( - *self.tcx, - ty::ParamEnv::reveal_all(), - const_panic_fmt, - self.tcx.intern_substs(&[]), - ) - .unwrap() - .unwrap(), - )); + let Some(const_def_id) = self.tcx.lang_items().const_panic_fmt() else { + bug!("`const_panic_fmt` must be defined to call `panic_fmt` in const eval") + }; + let new_instance = ty::Instance::resolve( + *self.tcx, + ty::ParamEnv::reveal_all(), + const_def_id, + instance.substs, + ) + .unwrap() + .unwrap(); + + return Ok(Some(new_instance)); + } else if Some(def_id) == self.tcx.lang_items().align_offset_fn() { + // For align_offset, we replace the function call if the pointer has no address. + match self.align_offset(instance, args, dest, ret)? { + ControlFlow::Continue(()) => return Ok(Some(instance)), + ControlFlow::Break(()) => return Ok(None), + } + } + Ok(Some(instance)) + } + + /// `align_offset(ptr, target_align)` needs special handling in const eval, because the pointer + /// may not have an address. + /// + /// If `ptr` does have a known address, then we return `CONTINUE` and the function call should + /// proceed as normal. + /// + /// If `ptr` doesn't have an address, but its underlying allocation's alignment is at most + /// `target_align`, then we call the function again with an dummy address relative to the + /// allocation. + /// + /// If `ptr` doesn't have an address and `target_align` is stricter than the underlying + /// allocation's alignment, then we return `usize::MAX` immediately. + fn align_offset( + &mut self, + instance: ty::Instance<'tcx>, + args: &[OpTy<'tcx>], + dest: &PlaceTy<'tcx>, + ret: Option, + ) -> InterpResult<'tcx, ControlFlow<()>> { + assert_eq!(args.len(), 2); + + let ptr = self.read_pointer(&args[0])?; + let target_align = self.read_scalar(&args[1])?.to_machine_usize(self)?; + + if !target_align.is_power_of_two() { + throw_ub_format!("`align_offset` called with non-power-of-two align: {}", target_align); + } + + match self.ptr_try_get_alloc_id(ptr) { + Ok((alloc_id, offset, _extra)) => { + let (_size, alloc_align, _kind) = self.get_alloc_info(alloc_id); + + if target_align <= alloc_align.bytes() { + // Extract the address relative to the allocation base that is definitely + // sufficiently aligned and call `align_offset` again. + let addr = ImmTy::from_uint(offset.bytes(), args[0].layout).into(); + let align = ImmTy::from_uint(target_align, args[1].layout).into(); + + let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty())?; + self.eval_fn_call( + FnVal::Instance(instance), + (CallAbi::Rust, fn_abi), + &[addr, align], + false, + dest, + ret, + StackPopUnwind::NotAllowed, + )?; + Ok(ControlFlow::BREAK) + } else { + // Not alignable in const, return `usize::MAX`. + let usize_max = Scalar::from_machine_usize(self.machine_usize_max(), self); + self.write_scalar(usize_max, dest)?; + self.return_to_block(ret)?; + Ok(ControlFlow::BREAK) + } + } + Err(_addr) => { + // The pointer has an address, continue with function call. + Ok(ControlFlow::CONTINUE) } } - Ok(None) } /// See documentation on the `ptr_guaranteed_cmp` intrinsic. @@ -269,8 +347,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, instance: ty::Instance<'tcx>, _abi: CallAbi, args: &[OpTy<'tcx>], - _dest: &PlaceTy<'tcx>, - _ret: Option, + dest: &PlaceTy<'tcx>, + ret: Option, _unwind: StackPopUnwind, // unwinding is not supported in consts ) -> InterpResult<'tcx, Option<(&'mir mir::Body<'tcx>, ty::Instance<'tcx>)>> { debug!("find_mir_or_eval_fn: {:?}", instance); @@ -289,7 +367,11 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, } } - if let Some(new_instance) = ecx.hook_special_const_fn(instance, args)? { + let Some(new_instance) = ecx.hook_special_const_fn(instance, _abi, args, dest, ret)? else { + return Ok(None); + }; + + if new_instance != instance { // We call another const fn instead. // However, we return the *original* instance to make backtraces work out // (and we hope this does not confuse the FnAbi checks too much). @@ -298,13 +380,14 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, new_instance, _abi, args, - _dest, - _ret, + dest, + ret, _unwind, )? .map(|(body, _instance)| (body, instance))); } } + // This is a const fn. Call it. Ok(Some((ecx.load_mir(instance.def, None)?, instance))) } diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index bff270b787ece..f0cdc3d839998 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -1322,6 +1322,21 @@ impl *const T { /// ``` #[stable(feature = "align_offset", since = "1.36.0")] #[rustc_const_unstable(feature = "const_align_offset", issue = "90962")] + #[cfg(not(bootstrap))] + pub const fn align_offset(self, align: usize) -> usize + where + T: Sized, + { + assert!(align.is_power_of_two(), "align_offset: align is not a power-of-two"); + + // SAFETY: `align` has been checked to be a power of 2 above + unsafe { align_offset(self, align) } + } + + #[stable(feature = "align_offset", since = "1.36.0")] + #[rustc_const_unstable(feature = "const_align_offset", issue = "90962")] + #[allow(missing_docs)] + #[cfg(bootstrap)] pub const fn align_offset(self, align: usize) -> usize where T: Sized, diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index e0ddb3154de12..1ebd9dca09838 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -1574,10 +1574,14 @@ pub unsafe fn write_volatile(dst: *mut T, src: T) { /// Align pointer `p`. /// -/// Calculate offset (in terms of elements of `stride` stride) that has to be applied +/// Calculate offset (in terms of elements of `size_of::()` stride) that has to be applied /// to pointer `p` so that pointer `p` would get aligned to `a`. /// -/// Note: This implementation has been carefully tailored to not panic. It is UB for this to panic. +/// # Safety +/// `a` must be a power of two. +/// +/// # Notes +/// This implementation has been carefully tailored to not panic. It is UB for this to panic. /// The only real change that can be made here is change of `INV_TABLE_MOD_16` and associated /// constants. /// @@ -1586,8 +1590,10 @@ pub unsafe fn write_volatile(dst: *mut T, src: T) { /// than trying to adapt this to accommodate that change. /// /// Any questions go to @nagisa. +// #[cfg(not(bootstrap))] -- Calling this function in a const context from the bootstrap +// compiler will always cause an error. #[lang = "align_offset"] -pub(crate) unsafe fn align_offset(p: *const T, a: usize) -> usize { +pub(crate) const unsafe fn align_offset(p: *const T, a: usize) -> usize { // FIXME(#75598): Direct use of these intrinsics improves codegen significantly at opt-level <= // 1, where the method versions of these operations are not inlined. use intrinsics::{ @@ -1604,7 +1610,7 @@ pub(crate) unsafe fn align_offset(p: *const T, a: usize) -> usize { /// /// Implementation of this function shall not panic. Ever. #[inline] - unsafe fn mod_inv(x: usize, m: usize) -> usize { + const unsafe fn mod_inv(x: usize, m: usize) -> usize { /// Multiplicative modular inverse table modulo 2⁴ = 16. /// /// Note, that this table does not contain values where inverse does not exist (i.e., for @@ -1646,8 +1652,13 @@ pub(crate) unsafe fn align_offset(p: *const T, a: usize) -> usize { inverse & m_minus_one } - let addr = p.addr(); let stride = mem::size_of::(); + + // SAFETY: At runtime transmuting a pointer to `usize` is always safe, because they have the + // same layout. During const eval we hook this function to ensure that the pointer always has + // an address (only the standard library can do this). + let addr = unsafe { mem::transmute(p) }; + // SAFETY: `a` is a power-of-two, therefore non-zero. let a_minus_one = unsafe { unchecked_sub(a, 1) }; diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 8f4809ec4baa4..eb1a6a07c6b89 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -1590,6 +1590,21 @@ impl *mut T { /// ``` #[stable(feature = "align_offset", since = "1.36.0")] #[rustc_const_unstable(feature = "const_align_offset", issue = "90962")] + #[cfg(not(bootstrap))] + pub const fn align_offset(self, align: usize) -> usize + where + T: Sized, + { + assert!(align.is_power_of_two(), "align_offset: align is not a power-of-two"); + + // SAFETY: `align` has been checked to be a power of 2 above + unsafe { align_offset(self, align) } + } + + #[stable(feature = "align_offset", since = "1.36.0")] + #[rustc_const_unstable(feature = "const_align_offset", issue = "90962")] + #[allow(missing_docs)] + #[cfg(bootstrap)] pub const fn align_offset(self, align: usize) -> usize where T: Sized, From 8cf6b16185745822b109dfa17c26d2a4ee4184ab Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Fri, 7 Oct 2022 20:59:23 +0200 Subject: [PATCH 085/103] add coretests for const `align_offset` --- library/core/tests/lib.rs | 1 + library/core/tests/ptr.rs | 165 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+) diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 61d31b3448734..7447123253adb 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -4,6 +4,7 @@ #![feature(array_windows)] #![feature(bigint_helper_methods)] #![feature(cell_update)] +#![feature(const_align_offset)] #![feature(const_assume)] #![feature(const_align_of_val_raw)] #![feature(const_black_box)] diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index 0977980ba47bf..186e83d50b6ca 100644 --- a/library/core/tests/ptr.rs +++ b/library/core/tests/ptr.rs @@ -358,6 +358,23 @@ fn align_offset_zst() { } } +#[test] +#[cfg(not(bootstrap))] +fn align_offset_zst_const() { + const { + // For pointers of stride = 0, the pointer is already aligned or it cannot be aligned at + // all, because no amount of elements will align the pointer. + let mut p = 1; + while p < 1024 { + assert!(ptr::invalid::<()>(p).align_offset(p) == 0); + if p != 1 { + assert!(ptr::invalid::<()>(p + 1).align_offset(p) == !0); + } + p = (p + 1).next_power_of_two(); + } + } +} + #[test] fn align_offset_stride_one() { // For pointers of stride = 1, the pointer can always be aligned. The offset is equal to @@ -379,6 +396,26 @@ fn align_offset_stride_one() { } } +#[test] +#[cfg(not(bootstrap))] +fn align_offset_stride_one_const() { + const { + // For pointers of stride = 1, the pointer can always be aligned. The offset is equal to + // number of bytes. + let mut align = 1; + while align < 1024 { + let mut ptr = 1; + while ptr < 2 * align { + let expected = ptr % align; + let offset = if expected == 0 { 0 } else { align - expected }; + assert!(ptr::invalid::(ptr).align_offset(align) == offset); + ptr += 1; + } + align = (align + 1).next_power_of_two(); + } + } +} + #[test] fn align_offset_various_strides() { unsafe fn test_stride(ptr: *const T, align: usize) -> bool { @@ -455,6 +492,134 @@ fn align_offset_various_strides() { assert!(!x); } +#[test] +#[cfg(not(bootstrap))] +fn align_offset_various_strides_const() { + const unsafe fn test_stride(ptr: *const T, numptr: usize, align: usize) { + let mut expected = usize::MAX; + // Naive but definitely correct way to find the *first* aligned element of stride::. + let mut el = 0; + while el < align { + if (numptr + el * ::std::mem::size_of::()) % align == 0 { + expected = el; + break; + } + el += 1; + } + let got = ptr.align_offset(align); + assert!(got == expected); + } + + // For pointers of stride != 1, we verify the algorithm against the naivest possible + // implementation + let mut align = 1; + let limit = 1024; + while align < limit { + for ptr in 1usize..4 * align { + unsafe { + #[repr(packed)] + struct A3(u16, u8); + test_stride::(ptr::invalid::(ptr), ptr, align); + + struct A4(u32); + test_stride::(ptr::invalid::(ptr), ptr, align); + + #[repr(packed)] + struct A5(u32, u8); + test_stride::(ptr::invalid::(ptr), ptr, align); + + #[repr(packed)] + struct A6(u32, u16); + test_stride::(ptr::invalid::(ptr), ptr, align); + + #[repr(packed)] + struct A7(u32, u16, u8); + test_stride::(ptr::invalid::(ptr), ptr, align); + + #[repr(packed)] + struct A8(u32, u32); + test_stride::(ptr::invalid::(ptr), ptr, align); + + #[repr(packed)] + struct A9(u32, u32, u8); + test_stride::(ptr::invalid::(ptr), ptr, align); + + #[repr(packed)] + struct A10(u32, u32, u16); + test_stride::(ptr::invalid::(ptr), ptr, align); + + test_stride::(ptr::invalid::(ptr), ptr, align); + test_stride::(ptr::invalid::(ptr), ptr, align); + } + } + align = (align + 1).next_power_of_two(); + } +} + +#[test] +#[cfg(not(bootstrap))] +fn align_offset_with_provenance_const() { + const { + let data = 42; + + let ptr: *const i32 = &data; + assert!(ptr.align_offset(1) == 0); + assert!(ptr.align_offset(2) == 0); + assert!(ptr.align_offset(4) == 0); + assert!(ptr.align_offset(8) == usize::MAX); + assert!(ptr.wrapping_byte_add(1).align_offset(1) == 0); + assert!(ptr.wrapping_byte_add(1).align_offset(2) == usize::MAX); + assert!(ptr.wrapping_byte_add(2).align_offset(1) == 0); + assert!(ptr.wrapping_byte_add(2).align_offset(2) == 0); + assert!(ptr.wrapping_byte_add(2).align_offset(4) == usize::MAX); + assert!(ptr.wrapping_byte_add(3).align_offset(1) == 0); + assert!(ptr.wrapping_byte_add(3).align_offset(2) == usize::MAX); + + assert!(ptr.wrapping_add(42).align_offset(4) == 0); + assert!(ptr.wrapping_add(42).align_offset(8) == usize::MAX); + + let ptr1: *const i8 = ptr.cast(); + assert!(ptr1.align_offset(1) == 0); + assert!(ptr1.align_offset(2) == 0); + assert!(ptr1.align_offset(4) == 0); + assert!(ptr1.align_offset(8) == usize::MAX); + assert!(ptr1.wrapping_byte_add(1).align_offset(1) == 0); + assert!(ptr1.wrapping_byte_add(1).align_offset(2) == 1); + assert!(ptr1.wrapping_byte_add(1).align_offset(4) == 3); + assert!(ptr1.wrapping_byte_add(1).align_offset(8) == usize::MAX); + assert!(ptr1.wrapping_byte_add(2).align_offset(1) == 0); + assert!(ptr1.wrapping_byte_add(2).align_offset(2) == 0); + assert!(ptr1.wrapping_byte_add(2).align_offset(4) == 2); + assert!(ptr1.wrapping_byte_add(2).align_offset(8) == usize::MAX); + assert!(ptr1.wrapping_byte_add(3).align_offset(1) == 0); + assert!(ptr1.wrapping_byte_add(3).align_offset(2) == 1); + assert!(ptr1.wrapping_byte_add(3).align_offset(4) == 1); + assert!(ptr1.wrapping_byte_add(3).align_offset(8) == usize::MAX); + + let ptr2: *const i16 = ptr.cast(); + assert!(ptr2.align_offset(1) == 0); + assert!(ptr2.align_offset(2) == 0); + assert!(ptr2.align_offset(4) == 0); + assert!(ptr2.align_offset(8) == usize::MAX); + assert!(ptr2.wrapping_byte_add(1).align_offset(1) == 0); + assert!(ptr2.wrapping_byte_add(1).align_offset(2) == usize::MAX); + assert!(ptr2.wrapping_byte_add(2).align_offset(1) == 0); + assert!(ptr2.wrapping_byte_add(2).align_offset(2) == 0); + assert!(ptr2.wrapping_byte_add(2).align_offset(4) == 1); + assert!(ptr2.wrapping_byte_add(2).align_offset(8) == usize::MAX); + assert!(ptr2.wrapping_byte_add(3).align_offset(1) == 0); + assert!(ptr2.wrapping_byte_add(3).align_offset(2) == usize::MAX); + + let ptr3: *const i64 = ptr.cast(); + assert!(ptr3.align_offset(1) == 0); + assert!(ptr3.align_offset(2) == 0); + assert!(ptr3.align_offset(4) == 0); + assert!(ptr3.align_offset(8) == usize::MAX); + assert!(ptr3.wrapping_byte_add(1).align_offset(1) == 0); + assert!(ptr3.wrapping_byte_add(1).align_offset(2) == usize::MAX); + } +} + #[test] fn align_offset_issue_103361() { #[cfg(target_pointer_width = "64")] From 6f6320a0a916b57dc37568d3ce5f5ed0e749ef61 Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Fri, 7 Oct 2022 22:24:31 +0200 Subject: [PATCH 086/103] constify `pointer::is_aligned{,_to}` --- library/core/src/lib.rs | 1 + library/core/src/ptr/const_ptr.rs | 25 +++++++++++++++++++------ library/core/src/ptr/mut_ptr.rs | 25 +++++++++++++++++++------ 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 33b969c249a2f..848eccd7f2908 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -130,6 +130,7 @@ #![feature(const_option)] #![feature(const_option_ext)] #![feature(const_pin)] +#![feature(const_pointer_is_aligned)] #![feature(const_ptr_sub_ptr)] #![feature(const_replace)] #![feature(const_result_drop)] diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index f0cdc3d839998..8b96cf06be462 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -1363,10 +1363,13 @@ impl *const T { } /// Returns whether the pointer is properly aligned for `T`. + // #[cfg(not(bootstrap))] -- Calling this function in a const context from the bootstrap + // compiler will always return false. #[must_use] #[inline] #[unstable(feature = "pointer_is_aligned", issue = "96284")] - pub fn is_aligned(self) -> bool + #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "none")] + pub const fn is_aligned(self) -> bool where T: Sized, { @@ -1381,16 +1384,26 @@ impl *const T { /// # Panics /// /// The function panics if `align` is not a power-of-two (this includes 0). + // #[cfg(not(bootstrap))] -- Calling this function in a const context from the bootstrap + // compiler will always return false. #[must_use] #[inline] #[unstable(feature = "pointer_is_aligned", issue = "96284")] - pub fn is_aligned_to(self, align: usize) -> bool { - if !align.is_power_of_two() { - panic!("is_aligned_to: align is not a power-of-two"); + #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "none")] + pub const fn is_aligned_to(self, align: usize) -> bool { + assert!(align.is_power_of_two(), "is_aligned_to: align is not a power-of-two"); + + #[inline] + fn runtime(ptr: *const u8, align: usize) -> bool { + ptr.addr() & (align - 1) == 0 + } + + const fn comptime(ptr: *const u8, align: usize) -> bool { + ptr.align_offset(align) == 0 } - // Cast is needed for `T: !Sized` - self.cast::().addr() & align - 1 == 0 + // SAFETY: `ptr.align_offset(align)` returns 0 if and only if the pointer is already aligned. + unsafe { intrinsics::const_eval_select((self.cast::(), align), comptime, runtime) } } } diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index eb1a6a07c6b89..2d73c24b5b4c8 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -1631,10 +1631,13 @@ impl *mut T { } /// Returns whether the pointer is properly aligned for `T`. + // #[cfg(not(bootstrap))] -- Calling this function in a const context from the bootstrap + // compiler will always return false. #[must_use] #[inline] #[unstable(feature = "pointer_is_aligned", issue = "96284")] - pub fn is_aligned(self) -> bool + #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "none")] + pub const fn is_aligned(self) -> bool where T: Sized, { @@ -1649,16 +1652,26 @@ impl *mut T { /// # Panics /// /// The function panics if `align` is not a power-of-two (this includes 0). + // #[cfg(not(bootstrap))] -- Calling this function in a const context from the bootstrap + // compiler will always return false. #[must_use] #[inline] #[unstable(feature = "pointer_is_aligned", issue = "96284")] - pub fn is_aligned_to(self, align: usize) -> bool { - if !align.is_power_of_two() { - panic!("is_aligned_to: align is not a power-of-two"); + #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "none")] + pub const fn is_aligned_to(self, align: usize) -> bool { + assert!(align.is_power_of_two(), "is_aligned_to: align is not a power-of-two"); + + #[inline] + fn runtime(ptr: *mut u8, align: usize) -> bool { + ptr.addr() & (align - 1) == 0 + } + + const fn comptime(ptr: *mut u8, align: usize) -> bool { + ptr.align_offset(align) == 0 } - // Cast is needed for `T: !Sized` - self.cast::().addr() & align - 1 == 0 + // SAFETY: `ptr.align_offset(align)` returns 0 if and only if the pointer is already aligned. + unsafe { intrinsics::const_eval_select((self.cast::(), align), comptime, runtime) } } } From 2ef9a8ae0fed0a92b86b316f98f3467aef1e547c Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Fri, 7 Oct 2022 21:46:28 +0200 Subject: [PATCH 087/103] add coretests for `is_aligned` --- library/core/tests/lib.rs | 2 ++ library/core/tests/ptr.rs | 48 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 7447123253adb..66d28770b87f9 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -19,6 +19,7 @@ #![feature(const_nonnull_new)] #![feature(const_num_from_num)] #![feature(const_pointer_byte_offsets)] +#![feature(const_pointer_is_aligned)] #![feature(const_ptr_as_ref)] #![feature(const_ptr_read)] #![feature(const_ptr_write)] @@ -82,6 +83,7 @@ #![feature(never_type)] #![feature(unwrap_infallible)] #![feature(pointer_byte_offsets)] +#![feature(pointer_is_aligned)] #![feature(portable_simd)] #![feature(ptr_metadata)] #![feature(once_cell)] diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index 186e83d50b6ca..9f74b0c04107e 100644 --- a/library/core/tests/ptr.rs +++ b/library/core/tests/ptr.rs @@ -632,6 +632,54 @@ fn align_offset_issue_103361() { let _ = (SIZE as *const HugeSize).align_offset(SIZE); } +#[test] +fn is_aligned() { + let data = 42; + let ptr: *const i32 = &data; + assert!(ptr.is_aligned()); + assert!(ptr.is_aligned_to(1)); + assert!(ptr.is_aligned_to(2)); + assert!(ptr.is_aligned_to(4)); + assert!(ptr.wrapping_byte_add(2).is_aligned_to(1)); + assert!(ptr.wrapping_byte_add(2).is_aligned_to(2)); + assert!(!ptr.wrapping_byte_add(2).is_aligned_to(4)); + + // At runtime either `ptr` or `ptr+1` is aligned to 8. + assert_ne!(ptr.is_aligned_to(8), ptr.wrapping_add(1).is_aligned_to(8)); +} + +#[test] +#[cfg(not(bootstrap))] +fn is_aligned_const() { + const { + let data = 42; + let ptr: *const i32 = &data; + assert!(ptr.is_aligned()); + assert!(ptr.is_aligned_to(1)); + assert!(ptr.is_aligned_to(2)); + assert!(ptr.is_aligned_to(4)); + assert!(ptr.wrapping_byte_add(2).is_aligned_to(1)); + assert!(ptr.wrapping_byte_add(2).is_aligned_to(2)); + assert!(!ptr.wrapping_byte_add(2).is_aligned_to(4)); + + // At comptime neither `ptr` nor `ptr+1` is aligned to 8. + assert!(!ptr.is_aligned_to(8)); + assert!(!ptr.wrapping_add(1).is_aligned_to(8)); + } +} + +#[test] +#[cfg(bootstrap)] +fn is_aligned_const() { + const { + let data = 42; + let ptr: *const i32 = &data; + // The bootstrap compiler always returns false for is_aligned. + assert!(!ptr.is_aligned()); + assert!(!ptr.is_aligned_to(1)); + } +} + #[test] fn offset_from() { let mut a = [0; 5]; From 24e88066dc702da8fbe0381044645a91669bf02f Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Thu, 20 Oct 2022 19:46:31 +0200 Subject: [PATCH 088/103] mark `align_offset` as `#[must_use]` --- library/core/src/ptr/const_ptr.rs | 1 + library/core/src/ptr/mut_ptr.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 8b96cf06be462..cedf58c27ffcc 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -1320,6 +1320,7 @@ impl *const T { /// } /// # } /// ``` + #[must_use] #[stable(feature = "align_offset", since = "1.36.0")] #[rustc_const_unstable(feature = "const_align_offset", issue = "90962")] #[cfg(not(bootstrap))] diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 2d73c24b5b4c8..21c836efd5c46 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -1588,6 +1588,7 @@ impl *mut T { /// } /// # } /// ``` + #[must_use] #[stable(feature = "align_offset", since = "1.36.0")] #[rustc_const_unstable(feature = "const_align_offset", issue = "90962")] #[cfg(not(bootstrap))] From a906f6cb698df6d29093e14984878446c269082d Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Sat, 22 Oct 2022 17:31:07 +0200 Subject: [PATCH 089/103] don't call `align_offset` during const eval, ever --- .../src/const_eval/machine.rs | 131 ++++++++++++------ library/core/src/ptr/mod.rs | 9 +- 2 files changed, 90 insertions(+), 50 deletions(-) diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 97d168ceb01a6..6cf8a581d71a6 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -1,11 +1,10 @@ use rustc_hir::def::DefKind; use rustc_middle::mir; use rustc_middle::mir::interpret::PointerArithmetic; -use rustc_middle::ty::layout::FnAbiOf; +use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, Ty, TyCtxt}; use std::borrow::Borrow; use std::hash::Hash; -use std::ops::ControlFlow; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::fx::IndexEntry; @@ -20,8 +19,8 @@ use rustc_target::abi::{Align, Size}; use rustc_target::spec::abi::Abi as CallAbi; use crate::interpret::{ - self, compile_time_machine, AllocId, ConstAllocation, FnVal, Frame, ImmTy, InterpCx, - InterpResult, OpTy, PlaceTy, Pointer, Scalar, StackPopUnwind, + self, compile_time_machine, AllocId, ConstAllocation, Frame, ImmTy, InterpCx, InterpResult, + OpTy, PlaceTy, Pointer, Scalar, StackPopUnwind, }; use super::error::*; @@ -156,7 +155,6 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> { fn hook_special_const_fn( &mut self, instance: ty::Instance<'tcx>, - _abi: CallAbi, args: &[OpTy<'tcx>], dest: &PlaceTy<'tcx>, ret: Option, @@ -194,24 +192,21 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> { return Ok(Some(new_instance)); } else if Some(def_id) == self.tcx.lang_items().align_offset_fn() { - // For align_offset, we replace the function call if the pointer has no address. - match self.align_offset(instance, args, dest, ret)? { - ControlFlow::Continue(()) => return Ok(Some(instance)), - ControlFlow::Break(()) => return Ok(None), - } + // For align_offset, we replace the function call entirely. + self.align_offset(instance, args, dest, ret)?; + return Ok(None); } Ok(Some(instance)) } - /// `align_offset(ptr, target_align)` needs special handling in const eval, because the pointer - /// may not have an address. + /// This function replaces `align_offset(ptr, target_align)` in const eval, because the + /// pointer may not have an address. /// - /// If `ptr` does have a known address, then we return `CONTINUE` and the function call should - /// proceed as normal. + /// If `ptr` does have a known address, we forward it to [`Self::align_offset_impl`]. /// /// If `ptr` doesn't have an address, but its underlying allocation's alignment is at most - /// `target_align`, then we call the function again with an dummy address relative to the - /// allocation. + /// `target_align`, then we call [`Self::align_offset_impl`] with an dummy address relative + /// to the allocation. /// /// If `ptr` doesn't have an address and `target_align` is stricter than the underlying /// allocation's alignment, then we return `usize::MAX` immediately. @@ -221,50 +216,100 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> { args: &[OpTy<'tcx>], dest: &PlaceTy<'tcx>, ret: Option, - ) -> InterpResult<'tcx, ControlFlow<()>> { + ) -> InterpResult<'tcx> { assert_eq!(args.len(), 2); let ptr = self.read_pointer(&args[0])?; let target_align = self.read_scalar(&args[1])?.to_machine_usize(self)?; + let pointee_ty = instance.substs.type_at(0); + let stride = self.layout_of(pointee_ty)?.size.bytes(); + if !target_align.is_power_of_two() { throw_ub_format!("`align_offset` called with non-power-of-two align: {}", target_align); } - match self.ptr_try_get_alloc_id(ptr) { + let mut align_offset = match self.ptr_try_get_alloc_id(ptr) { Ok((alloc_id, offset, _extra)) => { + // Extract the address relative to a base that is definitely sufficiently aligned. let (_size, alloc_align, _kind) = self.get_alloc_info(alloc_id); if target_align <= alloc_align.bytes() { - // Extract the address relative to the allocation base that is definitely - // sufficiently aligned and call `align_offset` again. - let addr = ImmTy::from_uint(offset.bytes(), args[0].layout).into(); - let align = ImmTy::from_uint(target_align, args[1].layout).into(); - - let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty())?; - self.eval_fn_call( - FnVal::Instance(instance), - (CallAbi::Rust, fn_abi), - &[addr, align], - false, - dest, - ret, - StackPopUnwind::NotAllowed, - )?; - Ok(ControlFlow::BREAK) + // The pointer *is* alignable in const. We use an address relative to the + // allocation base that is definitely sufficiently aligned. + let addr = offset.bytes(); + Self::align_offset_impl(addr, stride, target_align) } else { - // Not alignable in const, return `usize::MAX`. - let usize_max = Scalar::from_machine_usize(self.machine_usize_max(), self); - self.write_scalar(usize_max, dest)?; - self.return_to_block(ret)?; - Ok(ControlFlow::BREAK) + // The pointer *is not* alignable in const, return `usize::MAX`. + // (We clamp this to machine `usize` below.) + u64::MAX } } - Err(_addr) => { - // The pointer has an address, continue with function call. - Ok(ControlFlow::CONTINUE) + Err(addr) => { + // The pointer has a known address. + Self::align_offset_impl(addr, stride, target_align) } + }; + + let usize_max = self.machine_usize_max(); + if align_offset > usize_max { + align_offset = usize_max; + } + + self.write_scalar(Scalar::from_machine_usize(align_offset, self), dest)?; + self.return_to_block(ret)?; + + Ok(()) + } + + /// Const eval implementation of `#[lang = "align_offset"]`. + /// See the runtime version for a detailed explanation how this works. + fn align_offset_impl(addr: u64, stride: u64, align: u64) -> u64 { + assert!(align.is_power_of_two()); + + let addr_mod_align = addr % align; + + if addr_mod_align == 0 { + // The address is already sufficiently aligned. + return 0; } + + if stride == 0 { + // The address cannot be aligned. + return u64::MAX; + } + + let byte_offset = align - addr_mod_align; + + if align % stride == 0 { + if byte_offset % stride == 0 { + return byte_offset / stride; + } else { + return u64::MAX; + } + } + + // This only works, because `align` is a power of two. + let gcd = 1u64 << (stride | align).trailing_zeros(); + + if addr % gcd != 0 { + // The address cannot be aligned. + return u64::MAX; + } + + let align2 = align / gcd; + let stride2 = (stride / gcd) % align2; + + let mut stride_inv = 1u64; + let mut mod_gate = 2u64; + let mut overflow = false; + while !overflow && mod_gate < align2 { + stride_inv = + stride_inv.wrapping_mul(2u64.wrapping_sub(stride2.wrapping_mul(stride_inv))); + (mod_gate, overflow) = mod_gate.overflowing_mul(mod_gate); + } + + byte_offset.wrapping_mul(stride_inv) % align2 } /// See documentation on the `ptr_guaranteed_cmp` intrinsic. @@ -367,7 +412,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, } } - let Some(new_instance) = ecx.hook_special_const_fn(instance, _abi, args, dest, ret)? else { + let Some(new_instance) = ecx.hook_special_const_fn(instance, args, dest, ret)? else { return Ok(None); }; diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index 1ebd9dca09838..e762837ff90a9 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -1590,9 +1590,8 @@ pub unsafe fn write_volatile(dst: *mut T, src: T) { /// than trying to adapt this to accommodate that change. /// /// Any questions go to @nagisa. -// #[cfg(not(bootstrap))] -- Calling this function in a const context from the bootstrap -// compiler will always cause an error. #[lang = "align_offset"] +#[rustc_do_not_const_check] // hooked by const-eval pub(crate) const unsafe fn align_offset(p: *const T, a: usize) -> usize { // FIXME(#75598): Direct use of these intrinsics improves codegen significantly at opt-level <= // 1, where the method versions of these operations are not inlined. @@ -1652,13 +1651,9 @@ pub(crate) const unsafe fn align_offset(p: *const T, a: usize) -> usiz inverse & m_minus_one } + let addr = p.addr(); let stride = mem::size_of::(); - // SAFETY: At runtime transmuting a pointer to `usize` is always safe, because they have the - // same layout. During const eval we hook this function to ensure that the pointer always has - // an address (only the standard library can do this). - let addr = unsafe { mem::transmute(p) }; - // SAFETY: `a` is a power-of-two, therefore non-zero. let a_minus_one = unsafe { unchecked_sub(a, 1) }; From 093c02ed460cfe726badc7d7bee2c868f8288e16 Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Sat, 22 Oct 2022 19:15:03 +0200 Subject: [PATCH 090/103] document `is_aligned{,_to}` --- library/core/src/ptr/const_ptr.rs | 138 +++++++++++++++++++++++++++++- library/core/src/ptr/mut_ptr.rs | 138 +++++++++++++++++++++++++++++- 2 files changed, 268 insertions(+), 8 deletions(-) diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index cedf58c27ffcc..6457e5184b0e4 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -1364,8 +1364,72 @@ impl *const T { } /// Returns whether the pointer is properly aligned for `T`. - // #[cfg(not(bootstrap))] -- Calling this function in a const context from the bootstrap - // compiler will always return false. + /// + /// # Examples + /// + /// Basic usage: + /// ``` + /// #![feature(pointer_is_aligned)] + /// #![feature(pointer_byte_offsets)] + /// + /// let data: i32 = 42; + /// let ptr: *const i32 = &data; + /// + /// assert!(ptr.is_aligned()); + /// assert!(!ptr.wrapping_byte_add(1).is_aligned()); + /// ``` + /// + /// # At compiletime + /// **Note: Alignment at compiletime is experimental and subject to change. See the + /// [tracking issue] for details.** + /// + /// At compiletime, the compiler may not know where a value will end up in memory. + /// Calling this function on a pointer created from a reference at compiletime will only + /// return `true` if the pointer is guaranteed to be aligned. This means that the pointer + /// is never aligned if cast to a type with a stricter alignment than the reference's + /// underlying allocation. + /// + #[cfg_attr(bootstrap, doc = "```ignore")] + #[cfg_attr(not(bootstrap), doc = "```")] + /// #![feature(pointer_is_aligned)] + /// #![feature(const_pointer_is_aligned)] + /// + /// const _: () = { + /// let data: i32 = 42; + /// let ptr: *const i32 = &data; + /// assert!(ptr.is_aligned()); + /// + /// // At runtime either `ptr1` or `ptr2` would be aligned, + /// // but at compiletime neither is aligned. + /// let ptr1: *const i64 = ptr.cast(); + /// let ptr2: *const i64 = ptr.wrapping_add(1).cast(); + /// assert!(!ptr1.is_aligned()); + /// assert!(!ptr2.is_aligned()); + /// }; + /// ``` + /// + /// If a pointer is created from a fixed address, this function behaves the same during + /// runtime and compiletime. + /// + #[cfg_attr(bootstrap, doc = "```ignore")] + #[cfg_attr(not(bootstrap), doc = "```")] + /// #![feature(pointer_is_aligned)] + /// #![feature(const_pointer_is_aligned)] + /// + /// const _: () = { + /// let ptr = 40 as *const i32; + /// assert!(ptr.is_aligned()); + /// + /// // For pointers with a known address, runtime and + /// // compiletime behavior are identical. + /// let ptr1: *const i64 = ptr.cast(); + /// let ptr2: *const i64 = ptr.wrapping_add(1).cast(); + /// assert!(ptr1.is_aligned()); + /// assert!(!ptr2.is_aligned()); + /// }; + /// ``` + /// + /// [tracking issue]: https://github.com/rust-lang/rust/issues/comming-soon #[must_use] #[inline] #[unstable(feature = "pointer_is_aligned", issue = "96284")] @@ -1385,8 +1449,74 @@ impl *const T { /// # Panics /// /// The function panics if `align` is not a power-of-two (this includes 0). - // #[cfg(not(bootstrap))] -- Calling this function in a const context from the bootstrap - // compiler will always return false. + /// + /// # Examples + /// + /// Basic usage: + /// ``` + /// #![feature(pointer_is_aligned)] + /// #![feature(pointer_byte_offsets)] + /// + /// let data: i32 = 42; + /// let ptr: *const i32 = &data; + /// + /// assert!(ptr.is_aligned_to(1)); + /// assert!(ptr.is_aligned_to(2)); + /// assert!(ptr.is_aligned_to(4)); + /// + /// assert!(ptr.wrapping_byte_add(2).is_aligned_to(2)); + /// assert!(!ptr.wrapping_byte_add(2).is_aligned_to(4)); + /// + /// assert_ne!(ptr.is_aligned_to(8), ptr.wrapping_add(1).is_aligned_to(8)); + /// ``` + /// + /// # At compiletime + /// **Note: Alignment at compiletime is experimental and subject to change. See the + /// [tracking issue] for details.** + /// + /// At compiletime, the compiler may not know where a value will end up in memory. + /// Calling this function on a pointer created from a reference at compiletime will only + /// return `true` if the pointer is guaranteed to be aligned. This means that the pointer + /// cannot be stricter aligned than the reference's underlying allocation. + /// + #[cfg_attr(bootstrap, doc = "```ignore")] + #[cfg_attr(not(bootstrap), doc = "```")] + /// #![feature(pointer_is_aligned)] + /// #![feature(const_pointer_is_aligned)] + /// + /// const _: () = { + /// let data: i32 = 42; + /// let ptr: *const i32 = &data; + /// + /// assert!(ptr.is_aligned_to(1)); + /// assert!(ptr.is_aligned_to(2)); + /// assert!(ptr.is_aligned_to(4)); + /// + /// // At compiletime, we know for sure that the pointer isn't aligned to 8. + /// assert!(!ptr.is_aligned_to(8)); + /// assert!(!ptr.wrapping_add(1).is_aligned_to(8)); + /// }; + /// ``` + /// + /// If a pointer is created from a fixed address, this function behaves the same during + /// runtime and compiletime. + /// + #[cfg_attr(bootstrap, doc = "```ignore")] + #[cfg_attr(not(bootstrap), doc = "```")] + /// #![feature(pointer_is_aligned)] + /// #![feature(const_pointer_is_aligned)] + /// + /// const _: () = { + /// let ptr = 40 as *const i32; + /// assert!(ptr.is_aligned_to(1)); + /// assert!(ptr.is_aligned_to(2)); + /// assert!(ptr.is_aligned_to(4)); + /// assert!(ptr.is_aligned_to(8)); + /// assert!(!ptr.is_aligned_to(16)); + /// }; + /// ``` + /// + /// [tracking issue]: https://github.com/rust-lang/rust/issues/comming-soon #[must_use] #[inline] #[unstable(feature = "pointer_is_aligned", issue = "96284")] diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 21c836efd5c46..c79f815e35fd4 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -1632,8 +1632,72 @@ impl *mut T { } /// Returns whether the pointer is properly aligned for `T`. - // #[cfg(not(bootstrap))] -- Calling this function in a const context from the bootstrap - // compiler will always return false. + /// + /// # Examples + /// + /// Basic usage: + /// ``` + /// #![feature(pointer_is_aligned)] + /// #![feature(pointer_byte_offsets)] + /// + /// let data: i32 = 42; + /// let ptr: *const i32 = &data; + /// + /// assert!(ptr.is_aligned()); + /// assert!(!ptr.wrapping_byte_add(1).is_aligned()); + /// ``` + /// + /// # At compiletime + /// **Note: Alignment at compiletime is experimental and subject to change. See the + /// [tracking issue] for details.** + /// + /// At compiletime, the compiler may not know where a value will end up in memory. + /// Calling this function on a pointer created from a reference at compiletime will only + /// return `true` if the pointer is guaranteed to be aligned. This means that the pointer + /// is never aligned if cast to a type with a stricter alignment than the reference's + /// underlying allocation. + /// + #[cfg_attr(bootstrap, doc = "```ignore")] + #[cfg_attr(not(bootstrap), doc = "```")] + /// #![feature(pointer_is_aligned)] + /// #![feature(const_pointer_is_aligned)] + /// + /// const _: () = { + /// let data: i32 = 42; + /// let ptr: *const i32 = &data; + /// assert!(ptr.is_aligned()); + /// + /// // At runtime either `ptr1` or `ptr2` would be aligned, + /// // but at compiletime neither is aligned. + /// let ptr1: *const i64 = ptr.cast(); + /// let ptr2: *const i64 = ptr.wrapping_add(1).cast(); + /// assert!(!ptr1.is_aligned()); + /// assert!(!ptr2.is_aligned()); + /// }; + /// ``` + /// + /// If a pointer is created from a fixed address, this function behaves the same during + /// runtime and compiletime. + /// + #[cfg_attr(bootstrap, doc = "```ignore")] + #[cfg_attr(not(bootstrap), doc = "```")] + /// #![feature(pointer_is_aligned)] + /// #![feature(const_pointer_is_aligned)] + /// + /// const _: () = { + /// let ptr = 40 as *const i32; + /// assert!(ptr.is_aligned()); + /// + /// // For pointers with a known address, runtime and + /// // compiletime behavior are identical. + /// let ptr1: *const i64 = ptr.cast(); + /// let ptr2: *const i64 = ptr.wrapping_add(1).cast(); + /// assert!(ptr1.is_aligned()); + /// assert!(!ptr2.is_aligned()); + /// }; + /// ``` + /// + /// [tracking issue]: https://github.com/rust-lang/rust/issues/comming-soon #[must_use] #[inline] #[unstable(feature = "pointer_is_aligned", issue = "96284")] @@ -1653,8 +1717,74 @@ impl *mut T { /// # Panics /// /// The function panics if `align` is not a power-of-two (this includes 0). - // #[cfg(not(bootstrap))] -- Calling this function in a const context from the bootstrap - // compiler will always return false. + /// + /// # Examples + /// + /// Basic usage: + /// ``` + /// #![feature(pointer_is_aligned)] + /// #![feature(pointer_byte_offsets)] + /// + /// let data: i32 = 42; + /// let ptr: *const i32 = &data; + /// + /// assert!(ptr.is_aligned_to(1)); + /// assert!(ptr.is_aligned_to(2)); + /// assert!(ptr.is_aligned_to(4)); + /// + /// assert!(ptr.wrapping_byte_add(2).is_aligned_to(2)); + /// assert!(!ptr.wrapping_byte_add(2).is_aligned_to(4)); + /// + /// assert_ne!(ptr.is_aligned_to(8), ptr.wrapping_add(1).is_aligned_to(8)); + /// ``` + /// + /// # At compiletime + /// **Note: Alignment at compiletime is experimental and subject to change. See the + /// [tracking issue] for details.** + /// + /// At compiletime, the compiler may not know where a value will end up in memory. + /// Calling this function on a pointer created from a reference at compiletime will only + /// return `true` if the pointer is guaranteed to be aligned. This means that the pointer + /// cannot be stricter aligned than the reference's underlying allocation. + /// + #[cfg_attr(bootstrap, doc = "```ignore")] + #[cfg_attr(not(bootstrap), doc = "```")] + /// #![feature(pointer_is_aligned)] + /// #![feature(const_pointer_is_aligned)] + /// + /// const _: () = { + /// let data: i32 = 42; + /// let ptr: *const i32 = &data; + /// + /// assert!(ptr.is_aligned_to(1)); + /// assert!(ptr.is_aligned_to(2)); + /// assert!(ptr.is_aligned_to(4)); + /// + /// // At compiletime, we know for sure that the pointer isn't aligned to 8. + /// assert!(!ptr.is_aligned_to(8)); + /// assert!(!ptr.wrapping_add(1).is_aligned_to(8)); + /// }; + /// ``` + /// + /// If a pointer is created from a fixed address, this function behaves the same during + /// runtime and compiletime. + /// + #[cfg_attr(bootstrap, doc = "```ignore")] + #[cfg_attr(not(bootstrap), doc = "```")] + /// #![feature(pointer_is_aligned)] + /// #![feature(const_pointer_is_aligned)] + /// + /// const _: () = { + /// let ptr = 40 as *const i32; + /// assert!(ptr.is_aligned_to(1)); + /// assert!(ptr.is_aligned_to(2)); + /// assert!(ptr.is_aligned_to(4)); + /// assert!(ptr.is_aligned_to(8)); + /// assert!(!ptr.is_aligned_to(16)); + /// }; + /// ``` + /// + /// [tracking issue]: https://github.com/rust-lang/rust/issues/comming-soon #[must_use] #[inline] #[unstable(feature = "pointer_is_aligned", issue = "96284")] From df0bcfe6448793e423bd6b8fd5294f10798dd469 Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Sat, 22 Oct 2022 21:20:04 +0200 Subject: [PATCH 091/103] address more review comments * `cfg` only the body of `align_offset` * put explicit panics back * explain why `ptr.align_offset(align) == 0` is slow --- library/core/src/ptr/const_ptr.rs | 54 +++++++++++++++---------------- library/core/src/ptr/mut_ptr.rs | 54 +++++++++++++++---------------- 2 files changed, 52 insertions(+), 56 deletions(-) diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 6457e5184b0e4..37679c504b303 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -1323,21 +1323,6 @@ impl *const T { #[must_use] #[stable(feature = "align_offset", since = "1.36.0")] #[rustc_const_unstable(feature = "const_align_offset", issue = "90962")] - #[cfg(not(bootstrap))] - pub const fn align_offset(self, align: usize) -> usize - where - T: Sized, - { - assert!(align.is_power_of_two(), "align_offset: align is not a power-of-two"); - - // SAFETY: `align` has been checked to be a power of 2 above - unsafe { align_offset(self, align) } - } - - #[stable(feature = "align_offset", since = "1.36.0")] - #[rustc_const_unstable(feature = "const_align_offset", issue = "90962")] - #[allow(missing_docs)] - #[cfg(bootstrap)] pub const fn align_offset(self, align: usize) -> usize where T: Sized, @@ -1346,21 +1331,30 @@ impl *const T { panic!("align_offset: align is not a power-of-two"); } - fn rt_impl(p: *const T, align: usize) -> usize { - // SAFETY: `align` has been checked to be a power of 2 above - unsafe { align_offset(p, align) } - } + #[cfg(bootstrap)] + { + fn rt_impl(p: *const T, align: usize) -> usize { + // SAFETY: `align` has been checked to be a power of 2 above + unsafe { align_offset(p, align) } + } - const fn ctfe_impl(_: *const T, _: usize) -> usize { - usize::MAX + const fn ctfe_impl(_: *const T, _: usize) -> usize { + usize::MAX + } + + // SAFETY: + // It is permissible for `align_offset` to always return `usize::MAX`, + // algorithm correctness can not depend on `align_offset` returning non-max values. + // + // As such the behaviour can't change after replacing `align_offset` with `usize::MAX`, only performance can. + unsafe { intrinsics::const_eval_select((self, align), ctfe_impl, rt_impl) } } - // SAFETY: - // It is permissible for `align_offset` to always return `usize::MAX`, - // algorithm correctness can not depend on `align_offset` returning non-max values. - // - // As such the behaviour can't change after replacing `align_offset` with `usize::MAX`, only performance can. - unsafe { intrinsics::const_eval_select((self, align), ctfe_impl, rt_impl) } + #[cfg(not(bootstrap))] + { + // SAFETY: `align` has been checked to be a power of 2 above + unsafe { align_offset(self, align) } + } } /// Returns whether the pointer is properly aligned for `T`. @@ -1522,13 +1516,17 @@ impl *const T { #[unstable(feature = "pointer_is_aligned", issue = "96284")] #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "none")] pub const fn is_aligned_to(self, align: usize) -> bool { - assert!(align.is_power_of_two(), "is_aligned_to: align is not a power-of-two"); + if !align.is_power_of_two() { + panic!("is_aligned_to: align is not a power-of-two") + } #[inline] fn runtime(ptr: *const u8, align: usize) -> bool { ptr.addr() & (align - 1) == 0 } + // This optimizes to `(ptr + align - 1) & -align == ptr`, which is slightly + // slower than `ptr & (align - 1) == 0` const fn comptime(ptr: *const u8, align: usize) -> bool { ptr.align_offset(align) == 0 } diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index c79f815e35fd4..9174728868936 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -1591,21 +1591,6 @@ impl *mut T { #[must_use] #[stable(feature = "align_offset", since = "1.36.0")] #[rustc_const_unstable(feature = "const_align_offset", issue = "90962")] - #[cfg(not(bootstrap))] - pub const fn align_offset(self, align: usize) -> usize - where - T: Sized, - { - assert!(align.is_power_of_two(), "align_offset: align is not a power-of-two"); - - // SAFETY: `align` has been checked to be a power of 2 above - unsafe { align_offset(self, align) } - } - - #[stable(feature = "align_offset", since = "1.36.0")] - #[rustc_const_unstable(feature = "const_align_offset", issue = "90962")] - #[allow(missing_docs)] - #[cfg(bootstrap)] pub const fn align_offset(self, align: usize) -> usize where T: Sized, @@ -1614,21 +1599,30 @@ impl *mut T { panic!("align_offset: align is not a power-of-two"); } - fn rt_impl(p: *mut T, align: usize) -> usize { - // SAFETY: `align` has been checked to be a power of 2 above - unsafe { align_offset(p, align) } + #[cfg(bootstrap)] + { + fn rt_impl(p: *mut T, align: usize) -> usize { + // SAFETY: `align` has been checked to be a power of 2 above + unsafe { align_offset(p, align) } + } + + const fn ctfe_impl(_: *mut T, _: usize) -> usize { + usize::MAX + } + + // SAFETY: + // It is permissible for `align_offset` to always return `usize::MAX`, + // algorithm correctness can not depend on `align_offset` returning non-max values. + // + // As such the behaviour can't change after replacing `align_offset` with `usize::MAX`, only performance can. + unsafe { intrinsics::const_eval_select((self, align), ctfe_impl, rt_impl) } } - const fn ctfe_impl(_: *mut T, _: usize) -> usize { - usize::MAX + #[cfg(not(bootstrap))] + { + // SAFETY: `align` has been checked to be a power of 2 above + unsafe { align_offset(self, align) } } - - // SAFETY: - // It is permissible for `align_offset` to always return `usize::MAX`, - // algorithm correctness can not depend on `align_offset` returning non-max values. - // - // As such the behaviour can't change after replacing `align_offset` with `usize::MAX`, only performance can. - unsafe { intrinsics::const_eval_select((self, align), ctfe_impl, rt_impl) } } /// Returns whether the pointer is properly aligned for `T`. @@ -1790,13 +1784,17 @@ impl *mut T { #[unstable(feature = "pointer_is_aligned", issue = "96284")] #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "none")] pub const fn is_aligned_to(self, align: usize) -> bool { - assert!(align.is_power_of_two(), "is_aligned_to: align is not a power-of-two"); + if !align.is_power_of_two() { + panic!("is_aligned_to: align is not a power-of-two") + } #[inline] fn runtime(ptr: *mut u8, align: usize) -> bool { ptr.addr() & (align - 1) == 0 } + // This optimizes to `(ptr + align - 1) & -align == ptr`, which is slightly + // slower than `ptr & (align - 1) == 0` const fn comptime(ptr: *mut u8, align: usize) -> bool { ptr.align_offset(align) == 0 } From 4696e8906d362c1e10ffe40a5935de0ada45fb48 Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Sun, 23 Oct 2022 00:47:21 +0200 Subject: [PATCH 092/103] =?UTF-8?q?Schr=C3=B6dinger's=20pointer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's aligned *and* not aligned! --- library/core/src/ptr/const_ptr.rs | 42 +++++++++++++++++++++++++++++++ library/core/src/ptr/mut_ptr.rs | 42 +++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 37679c504b303..d042f22f0266f 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -1402,6 +1402,27 @@ impl *const T { /// }; /// ``` /// + /// Due to this behavior, it is possible that a runtime pointer derived from a compiletime + /// pointer is aligned, even if the compiletime pointer wasn't aligned. + /// + #[cfg_attr(bootstrap, doc = "```ignore")] + #[cfg_attr(not(bootstrap), doc = "```")] + /// #![feature(pointer_is_aligned)] + /// #![feature(const_pointer_is_aligned)] + /// + /// // At compiletime, neither `CONST_PTR` nor `CONST_PTR + 1` is aligned. + /// const CONST_PTR: *const i32 = &42; + /// const _: () = assert!(!CONST_PTR.cast::().is_aligned()); + /// const _: () = assert!(!CONST_PTR.wrapping_add(1).cast::().is_aligned()); + /// + /// // At runtime, either `runtime_ptr` or `runtime_ptr + 1` is aligned. + /// let runtime_ptr = CONST_PTR; + /// assert_ne!( + /// runtime_ptr.cast::().is_aligned(), + /// runtime_ptr.wrapping_add(1).cast::().is_aligned(), + /// ); + /// ``` + /// /// If a pointer is created from a fixed address, this function behaves the same during /// runtime and compiletime. /// @@ -1492,6 +1513,27 @@ impl *const T { /// }; /// ``` /// + /// Due to this behavior, it is possible that a runtime pointer derived from a compiletime + /// pointer is aligned, even if the compiletime pointer wasn't aligned. + /// + #[cfg_attr(bootstrap, doc = "```ignore")] + #[cfg_attr(not(bootstrap), doc = "```")] + /// #![feature(pointer_is_aligned)] + /// #![feature(const_pointer_is_aligned)] + /// + /// // At compiletime, neither `CONST_PTR` nor `CONST_PTR + 1` is aligned. + /// const CONST_PTR: *const i32 = &42; + /// const _: () = assert!(!CONST_PTR.is_aligned_to(8)); + /// const _: () = assert!(!CONST_PTR.wrapping_add(1).is_aligned_to(8)); + /// + /// // At runtime, either `runtime_ptr` or `runtime_ptr + 1` is aligned. + /// let runtime_ptr = CONST_PTR; + /// assert_ne!( + /// runtime_ptr.is_aligned_to(8), + /// runtime_ptr.wrapping_add(1).is_aligned_to(8), + /// ); + /// ``` + /// /// If a pointer is created from a fixed address, this function behaves the same during /// runtime and compiletime. /// diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 9174728868936..764fa9d8ba812 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -1670,6 +1670,27 @@ impl *mut T { /// }; /// ``` /// + /// Due to this behavior, it is possible that a runtime pointer derived from a compiletime + /// pointer is aligned, even if the compiletime pointer wasn't aligned. + /// + #[cfg_attr(bootstrap, doc = "```ignore")] + #[cfg_attr(not(bootstrap), doc = "```")] + /// #![feature(pointer_is_aligned)] + /// #![feature(const_pointer_is_aligned)] + /// + /// // At compiletime, neither `CONST_PTR` nor `CONST_PTR + 1` is aligned. + /// const CONST_PTR: *const i32 = &42; + /// const _: () = assert!(!CONST_PTR.cast::().is_aligned()); + /// const _: () = assert!(!CONST_PTR.wrapping_add(1).cast::().is_aligned()); + /// + /// // At runtime, either `runtime_ptr` or `runtime_ptr + 1` is aligned. + /// let runtime_ptr = CONST_PTR; + /// assert_ne!( + /// runtime_ptr.cast::().is_aligned(), + /// runtime_ptr.wrapping_add(1).cast::().is_aligned(), + /// ); + /// ``` + /// /// If a pointer is created from a fixed address, this function behaves the same during /// runtime and compiletime. /// @@ -1760,6 +1781,27 @@ impl *mut T { /// }; /// ``` /// + /// Due to this behavior, it is possible that a runtime pointer derived from a compiletime + /// pointer is aligned, even if the compiletime pointer wasn't aligned. + /// + #[cfg_attr(bootstrap, doc = "```ignore")] + #[cfg_attr(not(bootstrap), doc = "```")] + /// #![feature(pointer_is_aligned)] + /// #![feature(const_pointer_is_aligned)] + /// + /// // At compiletime, neither `CONST_PTR` nor `CONST_PTR + 1` is aligned. + /// const CONST_PTR: *const i32 = &42; + /// const _: () = assert!(!CONST_PTR.is_aligned_to(8)); + /// const _: () = assert!(!CONST_PTR.wrapping_add(1).is_aligned_to(8)); + /// + /// // At runtime, either `runtime_ptr` or `runtime_ptr + 1` is aligned. + /// let runtime_ptr = CONST_PTR; + /// assert_ne!( + /// runtime_ptr.is_aligned_to(8), + /// runtime_ptr.wrapping_add(1).is_aligned_to(8), + /// ); + /// ``` + /// /// If a pointer is created from a fixed address, this function behaves the same during /// runtime and compiletime. /// From daccb8c11a464040acd744729231429dcb2e4d4b Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Sun, 23 Oct 2022 12:30:46 +0200 Subject: [PATCH 093/103] always use `align_offset` in `is_aligned_to` + add assembly test --- library/core/src/ptr/const_ptr.rs | 19 ++++------ library/core/src/ptr/mut_ptr.rs | 19 ++++------ src/test/assembly/is_aligned.rs | 58 +++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 26 deletions(-) create mode 100644 src/test/assembly/is_aligned.rs diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index d042f22f0266f..82a01a70a4113 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -1321,6 +1321,7 @@ impl *const T { /// # } /// ``` #[must_use] + #[inline] #[stable(feature = "align_offset", since = "1.36.0")] #[rustc_const_unstable(feature = "const_align_offset", issue = "90962")] pub const fn align_offset(self, align: usize) -> usize @@ -1562,19 +1563,11 @@ impl *const T { panic!("is_aligned_to: align is not a power-of-two") } - #[inline] - fn runtime(ptr: *const u8, align: usize) -> bool { - ptr.addr() & (align - 1) == 0 - } - - // This optimizes to `(ptr + align - 1) & -align == ptr`, which is slightly - // slower than `ptr & (align - 1) == 0` - const fn comptime(ptr: *const u8, align: usize) -> bool { - ptr.align_offset(align) == 0 - } - - // SAFETY: `ptr.align_offset(align)` returns 0 if and only if the pointer is already aligned. - unsafe { intrinsics::const_eval_select((self.cast::(), align), comptime, runtime) } + // We can't use the address of `self` in a `const fn`, so we use `align_offset` instead. + // The cast to `()` is used to + // 1. deal with fat pointers; and + // 2. ensure that `align_offset` doesn't actually try to compute an offset. + self.cast::<()>().align_offset(align) == 0 } } diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 764fa9d8ba812..fdb99818ac7f9 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -1589,6 +1589,7 @@ impl *mut T { /// # } /// ``` #[must_use] + #[inline] #[stable(feature = "align_offset", since = "1.36.0")] #[rustc_const_unstable(feature = "const_align_offset", issue = "90962")] pub const fn align_offset(self, align: usize) -> usize @@ -1830,19 +1831,11 @@ impl *mut T { panic!("is_aligned_to: align is not a power-of-two") } - #[inline] - fn runtime(ptr: *mut u8, align: usize) -> bool { - ptr.addr() & (align - 1) == 0 - } - - // This optimizes to `(ptr + align - 1) & -align == ptr`, which is slightly - // slower than `ptr & (align - 1) == 0` - const fn comptime(ptr: *mut u8, align: usize) -> bool { - ptr.align_offset(align) == 0 - } - - // SAFETY: `ptr.align_offset(align)` returns 0 if and only if the pointer is already aligned. - unsafe { intrinsics::const_eval_select((self.cast::(), align), comptime, runtime) } + // We can't use the address of `self` in a `const fn`, so we use `align_offset` instead. + // The cast to `()` is used to + // 1. deal with fat pointers; and + // 2. ensure that `align_offset` doesn't actually try to compute an offset. + self.cast::<()>().align_offset(align) == 0 } } diff --git a/src/test/assembly/is_aligned.rs b/src/test/assembly/is_aligned.rs new file mode 100644 index 0000000000000..3949f5f6530b0 --- /dev/null +++ b/src/test/assembly/is_aligned.rs @@ -0,0 +1,58 @@ +// assembly-output: emit-asm +// min-llvm-version: 14.0 +// only-x86_64 +// revisions: opt-speed opt-size +// [opt-speed] compile-flags: -Copt-level=1 +// [opt-size] compile-flags: -Copt-level=s +#![crate_type="rlib"] + +#![feature(core_intrinsics)] +#![feature(pointer_is_aligned)] + +// CHECK-LABEL: is_aligned_to_unchecked +// CHECK: decq %rsi +// CHECK-NEXT: testq %rdi, %rsi +// CHECK-NEXT: sete %al +// CHECK-NEXT: retq +#[no_mangle] +pub unsafe fn is_aligned_to_unchecked(ptr: *const u8, align: usize) -> bool { + unsafe { + std::intrinsics::assume(align.is_power_of_two()) + } + ptr.is_aligned_to(align) +} + +// CHECK-LABEL: is_aligned_1 +// CHECK: movb $1, %al +// CHECK-NEXT: retq +#[no_mangle] +pub fn is_aligned_1(ptr: *const u8) -> bool { + ptr.is_aligned() +} + +// CHECK-LABEL: is_aligned_2 +// CHECK: testb $1, %dil +// CHECK-NEXT: sete %al +// CHECK-NEXT: retq +#[no_mangle] +pub fn is_aligned_2(ptr: *const u16) -> bool { + ptr.is_aligned() +} + +// CHECK-LABEL: is_aligned_4 +// CHECK: testb $3, %dil +// CHECK-NEXT: sete %al +// CHECK-NEXT: retq +#[no_mangle] +pub fn is_aligned_4(ptr: *const u32) -> bool { + ptr.is_aligned() +} + +// CHECK-LABEL: is_aligned_8 +// CHECK: testb $7, %dil +// CHECK-NEXT: sete %al +// CHECK-NEXT: retq +#[no_mangle] +pub fn is_aligned_8(ptr: *const u64) -> bool { + ptr.is_aligned() +} From 8a6053618f99852d31b46144043e881f6556ff1c Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Wed, 9 Nov 2022 20:18:00 +0100 Subject: [PATCH 094/103] docs cleanup * Fix doc examples for Platforms with underaligned integer primitives. * Mutable pointer doc examples use mutable pointers. * Fill out tracking issue. * Minor formatting changes. --- library/core/src/ptr/const_ptr.rs | 104 ++++++++++++++++++---------- library/core/src/ptr/mut_ptr.rs | 108 ++++++++++++++++++++---------- 2 files changed, 140 insertions(+), 72 deletions(-) diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 82a01a70a4113..8a3eee0dc529f 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -1367,8 +1367,12 @@ impl *const T { /// #![feature(pointer_is_aligned)] /// #![feature(pointer_byte_offsets)] /// - /// let data: i32 = 42; - /// let ptr: *const i32 = &data; + /// // On some platforms, the alignment of i32 is less than 4. + /// #[repr(align(4))] + /// struct AlignedI32(i32); + /// + /// let data = AlignedI32(42); + /// let ptr = &data as *const AlignedI32; /// /// assert!(ptr.is_aligned()); /// assert!(!ptr.wrapping_byte_add(1).is_aligned()); @@ -1389,15 +1393,20 @@ impl *const T { /// #![feature(pointer_is_aligned)] /// #![feature(const_pointer_is_aligned)] /// + /// // On some platforms, the alignment of primitives is less than their size. + /// #[repr(align(4))] + /// struct AlignedI32(i32); + /// #[repr(align(8))] + /// struct AlignedI64(i64); + /// /// const _: () = { - /// let data: i32 = 42; - /// let ptr: *const i32 = &data; + /// let data = AlignedI32(42); + /// let ptr = &data as *const AlignedI32; /// assert!(ptr.is_aligned()); /// - /// // At runtime either `ptr1` or `ptr2` would be aligned, - /// // but at compiletime neither is aligned. - /// let ptr1: *const i64 = ptr.cast(); - /// let ptr2: *const i64 = ptr.wrapping_add(1).cast(); + /// // At runtime either `ptr1` or `ptr2` would be aligned, but at compiletime neither is aligned. + /// let ptr1 = ptr.cast::(); + /// let ptr2 = ptr.wrapping_add(1).cast::(); /// assert!(!ptr1.is_aligned()); /// assert!(!ptr2.is_aligned()); /// }; @@ -1411,16 +1420,22 @@ impl *const T { /// #![feature(pointer_is_aligned)] /// #![feature(const_pointer_is_aligned)] /// - /// // At compiletime, neither `CONST_PTR` nor `CONST_PTR + 1` is aligned. - /// const CONST_PTR: *const i32 = &42; - /// const _: () = assert!(!CONST_PTR.cast::().is_aligned()); - /// const _: () = assert!(!CONST_PTR.wrapping_add(1).cast::().is_aligned()); + /// // On some platforms, the alignment of primitives is less than their size. + /// #[repr(align(4))] + /// struct AlignedI32(i32); + /// #[repr(align(8))] + /// struct AlignedI64(i64); + /// + /// // At compiletime, neither `COMPTIME_PTR` nor `COMPTIME_PTR + 1` is aligned. + /// const COMPTIME_PTR: *const AlignedI32 = &AlignedI32(42); + /// const _: () = assert!(!COMPTIME_PTR.cast::().is_aligned()); + /// const _: () = assert!(!COMPTIME_PTR.wrapping_add(1).cast::().is_aligned()); /// /// // At runtime, either `runtime_ptr` or `runtime_ptr + 1` is aligned. - /// let runtime_ptr = CONST_PTR; + /// let runtime_ptr = COMPTIME_PTR; /// assert_ne!( - /// runtime_ptr.cast::().is_aligned(), - /// runtime_ptr.wrapping_add(1).cast::().is_aligned(), + /// runtime_ptr.cast::().is_aligned(), + /// runtime_ptr.wrapping_add(1).cast::().is_aligned(), /// ); /// ``` /// @@ -1432,29 +1447,34 @@ impl *const T { /// #![feature(pointer_is_aligned)] /// #![feature(const_pointer_is_aligned)] /// + /// // On some platforms, the alignment of primitives is less than their size. + /// #[repr(align(4))] + /// struct AlignedI32(i32); + /// #[repr(align(8))] + /// struct AlignedI64(i64); + /// /// const _: () = { - /// let ptr = 40 as *const i32; + /// let ptr = 40 as *const AlignedI32; /// assert!(ptr.is_aligned()); /// - /// // For pointers with a known address, runtime and - /// // compiletime behavior are identical. - /// let ptr1: *const i64 = ptr.cast(); - /// let ptr2: *const i64 = ptr.wrapping_add(1).cast(); + /// // For pointers with a known address, runtime and compiletime behavior are identical. + /// let ptr1 = ptr.cast::(); + /// let ptr2 = ptr.wrapping_add(1).cast::(); /// assert!(ptr1.is_aligned()); /// assert!(!ptr2.is_aligned()); /// }; /// ``` /// - /// [tracking issue]: https://github.com/rust-lang/rust/issues/comming-soon + /// [tracking issue]: https://github.com/rust-lang/rust/issues/104203 #[must_use] #[inline] #[unstable(feature = "pointer_is_aligned", issue = "96284")] - #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "none")] + #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")] pub const fn is_aligned(self) -> bool where T: Sized, { - self.is_aligned_to(core::mem::align_of::()) + self.is_aligned_to(mem::align_of::()) } /// Returns whether the pointer is aligned to `align`. @@ -1473,8 +1493,12 @@ impl *const T { /// #![feature(pointer_is_aligned)] /// #![feature(pointer_byte_offsets)] /// - /// let data: i32 = 42; - /// let ptr: *const i32 = &data; + /// // On some platforms, the alignment of i32 is less than 4. + /// #[repr(align(4))] + /// struct AlignedI32(i32); + /// + /// let data = AlignedI32(42); + /// let ptr = &data as *const AlignedI32; /// /// assert!(ptr.is_aligned_to(1)); /// assert!(ptr.is_aligned_to(2)); @@ -1500,9 +1524,13 @@ impl *const T { /// #![feature(pointer_is_aligned)] /// #![feature(const_pointer_is_aligned)] /// + /// // On some platforms, the alignment of i32 is less than 4. + /// #[repr(align(4))] + /// struct AlignedI32(i32); + /// /// const _: () = { - /// let data: i32 = 42; - /// let ptr: *const i32 = &data; + /// let data = AlignedI32(42); + /// let ptr = &data as *const AlignedI32; /// /// assert!(ptr.is_aligned_to(1)); /// assert!(ptr.is_aligned_to(2)); @@ -1522,13 +1550,17 @@ impl *const T { /// #![feature(pointer_is_aligned)] /// #![feature(const_pointer_is_aligned)] /// - /// // At compiletime, neither `CONST_PTR` nor `CONST_PTR + 1` is aligned. - /// const CONST_PTR: *const i32 = &42; - /// const _: () = assert!(!CONST_PTR.is_aligned_to(8)); - /// const _: () = assert!(!CONST_PTR.wrapping_add(1).is_aligned_to(8)); + /// // On some platforms, the alignment of i32 is less than 4. + /// #[repr(align(4))] + /// struct AlignedI32(i32); + /// + /// // At compiletime, neither `COMPTIME_PTR` nor `COMPTIME_PTR + 1` is aligned. + /// const COMPTIME_PTR: *const AlignedI32 = &AlignedI32(42); + /// const _: () = assert!(!COMPTIME_PTR.is_aligned_to(8)); + /// const _: () = assert!(!COMPTIME_PTR.wrapping_add(1).is_aligned_to(8)); /// /// // At runtime, either `runtime_ptr` or `runtime_ptr + 1` is aligned. - /// let runtime_ptr = CONST_PTR; + /// let runtime_ptr = COMPTIME_PTR; /// assert_ne!( /// runtime_ptr.is_aligned_to(8), /// runtime_ptr.wrapping_add(1).is_aligned_to(8), @@ -1544,7 +1576,7 @@ impl *const T { /// #![feature(const_pointer_is_aligned)] /// /// const _: () = { - /// let ptr = 40 as *const i32; + /// let ptr = 40 as *const u8; /// assert!(ptr.is_aligned_to(1)); /// assert!(ptr.is_aligned_to(2)); /// assert!(ptr.is_aligned_to(4)); @@ -1553,14 +1585,14 @@ impl *const T { /// }; /// ``` /// - /// [tracking issue]: https://github.com/rust-lang/rust/issues/comming-soon + /// [tracking issue]: https://github.com/rust-lang/rust/issues/104203 #[must_use] #[inline] #[unstable(feature = "pointer_is_aligned", issue = "96284")] - #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "none")] + #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")] pub const fn is_aligned_to(self, align: usize) -> bool { if !align.is_power_of_two() { - panic!("is_aligned_to: align is not a power-of-two") + panic!("is_aligned_to: align is not a power-of-two"); } // We can't use the address of `self` in a `const fn`, so we use `align_offset` instead. diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index fdb99818ac7f9..8472b05ddbd40 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -1635,8 +1635,12 @@ impl *mut T { /// #![feature(pointer_is_aligned)] /// #![feature(pointer_byte_offsets)] /// - /// let data: i32 = 42; - /// let ptr: *const i32 = &data; + /// // On some platforms, the alignment of i32 is less than 4. + /// #[repr(align(4))] + /// struct AlignedI32(i32); + /// + /// let mut data = AlignedI32(42); + /// let ptr = &mut data as *mut AlignedI32; /// /// assert!(ptr.is_aligned()); /// assert!(!ptr.wrapping_byte_add(1).is_aligned()); @@ -1656,16 +1660,22 @@ impl *mut T { #[cfg_attr(not(bootstrap), doc = "```")] /// #![feature(pointer_is_aligned)] /// #![feature(const_pointer_is_aligned)] + /// #![feature(const_mut_refs)] + /// + /// // On some platforms, the alignment of primitives is less than their size. + /// #[repr(align(4))] + /// struct AlignedI32(i32); + /// #[repr(align(8))] + /// struct AlignedI64(i64); /// /// const _: () = { - /// let data: i32 = 42; - /// let ptr: *const i32 = &data; + /// let mut data = AlignedI32(42); + /// let ptr = &mut data as *mut AlignedI32; /// assert!(ptr.is_aligned()); /// - /// // At runtime either `ptr1` or `ptr2` would be aligned, - /// // but at compiletime neither is aligned. - /// let ptr1: *const i64 = ptr.cast(); - /// let ptr2: *const i64 = ptr.wrapping_add(1).cast(); + /// // At runtime either `ptr1` or `ptr2` would be aligned, but at compiletime neither is aligned. + /// let ptr1 = ptr.cast::(); + /// let ptr2 = ptr.wrapping_add(1).cast::(); /// assert!(!ptr1.is_aligned()); /// assert!(!ptr2.is_aligned()); /// }; @@ -1679,16 +1689,23 @@ impl *mut T { /// #![feature(pointer_is_aligned)] /// #![feature(const_pointer_is_aligned)] /// - /// // At compiletime, neither `CONST_PTR` nor `CONST_PTR + 1` is aligned. - /// const CONST_PTR: *const i32 = &42; - /// const _: () = assert!(!CONST_PTR.cast::().is_aligned()); - /// const _: () = assert!(!CONST_PTR.wrapping_add(1).cast::().is_aligned()); + /// // On some platforms, the alignment of primitives is less than their size. + /// #[repr(align(4))] + /// struct AlignedI32(i32); + /// #[repr(align(8))] + /// struct AlignedI64(i64); + /// + /// // At compiletime, neither `COMPTIME_PTR` nor `COMPTIME_PTR + 1` is aligned. + /// // Also, note that mutable references are not allowed in the final value of constants. + /// const COMPTIME_PTR: *mut AlignedI32 = (&AlignedI32(42) as *const AlignedI32).cast_mut(); + /// const _: () = assert!(!COMPTIME_PTR.cast::().is_aligned()); + /// const _: () = assert!(!COMPTIME_PTR.wrapping_add(1).cast::().is_aligned()); /// /// // At runtime, either `runtime_ptr` or `runtime_ptr + 1` is aligned. - /// let runtime_ptr = CONST_PTR; + /// let runtime_ptr = COMPTIME_PTR; /// assert_ne!( - /// runtime_ptr.cast::().is_aligned(), - /// runtime_ptr.wrapping_add(1).cast::().is_aligned(), + /// runtime_ptr.cast::().is_aligned(), + /// runtime_ptr.wrapping_add(1).cast::().is_aligned(), /// ); /// ``` /// @@ -1700,29 +1717,34 @@ impl *mut T { /// #![feature(pointer_is_aligned)] /// #![feature(const_pointer_is_aligned)] /// + /// // On some platforms, the alignment of primitives is less than their size. + /// #[repr(align(4))] + /// struct AlignedI32(i32); + /// #[repr(align(8))] + /// struct AlignedI64(i64); + /// /// const _: () = { - /// let ptr = 40 as *const i32; + /// let ptr = 40 as *mut AlignedI32; /// assert!(ptr.is_aligned()); /// - /// // For pointers with a known address, runtime and - /// // compiletime behavior are identical. - /// let ptr1: *const i64 = ptr.cast(); - /// let ptr2: *const i64 = ptr.wrapping_add(1).cast(); + /// // For pointers with a known address, runtime and compiletime behavior are identical. + /// let ptr1 = ptr.cast::(); + /// let ptr2 = ptr.wrapping_add(1).cast::(); /// assert!(ptr1.is_aligned()); /// assert!(!ptr2.is_aligned()); /// }; /// ``` /// - /// [tracking issue]: https://github.com/rust-lang/rust/issues/comming-soon + /// [tracking issue]: https://github.com/rust-lang/rust/issues/104203 #[must_use] #[inline] #[unstable(feature = "pointer_is_aligned", issue = "96284")] - #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "none")] + #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")] pub const fn is_aligned(self) -> bool where T: Sized, { - self.is_aligned_to(core::mem::align_of::()) + self.is_aligned_to(mem::align_of::()) } /// Returns whether the pointer is aligned to `align`. @@ -1741,8 +1763,12 @@ impl *mut T { /// #![feature(pointer_is_aligned)] /// #![feature(pointer_byte_offsets)] /// - /// let data: i32 = 42; - /// let ptr: *const i32 = &data; + /// // On some platforms, the alignment of i32 is less than 4. + /// #[repr(align(4))] + /// struct AlignedI32(i32); + /// + /// let mut data = AlignedI32(42); + /// let ptr = &mut data as *mut AlignedI32; /// /// assert!(ptr.is_aligned_to(1)); /// assert!(ptr.is_aligned_to(2)); @@ -1767,10 +1793,15 @@ impl *mut T { #[cfg_attr(not(bootstrap), doc = "```")] /// #![feature(pointer_is_aligned)] /// #![feature(const_pointer_is_aligned)] + /// #![feature(const_mut_refs)] + /// + /// // On some platforms, the alignment of i32 is less than 4. + /// #[repr(align(4))] + /// struct AlignedI32(i32); /// /// const _: () = { - /// let data: i32 = 42; - /// let ptr: *const i32 = &data; + /// let mut data = AlignedI32(42); + /// let ptr = &mut data as *mut AlignedI32; /// /// assert!(ptr.is_aligned_to(1)); /// assert!(ptr.is_aligned_to(2)); @@ -1790,13 +1821,18 @@ impl *mut T { /// #![feature(pointer_is_aligned)] /// #![feature(const_pointer_is_aligned)] /// - /// // At compiletime, neither `CONST_PTR` nor `CONST_PTR + 1` is aligned. - /// const CONST_PTR: *const i32 = &42; - /// const _: () = assert!(!CONST_PTR.is_aligned_to(8)); - /// const _: () = assert!(!CONST_PTR.wrapping_add(1).is_aligned_to(8)); + /// // On some platforms, the alignment of i32 is less than 4. + /// #[repr(align(4))] + /// struct AlignedI32(i32); + /// + /// // At compiletime, neither `COMPTIME_PTR` nor `COMPTIME_PTR + 1` is aligned. + /// // Also, note that mutable references are not allowed in the final value of constants. + /// const COMPTIME_PTR: *mut AlignedI32 = (&AlignedI32(42) as *const AlignedI32).cast_mut(); + /// const _: () = assert!(!COMPTIME_PTR.is_aligned_to(8)); + /// const _: () = assert!(!COMPTIME_PTR.wrapping_add(1).is_aligned_to(8)); /// /// // At runtime, either `runtime_ptr` or `runtime_ptr + 1` is aligned. - /// let runtime_ptr = CONST_PTR; + /// let runtime_ptr = COMPTIME_PTR; /// assert_ne!( /// runtime_ptr.is_aligned_to(8), /// runtime_ptr.wrapping_add(1).is_aligned_to(8), @@ -1812,7 +1848,7 @@ impl *mut T { /// #![feature(const_pointer_is_aligned)] /// /// const _: () = { - /// let ptr = 40 as *const i32; + /// let ptr = 40 as *mut u8; /// assert!(ptr.is_aligned_to(1)); /// assert!(ptr.is_aligned_to(2)); /// assert!(ptr.is_aligned_to(4)); @@ -1821,14 +1857,14 @@ impl *mut T { /// }; /// ``` /// - /// [tracking issue]: https://github.com/rust-lang/rust/issues/comming-soon + /// [tracking issue]: https://github.com/rust-lang/rust/issues/104203 #[must_use] #[inline] #[unstable(feature = "pointer_is_aligned", issue = "96284")] - #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "none")] + #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")] pub const fn is_aligned_to(self, align: usize) -> bool { if !align.is_power_of_two() { - panic!("is_aligned_to: align is not a power-of-two") + panic!("is_aligned_to: align is not a power-of-two"); } // We can't use the address of `self` in a `const fn`, so we use `align_offset` instead. From 60f352fd7d1b3443a07bbfefb955a4e836749ee6 Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Fri, 11 Nov 2022 10:01:06 +0100 Subject: [PATCH 095/103] replace potential ICE with graceful error (`no_core` only) --- compiler/rustc_const_eval/src/const_eval/machine.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 6cf8a581d71a6..93afbbd27a4e6 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -1,4 +1,5 @@ use rustc_hir::def::DefKind; +use rustc_hir::LangItem; use rustc_middle::mir; use rustc_middle::mir::interpret::PointerArithmetic; use rustc_middle::ty::layout::LayoutOf; @@ -178,9 +179,7 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> { return Err(ConstEvalErrKind::Panic { msg, file, line, col }.into()); } else if Some(def_id) == self.tcx.lang_items().panic_fmt() { // For panic_fmt, call const_panic_fmt instead. - let Some(const_def_id) = self.tcx.lang_items().const_panic_fmt() else { - bug!("`const_panic_fmt` must be defined to call `panic_fmt` in const eval") - }; + let const_def_id = self.tcx.require_lang_item(LangItem::ConstPanicFmt, None); let new_instance = ty::Instance::resolve( *self.tcx, ty::ParamEnv::reveal_all(), From 8717455b9dd5f56d42d605ae7c0b657070cf4774 Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Fri, 11 Nov 2022 15:52:49 +0100 Subject: [PATCH 096/103] fix assembly test on windows --- src/test/assembly/is_aligned.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/assembly/is_aligned.rs b/src/test/assembly/is_aligned.rs index 3949f5f6530b0..e8e6ad5cf112e 100644 --- a/src/test/assembly/is_aligned.rs +++ b/src/test/assembly/is_aligned.rs @@ -10,9 +10,9 @@ #![feature(pointer_is_aligned)] // CHECK-LABEL: is_aligned_to_unchecked -// CHECK: decq %rsi -// CHECK-NEXT: testq %rdi, %rsi -// CHECK-NEXT: sete %al +// CHECK: decq +// CHECK-NEXT: testq +// CHECK-NEXT: sete // CHECK-NEXT: retq #[no_mangle] pub unsafe fn is_aligned_to_unchecked(ptr: *const u8, align: usize) -> bool { @@ -23,7 +23,7 @@ pub unsafe fn is_aligned_to_unchecked(ptr: *const u8, align: usize) -> bool { } // CHECK-LABEL: is_aligned_1 -// CHECK: movb $1, %al +// CHECK: movb $1 // CHECK-NEXT: retq #[no_mangle] pub fn is_aligned_1(ptr: *const u8) -> bool { @@ -31,8 +31,8 @@ pub fn is_aligned_1(ptr: *const u8) -> bool { } // CHECK-LABEL: is_aligned_2 -// CHECK: testb $1, %dil -// CHECK-NEXT: sete %al +// CHECK: testb $1 +// CHECK-NEXT: sete // CHECK-NEXT: retq #[no_mangle] pub fn is_aligned_2(ptr: *const u16) -> bool { @@ -40,8 +40,8 @@ pub fn is_aligned_2(ptr: *const u16) -> bool { } // CHECK-LABEL: is_aligned_4 -// CHECK: testb $3, %dil -// CHECK-NEXT: sete %al +// CHECK: testb $3 +// CHECK-NEXT: sete // CHECK-NEXT: retq #[no_mangle] pub fn is_aligned_4(ptr: *const u32) -> bool { @@ -49,8 +49,8 @@ pub fn is_aligned_4(ptr: *const u32) -> bool { } // CHECK-LABEL: is_aligned_8 -// CHECK: testb $7, %dil -// CHECK-NEXT: sete %al +// CHECK: testb $7 +// CHECK-NEXT: sete // CHECK-NEXT: retq #[no_mangle] pub fn is_aligned_8(ptr: *const u64) -> bool { From 9e5d497b67c7566001bdcfc8a2767f26a23afc5b Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Tue, 15 Nov 2022 15:55:37 +0100 Subject: [PATCH 097/103] fix const `align_offset` implementation --- .../src/const_eval/machine.rs | 9 +- library/core/tests/ptr.rs | 104 +++++++++++------- 2 files changed, 69 insertions(+), 44 deletions(-) diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 93afbbd27a4e6..92ccc94e63024 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -278,9 +278,8 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> { return u64::MAX; } - let byte_offset = align - addr_mod_align; - if align % stride == 0 { + let byte_offset = align - addr_mod_align; if byte_offset % stride == 0 { return byte_offset / stride; } else { @@ -296,8 +295,11 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> { return u64::MAX; } + // Instead of `(addr + offset * stride) % align == 0`, we solve + // `((addr + offset * stride) / gcd) % (align / gcd) == 0`. + let addr2 = addr / gcd; let align2 = align / gcd; - let stride2 = (stride / gcd) % align2; + let stride2 = stride / gcd; let mut stride_inv = 1u64; let mut mod_gate = 2u64; @@ -308,6 +310,7 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> { (mod_gate, overflow) = mod_gate.overflowing_mul(mod_gate); } + let byte_offset = align2 - addr2 % align2; byte_offset.wrapping_mul(stride_inv) % align2 } diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index 9f74b0c04107e..036acc46daba8 100644 --- a/library/core/tests/ptr.rs +++ b/library/core/tests/ptr.rs @@ -510,49 +510,53 @@ fn align_offset_various_strides_const() { assert!(got == expected); } - // For pointers of stride != 1, we verify the algorithm against the naivest possible - // implementation - let mut align = 1; - let limit = 1024; - while align < limit { - for ptr in 1usize..4 * align { - unsafe { - #[repr(packed)] - struct A3(u16, u8); - test_stride::(ptr::invalid::(ptr), ptr, align); - - struct A4(u32); - test_stride::(ptr::invalid::(ptr), ptr, align); - - #[repr(packed)] - struct A5(u32, u8); - test_stride::(ptr::invalid::(ptr), ptr, align); - - #[repr(packed)] - struct A6(u32, u16); - test_stride::(ptr::invalid::(ptr), ptr, align); - - #[repr(packed)] - struct A7(u32, u16, u8); - test_stride::(ptr::invalid::(ptr), ptr, align); - - #[repr(packed)] - struct A8(u32, u32); - test_stride::(ptr::invalid::(ptr), ptr, align); - - #[repr(packed)] - struct A9(u32, u32, u8); - test_stride::(ptr::invalid::(ptr), ptr, align); - - #[repr(packed)] - struct A10(u32, u32, u16); - test_stride::(ptr::invalid::(ptr), ptr, align); - - test_stride::(ptr::invalid::(ptr), ptr, align); - test_stride::(ptr::invalid::(ptr), ptr, align); + const { + // For pointers of stride != 1, we verify the algorithm against the naivest possible + // implementation + let mut align = 1; + let limit = 32; + while align < limit { + let mut ptr = 1; + while ptr < 4 * align { + unsafe { + #[repr(packed)] + struct A3(u16, u8); + test_stride::(ptr::invalid::(ptr), ptr, align); + + struct A4(u32); + test_stride::(ptr::invalid::(ptr), ptr, align); + + #[repr(packed)] + struct A5(u32, u8); + test_stride::(ptr::invalid::(ptr), ptr, align); + + #[repr(packed)] + struct A6(u32, u16); + test_stride::(ptr::invalid::(ptr), ptr, align); + + #[repr(packed)] + struct A7(u32, u16, u8); + test_stride::(ptr::invalid::(ptr), ptr, align); + + #[repr(packed)] + struct A8(u32, u32); + test_stride::(ptr::invalid::(ptr), ptr, align); + + #[repr(packed)] + struct A9(u32, u32, u8); + test_stride::(ptr::invalid::(ptr), ptr, align); + + #[repr(packed)] + struct A10(u32, u32, u16); + test_stride::(ptr::invalid::(ptr), ptr, align); + + test_stride::(ptr::invalid::(ptr), ptr, align); + test_stride::(ptr::invalid::(ptr), ptr, align); + } + ptr += 1; } + align = (align + 1).next_power_of_two(); } - align = (align + 1).next_power_of_two(); } } @@ -632,6 +636,24 @@ fn align_offset_issue_103361() { let _ = (SIZE as *const HugeSize).align_offset(SIZE); } +#[test] +#[cfg(not(bootstrap))] +fn align_offset_issue_103361_const() { + #[cfg(target_pointer_width = "64")] + const SIZE: usize = 1 << 47; + #[cfg(target_pointer_width = "32")] + const SIZE: usize = 1 << 30; + #[cfg(target_pointer_width = "16")] + const SIZE: usize = 1 << 13; + struct HugeSize([u8; SIZE - 1]); + + const { + assert!(ptr::invalid::(SIZE - 1).align_offset(SIZE) == SIZE - 1); + assert!(ptr::invalid::(SIZE).align_offset(SIZE) == 0); + assert!(ptr::invalid::(SIZE + 1).align_offset(SIZE) == 1); + } +} + #[test] fn is_aligned() { let data = 42; From 3d7e9c4b7fdce062b2b337f708980ecb3e9f4c9a Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Wed, 16 Nov 2022 11:41:18 +0100 Subject: [PATCH 098/103] Revert "don't call `align_offset` during const eval, ever" This reverts commit f3a577bfae376c0222e934911865ed14cddd1539. --- .../src/const_eval/machine.rs | 134 ++++++------------ library/core/src/ptr/mod.rs | 7 +- 2 files changed, 49 insertions(+), 92 deletions(-) diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 92ccc94e63024..04e68b9645525 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -2,10 +2,11 @@ use rustc_hir::def::DefKind; use rustc_hir::LangItem; use rustc_middle::mir; use rustc_middle::mir::interpret::PointerArithmetic; -use rustc_middle::ty::layout::LayoutOf; +use rustc_middle::ty::layout::FnAbiOf; use rustc_middle::ty::{self, Ty, TyCtxt}; use std::borrow::Borrow; use std::hash::Hash; +use std::ops::ControlFlow; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::fx::IndexEntry; @@ -20,8 +21,8 @@ use rustc_target::abi::{Align, Size}; use rustc_target::spec::abi::Abi as CallAbi; use crate::interpret::{ - self, compile_time_machine, AllocId, ConstAllocation, Frame, ImmTy, InterpCx, InterpResult, - OpTy, PlaceTy, Pointer, Scalar, StackPopUnwind, + self, compile_time_machine, AllocId, ConstAllocation, FnVal, Frame, ImmTy, InterpCx, + InterpResult, OpTy, PlaceTy, Pointer, Scalar, StackPopUnwind, }; use super::error::*; @@ -191,21 +192,24 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> { return Ok(Some(new_instance)); } else if Some(def_id) == self.tcx.lang_items().align_offset_fn() { - // For align_offset, we replace the function call entirely. - self.align_offset(instance, args, dest, ret)?; - return Ok(None); + // For align_offset, we replace the function call if the pointer has no address. + match self.align_offset(instance, args, dest, ret)? { + ControlFlow::Continue(()) => return Ok(Some(instance)), + ControlFlow::Break(()) => return Ok(None), + } } Ok(Some(instance)) } - /// This function replaces `align_offset(ptr, target_align)` in const eval, because the - /// pointer may not have an address. + /// `align_offset(ptr, target_align)` needs special handling in const eval, because the pointer + /// may not have an address. /// - /// If `ptr` does have a known address, we forward it to [`Self::align_offset_impl`]. + /// If `ptr` does have a known address, then we return `CONTINUE` and the function call should + /// proceed as normal. /// /// If `ptr` doesn't have an address, but its underlying allocation's alignment is at most - /// `target_align`, then we call [`Self::align_offset_impl`] with an dummy address relative - /// to the allocation. + /// `target_align`, then we call the function again with an dummy address relative to the + /// allocation. /// /// If `ptr` doesn't have an address and `target_align` is stricter than the underlying /// allocation's alignment, then we return `usize::MAX` immediately. @@ -215,103 +219,53 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> { args: &[OpTy<'tcx>], dest: &PlaceTy<'tcx>, ret: Option, - ) -> InterpResult<'tcx> { + ) -> InterpResult<'tcx, ControlFlow<()>> { assert_eq!(args.len(), 2); let ptr = self.read_pointer(&args[0])?; let target_align = self.read_scalar(&args[1])?.to_machine_usize(self)?; - let pointee_ty = instance.substs.type_at(0); - let stride = self.layout_of(pointee_ty)?.size.bytes(); - if !target_align.is_power_of_two() { throw_ub_format!("`align_offset` called with non-power-of-two align: {}", target_align); } - let mut align_offset = match self.ptr_try_get_alloc_id(ptr) { + match self.ptr_try_get_alloc_id(ptr) { Ok((alloc_id, offset, _extra)) => { - // Extract the address relative to a base that is definitely sufficiently aligned. let (_size, alloc_align, _kind) = self.get_alloc_info(alloc_id); if target_align <= alloc_align.bytes() { - // The pointer *is* alignable in const. We use an address relative to the - // allocation base that is definitely sufficiently aligned. - let addr = offset.bytes(); - Self::align_offset_impl(addr, stride, target_align) + // Extract the address relative to the allocation base that is definitely + // sufficiently aligned and call `align_offset` again. + let addr = ImmTy::from_uint(offset.bytes(), args[0].layout).into(); + let align = ImmTy::from_uint(target_align, args[1].layout).into(); + let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty())?; + + // We replace the entire entire function call with a "tail call". + // Note that this happens before the frame of the original function + // is pushed on the stack. + self.eval_fn_call( + FnVal::Instance(instance), + (CallAbi::Rust, fn_abi), + &[addr, align], + /* with_caller_location = */ false, + dest, + ret, + StackPopUnwind::NotAllowed, + )?; + Ok(ControlFlow::BREAK) } else { - // The pointer *is not* alignable in const, return `usize::MAX`. - // (We clamp this to machine `usize` below.) - u64::MAX + // Not alignable in const, return `usize::MAX`. + let usize_max = Scalar::from_machine_usize(self.machine_usize_max(), self); + self.write_scalar(usize_max, dest)?; + self.return_to_block(ret)?; + Ok(ControlFlow::BREAK) } } - Err(addr) => { - // The pointer has a known address. - Self::align_offset_impl(addr, stride, target_align) - } - }; - - let usize_max = self.machine_usize_max(); - if align_offset > usize_max { - align_offset = usize_max; - } - - self.write_scalar(Scalar::from_machine_usize(align_offset, self), dest)?; - self.return_to_block(ret)?; - - Ok(()) - } - - /// Const eval implementation of `#[lang = "align_offset"]`. - /// See the runtime version for a detailed explanation how this works. - fn align_offset_impl(addr: u64, stride: u64, align: u64) -> u64 { - assert!(align.is_power_of_two()); - - let addr_mod_align = addr % align; - - if addr_mod_align == 0 { - // The address is already sufficiently aligned. - return 0; - } - - if stride == 0 { - // The address cannot be aligned. - return u64::MAX; - } - - if align % stride == 0 { - let byte_offset = align - addr_mod_align; - if byte_offset % stride == 0 { - return byte_offset / stride; - } else { - return u64::MAX; + Err(_addr) => { + // The pointer has an address, continue with function call. + Ok(ControlFlow::CONTINUE) } } - - // This only works, because `align` is a power of two. - let gcd = 1u64 << (stride | align).trailing_zeros(); - - if addr % gcd != 0 { - // The address cannot be aligned. - return u64::MAX; - } - - // Instead of `(addr + offset * stride) % align == 0`, we solve - // `((addr + offset * stride) / gcd) % (align / gcd) == 0`. - let addr2 = addr / gcd; - let align2 = align / gcd; - let stride2 = stride / gcd; - - let mut stride_inv = 1u64; - let mut mod_gate = 2u64; - let mut overflow = false; - while !overflow && mod_gate < align2 { - stride_inv = - stride_inv.wrapping_mul(2u64.wrapping_sub(stride2.wrapping_mul(stride_inv))); - (mod_gate, overflow) = mod_gate.overflowing_mul(mod_gate); - } - - let byte_offset = align2 - addr2 % align2; - byte_offset.wrapping_mul(stride_inv) % align2 } /// See documentation on the `ptr_guaranteed_cmp` intrinsic. diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index e762837ff90a9..9283b81a84e2b 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -1591,7 +1591,6 @@ pub unsafe fn write_volatile(dst: *mut T, src: T) { /// /// Any questions go to @nagisa. #[lang = "align_offset"] -#[rustc_do_not_const_check] // hooked by const-eval pub(crate) const unsafe fn align_offset(p: *const T, a: usize) -> usize { // FIXME(#75598): Direct use of these intrinsics improves codegen significantly at opt-level <= // 1, where the method versions of these operations are not inlined. @@ -1651,9 +1650,13 @@ pub(crate) const unsafe fn align_offset(p: *const T, a: usize) -> usiz inverse & m_minus_one } - let addr = p.addr(); let stride = mem::size_of::(); + // SAFETY: At runtime, transmuting a pointer to `usize` is always safe, because they have the + // same layout. During const eval, we hook this function to ensure that the pointer always has + // an address (only the standard library can do this). + let addr: usize = unsafe { mem::transmute(p) }; + // SAFETY: `a` is a power-of-two, therefore non-zero. let a_minus_one = unsafe { unchecked_sub(a, 1) }; From e90d15b247bdaf12a6d51f492bf94d2e0064d177 Mon Sep 17 00:00:00 2001 From: Lukas Date: Wed, 16 Nov 2022 15:08:35 +0100 Subject: [PATCH 099/103] Update comment on pointer-to-usize transmute Co-authored-by: Ralf Jung --- library/core/src/ptr/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index 9283b81a84e2b..73923753a3020 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -1652,9 +1652,10 @@ pub(crate) const unsafe fn align_offset(p: *const T, a: usize) -> usiz let stride = mem::size_of::(); - // SAFETY: At runtime, transmuting a pointer to `usize` is always safe, because they have the - // same layout. During const eval, we hook this function to ensure that the pointer always has - // an address (only the standard library can do this). + // SAFETY: This is just an inlined `p.addr()` (which is not + // a `const fn` so we cannot call it). + // During const eval, we hook this function to ensure that the pointer never + // has provenance, making this sound. let addr: usize = unsafe { mem::transmute(p) }; // SAFETY: `a` is a power-of-two, therefore non-zero. From 53c2ee8e9b815b687a8f203bc5fb99d535a10a0d Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Wed, 16 Nov 2022 21:07:51 +0100 Subject: [PATCH 100/103] fix assembly test on apple --- src/test/assembly/is_aligned.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/assembly/is_aligned.rs b/src/test/assembly/is_aligned.rs index e8e6ad5cf112e..04b5de8342370 100644 --- a/src/test/assembly/is_aligned.rs +++ b/src/test/assembly/is_aligned.rs @@ -13,7 +13,7 @@ // CHECK: decq // CHECK-NEXT: testq // CHECK-NEXT: sete -// CHECK-NEXT: retq +// CHECK: retq #[no_mangle] pub unsafe fn is_aligned_to_unchecked(ptr: *const u8, align: usize) -> bool { unsafe { @@ -24,7 +24,7 @@ pub unsafe fn is_aligned_to_unchecked(ptr: *const u8, align: usize) -> bool { // CHECK-LABEL: is_aligned_1 // CHECK: movb $1 -// CHECK-NEXT: retq +// CHECK: retq #[no_mangle] pub fn is_aligned_1(ptr: *const u8) -> bool { ptr.is_aligned() @@ -33,7 +33,7 @@ pub fn is_aligned_1(ptr: *const u8) -> bool { // CHECK-LABEL: is_aligned_2 // CHECK: testb $1 // CHECK-NEXT: sete -// CHECK-NEXT: retq +// CHECK: retq #[no_mangle] pub fn is_aligned_2(ptr: *const u16) -> bool { ptr.is_aligned() @@ -42,7 +42,7 @@ pub fn is_aligned_2(ptr: *const u16) -> bool { // CHECK-LABEL: is_aligned_4 // CHECK: testb $3 // CHECK-NEXT: sete -// CHECK-NEXT: retq +// CHECK: retq #[no_mangle] pub fn is_aligned_4(ptr: *const u32) -> bool { ptr.is_aligned() @@ -51,7 +51,7 @@ pub fn is_aligned_4(ptr: *const u32) -> bool { // CHECK-LABEL: is_aligned_8 // CHECK: testb $7 // CHECK-NEXT: sete -// CHECK-NEXT: retq +// CHECK: retq #[no_mangle] pub fn is_aligned_8(ptr: *const u64) -> bool { ptr.is_aligned() From c9c017dfb55e375800c3e424311939a7ba3d4deb Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Fri, 18 Nov 2022 13:59:21 +0100 Subject: [PATCH 101/103] update provenance test * fix allocation alignment for 16bit platforms * add edge case where `stride % align != 0` on pointers with provenance --- library/core/tests/ptr.rs | 48 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index 036acc46daba8..390148550a4b3 100644 --- a/library/core/tests/ptr.rs +++ b/library/core/tests/ptr.rs @@ -564,9 +564,15 @@ fn align_offset_various_strides_const() { #[cfg(not(bootstrap))] fn align_offset_with_provenance_const() { const { - let data = 42; + // On some platforms (e.g. msp430-none-elf), the alignment of `i32` is less than 4. + #[repr(align(4))] + struct AlignedI32(i32); - let ptr: *const i32 = &data; + let data = AlignedI32(42); + + // `stride % align == 0` (usual case) + + let ptr: *const i32 = &data.0; assert!(ptr.align_offset(1) == 0); assert!(ptr.align_offset(2) == 0); assert!(ptr.align_offset(4) == 0); @@ -621,6 +627,44 @@ fn align_offset_with_provenance_const() { assert!(ptr3.align_offset(8) == usize::MAX); assert!(ptr3.wrapping_byte_add(1).align_offset(1) == 0); assert!(ptr3.wrapping_byte_add(1).align_offset(2) == usize::MAX); + + // `stride % align != 0` (edge case) + + let ptr4: *const [u8; 3] = ptr.cast(); + assert!(ptr4.align_offset(1) == 0); + assert!(ptr4.align_offset(2) == 0); + assert!(ptr4.align_offset(4) == 0); + assert!(ptr4.align_offset(8) == usize::MAX); + assert!(ptr4.wrapping_byte_add(1).align_offset(1) == 0); + assert!(ptr4.wrapping_byte_add(1).align_offset(2) == 1); + assert!(ptr4.wrapping_byte_add(1).align_offset(4) == 1); + assert!(ptr4.wrapping_byte_add(1).align_offset(8) == usize::MAX); + assert!(ptr4.wrapping_byte_add(2).align_offset(1) == 0); + assert!(ptr4.wrapping_byte_add(2).align_offset(2) == 0); + assert!(ptr4.wrapping_byte_add(2).align_offset(4) == 2); + assert!(ptr4.wrapping_byte_add(2).align_offset(8) == usize::MAX); + assert!(ptr4.wrapping_byte_add(3).align_offset(1) == 0); + assert!(ptr4.wrapping_byte_add(3).align_offset(2) == 1); + assert!(ptr4.wrapping_byte_add(3).align_offset(4) == 3); + assert!(ptr4.wrapping_byte_add(3).align_offset(8) == usize::MAX); + + let ptr5: *const [u8; 5] = ptr.cast(); + assert!(ptr5.align_offset(1) == 0); + assert!(ptr5.align_offset(2) == 0); + assert!(ptr5.align_offset(4) == 0); + assert!(ptr5.align_offset(8) == usize::MAX); + assert!(ptr5.wrapping_byte_add(1).align_offset(1) == 0); + assert!(ptr5.wrapping_byte_add(1).align_offset(2) == 1); + assert!(ptr5.wrapping_byte_add(1).align_offset(4) == 3); + assert!(ptr5.wrapping_byte_add(1).align_offset(8) == usize::MAX); + assert!(ptr5.wrapping_byte_add(2).align_offset(1) == 0); + assert!(ptr5.wrapping_byte_add(2).align_offset(2) == 0); + assert!(ptr5.wrapping_byte_add(2).align_offset(4) == 2); + assert!(ptr5.wrapping_byte_add(2).align_offset(8) == usize::MAX); + assert!(ptr5.wrapping_byte_add(3).align_offset(1) == 0); + assert!(ptr5.wrapping_byte_add(3).align_offset(2) == 1); + assert!(ptr5.wrapping_byte_add(3).align_offset(4) == 1); + assert!(ptr5.wrapping_byte_add(3).align_offset(8) == usize::MAX); } } From aada2d16892ed411d9f6d22b3b9dcfcf47977647 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 20 Nov 2022 07:48:21 +0100 Subject: [PATCH 102/103] Preparing for merge from rustc --- src/tools/miri/rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri/rust-version b/src/tools/miri/rust-version index d3e139e4651e7..d007f952a67a1 100644 --- a/src/tools/miri/rust-version +++ b/src/tools/miri/rust-version @@ -1 +1 @@ -2f8d8040166a730d0da7bba0f2864f0ef7ff6364 +7477c1f4f7d6bef037d523099b240d22aa1b63a0 From 4da7d4b168193f0725444678cd05bd69965c5da1 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 20 Nov 2022 08:04:36 +0100 Subject: [PATCH 103/103] fix unused warning in a test --- src/tools/miri/tests/pass/panic/catch_panic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri/tests/pass/panic/catch_panic.rs b/src/tools/miri/tests/pass/panic/catch_panic.rs index 308904406538c..5d57df4e52bfa 100644 --- a/src/tools/miri/tests/pass/panic/catch_panic.rs +++ b/src/tools/miri/tests/pass/panic/catch_panic.rs @@ -69,7 +69,7 @@ fn main() { }); test(Some("align_offset: align is not a power-of-two"), |_old_val| { - (0usize as *const u8).align_offset(3); + let _ = (0usize as *const u8).align_offset(3); loop {} });