From 41fe648b5929531f1e122a11f0bd5823dd120803 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Mon, 14 Jun 2021 17:59:53 -0400 Subject: [PATCH 1/9] Cherry-pick release notes for 1.53 --- RELEASES.md | 206 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 204 insertions(+), 2 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 9767ba33eaa65..28b0c5c4586a2 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,205 @@ +Version 1.53.0 (2021-06-17) +============================ + +Language +----------------------- +- [You can now use unicode for identifiers.][83799] This allows multilingual + identifiers but still doesn't allow glyphs that are not considered characters + such as `◆` or `🦀`. More specifically you can now use any identifier that + matches the UAX #31 "Unicode Identifier and Pattern Syntax" standard. This + is the same standard as languages like Python, however Rust uses NFC + normalization which may be different from other languages. +- [You can now specify "or patterns" inside pattern matches.][79278] + Previously you could only use `|` (OR) on complete patterns. E.g. + ```rust + let x = Some(2u8); + // Before + matches!(x, Some(1) | Some(2)); + // Now + matches!(x, Some(1 | 2)); + ``` +- [Added the `:pat_param` `macro_rules!` matcher.][83386] This matcher + has the same semantics as the `:pat` matcher. This is to allow `:pat` + to change semantics to being a pattern fragment in a future edition. + +Compiler +----------------------- +- [Updated the minimum external LLVM version to LLVM 10.][83387] +- [Added Tier 3\* support for the `wasm64-unknown-unknown` target.][80525] +- [Improved debuginfo for closures and async functions on Windows MSVC.][83941] + +\* Refer to Rust's [platform support page][platform-support-doc] for more +information on Rust's tiered platform support. + +Libraries +----------------------- +- [Abort messages will now forward to `android_set_abort_message` on + Android platforms when available.][81469] +- [`slice::IterMut<'_, T>` now implements `AsRef<[T]>`][82771] +- [Arrays of any length now implement `IntoIterator`.][84147] + Currently calling `.into_iter()` as a method on an array will + return `impl Iterator`, but this may change in a + future edition to change `Item` to `T`. Calling `IntoIterator::into_iter` + directly on arrays will provide `impl Iterator` as expected. +- [`leading_zeros`, and `trailing_zeros` are now available on all + `NonZero` integer types.][84082] +- [`{f32, f64}::from_str` now parse and print special values + (`NaN`, `-0`) according to IEEE RFC 754.][78618] +- [You can now index into slices using `(Bound, Bound)`.][77704] +- [Add the `BITS` associated constant to all numeric types.][82565] + +Stabilised APIs +--------------- +- [`AtomicBool::fetch_update`] +- [`AtomicPtr::fetch_update`] +- [`BTreeMap::retain`] +- [`BTreeSet::retain`] +- [`BufReader::seek_relative`] +- [`DebugStruct::non_exhaustive`] +- [`Duration::MAX`] +- [`Duration::ZERO`] +- [`Duration::is_zero`] +- [`Duration::saturating_add`] +- [`Duration::saturating_mul`] +- [`Duration::saturating_sub`] +- [`ErrorKind::Unsupported`] +- [`Option::insert`] +- [`Ordering::is_eq`] +- [`Ordering::is_ge`] +- [`Ordering::is_gt`] +- [`Ordering::is_le`] +- [`Ordering::is_lt`] +- [`Ordering::is_ne`] +- [`OsStr::is_ascii`] +- [`OsStr::make_ascii_lowercase`] +- [`OsStr::make_ascii_uppercase`] +- [`OsStr::to_ascii_lowercase`] +- [`OsStr::to_ascii_uppercase`] +- [`Peekable::peek_mut`] +- [`Rc::decrement_strong_count`] +- [`Rc::increment_strong_count`] +- [`Vec::extend_from_within`] +- [`array::from_mut`] +- [`array::from_ref`] +- [`char::MAX`] +- [`char::REPLACEMENT_CHARACTER`] +- [`char::UNICODE_VERSION`] +- [`char::decode_utf16`] +- [`char::from_digit`] +- [`char::from_u32_unchecked`] +- [`char::from_u32`] +- [`cmp::max_by_key`] +- [`cmp::max_by`] +- [`cmp::min_by_key`] +- [`cmp::min_by`] +- [`f32::is_subnormal`] +- [`f64::is_subnormal`] + +Cargo +----------------------- +- [Cargo now supports git repositories where the default `HEAD` branch is not + "master".][cargo/9392] This also includes a switch to the version 3 `Cargo.lock` format + which can handle default branches correctly. +- [macOS targets now default to `unpacked` split-debuginfo.][cargo/9298] +- [The `authors` field is no longer included in `Cargo.toml` for new + projects.][cargo/9282] + +Rustdoc +----------------------- +- [Added the `rustdoc::bare_urls` lint that warns when you have URLs + without hyperlinks.][81764] + +Compatibility Notes +------------------- +- [Implement token-based handling of attributes during expansion][82608] +- [`Ipv4::from_str` will now reject octal format IP addresses in addition + to rejecting hexadecimal IP addresses.][83652] The octal format can lead + to confusion and potential security vulnerabilities and [is no + longer recommended][ietf6943]. + + +Internal Only +------------- +These changes provide no direct user facing benefits, but represent significant +improvements to the internals and overall performance of rustc and +related tools. + +- [Rework the `std::sys::windows::alloc` implementation.][83065] +- [rustdoc: Don't enter an infer_ctxt in get_blanket_impls for impls that aren't blanket impls.][82864] +- [rustdoc: Only look at blanket impls in `get_blanket_impls`][83681] +- [Rework rustdoc const type][82873] + +[83386]: https://github.com/rust-lang/rust/pull/83386 +[82771]: https://github.com/rust-lang/rust/pull/82771 +[84147]: https://github.com/rust-lang/rust/pull/84147 +[84082]: https://github.com/rust-lang/rust/pull/84082 +[83799]: https://github.com/rust-lang/rust/pull/83799 +[83681]: https://github.com/rust-lang/rust/pull/83681 +[83652]: https://github.com/rust-lang/rust/pull/83652 +[83387]: https://github.com/rust-lang/rust/pull/83387 +[82873]: https://github.com/rust-lang/rust/pull/82873 +[82864]: https://github.com/rust-lang/rust/pull/82864 +[82608]: https://github.com/rust-lang/rust/pull/82608 +[82565]: https://github.com/rust-lang/rust/pull/82565 +[80525]: https://github.com/rust-lang/rust/pull/80525 +[79278]: https://github.com/rust-lang/rust/pull/79278 +[78618]: https://github.com/rust-lang/rust/pull/78618 +[77704]: https://github.com/rust-lang/rust/pull/77704 +[83941]: https://github.com/rust-lang/rust/pull/83941 +[83065]: https://github.com/rust-lang/rust/pull/83065 +[81764]: https://github.com/rust-lang/rust/pull/81764 +[81469]: https://github.com/rust-lang/rust/pull/81469 +[cargo/9298]: https://github.com/rust-lang/cargo/pull/9298 +[cargo/9282]: https://github.com/rust-lang/cargo/pull/9282 +[cargo/9392]: https://github.com/rust-lang/cargo/pull/9392 +[`char::MAX`]: https://doc.rust-lang.org/std/primitive.char.html#associatedconstant.MAX +[`char::REPLACEMENT_CHARACTER`]: https://doc.rust-lang.org/std/primitive.char.html#associatedconstant.REPLACEMENT_CHARACTER +[`char::UNICODE_VERSION`]: https://doc.rust-lang.org/std/primitive.char.html#associatedconstant.UNICODE_VERSION +[`char::decode_utf16`]: https://doc.rust-lang.org/std/primitive.char.html#method.decode_utf16 +[`char::from_u32`]: https://doc.rust-lang.org/std/primitive.char.html#method.from_u32 +[`char::from_u32_unchecked`]: https://doc.rust-lang.org/std/primitive.char.html#method.from_u32_unchecked +[`char::from_digit`]: https://doc.rust-lang.org/std/primitive.char.html#method.from_digit +[`AtomicBool::fetch_update`]: https://doc.rust-lang.org/std/sync/atomic/struct.AtomicBool.html#method.fetch_update +[`AtomicPtr::fetch_update`]: https://doc.rust-lang.org/std/sync/atomic/struct.AtomicPtr.html#method.fetch_update +[`BTreeMap::retain`]: https://doc.rust-lang.org/std/collections/struct.BTreeMap.html#method.retain +[`BTreeSet::retain`]: https://doc.rust-lang.org/std/collections/struct.BTreeSet.html#method.retain +[`BufReader::seek_relative`]: https://doc.rust-lang.org/std/io/struct.BufReader.html#method.seek_relative +[`DebugStruct::non_exhaustive`]: https://doc.rust-lang.org/std/fmt/struct.DebugStruct.html#method.finish_non_exhaustive +[`Duration::MAX`]: https://doc.rust-lang.org/std/time/struct.Duration.html#associatedconstant.MAX +[`Duration::ZERO`]: https://doc.rust-lang.org/std/time/struct.Duration.html#associatedconstant.ZERO +[`Duration::is_zero`]: https://doc.rust-lang.org/std/time/struct.Duration.html#method.is_zero +[`Duration::saturating_add`]: https://doc.rust-lang.org/std/time/struct.Duration.html#method.saturating_add +[`Duration::saturating_mul`]: https://doc.rust-lang.org/std/time/struct.Duration.html#method.saturating_mul +[`Duration::saturating_sub`]: https://doc.rust-lang.org/std/time/struct.Duration.html#method.saturating_sub +[`ErrorKind::Unsupported`]: https://doc.rust-lang.org/std/io/enum.ErrorKind.html#variant.Unsupported +[`Option::insert`]: https://doc.rust-lang.org/std/option/enum.Option.html#method.insert +[`Ordering::is_eq`]: https://doc.rust-lang.org/std/cmp/enum.Ordering.html#method.is_eq +[`Ordering::is_ge`]: https://doc.rust-lang.org/std/cmp/enum.Ordering.html#method.is_ge +[`Ordering::is_gt`]: https://doc.rust-lang.org/std/cmp/enum.Ordering.html#method.is_gt +[`Ordering::is_le`]: https://doc.rust-lang.org/std/cmp/enum.Ordering.html#method.is_le +[`Ordering::is_lt`]: https://doc.rust-lang.org/std/cmp/enum.Ordering.html#method.is_lt +[`Ordering::is_ne`]: https://doc.rust-lang.org/std/cmp/enum.Ordering.html#method.is_ne +[`OsStr::eq_ignore_ascii_case`]: https://doc.rust-lang.org/std/ffi/struct.OsStr.html#method.eq_ignore_ascii_case +[`OsStr::is_ascii`]: https://doc.rust-lang.org/std/ffi/struct.OsStr.html#method.is_ascii +[`OsStr::make_ascii_lowercase`]: https://doc.rust-lang.org/std/ffi/struct.OsStr.html#method.make_ascii_lowercase +[`OsStr::make_ascii_uppercase`]: https://doc.rust-lang.org/std/ffi/struct.OsStr.html#method.make_ascii_uppercase +[`OsStr::to_ascii_lowercase`]: https://doc.rust-lang.org/std/ffi/struct.OsStr.html#method.to_ascii_lowercase +[`OsStr::to_ascii_uppercase`]: https://doc.rust-lang.org/std/ffi/struct.OsStr.html#method.to_ascii_uppercase +[`Peekable::peek_mut`]: https://doc.rust-lang.org/std/iter/struct.Peekable.html#method.peek_mut +[`Rc::decrement_strong_count`]: https://doc.rust-lang.org/std/rc/struct.Rc.html#method.increment_strong_count +[`Rc::increment_strong_count`]: https://doc.rust-lang.org/std/rc/struct.Rc.html#method.increment_strong_count +[`Vec::extend_from_within`]: https://doc.rust-lang.org/beta/std/vec/struct.Vec.html#method.extend_from_within +[`array::from_mut`]: https://doc.rust-lang.org/beta/std/array/fn.from_mut.html +[`array::from_ref`]: https://doc.rust-lang.org/beta/std/array/fn.from_ref.html +[`cmp::max_by_key`]: https://doc.rust-lang.org/beta/std/cmp/fn.max_by_key.html +[`cmp::max_by`]: https://doc.rust-lang.org/beta/std/cmp/fn.max_by.html +[`cmp::min_by_key`]: https://doc.rust-lang.org/beta/std/cmp/fn.min_by_key.html +[`cmp::min_by`]: https://doc.rust-lang.org/beta/std/cmp/fn.min_by.html +[`f32::is_subnormal`]: https://doc.rust-lang.org/std/primitive.f64.html#method.is_subnormal +[`f64::is_subnormal`]: https://doc.rust-lang.org/std/primitive.f64.html#method.is_subnormal +[ietf6943]: https://datatracker.ietf.org/doc/html/rfc6943#section-3.1.1 + + Version 1.52.1 (2021-05-10) ============================ @@ -79,7 +281,7 @@ The following previously stable APIs are now `const`. Rustdoc ------- - [Rustdoc lints are now treated as a tool lint, meaning that - lints are now prefixed with `rustdoc::` (e.g. `#[warn(rustdoc::non_autolinks)]`).][80527] + lints are now prefixed with `rustdoc::` (e.g. `#[warn(rustdoc::broken_intra_doc_links)]`).][80527] Using the old style is still allowed, and will become a warning in a future release. - [Rustdoc now supports argument files.][82261] @@ -174,7 +376,7 @@ Language -------- - [You can now parameterize items such as functions, traits, and `struct`s by constant values in addition to by types and lifetimes.][79135] Also known as "const generics" - E.g. you can now write the following. Note: Only values of primitive integers, + E.g. you can now write the following. Note: Only values of primitive integers, `bool`, or `char` types are currently permitted. ```rust struct GenericArray { From 9dccd968b2de2d1c7547a77d8628fe84d4e8452f Mon Sep 17 00:00:00 2001 From: The8472 Date: Thu, 3 Jun 2021 21:47:59 +0200 Subject: [PATCH 2/9] Revert "implement TrustedRandomAccess for Take iterator adapter" This reverts commit 37a5b515e9c36ee3f57d9e0d7db7efce2fb02195. --- library/core/src/iter/adapters/take.rs | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/library/core/src/iter/adapters/take.rs b/library/core/src/iter/adapters/take.rs index 54a47f1323ebf..9efc7a480aeb4 100644 --- a/library/core/src/iter/adapters/take.rs +++ b/library/core/src/iter/adapters/take.rs @@ -1,8 +1,5 @@ use crate::cmp; -use crate::iter::{ - adapters::zip::try_get_unchecked, adapters::SourceIter, FusedIterator, InPlaceIterable, - TrustedLen, TrustedRandomAccess, -}; +use crate::iter::{adapters::SourceIter, FusedIterator, InPlaceIterable, TrustedLen}; use crate::ops::{ControlFlow, Try}; /// An iterator that only iterates over the first `n` iterations of `iter`. @@ -114,15 +111,6 @@ where self.try_fold(init, ok(fold)).unwrap() } - - unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> ::Item - where - Self: TrustedRandomAccess, - { - // SAFETY: the caller must uphold the contract for - // `Iterator::__iterator_get_unchecked`. - unsafe { try_get_unchecked(&mut self.iter, idx) } - } } #[unstable(issue = "none", feature = "inplace_iteration")] @@ -219,12 +207,3 @@ impl FusedIterator for Take where I: FusedIterator {} #[unstable(feature = "trusted_len", issue = "37572")] unsafe impl TrustedLen for Take {} - -#[doc(hidden)] -#[unstable(feature = "trusted_random_access", issue = "none")] -unsafe impl TrustedRandomAccess for Take -where - I: TrustedRandomAccess, -{ - const MAY_HAVE_SIDE_EFFECT: bool = I::MAY_HAVE_SIDE_EFFECT; -} From 02d3bca8b644988bd654d707b01613f61b5807e4 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Mon, 14 Jun 2021 18:12:45 -0400 Subject: [PATCH 3/9] bump to stable channel --- src/ci/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/run.sh b/src/ci/run.sh index 02d868f8f2a37..a408fa83e5553 100755 --- a/src/ci/run.sh +++ b/src/ci/run.sh @@ -68,7 +68,7 @@ fi # # FIXME: need a scheme for changing this `nightly` value to `beta` and `stable` # either automatically or manually. -export RUST_RELEASE_CHANNEL=beta +export RUST_RELEASE_CHANNEL=stable # Always set the release channel for bootstrap; this is normally not important (i.e., only dist # builds would seem to matter) but in practice bootstrap wants to know whether we're targeting From e96136abc9017558818b14a1d95ffdc08468b9ef Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sat, 8 May 2021 20:30:54 -0400 Subject: [PATCH 4/9] Soft disable incremental This disables incremental (i.e., -Cincremental) taking effect unless an environment variable, RUSTC_FORCE_INCREMENTAL, is set to 1 in the environment of the running rustc. Currently incremental causes errors for many users, and we do not have an expectation of being able to quickly fix these errors in a backportable way - so, for now, disable incremental entirely. The user can still opt-in, but this way the majority of users merely get slower builds, not broken builds. --- compiler/rustc_session/src/config.rs | 7 ++++++- src/doc/rustc/src/codegen-options/index.md | 3 +++ src/tools/compiletest/src/runtest.rs | 16 ++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 1f5cb5b8abc8c..ad2b36691b509 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1865,7 +1865,12 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { check_thread_count(&debugging_opts, error_format); - let incremental = cg.incremental.as_ref().map(PathBuf::from); + let incremental = + if std::env::var_os("RUSTC_FORCE_INCREMENTAL").map(|v| v == "1").unwrap_or(false) { + cg.incremental.as_ref().map(PathBuf::from) + } else { + None + }; if debugging_opts.profile && incremental.is_some() { early_error( diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md index 077c322bd7736..d9083a5c4ada5 100644 --- a/src/doc/rustc/src/codegen-options/index.md +++ b/src/doc/rustc/src/codegen-options/index.md @@ -161,6 +161,9 @@ to save information after compiling a crate to be reused when recompiling the crate, improving re-compile times. This takes a path to a directory where incremental files will be stored. +Note that this option currently does not take effect unless +`RUSTC_FORCE_INCREMENTAL=1` in the environment. + ## inline-threshold This option lets you set the default threshold for inlining a function. It diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index ecbaccf744dcd..8561311c34fcc 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -229,7 +229,15 @@ pub fn run(config: Config, testpaths: &TestPaths, revision: Option<&str>) { print!("\n\n"); } debug!("running {:?}", testpaths.file.display()); - let props = TestProps::from_file(&testpaths.file, revision, &config); + let mut props = TestProps::from_file(&testpaths.file, revision, &config); + + // Currently, incremental is soft disabled unless this environment + // variable is set. A bunch of our tests assume it's enabled, though - so + // just enable it for our tests. + // + // This is deemed preferable to ignoring those tests; we still want to test + // incremental somewhat, as users can opt in to it. + props.rustc_env.push((String::from("RUSTC_FORCE_INCREMENTAL"), String::from("1"))); let cx = TestCx { config: &config, props: &props, testpaths, revision }; create_dir_all(&cx.output_base_dir()).unwrap(); @@ -240,7 +248,11 @@ pub fn run(config: Config, testpaths: &TestPaths, revision: Option<&str>) { assert!(!props.revisions.is_empty(), "Incremental tests require revisions."); cx.init_incremental_test(); for revision in &props.revisions { - let revision_props = TestProps::from_file(&testpaths.file, Some(revision), &config); + let mut revision_props = TestProps::from_file(&testpaths.file, Some(revision), &config); + // See above - need to enable it explicitly for now. + revision_props + .rustc_env + .push((String::from("RUSTC_FORCE_INCREMENTAL"), String::from("1"))); let rev_cx = TestCx { config: &config, props: &revision_props, From 7e4d056874c8a0af9e0b337197d8217db8ef2a3e Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Thu, 6 May 2021 13:44:17 -0400 Subject: [PATCH 5/9] Show nicer error when an 'unstable fingerprints' error occurs --- .../rustc_query_system/src/query/plumbing.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index f7b83812e89fb..c16a8ae4b7365 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -585,13 +585,18 @@ fn incremental_verify_ich( let old_hash = tcx.dep_graph().prev_fingerprint_of(dep_node); - assert_eq!( - Some(new_hash), - old_hash, - "found unstable fingerprints for {:?}: {:?}", - dep_node, - result - ); + if Some(new_hash) != old_hash { + let run_cmd = if let Some(crate_name) = &tcx.sess().opts.crate_name { + format!("`cargo clean -p {}` or `cargo clean`", crate_name) + } else { + "`cargo clean`".to_string() + }; + tcx.sess().struct_err(&format!("internal compiler error: encountered incremental compilation error with {:?}", dep_node)) + .help(&format!("This is a known issue with the compiler. Run {} to allow your project to compile", run_cmd)) + .note(&format!("Please follow the instructions below to create a bug report with the provided information")) + .emit(); + panic!("Found unstable fingerprints for {:?}: {:?}", dep_node, result); + } } fn force_query_with_job( From ff12b110e3a56756f6a62d28f93ab7f11226496d Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sat, 8 May 2021 20:43:23 -0400 Subject: [PATCH 6/9] Add link to issue --- compiler/rustc_query_system/src/query/plumbing.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index c16a8ae4b7365..06a364691d653 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -594,6 +594,7 @@ fn incremental_verify_ich( tcx.sess().struct_err(&format!("internal compiler error: encountered incremental compilation error with {:?}", dep_node)) .help(&format!("This is a known issue with the compiler. Run {} to allow your project to compile", run_cmd)) .note(&format!("Please follow the instructions below to create a bug report with the provided information")) + .note(&format!("See for more information.")) .emit(); panic!("Found unstable fingerprints for {:?}: {:?}", dep_node, result); } From 2c521aed7cf6502f35c448c5531cc007fd32af8b Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Mon, 14 Jun 2021 19:32:32 -0400 Subject: [PATCH 7/9] Pass RUSTC_FORCE_INCREMENTAL to auxiliary tests This won't enable incremental if -Cincremental is not already passed, but is seemingly necessary in the presence of -Zincremental-verify-ich which does not check for incremental being enabled before accessing incremental data structures, leading to an ICE. --- src/tools/compiletest/src/runtest.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 8561311c34fcc..5125acb9b6638 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1784,7 +1784,9 @@ impl<'test> TestCx<'test> { /// Returns whether or not it is a dylib. fn build_auxiliary(&self, source_path: &str, aux_dir: &Path) -> bool { let aux_testpaths = self.compute_aux_test_paths(source_path); - let aux_props = self.props.from_aux_file(&aux_testpaths.file, self.revision, self.config); + let mut aux_props = + self.props.from_aux_file(&aux_testpaths.file, self.revision, self.config); + aux_props.rustc_env.push((String::from("RUSTC_FORCE_INCREMENTAL"), String::from("1"))); let aux_output = TargetLocation::ThisDirectory(self.aux_output_dir_name()); let aux_cx = TestCx { config: self.config, From fce2a229f6889e65d857a18dc905b101f5a5a7e8 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 14 Jun 2021 12:14:30 -0400 Subject: [PATCH 8/9] Revert "Allow specifying alignment for functions" This reverts commit 448d07683a6defd567996114793a09c9a8aef5df to address issue 85713 on beta. --- compiler/rustc_attr/src/builtin.rs | 50 +++++++++++++------ compiler/rustc_codegen_llvm/src/attributes.rs | 3 -- compiler/rustc_feature/src/active.rs | 3 -- .../src/middle/codegen_fn_attrs.rs | 4 -- compiler/rustc_passes/src/check_attr.rs | 46 +++-------------- compiler/rustc_span/src/symbol.rs | 1 - compiler/rustc_typeck/src/collect.rs | 32 ------------ src/test/codegen/align-fn.rs | 9 ---- .../ui/attributes/nonterminal-expansion.rs | 1 + .../attributes/nonterminal-expansion.stderr | 14 +++++- src/test/ui/error-codes/E0565.rs | 5 +- src/test/ui/error-codes/E0565.stderr | 8 ++- .../ui/feature-gates/feature-gate-fn_align.rs | 4 -- .../feature-gate-fn_align.stderr | 12 ----- src/test/ui/issues/issue-43988.rs | 4 +- src/test/ui/issues/issue-43988.stderr | 18 ++++--- src/test/ui/repr/repr-disallow-on-variant.rs | 2 +- .../ui/repr/repr-disallow-on-variant.stderr | 4 +- 18 files changed, 83 insertions(+), 137 deletions(-) delete mode 100644 src/test/codegen/align-fn.rs delete mode 100644 src/test/ui/feature-gates/feature-gate-fn_align.rs delete mode 100644 src/test/ui/feature-gates/feature-gate-fn_align.stderr diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index 20971ebb95748..e58b266fdb9e1 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -862,6 +862,18 @@ pub fn find_repr_attrs(sess: &Session, attr: &Attribute) -> Vec { if let Some(items) = attr.meta_item_list() { sess.mark_attr_used(attr); for item in items { + if !item.is_meta_item() { + handle_errors( + &sess.parse_sess, + item.span(), + AttrError::UnsupportedLiteral( + "meta item in `repr` must be an identifier", + false, + ), + ); + continue; + } + let mut recognised = false; if item.is_word() { let hint = match item.name_or_empty() { @@ -878,6 +890,23 @@ pub fn find_repr_attrs(sess: &Session, attr: &Attribute) -> Vec { acc.push(h); } } else if let Some((name, value)) = item.name_value_literal() { + let parse_alignment = |node: &ast::LitKind| -> Result { + if let ast::LitKind::Int(literal, ast::LitIntType::Unsuffixed) = node { + if literal.is_power_of_two() { + // rustc_middle::ty::layout::Align restricts align to <= 2^29 + if *literal <= 1 << 29 { + Ok(*literal as u32) + } else { + Err("larger than 2^29") + } + } else { + Err("not a power of two") + } + } else { + Err("not an unsuffixed integer") + } + }; + let mut literal_error = None; if name == sym::align { recognised = true; @@ -937,7 +966,13 @@ pub fn find_repr_attrs(sess: &Session, attr: &Attribute) -> Vec { } if !recognised { // Not a word we recognize - diagnostic.delay_span_bug(item.span(), "unrecognized representation hint"); + struct_span_err!( + diagnostic, + item.span(), + E0552, + "unrecognized representation hint" + ) + .emit(); } } } @@ -1045,16 +1080,3 @@ fn allow_unstable<'a>( name }) } - -pub fn parse_alignment(node: &ast::LitKind) -> Result { - if let ast::LitKind::Int(literal, ast::LitIntType::Unsuffixed) = node { - if literal.is_power_of_two() { - // rustc_middle::ty::layout::Align restricts align to <= 2^29 - if *literal <= 1 << 29 { Ok(*literal as u32) } else { Err("larger than 2^29") } - } else { - Err("not a power of two") - } - } else { - Err("not an unsuffixed integer") - } -} diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index 9e5e2b1039efe..ede38b723cbac 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -281,9 +281,6 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty:: if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::CMSE_NONSECURE_ENTRY) { llvm::AddFunctionAttrString(llfn, Function, cstr!("cmse_nonsecure_entry")); } - if let Some(align) = codegen_fn_attrs.alignment { - llvm::set_alignment(llfn, align as usize); - } sanitize(cx, codegen_fn_attrs.no_sanitize, llfn); // Always annotate functions with the target-cpu they are compiled for. diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 4ad5f085ad055..bc9f1039d6f63 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -637,9 +637,6 @@ declare_features! ( /// Allows `extern "C-unwind" fn` to enable unwinding across ABI boundaries. (active, c_unwind, "1.52.0", Some(74990), None), - /// Allows using `#[repr(align(...))]` on function items - (active, fn_align, "1.53.0", Some(82232), None), - /// Allows `extern "wasm" fn` (active, wasm_abi, "1.53.0", Some(83788), None), diff --git a/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs b/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs index 93e7aeaffce37..fc3dafe99e5ec 100644 --- a/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs +++ b/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs @@ -38,9 +38,6 @@ pub struct CodegenFnAttrs { /// be generated against a specific instruction set. Only usable on architectures which allow /// switching between multiple instruction sets. pub instruction_set: Option, - /// The `#[repr(align(...))]` attribute. Indicates the value of which the function should be - /// aligned to. - pub alignment: Option, } bitflags! { @@ -110,7 +107,6 @@ impl CodegenFnAttrs { link_section: None, no_sanitize: SanitizerSet::empty(), instruction_set: None, - alignment: None, } } diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index d57cba6420f7b..3ffe488caef0a 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -1120,41 +1120,17 @@ impl CheckAttrVisitor<'tcx> { let mut is_transparent = false; for hint in &hints { - if !hint.is_meta_item() { - struct_span_err!( - self.tcx.sess, - hint.span(), - E0565, - "meta item in `repr` must be an identifier" - ) - .emit(); - continue; - } - let (article, allowed_targets) = match hint.name_or_empty() { - sym::C => { - is_c = true; + _ if !matches!(target, Target::Struct | Target::Enum | Target::Union) => { + ("a", "struct, enum, or union") + } + name @ sym::C | name @ sym::align => { + is_c |= name == sym::C; match target { Target::Struct | Target::Union | Target::Enum => continue, _ => ("a", "struct, enum, or union"), } } - sym::align => { - if let (Target::Fn, true) = (target, !self.tcx.features().fn_align) { - feature_err( - &self.tcx.sess.parse_sess, - sym::fn_align, - hint.span(), - "`repr(align)` attributes on functions are unstable", - ) - .emit(); - } - - match target { - Target::Struct | Target::Union | Target::Enum | Target::Fn => continue, - _ => ("a", "struct, enum, function, or union"), - } - } sym::packed => { if target != Target::Struct && target != Target::Union { ("a", "struct or union") @@ -1211,17 +1187,7 @@ impl CheckAttrVisitor<'tcx> { continue; } } - _ => { - struct_span_err!( - self.tcx.sess, - hint.span(), - E0552, - "unrecognized representation hint" - ) - .emit(); - - continue; - } + _ => continue, }; struct_span_err!( diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index b2dac10c83fac..c4007f74bd3c3 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -563,7 +563,6 @@ symbols! { fmt, fmt_internals, fmul_fast, - fn_align, fn_must_use, fn_mut, fn_once, diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 0528f8812f920..d073262cad536 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -15,8 +15,6 @@ //! At present, however, we do run collection across all items in the //! crate as a kind of pass. This should eventually be factored away. -// ignore-tidy-filelength - use crate::astconv::{AstConv, SizedByDefault}; use crate::bounds::Bounds; use crate::check::intrinsic::intrinsic_operation_unsafety; @@ -2903,36 +2901,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs { None } }; - } else if tcx.sess.check_name(attr, sym::repr) { - codegen_fn_attrs.alignment = match attr.meta_item_list() { - Some(items) => match items.as_slice() { - [item] => match item.name_value_literal() { - Some((sym::align, literal)) => { - let alignment = rustc_attr::parse_alignment(&literal.kind); - - match alignment { - Ok(align) => Some(align), - Err(msg) => { - struct_span_err!( - tcx.sess.diagnostic(), - attr.span, - E0589, - "invalid `repr(align)` attribute: {}", - msg - ) - .emit(); - - None - } - } - } - _ => None, - }, - [] => None, - _ => None, - }, - None => None, - }; } } diff --git a/src/test/codegen/align-fn.rs b/src/test/codegen/align-fn.rs deleted file mode 100644 index c5886cf28081a..0000000000000 --- a/src/test/codegen/align-fn.rs +++ /dev/null @@ -1,9 +0,0 @@ -// compile-flags: -C no-prepopulate-passes -Z mir-opt-level=0 - -#![crate_type = "lib"] -#![feature(fn_align)] - -// CHECK: align 16 -#[no_mangle] -#[repr(align(16))] -pub fn fn_align() {} diff --git a/src/test/ui/attributes/nonterminal-expansion.rs b/src/test/ui/attributes/nonterminal-expansion.rs index d663431d6836f..b4f523936a0b0 100644 --- a/src/test/ui/attributes/nonterminal-expansion.rs +++ b/src/test/ui/attributes/nonterminal-expansion.rs @@ -3,6 +3,7 @@ macro_rules! pass_nonterminal { ($n:expr) => { #[repr(align($n))] //~ ERROR expected unsuffixed literal or identifier, found `n!()` + //~| ERROR unrecognized representation hint struct S; }; } diff --git a/src/test/ui/attributes/nonterminal-expansion.stderr b/src/test/ui/attributes/nonterminal-expansion.stderr index 75663a666a56d..9f7f185f94752 100644 --- a/src/test/ui/attributes/nonterminal-expansion.stderr +++ b/src/test/ui/attributes/nonterminal-expansion.stderr @@ -9,5 +9,17 @@ LL | pass_nonterminal!(n!()); | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to previous error +error[E0552]: unrecognized representation hint + --> $DIR/nonterminal-expansion.rs:5:16 + | +LL | #[repr(align($n))] + | ^^^^^^^^^ +... +LL | pass_nonterminal!(n!()); + | ------------------------ in this macro invocation + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0552`. diff --git a/src/test/ui/error-codes/E0565.rs b/src/test/ui/error-codes/E0565.rs index df76f6b13af9b..3bf428676105d 100644 --- a/src/test/ui/error-codes/E0565.rs +++ b/src/test/ui/error-codes/E0565.rs @@ -1,5 +1,6 @@ // repr currently doesn't support literals #[repr("C")] //~ ERROR E0565 -struct A {} + //~| ERROR E0565 +struct A { } -fn main() {} +fn main() { } diff --git a/src/test/ui/error-codes/E0565.stderr b/src/test/ui/error-codes/E0565.stderr index 6ed90c0ae4ffe..aa0951528e1ed 100644 --- a/src/test/ui/error-codes/E0565.stderr +++ b/src/test/ui/error-codes/E0565.stderr @@ -4,6 +4,12 @@ error[E0565]: meta item in `repr` must be an identifier LL | #[repr("C")] | ^^^ -error: aborting due to previous error +error[E0565]: meta item in `repr` must be an identifier + --> $DIR/E0565.rs:2:8 + | +LL | #[repr("C")] + | ^^^ + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0565`. diff --git a/src/test/ui/feature-gates/feature-gate-fn_align.rs b/src/test/ui/feature-gates/feature-gate-fn_align.rs deleted file mode 100644 index ea873dba269c4..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-fn_align.rs +++ /dev/null @@ -1,4 +0,0 @@ -#![crate_type = "lib"] - -#[repr(align(16))] //~ ERROR `repr(align)` attributes on functions are unstable -fn requires_alignment() {} diff --git a/src/test/ui/feature-gates/feature-gate-fn_align.stderr b/src/test/ui/feature-gates/feature-gate-fn_align.stderr deleted file mode 100644 index 5ff124e48dca9..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-fn_align.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0658]: `repr(align)` attributes on functions are unstable - --> $DIR/feature-gate-fn_align.rs:3:8 - | -LL | #[repr(align(16))] - | ^^^^^^^^^ - | - = note: see issue #82232 for more information - = help: add `#![feature(fn_align)]` to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/issues/issue-43988.rs b/src/test/ui/issues/issue-43988.rs index b114e8e03333d..4b3a0269baea2 100644 --- a/src/test/ui/issues/issue-43988.rs +++ b/src/test/ui/issues/issue-43988.rs @@ -13,13 +13,13 @@ fn main() { #[repr(nothing)] let _x = 0; - //~^^ ERROR E0552 + //~^^ ERROR attribute should be applied to a struct, enum, or union #[repr(something_not_real)] loop { () }; - //~^^^^ ERROR E0552 + //~^^^^ ERROR attribute should be applied to a struct, enum, or union #[repr] let _y = "123"; diff --git a/src/test/ui/issues/issue-43988.stderr b/src/test/ui/issues/issue-43988.stderr index 03aa37f52075f..f1205d447e4ba 100644 --- a/src/test/ui/issues/issue-43988.stderr +++ b/src/test/ui/issues/issue-43988.stderr @@ -26,17 +26,23 @@ LL | #[inline(XYZ)] LL | let _b = 4; | ----------- not a function or closure -error[E0552]: unrecognized representation hint +error[E0517]: attribute should be applied to a struct, enum, or union --> $DIR/issue-43988.rs:14:12 | LL | #[repr(nothing)] | ^^^^^^^ +LL | let _x = 0; + | ----------- not a struct, enum, or union -error[E0552]: unrecognized representation hint +error[E0517]: attribute should be applied to a struct, enum, or union --> $DIR/issue-43988.rs:18:12 | -LL | #[repr(something_not_real)] - | ^^^^^^^^^^^^^^^^^^ +LL | #[repr(something_not_real)] + | ^^^^^^^^^^^^^^^^^^ +LL | / loop { +LL | | () +LL | | }; + | |_____- not a struct, enum, or union error[E0518]: attribute should be applied to function or closure --> $DIR/issue-43988.rs:30:5 @@ -48,5 +54,5 @@ LL | foo(); error: aborting due to 7 previous errors -Some errors have detailed explanations: E0518, E0552. -For more information about an error, try `rustc --explain E0518`. +Some errors have detailed explanations: E0517, E0518. +For more information about an error, try `rustc --explain E0517`. diff --git a/src/test/ui/repr/repr-disallow-on-variant.rs b/src/test/ui/repr/repr-disallow-on-variant.rs index d9bd0b0e38a69..90cad7e647b05 100644 --- a/src/test/ui/repr/repr-disallow-on-variant.rs +++ b/src/test/ui/repr/repr-disallow-on-variant.rs @@ -2,7 +2,7 @@ struct Test; enum Foo { #[repr(u8)] - //~^ ERROR attribute should be applied to an enum + //~^ ERROR attribute should be applied to a struct, enum, or union Variant, } diff --git a/src/test/ui/repr/repr-disallow-on-variant.stderr b/src/test/ui/repr/repr-disallow-on-variant.stderr index f7e4dcc9d81be..70b45e393fcf1 100644 --- a/src/test/ui/repr/repr-disallow-on-variant.stderr +++ b/src/test/ui/repr/repr-disallow-on-variant.stderr @@ -1,11 +1,11 @@ -error[E0517]: attribute should be applied to an enum +error[E0517]: attribute should be applied to a struct, enum, or union --> $DIR/repr-disallow-on-variant.rs:4:12 | LL | #[repr(u8)] | ^^ LL | LL | Variant, - | ------- not an enum + | ------- not a struct, enum, or union error: aborting due to previous error From 196e18555ba1206bafa8d15cffaf7bddd7846a09 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 14 Jun 2021 13:18:02 -0400 Subject: [PATCH 9/9] regression test for issue 85713. --- src/test/ui/issue-85713-align-with-no-arg.rs | 6 ++++++ src/test/ui/issue-85713-align-with-no-arg.stderr | 15 +++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/test/ui/issue-85713-align-with-no-arg.rs create mode 100644 src/test/ui/issue-85713-align-with-no-arg.stderr diff --git a/src/test/ui/issue-85713-align-with-no-arg.rs b/src/test/ui/issue-85713-align-with-no-arg.rs new file mode 100644 index 0000000000000..1afb8e7cb5bf5 --- /dev/null +++ b/src/test/ui/issue-85713-align-with-no-arg.rs @@ -0,0 +1,6 @@ +#[repr(align)] +//~^ ERROR unrecognized representation hint +//~| ERROR unrecognized representation hint +pub struct Foo; + +pub fn main() { } diff --git a/src/test/ui/issue-85713-align-with-no-arg.stderr b/src/test/ui/issue-85713-align-with-no-arg.stderr new file mode 100644 index 0000000000000..99b22ec698ff7 --- /dev/null +++ b/src/test/ui/issue-85713-align-with-no-arg.stderr @@ -0,0 +1,15 @@ +error[E0552]: unrecognized representation hint + --> $DIR/issue-85713-align-with-no-arg.rs:1:8 + | +LL | #[repr(align)] + | ^^^^^ + +error[E0552]: unrecognized representation hint + --> $DIR/issue-85713-align-with-no-arg.rs:1:8 + | +LL | #[repr(align)] + | ^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0552`.