From c13669e00b4ba3f353ea1cfa825aecb0bb765f9c Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Wed, 25 Jan 2023 17:15:59 -0800 Subject: [PATCH 01/11] Implement `AsFd` and `AsRawFd` for `Rc` Fixes https://github.com/rust-lang/rust/issues/105931. --- library/std/src/os/fd/owned.rs | 8 ++++++++ library/std/src/os/fd/raw.rs | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs index c41e093a7e5..439b8d52a2d 100644 --- a/library/std/src/os/fd/owned.rs +++ b/library/std/src/os/fd/owned.rs @@ -396,6 +396,14 @@ impl AsFd for crate::sync::Arc { } } +#[stable(feature = "asfd_rc", since = "CURRENT_RUSTC_VERSION")] +impl AsFd for crate::rc::Rc { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + (**self).as_fd() + } +} + #[stable(feature = "asfd_ptrs", since = "1.64.0")] impl AsFd for Box { #[inline] diff --git a/library/std/src/os/fd/raw.rs b/library/std/src/os/fd/raw.rs index f92a0506670..c138162f1ab 100644 --- a/library/std/src/os/fd/raw.rs +++ b/library/std/src/os/fd/raw.rs @@ -244,6 +244,14 @@ impl AsRawFd for crate::sync::Arc { } } +#[stable(feature = "asfd_rc", since = "CURRENT_RUSTC_VERSION")] +impl AsRawFd for crate::rc::Rc { + #[inline] + fn as_raw_fd(&self) -> RawFd { + (**self).as_raw_fd() + } +} + #[stable(feature = "asrawfd_ptrs", since = "1.63.0")] impl AsRawFd for Box { #[inline] From 83b05ef0ee05307143e2d04db401d6085f4759b9 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sat, 28 Jan 2023 17:06:30 -0500 Subject: [PATCH 02/11] Stabilize feature 'cstr_from_bytes_until_nul' --- library/alloc/src/lib.rs | 1 - library/core/src/error.rs | 2 +- library/core/src/ffi/c_str.rs | 10 ++++------ library/std/src/lib.rs | 1 - src/tools/miri/tests/pass-dep/shims/pthreads.rs | 1 - 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 76dabfb429d..e9cc3875f68 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -116,7 +116,6 @@ #![feature(const_eval_select)] #![feature(const_pin)] #![feature(const_waker)] -#![feature(cstr_from_bytes_until_nul)] #![feature(dispatch_from_dyn)] #![feature(error_generic_member_access)] #![feature(error_in_core)] diff --git a/library/core/src/error.rs b/library/core/src/error.rs index d2fac23ff18..e11a5e99184 100644 --- a/library/core/src/error.rs +++ b/library/core/src/error.rs @@ -505,7 +505,7 @@ impl Error for crate::ffi::FromBytesWithNulError { } } -#[unstable(feature = "cstr_from_bytes_until_nul", issue = "95027")] +#[stable(feature = "cstr_from_bytes_until_nul", since = "CURRENT_RUSTC_VERSION")] impl Error for crate::ffi::FromBytesUntilNulError {} #[unstable(feature = "get_many_mut", issue = "104642")] diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index 15dd9ea7e80..288bac67f75 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -150,10 +150,10 @@ impl FromBytesWithNulError { /// This error is created by the [`CStr::from_bytes_until_nul`] method. /// #[derive(Clone, PartialEq, Eq, Debug)] -#[unstable(feature = "cstr_from_bytes_until_nul", issue = "95027")] +#[stable(feature = "cstr_from_bytes_until_nul", since = "CURRENT_RUSTC_VERSION")] pub struct FromBytesUntilNulError(()); -#[unstable(feature = "cstr_from_bytes_until_nul", issue = "95027")] +#[stable(feature = "cstr_from_bytes_until_nul", since = "CURRENT_RUSTC_VERSION")] impl fmt::Display for FromBytesUntilNulError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "data provided does not contain a nul") @@ -306,8 +306,6 @@ impl CStr { /// /// # Examples /// ``` - /// #![feature(cstr_from_bytes_until_nul)] - /// /// use std::ffi::CStr; /// /// let mut buffer = [0u8; 16]; @@ -322,8 +320,8 @@ impl CStr { /// assert_eq!(c_str.to_str().unwrap(), "AAAAAAAA"); /// ``` /// - #[unstable(feature = "cstr_from_bytes_until_nul", issue = "95027")] - #[rustc_const_unstable(feature = "cstr_from_bytes_until_nul", issue = "95027")] + #[stable(feature = "cstr_from_bytes_until_nul", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_unstable(feature = "const_cstr_from_bytes_until_nul", issue = "95027")] pub const fn from_bytes_until_nul(bytes: &[u8]) -> Result<&CStr, FromBytesUntilNulError> { let nul_pos = memchr::memchr(0, bytes); match nul_pos { diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 762f7a7c9a1..cd9f74820ae 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -278,7 +278,6 @@ #![feature(char_error_internals)] #![feature(char_internals)] #![feature(core_intrinsics)] -#![feature(cstr_from_bytes_until_nul)] #![feature(cstr_internals)] #![feature(duration_constants)] #![feature(error_generic_member_access)] diff --git a/src/tools/miri/tests/pass-dep/shims/pthreads.rs b/src/tools/miri/tests/pass-dep/shims/pthreads.rs index 09dd92564d3..80b8d67401a 100644 --- a/src/tools/miri/tests/pass-dep/shims/pthreads.rs +++ b/src/tools/miri/tests/pass-dep/shims/pthreads.rs @@ -1,5 +1,4 @@ //@ignore-target-windows: No libc on Windows -#![feature(cstr_from_bytes_until_nul)] use std::ffi::{CStr, CString}; use std::thread; From 877e9f5d3a8282932e1be8ac63fdea584eef804a Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 30 Jan 2023 18:11:03 -0500 Subject: [PATCH 03/11] Change 'from_bytes_until_nul' to const stable --- library/core/src/ffi/c_str.rs | 3 ++- library/core/src/slice/memchr.rs | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index 288bac67f75..82e5fa75ded 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -320,8 +320,9 @@ impl CStr { /// assert_eq!(c_str.to_str().unwrap(), "AAAAAAAA"); /// ``` /// + #[rustc_allow_const_fn_unstable(const_slice_index)] #[stable(feature = "cstr_from_bytes_until_nul", since = "CURRENT_RUSTC_VERSION")] - #[rustc_const_unstable(feature = "const_cstr_from_bytes_until_nul", issue = "95027")] + #[rustc_const_stable(feature = "cstr_from_bytes_until_nul", since = "CURRENT_RUSTC_VERSION")] pub const fn from_bytes_until_nul(bytes: &[u8]) -> Result<&CStr, FromBytesUntilNulError> { let nul_pos = memchr::memchr(0, bytes); match nul_pos { diff --git a/library/core/src/slice/memchr.rs b/library/core/src/slice/memchr.rs index c848c2e18e9..98c8349eb60 100644 --- a/library/core/src/slice/memchr.rs +++ b/library/core/src/slice/memchr.rs @@ -16,25 +16,29 @@ const USIZE_BYTES: usize = mem::size_of::(); /// bytes where the borrow propagated all the way to the most significant /// bit." #[inline] +#[rustc_const_stable(feature = "const_memchr", since = "1.65.0")] const fn contains_zero_byte(x: usize) -> bool { x.wrapping_sub(LO_USIZE) & !x & HI_USIZE != 0 } -#[cfg(target_pointer_width = "16")] #[inline] +#[cfg(target_pointer_width = "16")] +#[rustc_const_stable(feature = "const_memchr", since = "1.65.0")] const fn repeat_byte(b: u8) -> usize { (b as usize) << 8 | b as usize } -#[cfg(not(target_pointer_width = "16"))] #[inline] +#[cfg(not(target_pointer_width = "16"))] +#[rustc_const_stable(feature = "const_memchr", since = "1.65.0")] const fn repeat_byte(b: u8) -> usize { (b as usize) * (usize::MAX / 255) } /// Returns the first index matching the byte `x` in `text`. -#[must_use] #[inline] +#[must_use] +#[rustc_const_stable(feature = "const_memchr", since = "1.65.0")] pub const fn memchr(x: u8, text: &[u8]) -> Option { // Fast path for small slices. if text.len() < 2 * USIZE_BYTES { @@ -45,6 +49,7 @@ pub const fn memchr(x: u8, text: &[u8]) -> Option { } #[inline] +#[rustc_const_stable(feature = "const_memchr", since = "1.65.0")] const fn memchr_naive(x: u8, text: &[u8]) -> Option { let mut i = 0; @@ -60,6 +65,10 @@ const fn memchr_naive(x: u8, text: &[u8]) -> Option { None } +#[rustc_allow_const_fn_unstable(const_cmp)] +#[rustc_allow_const_fn_unstable(const_slice_index)] +#[rustc_allow_const_fn_unstable(const_align_offset)] +#[rustc_const_stable(feature = "const_memchr", since = "1.65.0")] const fn memchr_aligned(x: u8, text: &[u8]) -> Option { // Scan for a single byte value by reading two `usize` words at a time. // From f95b553eb4b6a2a0bf45e48c0cc5e9f635ba1e0c Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 7 Feb 2023 14:24:35 +0000 Subject: [PATCH 04/11] Replace a command line flag with an env var to allow tools to initialize the tracing loggers at their own discretion --- compiler/rustc_driver_impl/src/lib.rs | 16 ++-------------- compiler/rustc_interface/src/tests.rs | 1 - compiler/rustc_log/src/lib.rs | 21 ++++----------------- compiler/rustc_session/src/options.rs | 2 -- tests/rustdoc-ui/z-help.stdout | 1 - tests/ui/attributes/log-backtrace.rs | 4 ++-- 6 files changed, 8 insertions(+), 37 deletions(-) diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 02e0b042ad2..86807098723 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -229,10 +229,6 @@ fn run_compiler( registry: diagnostics_registry(), }; - if !tracing::dispatcher::has_been_set() { - init_rustc_env_logger_with_backtrace_option(&config.opts.unstable_opts.log_backtrace); - } - match make_input(config.opts.error_format, &matches.free) { Err(reported) => return Err(reported), Ok(Some(input)) => { @@ -1253,16 +1249,7 @@ pub fn install_ice_hook() { /// This allows tools to enable rust logging without having to magically match rustc's /// tracing crate version. pub fn init_rustc_env_logger() { - init_rustc_env_logger_with_backtrace_option(&None); -} - -/// This allows tools to enable rust logging without having to magically match rustc's -/// tracing crate version. In contrast to `init_rustc_env_logger` it allows you to -/// choose a target module you wish to show backtraces along with its logging. -pub fn init_rustc_env_logger_with_backtrace_option(backtrace_target: &Option) { - if let Err(error) = rustc_log::init_rustc_env_logger_with_backtrace_option(backtrace_target) { - early_error(ErrorOutputType::default(), &error.to_string()); - } + init_env_logger("RUSTC_LOG"); } /// This allows tools to enable rust logging without having to magically match rustc's @@ -1326,6 +1313,7 @@ mod signal_handler { pub fn main() -> ! { let start_time = Instant::now(); let start_rss = get_resident_set_size(); + init_rustc_env_logger(); signal_handler::install(); let mut callbacks = TimePassesCallbacks::default(); install_ice_hook(); diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 52a4e0e7418..5165ee424e3 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -758,7 +758,6 @@ fn test_unstable_options_tracking_hash() { tracked!(link_only, true); tracked!(llvm_plugins, vec![String::from("plugin_name")]); tracked!(location_detail, LocationDetail { file: true, line: false, column: false }); - tracked!(log_backtrace, Some("filter".to_string())); tracked!(maximal_hir_to_mir_coverage, true); tracked!(merge_functions, Some(MergeFunctions::Disabled)); tracked!(mir_emit_retag, true); diff --git a/compiler/rustc_log/src/lib.rs b/compiler/rustc_log/src/lib.rs index fc1cabd2de9..019fdc30dce 100644 --- a/compiler/rustc_log/src/lib.rs +++ b/compiler/rustc_log/src/lib.rs @@ -54,25 +54,12 @@ use tracing_subscriber::fmt::{ use tracing_subscriber::layer::SubscriberExt; pub fn init_rustc_env_logger() -> Result<(), Error> { - init_rustc_env_logger_with_backtrace_option(&None) -} - -pub fn init_rustc_env_logger_with_backtrace_option( - backtrace_target: &Option, -) -> Result<(), Error> { - init_env_logger_with_backtrace_option("RUSTC_LOG", backtrace_target) + init_env_logger("RUSTC_LOG") } /// In contrast to `init_rustc_env_logger` this allows you to choose an env var /// other than `RUSTC_LOG`. pub fn init_env_logger(env: &str) -> Result<(), Error> { - init_env_logger_with_backtrace_option(env, &None) -} - -pub fn init_env_logger_with_backtrace_option( - env: &str, - backtrace_target: &Option, -) -> Result<(), Error> { let filter = match env::var(env) { Ok(env) => EnvFilter::new(env), _ => EnvFilter::default().add_directive(Directive::from(LevelFilter::WARN)), @@ -106,8 +93,8 @@ pub fn init_env_logger_with_backtrace_option( let layer = layer.with_thread_ids(true).with_thread_names(true); let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer); - match backtrace_target { - Some(str) => { + match env::var(format!("{env}_BACKTRACE")) { + Ok(str) => { let fmt_layer = tracing_subscriber::fmt::layer() .with_writer(io::stderr) .without_time() @@ -115,7 +102,7 @@ pub fn init_env_logger_with_backtrace_option( let subscriber = subscriber.with(fmt_layer); tracing::subscriber::set_global_default(subscriber).unwrap(); } - None => { + Err(_) => { tracing::subscriber::set_global_default(subscriber).unwrap(); } }; diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 0db4d85ff4b..61cb81aec3d 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1413,8 +1413,6 @@ options! { "what location details should be tracked when using caller_location, either \ `none`, or a comma separated list of location details, for which \ valid options are `file`, `line`, and `column` (default: `file,line,column`)"), - log_backtrace: Option = (None, parse_opt_string, [TRACKED], - "add a backtrace along with logging"), ls: bool = (false, parse_bool, [UNTRACKED], "list the symbols defined by a library crate (default: no)"), macro_backtrace: bool = (false, parse_bool, [UNTRACKED], diff --git a/tests/rustdoc-ui/z-help.stdout b/tests/rustdoc-ui/z-help.stdout index 4f07fca82d1..706db892cb3 100644 --- a/tests/rustdoc-ui/z-help.stdout +++ b/tests/rustdoc-ui/z-help.stdout @@ -77,7 +77,6 @@ -Z llvm-plugins=val -- a list LLVM plugins to enable (space separated) -Z llvm-time-trace=val -- generate JSON tracing data file from LLVM data (default: no) -Z location-detail=val -- what location details should be tracked when using caller_location, either `none`, or a comma separated list of location details, for which valid options are `file`, `line`, and `column` (default: `file,line,column`) - -Z log-backtrace=val -- add a backtrace along with logging -Z ls=val -- list the symbols defined by a library crate (default: no) -Z macro-backtrace=val -- show macro backtraces (default: no) -Z maximal-hir-to-mir-coverage=val -- save as much information as possible about the correspondence between MIR and HIR as source scopes (default: no) diff --git a/tests/ui/attributes/log-backtrace.rs b/tests/ui/attributes/log-backtrace.rs index 3979d2001fc..e42edf1d4af 100644 --- a/tests/ui/attributes/log-backtrace.rs +++ b/tests/ui/attributes/log-backtrace.rs @@ -1,9 +1,9 @@ // run-pass // -// This test makes sure that log-backtrace option doesn't give a compilation error. +// This test makes sure that log-backtrace option at least parses correctly // // dont-check-compiler-stdout // dont-check-compiler-stderr // rustc-env:RUSTC_LOG=info -// compile-flags: -Zlog-backtrace=rustc_metadata::creader +// rustc-env:RUSTC_LOG_BACKTRACE=rustc_metadata::creader fn main() {} From 4259073e9a5bedd25f4860ddec2be55d995b4b9d Mon Sep 17 00:00:00 2001 From: Tharun Suresh Date: Wed, 8 Feb 2023 13:37:15 +0530 Subject: [PATCH 05/11] x.py fails all downloads that use a tempdir with snap curl #107722 --- src/bootstrap/bootstrap.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 5b19a658fb5..c298817895c 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -87,14 +87,16 @@ def _download(path, url, probably_big, verbose, exception): # If curl is not present on Win32, we should not sys.exit # but raise `CalledProcessError` or `OSError` instead require(["curl", "--version"], exception=platform_is_win32) - run(["curl", option, - "-L", # Follow redirect. - "-y", "30", "-Y", "10", # timeout if speed is < 10 bytes/sec for > 30 seconds - "--connect-timeout", "30", # timeout if cannot connect within 30 seconds - "--retry", "3", "-Sf", "-o", path, url], - verbose=verbose, - exception=True, # Will raise RuntimeError on failure - ) + with open(path, "wb") as outfile: + run(["curl", option, + "-L", # Follow redirect. + "-y", "30", "-Y", "10", # timeout if speed is < 10 bytes/sec for > 30 seconds + "--connect-timeout", "30", # timeout if cannot connect within 30 seconds + "--retry", "3", "-Sf", url], + stdout=outfile, #Implements cli redirect operator '>' + verbose=verbose, + exception=True, # Will raise RuntimeError on failure + ) except (subprocess.CalledProcessError, OSError, RuntimeError): # see http://serverfault.com/questions/301128/how-to-download if platform_is_win32: From 0017822b708d2dde46fa603592d322951dc7ba0a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 8 Feb 2023 17:56:04 +0000 Subject: [PATCH 06/11] Do not eagerly recover for bad impl-trait in macros --- compiler/rustc_parse/src/parser/ty.rs | 5 +++-- tests/ui/parser/bad-recover-kw-after-impl.rs | 15 +++++++++++++++ tests/ui/parser/bad-recover-ty-after-impl.rs | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 tests/ui/parser/bad-recover-kw-after-impl.rs create mode 100644 tests/ui/parser/bad-recover-ty-after-impl.rs diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index a19ea04fa5e..5b92563fc35 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -694,8 +694,9 @@ impl<'a> Parser<'a> { // `where`, so stop if it's it. // We also continue if we find types (not traits), again for error recovery. while self.can_begin_bound() - || self.token.can_begin_type() - || (self.token.is_reserved_ident() && !self.token.is_keyword(kw::Where)) + || (self.may_recover() + && (self.token.can_begin_type() + || (self.token.is_reserved_ident() && !self.token.is_keyword(kw::Where)))) { if self.token.is_keyword(kw::Dyn) { // Account for `&dyn Trait + dyn Other`. diff --git a/tests/ui/parser/bad-recover-kw-after-impl.rs b/tests/ui/parser/bad-recover-kw-after-impl.rs new file mode 100644 index 00000000000..218cd767859 --- /dev/null +++ b/tests/ui/parser/bad-recover-kw-after-impl.rs @@ -0,0 +1,15 @@ +// check-pass + +// edition:2021 +// for the `impl` + keyword test + +macro_rules! impl_primitive { + ($ty:ty) => { + compile_error!("whoops"); + }; + (impl async) => {}; +} + +impl_primitive!(impl async); + +fn main() {} diff --git a/tests/ui/parser/bad-recover-ty-after-impl.rs b/tests/ui/parser/bad-recover-ty-after-impl.rs new file mode 100644 index 00000000000..510e08ba091 --- /dev/null +++ b/tests/ui/parser/bad-recover-ty-after-impl.rs @@ -0,0 +1,17 @@ +// check-pass + +macro_rules! impl_primitive { + ($ty:ty) => { impl_primitive!(impl $ty); }; + (impl $ty:ty) => { fn a(_: $ty) {} } +} + +impl_primitive! { u8 } + +macro_rules! test { + ($ty:ty) => { compile_error!("oh no"); }; + (impl &) => {}; +} + +test!(impl &); + +fn main() {} From a5164605bc3b572cf2281ce81ad5339fd6249aea Mon Sep 17 00:00:00 2001 From: lcnr Date: Wed, 8 Feb 2023 13:50:27 +0100 Subject: [PATCH 07/11] correctly update goals in the cache --- .../src/solve/search_graph/mod.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_trait_selection/src/solve/search_graph/mod.rs b/compiler/rustc_trait_selection/src/solve/search_graph/mod.rs index 7514c7ee551..a2ca4bc189c 100644 --- a/compiler/rustc_trait_selection/src/solve/search_graph/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/search_graph/mod.rs @@ -7,7 +7,7 @@ use cache::ProvisionalCache; use overflow::OverflowData; use rustc_index::vec::IndexVec; use rustc_middle::ty::TyCtxt; -use std::collections::hash_map::Entry; +use std::{collections::hash_map::Entry, mem}; rustc_index::newtype_index! { pub struct StackDepth {} @@ -134,12 +134,15 @@ impl<'tcx> SearchGraph<'tcx> { let provisional_entry_index = *cache.lookup_table.get(&goal).unwrap(); let provisional_entry = &mut cache.entries[provisional_entry_index]; let depth = provisional_entry.depth; + // We eagerly update the response in the cache here. If we have to reevaluate + // this goal we use the new response when hitting a cycle, and we definitely + // want to access the final response whenever we look at the cache. + let prev_response = mem::replace(&mut provisional_entry.response, response); + // Was the current goal the root of a cycle and was the provisional response // different from the final one. - if has_been_used && provisional_entry.response != response { - // If so, update the provisional reponse for this goal... - provisional_entry.response = response; - // ...remove all entries whose result depends on this goal + if has_been_used && prev_response != response { + // If so, remove all entries whose result depends on this goal // from the provisional cache... // // That's not completely correct, as a nested goal can also From 4c7c5e597f2c7d6d9453a8288d54a211ae0414bb Mon Sep 17 00:00:00 2001 From: lcnr Date: Wed, 8 Feb 2023 14:16:22 +0100 Subject: [PATCH 08/11] add (currently ICEing) test --- .../new-solver/provisional-result-done.rs | 37 +++++++++++++++++++ .../new-solver/provisional-result-done.stderr | 6 +++ 2 files changed, 43 insertions(+) create mode 100644 tests/ui/traits/new-solver/provisional-result-done.rs create mode 100644 tests/ui/traits/new-solver/provisional-result-done.stderr diff --git a/tests/ui/traits/new-solver/provisional-result-done.rs b/tests/ui/traits/new-solver/provisional-result-done.rs new file mode 100644 index 00000000000..a3d97927bad --- /dev/null +++ b/tests/ui/traits/new-solver/provisional-result-done.rs @@ -0,0 +1,37 @@ +// known-bug: unknown +// compile-flags: -Ztrait-solver=next +// failure-status: 101 +// normalize-stderr-test "note: .*\n\n" -> "" +// normalize-stderr-test "thread 'rustc' panicked.*\n" -> "" +// rustc-env:RUST_BACKTRACE=0 + +// This tests checks that we update results in the provisional cache when +// we pop a goal from the stack. +#![feature(auto_traits)] +auto trait Coinductive {} +struct Foo(T); +struct Bar(T); + +impl Coinductive for Foo +where + Bar: Coinductive +{} + +impl Coinductive for Bar +where + Foo: Coinductive, + Bar: ConstrainInfer, +{} + +trait ConstrainInfer {} +impl ConstrainInfer for Bar {} +impl ConstrainInfer for Foo {} + +fn impls() -> T { todo!() } + +fn constrain(_: T) {} + +fn main() { + // This should constrain `_` to `u8`. + impls::>(); +} diff --git a/tests/ui/traits/new-solver/provisional-result-done.stderr b/tests/ui/traits/new-solver/provisional-result-done.stderr new file mode 100644 index 00000000000..ffc92b81f08 --- /dev/null +++ b/tests/ui/traits/new-solver/provisional-result-done.stderr @@ -0,0 +1,6 @@ +error: the compiler unexpectedly panicked. this is a bug. + +query stack during panic: +#0 [check_well_formed] checking that `` is well-formed +#1 [check_mod_type_wf] checking that types are well-formed in top-level module +end of query stack From 8cb5be96c4740e70faa710a7b0d6140c8fbcc4ea Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 8 Feb 2023 14:05:20 -0700 Subject: [PATCH 09/11] rustdoc: use [svgo] to shrink `wheel.svg` [svgo]: https://github.com/svg/svgo $ du -bs src/librustdoc/html/static/images/wheel.svg wheel-old.svg 2972 src/librustdoc/html/static/images/wheel.svg 3764 wheel-old.svg 100*((2972-3764)/3764) = -21.04% --- src/librustdoc/html/static/images/wheel.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/images/wheel.svg b/src/librustdoc/html/static/images/wheel.svg index 01da3b24c7c..83c07f63d10 100644 --- a/src/librustdoc/html/static/images/wheel.svg +++ b/src/librustdoc/html/static/images/wheel.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file From 730470c8dd9b605333f84119e501193d06966528 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Wed, 8 Feb 2023 22:38:20 +0000 Subject: [PATCH 10/11] Set `rust-analyzer.check.invocationLocation` to `root` --- src/bootstrap/setup.rs | 8 +++++--- src/etc/vscode_settings.json | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/setup.rs b/src/bootstrap/setup.rs index c98a5245084..2b613ad50ee 100644 --- a/src/bootstrap/setup.rs +++ b/src/bootstrap/setup.rs @@ -24,10 +24,12 @@ pub enum Profile { } /// A list of historical hashes of `src/etc/vscode_settings.json`. -/// New entries should be appended whenever this is updated so we can detected +/// New entries should be appended whenever this is updated so we can detect /// outdated vs. user-modified settings files. -static SETTINGS_HASHES: &[&str] = - &["ea67e259dedf60d4429b6c349a564ffcd1563cf41c920a856d1f5b16b4701ac8"]; +static SETTINGS_HASHES: &[&str] = &[ + "ea67e259dedf60d4429b6c349a564ffcd1563cf41c920a856d1f5b16b4701ac8", + "56e7bf011c71c5d81e0bf42e84938111847a810eee69d906bba494ea90b51922", +]; static VSCODE_SETTINGS: &str = include_str!("../etc/vscode_settings.json"); impl Profile { diff --git a/src/etc/vscode_settings.json b/src/etc/vscode_settings.json index cd61a38c5da..04c34ce91c0 100644 --- a/src/etc/vscode_settings.json +++ b/src/etc/vscode_settings.json @@ -1,4 +1,6 @@ { + "rust-analyzer.check.invocationLocation": "root", + "rust-analyzer.check.invocationStrategy": "once", "rust-analyzer.checkOnSave.overrideCommand": [ "python3", "x.py", From a70d03b62454f57672e14b48715ae10c01e5fd34 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 6 Feb 2023 12:58:39 +1100 Subject: [PATCH 11/11] Extend `BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE`. To temporarily allow a `str` field in a packed struct using `derive`, along with `[u8]`. --- .../src/deriving/generic/mod.rs | 55 ++++++++++++------- compiler/rustc_lint_defs/src/builtin.rs | 9 +-- tests/ui/derives/deriving-with-repr-packed.rs | 10 ++++ .../derives/deriving-with-repr-packed.stderr | 32 ++++++++++- 4 files changed, 81 insertions(+), 25 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index a8c0aeb7870..970b9115d8d 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -1557,31 +1557,46 @@ impl<'a> TraitDef<'a> { }), ), ); - // In general, fields in packed structs are copied via a - // block, e.g. `&{self.0}`. The one exception is `[u8]` - // fields, which cannot be copied and also never cause - // unaligned references. This exception is allowed to - // handle the `FlexZeroSlice` type in the `zerovec` crate - // within `icu4x-0.9.0`. - // - // Once use of `icu4x-0.9.0` has dropped sufficiently, this - // exception should be removed. - let is_u8_slice = if let TyKind::Slice(ty) = &struct_field.ty.kind && - let TyKind::Path(None, rustc_ast::Path { segments, .. }) = &ty.kind && - let [seg] = segments.as_slice() && - seg.ident.name == sym::u8 && seg.args.is_none() - { - true - } else { - false - }; if is_packed { - if is_u8_slice { + // In general, fields in packed structs are copied via a + // block, e.g. `&{self.0}`. The two exceptions are `[u8]` + // and `str` fields, which cannot be copied and also never + // cause unaligned references. These exceptions are allowed + // to handle the `FlexZeroSlice` type in the `zerovec` + // crate within `icu4x-0.9.0`. + // + // Once use of `icu4x-0.9.0` has dropped sufficiently, this + // exception should be removed. + let is_simple_path = |ty: &P, sym| { + if let TyKind::Path(None, ast::Path { segments, .. }) = &ty.kind && + let [seg] = segments.as_slice() && + seg.ident.name == sym && seg.args.is_none() + { + true + } else { + false + } + }; + + let exception = if let TyKind::Slice(ty) = &struct_field.ty.kind && + is_simple_path(ty, sym::u8) + { + Some("byte") + } else if is_simple_path(&struct_field.ty, sym::str) { + Some("string") + } else { + None + }; + + if let Some(ty) = exception { cx.sess.parse_sess.buffer_lint_with_diagnostic( BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE, sp, ast::CRATE_NODE_ID, - "byte slice in a packed struct that derives a built-in trait", + &format!( + "{} slice in a packed struct that derives a built-in trait", + ty + ), rustc_lint_defs::BuiltinLintDiagnostics::ByteSliceInPackedStructWithDerive ); } else { diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 7e9ba4cd22b..9d8ad9d9ed9 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -4073,7 +4073,8 @@ declare_lint! { declare_lint! { /// The `byte_slice_in_packed_struct_with_derive` lint detects cases where a byte slice field - /// (`[u8]`) is used in a `packed` struct that derives one or more built-in traits. + /// (`[u8]`) or string slice field (`str`) is used in a `packed` struct that derives one or + /// more built-in traits. /// /// ### Example /// @@ -4091,11 +4092,11 @@ declare_lint! { /// ### Explanation /// /// This was previously accepted but is being phased out, because fields in packed structs are - /// now required to implement `Copy` for `derive` to work. Byte slices are a temporary - /// exception because certain crates depended on them. + /// now required to implement `Copy` for `derive` to work. Byte slices and string slices are a + /// temporary exception because certain crates depended on them. pub BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE, Warn, - "`[u8]` slice used in a packed struct with `derive`", + "`[u8]` or `str` used in a packed struct with `derive`", @future_incompatible = FutureIncompatibleInfo { reference: "issue #107457 ", reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow, diff --git a/tests/ui/derives/deriving-with-repr-packed.rs b/tests/ui/derives/deriving-with-repr-packed.rs index afa91da133d..58be4519720 100644 --- a/tests/ui/derives/deriving-with-repr-packed.rs +++ b/tests/ui/derives/deriving-with-repr-packed.rs @@ -33,4 +33,14 @@ struct FlexZeroSlice { //~^^ this was previously accepted } +// Again, currently allowed, but will be phased out. +#[derive(Debug)] +#[repr(packed)] +struct WithStr { + width: u8, + data: str, + //~^ WARNING string slice in a packed struct that derives a built-in trait + //~^^ this was previously accepted +} + fn main() {} diff --git a/tests/ui/derives/deriving-with-repr-packed.stderr b/tests/ui/derives/deriving-with-repr-packed.stderr index 7ed84af91bd..0cfe03869af 100644 --- a/tests/ui/derives/deriving-with-repr-packed.stderr +++ b/tests/ui/derives/deriving-with-repr-packed.stderr @@ -13,6 +13,20 @@ LL | data: [u8], = note: `#[warn(byte_slice_in_packed_struct_with_derive)]` on by default = note: this warning originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +warning: string slice in a packed struct that derives a built-in trait + --> $DIR/deriving-with-repr-packed.rs:41:5 + | +LL | #[derive(Debug)] + | ----- in this derive macro expansion +... +LL | data: str, + | ^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #107457 + = help: consider implementing the trait by hand, or remove the `packed` attribute + = note: this warning originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) + error[E0507]: cannot move out of `self` which is behind a shared reference --> $DIR/deriving-with-repr-packed.rs:22:10 | @@ -24,7 +38,7 @@ LL | struct X(Y); | = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to previous error; 1 warning emitted +error: aborting due to previous error; 2 warnings emitted For more information about this error, try `rustc --explain E0507`. Future incompatibility report: Future breakage diagnostic: @@ -43,3 +57,19 @@ LL | data: [u8], = note: `#[warn(byte_slice_in_packed_struct_with_derive)]` on by default = note: this warning originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +Future breakage diagnostic: +warning: string slice in a packed struct that derives a built-in trait + --> $DIR/deriving-with-repr-packed.rs:41:5 + | +LL | #[derive(Debug)] + | ----- in this derive macro expansion +... +LL | data: str, + | ^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #107457 + = help: consider implementing the trait by hand, or remove the `packed` attribute + = note: `#[warn(byte_slice_in_packed_struct_with_derive)]` on by default + = note: this warning originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +