From f01b35ed4649c4f868995563f81e6e0f383df808 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Tue, 4 May 2021 16:22:40 +0200 Subject: [PATCH 01/52] this is beta 1.53.0 --- src/ci/run.sh | 2 +- src/stage0.txt | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ci/run.sh b/src/ci/run.sh index 1958b6ee41d7f..02d868f8f2a37 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=nightly +export RUST_RELEASE_CHANNEL=beta # 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 diff --git a/src/stage0.txt b/src/stage0.txt index 6ad0f6db42b9f..3a76177474908 100644 --- a/src/stage0.txt +++ b/src/stage0.txt @@ -12,14 +12,14 @@ # stable release's version number. `date` is the date where the release we're # bootstrapping off was released. -date: 2021-04-07 -rustc: beta +date: 2021-05-04 +rustc: 1.52.0 # We use a nightly rustfmt to format the source because it solves some # bootstrapping issues with use of new syntax in this repo. If you're looking at # the beta/stable branch, this key should be omitted, as we don't want to depend # on rustfmt from nightly there. -rustfmt: nightly-2021-03-25 +#rustfmt: nightly-2021-03-25 # When making a stable release the process currently looks like: # @@ -39,4 +39,4 @@ rustfmt: nightly-2021-03-25 # looking at a beta source tarball and it's uncommented we'll shortly comment it # out. -#dev: 1 +dev: 1 From 0ffdf882a30c280db37ff4e5cff58fdd86f6a0e3 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Tue, 6 Oct 2020 22:36:12 -0400 Subject: [PATCH 02/52] Update fulldeps test --- .../ui-fulldeps/session-derive-errors.stderr | 47 +++++++------------ 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/src/test/ui-fulldeps/session-derive-errors.stderr b/src/test/ui-fulldeps/session-derive-errors.stderr index c1be151f1c1ce..303268fae27a1 100644 --- a/src/test/ui-fulldeps/session-derive-errors.stderr +++ b/src/test/ui-fulldeps/session-derive-errors.stderr @@ -1,25 +1,20 @@ error: `#[derive(SessionDiagnostic)]` can only be used on structs --> $DIR/session-derive-errors.rs:28:1 | -LL | / #[error = "E0123"] -LL | | -LL | | enum SessionDiagnosticOnEnum { -LL | | Foo, -LL | | Bar, -LL | | } - | |_^ +LL | #[error = "E0123"] + | ^ error: `#[label = ...]` is not a valid SessionDiagnostic struct attribute --> $DIR/session-derive-errors.rs:37:1 | LL | #[label = "This is in the wrong place"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ error: `#[suggestion = ...]` is not a valid SessionDiagnostic field attribute --> $DIR/session-derive-errors.rs:44:5 | LL | #[suggestion = "this is the wrong kind of attribute"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ error: `error` specified multiple times --> $DIR/session-derive-errors.rs:52:11 @@ -37,7 +32,7 @@ error: `code` not specified --> $DIR/session-derive-errors.rs:67:1 | LL | struct ErrorCodeNotProvided {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^ | = help: use the [code = "..."] attribute to set this diagnostic's error code @@ -45,13 +40,13 @@ error: the `#[message = "..."]` attribute can only be applied to fields of type --> $DIR/session-derive-errors.rs:95:5 | LL | #[message = "this message is applied to a String field"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ error: `name` doesn't refer to a field on this type --> $DIR/session-derive-errors.rs:102:1 | LL | #[message = "This error has a field, and references {name}"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ error: invalid format string: expected `'}'` but string was terminated --> $DIR/session-derive-errors.rs:110:1 @@ -77,59 +72,53 @@ error: The `#[label = ...]` attribute can only be applied to fields of type Span --> $DIR/session-derive-errors.rs:138:5 | LL | #[label = "See here"] - | ^^^^^^^^^^^^^^^^^^^^^ + | ^ error: `nonsense` is not a valid key for `#[suggestion(...)]` --> $DIR/session-derive-errors.rs:163:18 | LL | #[suggestion(nonsense = "This is nonsense")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^ error: `msg` is not a valid key for `#[suggestion(...)]` --> $DIR/session-derive-errors.rs:171:18 | LL | #[suggestion(msg = "This is a suggestion")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error: missing suggestion message --> $DIR/session-derive-errors.rs:179:7 | LL | #[suggestion(code = "This is suggested code")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^ | = help: provide a suggestion message using #[suggestion(message = "...")] error: wrong field type for suggestion --> $DIR/session-derive-errors.rs:194:5 | -LL | / #[suggestion(message = "This is a message", code = "This is suggested code")] -LL | | -LL | | suggestion: Applicability, - | |_____________________________^ +LL | #[suggestion(message = "This is a message", code = "This is suggested code")] + | ^ | = help: #[suggestion(...)] should be applied to fields of type Span or (Span, Applicability) error: type of field annotated with `#[suggestion(...)]` contains more than one Span --> $DIR/session-derive-errors.rs:209:5 | -LL | / #[suggestion(message = "This is a message", code = "This is suggested code")] -LL | | -LL | | suggestion: (Span, Span, Applicability), - | |___________________________________________^ +LL | #[suggestion(message = "This is a message", code = "This is suggested code")] + | ^ error: type of field annotated with `#[suggestion(...)]` contains more than one Applicability --> $DIR/session-derive-errors.rs:217:5 | -LL | / #[suggestion(message = "This is a message", code = "This is suggested code")] -LL | | -LL | | suggestion: (Applicability, Applicability, Span), - | |____________________________________________________^ +LL | #[suggestion(message = "This is a message", code = "This is suggested code")] + | ^ error: invalid annotation list `#[label(...)]` --> $DIR/session-derive-errors.rs:225:7 | LL | #[label("wrong kind of annotation for label")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^ error: aborting due to 18 previous errors From b14eaf4bb1debaec74f4c6272192133669b0694f Mon Sep 17 00:00:00 2001 From: Erin Power Date: Wed, 14 Apr 2021 11:34:20 +0200 Subject: [PATCH 03/52] Update RELEASES.md for 1.52.0 --- RELEASES.md | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index 024610bc7a417..1f940e6bc2d3b 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,151 @@ +Version 1.52.0 (2021-05-06) +============================ + +Language +-------- +- [Added the `unsafe_op_in_unsafe_fn` lint, which checks whether the unsafe code + in an `unsafe fn` is wrapped in a `unsafe` block.][79208] This lint + is allowed by default, and may become a warning or hard error in a + future edition. +- [You can now cast mutable references to arrays to a pointer of the same type as + the element.][81479] + +Compiler +-------- +- [Upgraded the default LLVM to LLVM 12.][81451] + +Added tier 3\* support for the following targets. + +- [`s390x-unknown-linux-musl`][82166] +- [`riscv32gc-unknown-linux-musl` & `riscv64gc-unknown-linux-musl`][82202] +- [`powerpc-unknown-openbsd`][82733] + +\* Refer to Rust's [platform support page][platform-support-doc] for more +information on Rust's tiered platform support. + +Libraries +--------- +- [`OsString` now implements `Extend` and `FromIterator`.][82121] +- [`cmp::Reverse` now has `#[repr(transparent)]` representation.][81879] +- [`Arc` now implements `error::Error`.][80553] +- [All integer division and remainder operations are now `const`.][80962] + +Stabilised APIs +------------- +- [`Arguments::as_str`] +- [`char::MAX`] +- [`char::REPLACEMENT_CHARACTER`] +- [`char::UNICODE_VERSION`] +- [`char::decode_utf16`] +- [`char::from_digit`] +- [`char::from_u32_unchecked`] +- [`char::from_u32`] +- [`slice::partition_point`] +- [`str::rsplit_once`] +- [`str::split_once`] + +The following previously stable APIs are now `const`. + +- [`char::len_utf8`] +- [`char::len_utf16`] +- [`char::to_ascii_uppercase`] +- [`char::to_ascii_lowercase`] +- [`char::eq_ignore_ascii_case`] +- [`u8::to_ascii_uppercase`] +- [`u8::to_ascii_lowercase`] +- [`u8::eq_ignore_ascii_case`] + +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] + Using the old style is still allowed, and will become a warning in + a future release. +- [Rustdoc now supports argument files.][82261] +- [Rustdoc now generates smart punctuation for documentation.][79423] +- [You can now use "task lists" in Rustdoc Markdown.][81766] E.g. + ```markdown + - [x] Complete + - [ ] Todo + ``` + +Misc +---- +- [You can now pass multiple filters to tests.][81356] E.g. + `cargo test -- foo bar` will run all tests that match `foo` and `bar`. +- [Rustup now distributes PDB symbols for the `std` library on Windows, + allowing you to see `std` symbols when debugging.][82218] + +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. + +- [Check the result cache before the DepGraph when ensuring queries][81855] +- [Try fast_reject::simplify_type in coherence before doing full check][81744] +- [Only store a LocalDefId in some HIR nodes][81611] +- [Store HIR attributes in a side table][79519] + +Compatibility Notes +------------------- +- [Cargo build scripts are now forbidden from setting `RUSTC_BOOTSTRAP`.][cargo/9181] +- [Removed support for the `x86_64-rumprun-netbsd` target.][82594] +- [Deprecated the `x86_64-sun-solaris` target in favor of `x86_64-pc-solaris`.][82216] +- [Rustdoc now only accepts `,`, ` `, and `\t` as delimiters for specifying + languages in code blocks.][78429] +- [Rustc now catches more cases of `pub_use_of_private_extern_crate`][80763] +- [Changes in how proc macros handle whitespace may lead to panics when used + with older `proc-macro-hack` versions. A `cargo update` should be sufficient to fix this in all cases.][84136] + +[84136]: https://github.com/rust-lang/rust/issues/84136 +[80763]: https://github.com/rust-lang/rust/pull/80763 +[82166]: https://github.com/rust-lang/rust/pull/82166 +[82121]: https://github.com/rust-lang/rust/pull/82121 +[81879]: https://github.com/rust-lang/rust/pull/81879 +[82261]: https://github.com/rust-lang/rust/pull/82261 +[82218]: https://github.com/rust-lang/rust/pull/82218 +[82216]: https://github.com/rust-lang/rust/pull/82216 +[82202]: https://github.com/rust-lang/rust/pull/82202 +[81855]: https://github.com/rust-lang/rust/pull/81855 +[81766]: https://github.com/rust-lang/rust/pull/81766 +[81744]: https://github.com/rust-lang/rust/pull/81744 +[81611]: https://github.com/rust-lang/rust/pull/81611 +[81479]: https://github.com/rust-lang/rust/pull/81479 +[81451]: https://github.com/rust-lang/rust/pull/81451 +[81356]: https://github.com/rust-lang/rust/pull/81356 +[80962]: https://github.com/rust-lang/rust/pull/80962 +[80553]: https://github.com/rust-lang/rust/pull/80553 +[80527]: https://github.com/rust-lang/rust/pull/80527 +[79519]: https://github.com/rust-lang/rust/pull/79519 +[79423]: https://github.com/rust-lang/rust/pull/79423 +[79208]: https://github.com/rust-lang/rust/pull/79208 +[78429]: https://github.com/rust-lang/rust/pull/78429 +[82733]: https://github.com/rust-lang/rust/pull/82733 +[82594]: https://github.com/rust-lang/rust/pull/82594 +[cargo/9181]: https://github.com/rust-lang/cargo/pull/9181 +[`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 +[`Peekable::next_if`]: https://doc.rust-lang.org/stable/std/iter/struct.Peekable.html#method.next_if +[`Peekable::next_if_eq`]: https://doc.rust-lang.org/stable/std/iter/struct.Peekable.html#method.next_if_eq +[`Arguments::as_str`]: https://doc.rust-lang.org/stable/std/fmt/struct.Arguments.html#method.as_str +[`str::split_once`]: https://doc.rust-lang.org/stable/std/primitive.str.html#method.split_once +[`str::rsplit_once`]: https://doc.rust-lang.org/stable/std/primitive.str.html#method.rsplit_once +[`slice::partition_point`]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.partition_point +[`char::len_utf8`]: https://doc.rust-lang.org/stable/std/primitive.char.html#method.len_utf8 +[`char::len_utf16`]: https://doc.rust-lang.org/stable/std/primitive.char.html#method.len_utf16 +[`char::to_ascii_uppercase`]: https://doc.rust-lang.org/stable/std/primitive.char.html#method.to_ascii_uppercase +[`char::to_ascii_lowercase`]: https://doc.rust-lang.org/stable/std/primitive.char.html#method.to_ascii_lowercase +[`char::eq_ignore_ascii_case`]: https://doc.rust-lang.org/stable/std/primitive.char.html#method.eq_ignore_ascii_case +[`u8::to_ascii_uppercase`]: https://doc.rust-lang.org/stable/std/primitive.u8.html#method.to_ascii_uppercase +[`u8::to_ascii_lowercase`]: https://doc.rust-lang.org/stable/std/primitive.u8.html#method.to_ascii_lowercase +[`u8::eq_ignore_ascii_case`]: https://doc.rust-lang.org/stable/std/primitive.u8.html#method.eq_ignore_ascii_case + Version 1.51.0 (2021-03-25) ============================ From 725a85a88a64e8b04a697cf589d1af904d17199d Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 3 May 2021 09:21:52 -0400 Subject: [PATCH 04/52] manually crafted revert of PR #80653, to address issue #82465. (update: placated tidy) --- src/librustdoc/html/render/context.rs | 9 +- src/librustdoc/html/render/mod.rs | 26 ++--- src/librustdoc/passes/collect_trait_impls.rs | 102 +++++++------------ src/test/rustdoc-ui/deref-recursive-cycle.rs | 17 ---- src/test/rustdoc/deref-recursive-pathbuf.rs | 24 ----- src/test/rustdoc/deref-recursive.rs | 40 -------- src/test/rustdoc/deref-typedef.rs | 4 +- 7 files changed, 46 insertions(+), 176 deletions(-) delete mode 100644 src/test/rustdoc-ui/deref-recursive-cycle.rs delete mode 100644 src/test/rustdoc/deref-recursive-pathbuf.rs delete mode 100644 src/test/rustdoc/deref-recursive.rs diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 4c8ba0e7b496e..7cb7e070f7041 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -6,7 +6,7 @@ use std::rc::Rc; use std::sync::mpsc::{channel, Receiver}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_hir::def_id::{DefId, LOCAL_CRATE}; +use rustc_hir::def_id::LOCAL_CRATE; use rustc_middle::ty::TyCtxt; use rustc_session::Session; use rustc_span::edition::Edition; @@ -50,9 +50,6 @@ crate struct Context<'tcx> { pub(super) render_redirect_pages: bool, /// The map used to ensure all generated 'id=' attributes are unique. pub(super) id_map: RefCell, - /// Tracks section IDs for `Deref` targets so they match in both the main - /// body and the sidebar. - pub(super) deref_id_map: RefCell>, /// Shared mutable state. /// /// Issue for improving the situation: [#82381][] @@ -73,7 +70,7 @@ crate struct Context<'tcx> { // `Context` is cloned a lot, so we don't want the size to grow unexpectedly. #[cfg(target_arch = "x86_64")] -rustc_data_structures::static_assert_size!(Context<'_>, 152); +rustc_data_structures::static_assert_size!(Context<'_>, 112); /// Shared mutable state used in [`Context`] and elsewhere. crate struct SharedContext<'tcx> { @@ -470,7 +467,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { dst, render_redirect_pages: false, id_map: RefCell::new(id_map), - deref_id_map: RefCell::new(FxHashMap::default()), shared: Rc::new(scx), cache: Rc::new(cache), }; @@ -488,7 +484,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { dst: self.dst.clone(), render_redirect_pages: self.render_redirect_pages, id_map: RefCell::new(IdMap::new()), - deref_id_map: RefCell::new(FxHashMap::default()), shared: Rc::clone(&self.shared), cache: Rc::clone(&self.cache), } diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 7de72d8198725..15ce3740e05d4 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1034,17 +1034,12 @@ fn render_assoc_items( RenderMode::Normal } AssocItemRender::DerefFor { trait_, type_, deref_mut_ } => { - let id = - cx.derive_id(small_url_encode(format!("deref-methods-{:#}", type_.print(cx)))); - debug!("Adding {} to deref id map", type_.print(cx)); - cx.deref_id_map.borrow_mut().insert(type_.def_id_full(cache).unwrap(), id.clone()); write!( w, - "

\ + "

\ Methods from {trait_}<Target = {type_}>\ - \ + \

", - id = id, trait_ = trait_.print(cx), type_ = type_.print(cx), ); @@ -1069,6 +1064,9 @@ fn render_assoc_items( ); } } + if let AssocItemRender::DerefFor { .. } = what { + return; + } if !traits.is_empty() { let deref_impl = traits .iter() @@ -1079,13 +1077,6 @@ fn render_assoc_items( .any(|t| t.inner_impl().trait_.def_id_full(cache) == cx.cache.deref_mut_trait_did); render_deref_methods(w, cx, impl_, containing_item, has_deref_mut); } - - // If we were already one level into rendering deref methods, we don't want to render - // anything after recursing into any further deref methods above. - if let AssocItemRender::DerefFor { .. } = what { - return; - } - let (synthetic, concrete): (Vec<&&Impl>, Vec<&&Impl>) = traits.iter().partition(|t| t.inner_impl().synthetic); let (blanket_impl, concrete): (Vec<&&Impl>, _) = @@ -1967,14 +1958,9 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V .flat_map(|i| get_methods(i.inner_impl(), true, &mut used_links, deref_mut, c)) .collect::>(); if !ret.is_empty() { - let deref_id_map = cx.deref_id_map.borrow(); - let id = deref_id_map - .get(&real_target.def_id_full(c).unwrap()) - .expect("Deref section without derived id"); write!( out, - "Methods from {}<Target={}>", - id, + "Methods from {}<Target={}>", Escape(&format!("{:#}", impl_.inner_impl().trait_.as_ref().unwrap().print(cx))), Escape(&format!("{:#}", real_target.print(cx))), ); diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs index 7b0b2f28fdfff..12f16c9359235 100644 --- a/src/librustdoc/passes/collect_trait_impls.rs +++ b/src/librustdoc/passes/collect_trait_impls.rs @@ -3,7 +3,7 @@ use crate::clean::*; use crate::core::DocContext; use crate::fold::DocFolder; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::FxHashSet; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_middle::ty::DefIdTree; use rustc_span::symbol::sym; @@ -53,6 +53,39 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate { } } + let mut cleaner = BadImplStripper { prims, items: crate_items }; + + // scan through included items ahead of time to splice in Deref targets to the "valid" sets + for it in &new_items { + if let ImplItem(Impl { ref for_, ref trait_, ref items, .. }) = *it.kind { + if cleaner.keep_impl(for_) && trait_.def_id() == cx.tcx.lang_items().deref_trait() { + let target = items + .iter() + .find_map(|item| match *item.kind { + TypedefItem(ref t, true) => Some(&t.type_), + _ => None, + }) + .expect("Deref impl without Target type"); + + if let Some(prim) = target.primitive_type() { + cleaner.prims.insert(prim); + } else if let Some(did) = target.def_id() { + cleaner.items.insert(did); + } + } + } + } + + new_items.retain(|it| { + if let ImplItem(Impl { ref for_, ref trait_, ref blanket_impl, .. }) = *it.kind { + cleaner.keep_impl(for_) + || trait_.as_ref().map_or(false, |t| cleaner.keep_impl(t)) + || blanket_impl.is_some() + } else { + true + } + }); + // `tcx.crates()` doesn't include the local crate, and `tcx.all_trait_implementations` // doesn't work with it anyway, so pull them from the HIR map instead let mut extra_attrs = Vec::new(); @@ -84,53 +117,6 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate { } } - let mut cleaner = BadImplStripper { prims, items: crate_items }; - - let mut type_did_to_deref_target: FxHashMap = FxHashMap::default(); - // Gather all type to `Deref` target edges. - for it in &new_items { - if let ImplItem(Impl { ref for_, ref trait_, ref items, .. }) = *it.kind { - if trait_.def_id() == cx.tcx.lang_items().deref_trait() { - let target = items.iter().find_map(|item| match *item.kind { - TypedefItem(ref t, true) => Some(&t.type_), - _ => None, - }); - if let (Some(for_did), Some(target)) = (for_.def_id(), target) { - type_did_to_deref_target.insert(for_did, target); - } - } - } - } - // Follow all `Deref` targets of included items and recursively add them as valid - fn add_deref_target( - map: &FxHashMap, - cleaner: &mut BadImplStripper, - type_did: &DefId, - ) { - if let Some(target) = map.get(type_did) { - debug!("add_deref_target: type {:?}, target {:?}", type_did, target); - if let Some(target_prim) = target.primitive_type() { - cleaner.prims.insert(target_prim); - } else if let Some(target_did) = target.def_id() { - // `impl Deref for S` - if target_did == *type_did { - // Avoid infinite cycles - return; - } - cleaner.items.insert(target_did); - add_deref_target(map, cleaner, &target_did); - } - } - } - for type_did in type_did_to_deref_target.keys() { - // Since only the `DefId` portion of the `Type` instances is known to be same for both the - // `Deref` target type and the impl for type positions, this map of types is keyed by - // `DefId` and for convenience uses a special cleaner that accepts `DefId`s directly. - if cleaner.keep_impl_with_def_id(type_did) { - add_deref_target(&type_did_to_deref_target, &mut cleaner, type_did); - } - } - let items = if let ModuleItem(Module { ref mut items, .. }) = *krate.module.kind { items } else { @@ -138,19 +124,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate { }; items.extend(synth_impls); - for it in new_items.drain(..) { - if let ImplItem(Impl { ref for_, ref trait_, ref blanket_impl, .. }) = *it.kind { - if !(cleaner.keep_impl(for_) - || trait_.as_ref().map_or(false, |t| cleaner.keep_impl(t)) - || blanket_impl.is_some()) - { - continue; - } - } - - items.push(it); - } - + items.extend(new_items); krate } @@ -204,13 +178,9 @@ impl BadImplStripper { } else if let Some(prim) = ty.primitive_type() { self.prims.contains(&prim) } else if let Some(did) = ty.def_id() { - self.keep_impl_with_def_id(&did) + self.items.contains(&did) } else { false } } - - fn keep_impl_with_def_id(&self, did: &DefId) -> bool { - self.items.contains(did) - } } diff --git a/src/test/rustdoc-ui/deref-recursive-cycle.rs b/src/test/rustdoc-ui/deref-recursive-cycle.rs deleted file mode 100644 index 4cb518cbbbd5c..0000000000000 --- a/src/test/rustdoc-ui/deref-recursive-cycle.rs +++ /dev/null @@ -1,17 +0,0 @@ -// check-pass -// #26207: Ensure `Deref` cycles are properly handled without errors. - -#[derive(Copy, Clone)] -struct S; - -impl std::ops::Deref for S { - type Target = S; - - fn deref(&self) -> &S { - self - } -} - -fn main() { - let s: S = *******S; -} diff --git a/src/test/rustdoc/deref-recursive-pathbuf.rs b/src/test/rustdoc/deref-recursive-pathbuf.rs deleted file mode 100644 index 459a30060c623..0000000000000 --- a/src/test/rustdoc/deref-recursive-pathbuf.rs +++ /dev/null @@ -1,24 +0,0 @@ -// #26207: Show all methods reachable via Deref impls, recursing through multiple dereferencing -// levels and across multiple crates. - -// @has 'foo/struct.Foo.html' -// @has '-' '//*[@id="deref-methods-PathBuf"]' 'Methods from Deref' -// @has '-' '//*[@class="impl-items"]//*[@id="method.as_path"]' 'pub fn as_path(&self)' -// @has '-' '//*[@id="deref-methods-Path"]' 'Methods from Deref' -// @has '-' '//*[@class="impl-items"]//*[@id="method.exists"]' 'pub fn exists(&self)' -// @has '-' '//*[@class="sidebar-title"][@href="#deref-methods-PathBuf"]' 'Methods from Deref' -// @has '-' '//*[@class="sidebar-links"]/a[@href="#method.as_path"]' 'as_path' -// @has '-' '//*[@class="sidebar-title"][@href="#deref-methods-Path"]' 'Methods from Deref' -// @has '-' '//*[@class="sidebar-links"]/a[@href="#method.exists"]' 'exists' - -#![crate_name = "foo"] - -use std::ops::Deref; -use std::path::PathBuf; - -pub struct Foo(PathBuf); - -impl Deref for Foo { - type Target = PathBuf; - fn deref(&self) -> &PathBuf { &self.0 } -} diff --git a/src/test/rustdoc/deref-recursive.rs b/src/test/rustdoc/deref-recursive.rs deleted file mode 100644 index b96b5397ad78b..0000000000000 --- a/src/test/rustdoc/deref-recursive.rs +++ /dev/null @@ -1,40 +0,0 @@ -// #26207: Show all methods reachable via Deref impls, recursing through multiple dereferencing -// levels if needed. - -// @has 'foo/struct.Foo.html' -// @has '-' '//*[@id="deref-methods-Bar"]' 'Methods from Deref' -// @has '-' '//*[@class="impl-items"]//*[@id="method.bar"]' 'pub fn bar(&self)' -// @has '-' '//*[@id="deref-methods-Baz"]' 'Methods from Deref' -// @has '-' '//*[@class="impl-items"]//*[@id="method.baz"]' 'pub fn baz(&self)' -// @has '-' '//*[@class="sidebar-title"][@href="#deref-methods-Bar"]' 'Methods from Deref' -// @has '-' '//*[@class="sidebar-links"]/a[@href="#method.bar"]' 'bar' -// @has '-' '//*[@class="sidebar-title"][@href="#deref-methods-Baz"]' 'Methods from Deref' -// @has '-' '//*[@class="sidebar-links"]/a[@href="#method.baz"]' 'baz' - -#![crate_name = "foo"] - -use std::ops::Deref; - -pub struct Foo(Bar); -pub struct Bar(Baz); -pub struct Baz; - -impl Deref for Foo { - type Target = Bar; - fn deref(&self) -> &Bar { &self.0 } -} - -impl Deref for Bar { - type Target = Baz; - fn deref(&self) -> &Baz { &self.0 } -} - -impl Bar { - /// This appears under `Foo` methods - pub fn bar(&self) {} -} - -impl Baz { - /// This should also appear in `Foo` methods when recursing - pub fn baz(&self) {} -} diff --git a/src/test/rustdoc/deref-typedef.rs b/src/test/rustdoc/deref-typedef.rs index 47009559e6f74..3fc48b46d7410 100644 --- a/src/test/rustdoc/deref-typedef.rs +++ b/src/test/rustdoc/deref-typedef.rs @@ -1,12 +1,12 @@ #![crate_name = "foo"] // @has 'foo/struct.Bar.html' -// @has '-' '//*[@id="deref-methods-FooJ"]' 'Methods from Deref' +// @has '-' '//*[@id="deref-methods"]' 'Methods from Deref' // @has '-' '//*[@class="impl-items"]//*[@id="method.foo_a"]' 'pub fn foo_a(&self)' // @has '-' '//*[@class="impl-items"]//*[@id="method.foo_b"]' 'pub fn foo_b(&self)' // @has '-' '//*[@class="impl-items"]//*[@id="method.foo_c"]' 'pub fn foo_c(&self)' // @has '-' '//*[@class="impl-items"]//*[@id="method.foo_j"]' 'pub fn foo_j(&self)' -// @has '-' '//*[@class="sidebar-title"][@href="#deref-methods-FooJ"]' 'Methods from Deref' +// @has '-' '//*[@class="sidebar-title"][@href="#deref-methods"]' 'Methods from Deref' // @has '-' '//*[@class="sidebar-links"]/a[@href="#method.foo_a"]' 'foo_a' // @has '-' '//*[@class="sidebar-links"]/a[@href="#method.foo_b"]' 'foo_b' // @has '-' '//*[@class="sidebar-links"]/a[@href="#method.foo_c"]' 'foo_c' From c2c18bc8d51cdfbbd786d9bffc8fe9cf12ada265 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 3 May 2021 10:06:57 -0400 Subject: [PATCH 05/52] regression test for issue 82465. --- .../issue-82465-asref-for-and-of-local.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/test/rustdoc/issue-82465-asref-for-and-of-local.rs diff --git a/src/test/rustdoc/issue-82465-asref-for-and-of-local.rs b/src/test/rustdoc/issue-82465-asref-for-and-of-local.rs new file mode 100644 index 0000000000000..618ac20ac487d --- /dev/null +++ b/src/test/rustdoc/issue-82465-asref-for-and-of-local.rs @@ -0,0 +1,16 @@ +use std::convert::AsRef; +pub struct Local; + +// @has issue_82465_asref_for_and_of_local/struct.Local.html '//code' 'impl AsRef for Local' +impl AsRef for Local { + fn as_ref(&self) -> &str { + todo!() + } +} + +// @has - '//code' 'impl AsRef for str' +impl AsRef for str { + fn as_ref(&self) -> &Local { + todo!() + } +} From e2096668babb63f27b5f21576c709e6c390abf58 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Fri, 30 Apr 2021 12:06:52 -0400 Subject: [PATCH 06/52] Revert "Add assert_matches!(expr, pat)." This reverts commit eb18746bc6c6c5c710ad674873438cbad5894f06. --- library/core/src/macros/mod.rs | 54 -------------------------- library/core/src/panicking.rs | 69 ++++++++++++---------------------- library/std/src/lib.rs | 5 +-- 3 files changed, 25 insertions(+), 103 deletions(-) diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 5d9b0f80d3a6f..c176892937456 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -110,60 +110,6 @@ macro_rules! assert_ne { }); } -/// Asserts that an expression matches any of the given patterns. -/// -/// Like in a `match` expression, the pattern can be optionally followed by `if` -/// and a guard expression that has access to names bound by the pattern. -/// -/// On panic, this macro will print the value of the expression with its -/// debug representation. -/// -/// Like [`assert!`], this macro has a second form, where a custom -/// panic message can be provided. -/// -/// # Examples -/// -/// ``` -/// #![feature(assert_matches)] -/// -/// let a = 1u32.checked_add(2); -/// let b = 1u32.checked_sub(2); -/// assert_matches!(a, Some(_)); -/// assert_matches!(b, None); -/// -/// let c = Ok("abc".to_string()); -/// assert_matches!(c, Ok(x) | Err(x) if x.len() < 100); -/// ``` -#[macro_export] -#[unstable(feature = "assert_matches", issue = "82775")] -#[allow_internal_unstable(core_panic)] -macro_rules! assert_matches { - ($left:expr, $( $pattern:pat )|+ $( if $guard: expr )? $(,)?) => ({ - match $left { - $( $pattern )|+ $( if $guard )? => {} - ref left_val => { - $crate::panicking::assert_matches_failed( - left_val, - $crate::stringify!($($pattern)|+ $(if $guard)?), - $crate::option::Option::None - ); - } - } - }); - ($left:expr, $( $pattern:pat )|+ $( if $guard: expr )?, $($arg:tt)+) => ({ - match $left { - $( $pattern )|+ $( if $guard )? => {} - ref left_val => { - $crate::panicking::assert_matches_failed( - left_val, - $crate::stringify!($($pattern)|+ $(if $guard)?), - $crate::option::Option::Some($crate::format_args!($($arg)+)) - ); - } - } - }); -} - /// Asserts that a boolean expression is `true` at runtime. /// /// This will invoke the [`panic!`] macro if the provided expression cannot be diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs index 3e3e96fcd7f78..35d9b2c5d267f 100644 --- a/library/core/src/panicking.rs +++ b/library/core/src/panicking.rs @@ -97,7 +97,6 @@ pub fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! { pub enum AssertKind { Eq, Ne, - Match, } /// Internal function for `assert_eq!` and `assert_ne!` macros @@ -114,54 +113,32 @@ where T: fmt::Debug + ?Sized, U: fmt::Debug + ?Sized, { - assert_failed_inner(kind, &left, &right, args) -} - -/// Internal function for `assert_match!` -#[cold] -#[track_caller] -#[doc(hidden)] -pub fn assert_matches_failed( - left: &T, - right: &str, - args: Option>, -) -> ! { - // Use the Display implementation to display the pattern. - struct Pattern<'a>(&'a str); - impl fmt::Debug for Pattern<'_> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(self.0, f) - } - } - assert_failed_inner(AssertKind::Match, &left, &Pattern(right), args); -} - -/// Non-generic version of the above functions, to avoid code bloat. -#[track_caller] -fn assert_failed_inner( - kind: AssertKind, - left: &dyn fmt::Debug, - right: &dyn fmt::Debug, - args: Option>, -) -> ! { - let op = match kind { - AssertKind::Eq => "==", - AssertKind::Ne => "!=", - AssertKind::Match => "matches", - }; - - match args { - Some(args) => panic!( - r#"assertion failed: `(left {} right)` + #[track_caller] + fn inner( + kind: AssertKind, + left: &dyn fmt::Debug, + right: &dyn fmt::Debug, + args: Option>, + ) -> ! { + let op = match kind { + AssertKind::Eq => "==", + AssertKind::Ne => "!=", + }; + + match args { + Some(args) => panic!( + r#"assertion failed: `(left {} right)` left: `{:?}`, right: `{:?}`: {}"#, - op, left, right, args - ), - None => panic!( - r#"assertion failed: `(left {} right)` + op, left, right, args + ), + None => panic!( + r#"assertion failed: `(left {} right)` left: `{:?}`, right: `{:?}`"#, - op, left, right, - ), + op, left, right, + ), + } } + inner(kind, &left, &right, args) } diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 0ab9f490fd420..314c10fc7c438 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -230,7 +230,6 @@ #![feature(arbitrary_self_types)] #![feature(array_error_internals)] #![feature(asm)] -#![feature(assert_matches)] #![feature(associated_type_bounds)] #![feature(atomic_mut_ptr)] #![feature(bench_black_box)] @@ -557,8 +556,8 @@ pub use std_detect::{ #[stable(feature = "rust1", since = "1.0.0")] #[allow(deprecated, deprecated_in_future)] pub use core::{ - assert_eq, assert_matches, assert_ne, debug_assert, debug_assert_eq, debug_assert_matches, - debug_assert_ne, matches, r#try, todo, unimplemented, unreachable, write, writeln, + assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_matches, debug_assert_ne, + matches, r#try, todo, unimplemented, unreachable, write, writeln, }; // Re-export built-in macros defined through libcore. From 607a225695d2773fca773136ba0efb1cdb073213 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Fri, 30 Apr 2021 12:08:30 -0400 Subject: [PATCH 07/52] Revert "Add debug_assert_matches macro." This reverts commit 0a8e401188062f0c60c989978352663b1e25e70e. --- library/core/src/macros/mod.rs | 36 ---------------------------------- library/std/src/lib.rs | 4 ++-- 2 files changed, 2 insertions(+), 38 deletions(-) diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index c176892937456..66efa3c20b642 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -208,42 +208,6 @@ macro_rules! debug_assert_ne { ($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_ne!($($arg)*); }) } -/// Asserts that an expression matches any of the given patterns. -/// -/// Like in a `match` expression, the pattern can be optionally followed by `if` -/// and a guard expression that has access to names bound by the pattern. -/// -/// On panic, this macro will print the value of the expression with its -/// debug representation. -/// -/// Unlike [`assert_matches!`], `debug_assert_matches!` statements are only -/// enabled in non optimized builds by default. An optimized build will not -/// execute `debug_assert_matches!` statements unless `-C debug-assertions` is -/// passed to the compiler. This makes `debug_assert_matches!` useful for -/// checks that are too expensive to be present in a release build but may be -/// helpful during development. The result of expanding `debug_assert_matches!` -/// is always type checked. -/// -/// # Examples -/// -/// ``` -/// #![feature(assert_matches)] -/// -/// let a = 1u32.checked_add(2); -/// let b = 1u32.checked_sub(2); -/// debug_assert_matches!(a, Some(_)); -/// debug_assert_matches!(b, None); -/// -/// let c = Ok("abc".to_string()); -/// debug_assert_matches!(c, Ok(x) | Err(x) if x.len() < 100); -/// ``` -#[macro_export] -#[unstable(feature = "assert_matches", issue = "82775")] -#[allow_internal_unstable(assert_matches)] -macro_rules! debug_assert_matches { - ($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_matches!($($arg)*); }) -} - /// Returns whether the given expression matches any of the given patterns. /// /// Like in a `match` expression, the pattern can be optionally followed by `if` diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 314c10fc7c438..1b764d5a6994e 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -556,8 +556,8 @@ pub use std_detect::{ #[stable(feature = "rust1", since = "1.0.0")] #[allow(deprecated, deprecated_in_future)] pub use core::{ - assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_matches, debug_assert_ne, - matches, r#try, todo, unimplemented, unreachable, write, writeln, + assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, matches, r#try, todo, + unimplemented, unreachable, write, writeln, }; // Re-export built-in macros defined through libcore. From d18f0a42deafa67cf860ba78f05e6395ea391450 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Fri, 30 Apr 2021 12:11:35 -0400 Subject: [PATCH 08/52] Remove assert_matches users --- compiler/rustc_middle/src/ich/impls_syntax.rs | 6 +----- .../rustc_middle/src/mir/interpret/allocation.rs | 2 +- compiler/rustc_mir/src/interpret/memory.rs | 14 +++----------- src/test/ui/macros/assert-matches-macro-msg.rs | 11 ----------- 4 files changed, 5 insertions(+), 28 deletions(-) delete mode 100644 src/test/ui/macros/assert-matches-macro-msg.rs diff --git a/compiler/rustc_middle/src/ich/impls_syntax.rs b/compiler/rustc_middle/src/ich/impls_syntax.rs index b93b25d6b5c9a..f53992172beed 100644 --- a/compiler/rustc_middle/src/ich/impls_syntax.rs +++ b/compiler/rustc_middle/src/ich/impls_syntax.rs @@ -45,11 +45,7 @@ impl<'ctx> rustc_ast::HashStableContext for StableHashingContext<'ctx> { item.hash_stable(self, hasher); style.hash_stable(self, hasher); span.hash_stable(self, hasher); - assert_matches!( - tokens.as_ref(), - None, - "Tokens should have been removed during lowering!" - ); + assert!(tokens.as_ref().is_none(), "Tokens should have been removed during lowering!"); } else { unreachable!(); } diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index 766d6a06f7e59..898c375e9ae1a 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -339,7 +339,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra> Allocation { for dest in bytes { *dest = src.next().expect("iterator was shorter than it said it would be"); } - assert_matches!(src.next(), None, "iterator was longer than it said it would be"); + assert!(src.next().is_none(), "iterator was longer than it said it would be"); Ok(()) } diff --git a/compiler/rustc_mir/src/interpret/memory.rs b/compiler/rustc_mir/src/interpret/memory.rs index fe5ebf0b6fe97..3648748a90908 100644 --- a/compiler/rustc_mir/src/interpret/memory.rs +++ b/compiler/rustc_mir/src/interpret/memory.rs @@ -854,11 +854,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { Some(ptr) => ptr, None => { // zero-sized access - assert_matches!( - src.next(), - None, - "iterator said it was empty but returned an element" - ); + assert!(src.next().is_none(), "iterator said it was empty but returned an element"); return Ok(()); } }; @@ -884,11 +880,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { Some(ptr) => ptr, None => { // zero-sized access - assert_matches!( - src.next(), - None, - "iterator said it was empty but returned an element" - ); + assert!(src.next().is_none(), "iterator said it was empty but returned an element"); return Ok(()); } }; @@ -902,7 +894,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { let offset_ptr = ptr.offset(Size::from_bytes(idx) * 2, &tcx)?; // `Size` multiplication allocation.write_scalar(&tcx, offset_ptr, val.into(), Size::from_bytes(2))?; } - assert_matches!(src.next(), None, "iterator was longer than it said it would be"); + assert!(src.next().is_none(), "iterator was longer than it said it would be"); Ok(()) } diff --git a/src/test/ui/macros/assert-matches-macro-msg.rs b/src/test/ui/macros/assert-matches-macro-msg.rs deleted file mode 100644 index 43be9532f5d1c..0000000000000 --- a/src/test/ui/macros/assert-matches-macro-msg.rs +++ /dev/null @@ -1,11 +0,0 @@ -// run-fail -// error-pattern:panicked at 'assertion failed: `(left matches right)` -// error-pattern: left: `2` -// error-pattern:right: `3`: 1 + 1 definitely should be 3' -// ignore-emscripten no processes - -#![feature(assert_matches)] - -fn main() { - assert_matches!(1 + 1, 3, "1 + 1 definitely should be 3"); -} From ded409e6b8720414356a0c163c1061b2168e86db Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 30 Apr 2021 18:22:06 +0200 Subject: [PATCH 09/52] Remove assert_matches feature attributes. --- compiler/rustc_codegen_ssa/src/lib.rs | 1 - compiler/rustc_middle/src/lib.rs | 1 - compiler/rustc_mir/src/lib.rs | 1 - 3 files changed, 3 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index f0f45b067b352..b761bb4e193d3 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -1,5 +1,4 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] -#![feature(assert_matches)] #![feature(bool_to_option)] #![feature(box_patterns)] #![feature(drain_filter)] diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index 45ea07a3db6b6..2ff271f3981f0 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -24,7 +24,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(array_windows)] -#![feature(assert_matches)] #![feature(backtrace)] #![feature(bool_to_option)] #![feature(box_patterns)] diff --git a/compiler/rustc_mir/src/lib.rs b/compiler/rustc_mir/src/lib.rs index 783aa9465c395..f9adc27116608 100644 --- a/compiler/rustc_mir/src/lib.rs +++ b/compiler/rustc_mir/src/lib.rs @@ -7,7 +7,6 @@ Rust MIR: a lowered representation of Rust. #![feature(nll)] #![feature(in_band_lifetimes)] #![feature(array_windows)] -#![feature(assert_matches)] #![feature(bindings_after_at)] #![feature(bool_to_option)] #![feature(box_patterns)] From bd9c30d63235b73968913c5905f8699a399d19a6 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 15 Mar 2021 16:39:41 -0400 Subject: [PATCH 10/52] Revert PR 81473 to resolve (on beta) issues 81626 and 81658. Revert "Add missing brace" This reverts commit 85ad773049536d7fed9a94ae0ac74f97135c8655. Revert "Simplify base_expr" This reverts commit 899aae465eb4ef295dc1eeb2603f744568e0768c. Revert "Warn write-only fields" This reverts commit d3c69a4c0dd98af2611b7553d1a65afef6a6ccb0. --- compiler/rustc_passes/src/dead.rs | 21 ------ .../borrowck/borrowck-assign-to-subfield.rs | 1 - .../ui/lint/dead-code/write-only-field.rs | 69 ------------------- .../ui/lint/dead-code/write-only-field.stderr | 44 ------------ 4 files changed, 135 deletions(-) delete mode 100644 src/test/ui/lint/dead-code/write-only-field.rs delete mode 100644 src/test/ui/lint/dead-code/write-only-field.stderr diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index d32180525bf70..c671035bb7ba1 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -133,22 +133,6 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { } } - fn handle_assign(&mut self, expr: &'tcx hir::Expr<'tcx>) { - if self - .typeck_results() - .expr_adjustments(expr) - .iter() - .any(|adj| matches!(adj.kind, ty::adjustment::Adjust::Deref(_))) - { - self.visit_expr(expr); - } else if let hir::ExprKind::Field(base, ..) = expr.kind { - // Ignore write to field - self.handle_assign(base); - } else { - self.visit_expr(expr); - } - } - fn handle_field_pattern_match( &mut self, lhs: &hir::Pat<'_>, @@ -277,11 +261,6 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> { hir::ExprKind::MethodCall(..) => { self.lookup_and_handle_method(expr.hir_id); } - hir::ExprKind::Assign(ref left, ref right, ..) => { - self.handle_assign(left); - self.visit_expr(right); - return; - } hir::ExprKind::Field(ref lhs, ..) => { self.handle_field_access(&lhs, expr.hir_id); } diff --git a/src/test/ui/borrowck/borrowck-assign-to-subfield.rs b/src/test/ui/borrowck/borrowck-assign-to-subfield.rs index dfa3a561ec7ee..050d702b625ab 100644 --- a/src/test/ui/borrowck/borrowck-assign-to-subfield.rs +++ b/src/test/ui/borrowck/borrowck-assign-to-subfield.rs @@ -1,6 +1,5 @@ // run-pass // pretty-expanded FIXME #23616 -#![allow(dead_code)] pub fn main() { struct A { diff --git a/src/test/ui/lint/dead-code/write-only-field.rs b/src/test/ui/lint/dead-code/write-only-field.rs deleted file mode 100644 index 7b3f1e9f5b6cb..0000000000000 --- a/src/test/ui/lint/dead-code/write-only-field.rs +++ /dev/null @@ -1,69 +0,0 @@ -#![deny(dead_code)] - -struct S { - f: i32, //~ ERROR: field is never read - sub: Sub, //~ ERROR: field is never read -} - -struct Sub { - f: i32, //~ ERROR: field is never read -} - -fn field_write(s: &mut S) { - s.f = 1; - s.sub.f = 2; -} - -fn main() { - let mut s = S { f: 0, sub: Sub { f: 0 } }; - field_write(&mut s); - - auto_deref(); - nested_boxes(); -} - -fn auto_deref() { - struct E { - x: bool, - y: bool, //~ ERROR: field is never read - } - - struct P<'a> { - e: &'a mut E - } - - impl P<'_> { - fn f(&mut self) { - self.e.x = true; - self.e.y = true; - } - } - - let mut e = E { x: false, y: false }; - let mut p = P { e: &mut e }; - p.f(); - assert!(e.x); -} - -fn nested_boxes() { - struct A { - b: Box, - } - - struct B { - c: Box, - } - - struct C { - u: u32, //~ ERROR: field is never read - v: u32, //~ ERROR: field is never read - } - - let mut a = A { - b: Box::new(B { - c: Box::new(C { u: 0, v: 0 }), - }), - }; - a.b.c.v = 10; - a.b.c = Box::new(C { u: 1, v: 2 }); -} diff --git a/src/test/ui/lint/dead-code/write-only-field.stderr b/src/test/ui/lint/dead-code/write-only-field.stderr deleted file mode 100644 index a191d22c8b94c..0000000000000 --- a/src/test/ui/lint/dead-code/write-only-field.stderr +++ /dev/null @@ -1,44 +0,0 @@ -error: field is never read: `f` - --> $DIR/write-only-field.rs:4:5 - | -LL | f: i32, - | ^^^^^^ - | -note: the lint level is defined here - --> $DIR/write-only-field.rs:1:9 - | -LL | #![deny(dead_code)] - | ^^^^^^^^^ - -error: field is never read: `sub` - --> $DIR/write-only-field.rs:5:5 - | -LL | sub: Sub, - | ^^^^^^^^ - -error: field is never read: `f` - --> $DIR/write-only-field.rs:9:5 - | -LL | f: i32, - | ^^^^^^ - -error: field is never read: `y` - --> $DIR/write-only-field.rs:28:9 - | -LL | y: bool, - | ^^^^^^^ - -error: field is never read: `u` - --> $DIR/write-only-field.rs:58:9 - | -LL | u: u32, - | ^^^^^^ - -error: field is never read: `v` - --> $DIR/write-only-field.rs:59:9 - | -LL | v: u32, - | ^^^^^^ - -error: aborting due to 6 previous errors - From bbfdfa9174deeb8212ca82248f0ec34f461cdb3a Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Wed, 5 May 2021 12:04:18 +0200 Subject: [PATCH 11/52] Revert PR 83866 That PR caused multiple test failures when Rust's channel is changed from nightly to anything else. The commit will have to be landed again after the test suite is fixed. --- src/librustdoc/clean/types.rs | 7 +++---- src/librustdoc/clean/utils.rs | 11 ----------- src/librustdoc/core.rs | 9 +++------ src/librustdoc/lib.rs | 7 +------ src/librustdoc/passes/collect_intra_doc_links.rs | 9 +-------- .../intra-doc/email-address-localhost.stderr | 1 - .../rustdoc-ui/intra-doc/unknown-disambiguator.stderr | 11 ----------- 7 files changed, 8 insertions(+), 47 deletions(-) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 5e47144588b3f..ad4a09d45f30a 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -393,10 +393,9 @@ impl Item { Some(&(_, _, ExternalLocation::Remote(ref s))) => { format!("{}/std/", s.trim_end_matches('/')) } - Some(&(_, _, ExternalLocation::Unknown)) | None => format!( - "https://doc.rust-lang.org/{}/std/", - crate::doc_rust_lang_org_channel(), - ), + Some(&(_, _, ExternalLocation::Unknown)) | None => { + "https://doc.rust-lang.org/nightly/std/".to_string() + } }; // This is a primitive so the url is done "by hand". let tail = fragment.find('#').unwrap_or_else(|| fragment.len()); diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 7df8b442e5acc..b5953d2dc48a9 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -525,14 +525,3 @@ crate fn has_doc_flag(attrs: ty::Attributes<'_>, flag: Symbol) -> bool { && attr.meta_item_list().map_or(false, |l| rustc_attr::list_contains_name(&l, flag)) }) } - -/// Return a channel suitable for using in a `doc.rust-lang.org/{channel}` format string. -crate fn doc_rust_lang_org_channel() -> &'static str { - match env!("CFG_RELEASE_CHANNEL") { - "stable" => env!("CFG_RELEASE_NUM"), - "beta" => "beta", - "nightly" | "dev" => "nightly", - // custom build of rustdoc maybe? link to the stable docs just in case - _ => "", - } -} diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 212aac0e5b43c..1ec4757a9113e 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -450,18 +450,15 @@ crate fn run_global_ctxt( let mut krate = tcx.sess.time("clean_crate", || clean::krate(&mut ctxt)); if krate.module.doc_value().map(|d| d.is_empty()).unwrap_or(true) { - let help = format!( - "The following guide may be of use:\n\ - https://doc.rust-lang.org/{}/rustdoc/how-to-write-documentation.html", - crate::doc_rust_lang_org_channel(), - ); + let help = "The following guide may be of use:\n\ + https://doc.rust-lang.org/nightly/rustdoc/how-to-write-documentation.html"; tcx.struct_lint_node( crate::lint::MISSING_CRATE_LEVEL_DOCS, DocContext::as_local_hir_id(tcx, krate.module.def_id).unwrap(), |lint| { let mut diag = lint.build("no documentation found for this crate's top-level module"); - diag.help(&help); + diag.help(help); diag.emit(); }, ); diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 985aeedabb106..943e2961d3b43 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -82,8 +82,6 @@ use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGro use rustc_session::getopts; use rustc_session::{early_error, early_warn}; -use crate::clean::utils::doc_rust_lang_org_channel; - /// A macro to create a FxHashMap. /// /// Example: @@ -605,10 +603,7 @@ fn usage(argv0: &str) { } println!("{}", options.usage(&format!("{} [options] ", argv0))); println!(" @path Read newline separated options from `path`\n"); - println!( - "More information available at https://doc.rust-lang.org/{}/rustdoc/what-is-rustdoc.html", - doc_rust_lang_org_channel() - ); + println!("More information available at https://doc.rust-lang.org/rustdoc/what-is-rustdoc.html") } /// A result type used by several functions under `main()`. diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index f1064756fdde7..aeaceeefc08a1 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -1993,14 +1993,7 @@ fn disambiguator_error( msg: &str, ) { diag_info.link_range = disambiguator_range; - report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, msg, &diag_info, |diag, _sp| { - let msg = format!( - "see https://doc.rust-lang.org/{}/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators \ - for more info about disambiguators", - crate::doc_rust_lang_org_channel(), - ); - diag.note(&msg); - }); + report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, msg, &diag_info, |_diag, _sp| {}); } /// Report an ambiguity error, where there were multiple possible resolutions. diff --git a/src/test/rustdoc-ui/intra-doc/email-address-localhost.stderr b/src/test/rustdoc-ui/intra-doc/email-address-localhost.stderr index f287f87408c48..de215b2163bd4 100644 --- a/src/test/rustdoc-ui/intra-doc/email-address-localhost.stderr +++ b/src/test/rustdoc-ui/intra-doc/email-address-localhost.stderr @@ -10,7 +10,6 @@ note: the lint level is defined here LL | #![deny(warnings)] | ^^^^^^^^ = note: `#[deny(rustdoc::broken_intra_doc_links)]` implied by `#[deny(warnings)]` - = note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators error: aborting due to previous error diff --git a/src/test/rustdoc-ui/intra-doc/unknown-disambiguator.stderr b/src/test/rustdoc-ui/intra-doc/unknown-disambiguator.stderr index 94d6d4616518e..195aaca32a27d 100644 --- a/src/test/rustdoc-ui/intra-doc/unknown-disambiguator.stderr +++ b/src/test/rustdoc-ui/intra-doc/unknown-disambiguator.stderr @@ -10,47 +10,36 @@ note: the lint level is defined here LL | #![deny(warnings)] | ^^^^^^^^ = note: `#[deny(rustdoc::broken_intra_doc_links)]` implied by `#[deny(warnings)]` - = note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators error: unknown disambiguator `bar` --> $DIR/unknown-disambiguator.rs:3:35 | LL | //! Linking to [foo@banana] and [`bar@banana!()`]. | ^^^ - | - = note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators error: unknown disambiguator `foo` --> $DIR/unknown-disambiguator.rs:9:34 | LL | //! And with weird backticks: [``foo@hello``] [foo`@`hello]. | ^^^ - | - = note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators error: unknown disambiguator `foo` --> $DIR/unknown-disambiguator.rs:9:48 | LL | //! And with weird backticks: [``foo@hello``] [foo`@`hello]. | ^^^ - | - = note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators error: unknown disambiguator `` --> $DIR/unknown-disambiguator.rs:6:31 | LL | //! And to [no disambiguator](@nectarine) and [another](@apricot!()). | ^ - | - = note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators error: unknown disambiguator `` --> $DIR/unknown-disambiguator.rs:6:57 | LL | //! And to [no disambiguator](@nectarine) and [another](@apricot!()). | ^ - | - = note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators error: aborting due to 6 previous errors From c835a59cab7628f70e4d92204c948011a349972c Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 3 May 2021 22:59:35 +0200 Subject: [PATCH 12/52] Update RLS and Rustfmt --- Cargo.lock | 187 ++++++++++++++-------------------------------- src/tools/rls | 2 +- src/tools/rustfmt | 2 +- 3 files changed, 60 insertions(+), 131 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a55ef7b61436e..0939f19cdfe20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,20 +58,14 @@ dependencies = [ "url 2.1.1", ] -[[package]] -name = "annotate-snippets" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7021ce4924a3f25f802b2cccd1af585e39ea1a363a1aa2e72afe54b67a3a7a7" -dependencies = [ - "ansi_term 0.11.0", -] - [[package]] name = "annotate-snippets" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d78ea013094e5ea606b1c05fe35f1dd7ea1eb1ea259908d040b25bd5ec677ee5" +dependencies = [ + "yansi-term", +] [[package]] name = "ansi_term" @@ -103,12 +97,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f8cb5d814eb646a863c4f24978cff2880c4be96ad8cde2c0f0678732902e271" -[[package]] -name = "arrayvec" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" - [[package]] name = "arrayvec" version = "0.7.0" @@ -2856,9 +2844,9 @@ dependencies = [ [[package]] name = "racer" -version = "2.1.45" +version = "2.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15408926f6207643150e0fc2c54a75a689b192df03ac6c59d42ea99c6782c7f7" +checksum = "e7cbda48a9124ed2e83766d2c15e3725710d344abca35fad8cf52341a55883b1" dependencies = [ "bitflags", "clap", @@ -3221,9 +3209,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_arena" -version = "712.0.0" +version = "718.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "259cca0e975ecb05fd289ace45280c30ff792efc04e856a7f18b7fc86a3cb610" +checksum = "526610f47139efa440178239553b59ea805ff57a532b4e295c71d2a9b18fd676" dependencies = [ "rustc-ap-rustc_data_structures", "smallvec", @@ -3231,9 +3219,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_ast" -version = "712.0.0" +version = "718.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb9be435d50c88e94bbad6ea468c8680b52c5043bb298ab8058d05251717f8f8" +checksum = "cf6a9dda0804a7243b0282e3b75a8cf4654c7a61f033e587751941e1fe39391b" dependencies = [ "bitflags", "rustc-ap-rustc_data_structures", @@ -3246,69 +3234,33 @@ dependencies = [ "tracing", ] -[[package]] -name = "rustc-ap-rustc_ast_passes" -version = "712.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75246dd1a95a57f7767e53bde3971baa2d948078e180564709f5ea46cf863ddd" -dependencies = [ - "itertools 0.9.0", - "rustc-ap-rustc_ast", - "rustc-ap-rustc_ast_pretty", - "rustc-ap-rustc_attr", - "rustc-ap-rustc_data_structures", - "rustc-ap-rustc_errors", - "rustc-ap-rustc_feature", - "rustc-ap-rustc_parse", - "rustc-ap-rustc_session", - "rustc-ap-rustc_span", - "tracing", -] - [[package]] name = "rustc-ap-rustc_ast_pretty" -version = "712.0.0" +version = "718.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79bede0b44bed453fd0034b7ba492840391f6486bf3e17a1af12922f0b98d4cc" +checksum = "82f5019be8b41a58664169fd2f4b1a37fe82705681db394b76419e4e87d40ab1" dependencies = [ "rustc-ap-rustc_ast", "rustc-ap-rustc_span", "tracing", ] -[[package]] -name = "rustc-ap-rustc_attr" -version = "712.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a92a4a34b996694ca2dab70361c60d2d48c07adce57e8155b7ec75e069e3ea" -dependencies = [ - "rustc-ap-rustc_ast", - "rustc-ap-rustc_ast_pretty", - "rustc-ap-rustc_data_structures", - "rustc-ap-rustc_errors", - "rustc-ap-rustc_feature", - "rustc-ap-rustc_lexer", - "rustc-ap-rustc_macros", - "rustc-ap-rustc_serialize", - "rustc-ap-rustc_session", - "rustc-ap-rustc_span", -] - [[package]] name = "rustc-ap-rustc_data_structures" -version = "712.0.0" +version = "718.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cbfa7f82517a1b2efe7106c864c3f930b1da8aff07a27fd317af2f36522fd2e" +checksum = "a701717fb14549331085756b9741ae3b4bf35808489f1887d72c1d0e0fe52b77" dependencies = [ - "arrayvec 0.5.2", + "arrayvec", "bitflags", "cfg-if 0.1.10", - "crossbeam-utils 0.7.2", + "crossbeam-utils 0.8.3", "ena", "indexmap", "jobserver", "libc", "measureme", + "memmap2", "parking_lot", "rustc-ap-rustc_graphviz", "rustc-ap-rustc_index", @@ -3327,11 +3279,11 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_errors" -version = "712.0.0" +version = "718.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58a272a5101843bcb40900cc9ccf80ecfec62830bb1f4a242986da4a34c0da89" +checksum = "e3182ce85e8bfc96443475547f2f5aa2b5e67655d9b88721795f36f0ba9e265a" dependencies = [ - "annotate-snippets 0.8.0", + "annotate-snippets", "atty", "rustc-ap-rustc_data_structures", "rustc-ap-rustc_lint_defs", @@ -3345,35 +3297,11 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "rustc-ap-rustc_expand" -version = "712.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bc7988f3facf2402fe057405ef0f7fbacc7e7a483da25e35a35ac09491fbbfb" -dependencies = [ - "rustc-ap-rustc_ast", - "rustc-ap-rustc_ast_passes", - "rustc-ap-rustc_ast_pretty", - "rustc-ap-rustc_attr", - "rustc-ap-rustc_data_structures", - "rustc-ap-rustc_errors", - "rustc-ap-rustc_feature", - "rustc-ap-rustc_lexer", - "rustc-ap-rustc_lint_defs", - "rustc-ap-rustc_macros", - "rustc-ap-rustc_parse", - "rustc-ap-rustc_serialize", - "rustc-ap-rustc_session", - "rustc-ap-rustc_span", - "smallvec", - "tracing", -] - [[package]] name = "rustc-ap-rustc_feature" -version = "712.0.0" +version = "718.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e931cd1580ae60c5737d3fa57633034935e885414e794d83b3e52a81021985c" +checksum = "eed033b93270126ef60963c3ebbd0e026bf53b985172b6366c7b0e7881c9d507" dependencies = [ "rustc-ap-rustc_data_structures", "rustc-ap-rustc_span", @@ -3381,41 +3309,41 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_fs_util" -version = "712.0.0" +version = "718.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fe9422e10d5b441d2a78202667bc85d7cf713a087b9ae6cdea0dfc825d79f07" +checksum = "28ee6531986a205101e09fd143d7bf31897388f33b1814d4bcc45fd62211dca6" [[package]] name = "rustc-ap-rustc_graphviz" -version = "712.0.0" +version = "718.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffffffdef9fd51db69c1d4c045ced8aaab999be5627f2d3a0ce020d74c1f1e50" +checksum = "3398fddc0e23d2db89c036f8952ddf78cadc597f7059752116e69483e164a5b6" [[package]] name = "rustc-ap-rustc_index" -version = "712.0.0" +version = "718.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f6f53afc4f7111c82295cb7ea3878f520bbac6a2c5a12e125b4ca9156498cff" +checksum = "dca4e27eb5b701f6bbd47d8fc9d242378fca3e4107a519a28415c2989c4a3bd3" dependencies = [ - "arrayvec 0.5.2", + "arrayvec", "rustc-ap-rustc_macros", "rustc-ap-rustc_serialize", ] [[package]] name = "rustc-ap-rustc_lexer" -version = "712.0.0" +version = "718.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8056b05346dff7e39164d0434c6ec443a14ab5fbf6221bd1a56e5abbeae5f60c" +checksum = "786bbfe9d4d5264294c1819dbf1497a2480b583d5eda1ca9ae22e12d6661f5df" dependencies = [ "unicode-xid", ] [[package]] name = "rustc-ap-rustc_lint_defs" -version = "712.0.0" +version = "718.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "364c3fb7b3cbdfe3fbb21d4078ff2cb3c58df63cda27995f8b064d21ee6dede5" +checksum = "be2f045e2b999c154ec505d5fea69c994b742f3ebd2f552d11a6c81723921e47" dependencies = [ "rustc-ap-rustc_ast", "rustc-ap-rustc_data_structures", @@ -3428,9 +3356,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_macros" -version = "712.0.0" +version = "718.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4607d6879cae3bae4d0369ca4b3a7510fd6295ac32eec088ac975208ba96ca45" +checksum = "27789cd26d6b9e2fdfa68a262a20664d79ca67d31a3886d40fb88ebf6935869c" dependencies = [ "proc-macro2", "quote", @@ -3440,9 +3368,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_parse" -version = "712.0.0" +version = "718.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78d22889bff7ca2346037c9df7ea55c66ffb714f5b50fb62b41975f8ac7a2d70" +checksum = "1dc331f4958350679679e619d63a891e8d5d34ef99087068c89aa9e657d52caa" dependencies = [ "bitflags", "rustc-ap-rustc_ast", @@ -3460,9 +3388,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_serialize" -version = "712.0.0" +version = "718.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d33c710120953c0214f47a6caf42064d7e241003b4af36c98a6d6156e70335f1" +checksum = "e9a6824a462c4c1a379e911b0faf86d303a54bcf8673d4cc445195085966a4a4" dependencies = [ "indexmap", "smallvec", @@ -3470,9 +3398,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_session" -version = "712.0.0" +version = "718.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d35919041429a90713c8f704fa5209ba159cb554ce74d95722cbc18ac4b4c6f" +checksum = "a782a5f6ada0dbe089c6416ad0104f0b8a8bdb4bd26ea95e5fefaec67aed5e8a" dependencies = [ "bitflags", "getopts", @@ -3492,9 +3420,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_span" -version = "712.0.0" +version = "718.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73b12170c69603c0bf4b50e5c25fd348aae13b8c6465aa0ef4389c9eaa568e51" +checksum = "a257546cb264b250c7abdb81239bb02f18a274a966211755a3ea89411b122214" dependencies = [ "cfg-if 0.1.10", "md-5", @@ -3512,9 +3440,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_target" -version = "712.0.0" +version = "718.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a8329d92e7dc24b974f759e6c6e97e2bbc47b18d0573343028f8135ca367200" +checksum = "b5a72dd689421bcb5750f3ed0dedf367076e714ef0ba56c02ed391b9a8582862" dependencies = [ "bitflags", "rustc-ap-rustc_data_structures", @@ -3797,7 +3725,7 @@ dependencies = [ name = "rustc_data_structures" version = "0.0.0" dependencies = [ - "arrayvec 0.7.0", + "arrayvec", "bitflags", "cfg-if 0.1.10", "crossbeam-utils 0.8.3", @@ -3866,7 +3794,7 @@ version = "0.0.0" name = "rustc_errors" version = "0.0.0" dependencies = [ - "annotate-snippets 0.8.0", + "annotate-snippets", "atty", "rustc_data_structures", "rustc_lint_defs", @@ -3967,7 +3895,7 @@ dependencies = [ name = "rustc_index" version = "0.0.0" dependencies = [ - "arrayvec 0.7.0", + "arrayvec", "rustc_macros", "rustc_serialize", ] @@ -4563,7 +4491,7 @@ dependencies = [ name = "rustdoc" version = "0.0.0" dependencies = [ - "arrayvec 0.7.0", + "arrayvec", "expect-test", "itertools 0.9.0", "minifier", @@ -4625,7 +4553,7 @@ dependencies = [ name = "rustfmt-nightly" version = "1.4.37" dependencies = [ - "annotate-snippets 0.6.1", + "annotate-snippets", "anyhow", "bytecount", "cargo_metadata 0.8.2", @@ -4639,14 +4567,6 @@ dependencies = [ "lazy_static", "log", "regex", - "rustc-ap-rustc_ast", - "rustc-ap-rustc_ast_pretty", - "rustc-ap-rustc_data_structures", - "rustc-ap-rustc_errors", - "rustc-ap-rustc_expand", - "rustc-ap-rustc_parse", - "rustc-ap-rustc_session", - "rustc-ap-rustc_span", "rustc-workspace-hack", "rustfmt-config_proc_macro", "serde", @@ -5796,3 +5716,12 @@ checksum = "39f0c922f1a334134dc2f7a8b67dc5d25f0735263feec974345ff706bcf20b0d" dependencies = [ "linked-hash-map", ] + +[[package]] +name = "yansi-term" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe5c30ade05e61656247b2e334a031dfd0cc466fadef865bdcdea8d537951bf1" +dependencies = [ + "winapi 0.3.9", +] diff --git a/src/tools/rls b/src/tools/rls index 74d1800c25498..359513ce678ef 160000 --- a/src/tools/rls +++ b/src/tools/rls @@ -1 +1 @@ -Subproject commit 74d1800c25498689c5b5120a1e8495fce0cd0d0d +Subproject commit 359513ce678efba186972e4f280dbc7046cac15f diff --git a/src/tools/rustfmt b/src/tools/rustfmt index 0bd2b1927c2b0..2a3635d5d1218 160000 --- a/src/tools/rustfmt +++ b/src/tools/rustfmt @@ -1 +1 @@ -Subproject commit 0bd2b1927c2b02a6fe7447d58e897cf1f1a1d41f +Subproject commit 2a3635d5d1218c726ff58af4bc35418836143f69 From 3a1e4148e19b8c6c3be272204207f068f21efe7f Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 2 May 2021 15:06:24 -0400 Subject: [PATCH 13/52] Add `yansi-term` as a permitted dependency --- src/tools/tidy/src/deps.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 5a843ea61ec6f..b604b39967ec7 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -189,6 +189,8 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[ "winapi-i686-pc-windows-gnu", "winapi-util", "winapi-x86_64-pc-windows-gnu", + // 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", ]; /// Dependency checks. From 489465673f80e43a1fcb09fd60a2fe2dacc56b25 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Tue, 17 Nov 2020 16:00:41 -0500 Subject: [PATCH 14/52] Ignore failures of RLS on aarch64 Windows --- src/bootstrap/dist.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index aee3c8324bc11..8224eac823b18 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -1029,7 +1029,13 @@ impl Step for Rls { let rls = builder .ensure(tool::Rls { compiler, target, extra_features: Vec::new() }) .or_else(|| { - missing_tool("RLS", builder.build.config.missing_tools); + // We ignore failure on aarch64 Windows because RLS currently + // fails to build, due to winapi 0.2 not supporting aarch64. + missing_tool( + "RLS", + builder.build.config.missing_tools + || (target.triple.contains("aarch64") && target.triple.contains("windows")), + ); None })?; From fb327ab85575af7d66ab2fb0a10164365717a32b Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Sun, 25 Apr 2021 15:11:49 -0400 Subject: [PATCH 15/52] Deduplicate ParamCandidates with the same value except for bound vars --- .../src/traits/select/mod.rs | 12 ++++++++++- src/test/ui/lifetimes/issue-84398.rs | 20 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/lifetimes/issue-84398.rs diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index e4aabbdb7ede7..c9ba8e6dc8ce7 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1361,7 +1361,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ) => false, (ParamCandidate(other), ParamCandidate(victim)) => { - if other.value == victim.value && victim.constness == Constness::NotConst { + let value_same_except_bound_vars = other.value.skip_binder() + == victim.value.skip_binder() + && !other.value.skip_binder().has_escaping_bound_vars(); + if value_same_except_bound_vars { + // See issue #84398. In short, we can generate multiple ParamCandidates which are + // the same except for unused bound vars. Just pick the current one (the should + // both evaluate to the same answer). This is probably best characterized as a + // "hack", since we might prefer to just do our best to *not* create essentially + // duplicate candidates in the first place. + true + } else if other.value == victim.value && victim.constness == Constness::NotConst { // Drop otherwise equivalent non-const candidates in favor of const candidates. true } else { diff --git a/src/test/ui/lifetimes/issue-84398.rs b/src/test/ui/lifetimes/issue-84398.rs new file mode 100644 index 0000000000000..1912fa59b7990 --- /dev/null +++ b/src/test/ui/lifetimes/issue-84398.rs @@ -0,0 +1,20 @@ +// check-pass + +pub trait Deserialize<'de>: Sized {} +pub trait DeserializeOwned: for<'de> Deserialize<'de> {} + +pub trait Extensible { + type Config; +} + +// The `C` here generates a `C: Sized` candidate +pub trait Installer { + fn init>(&mut self) -> () + where + // This clause generates a `for<'de> C: Sized` candidate + B::Config: DeserializeOwned, + { + } +} + +fn main() {} From 40e2c346c632426346bcb8c06c40d465bbb78d55 Mon Sep 17 00:00:00 2001 From: Jack Huey <31162821+jackh726@users.noreply.github.com> Date: Thu, 6 May 2021 10:19:51 -0400 Subject: [PATCH 16/52] Pick candidate with fewer bound vars --- .../rustc_trait_selection/src/traits/select/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index c9ba8e6dc8ce7..727285e4927a0 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1366,11 +1366,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { && !other.value.skip_binder().has_escaping_bound_vars(); if value_same_except_bound_vars { // See issue #84398. In short, we can generate multiple ParamCandidates which are - // the same except for unused bound vars. Just pick the current one (the should - // both evaluate to the same answer). This is probably best characterized as a - // "hack", since we might prefer to just do our best to *not* create essentially - // duplicate candidates in the first place. - true + // the same except for unused bound vars. Just pick the one with the fewest bound vars + // or the current one if tied (they should both evaluate to the same answer). This is + // probably best characterized as a "hack", since we might prefer to just do our + // best to *not* create essentially duplicate candidates in the first place. + other.value.bound_vars().len() <= victim.value.bound_vars().len() } else if other.value == victim.value && victim.constness == Constness::NotConst { // Drop otherwise equivalent non-const candidates in favor of const candidates. true From 8c48c6e8ab841f980b015870aff8ccd72974d820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 1 May 2021 17:18:04 -0700 Subject: [PATCH 17/52] Account for unsatisfied bounds in E0599 Fix #84769, follow up to #84499, #83667. --- .../rustc_typeck/src/check/method/suggest.rs | 6 +++++- .../import-trait-for-method-call.rs | 9 ++++++++- .../import-trait-for-method-call.stderr | 18 +++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index 73e35f0171aa7..b2e4e7a981d20 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -579,6 +579,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } let mut restrict_type_params = false; + let mut unsatisfied_bounds = false; if !unsatisfied_predicates.is_empty() { let def_span = |def_id| { self.tcx.sess.source_map().guess_head_span(self.tcx.def_span(def_id)) @@ -739,6 +740,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err.note(&format!( "the following trait bounds were not satisfied:\n{bound_list}" )); + unsatisfied_bounds = true; } } @@ -752,6 +754,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { source, out_of_scope_traits, &unsatisfied_predicates, + unsatisfied_bounds, ); } @@ -984,9 +987,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { source: SelfSource<'tcx>, valid_out_of_scope_traits: Vec, unsatisfied_predicates: &[(ty::Predicate<'tcx>, Option>)], + unsatisfied_bounds: bool, ) { let mut alt_rcvr_sugg = false; - if let SelfSource::MethodCall(rcvr) = source { + if let (SelfSource::MethodCall(rcvr), false) = (source, unsatisfied_bounds) { debug!(?span, ?item_name, ?rcvr_ty, ?rcvr); let skippable = [ self.tcx.lang_items().clone_trait(), diff --git a/src/test/ui/suggestions/import-trait-for-method-call.rs b/src/test/ui/suggestions/import-trait-for-method-call.rs index 646f68dea14e8..4dbadbdf98206 100644 --- a/src/test/ui/suggestions/import-trait-for-method-call.rs +++ b/src/test/ui/suggestions/import-trait-for-method-call.rs @@ -6,4 +6,11 @@ fn next_u64() -> u64 { h.finish() //~ ERROR no method named `finish` found for struct `DefaultHasher` } -fn main() {} +trait Bar {} +impl Bar for String {} + +fn main() { + let s = String::from("hey"); + let x: &dyn Bar = &s; + x.as_ref(); //~ ERROR the method `as_ref` exists for reference `&dyn Bar`, but its trait bounds +} diff --git a/src/test/ui/suggestions/import-trait-for-method-call.stderr b/src/test/ui/suggestions/import-trait-for-method-call.stderr index f3ae20552f3d5..a2b9b9d14ab09 100644 --- a/src/test/ui/suggestions/import-trait-for-method-call.stderr +++ b/src/test/ui/suggestions/import-trait-for-method-call.stderr @@ -15,6 +15,22 @@ help: the following trait is implemented but not in scope; perhaps add a `use` f LL | use std::hash::Hasher; | -error: aborting due to previous error +error[E0599]: the method `as_ref` exists for reference `&dyn Bar`, but its trait bounds were not satisfied + --> $DIR/import-trait-for-method-call.rs:15:7 + | +LL | trait Bar {} + | --------- doesn't satisfy `dyn Bar: AsRef<_>` +... +LL | x.as_ref(); + | ^^^^^^ method cannot be called on `&dyn Bar` due to unsatisfied trait bounds + | + = note: the following trait bounds were not satisfied: + `dyn Bar: AsRef<_>` + which is required by `&dyn Bar: AsRef<_>` + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `as_ref`, perhaps you need to implement it: + candidate #1: `AsRef` + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0599`. From 0013b4442f1c4f89c3683a8fda06555494e0cee7 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Thu, 6 May 2021 18:08:57 +0200 Subject: [PATCH 18/52] bump stage0 to production 1.52.0 --- src/stage0.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stage0.txt b/src/stage0.txt index 3a76177474908..231e66719d00a 100644 --- a/src/stage0.txt +++ b/src/stage0.txt @@ -12,7 +12,7 @@ # stable release's version number. `date` is the date where the release we're # bootstrapping off was released. -date: 2021-05-04 +date: 2021-05-06 rustc: 1.52.0 # We use a nightly rustfmt to format the source because it solves some @@ -39,4 +39,4 @@ rustc: 1.52.0 # looking at a beta source tarball and it's uncommented we'll shortly comment it # out. -dev: 1 +#dev: 1 From 5a2dbd0f505afdcefb1cc102be9c448ae0c87d21 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Mon, 17 May 2021 12:03:49 +0200 Subject: [PATCH 19/52] backport 1.52.1 release notes --- RELEASES.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index 1f940e6bc2d3b..9767ba33eaa65 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,24 @@ +Version 1.52.1 (2021-05-10) +============================ + +This release disables incremental compilation, unless the user has explicitly +opted in via the newly added RUSTC_FORCE_INCREMENTAL=1 environment variable. + +This is due to the widespread, and frequently occuring, breakage encountered by +Rust users due to newly enabled incremental verification in 1.52.0. Notably, +Rust users **should** upgrade to 1.52.0 or 1.52.1: the bugs that are detected by +newly added incremental verification are still present in past stable versions, +and are not yet fixed on any channel. These bugs can lead to miscompilation of +Rust binaries. + +These problems only affect incremental builds, so release builds with Cargo +should not be affected unless the user has explicitly opted into incremental. +Debug and check builds are affected. + +See [84970] for more details. + +[84970]: https://github.com/rust-lang/rust/issues/84970 + Version 1.52.0 (2021-05-06) ============================ From 586b51a78a8d63026d202d51a0735825f38daf74 Mon Sep 17 00:00:00 2001 From: The8472 Date: Sat, 15 May 2021 20:08:09 +0200 Subject: [PATCH 20/52] remove InPlaceIterable marker from Peekable due to unsoundness The unsoundness is not in Peekable per se, it rather is due to the interaction between Peekable being able to hold an extra item and vec::IntoIter's clone implementation shortening the allocation. An alternative solution would be to change IntoIter's clone implementation to keep enough spare capacity available. --- library/alloc/benches/vec.rs | 1 - library/alloc/tests/vec.rs | 1 - library/core/src/iter/adapters/peekable.rs | 5 +---- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/library/alloc/benches/vec.rs b/library/alloc/benches/vec.rs index 48709e89823d8..c9bdcaa78f391 100644 --- a/library/alloc/benches/vec.rs +++ b/library/alloc/benches/vec.rs @@ -468,7 +468,6 @@ fn bench_in_place_recycle(b: &mut Bencher) { .enumerate() .map(|(idx, e)| idx.wrapping_add(e)) .fuse() - .peekable() .collect::>(), ); }); diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index 4dcc5d30debf7..aa606cd23158a 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -1002,7 +1002,6 @@ fn test_from_iter_specialization_with_iterator_adapters() { .zip(std::iter::repeat(1usize)) .map(|(a, b)| a + b) .map_while(Option::Some) - .peekable() .skip(1) .map(|e| if e != usize::MAX { Ok(std::num::NonZeroUsize::new(e)) } else { Err(()) }); assert_in_place_trait(&iter); diff --git a/library/core/src/iter/adapters/peekable.rs b/library/core/src/iter/adapters/peekable.rs index 21386e28a9643..0d860aec49a0e 100644 --- a/library/core/src/iter/adapters/peekable.rs +++ b/library/core/src/iter/adapters/peekable.rs @@ -1,4 +1,4 @@ -use crate::iter::{adapters::SourceIter, FusedIterator, InPlaceIterable, TrustedLen}; +use crate::iter::{adapters::SourceIter, FusedIterator, TrustedLen}; use crate::ops::Try; /// An iterator with a `peek()` that returns an optional reference to the next @@ -333,6 +333,3 @@ where unsafe { SourceIter::as_inner(&mut self.iter) } } } - -#[unstable(issue = "none", feature = "inplace_iteration")] -unsafe impl InPlaceIterable for Peekable {} From c47274b2eb70aae802ed9022f5e4315044abd66e Mon Sep 17 00:00:00 2001 From: The8472 Date: Sat, 15 May 2021 20:41:15 +0200 Subject: [PATCH 21/52] add regression test --- library/alloc/tests/vec.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index aa606cd23158a..6c71cf924d2a3 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -1094,6 +1094,18 @@ fn test_from_iter_specialization_panic_during_drop_leaks() { } } +// regression test for issue #85322. Peekable previously implemented InPlaceIterable, +// but due to an interaction with IntoIter's current Clone implementation it failed to uphold +// the contract. +#[test] +fn test_collect_after_iterator_clone() { + let v = vec![0; 5]; + let mut i = v.into_iter().peekable(); + i.peek(); + let v = i.clone().collect::>(); + assert!(v.len() <= v.capacity()); +} + #[test] fn test_cow_from() { let borrowed: &[_] = &["borrowed", "(slice)"]; From ff346b98e291d58f3cb2433230d83929410ea1e9 Mon Sep 17 00:00:00 2001 From: the8472 Date: Sun, 16 May 2021 15:35:05 +0200 Subject: [PATCH 22/52] from review: more robust test This also checks the contents and not only the capacity in case IntoIter's clone implementation is changed to add capacity at the end. Extra capacity at the beginning would be needed to make InPlaceIterable work. Co-authored-by: Giacomo Stevanato --- library/alloc/tests/vec.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index 6c71cf924d2a3..ad69234403b9c 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -1100,12 +1100,12 @@ fn test_from_iter_specialization_panic_during_drop_leaks() { #[test] fn test_collect_after_iterator_clone() { let v = vec![0; 5]; - let mut i = v.into_iter().peekable(); + let mut i = v.into_iter().map(|i| i + 1).peekable(); i.peek(); let v = i.clone().collect::>(); + assert_eq!(v, [1, 1, 1, 1, 1]); assert!(v.len() <= v.capacity()); } - #[test] fn test_cow_from() { let borrowed: &[_] = &["borrowed", "(slice)"]; From 855a573d66aef0adc16be38cde97f1ffca325da1 Mon Sep 17 00:00:00 2001 From: Justus K Date: Fri, 14 May 2021 22:45:00 +0200 Subject: [PATCH 23/52] Call `initSidebarItems` in root module of crate --- src/librustdoc/html/render/mod.rs | 11 ++++++++--- src/librustdoc/html/render/write_shared.rs | 2 ++ src/librustdoc/html/static/sidebar-items.js | 1 + src/librustdoc/html/static_files.rs | 3 +++ 4 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 src/librustdoc/html/static/sidebar-items.js diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 15ce3740e05d4..ab500c165e60d 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1724,12 +1724,17 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) { ty = it.type_(), path = relpath ); + if parentlen == 0 { - // There is no sidebar-items.js beyond the crate root path - // FIXME maybe dynamic crate loading can be merged here + write!( + buffer, + "", + relpath, cx.shared.resource_suffix + ); } else { - write!(buffer, "", path = relpath); + write!(buffer, "", relpath); } + // Closes sidebar-elems div. buffer.write_str(""); } diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs index 8e10c696df05d..ea19501023a69 100644 --- a/src/librustdoc/html/render/write_shared.rs +++ b/src/librustdoc/html/render/write_shared.rs @@ -224,6 +224,8 @@ pub(super) fn write_shared( )?; write_minify("search.js", static_files::SEARCH_JS)?; write_minify("settings.js", static_files::SETTINGS_JS)?; + write_minify("sidebar-items.js", static_files::sidebar::ITEMS)?; + if cx.shared.include_sources { write_minify("source-script.js", static_files::sidebar::SOURCE_SCRIPT)?; } diff --git a/src/librustdoc/html/static/sidebar-items.js b/src/librustdoc/html/static/sidebar-items.js new file mode 100644 index 0000000000000..81172ba0d9280 --- /dev/null +++ b/src/librustdoc/html/static/sidebar-items.js @@ -0,0 +1 @@ +initSidebarItems({}); diff --git a/src/librustdoc/html/static_files.rs b/src/librustdoc/html/static_files.rs index 2b73bd5d52ee6..6b1e1e9622106 100644 --- a/src/librustdoc/html/static_files.rs +++ b/src/librustdoc/html/static_files.rs @@ -127,4 +127,7 @@ crate mod source_code_pro { crate mod sidebar { /// File script to handle sidebar. crate static SOURCE_SCRIPT: &str = include_str!("static/source-script.js"); + + /// Top Level sidebar items script which will load a sidebar without items. + crate static ITEMS: &str = include_str!("static/sidebar-items.js"); } From 5d1125d0833993679c95c3bb8d6fe37be2295d5d Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sat, 22 May 2021 15:28:47 -0400 Subject: [PATCH 24/52] Synchronize llvm to master commit --- src/llvm-project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/llvm-project b/src/llvm-project index b61c24f352130..5f67a5715771b 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit b61c24f3521303d442fa86fe691bc8e6acc15103 +Subproject commit 5f67a5715771b7d29e4713e8d68338602d216dcf From e68af1269106a79cb0e4383872adf7bfb0ad3baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 4 May 2021 08:41:40 -0700 Subject: [PATCH 25/52] Do not ICE on invalid const param When encountering a path that can't have generics, do not call `generics_of`. This would happen when writing something like `path::this_is_a_mod`. Fix #84831. --- compiler/rustc_typeck/src/collect/type_of.rs | 20 ++++++++++++++- src/test/ui/typeck/issue-84831.rs | 9 +++++++ src/test/ui/typeck/issue-84831.stderr | 26 ++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/typeck/issue-84831.rs create mode 100644 src/test/ui/typeck/issue-84831.stderr diff --git a/compiler/rustc_typeck/src/collect/type_of.rs b/compiler/rustc_typeck/src/collect/type_of.rs index 51d5f4ebe2bd2..97b6f5cf41211 100644 --- a/compiler/rustc_typeck/src/collect/type_of.rs +++ b/compiler/rustc_typeck/src/collect/type_of.rs @@ -191,7 +191,25 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option< Res::Def(DefKind::Ctor(..), def_id) => { tcx.generics_of(tcx.parent(def_id).unwrap()) } - Res::Def(_, def_id) => tcx.generics_of(def_id), + // Other `DefKind`s don't have generics and would ICE when calling + // `generics_of`. + Res::Def( + DefKind::Struct + | DefKind::Union + | DefKind::Enum + | DefKind::Variant + | DefKind::Trait + | DefKind::OpaqueTy + | DefKind::TyAlias + | DefKind::ForeignTy + | DefKind::TraitAlias + | DefKind::AssocTy + | DefKind::Fn + | DefKind::AssocFn + | DefKind::AssocConst + | DefKind::Impl, + def_id, + ) => tcx.generics_of(def_id), Res::Err => { tcx.sess.delay_span_bug(tcx.def_span(def_id), "anon const with Res::Err"); return None; diff --git a/src/test/ui/typeck/issue-84831.rs b/src/test/ui/typeck/issue-84831.rs new file mode 100644 index 0000000000000..c646f71072532 --- /dev/null +++ b/src/test/ui/typeck/issue-84831.rs @@ -0,0 +1,9 @@ +fn f() { + std::<0>; //~ ERROR expected value +} +fn j() { + std::<_ as _>; //~ ERROR expected value + //~^ ERROR expected one of `,` or `>`, found keyword `as` +} + +fn main () {} diff --git a/src/test/ui/typeck/issue-84831.stderr b/src/test/ui/typeck/issue-84831.stderr new file mode 100644 index 0000000000000..e3cce10a00fd1 --- /dev/null +++ b/src/test/ui/typeck/issue-84831.stderr @@ -0,0 +1,26 @@ +error: expected one of `,` or `>`, found keyword `as` + --> $DIR/issue-84831.rs:5:13 + | +LL | std::<_ as _>; + | ^^ expected one of `,` or `>` + | +help: expressions must be enclosed in braces to be used as const generic arguments + | +LL | std::<{ _ as _ }>; + | ^ ^ + +error[E0423]: expected value, found crate `std` + --> $DIR/issue-84831.rs:2:5 + | +LL | std::<0>; + | ^^^^^^^^ not a value + +error[E0423]: expected value, found crate `std` + --> $DIR/issue-84831.rs:5:5 + | +LL | std::<_ as _>; + | ^^^^^^^^^^^^^ not a value + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0423`. From d1e2499b3b5a5e3903c6e3b6d1e2a59f40f0ff00 Mon Sep 17 00:00:00 2001 From: Rich Kadel Date: Mon, 3 May 2021 08:47:43 -0700 Subject: [PATCH 26/52] Disallows `#![feature(no_coverage)]` on stable and beta using allow_internal_unstable (as recommended) Fixes: #84836 ```shell $ ./build/x86_64-unknown-linux-gnu/stage1/bin/rustc src/test/run-make-fulldeps/coverage/no_cov_crate.rs error[E0554]: `#![feature]` may not be used on the dev release channel --> src/test/run-make-fulldeps/coverage/no_cov_crate.rs:2:1 | 2 | #![feature(no_coverage)] | ^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error For more information about this error, try `rustc --explain E0554`. ``` --- .../src/deriving/cmp/eq.rs | 14 ++-------- compiler/rustc_feature/src/builtin_attrs.rs | 8 +----- compiler/rustc_typeck/src/collect.rs | 28 +------------------ library/core/src/cmp.rs | 5 ++-- library/core/src/lib.rs | 1 + .../expected_show_coverage.no_cov_func.txt | 19 ------------- .../run-make-fulldeps/coverage/no_cov_func.rs | 18 ------------ .../feature-gates/feature-gate-no_coverage.rs | 13 ++++++--- .../feature-gate-no_coverage.stderr | 3 +- 9 files changed, 18 insertions(+), 91 deletions(-) delete mode 100644 src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.no_cov_func.txt delete mode 100644 src/test/run-make-fulldeps/coverage/no_cov_func.rs diff --git a/compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs b/compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs index 5a4e7fd9d07b4..54ab88dc3ffc9 100644 --- a/compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs +++ b/compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs @@ -15,20 +15,12 @@ pub fn expand_deriving_eq( item: &Annotatable, push: &mut dyn FnMut(Annotatable), ) { + let span = cx.with_def_site_ctxt(span); let inline = cx.meta_word(span, sym::inline); - let no_coverage_ident = - rustc_ast::attr::mk_nested_word_item(Ident::new(sym::no_coverage, span)); - let no_coverage_feature = - rustc_ast::attr::mk_list_item(Ident::new(sym::feature, span), vec![no_coverage_ident]); - let no_coverage = cx.meta_word(span, sym::no_coverage); let hidden = rustc_ast::attr::mk_nested_word_item(Ident::new(sym::hidden, span)); let doc = rustc_ast::attr::mk_list_item(Ident::new(sym::doc, span), vec![hidden]); - let attrs = vec![ - cx.attribute(inline), - cx.attribute(no_coverage_feature), - cx.attribute(no_coverage), - cx.attribute(doc), - ]; + let no_coverage = cx.meta_word(span, sym::no_coverage); + let attrs = vec![cx.attribute(inline), cx.attribute(doc), cx.attribute(no_coverage)]; let trait_def = TraitDef { span, attributes: Vec::new(), diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 5474fea9c7857..a8719be84c2a4 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -273,13 +273,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ template!(List: "address, memory, thread"), experimental!(no_sanitize) ), - ungated!( - // Not exclusively gated at the crate level (though crate-level is - // supported). The feature can alternatively be enabled on individual - // functions. - no_coverage, AssumedUsed, - template!(Word), - ), + gated!(no_coverage, AssumedUsed, template!(Word), experimental!(no_coverage)), // FIXME: #14408 assume docs are used since rustdoc looks at them. ungated!(doc, AssumedUsed, template!(List: "hidden|inline|...", NameValueStr: "string")), diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 190c9d35934f9..0528f8812f920 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -2661,8 +2661,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs { let mut inline_span = None; let mut link_ordinal_span = None; let mut no_sanitize_span = None; - let mut no_coverage_feature_enabled = false; - let mut no_coverage_attr = None; for attr in attrs.iter() { if tcx.sess.check_name(attr, sym::cold) { codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD; @@ -2726,15 +2724,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs { codegen_fn_attrs.flags |= CodegenFnAttrFlags::NAKED; } else if tcx.sess.check_name(attr, sym::no_mangle) { codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE; - } else if attr.has_name(sym::feature) { - if let Some(list) = attr.meta_item_list() { - if list.iter().any(|nested_meta_item| nested_meta_item.has_name(sym::no_coverage)) { - tcx.sess.mark_attr_used(attr); - no_coverage_feature_enabled = true; - } - } } else if tcx.sess.check_name(attr, sym::no_coverage) { - no_coverage_attr = Some(attr); + codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_COVERAGE; } else if tcx.sess.check_name(attr, sym::rustc_std_internal_symbol) { codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL; } else if tcx.sess.check_name(attr, sym::used) { @@ -2945,23 +2936,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs { } } - if let Some(no_coverage_attr) = no_coverage_attr { - if tcx.sess.features_untracked().no_coverage || no_coverage_feature_enabled { - codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_COVERAGE - } else { - let mut err = feature_err( - &tcx.sess.parse_sess, - sym::no_coverage, - no_coverage_attr.span, - "the `#[no_coverage]` attribute is an experimental feature", - ); - if tcx.sess.parse_sess.unstable_features.is_nightly_build() { - err.help("or, alternatively, add `#[feature(no_coverage)]` to the function"); - } - err.emit(); - } - } - codegen_fn_attrs.inline = attrs.iter().fold(InlineAttr::None, |ia, attr| { if !attr.has_name(sym::inline) { return ia; diff --git a/library/core/src/cmp.rs b/library/core/src/cmp.rs index 0a3e5789e8bed..f8b16b6f9275c 100644 --- a/library/core/src/cmp.rs +++ b/library/core/src/cmp.rs @@ -274,8 +274,7 @@ pub trait Eq: PartialEq { // // This should never be implemented by hand. #[doc(hidden)] - #[cfg_attr(not(bootstrap), feature(no_coverage))] - #[cfg_attr(not(bootstrap), no_coverage)] + #[cfg_attr(not(bootstrap), no_coverage)] // rust-lang/rust#84605 #[inline] #[stable(feature = "rust1", since = "1.0.0")] fn assert_receiver_is_total_eq(&self) {} @@ -284,7 +283,7 @@ pub trait Eq: PartialEq { /// Derive macro generating an impl of the trait `Eq`. #[rustc_builtin_macro] #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] -#[allow_internal_unstable(core_intrinsics, derive_eq, structural_match)] +#[allow_internal_unstable(core_intrinsics, derive_eq, structural_match, no_coverage)] pub macro Eq($item:item) { /* compiler built-in */ } diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 0e2c140c367a9..d1329b8f22116 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -166,6 +166,7 @@ #![feature(const_caller_location)] #![feature(slice_ptr_get)] #![feature(no_niche)] // rust-lang/rust#68303 +#![cfg_attr(not(bootstrap), feature(no_coverage))] // rust-lang/rust#84605 #![feature(int_error_matching)] #![deny(unsafe_op_in_unsafe_fn)] diff --git a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.no_cov_func.txt b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.no_cov_func.txt deleted file mode 100644 index 16eaf7c858c19..0000000000000 --- a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.no_cov_func.txt +++ /dev/null @@ -1,19 +0,0 @@ - 1| |// Enables `no_coverage` on individual functions - 2| | - 3| |#[feature(no_coverage)] - 4| |#[no_coverage] - 5| |fn do_not_add_coverage_1() { - 6| | println!("called but not covered"); - 7| |} - 8| | - 9| |#[no_coverage] - 10| |#[feature(no_coverage)] - 11| |fn do_not_add_coverage_2() { - 12| | println!("called but not covered"); - 13| |} - 14| | - 15| 1|fn main() { - 16| 1| do_not_add_coverage_1(); - 17| 1| do_not_add_coverage_2(); - 18| 1|} - diff --git a/src/test/run-make-fulldeps/coverage/no_cov_func.rs b/src/test/run-make-fulldeps/coverage/no_cov_func.rs deleted file mode 100644 index e19a2c4a87200..0000000000000 --- a/src/test/run-make-fulldeps/coverage/no_cov_func.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Enables `no_coverage` on individual functions - -#[feature(no_coverage)] -#[no_coverage] -fn do_not_add_coverage_1() { - println!("called but not covered"); -} - -#[no_coverage] -#[feature(no_coverage)] -fn do_not_add_coverage_2() { - println!("called but not covered"); -} - -fn main() { - do_not_add_coverage_1(); - do_not_add_coverage_2(); -} diff --git a/src/test/ui/feature-gates/feature-gate-no_coverage.rs b/src/test/ui/feature-gates/feature-gate-no_coverage.rs index c6b79f9a43171..fd4c6f76059aa 100644 --- a/src/test/ui/feature-gates/feature-gate-no_coverage.rs +++ b/src/test/ui/feature-gates/feature-gate-no_coverage.rs @@ -1,8 +1,13 @@ #![crate_type = "lib"] -#[no_coverage] -#[feature(no_coverage)] // does not have to be enabled before `#[no_coverage]` -fn no_coverage_is_enabled_on_this_function() {} +#[derive(PartialEq, Eq)] // ensure deriving `Eq` does not enable `feature(no_coverage)` +struct Foo { + a: u8, + b: u32, +} #[no_coverage] //~ ERROR the `#[no_coverage]` attribute is an experimental feature -fn requires_feature_no_coverage() {} +fn requires_feature_no_coverage() -> bool { + let bar = Foo { a: 0, b: 0 }; + bar == Foo { a: 0, b: 0 } +} diff --git a/src/test/ui/feature-gates/feature-gate-no_coverage.stderr b/src/test/ui/feature-gates/feature-gate-no_coverage.stderr index 04627be4aaf65..f7167e0b771c0 100644 --- a/src/test/ui/feature-gates/feature-gate-no_coverage.stderr +++ b/src/test/ui/feature-gates/feature-gate-no_coverage.stderr @@ -1,12 +1,11 @@ error[E0658]: the `#[no_coverage]` attribute is an experimental feature - --> $DIR/feature-gate-no_coverage.rs:7:1 + --> $DIR/feature-gate-no_coverage.rs:9:1 | LL | #[no_coverage] | ^^^^^^^^^^^^^^ | = note: see issue #84605 for more information = help: add `#![feature(no_coverage)]` to the crate attributes to enable - = help: or, alternatively, add `#[feature(no_coverage)]` to the function error: aborting due to previous error From c297d1e61bde36b840172a44b9fc6b97a37be6d6 Mon Sep 17 00:00:00 2001 From: Mohsen Zohrevandi Date: Wed, 21 Apr 2021 13:45:57 -0700 Subject: [PATCH 27/52] Ensure TLS destructors run before thread joins in SGX --- library/std/src/sys/sgx/abi/mod.rs | 6 ++- library/std/src/sys/sgx/thread.rs | 69 +++++++++++++++++++++++---- library/std/src/thread/local/tests.rs | 55 ++++++++++++++++++++- 3 files changed, 119 insertions(+), 11 deletions(-) diff --git a/library/std/src/sys/sgx/abi/mod.rs b/library/std/src/sys/sgx/abi/mod.rs index a5e453034762c..f9536c4203df2 100644 --- a/library/std/src/sys/sgx/abi/mod.rs +++ b/library/std/src/sys/sgx/abi/mod.rs @@ -62,10 +62,12 @@ unsafe extern "C" fn tcs_init(secondary: bool) { extern "C" fn entry(p1: u64, p2: u64, p3: u64, secondary: bool, p4: u64, p5: u64) -> EntryReturn { // FIXME: how to support TLS in library mode? let tls = Box::new(tls::Tls::new()); - let _tls_guard = unsafe { tls.activate() }; + let tls_guard = unsafe { tls.activate() }; if secondary { - super::thread::Thread::entry(); + let join_notifier = super::thread::Thread::entry(); + drop(tls_guard); + drop(join_notifier); EntryReturn(0, 0) } else { diff --git a/library/std/src/sys/sgx/thread.rs b/library/std/src/sys/sgx/thread.rs index 55ef460cc90c5..67e2e8b59d397 100644 --- a/library/std/src/sys/sgx/thread.rs +++ b/library/std/src/sys/sgx/thread.rs @@ -9,26 +9,37 @@ pub struct Thread(task_queue::JoinHandle); pub const DEFAULT_MIN_STACK_SIZE: usize = 4096; +pub use self::task_queue::JoinNotifier; + mod task_queue { - use crate::sync::mpsc; + use super::wait_notify; use crate::sync::{Mutex, MutexGuard, Once}; - pub type JoinHandle = mpsc::Receiver<()>; + pub type JoinHandle = wait_notify::Waiter; + + pub struct JoinNotifier(Option); + + impl Drop for JoinNotifier { + fn drop(&mut self) { + self.0.take().unwrap().notify(); + } + } pub(super) struct Task { p: Box, - done: mpsc::Sender<()>, + done: JoinNotifier, } impl Task { pub(super) fn new(p: Box) -> (Task, JoinHandle) { - let (done, recv) = mpsc::channel(); + let (done, recv) = wait_notify::new(); + let done = JoinNotifier(Some(done)); (Task { p, done }, recv) } - pub(super) fn run(self) { + pub(super) fn run(self) -> JoinNotifier { (self.p)(); - let _ = self.done.send(()); + self.done } } @@ -47,6 +58,48 @@ mod task_queue { } } +/// This module provides a synchronization primitive that does not use thread +/// local variables. This is needed for signaling that a thread has finished +/// execution. The signal is sent once all TLS destructors have finished at +/// which point no new thread locals should be created. +pub mod wait_notify { + use super::super::waitqueue::{SpinMutex, WaitQueue, WaitVariable}; + use crate::sync::Arc; + + pub struct Notifier(Arc>>); + + impl Notifier { + /// Notify the waiter. The waiter is either notified right away (if + /// currently blocked in `Waiter::wait()`) or later when it calls the + /// `Waiter::wait()` method. + pub fn notify(self) { + let mut guard = self.0.lock(); + *guard.lock_var_mut() = true; + let _ = WaitQueue::notify_one(guard); + } + } + + pub struct Waiter(Arc>>); + + impl Waiter { + /// Wait for a notification. If `Notifier::notify()` has already been + /// called, this will return immediately, otherwise the current thread + /// is blocked until notified. + pub fn wait(self) { + let guard = self.0.lock(); + if *guard.lock_var() { + return; + } + WaitQueue::wait(guard, || {}); + } + } + + pub fn new() -> (Notifier, Waiter) { + let inner = Arc::new(SpinMutex::new(WaitVariable::new(false))); + (Notifier(inner.clone()), Waiter(inner)) + } +} + impl Thread { // unsafe: see thread::Builder::spawn_unchecked for safety requirements pub unsafe fn new(_stack: usize, p: Box) -> io::Result { @@ -57,7 +110,7 @@ impl Thread { Ok(Thread(handle)) } - pub(super) fn entry() { + pub(super) fn entry() -> JoinNotifier { let mut pending_tasks = task_queue::lock(); let task = rtunwrap!(Some, pending_tasks.pop()); drop(pending_tasks); // make sure to not hold the task queue lock longer than necessary @@ -78,7 +131,7 @@ impl Thread { } pub fn join(self) { - let _ = self.0.recv(); + self.0.wait(); } } diff --git a/library/std/src/thread/local/tests.rs b/library/std/src/thread/local/tests.rs index 80e6798d847b1..98f525eafb0f6 100644 --- a/library/std/src/thread/local/tests.rs +++ b/library/std/src/thread/local/tests.rs @@ -1,5 +1,6 @@ use crate::cell::{Cell, UnsafeCell}; -use crate::sync::mpsc::{channel, Sender}; +use crate::sync::atomic::{AtomicBool, Ordering}; +use crate::sync::mpsc::{self, channel, Sender}; use crate::thread::{self, LocalKey}; use crate::thread_local; @@ -207,3 +208,55 @@ fn dtors_in_dtors_in_dtors_const_init() { }); rx.recv().unwrap(); } + +// This test tests that TLS destructors have run before the thread joins. The +// test has no false positives (meaning: if the test fails, there's actually +// an ordering problem). It may have false negatives, where the test passes but +// join is not guaranteed to be after the TLS destructors. However, false +// negatives should be exceedingly rare due to judicious use of +// thread::yield_now and running the test several times. +#[test] +fn join_orders_after_tls_destructors() { + static THREAD2_LAUNCHED: AtomicBool = AtomicBool::new(false); + + for _ in 0..10 { + let (tx, rx) = mpsc::sync_channel(0); + THREAD2_LAUNCHED.store(false, Ordering::SeqCst); + + let jh = thread::spawn(move || { + struct RecvOnDrop(Cell>>); + + impl Drop for RecvOnDrop { + fn drop(&mut self) { + let rx = self.0.take().unwrap(); + while !THREAD2_LAUNCHED.load(Ordering::SeqCst) { + thread::yield_now(); + } + rx.recv().unwrap(); + } + } + + thread_local! { + static TL_RX: RecvOnDrop = RecvOnDrop(Cell::new(None)); + } + + TL_RX.with(|v| v.0.set(Some(rx))) + }); + + let tx_clone = tx.clone(); + let jh2 = thread::spawn(move || { + THREAD2_LAUNCHED.store(true, Ordering::SeqCst); + jh.join().unwrap(); + tx_clone.send(()).expect_err( + "Expecting channel to be closed because thread 1 TLS destructors must've run", + ); + }); + + while !THREAD2_LAUNCHED.load(Ordering::SeqCst) { + thread::yield_now(); + } + thread::yield_now(); + tx.send(()).expect("Expecting channel to be live because thread 2 must block on join"); + jh2.join().unwrap(); + } +} From 5d1fdf44a996a71015a1e086f060e9ef36f987d6 Mon Sep 17 00:00:00 2001 From: Mohsen Zohrevandi Date: Thu, 29 Apr 2021 08:44:45 -0700 Subject: [PATCH 28/52] Use atomics in join_orders_after_tls_destructors test std::sync::mpsc uses thread locals and depending on the order TLS dtors are run `rx.recv()` can panic when used in a TLS dtor. --- library/std/src/thread/local/tests.rs | 122 +++++++++++++++++++------- 1 file changed, 88 insertions(+), 34 deletions(-) diff --git a/library/std/src/thread/local/tests.rs b/library/std/src/thread/local/tests.rs index 98f525eafb0f6..494ad4e5fda9a 100644 --- a/library/std/src/thread/local/tests.rs +++ b/library/std/src/thread/local/tests.rs @@ -1,6 +1,6 @@ use crate::cell::{Cell, UnsafeCell}; -use crate::sync::atomic::{AtomicBool, Ordering}; -use crate::sync::mpsc::{self, channel, Sender}; +use crate::sync::atomic::{AtomicU8, Ordering}; +use crate::sync::mpsc::{channel, Sender}; use crate::thread::{self, LocalKey}; use crate::thread_local; @@ -217,46 +217,100 @@ fn dtors_in_dtors_in_dtors_const_init() { // thread::yield_now and running the test several times. #[test] fn join_orders_after_tls_destructors() { - static THREAD2_LAUNCHED: AtomicBool = AtomicBool::new(false); + // We emulate a synchronous MPSC rendezvous channel using only atomics and + // thread::yield_now. We can't use std::mpsc as the implementation itself + // may rely on thread locals. + // + // The basic state machine for an SPSC rendezvous channel is: + // FRESH -> THREAD1_WAITING -> MAIN_THREAD_RENDEZVOUS + // where the first transition is done by the “receiving” thread and the 2nd + // transition is done by the “sending” thread. + // + // We add an additional state `THREAD2_LAUNCHED` between `FRESH` and + // `THREAD1_WAITING` to block until all threads are actually running. + // + // A thread that joins on the “receiving” thread completion should never + // observe the channel in the `THREAD1_WAITING` state. If this does occur, + // we switch to the “poison” state `THREAD2_JOINED` and panic all around. + // (This is equivalent to “sending” from an alternate producer thread.) + const FRESH: u8 = 0; + const THREAD2_LAUNCHED: u8 = 1; + const THREAD1_WAITING: u8 = 2; + const MAIN_THREAD_RENDEZVOUS: u8 = 3; + const THREAD2_JOINED: u8 = 4; + static SYNC_STATE: AtomicU8 = AtomicU8::new(FRESH); for _ in 0..10 { - let (tx, rx) = mpsc::sync_channel(0); - THREAD2_LAUNCHED.store(false, Ordering::SeqCst); + SYNC_STATE.store(FRESH, Ordering::SeqCst); + + let jh = thread::Builder::new() + .name("thread1".into()) + .spawn(move || { + struct TlDrop; + + impl Drop for TlDrop { + fn drop(&mut self) { + loop { + match SYNC_STATE.load(Ordering::SeqCst) { + FRESH => thread::yield_now(), + THREAD2_LAUNCHED => break, + v => unreachable!("sync state: {}", v), + } + } + let mut sync_state = SYNC_STATE.swap(THREAD1_WAITING, Ordering::SeqCst); + loop { + match sync_state { + THREAD2_LAUNCHED | THREAD1_WAITING => thread::yield_now(), + MAIN_THREAD_RENDEZVOUS => break, + THREAD2_JOINED => panic!( + "Thread 1 still running after thread 2 joined on thread 1" + ), + v => unreachable!("sync state: {}", v), + } + sync_state = SYNC_STATE.load(Ordering::SeqCst); + } + } + } - let jh = thread::spawn(move || { - struct RecvOnDrop(Cell>>); + thread_local! { + static TL_DROP: TlDrop = TlDrop; + } - impl Drop for RecvOnDrop { - fn drop(&mut self) { - let rx = self.0.take().unwrap(); - while !THREAD2_LAUNCHED.load(Ordering::SeqCst) { - thread::yield_now(); + TL_DROP.with(|_| {}) + }) + .unwrap(); + + let jh2 = thread::Builder::new() + .name("thread2".into()) + .spawn(move || { + assert_eq!(SYNC_STATE.swap(THREAD2_LAUNCHED, Ordering::SeqCst), FRESH); + jh.join().unwrap(); + match SYNC_STATE.swap(THREAD2_JOINED, Ordering::SeqCst) { + MAIN_THREAD_RENDEZVOUS => return, + THREAD2_LAUNCHED | THREAD1_WAITING => { + panic!("Thread 2 running after thread 1 join before main thread rendezvous") } - rx.recv().unwrap(); + v => unreachable!("sync state: {:?}", v), } + }) + .unwrap(); + + loop { + match SYNC_STATE.compare_exchange_weak( + THREAD1_WAITING, + MAIN_THREAD_RENDEZVOUS, + Ordering::SeqCst, + Ordering::SeqCst, + ) { + Ok(_) => break, + Err(FRESH) => thread::yield_now(), + Err(THREAD2_LAUNCHED) => thread::yield_now(), + Err(THREAD2_JOINED) => { + panic!("Main thread rendezvous after thread 2 joined thread 1") + } + v => unreachable!("sync state: {:?}", v), } - - thread_local! { - static TL_RX: RecvOnDrop = RecvOnDrop(Cell::new(None)); - } - - TL_RX.with(|v| v.0.set(Some(rx))) - }); - - let tx_clone = tx.clone(); - let jh2 = thread::spawn(move || { - THREAD2_LAUNCHED.store(true, Ordering::SeqCst); - jh.join().unwrap(); - tx_clone.send(()).expect_err( - "Expecting channel to be closed because thread 1 TLS destructors must've run", - ); - }); - - while !THREAD2_LAUNCHED.load(Ordering::SeqCst) { - thread::yield_now(); } - thread::yield_now(); - tx.send(()).expect("Expecting channel to be live because thread 2 must block on join"); jh2.join().unwrap(); } } From 0e49ff0cb041fec36df8b17209b4655424d5e184 Mon Sep 17 00:00:00 2001 From: Mohsen Zohrevandi Date: Thu, 6 May 2021 09:36:26 -0700 Subject: [PATCH 29/52] join_orders_after_tls_destructors: ensure thread 2 is launched before thread 1 enters TLS destructors --- library/std/src/thread/local/tests.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/library/std/src/thread/local/tests.rs b/library/std/src/thread/local/tests.rs index 494ad4e5fda9a..f33d612961931 100644 --- a/library/std/src/thread/local/tests.rs +++ b/library/std/src/thread/local/tests.rs @@ -250,13 +250,6 @@ fn join_orders_after_tls_destructors() { impl Drop for TlDrop { fn drop(&mut self) { - loop { - match SYNC_STATE.load(Ordering::SeqCst) { - FRESH => thread::yield_now(), - THREAD2_LAUNCHED => break, - v => unreachable!("sync state: {}", v), - } - } let mut sync_state = SYNC_STATE.swap(THREAD1_WAITING, Ordering::SeqCst); loop { match sync_state { @@ -276,7 +269,15 @@ fn join_orders_after_tls_destructors() { static TL_DROP: TlDrop = TlDrop; } - TL_DROP.with(|_| {}) + TL_DROP.with(|_| {}); + + loop { + match SYNC_STATE.load(Ordering::SeqCst) { + FRESH => thread::yield_now(), + THREAD2_LAUNCHED => break, + v => unreachable!("sync state: {}", v), + } + } }) .unwrap(); From 75dc9638a84281262fb316b7581c1015bc7d1eed Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 21 May 2021 14:55:09 -0400 Subject: [PATCH 30/52] Revert portion of PR #83521 that injected issue #85435 (and thus exposed underlying issue #85561). --- .../src/build/expr/as_rvalue.rs | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs index 822fbd91c947e..689b27150e9ed 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs @@ -179,20 +179,26 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // match x { _ => () } // fake read of `x` // }; // ``` - for (thir_place, cause, hir_id) in fake_reads.into_iter() { - let place_builder = unpack!(block = this.as_place_builder(block, thir_place)); - - if let Ok(place_builder_resolved) = - place_builder.try_upvars_resolved(this.tcx, this.typeck_results) - { - let mir_place = - place_builder_resolved.into_place(this.tcx, this.typeck_results); - this.cfg.push_fake_read( - block, - this.source_info(this.tcx.hir().span(*hir_id)), - *cause, - mir_place, - ); + // + // FIXME(RFC2229, rust#85435): Remove feature gate once diagnostics are + // improved and unsafe checking works properly in closure bodies again. + if this.tcx.features().capture_disjoint_fields { + for (thir_place, cause, hir_id) in fake_reads.into_iter() { + let place_builder = + unpack!(block = this.as_place_builder(block, thir_place)); + + if let Ok(place_builder_resolved) = + place_builder.try_upvars_resolved(this.tcx, this.typeck_results) + { + let mir_place = + place_builder_resolved.into_place(this.tcx, this.typeck_results); + this.cfg.push_fake_read( + block, + this.source_info(this.tcx.hir().span(*hir_id)), + *cause, + mir_place, + ); + } } } From 355dc5cae201735da46e1bb7153e2e476255d88c Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 21 May 2021 15:05:53 -0400 Subject: [PATCH 31/52] Regression test for issue 85435. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apply suggestions from code review: 1. (removing confusing comment from my test, since the comment reflects the bad undesirable behavior that is being fixed here.) 2. test THIR unsafeck too. Co-authored-by: Léo Lanteri Thauvin --- ...fe-op-in-let-under-unsafe-under-closure.rs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/test/ui/unsafe/issue-85435-unsafe-op-in-let-under-unsafe-under-closure.rs diff --git a/src/test/ui/unsafe/issue-85435-unsafe-op-in-let-under-unsafe-under-closure.rs b/src/test/ui/unsafe/issue-85435-unsafe-op-in-let-under-unsafe-under-closure.rs new file mode 100644 index 0000000000000..72f7b67477712 --- /dev/null +++ b/src/test/ui/unsafe/issue-85435-unsafe-op-in-let-under-unsafe-under-closure.rs @@ -0,0 +1,27 @@ +// check-pass +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck + +// This is issue #85435. But the real story is reflected in issue #85561, where +// a bug in the implementation of feature(capture_disjoint_fields) () was +// exposed to non-feature-gated code by a diagnostic changing PR that removed +// the gating in one case. + +// This test is double-checking that the case of interest continues to work as +// expected in the *absence* of that feature gate. At the time of this writing, +// enabling the feature gate will cause this test to fail. We obviously cannot +// stabilize that feature until it can correctly handle this test. + +fn main() { + let val: u8 = 5; + let u8_ptr: *const u8 = &val; + let _closure = || { + unsafe { + let tmp = *u8_ptr; + tmp + + // Just dereferencing and returning directly compiles fine: + // *u8_ptr + } + }; +} From f9f5fc89267ab9ccc67a35d56d69e370d0852328 Mon Sep 17 00:00:00 2001 From: Felix S Klock II Date: Tue, 1 Jun 2021 14:43:16 -0400 Subject: [PATCH 32/52] no thir-unsafeck in beta remove testing via `-Z thir-unsafeck`, since it is not appropriate for beta branch. --- .../issue-85435-unsafe-op-in-let-under-unsafe-under-closure.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/ui/unsafe/issue-85435-unsafe-op-in-let-under-unsafe-under-closure.rs b/src/test/ui/unsafe/issue-85435-unsafe-op-in-let-under-unsafe-under-closure.rs index 72f7b67477712..b0d738855d731 100644 --- a/src/test/ui/unsafe/issue-85435-unsafe-op-in-let-under-unsafe-under-closure.rs +++ b/src/test/ui/unsafe/issue-85435-unsafe-op-in-let-under-unsafe-under-closure.rs @@ -1,6 +1,4 @@ // check-pass -// revisions: mir thir -// [thir]compile-flags: -Z thir-unsafeck // This is issue #85435. But the real story is reflected in issue #85561, where // a bug in the implementation of feature(capture_disjoint_fields) () was From bbd370cb25787abcacf49ec4411055a3dabfdae7 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 5 Jun 2021 22:16:40 +0200 Subject: [PATCH 33/52] Disable mutable noalias for Rust 1.53 --- compiler/rustc_codegen_llvm/src/abi.rs | 13 +++---------- src/test/codegen/function-arguments.rs | 6 +++--- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index 854e3ccc21b4f..fba5667784614 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -1,7 +1,6 @@ use crate::builder::Builder; use crate::context::CodegenCx; use crate::llvm::{self, AttributePlace}; -use crate::llvm_util; use crate::type_::Type; use crate::type_of::LayoutLlvmExt; use crate::value::Value; @@ -52,15 +51,9 @@ pub trait ArgAttributesExt { } fn should_use_mutable_noalias(cx: &CodegenCx<'_, '_>) -> bool { - // LLVM prior to version 12 has known miscompiles in the presence of - // noalias attributes (see #54878). Only enable mutable noalias by - // default for versions we believe to be safe. - cx.tcx - .sess - .opts - .debugging_opts - .mutable_noalias - .unwrap_or_else(|| llvm_util::get_version() >= (12, 0, 0)) + // While #84958 has been fixed, mutable noalias is not enabled by default + // in Rust 1.53 out of an abundance of caution. + cx.tcx.sess.opts.debugging_opts.mutable_noalias.unwrap_or(false) } impl ArgAttributesExt for ArgAttributes { diff --git a/src/test/codegen/function-arguments.rs b/src/test/codegen/function-arguments.rs index f936f90960346..7a8646c71b7f9 100644 --- a/src/test/codegen/function-arguments.rs +++ b/src/test/codegen/function-arguments.rs @@ -43,13 +43,13 @@ pub fn named_borrow<'r>(_: &'r i32) { pub fn unsafe_borrow(_: &UnsafeInner) { } -// CHECK: @mutable_unsafe_borrow(i16* noalias align 2 dereferenceable(2) %_1) +// CHECK: @mutable_unsafe_borrow(i16* align 2 dereferenceable(2) %_1) // ... unless this is a mutable borrow, those never alias #[no_mangle] pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) { } -// CHECK: @mutable_borrow(i32* noalias align 4 dereferenceable(4) %_1) +// CHECK: @mutable_borrow(i32* align 4 dereferenceable(4) %_1) // FIXME #25759 This should also have `nocapture` #[no_mangle] pub fn mutable_borrow(_: &mut i32) { @@ -94,7 +94,7 @@ pub fn helper(_: usize) { pub fn slice(_: &[u8]) { } -// CHECK: @mutable_slice([0 x i8]* noalias nonnull align 1 %_1.0, [[USIZE]] %_1.1) +// CHECK: @mutable_slice([0 x i8]* nonnull align 1 %_1.0, [[USIZE]] %_1.1) // FIXME #25759 This should also have `nocapture` #[no_mangle] pub fn mutable_slice(_: &mut [u8]) { From 849c075abc8802011f3bad1e2effeb8b28818366 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Mon, 3 May 2021 11:23:00 -0700 Subject: [PATCH 34/52] CI: Extract LLVM win64 installer directly, using 7z Currently, we have LLVM tarballs for win64, generated by someone running the installer via wine and tarring up the result. 7z knows how to extract NSIS installers directly, and the result is identical to our tarball, except that it doesn't include `Uninstall.exe` (which we don't care about) and it includes the NSIS plugin directory (which we also don't care about). This simplifies the process of upgrading CI, and allows us to just mirror the upstream release .exe directly. This also improves our supply chain. --- src/ci/scripts/install-clang.sh | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/ci/scripts/install-clang.sh b/src/ci/scripts/install-clang.sh index 8070e90f155df..a69e49b3f0800 100755 --- a/src/ci/scripts/install-clang.sh +++ b/src/ci/scripts/install-clang.sh @@ -42,23 +42,14 @@ elif isWindows && [[ ${CUSTOM_MINGW-0} -ne 1 ]]; then # clang has an output mode compatible with MinGW that we need. If it does we # should switch to clang for MinGW as well! # - # Note that the LLVM installer is an NSIS installer - # - # Original downloaded here came from: - # - # https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/LLVM-10.0.0-win64.exe - # - # That installer was run through `wine ./installer.exe /S /NCRC` on Linux - # and then the resulting installation directory (found in - # `$HOME/.wine/drive_c/Program Files/LLVM`) was packaged up into a tarball. - # We've had issues otherwise that the installer will randomly hang, provide - # not a lot of useful information, pollute global state, etc. In general the - # tarball is just more confined and easier to deal with when working with - # various CI environments. + # The LLVM installer is an NSIS installer, which we can extract with 7z. We + # don't want to run the installer directly; extracting it is more reliable + # in CI environments. - mkdir -p citools + mkdir -p citools/clang-rust cd citools - curl -f "${MIRRORS_BASE}/LLVM-${LLVM_VERSION}-win64.tar.gz" | tar xzf - + curl -f "${MIRRORS_BASE}/LLVM-${LLVM_VERSION}-win64.exe" -o "LLVM-${LLVM_VERSION}-win64.exe" + 7z x -oclang-rust/ "LLVM-${LLVM_VERSION}-win64.exe" ciCommandSetEnv RUST_CONFIGURE_ARGS \ "${RUST_CONFIGURE_ARGS} --set llvm.clang-cl=$(pwd)/clang-rust/bin/clang-cl.exe" fi From ff4c377dc1445b7d667197fa46da03247b78a4e0 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Mon, 3 May 2021 22:54:50 -0700 Subject: [PATCH 35/52] Update clang to 12.0.0 on Windows and macOS Needed for https://github.com/rust-lang/rust/pull/84764 . Tarballs already uploaded to the CI mirror bucket. --- src/ci/scripts/install-clang.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/scripts/install-clang.sh b/src/ci/scripts/install-clang.sh index a69e49b3f0800..8a30acc2e460f 100755 --- a/src/ci/scripts/install-clang.sh +++ b/src/ci/scripts/install-clang.sh @@ -9,7 +9,7 @@ IFS=$'\n\t' source "$(cd "$(dirname "$0")" && pwd)/../shared.sh" # Update both macOS's and Windows's tarballs when bumping the version here. -LLVM_VERSION="10.0.0" +LLVM_VERSION="12.0.0" if isMacOS; then # If the job selects a specific Xcode version, use that instead of From 4a887232dae8fad8eff8351dacd2b96d6246d560 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 4 Jun 2021 12:38:45 -0400 Subject: [PATCH 36/52] Revert effects of PRs 81167 and 83091. This is preparation for reverting 81238 for short-term resolution of issue 84297. --- library/core/src/mem/mod.rs | 6 ++---- library/core/src/ptr/mod.rs | 9 +++------ library/core/src/ptr/mut_ptr.rs | 3 +-- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index 5bf47c3951da2..c6750c52d16c8 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -682,8 +682,7 @@ pub unsafe fn uninitialized() -> T { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_swap", issue = "83163")] -pub const fn swap(x: &mut T, y: &mut T) { +pub fn swap(x: &mut T, y: &mut T) { // SAFETY: the raw pointers have been created from safe mutable references satisfying all the // constraints on `ptr::swap_nonoverlapping_one` unsafe { @@ -813,8 +812,7 @@ pub fn take(dest: &mut T) -> T { #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[must_use = "if you don't need the old value, you can just assign the new value directly"] -#[rustc_const_unstable(feature = "const_replace", issue = "83164")] -pub const fn replace(dest: &mut T, src: T) -> T { +pub fn replace(dest: &mut T, src: T) -> T { // SAFETY: We read from `dest` but directly write `src` into it afterwards, // such that the old value is not duplicated. Nothing is dropped and // nothing here can panic. diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index ad8696ab9272d..9eb7fa9973b3e 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -428,8 +428,7 @@ pub const unsafe fn swap_nonoverlapping(x: *mut T, y: *mut T, count: usize) { } #[inline] -#[rustc_const_unstable(feature = "const_swap", issue = "83163")] -pub(crate) const unsafe fn swap_nonoverlapping_one(x: *mut T, y: *mut T) { +pub(crate) unsafe fn swap_nonoverlapping_one(x: *mut T, y: *mut T) { // NOTE(eddyb) SPIR-V's Logical addressing model doesn't allow for arbitrary // reinterpretation of values as (chunkable) byte arrays, and the loop in the // block optimization in `swap_nonoverlapping_bytes` is hard to rewrite back @@ -562,8 +561,7 @@ const unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_replace", issue = "83164")] -pub const unsafe fn replace(dst: *mut T, mut src: T) -> T { +pub unsafe fn replace(dst: *mut T, mut src: T) -> T { // SAFETY: the caller must guarantee that `dst` is valid to be // cast to a mutable reference (valid for writes, aligned, initialized), // and cannot overlap `src` since `dst` must point to a distinct @@ -877,8 +875,7 @@ pub const unsafe fn read_unaligned(src: *const T) -> T { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_ptr_write", issue = "none")] -pub const unsafe fn write(dst: *mut T, src: T) { +pub unsafe fn write(dst: *mut T, src: T) { // SAFETY: the caller must guarantee that `dst` is valid for writes. // `dst` cannot overlap `src` because the caller has mutable access // to `dst` while `src` is owned by this function. diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 55c019c51d51b..16f6efc374500 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -1002,9 +1002,8 @@ impl *mut T { /// /// [`ptr::write`]: crate::ptr::write() #[stable(feature = "pointer_methods", since = "1.26.0")] - #[rustc_const_unstable(feature = "const_ptr_write", issue = "none")] #[inline] - pub const unsafe fn write(self, val: T) + pub unsafe fn write(self, val: T) where T: Sized, { From fd8c88a178433c77f648b52ccf8acbc5a63cd010 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 4 Jun 2021 16:43:57 -0400 Subject: [PATCH 37/52] Revert tests added by PR 81167. --- library/core/tests/const_ptr.rs | 50 --------------------------------- 1 file changed, 50 deletions(-) diff --git a/library/core/tests/const_ptr.rs b/library/core/tests/const_ptr.rs index 152fed803ecdb..4acd059ab03df 100644 --- a/library/core/tests/const_ptr.rs +++ b/library/core/tests/const_ptr.rs @@ -49,53 +49,3 @@ fn mut_ptr_read() { const UNALIGNED: u16 = unsafe { UNALIGNED_PTR.read_unaligned() }; assert_eq!(UNALIGNED, u16::from_ne_bytes([0x23, 0x45])); } - -#[test] -fn write() { - use core::ptr; - - const fn write_aligned() -> i32 { - let mut res = 0; - unsafe { - ptr::write(&mut res as *mut _, 42); - } - res - } - const ALIGNED: i32 = write_aligned(); - assert_eq!(ALIGNED, 42); - - const fn write_unaligned() -> [u16; 2] { - let mut two_aligned = [0u16; 2]; - unsafe { - let unaligned_ptr = (two_aligned.as_mut_ptr() as *mut u8).add(1) as *mut u16; - ptr::write_unaligned(unaligned_ptr, u16::from_ne_bytes([0x23, 0x45])); - } - two_aligned - } - const UNALIGNED: [u16; 2] = write_unaligned(); - assert_eq!(UNALIGNED, [u16::from_ne_bytes([0x00, 0x23]), u16::from_ne_bytes([0x45, 0x00])]); -} - -#[test] -fn mut_ptr_write() { - const fn aligned() -> i32 { - let mut res = 0; - unsafe { - (&mut res as *mut i32).write(42); - } - res - } - const ALIGNED: i32 = aligned(); - assert_eq!(ALIGNED, 42); - - const fn write_unaligned() -> [u16; 2] { - let mut two_aligned = [0u16; 2]; - unsafe { - let unaligned_ptr = (two_aligned.as_mut_ptr() as *mut u8).add(1) as *mut u16; - unaligned_ptr.write_unaligned(u16::from_ne_bytes([0x23, 0x45])); - } - two_aligned - } - const UNALIGNED: [u16; 2] = write_unaligned(); - assert_eq!(UNALIGNED, [u16::from_ne_bytes([0x00, 0x23]), u16::from_ne_bytes([0x45, 0x00])]); -} From f4f535bfef81a52b23462ba8c34168fcb8990557 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 4 Jun 2021 15:22:52 -0400 Subject: [PATCH 38/52] Revert PRs 81238 and 82967 (which made copy and copy_nonoverlapping intrinsics). This is to address issue 84297. --- library/core/src/intrinsics.rs | 337 +++++++++++++---------- library/core/src/ptr/mod.rs | 7 +- src/test/ui/consts/copy-intrinsic.rs | 45 --- src/test/ui/consts/copy-intrinsic.stderr | 69 ----- 4 files changed, 192 insertions(+), 266 deletions(-) delete mode 100644 src/test/ui/consts/copy-intrinsic.rs delete mode 100644 src/test/ui/consts/copy-intrinsic.stderr diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 1ba0b23ae5be3..175fc2e04c685 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -1742,157 +1742,6 @@ extern "rust-intrinsic" { /// Allocate at compile time. Should not be called at runtime. #[rustc_const_unstable(feature = "const_heap", issue = "79597")] pub fn const_allocate(size: usize, align: usize) -> *mut u8; - - /// Copies `count * size_of::()` bytes from `src` to `dst`. The source - /// and destination must *not* overlap. - /// - /// For regions of memory which might overlap, use [`copy`] instead. - /// - /// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`], but - /// with the argument order swapped. - /// - /// [`memcpy`]: https://en.cppreference.com/w/c/string/byte/memcpy - /// - /// # Safety - /// - /// Behavior is undefined if any of the following conditions are violated: - /// - /// * `src` must be [valid] for reads of `count * size_of::()` bytes. - /// - /// * `dst` must be [valid] for writes of `count * size_of::()` bytes. - /// - /// * Both `src` and `dst` must be properly aligned. - /// - /// * The region of memory beginning at `src` with a size of `count * - /// size_of::()` bytes must *not* overlap with the region of memory - /// beginning at `dst` with the same size. - /// - /// Like [`read`], `copy_nonoverlapping` creates a bitwise copy of `T`, regardless of - /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using *both* the values - /// in the region beginning at `*src` and the region beginning at `*dst` can - /// [violate memory safety][read-ownership]. - /// - /// Note that even if the effectively copied size (`count * size_of::()`) is - /// `0`, the pointers must be non-NULL and properly aligned. - /// - /// [`read`]: crate::ptr::read - /// [read-ownership]: crate::ptr::read#ownership-of-the-returned-value - /// [valid]: crate::ptr#safety - /// - /// # Examples - /// - /// Manually implement [`Vec::append`]: - /// - /// ``` - /// use std::ptr; - /// - /// /// Moves all the elements of `src` into `dst`, leaving `src` empty. - /// fn append(dst: &mut Vec, src: &mut Vec) { - /// let src_len = src.len(); - /// let dst_len = dst.len(); - /// - /// // Ensure that `dst` has enough capacity to hold all of `src`. - /// dst.reserve(src_len); - /// - /// unsafe { - /// // The call to offset is always safe because `Vec` will never - /// // allocate more than `isize::MAX` bytes. - /// let dst_ptr = dst.as_mut_ptr().offset(dst_len as isize); - /// let src_ptr = src.as_ptr(); - /// - /// // Truncate `src` without dropping its contents. We do this first, - /// // to avoid problems in case something further down panics. - /// src.set_len(0); - /// - /// // The two regions cannot overlap because mutable references do - /// // not alias, and two different vectors cannot own the same - /// // memory. - /// ptr::copy_nonoverlapping(src_ptr, dst_ptr, src_len); - /// - /// // Notify `dst` that it now holds the contents of `src`. - /// dst.set_len(dst_len + src_len); - /// } - /// } - /// - /// let mut a = vec!['r']; - /// let mut b = vec!['u', 's', 't']; - /// - /// append(&mut a, &mut b); - /// - /// assert_eq!(a, &['r', 'u', 's', 't']); - /// assert!(b.is_empty()); - /// ``` - /// - /// [`Vec::append`]: ../../std/vec/struct.Vec.html#method.append - #[doc(alias = "memcpy")] - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] - pub fn copy_nonoverlapping(src: *const T, dst: *mut T, count: usize); - - /// Copies `count * size_of::()` bytes from `src` to `dst`. The source - /// and destination may overlap. - /// - /// If the source and destination will *never* overlap, - /// [`copy_nonoverlapping`] can be used instead. - /// - /// `copy` is semantically equivalent to C's [`memmove`], but with the argument - /// order swapped. Copying takes place as if the bytes were copied from `src` - /// to a temporary array and then copied from the array to `dst`. - /// - /// [`memmove`]: https://en.cppreference.com/w/c/string/byte/memmove - /// - /// # Safety - /// - /// Behavior is undefined if any of the following conditions are violated: - /// - /// * `src` must be [valid] for reads of `count * size_of::()` bytes. - /// - /// * `dst` must be [valid] for writes of `count * size_of::()` bytes. - /// - /// * Both `src` and `dst` must be properly aligned. - /// - /// Like [`read`], `copy` creates a bitwise copy of `T`, regardless of - /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using both the values - /// in the region beginning at `*src` and the region beginning at `*dst` can - /// [violate memory safety][read-ownership]. - /// - /// Note that even if the effectively copied size (`count * size_of::()`) is - /// `0`, the pointers must be non-NULL and properly aligned. - /// - /// [`read`]: crate::ptr::read - /// [read-ownership]: crate::ptr::read#ownership-of-the-returned-value - /// [valid]: crate::ptr#safety - /// - /// # Examples - /// - /// Efficiently create a Rust vector from an unsafe buffer: - /// - /// ``` - /// use std::ptr; - /// - /// /// # Safety - /// /// - /// /// * `ptr` must be correctly aligned for its type and non-zero. - /// /// * `ptr` must be valid for reads of `elts` contiguous elements of type `T`. - /// /// * Those elements must not be used after calling this function unless `T: Copy`. - /// # #[allow(dead_code)] - /// unsafe fn from_buf_raw(ptr: *const T, elts: usize) -> Vec { - /// let mut dst = Vec::with_capacity(elts); - /// - /// // SAFETY: Our precondition ensures the source is aligned and valid, - /// // and `Vec::with_capacity` ensures that we have usable space to write them. - /// ptr::copy(ptr, dst.as_mut_ptr(), elts); - /// - /// // SAFETY: We created it with this much capacity earlier, - /// // and the previous `copy` has initialized these elements. - /// dst.set_len(elts); - /// dst - /// } - /// ``` - #[doc(alias = "memmove")] - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] - pub fn copy(src: *const T, dst: *mut T, count: usize); } // Some functions are defined here because they accidentally got made @@ -1906,6 +1755,192 @@ pub(crate) fn is_aligned_and_not_null(ptr: *const T) -> bool { !ptr.is_null() && ptr as usize % mem::align_of::() == 0 } +/// Copies `count * size_of::()` bytes from `src` to `dst`. The source +/// and destination must *not* overlap. +/// +/// For regions of memory which might overlap, use [`copy`] instead. +/// +/// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`], but +/// with the argument order swapped. +/// +/// [`memcpy`]: https://en.cppreference.com/w/c/string/byte/memcpy +/// +/// # Safety +/// +/// Behavior is undefined if any of the following conditions are violated: +/// +/// * `src` must be [valid] for reads of `count * size_of::()` bytes. +/// +/// * `dst` must be [valid] for writes of `count * size_of::()` bytes. +/// +/// * Both `src` and `dst` must be properly aligned. +/// +/// * The region of memory beginning at `src` with a size of `count * +/// size_of::()` bytes must *not* overlap with the region of memory +/// beginning at `dst` with the same size. +/// +/// Like [`read`], `copy_nonoverlapping` creates a bitwise copy of `T`, regardless of +/// whether `T` is [`Copy`]. If `T` is not [`Copy`], using *both* the values +/// in the region beginning at `*src` and the region beginning at `*dst` can +/// [violate memory safety][read-ownership]. +/// +/// Note that even if the effectively copied size (`count * size_of::()`) is +/// `0`, the pointers must be non-NULL and properly aligned. +/// +/// [`read`]: crate::ptr::read +/// [read-ownership]: crate::ptr::read#ownership-of-the-returned-value +/// [valid]: crate::ptr#safety +/// +/// # Examples +/// +/// Manually implement [`Vec::append`]: +/// +/// ``` +/// use std::ptr; +/// +/// /// Moves all the elements of `src` into `dst`, leaving `src` empty. +/// fn append(dst: &mut Vec, src: &mut Vec) { +/// let src_len = src.len(); +/// let dst_len = dst.len(); +/// +/// // Ensure that `dst` has enough capacity to hold all of `src`. +/// dst.reserve(src_len); +/// +/// unsafe { +/// // The call to offset is always safe because `Vec` will never +/// // allocate more than `isize::MAX` bytes. +/// let dst_ptr = dst.as_mut_ptr().offset(dst_len as isize); +/// let src_ptr = src.as_ptr(); +/// +/// // Truncate `src` without dropping its contents. We do this first, +/// // to avoid problems in case something further down panics. +/// src.set_len(0); +/// +/// // The two regions cannot overlap because mutable references do +/// // not alias, and two different vectors cannot own the same +/// // memory. +/// ptr::copy_nonoverlapping(src_ptr, dst_ptr, src_len); +/// +/// // Notify `dst` that it now holds the contents of `src`. +/// dst.set_len(dst_len + src_len); +/// } +/// } +/// +/// let mut a = vec!['r']; +/// let mut b = vec!['u', 's', 't']; +/// +/// append(&mut a, &mut b); +/// +/// assert_eq!(a, &['r', 'u', 's', 't']); +/// assert!(b.is_empty()); +/// ``` +/// +/// [`Vec::append`]: ../../std/vec/struct.Vec.html#method.append +#[doc(alias = "memcpy")] +#[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] +#[inline] +pub const unsafe fn copy_nonoverlapping(src: *const T, dst: *mut T, count: usize) { + extern "rust-intrinsic" { + #[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] + pub fn copy_nonoverlapping(src: *const T, dst: *mut T, count: usize); + } + + // FIXME: Perform these checks only at run time + /*if cfg!(debug_assertions) + && !(is_aligned_and_not_null(src) + && is_aligned_and_not_null(dst) + && is_nonoverlapping(src, dst, count)) + { + // Not panicking to keep codegen impact smaller. + abort(); + }*/ + + // SAFETY: the safety contract for `copy_nonoverlapping` must be + // upheld by the caller. + unsafe { copy_nonoverlapping(src, dst, count) } +} + +/// Copies `count * size_of::()` bytes from `src` to `dst`. The source +/// and destination may overlap. +/// +/// If the source and destination will *never* overlap, +/// [`copy_nonoverlapping`] can be used instead. +/// +/// `copy` is semantically equivalent to C's [`memmove`], but with the argument +/// order swapped. Copying takes place as if the bytes were copied from `src` +/// to a temporary array and then copied from the array to `dst`. +/// +/// [`memmove`]: https://en.cppreference.com/w/c/string/byte/memmove +/// +/// # Safety +/// +/// Behavior is undefined if any of the following conditions are violated: +/// +/// * `src` must be [valid] for reads of `count * size_of::()` bytes. +/// +/// * `dst` must be [valid] for writes of `count * size_of::()` bytes. +/// +/// * Both `src` and `dst` must be properly aligned. +/// +/// Like [`read`], `copy` creates a bitwise copy of `T`, regardless of +/// whether `T` is [`Copy`]. If `T` is not [`Copy`], using both the values +/// in the region beginning at `*src` and the region beginning at `*dst` can +/// [violate memory safety][read-ownership]. +/// +/// Note that even if the effectively copied size (`count * size_of::()`) is +/// `0`, the pointers must be non-NULL and properly aligned. +/// +/// [`read`]: crate::ptr::read +/// [read-ownership]: crate::ptr::read#ownership-of-the-returned-value +/// [valid]: crate::ptr#safety +/// +/// # Examples +/// +/// Efficiently create a Rust vector from an unsafe buffer: +/// +/// ``` +/// use std::ptr; +/// +/// /// # Safety +/// /// +/// /// * `ptr` must be correctly aligned for its type and non-zero. +/// /// * `ptr` must be valid for reads of `elts` contiguous elements of type `T`. +/// /// * Those elements must not be used after calling this function unless `T: Copy`. +/// # #[allow(dead_code)] +/// unsafe fn from_buf_raw(ptr: *const T, elts: usize) -> Vec { +/// let mut dst = Vec::with_capacity(elts); +/// +/// // SAFETY: Our precondition ensures the source is aligned and valid, +/// // and `Vec::with_capacity` ensures that we have usable space to write them. +/// ptr::copy(ptr, dst.as_mut_ptr(), elts); +/// +/// // SAFETY: We created it with this much capacity earlier, +/// // and the previous `copy` has initialized these elements. +/// dst.set_len(elts); +/// dst +/// } +/// ``` +#[doc(alias = "memmove")] +#[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] +#[inline] +pub const unsafe fn copy(src: *const T, dst: *mut T, count: usize) { + extern "rust-intrinsic" { + #[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] + fn copy(src: *const T, dst: *mut T, count: usize); + } + + // FIXME: Perform these checks only at run time + /*if cfg!(debug_assertions) && !(is_aligned_and_not_null(src) && is_aligned_and_not_null(dst)) { + // Not panicking to keep codegen impact smaller. + abort(); + }*/ + + // SAFETY: the safety contract for `copy` must be upheld by the caller. + unsafe { copy(src, dst, count) } +} + /// Sets `count * size_of::()` bytes of memory starting at `dst` to /// `val`. /// diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index 9eb7fa9973b3e..28044e065101c 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -876,12 +876,17 @@ pub const unsafe fn read_unaligned(src: *const T) -> T { #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn write(dst: *mut T, src: T) { + // We are calling the intrinsics directly to avoid function calls in the generated code + // as `intrinsics::copy_nonoverlapping` is a wrapper function. + extern "rust-intrinsic" { + fn copy_nonoverlapping(src: *const T, dst: *mut T, count: usize); + } + // SAFETY: the caller must guarantee that `dst` is valid for writes. // `dst` cannot overlap `src` because the caller has mutable access // to `dst` while `src` is owned by this function. unsafe { copy_nonoverlapping(&src as *const T, dst, 1); - // We are calling the intrinsic directly to avoid function calls in the generated code. intrinsics::forget(src); } } diff --git a/src/test/ui/consts/copy-intrinsic.rs b/src/test/ui/consts/copy-intrinsic.rs deleted file mode 100644 index 9dc595f37faae..0000000000000 --- a/src/test/ui/consts/copy-intrinsic.rs +++ /dev/null @@ -1,45 +0,0 @@ -// ignore-tidy-linelength -#![feature(const_mut_refs, const_intrinsic_copy, const_ptr_offset)] -use std::{ptr, mem}; - -const COPY_ZERO: () = unsafe { - // Since we are not copying anything, this should be allowed. - let src = (); - let mut dst = (); - ptr::copy_nonoverlapping(&src as *const _ as *const i32, &mut dst as *mut _ as *mut i32, 0); -}; - -const COPY_OOB_1: () = unsafe { - let mut x = 0i32; - let dangle = (&mut x as *mut i32).wrapping_add(10); - // Even if the first ptr is an int ptr and this is a ZST copy, we should detect dangling 2nd ptrs. - ptr::copy_nonoverlapping(0x100 as *const i32, dangle, 0); //~ ERROR any use of this value will cause an error - //~| memory access failed: pointer must be in-bounds - //~| previously accepted -}; -const COPY_OOB_2: () = unsafe { - let x = 0i32; - let dangle = (&x as *const i32).wrapping_add(10); - // Even if the second ptr is an int ptr and this is a ZST copy, we should detect dangling 1st ptrs. - ptr::copy_nonoverlapping(dangle, 0x100 as *mut i32, 0); //~ ERROR any use of this value will cause an error - //~| memory access failed: pointer must be in-bounds - //~| previously accepted -}; - -const COPY_SIZE_OVERFLOW: () = unsafe { - let x = 0; - let mut y = 0; - ptr::copy(&x, &mut y, 1usize << (mem::size_of::() * 8 - 1)); //~ ERROR any use of this value will cause an error - //~| overflow computing total size of `copy` - //~| previously accepted -}; -const COPY_NONOVERLAPPING_SIZE_OVERFLOW: () = unsafe { - let x = 0; - let mut y = 0; - ptr::copy_nonoverlapping(&x, &mut y, 1usize << (mem::size_of::() * 8 - 1)); //~ ERROR any use of this value will cause an error - //~| overflow computing total size of `copy_nonoverlapping` - //~| previously accepted -}; - -fn main() { -} diff --git a/src/test/ui/consts/copy-intrinsic.stderr b/src/test/ui/consts/copy-intrinsic.stderr deleted file mode 100644 index 2736cdeac690e..0000000000000 --- a/src/test/ui/consts/copy-intrinsic.stderr +++ /dev/null @@ -1,69 +0,0 @@ -error: any use of this value will cause an error - --> $DIR/copy-intrinsic.rs:16:5 - | -LL | / const COPY_OOB_1: () = unsafe { -LL | | let mut x = 0i32; -LL | | let dangle = (&mut x as *mut i32).wrapping_add(10); -LL | | // Even if the first ptr is an int ptr and this is a ZST copy, we should detect dangling 2nd ptrs. -LL | | ptr::copy_nonoverlapping(0x100 as *const i32, dangle, 0); - | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: pointer must be in-bounds at offset 40, but is outside bounds of alloc4 which has size 4 -LL | | -LL | | -LL | | }; - | |__- - | - = note: `#[deny(const_err)]` on by default - = 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 #71800 - -error: any use of this value will cause an error - --> $DIR/copy-intrinsic.rs:24:5 - | -LL | / const COPY_OOB_2: () = unsafe { -LL | | let x = 0i32; -LL | | let dangle = (&x as *const i32).wrapping_add(10); -LL | | // Even if the second ptr is an int ptr and this is a ZST copy, we should detect dangling 1st ptrs. -LL | | ptr::copy_nonoverlapping(dangle, 0x100 as *mut i32, 0); - | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: pointer must be in-bounds at offset 40, but is outside bounds of alloc6 which has size 4 -LL | | -LL | | -LL | | }; - | |__- - | - = 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 #71800 - -error: any use of this value will cause an error - --> $DIR/copy-intrinsic.rs:32:5 - | -LL | / const COPY_SIZE_OVERFLOW: () = unsafe { -LL | | let x = 0; -LL | | let mut y = 0; -LL | | ptr::copy(&x, &mut y, 1usize << (mem::size_of::() * 8 - 1)); - | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow computing total size of `copy` -LL | | -LL | | -LL | | }; - | |__- - | - = 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 #71800 - -error: any use of this value will cause an error - --> $DIR/copy-intrinsic.rs:39:5 - | -LL | / const COPY_NONOVERLAPPING_SIZE_OVERFLOW: () = unsafe { -LL | | let x = 0; -LL | | let mut y = 0; -LL | | ptr::copy_nonoverlapping(&x, &mut y, 1usize << (mem::size_of::() * 8 - 1)); - | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow computing total size of `copy_nonoverlapping` -LL | | -LL | | -LL | | }; - | |__- - | - = 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 #71800 - -error: aborting due to 4 previous errors - From bc843fda00c8554bc27d30d2e32b9f93c9fd1596 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 4 Jun 2021 16:14:03 -0400 Subject: [PATCH 39/52] Revert clippy's path to the copy intrinsics (part of reverting PR 81238). --- src/tools/clippy/clippy_utils/src/paths.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/clippy/clippy_utils/src/paths.rs b/src/tools/clippy/clippy_utils/src/paths.rs index 5e6733a300f2c..0d4c2ae4eee37 100644 --- a/src/tools/clippy/clippy_utils/src/paths.rs +++ b/src/tools/clippy/clippy_utils/src/paths.rs @@ -105,8 +105,8 @@ pub const PERMISSIONS_FROM_MODE: [&str; 7] = ["std", "sys", "unix", "ext", "fs", pub const POLL: [&str; 4] = ["core", "task", "poll", "Poll"]; pub const POLL_PENDING: [&str; 5] = ["core", "task", "poll", "Poll", "Pending"]; pub const POLL_READY: [&str; 5] = ["core", "task", "poll", "Poll", "Ready"]; -pub const PTR_COPY: [&str; 4] = ["core", "intrinsics", "", "copy"]; -pub const PTR_COPY_NONOVERLAPPING: [&str; 4] = ["core", "intrinsics", "", "copy_nonoverlapping"]; +pub const PTR_COPY: [&str; 3] = ["core", "intrinsics", "copy"]; +pub const PTR_COPY_NONOVERLAPPING: [&str; 3] = ["core", "intrinsics", "copy_nonoverlapping"]; pub const PTR_EQ: [&str; 3] = ["core", "ptr", "eq"]; pub const PTR_NULL: [&str; 3] = ["core", "ptr", "null"]; pub const PTR_NULL_MUT: [&str; 3] = ["core", "ptr", "null_mut"]; From 837cd138e4fc17767143f76753e0c33a0e330323 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 4 Jun 2021 15:23:45 -0400 Subject: [PATCH 40/52] Remove tests that were also added in PR 79684. --- src/test/ui/const-ptr/out_of_bounds_read.rs | 16 ----- .../ui/const-ptr/out_of_bounds_read.stderr | 59 ------------------- 2 files changed, 75 deletions(-) delete mode 100644 src/test/ui/const-ptr/out_of_bounds_read.rs delete mode 100644 src/test/ui/const-ptr/out_of_bounds_read.stderr diff --git a/src/test/ui/const-ptr/out_of_bounds_read.rs b/src/test/ui/const-ptr/out_of_bounds_read.rs deleted file mode 100644 index 183aa9e51228c..0000000000000 --- a/src/test/ui/const-ptr/out_of_bounds_read.rs +++ /dev/null @@ -1,16 +0,0 @@ -// error-pattern: any use of this value will cause an error - -#![feature(const_ptr_read)] -#![feature(const_ptr_offset)] - -fn main() { - use std::ptr; - - const DATA: [u32; 1] = [42]; - - const PAST_END_PTR: *const u32 = unsafe { DATA.as_ptr().add(1) }; - - const _READ: u32 = unsafe { ptr::read(PAST_END_PTR) }; - const _CONST_READ: u32 = unsafe { PAST_END_PTR.read() }; - const _MUT_READ: u32 = unsafe { (PAST_END_PTR as *mut u32).read() }; -} diff --git a/src/test/ui/const-ptr/out_of_bounds_read.stderr b/src/test/ui/const-ptr/out_of_bounds_read.stderr deleted file mode 100644 index 6c4092e3e5cc8..0000000000000 --- a/src/test/ui/const-ptr/out_of_bounds_read.stderr +++ /dev/null @@ -1,59 +0,0 @@ -error: any use of this value will cause an error - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL - | -LL | copy_nonoverlapping(src, tmp.as_mut_ptr(), 1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | memory access failed: pointer must be in-bounds at offset 8, but is outside bounds of alloc6 which has size 4 - | inside `std::ptr::read::` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL - | inside `_READ` at $DIR/out_of_bounds_read.rs:13:33 - | - ::: $DIR/out_of_bounds_read.rs:13:5 - | -LL | const _READ: u32 = unsafe { ptr::read(PAST_END_PTR) }; - | ------------------------------------------------------ - | - = note: `#[deny(const_err)]` on by default - = 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 #71800 - -error: any use of this value will cause an error - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL - | -LL | copy_nonoverlapping(src, tmp.as_mut_ptr(), 1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | memory access failed: pointer must be in-bounds at offset 8, but is outside bounds of alloc6 which has size 4 - | inside `std::ptr::read::` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL - | inside `ptr::const_ptr::::read` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL - | inside `_CONST_READ` at $DIR/out_of_bounds_read.rs:14:39 - | - ::: $DIR/out_of_bounds_read.rs:14:5 - | -LL | const _CONST_READ: u32 = unsafe { PAST_END_PTR.read() }; - | -------------------------------------------------------- - | - = 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 #71800 - -error: any use of this value will cause an error - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL - | -LL | copy_nonoverlapping(src, tmp.as_mut_ptr(), 1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | memory access failed: pointer must be in-bounds at offset 8, but is outside bounds of alloc6 which has size 4 - | inside `std::ptr::read::` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL - | inside `ptr::mut_ptr::::read` at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - | inside `_MUT_READ` at $DIR/out_of_bounds_read.rs:15:37 - | - ::: $DIR/out_of_bounds_read.rs:15:5 - | -LL | const _MUT_READ: u32 = unsafe { (PAST_END_PTR as *mut u32).read() }; - | -------------------------------------------------------------------- - | - = 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 #71800 - -error: aborting due to 3 previous errors - From 4d9e64b6e3b09c3d33ebaf0f325df3ef2ca74ad3 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 4 Jun 2021 15:37:16 -0400 Subject: [PATCH 41/52] Change test to use `likely`/`unlikely` instead of `copy`/`copy_overlapping`. Test was added in PR #84404. The intent here is: The `copy`/`copy_overlapping` intrinsics are going through some flip-flopping now of "are they intrinsics or not". We can achieve the same effect that the test intended by using `likely`/`unlikely`. --- src/test/ui/reify-intrinsic.rs | 6 +++--- src/test/ui/reify-intrinsic.stderr | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/ui/reify-intrinsic.rs b/src/test/ui/reify-intrinsic.rs index 05535b92cca73..9eb2f724017ed 100644 --- a/src/test/ui/reify-intrinsic.rs +++ b/src/test/ui/reify-intrinsic.rs @@ -1,6 +1,6 @@ // check-fail -#![feature(intrinsics)] +#![feature(core_intrinsics, intrinsics)] fn a() { let _: unsafe extern "rust-intrinsic" fn(isize) -> usize = std::mem::transmute; @@ -14,8 +14,8 @@ fn b() { fn c() { let _ = [ - std::intrinsics::copy_nonoverlapping::, - std::intrinsics::copy::, + std::intrinsics::likely, + std::intrinsics::unlikely, //~^ ERROR cannot coerce ]; } diff --git a/src/test/ui/reify-intrinsic.stderr b/src/test/ui/reify-intrinsic.stderr index 5d82fdbd31190..69c11b5c56fd3 100644 --- a/src/test/ui/reify-intrinsic.stderr +++ b/src/test/ui/reify-intrinsic.stderr @@ -22,11 +22,11 @@ LL | let _ = std::mem::transmute as unsafe extern "rust-intrinsic" fn(isize) error[E0308]: cannot coerce intrinsics to function pointers --> $DIR/reify-intrinsic.rs:18:9 | -LL | std::intrinsics::copy::, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot coerce intrinsics to function pointers +LL | std::intrinsics::unlikely, + | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot coerce intrinsics to function pointers | - = note: expected type `unsafe extern "rust-intrinsic" fn(_, _, _) {copy_nonoverlapping::}` - found fn item `unsafe extern "rust-intrinsic" fn(_, _, _) {std::intrinsics::copy::}` + = note: expected type `extern "rust-intrinsic" fn(_) -> _ {likely}` + found fn item `extern "rust-intrinsic" fn(_) -> _ {unlikely}` error: aborting due to 3 previous errors From 61520c8a43ea731e35453969b8e68c363887cf45 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 4 Jun 2021 16:23:18 -0400 Subject: [PATCH 42/52] Regression test for issue 84297. --- src/test/ui/intrinsics/issue-84297-reifying-copy.rs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/test/ui/intrinsics/issue-84297-reifying-copy.rs diff --git a/src/test/ui/intrinsics/issue-84297-reifying-copy.rs b/src/test/ui/intrinsics/issue-84297-reifying-copy.rs new file mode 100644 index 0000000000000..08ba9ce7ecb29 --- /dev/null +++ b/src/test/ui/intrinsics/issue-84297-reifying-copy.rs @@ -0,0 +1,9 @@ +// check-pass + +fn main() { + let _unused = if true { + core::ptr::copy:: + } else { + core::ptr::copy_nonoverlapping:: + }; +} From 752c939dfee797008da1af044786346adb2d7b4b Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Sat, 5 Jun 2021 14:35:19 +0300 Subject: [PATCH 43/52] Disable the machine outliner by default This addresses a codegen-issue that needs to be fixed upstream in LLVM. While we wait for the fix, we can disable it. Verified manually that the outliner is no longer run when `-Copt-level=z` is specified, and also that you can override this with `-Cllvm-args=-enable-machine-outliner` if you need it anyway. A regression test is not really feasible in this instance, given that we do not have any minimal reproducers. Fixes #85351 --- compiler/rustc_codegen_llvm/src/llvm_util.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index b44553e4f6d3b..97684ca6c1a31 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -1,5 +1,5 @@ use crate::back::write::create_informational_target_machine; -use crate::llvm; +use crate::{llvm, llvm_util}; use libc::c_int; use rustc_codegen_ssa::target_features::supported_target_features; use rustc_data_structures::fx::FxHashSet; @@ -84,6 +84,17 @@ unsafe fn configure_llvm(sess: &Session) { if !sess.opts.debugging_opts.no_generate_arange_section { add("-generate-arange-section", false); } + + // FIXME(nagisa): disable the machine outliner by default in LLVM versions 11, where it was + // introduced and up. + // + // This should remain in place until https://reviews.llvm.org/D103167 is fixed. If LLVM + // has been upgraded since, consider adjusting the version check below to contain an upper + // bound. + if llvm_util::get_version() >= (11, 0, 0) { + add("-enable-machine-outliner=never", false); + } + match sess.opts.debugging_opts.merge_functions.unwrap_or(sess.target.merge_functions) { MergeFunctions::Disabled | MergeFunctions::Trampolines => {} MergeFunctions::Aliases => { From c05bbb72371534ce02f76097280deca6518df69a Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 18 May 2021 14:14:20 -0400 Subject: [PATCH 44/52] Fix incorrect gating of nonterminals in key-value attributes Fixes #85432 When processing a `#[derive]` or `#[cfg_eval]` attribute, we need to re-parse our attribute target, which requires flattenting all `Nonterminals`. However, this caused us to incorrectly gate on a (flattented) nonterminal in a key-value attribute, which is supposed to be allowed. Since we already perform this gating during the initial parse, we suppress it in `capture_cfg` mode. --- compiler/rustc_parse/src/parser/mod.rs | 7 +++-- .../macros/issue-85432-ungated-attr-macro.rs | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/macros/issue-85432-ungated-attr-macro.rs diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index ed95a5661b18e..a55eb3cf7526d 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -1077,8 +1077,11 @@ impl<'a> Parser<'a> { let span = expr.span; match &expr.kind { - // Not gated to supporte things like `doc = $expr` that work on stable. - _ if is_interpolated_expr => {} + // Not gated to support things like `doc = $expr` that work on stable. + // Do not gate in `capture_cfg` mode, since we flatten all nontemrinals + // before parsing. `capture_cfg` mode is only used to reparse existing + // tokens, so the gating will be performed by the initial parse + _ if is_interpolated_expr || self.capture_cfg => {} ExprKind::Lit(lit) if lit.kind.is_unsuffixed() => {} _ => self.sess.gated_spans.gate(sym::extended_key_value_attributes, span), } diff --git a/src/test/ui/macros/issue-85432-ungated-attr-macro.rs b/src/test/ui/macros/issue-85432-ungated-attr-macro.rs new file mode 100644 index 0000000000000..bac124c6f4c3c --- /dev/null +++ b/src/test/ui/macros/issue-85432-ungated-attr-macro.rs @@ -0,0 +1,30 @@ +// check-pass +// Regression test for issue #85432 +// Ensures that we don't incorrectly gate nonterminals +// in key-value macros when we need to reparse due to +// the presence of `#[derive]` + +macro_rules! with_doc_comment { + ($comment:expr, $item:item) => { + #[doc = $comment] + $item + }; +} + +macro_rules! database_table_doc { + () => { + "" + }; +} + +with_doc_comment! { + database_table_doc!(), + #[derive(Debug)] + struct Image { + #[cfg(FALSE)] + _f: (), + } + +} + +fn main() {} From 8b1a5a74299e609a0e542b3c826dbe03da872efd Mon Sep 17 00:00:00 2001 From: 12101111 Date: Mon, 17 May 2021 11:22:07 +0800 Subject: [PATCH 45/52] Build crtbengin.o/crtend.o from source code --- src/bootstrap/builder.rs | 3 +- src/bootstrap/compile.rs | 3 +- src/bootstrap/native.rs | 66 +++++++++++++++++++ .../host-x86_64/dist-various-1/Dockerfile | 6 +- .../run-make-fulldeps/issue-47551/Makefile | 9 +++ .../issue-47551/eh_frame-terminator.rs | 23 +++++++ 6 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 src/test/run-make-fulldeps/issue-47551/Makefile create mode 100644 src/test/run-make-fulldeps/issue-47551/eh_frame-terminator.rs diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 62a3a87eeb850..cff1ec843ff71 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -369,7 +369,8 @@ impl<'a> Builder<'a> { tool::Rustfmt, tool::Miri, tool::CargoMiri, - native::Lld + native::Lld, + native::CrtBeginEnd ), Kind::Check | Kind::Clippy { .. } | Kind::Fix | Kind::Format => describe!( check::Std, diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 66a88e85fea39..ee3527b6bf197 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -199,8 +199,9 @@ fn copy_self_contained_objects( DependencyType::TargetSelfContained, ); } + let crt_path = builder.ensure(native::CrtBeginEnd { target }); for &obj in &["crtbegin.o", "crtbeginS.o", "crtend.o", "crtendS.o"] { - let src = compiler_file(builder, builder.cc(target), target, obj); + let src = crt_path.join(obj); let target = libdir_self_contained.join(obj); builder.copy(&src, &target); target_deps.push((target, DependencyType::TargetSelfContained)); diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index bde0a96f03013..156e8dd53d50d 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -858,3 +858,69 @@ impl HashStamp { fs::write(&self.path, self.hash.as_deref().unwrap_or(b"")) } } + +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub struct CrtBeginEnd { + pub target: TargetSelection, +} + +impl Step for CrtBeginEnd { + type Output = PathBuf; + + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { + run.path("src/llvm-project/compiler-rt/lib/crt") + } + + fn make_run(run: RunConfig<'_>) { + run.builder.ensure(CrtBeginEnd { target: run.target }); + } + + /// Build crtbegin.o/crtend.o for musl target. + fn run(self, builder: &Builder<'_>) -> Self::Output { + let out_dir = builder.native_dir(self.target).join("crt"); + + if builder.config.dry_run { + return out_dir; + } + + let crtbegin_src = builder.src.join("src/llvm-project/compiler-rt/lib/crt/crtbegin.c"); + let crtend_src = builder.src.join("src/llvm-project/compiler-rt/lib/crt/crtend.c"); + if up_to_date(&crtbegin_src, &out_dir.join("crtbegin.o")) + && up_to_date(&crtend_src, &out_dir.join("crtendS.o")) + { + return out_dir; + } + + builder.info("Building crtbegin.o and crtend.o"); + t!(fs::create_dir_all(&out_dir)); + + let mut cfg = cc::Build::new(); + + if let Some(ar) = builder.ar(self.target) { + cfg.archiver(ar); + } + cfg.compiler(builder.cc(self.target)); + cfg.cargo_metadata(false) + .out_dir(&out_dir) + .target(&self.target.triple) + .host(&builder.config.build.triple) + .warnings(false) + .debug(false) + .opt_level(3) + .file(crtbegin_src) + .file(crtend_src); + + // Those flags are defined in src/llvm-project/compiler-rt/lib/crt/CMakeLists.txt + // Currently only consumer of those objects is musl, which use .init_array/.fini_array + // instead of .ctors/.dtors + cfg.flag("-std=c11") + .define("CRT_HAS_INITFINI_ARRAY", None) + .define("EH_USE_FRAME_REGISTRY", None); + + cfg.compile("crt"); + + t!(fs::copy(out_dir.join("crtbegin.o"), out_dir.join("crtbeginS.o"))); + t!(fs::copy(out_dir.join("crtend.o"), out_dir.join("crtendS.o"))); + out_dir + } +} diff --git a/src/ci/docker/host-x86_64/dist-various-1/Dockerfile b/src/ci/docker/host-x86_64/dist-various-1/Dockerfile index 1f8f9fc518ac1..cd0f01faa1bfa 100644 --- a/src/ci/docker/host-x86_64/dist-various-1/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-various-1/Dockerfile @@ -144,7 +144,11 @@ ENV TARGETS=$TARGETS,armv7a-none-eabi # riscv targets currently do not need a C compiler, as compiler_builtins # doesn't currently have it enabled, and the riscv gcc compiler is not # installed. -ENV CC_mipsel_unknown_linux_musl=mipsel-openwrt-linux-gcc \ +ENV CFLAGS_armv5te_unknown_linux_musleabi="-march=armv5te -marm -mfloat-abi=soft" \ + CFLAGS_arm_unknown_linux_musleabi="-march=armv6 -marm" \ + CFLAGS_arm_unknown_linux_musleabihf="-march=armv6 -marm -mfpu=vfp" \ + CFLAGS_armv7_unknown_linux_musleabihf="-march=armv7-a" \ + CC_mipsel_unknown_linux_musl=mipsel-openwrt-linux-gcc \ CC_mips_unknown_linux_musl=mips-openwrt-linux-gcc \ CC_mips64el_unknown_linux_muslabi64=mips64el-linux-gnuabi64-gcc \ CC_mips64_unknown_linux_muslabi64=mips64-linux-gnuabi64-gcc \ diff --git a/src/test/run-make-fulldeps/issue-47551/Makefile b/src/test/run-make-fulldeps/issue-47551/Makefile new file mode 100644 index 0000000000000..f4495e6b671d7 --- /dev/null +++ b/src/test/run-make-fulldeps/issue-47551/Makefile @@ -0,0 +1,9 @@ +# only-linux +# ignore-32bit + +-include ../tools.mk + +all: + $(RUSTC) eh_frame-terminator.rs + $(call RUN,eh_frame-terminator) | $(CGREP) '1122334455667788' + objdump --dwarf=frames $(TMPDIR)/eh_frame-terminator | $(CGREP) 'ZERO terminator' diff --git a/src/test/run-make-fulldeps/issue-47551/eh_frame-terminator.rs b/src/test/run-make-fulldeps/issue-47551/eh_frame-terminator.rs new file mode 100644 index 0000000000000..2f740dc4fac38 --- /dev/null +++ b/src/test/run-make-fulldeps/issue-47551/eh_frame-terminator.rs @@ -0,0 +1,23 @@ +// run-pass + +#![feature(backtrace)] +#[derive(Clone, Copy)] +struct Foo { + array: [u64; 10240], +} + +impl Foo { + const fn new() -> Self { + Self { + array: [0x1122_3344_5566_7788; 10240] + } + } +} + +static BAR: [Foo; 10240] = [Foo::new(); 10240]; + +fn main() { + let bt = std::backtrace::Backtrace::force_capture(); + println!("Hello, world! {:?}", bt); + println!("{:x}", BAR[0].array[0]); +} From bf28f680b72251626dde1000a60479d2b8e0214a Mon Sep 17 00:00:00 2001 From: Jakub Kulik Date: Thu, 13 May 2021 12:40:06 +0200 Subject: [PATCH 46/52] Update Docker to build the deprecated target alongside the new one --- .../docker/host-x86_64/dist-various-2/Dockerfile | 10 ++++++++-- .../dist-various-2/build-solaris-toolchain.sh | 14 ++------------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile index de3a99f34fcfa..357ac7a2becb9 100644 --- a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile @@ -42,6 +42,9 @@ ENV \ AR_x86_64_pc_solaris=x86_64-pc-solaris2.10-ar \ CC_x86_64_pc_solaris=x86_64-pc-solaris2.10-gcc \ CXX_x86_64_pc_solaris=x86_64-pc-solaris2.10-g++ \ + AR_x86_64_sun_solaris=x86_64-sun-solaris2.10-ar \ + CC_x86_64_sun_solaris=x86_64-sun-solaris2.10-gcc \ + CXX_x86_64_sun_solaris=x86_64-sun-solaris2.10-g++ \ CC_armv7_unknown_linux_gnueabi=arm-linux-gnueabi-gcc-8 \ CXX_armv7_unknown_linux_gnueabi=arm-linux-gnueabi-g++-8 \ AR_x86_64_fortanix_unknown_sgx=ar \ @@ -68,8 +71,10 @@ COPY host-x86_64/dist-various-2/shared.sh /tmp/ COPY host-x86_64/dist-various-2/build-fuchsia-toolchain.sh /tmp/ RUN /tmp/build-fuchsia-toolchain.sh COPY host-x86_64/dist-various-2/build-solaris-toolchain.sh /tmp/ -RUN /tmp/build-solaris-toolchain.sh x86_64 amd64 solaris-i386 -RUN /tmp/build-solaris-toolchain.sh sparcv9 sparcv9 solaris-sparc +RUN /tmp/build-solaris-toolchain.sh x86_64 amd64 solaris-i386 pc +# Build now deprecated Solaris target as well +RUN /tmp/build-solaris-toolchain.sh x86_64 amd64 solaris-i386 sun +RUN /tmp/build-solaris-toolchain.sh sparcv9 sparcv9 solaris-sparc sun COPY host-x86_64/dist-various-2/build-x86_64-fortanix-unknown-sgx-toolchain.sh /tmp/ RUN /tmp/build-x86_64-fortanix-unknown-sgx-toolchain.sh @@ -99,6 +104,7 @@ ENV TARGETS=$TARGETS,wasm32-unknown-unknown ENV TARGETS=$TARGETS,wasm32-wasi ENV TARGETS=$TARGETS,sparcv9-sun-solaris ENV TARGETS=$TARGETS,x86_64-pc-solaris +ENV TARGETS=$TARGETS,x86_64-sun-solaris ENV TARGETS=$TARGETS,x86_64-unknown-linux-gnux32 ENV TARGETS=$TARGETS,x86_64-fortanix-unknown-sgx ENV TARGETS=$TARGETS,nvptx64-nvidia-cuda diff --git a/src/ci/docker/host-x86_64/dist-various-2/build-solaris-toolchain.sh b/src/ci/docker/host-x86_64/dist-various-2/build-solaris-toolchain.sh index ee76fafb1f948..4cbc2ccfe3814 100755 --- a/src/ci/docker/host-x86_64/dist-various-2/build-solaris-toolchain.sh +++ b/src/ci/docker/host-x86_64/dist-various-2/build-solaris-toolchain.sh @@ -6,21 +6,11 @@ source shared.sh ARCH=$1 LIB_ARCH=$2 APT_ARCH=$3 +MANUFACTURER=$4 BINUTILS=2.28.1 GCC=6.5.0 -# Choose correct target based on the $ARCH -case "$ARCH" in -x86_64) - TARGET=x86_64-pc-solaris2.10 - ;; -sparcv9) - TARGET=sparcv9-sun-solaris2.10 - ;; -*) - printf 'ERROR: unknown architecture: %s\n' "$ARCH" - exit 1 -esac +TARGET=${ARCH}-${MANUFACTURER}-solaris2.10 # First up, build binutils mkdir binutils From f724ee4233d72f14d58ecc3c56064c465dcbcfb8 Mon Sep 17 00:00:00 2001 From: Jakub Kulik Date: Thu, 13 May 2021 12:43:46 +0200 Subject: [PATCH 47/52] Improve comment --- src/ci/docker/host-x86_64/dist-various-2/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile index 357ac7a2becb9..b7f181adf2a09 100644 --- a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile @@ -72,7 +72,7 @@ COPY host-x86_64/dist-various-2/build-fuchsia-toolchain.sh /tmp/ RUN /tmp/build-fuchsia-toolchain.sh COPY host-x86_64/dist-various-2/build-solaris-toolchain.sh /tmp/ RUN /tmp/build-solaris-toolchain.sh x86_64 amd64 solaris-i386 pc -# Build now deprecated Solaris target as well +# Build deprecated target 'x86_64-sun-solaris2.10' until removed RUN /tmp/build-solaris-toolchain.sh x86_64 amd64 solaris-i386 sun RUN /tmp/build-solaris-toolchain.sh sparcv9 sparcv9 solaris-sparc sun COPY host-x86_64/dist-various-2/build-x86_64-fortanix-unknown-sgx-toolchain.sh /tmp/ From 9529cbd0ba0ec29308589dbc8899305bd629f72a Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Wed, 12 May 2021 00:10:41 -0400 Subject: [PATCH 48/52] Preserve `SyntaxContext` for invalid/dummy spans in crate metadata Fixes #85197 We already preserved the `SyntaxContext` for invalid/dummy spans in the incremental cache, but we weren't doing the same for crate metadata. If an invalid (lo/hi from different files) span is written to the incremental cache, we will decode it with a 'dummy' location, but keep the original `SyntaxContext`. Since the crate metadata encoder was only checking for `DUMMY_SP` (dummy location + root `SyntaxContext`), the metadata encoder would treat it as a normal span, encoding the `SyntaxContext`. As a result, the final span encoded to the metadata would change across sessions, even if the crate itself was unchanged. This PR updates our encoding of spans in the crate metadata to mirror the encoding of spans into the incremental cache. We now always encode a `SyntaxContext`, and encode location information for spans with a non-dummy location. --- compiler/rustc_metadata/src/rmeta/decoder.rs | 6 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 82 +++++++++---------- compiler/rustc_metadata/src/rmeta/mod.rs | 2 +- .../auxiliary/invalid-span-helper-lib.rs | 11 +++ .../auxiliary/invalid-span-helper-mod.rs | 14 ++++ .../auxiliary/respan.rs | 19 +++++ .../invalid_span_main.rs | 24 ++++++ 7 files changed, 113 insertions(+), 45 deletions(-) create mode 100644 src/test/incremental/issue-85197-invalid-span/auxiliary/invalid-span-helper-lib.rs create mode 100644 src/test/incremental/issue-85197-invalid-span/auxiliary/invalid-span-helper-mod.rs create mode 100644 src/test/incremental/issue-85197-invalid-span/auxiliary/respan.rs create mode 100644 src/test/incremental/issue-85197-invalid-span/invalid_span_main.rs diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 2ade1bb4f95de..6671cf6fea48f 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -406,17 +406,17 @@ impl<'a, 'tcx> Decodable> for ExpnId { impl<'a, 'tcx> Decodable> for Span { fn decode(decoder: &mut DecodeContext<'a, 'tcx>) -> Result { + let ctxt = SyntaxContext::decode(decoder)?; let tag = u8::decode(decoder)?; - if tag == TAG_INVALID_SPAN { - return Ok(DUMMY_SP); + if tag == TAG_PARTIAL_SPAN { + return Ok(DUMMY_SP.with_ctxt(ctxt)); } debug_assert!(tag == TAG_VALID_SPAN_LOCAL || tag == TAG_VALID_SPAN_FOREIGN); let lo = BytePos::decode(decoder)?; let len = BytePos::decode(decoder)?; - let ctxt = SyntaxContext::decode(decoder)?; let hi = lo + len; let sess = if let Some(sess) = decoder.sess { diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index e8f02b8e66f0a..02fa6905a08ce 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -184,11 +184,48 @@ impl<'a, 'tcx> Encodable> for ExpnId { impl<'a, 'tcx> Encodable> for Span { fn encode(&self, s: &mut EncodeContext<'a, 'tcx>) -> opaque::EncodeResult { - if *self == rustc_span::DUMMY_SP { - return TAG_INVALID_SPAN.encode(s); + let span = self.data(); + + // Don't serialize any `SyntaxContext`s from a proc-macro crate, + // since we don't load proc-macro dependencies during serialization. + // This means that any hygiene information from macros used *within* + // a proc-macro crate (e.g. invoking a macro that expands to a proc-macro + // definition) will be lost. + // + // This can show up in two ways: + // + // 1. Any hygiene information associated with identifier of + // a proc macro (e.g. `#[proc_macro] pub fn $name`) will be lost. + // Since proc-macros can only be invoked from a different crate, + // real code should never need to care about this. + // + // 2. Using `Span::def_site` or `Span::mixed_site` will not + // include any hygiene information associated with the definition + // site. This means that a proc-macro cannot emit a `$crate` + // identifier which resolves to one of its dependencies, + // which also should never come up in practice. + // + // Additionally, this affects `Span::parent`, and any other + // span inspection APIs that would otherwise allow traversing + // the `SyntaxContexts` associated with a span. + // + // None of these user-visible effects should result in any + // cross-crate inconsistencies (getting one behavior in the same + // crate, and a different behavior in another crate) due to the + // limited surface that proc-macros can expose. + // + // IMPORTANT: If this is ever changed, be sure to update + // `rustc_span::hygiene::raw_encode_expn_id` to handle + // encoding `ExpnData` for proc-macro crates. + if s.is_proc_macro { + SyntaxContext::root().encode(s)?; + } else { + span.ctxt.encode(s)?; } - let span = self.data(); + if self.is_dummy() { + return TAG_PARTIAL_SPAN.encode(s); + } // The Span infrastructure should make sure that this invariant holds: debug_assert!(span.lo <= span.hi); @@ -203,7 +240,7 @@ impl<'a, 'tcx> Encodable> for Span { if !s.source_file_cache.0.contains(span.hi) { // Unfortunately, macro expansion still sometimes generates Spans // that malformed in this way. - return TAG_INVALID_SPAN.encode(s); + return TAG_PARTIAL_SPAN.encode(s); } let source_files = s.required_source_files.as_mut().expect("Already encoded SourceMap!"); @@ -259,43 +296,6 @@ impl<'a, 'tcx> Encodable> for Span { let len = hi - lo; len.encode(s)?; - // Don't serialize any `SyntaxContext`s from a proc-macro crate, - // since we don't load proc-macro dependencies during serialization. - // This means that any hygiene information from macros used *within* - // a proc-macro crate (e.g. invoking a macro that expands to a proc-macro - // definition) will be lost. - // - // This can show up in two ways: - // - // 1. Any hygiene information associated with identifier of - // a proc macro (e.g. `#[proc_macro] pub fn $name`) will be lost. - // Since proc-macros can only be invoked from a different crate, - // real code should never need to care about this. - // - // 2. Using `Span::def_site` or `Span::mixed_site` will not - // include any hygiene information associated with the definition - // site. This means that a proc-macro cannot emit a `$crate` - // identifier which resolves to one of its dependencies, - // which also should never come up in practice. - // - // Additionally, this affects `Span::parent`, and any other - // span inspection APIs that would otherwise allow traversing - // the `SyntaxContexts` associated with a span. - // - // None of these user-visible effects should result in any - // cross-crate inconsistencies (getting one behavior in the same - // crate, and a different behavior in another crate) due to the - // limited surface that proc-macros can expose. - // - // IMPORTANT: If this is ever changed, be sure to update - // `rustc_span::hygiene::raw_encode_expn_id` to handle - // encoding `ExpnData` for proc-macro crates. - if s.is_proc_macro { - SyntaxContext::root().encode(s)?; - } else { - span.ctxt.encode(s)?; - } - if tag == TAG_VALID_SPAN_FOREIGN { // This needs to be two lines to avoid holding the `s.source_file_cache` // while calling `cnum.encode(s)` diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 9f665d5daaa03..959aa1719aef5 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -450,4 +450,4 @@ struct GeneratorData<'tcx> { // Tags used for encoding Spans: const TAG_VALID_SPAN_LOCAL: u8 = 0; const TAG_VALID_SPAN_FOREIGN: u8 = 1; -const TAG_INVALID_SPAN: u8 = 2; +const TAG_PARTIAL_SPAN: u8 = 2; diff --git a/src/test/incremental/issue-85197-invalid-span/auxiliary/invalid-span-helper-lib.rs b/src/test/incremental/issue-85197-invalid-span/auxiliary/invalid-span-helper-lib.rs new file mode 100644 index 0000000000000..2453af5b6b47b --- /dev/null +++ b/src/test/incremental/issue-85197-invalid-span/auxiliary/invalid-span-helper-lib.rs @@ -0,0 +1,11 @@ +// revisions: rpass1 rpass2 + +extern crate respan; + +#[macro_use] +#[path = "invalid-span-helper-mod.rs"] +mod invalid_span_helper_mod; + +// Invoke a macro from a different file - this +// allows us to get tokens with spans from different files +helper!(1); diff --git a/src/test/incremental/issue-85197-invalid-span/auxiliary/invalid-span-helper-mod.rs b/src/test/incremental/issue-85197-invalid-span/auxiliary/invalid-span-helper-mod.rs new file mode 100644 index 0000000000000..747174b1ebf15 --- /dev/null +++ b/src/test/incremental/issue-85197-invalid-span/auxiliary/invalid-span-helper-mod.rs @@ -0,0 +1,14 @@ +#[macro_export] +macro_rules! helper { + // Use `:tt` instead of `:ident` so that we don't get a `None`-delimited group + ($first:tt) => { + pub fn foo() { + // The span of `$first` comes from another file, + // so the expression `1 + $first` ends up with an + // 'invalid' span that starts and ends in different files. + // We use the `respan!` macro to give all tokens the same + // `SyntaxContext`, so that the parser will try to merge the spans. + respan::respan!(let a = 1 + $first;); + } + } +} diff --git a/src/test/incremental/issue-85197-invalid-span/auxiliary/respan.rs b/src/test/incremental/issue-85197-invalid-span/auxiliary/respan.rs new file mode 100644 index 0000000000000..5088eab62946f --- /dev/null +++ b/src/test/incremental/issue-85197-invalid-span/auxiliary/respan.rs @@ -0,0 +1,19 @@ +// force-host +// no-prefer-dynamic + +#![crate_type = "proc-macro"] + +extern crate proc_macro; +use proc_macro::TokenStream; + + +/// Copies the resolution information (the `SyntaxContext`) of the first +/// token to all other tokens in the stream. Does not recurse into groups. +#[proc_macro] +pub fn respan(input: TokenStream) -> TokenStream { + let first_span = input.clone().into_iter().next().unwrap().span(); + input.into_iter().map(|mut tree| { + tree.set_span(tree.span().resolved_at(first_span)); + tree + }).collect() +} diff --git a/src/test/incremental/issue-85197-invalid-span/invalid_span_main.rs b/src/test/incremental/issue-85197-invalid-span/invalid_span_main.rs new file mode 100644 index 0000000000000..f358460b33825 --- /dev/null +++ b/src/test/incremental/issue-85197-invalid-span/invalid_span_main.rs @@ -0,0 +1,24 @@ +// revisions: rpass1 rpass2 +// aux-build:respan.rs +// aux-build:invalid-span-helper-lib.rs + +// This issue has several different parts. The high level idea is: +// 1. We create an 'invalid' span with the help of the `respan` proc-macro, +// The compiler attempts to prevent the creation of invalid spans by +// refusing to join spans with different `SyntaxContext`s. We work around +// this by applying the same `SyntaxContext` to the span of every token, +// using `Span::resolved_at` +// 2. We using this invalid span in the body of a function, causing it to get +// encoded into the `optimized_mir` +// 3. We call the function from a different crate - since the function is generic, +// monomorphization runs, causing `optimized_mir` to get called. +// 4. We re-run compilation using our populated incremental cache, but without +// making any changes. When we recompile the crate containing our generic function +// (`invalid_span_helper_lib`), we load the span from the incremental cache, and +// write it into the crate metadata. + +extern crate invalid_span_helper_lib; + +fn main() { + invalid_span_helper_lib::foo::(); +} From 28ea3582642e9b41c7e047e007f68cd7bf20ba45 Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Tue, 1 Jun 2021 02:21:26 +0200 Subject: [PATCH 49/52] Remove unsound TrustedRandomAccess implementations Removes the implementations that depend on the user-definable trait `Copy`. Beta backport: Does not modify `vec::IntoIter`. --- .../src/collections/vec_deque/into_iter.rs | 29 +------------------ library/core/src/array/iter.rs | 25 +--------------- 2 files changed, 2 insertions(+), 52 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/into_iter.rs b/library/alloc/src/collections/vec_deque/into_iter.rs index 1c635dd4f27fa..612f7e6eb4da8 100644 --- a/library/alloc/src/collections/vec_deque/into_iter.rs +++ b/library/alloc/src/collections/vec_deque/into_iter.rs @@ -1,5 +1,5 @@ use core::fmt; -use core::iter::{FusedIterator, TrustedLen, TrustedRandomAccess}; +use core::iter::{FusedIterator, TrustedLen}; use super::VecDeque; @@ -36,22 +36,6 @@ impl Iterator for IntoIter { let len = self.inner.len(); (len, Some(len)) } - - #[inline] - unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item - where - Self: TrustedRandomAccess, - { - // Safety: The TrustedRandomAccess contract requires that callers only pass an index - // that is in bounds. - // Additionally Self: TrustedRandomAccess is only implemented for T: Copy which means even - // multiple repeated reads of the same index would be safe and the - // values are !Drop, thus won't suffer from double drops. - unsafe { - let idx = self.inner.wrap_add(self.inner.tail, idx); - self.inner.buffer_read(idx) - } - } } #[stable(feature = "rust1", since = "1.0.0")] @@ -74,14 +58,3 @@ impl FusedIterator for IntoIter {} #[unstable(feature = "trusted_len", issue = "37572")] unsafe impl TrustedLen for IntoIter {} - -#[doc(hidden)] -#[unstable(feature = "trusted_random_access", issue = "none")] -// T: Copy as approximation for !Drop since get_unchecked does not update the pointers -// and thus we can't implement drop-handling -unsafe impl TrustedRandomAccess for IntoIter -where - T: Copy, -{ - const MAY_HAVE_SIDE_EFFECT: bool = false; -} diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index c36542f631488..61ab1b1faff89 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -2,7 +2,7 @@ use crate::{ fmt, - iter::{self, ExactSizeIterator, FusedIterator, TrustedLen, TrustedRandomAccess}, + iter::{self, ExactSizeIterator, FusedIterator, TrustedLen}, mem::{self, MaybeUninit}, ops::Range, ptr, @@ -130,18 +130,6 @@ impl Iterator for IntoIter { fn last(mut self) -> Option { self.next_back() } - - #[inline] - unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item - where - Self: TrustedRandomAccess, - { - // SAFETY: Callers are only allowed to pass an index that is in bounds - // Additionally Self: TrustedRandomAccess is only implemented for T: Copy which means even - // multiple repeated reads of the same index would be safe and the - // values aree !Drop, thus won't suffer from double drops. - unsafe { self.data.get_unchecked(self.alive.start + idx).assume_init_read() } - } } #[stable(feature = "array_value_iter_impls", since = "1.40.0")] @@ -196,17 +184,6 @@ impl FusedIterator for IntoIter {} #[stable(feature = "array_value_iter_impls", since = "1.40.0")] unsafe impl TrustedLen for IntoIter {} -#[doc(hidden)] -#[unstable(feature = "trusted_random_access", issue = "none")] -// T: Copy as approximation for !Drop since get_unchecked does not update the pointers -// and thus we can't implement drop-handling -unsafe impl TrustedRandomAccess for IntoIter -where - T: Copy, -{ - const MAY_HAVE_SIDE_EFFECT: bool = false; -} - #[stable(feature = "array_value_iter_impls", since = "1.40.0")] impl Clone for IntoIter { fn clone(&self) -> Self { From b561bc520bc51f9287163f703ac0aab4921a7e18 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 11 Jun 2021 22:02:11 +0200 Subject: [PATCH 50/52] Hash attributes for crate_hash. --- .../rustc_middle/src/hir/map/collector.rs | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_middle/src/hir/map/collector.rs b/compiler/rustc_middle/src/hir/map/collector.rs index 501e7d624d2e4..57c1b9b82ef8b 100644 --- a/compiler/rustc_middle/src/hir/map/collector.rs +++ b/compiler/rustc_middle/src/hir/map/collector.rs @@ -1,6 +1,6 @@ use crate::arena::Arena; use crate::hir::map::{Entry, HirOwnerData, Map}; -use crate::hir::{Owner, OwnerNodes, ParentedNode}; +use crate::hir::{AttributeMap, Owner, OwnerNodes, ParentedNode}; use crate::ich::StableHashingContext; use crate::middle::cstore::CrateStore; use rustc_data_structures::fingerprint::Fingerprint; @@ -9,7 +9,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::svh::Svh; use rustc_hir as hir; use rustc_hir::def_id::CRATE_DEF_INDEX; -use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE}; +use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID, LOCAL_CRATE}; use rustc_hir::definitions::{self, DefPathHash}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::*; @@ -58,18 +58,28 @@ fn insert_vec_map(map: &mut IndexVec>, k: K, v: V fn hash_body( hcx: &mut StableHashingContext<'_>, + def_id: LocalDefId, def_path_hash: DefPathHash, item_like: impl for<'a> HashStable>, + krate: &Crate<'_>, hir_body_nodes: &mut Vec<(DefPathHash, Fingerprint)>, ) -> Fingerprint { - let hash = { + // Hash of nodes. + let hash: Fingerprint = { let mut stable_hasher = StableHasher::new(); hcx.while_hashing_hir_bodies(true, |hcx| { item_like.hash_stable(hcx, &mut stable_hasher); }); stable_hasher.finish() }; - hir_body_nodes.push((def_path_hash, hash)); + // Hash for crate_hash. + let hash_with_attrs: Fingerprint = { + let mut hasher = StableHasher::new(); + hash.hash_stable(hcx, &mut hasher); + AttributeMap { map: &krate.attrs, prefix: def_id }.hash_stable(hcx, &mut hasher); + hasher.finish() + }; + hir_body_nodes.push((def_path_hash, hash_with_attrs)); hash } @@ -120,7 +130,14 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { attrs: _, } = *krate; - hash_body(&mut hcx, root_mod_def_path_hash, item, &mut hir_body_nodes) + hash_body( + &mut hcx, + CRATE_DEF_ID, + root_mod_def_path_hash, + item, + krate, + &mut hir_body_nodes, + ) }; let mut collector = NodeCollector { @@ -186,6 +203,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { let crate_hash_input = ( ((node_hashes, upstream_crates), source_file_names), (commandline_args_hash, crate_disambiguator.to_fingerprint()), + &self.krate.non_exported_macro_attrs, ); let mut stable_hasher = StableHasher::new(); @@ -297,7 +315,14 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { let def_path_hash = self.definitions.def_path_hash(dep_node_owner); - let hash = hash_body(&mut self.hcx, def_path_hash, item_like, &mut self.hir_body_nodes); + let hash = hash_body( + &mut self.hcx, + dep_node_owner, + def_path_hash, + item_like, + self.krate, + &mut self.hir_body_nodes, + ); self.current_dep_node_owner = dep_node_owner; f(self, hash); From 0b4ed52e6863ea67c47b36c5d2e85ad6e1574a68 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 14 Jun 2021 12:14:30 -0400 Subject: [PATCH 51/52] 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 e105dc815c67717511cf6b204fd074c7ac5585d6 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 14 Jun 2021 13:18:02 -0400 Subject: [PATCH 52/52] 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`.