From 7c76eec30ff6cdb00b234896f6e0c5b76ef7143f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 12 May 2024 09:59:08 +0200 Subject: [PATCH 01/11] reference type safety invariant docs: clarification --- library/core/src/primitive_docs.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/library/core/src/primitive_docs.rs b/library/core/src/primitive_docs.rs index d8597369b9bfd..50e0afab9e6cf 100644 --- a/library/core/src/primitive_docs.rs +++ b/library/core/src/primitive_docs.rs @@ -1475,14 +1475,17 @@ mod prim_usize {} /// /// For instance, this means that unsafe code in a safe function may assume these invariants are /// ensured of arguments passed by the caller, and it may assume that these invariants are ensured -/// of return values from any safe functions it calls. In most cases, the inverse is also true: -/// unsafe code must not violate these invariants when passing arguments to safe functions or -/// returning values from safe functions; such violations may result in undefined behavior. Where -/// exceptions to this latter requirement exist, they will be called out explicitly in documentation. +/// of return values from any safe functions it calls. +/// +/// For the other direction, things are more complicated: when unsafe code passes arguments +/// to safe functions or returns values from safe functions, they generally must *at least* +/// not violate these invariants. The full requirements are stronger, as the reference generally +/// must point to data that is safe to use at type `T`. /// /// It is not decided yet whether unsafe code may violate these invariants temporarily on internal /// data. As a consequence, unsafe code which violates these invariants temporarily on internal data -/// may become unsound in future versions of Rust depending on how this question is decided. +/// may be unsound or become unsound in future versions of Rust depending on how this question is +/// decided. /// /// [allocated object]: ptr#allocated-object #[stable(feature = "rust1", since = "1.0.0")] From 6b3058204a91bb21e2aa845fedfab85a68f75b94 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 19 May 2024 23:45:25 -0400 Subject: [PATCH 02/11] Force the inner coroutine of an async closure to `move` if the outer closure is `move` and `FnOnce` --- compiler/rustc_hir_typeck/src/upvar.rs | 89 ++++++++++++------- .../force-move-due-to-actually-fnonce.rs | 27 ++++++ .../force-move-due-to-inferred-kind.rs | 24 +++++ 3 files changed, 109 insertions(+), 31 deletions(-) create mode 100644 tests/ui/async-await/async-closures/force-move-due-to-actually-fnonce.rs create mode 100644 tests/ui/async-await/async-closures/force-move-due-to-inferred-kind.rs diff --git a/compiler/rustc_hir_typeck/src/upvar.rs b/compiler/rustc_hir_typeck/src/upvar.rs index 9d16f0d48159e..e29a410e2e543 100644 --- a/compiler/rustc_hir_typeck/src/upvar.rs +++ b/compiler/rustc_hir_typeck/src/upvar.rs @@ -204,6 +204,60 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fake_reads: Default::default(), }; + let _ = euv::ExprUseVisitor::new( + &FnCtxt::new(self, self.tcx.param_env(closure_def_id), closure_def_id), + &mut delegate, + ) + .consume_body(body); + + // There are several curious situations with coroutine-closures where + // analysis is too aggressive with borrows when the coroutine-closure is + // marked `move`. Specifically: + // + // 1. If the coroutine-closure was inferred to be `FnOnce` during signature + // inference, then it's still possible that we try to borrow upvars from + // the coroutine-closure because they are not used by the coroutine body + // in a way that forces a move. See the test: + // `async-await/async-closures/force-move-due-to-inferred-kind.rs`. + // + // 2. If the coroutine-closure is forced to be `FnOnce` due to the way it + // uses its upvars, but not *all* upvars would force the closure to `FnOnce`. + // See the test: `async-await/async-closures/force-move-due-to-actually-fnonce.rs`. + // + // This would lead to an impossible to satisfy situation, since `AsyncFnOnce` + // coroutine bodies can't borrow from their parent closure. To fix this, + // we force the inner coroutine to also be `move`. This only matters for + // coroutine-closures that are `move` since otherwise they themselves will + // be borrowing from the outer environment, so there's no self-borrows occuring. + // + // One *important* note is that we do a call to `process_collected_capture_information` + // to eagerly test whether the coroutine would end up `FnOnce`, but we do this + // *before* capturing all the closure args by-value below, since that would always + // cause the analysis to return `FnOnce`. + if let UpvarArgs::Coroutine(..) = args + && let hir::CoroutineKind::Desugared(_, hir::CoroutineSource::Closure) = + self.tcx.coroutine_kind(closure_def_id).expect("coroutine should have kind") + && let parent_hir_id = + self.tcx.local_def_id_to_hir_id(self.tcx.local_parent(closure_def_id)) + && let parent_ty = self.node_ty(parent_hir_id) + && let hir::CaptureBy::Value { move_kw } = + self.tcx.hir_node(parent_hir_id).expect_closure().capture_clause + { + // (1.) Closure signature inference forced this closure to `FnOnce`. + if let Some(ty::ClosureKind::FnOnce) = self.closure_kind(parent_ty) { + capture_clause = hir::CaptureBy::Value { move_kw }; + } + // (2.) The way that the closure uses its upvars means it's `FnOnce`. + else if let (_, ty::ClosureKind::FnOnce, _) = self + .process_collected_capture_information( + capture_clause, + &delegate.capture_information, + ) + { + capture_clause = hir::CaptureBy::Value { move_kw }; + } + } + // As noted in `lower_coroutine_body_with_moved_arguments`, we default the capture mode // to `ByRef` for the `async {}` block internal to async fns/closure. This means // that we would *not* be moving all of the parameters into the async block by default. @@ -253,34 +307,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - let _ = euv::ExprUseVisitor::new( - &FnCtxt::new(self, self.tcx.param_env(closure_def_id), closure_def_id), - &mut delegate, - ) - .consume_body(body); - - // If a coroutine is comes from a coroutine-closure that is `move`, but - // the coroutine-closure was inferred to be `FnOnce` during signature - // inference, then it's still possible that we try to borrow upvars from - // the coroutine-closure because they are not used by the coroutine body - // in a way that forces a move. - // - // This would lead to an impossible to satisfy situation, since `AsyncFnOnce` - // coroutine bodies can't borrow from their parent closure. To fix this, - // we force the inner coroutine to also be `move`. This only matters for - // coroutine-closures that are `move` since otherwise they themselves will - // be borrowing from the outer environment, so there's no self-borrows occuring. - if let UpvarArgs::Coroutine(..) = args - && let hir::CoroutineKind::Desugared(_, hir::CoroutineSource::Closure) = - self.tcx.coroutine_kind(closure_def_id).expect("coroutine should have kind") - && let parent_hir_id = - self.tcx.local_def_id_to_hir_id(self.tcx.local_parent(closure_def_id)) - && let parent_ty = self.node_ty(parent_hir_id) - && let Some(ty::ClosureKind::FnOnce) = self.closure_kind(parent_ty) - { - capture_clause = self.tcx.hir_node(parent_hir_id).expect_closure().capture_clause; - } - debug!( "For closure={:?}, capture_information={:#?}", closure_def_id, delegate.capture_information @@ -289,7 +315,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.log_capture_analysis_first_pass(closure_def_id, &delegate.capture_information, span); let (capture_information, closure_kind, origin) = self - .process_collected_capture_information(capture_clause, delegate.capture_information); + .process_collected_capture_information(capture_clause, &delegate.capture_information); self.compute_min_captures(closure_def_id, capture_information, span); @@ -545,13 +571,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn process_collected_capture_information( &self, capture_clause: hir::CaptureBy, - capture_information: InferredCaptureInformation<'tcx>, + capture_information: &InferredCaptureInformation<'tcx>, ) -> (InferredCaptureInformation<'tcx>, ty::ClosureKind, Option<(Span, Place<'tcx>)>) { let mut closure_kind = ty::ClosureKind::LATTICE_BOTTOM; let mut origin: Option<(Span, Place<'tcx>)> = None; let processed = capture_information - .into_iter() + .iter() + .cloned() .map(|(place, mut capture_info)| { // Apply rules for safety before inferring closure kind let (place, capture_kind) = diff --git a/tests/ui/async-await/async-closures/force-move-due-to-actually-fnonce.rs b/tests/ui/async-await/async-closures/force-move-due-to-actually-fnonce.rs new file mode 100644 index 0000000000000..ce49f55e3e304 --- /dev/null +++ b/tests/ui/async-await/async-closures/force-move-due-to-actually-fnonce.rs @@ -0,0 +1,27 @@ +//@ aux-build:block-on.rs +//@ edition:2021 +//@ check-pass + +#![feature(async_closure)] + +extern crate block_on; + +fn consume(_: String) {} + +fn main() { + block_on::block_on(async { + let x = 1i32; + let s = String::new(); + // `consume(s)` pulls the closure's kind down to `FnOnce`, + // which means that we don't treat the borrow of `x` as a + // self-borrow (with `'env` lifetime). This leads to a lifetime + // error which is solved by forcing the inner coroutine to + // be `move` as well, so that it moves `x`. + let c = async move || { + println!("{x}"); + // This makes the closure FnOnce... + consume(s); + }; + c().await; + }); +} diff --git a/tests/ui/async-await/async-closures/force-move-due-to-inferred-kind.rs b/tests/ui/async-await/async-closures/force-move-due-to-inferred-kind.rs new file mode 100644 index 0000000000000..803c990ef93f1 --- /dev/null +++ b/tests/ui/async-await/async-closures/force-move-due-to-inferred-kind.rs @@ -0,0 +1,24 @@ +//@ aux-build:block-on.rs +//@ edition:2021 +//@ check-pass + +#![feature(async_closure)] + +extern crate block_on; + +fn force_fnonce(t: T) -> T { t } + +fn main() { + block_on::block_on(async { + let x = 1i32; + // `force_fnonce` pulls the closure's kind down to `FnOnce`, + // which means that we don't treat the borrow of `x` as a + // self-borrow (with `'env` lifetime). This leads to a lifetime + // error which is solved by forcing the inner coroutine to + // be `move` as well, so that it moves `x`. + let c = force_fnonce(async move || { + println!("{x}"); + }); + c().await; + }); +} From 8f11f48a027888b71efbb1769b432606e824e577 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Tue, 21 May 2024 10:54:36 +0200 Subject: [PATCH 03/11] Use Backtrace::force_capture instead of Backtrace::capture in rustc_log --- compiler/rustc_log/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_log/src/lib.rs b/compiler/rustc_log/src/lib.rs index 81257f9be8823..e11c45b66e6df 100644 --- a/compiler/rustc_log/src/lib.rs +++ b/compiler/rustc_log/src/lib.rs @@ -159,7 +159,9 @@ where if !target.contains(&self.backtrace_target) { return Ok(()); } - let backtrace = std::backtrace::Backtrace::capture(); + // Use Backtrace::force_capture because we don't want to depend on the + // RUST_BACKTRACE environment variable being set. + let backtrace = std::backtrace::Backtrace::force_capture(); writeln!(writer, "stack backtrace: \n{backtrace:?}") } } From 4486c24db3ca1c698b34ea08bee15194774b53df Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 21 May 2024 12:28:30 -0700 Subject: [PATCH 04/11] Add URL and crate_name to test cases --- tests/rustdoc/issue-80233-normalize-auto-trait.rs | 4 +++- .../issue-81141-private-reexport-in-public-api-2.rs | 1 + ...ssue-81141-private-reexport-in-public-api-generics.rs | 1 + .../issue-81141-private-reexport-in-public-api-hidden.rs | 1 + ...issue-81141-private-reexport-in-public-api-private.rs | 1 + .../issue-81141-private-reexport-in-public-api.rs | 1 + tests/rustdoc/issue-82465-asref-for-and-of-local.rs | 5 ++++- ...375-multiple-mods-w-same-name-doc-inline-last-item.rs | 1 + .../issue-83375-multiple-mods-w-same-name-doc-inline.rs | 1 + tests/rustdoc/issue-85454.rs | 1 + tests/rustdoc/issue-86620.rs | 6 ++++-- tests/rustdoc/issue-88600.rs | 4 +++- tests/rustdoc/issue-89309-heading-levels.rs | 1 + tests/rustdoc/issue-89852.rs | 6 ++++-- .../rustdoc/issue-94183-blanket-impl-reexported-trait.rs | 1 + tests/rustdoc/issue-95633.rs | 1 + tests/rustdoc/issue-95873.rs | 5 ++++- tests/rustdoc/issue-96381.rs | 1 + tests/rustdoc/issue-98697.rs | 9 +++++---- ...e-99221-multiple-macro-rules-w-same-name-submodule.rs | 1 + 20 files changed, 40 insertions(+), 12 deletions(-) diff --git a/tests/rustdoc/issue-80233-normalize-auto-trait.rs b/tests/rustdoc/issue-80233-normalize-auto-trait.rs index 62fbc2444dbc2..0649801863077 100644 --- a/tests/rustdoc/issue-80233-normalize-auto-trait.rs +++ b/tests/rustdoc/issue-80233-normalize-auto-trait.rs @@ -1,7 +1,9 @@ // Regression test for issue #80233 // Tests that we don't ICE when processing auto traits +// https://github.com/rust-lang/rust/issues/80233 #![crate_type = "lib"] +#![crate_name = "foo"] pub trait Trait1 {} pub trait Trait2 { @@ -30,7 +32,7 @@ impl Trait3 for Vec { pub struct Struct1 {} -// @has issue_80233_normalize_auto_trait/struct.Question.html +// @has foo/struct.Question.html // @has - '//h3[@class="code-header"]' 'impl Send for Question' pub struct Question { pub ins: < as Trait3>::Type3 as Trait2>::Type2, diff --git a/tests/rustdoc/issue-81141-private-reexport-in-public-api-2.rs b/tests/rustdoc/issue-81141-private-reexport-in-public-api-2.rs index fba310cec6d6b..c066f54b32b20 100644 --- a/tests/rustdoc/issue-81141-private-reexport-in-public-api-2.rs +++ b/tests/rustdoc/issue-81141-private-reexport-in-public-api-2.rs @@ -1,5 +1,6 @@ //@ edition:2015 +// https://github.com/rust-lang/rust/issues/81141 #![crate_name = "foo"] use external::Public as Private; diff --git a/tests/rustdoc/issue-81141-private-reexport-in-public-api-generics.rs b/tests/rustdoc/issue-81141-private-reexport-in-public-api-generics.rs index 7e289508628f5..1c86c769a124f 100644 --- a/tests/rustdoc/issue-81141-private-reexport-in-public-api-generics.rs +++ b/tests/rustdoc/issue-81141-private-reexport-in-public-api-generics.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/81141 #![crate_name = "foo"] use crate::bar::Foo as Alias; diff --git a/tests/rustdoc/issue-81141-private-reexport-in-public-api-hidden.rs b/tests/rustdoc/issue-81141-private-reexport-in-public-api-hidden.rs index 388f69ba3265a..7d6fadf26e2f2 100644 --- a/tests/rustdoc/issue-81141-private-reexport-in-public-api-hidden.rs +++ b/tests/rustdoc/issue-81141-private-reexport-in-public-api-hidden.rs @@ -1,5 +1,6 @@ //@ compile-flags: -Z unstable-options --document-hidden-items +// https://github.com/rust-lang/rust/issues/81141 #![crate_name = "foo"] #[doc(hidden)] diff --git a/tests/rustdoc/issue-81141-private-reexport-in-public-api-private.rs b/tests/rustdoc/issue-81141-private-reexport-in-public-api-private.rs index 2633f98c4f303..6bf507838d55d 100644 --- a/tests/rustdoc/issue-81141-private-reexport-in-public-api-private.rs +++ b/tests/rustdoc/issue-81141-private-reexport-in-public-api-private.rs @@ -1,5 +1,6 @@ //@ compile-flags: --document-private-items +// https://github.com/rust-lang/rust/issues/81141 #![crate_name = "foo"] use crate::bar::Bar as Alias; diff --git a/tests/rustdoc/issue-81141-private-reexport-in-public-api.rs b/tests/rustdoc/issue-81141-private-reexport-in-public-api.rs index bd54d02c6ec8f..d695ed7fbfac2 100644 --- a/tests/rustdoc/issue-81141-private-reexport-in-public-api.rs +++ b/tests/rustdoc/issue-81141-private-reexport-in-public-api.rs @@ -1,6 +1,7 @@ // This test ensures that if a private re-export is present in a public API, it'll be // replaced by the first public item in the re-export chain or by the private item. +// https://github.com/rust-lang/rust/issues/81141 #![crate_name = "foo"] use crate::bar::Bar as Alias; diff --git a/tests/rustdoc/issue-82465-asref-for-and-of-local.rs b/tests/rustdoc/issue-82465-asref-for-and-of-local.rs index adf4d111a6cb9..e620468890435 100644 --- a/tests/rustdoc/issue-82465-asref-for-and-of-local.rs +++ b/tests/rustdoc/issue-82465-asref-for-and-of-local.rs @@ -1,7 +1,10 @@ +// https://github.com/rust-lang/rust/issues/82465 +#![crate_name = "foo"] + use std::convert::AsRef; pub struct Local; -// @has issue_82465_asref_for_and_of_local/struct.Local.html '//h3[@class="code-header"]' 'impl AsRef for Local' +// @has foo/struct.Local.html '//h3[@class="code-header"]' 'impl AsRef for Local' impl AsRef for Local { fn as_ref(&self) -> &str { todo!() diff --git a/tests/rustdoc/issue-83375-multiple-mods-w-same-name-doc-inline-last-item.rs b/tests/rustdoc/issue-83375-multiple-mods-w-same-name-doc-inline-last-item.rs index 9bce25846d858..7bad825b35fe4 100644 --- a/tests/rustdoc/issue-83375-multiple-mods-w-same-name-doc-inline-last-item.rs +++ b/tests/rustdoc/issue-83375-multiple-mods-w-same-name-doc-inline-last-item.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/83375 #![crate_name = "foo"] pub mod sub { diff --git a/tests/rustdoc/issue-83375-multiple-mods-w-same-name-doc-inline.rs b/tests/rustdoc/issue-83375-multiple-mods-w-same-name-doc-inline.rs index d0960dfef4362..9b3dfd45370b1 100644 --- a/tests/rustdoc/issue-83375-multiple-mods-w-same-name-doc-inline.rs +++ b/tests/rustdoc/issue-83375-multiple-mods-w-same-name-doc-inline.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/83375 #![crate_name = "foo"] pub mod sub { diff --git a/tests/rustdoc/issue-85454.rs b/tests/rustdoc/issue-85454.rs index 790db0c5dcfef..de806db77094d 100644 --- a/tests/rustdoc/issue-85454.rs +++ b/tests/rustdoc/issue-85454.rs @@ -1,6 +1,7 @@ //@ aux-build:issue-85454.rs //@ build-aux-docs #![crate_name = "foo"] +// https://github.com/rust-lang/rust/issues/85454 extern crate issue_85454; diff --git a/tests/rustdoc/issue-86620.rs b/tests/rustdoc/issue-86620.rs index a7ac0f1d291b8..537dadd212419 100644 --- a/tests/rustdoc/issue-86620.rs +++ b/tests/rustdoc/issue-86620.rs @@ -1,9 +1,11 @@ //@ aux-build:issue-86620-1.rs +#![crate_name = "foo"] +// https://github.com/rust-lang/rust/issues/86620 extern crate issue_86620_1; use issue_86620_1::*; -// @!has issue_86620/struct.S.html '//*[@id="method.vzip"]//a[@class="fnname"]/@href' #tymethod.vzip -// @has issue_86620/struct.S.html '//*[@id="method.vzip"]//a[@class="anchor"]/@href' #method.vzip +// @!has foo/struct.S.html '//*[@id="method.vzip"]//a[@class="fnname"]/@href' #tymethod.vzip +// @has foo/struct.S.html '//*[@id="method.vzip"]//a[@class="anchor"]/@href' #method.vzip pub struct S; diff --git a/tests/rustdoc/issue-88600.rs b/tests/rustdoc/issue-88600.rs index f89af472f6e42..31d96e9db758b 100644 --- a/tests/rustdoc/issue-88600.rs +++ b/tests/rustdoc/issue-88600.rs @@ -1,4 +1,6 @@ // This test ensure that #[doc(hidden)] is applied correctly in enum variant fields. +// https://github.com/rust-lang/rust/issues/88600 +#![crate_name = "foo"] // Denotes a field which should be hidden. pub struct H; @@ -6,7 +8,7 @@ pub struct H; // Denotes a field which should not be hidden (shown). pub struct S; -// @has issue_88600/enum.FooEnum.html +// @has foo/enum.FooEnum.html pub enum FooEnum { // @has - '//*[@id="variant.HiddenTupleItem"]//h3' 'HiddenTupleItem(/* private fields */)' // @count - '//*[@id="variant.HiddenTupleItem.field.0"]' 0 diff --git a/tests/rustdoc/issue-89309-heading-levels.rs b/tests/rustdoc/issue-89309-heading-levels.rs index bb706c28ffa51..caa994285252f 100644 --- a/tests/rustdoc/issue-89309-heading-levels.rs +++ b/tests/rustdoc/issue-89309-heading-levels.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/89309 #![crate_name = "foo"] // @has foo/trait.Read.html diff --git a/tests/rustdoc/issue-89852.rs b/tests/rustdoc/issue-89852.rs index e9b3d80c92ee8..cffe1289ce823 100644 --- a/tests/rustdoc/issue-89852.rs +++ b/tests/rustdoc/issue-89852.rs @@ -1,10 +1,12 @@ //@ edition:2018 +// https://github.com/rust-lang/rust/issues/89852 +#![crate_name = "foo"] #![no_core] #![feature(no_core)] -// @matchesraw 'issue_89852/sidebar-items.js' '"repro"' -// @!matchesraw 'issue_89852/sidebar-items.js' '"repro".*"repro"' +// @matchesraw 'foo/sidebar-items.js' '"repro"' +// @!matchesraw 'foo/sidebar-items.js' '"repro".*"repro"' #[macro_export] macro_rules! repro { diff --git a/tests/rustdoc/issue-94183-blanket-impl-reexported-trait.rs b/tests/rustdoc/issue-94183-blanket-impl-reexported-trait.rs index 95ddd4c74715a..343e030da9e2b 100644 --- a/tests/rustdoc/issue-94183-blanket-impl-reexported-trait.rs +++ b/tests/rustdoc/issue-94183-blanket-impl-reexported-trait.rs @@ -2,6 +2,7 @@ // This test ensures that a publicly re-exported private trait will // appear in the blanket impl list. +// https://github.com/rust-lang/rust/issues/94183 #![crate_name = "foo"] // @has 'foo/struct.S.html' diff --git a/tests/rustdoc/issue-95633.rs b/tests/rustdoc/issue-95633.rs index 5695ef579f2b5..7f612a0b60ae4 100644 --- a/tests/rustdoc/issue-95633.rs +++ b/tests/rustdoc/issue-95633.rs @@ -1,6 +1,7 @@ //@ compile-flags: --document-private-items // This ensures that no ICE is triggered when rustdoc is run on this code. +// https://github.com/rust-lang/rust/issues/95633 mod stdlib { pub (crate) use std::i8; diff --git a/tests/rustdoc/issue-95873.rs b/tests/rustdoc/issue-95873.rs index 83f1f2f75bf02..5a817fb3409e9 100644 --- a/tests/rustdoc/issue-95873.rs +++ b/tests/rustdoc/issue-95873.rs @@ -1,2 +1,5 @@ -// @has issue_95873/index.html "//*[@class='item-name']" "pub use ::std as x;" +// https://github.com/rust-lang/rust/issues/95873 +#![crate_name = "foo"] + +// @has foo/index.html "//*[@class='item-name']" "pub use ::std as x;" pub use ::std as x; diff --git a/tests/rustdoc/issue-96381.rs b/tests/rustdoc/issue-96381.rs index 90875c076057d..6d6e5e0a8398b 100644 --- a/tests/rustdoc/issue-96381.rs +++ b/tests/rustdoc/issue-96381.rs @@ -1,4 +1,5 @@ //@ should-fail +// https://github.com/rust-lang/rust/issues/96381 #![allow(unused)] diff --git a/tests/rustdoc/issue-98697.rs b/tests/rustdoc/issue-98697.rs index df9f291511134..545af512d3d02 100644 --- a/tests/rustdoc/issue-98697.rs +++ b/tests/rustdoc/issue-98697.rs @@ -1,5 +1,6 @@ //@ aux-build:issue-98697-reexport-with-anonymous-lifetime.rs //@ ignore-cross-compile +#![crate_name = "foo"] // When reexporting a function with a HRTB with anonymous lifetimes, // make sure the anonymous lifetimes are not rendered. @@ -8,10 +9,10 @@ extern crate issue_98697_reexport_with_anonymous_lifetime; -// @has issue_98697/fn.repro.html '//pre[@class="rust item-decl"]/code' 'fn repro()where F: Fn(&str)' -// @!has issue_98697/fn.repro.html '//pre[@class="rust item-decl"]/code' 'for<' +// @has foo/fn.repro.html '//pre[@class="rust item-decl"]/code' 'fn repro()where F: Fn(&str)' +// @!has foo/fn.repro.html '//pre[@class="rust item-decl"]/code' 'for<' pub use issue_98697_reexport_with_anonymous_lifetime::repro; -// @has issue_98697/struct.Extra.html '//div[@id="trait-implementations-list"]//h3[@class="code-header"]' 'impl MyTrait<&Extra> for Extra' -// @!has issue_98697/struct.Extra.html '//div[@id="trait-implementations-list"]//h3[@class="code-header"]' 'impl<' +// @has foo/struct.Extra.html '//div[@id="trait-implementations-list"]//h3[@class="code-header"]' 'impl MyTrait<&Extra> for Extra' +// @!has foo/struct.Extra.html '//div[@id="trait-implementations-list"]//h3[@class="code-header"]' 'impl<' pub use issue_98697_reexport_with_anonymous_lifetime::Extra; diff --git a/tests/rustdoc/issue-99221-multiple-macro-rules-w-same-name-submodule.rs b/tests/rustdoc/issue-99221-multiple-macro-rules-w-same-name-submodule.rs index d3ccd1c069b6e..ed1e42c1f4eeb 100644 --- a/tests/rustdoc/issue-99221-multiple-macro-rules-w-same-name-submodule.rs +++ b/tests/rustdoc/issue-99221-multiple-macro-rules-w-same-name-submodule.rs @@ -2,6 +2,7 @@ //@ build-aux-docs //@ ignore-cross-compile +// https://github.com/rust-lang/rust/issues/99221 #![crate_name = "foo"] #[macro_use] From 55bd054a21533cbaa02836b0ca125c2eaaa4b8f4 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 21 May 2024 12:28:34 -0700 Subject: [PATCH 05/11] rustdoc: rename `issue-\d+.rs` tests to have meaningful names --- ...-asref-for-and-of-local.rs => asref-for-and-of-local-82465.rs} | 0 ...reexported-trait.rs => blanket-impl-reexported-trait-94183.rs} | 0 .../{issue-88600.rs => enum-variant-doc-hidden-field-88600.rs} | 0 .../{issue-89309-heading-levels.rs => heading-levels-89309.rs} | 0 .../{issue-86620.rs => method-anchor-in-blanket-impl-86620.rs} | 0 ...ule.rs => multiple-macro-rules-w-same-name-submodule-99221.rs} | 0 ...oc-inline.rs => multiple-mods-w-same-name-doc-inline-83375.rs} | 0 ...rs => multiple-mods-w-same-name-doc-inline-last-item-83375.rs} | 0 ...0233-normalize-auto-trait.rs => normalize-auto-trait-80233.rs} | 0 ...ort-in-public-api.rs => private-export-in-public-api-81141.rs} | 0 ...-public-api-2.rs => private-reexport-in-public-api-81141-2.rs} | 0 ...nerics.rs => private-reexport-in-public-api-generics-81141.rs} | 0 ...i-hidden.rs => private-reexport-in-public-api-hidden-81141.rs} | 0 ...private.rs => private-reexport-in-public-api-private-81141.rs} | 0 tests/rustdoc/{issue-89852.rs => pub-use-exported-macro-89852.rs} | 0 ...95633.rs => pub-use-primitive-document-private-items-95633.rs} | 0 tests/rustdoc/{issue-95873.rs => pub-use-root-path-95873.rs} | 0 tests/rustdoc/{issue-85454.rs => qpath-self-85454.rs} | 0 .../{issue-98697.rs => reexport-with-anonymous-lifetime-98697.rs} | 0 .../{issue-96381.rs => underscore-type-in-trait-impl-96381.rs} | 0 20 files changed, 0 insertions(+), 0 deletions(-) rename tests/rustdoc/{issue-82465-asref-for-and-of-local.rs => asref-for-and-of-local-82465.rs} (100%) rename tests/rustdoc/{issue-94183-blanket-impl-reexported-trait.rs => blanket-impl-reexported-trait-94183.rs} (100%) rename tests/rustdoc/{issue-88600.rs => enum-variant-doc-hidden-field-88600.rs} (100%) rename tests/rustdoc/{issue-89309-heading-levels.rs => heading-levels-89309.rs} (100%) rename tests/rustdoc/{issue-86620.rs => method-anchor-in-blanket-impl-86620.rs} (100%) rename tests/rustdoc/{issue-99221-multiple-macro-rules-w-same-name-submodule.rs => multiple-macro-rules-w-same-name-submodule-99221.rs} (100%) rename tests/rustdoc/{issue-83375-multiple-mods-w-same-name-doc-inline.rs => multiple-mods-w-same-name-doc-inline-83375.rs} (100%) rename tests/rustdoc/{issue-83375-multiple-mods-w-same-name-doc-inline-last-item.rs => multiple-mods-w-same-name-doc-inline-last-item-83375.rs} (100%) rename tests/rustdoc/{issue-80233-normalize-auto-trait.rs => normalize-auto-trait-80233.rs} (100%) rename tests/rustdoc/{issue-81141-private-reexport-in-public-api.rs => private-export-in-public-api-81141.rs} (100%) rename tests/rustdoc/{issue-81141-private-reexport-in-public-api-2.rs => private-reexport-in-public-api-81141-2.rs} (100%) rename tests/rustdoc/{issue-81141-private-reexport-in-public-api-generics.rs => private-reexport-in-public-api-generics-81141.rs} (100%) rename tests/rustdoc/{issue-81141-private-reexport-in-public-api-hidden.rs => private-reexport-in-public-api-hidden-81141.rs} (100%) rename tests/rustdoc/{issue-81141-private-reexport-in-public-api-private.rs => private-reexport-in-public-api-private-81141.rs} (100%) rename tests/rustdoc/{issue-89852.rs => pub-use-exported-macro-89852.rs} (100%) rename tests/rustdoc/{issue-95633.rs => pub-use-primitive-document-private-items-95633.rs} (100%) rename tests/rustdoc/{issue-95873.rs => pub-use-root-path-95873.rs} (100%) rename tests/rustdoc/{issue-85454.rs => qpath-self-85454.rs} (100%) rename tests/rustdoc/{issue-98697.rs => reexport-with-anonymous-lifetime-98697.rs} (100%) rename tests/rustdoc/{issue-96381.rs => underscore-type-in-trait-impl-96381.rs} (100%) diff --git a/tests/rustdoc/issue-82465-asref-for-and-of-local.rs b/tests/rustdoc/asref-for-and-of-local-82465.rs similarity index 100% rename from tests/rustdoc/issue-82465-asref-for-and-of-local.rs rename to tests/rustdoc/asref-for-and-of-local-82465.rs diff --git a/tests/rustdoc/issue-94183-blanket-impl-reexported-trait.rs b/tests/rustdoc/blanket-impl-reexported-trait-94183.rs similarity index 100% rename from tests/rustdoc/issue-94183-blanket-impl-reexported-trait.rs rename to tests/rustdoc/blanket-impl-reexported-trait-94183.rs diff --git a/tests/rustdoc/issue-88600.rs b/tests/rustdoc/enum-variant-doc-hidden-field-88600.rs similarity index 100% rename from tests/rustdoc/issue-88600.rs rename to tests/rustdoc/enum-variant-doc-hidden-field-88600.rs diff --git a/tests/rustdoc/issue-89309-heading-levels.rs b/tests/rustdoc/heading-levels-89309.rs similarity index 100% rename from tests/rustdoc/issue-89309-heading-levels.rs rename to tests/rustdoc/heading-levels-89309.rs diff --git a/tests/rustdoc/issue-86620.rs b/tests/rustdoc/method-anchor-in-blanket-impl-86620.rs similarity index 100% rename from tests/rustdoc/issue-86620.rs rename to tests/rustdoc/method-anchor-in-blanket-impl-86620.rs diff --git a/tests/rustdoc/issue-99221-multiple-macro-rules-w-same-name-submodule.rs b/tests/rustdoc/multiple-macro-rules-w-same-name-submodule-99221.rs similarity index 100% rename from tests/rustdoc/issue-99221-multiple-macro-rules-w-same-name-submodule.rs rename to tests/rustdoc/multiple-macro-rules-w-same-name-submodule-99221.rs diff --git a/tests/rustdoc/issue-83375-multiple-mods-w-same-name-doc-inline.rs b/tests/rustdoc/multiple-mods-w-same-name-doc-inline-83375.rs similarity index 100% rename from tests/rustdoc/issue-83375-multiple-mods-w-same-name-doc-inline.rs rename to tests/rustdoc/multiple-mods-w-same-name-doc-inline-83375.rs diff --git a/tests/rustdoc/issue-83375-multiple-mods-w-same-name-doc-inline-last-item.rs b/tests/rustdoc/multiple-mods-w-same-name-doc-inline-last-item-83375.rs similarity index 100% rename from tests/rustdoc/issue-83375-multiple-mods-w-same-name-doc-inline-last-item.rs rename to tests/rustdoc/multiple-mods-w-same-name-doc-inline-last-item-83375.rs diff --git a/tests/rustdoc/issue-80233-normalize-auto-trait.rs b/tests/rustdoc/normalize-auto-trait-80233.rs similarity index 100% rename from tests/rustdoc/issue-80233-normalize-auto-trait.rs rename to tests/rustdoc/normalize-auto-trait-80233.rs diff --git a/tests/rustdoc/issue-81141-private-reexport-in-public-api.rs b/tests/rustdoc/private-export-in-public-api-81141.rs similarity index 100% rename from tests/rustdoc/issue-81141-private-reexport-in-public-api.rs rename to tests/rustdoc/private-export-in-public-api-81141.rs diff --git a/tests/rustdoc/issue-81141-private-reexport-in-public-api-2.rs b/tests/rustdoc/private-reexport-in-public-api-81141-2.rs similarity index 100% rename from tests/rustdoc/issue-81141-private-reexport-in-public-api-2.rs rename to tests/rustdoc/private-reexport-in-public-api-81141-2.rs diff --git a/tests/rustdoc/issue-81141-private-reexport-in-public-api-generics.rs b/tests/rustdoc/private-reexport-in-public-api-generics-81141.rs similarity index 100% rename from tests/rustdoc/issue-81141-private-reexport-in-public-api-generics.rs rename to tests/rustdoc/private-reexport-in-public-api-generics-81141.rs diff --git a/tests/rustdoc/issue-81141-private-reexport-in-public-api-hidden.rs b/tests/rustdoc/private-reexport-in-public-api-hidden-81141.rs similarity index 100% rename from tests/rustdoc/issue-81141-private-reexport-in-public-api-hidden.rs rename to tests/rustdoc/private-reexport-in-public-api-hidden-81141.rs diff --git a/tests/rustdoc/issue-81141-private-reexport-in-public-api-private.rs b/tests/rustdoc/private-reexport-in-public-api-private-81141.rs similarity index 100% rename from tests/rustdoc/issue-81141-private-reexport-in-public-api-private.rs rename to tests/rustdoc/private-reexport-in-public-api-private-81141.rs diff --git a/tests/rustdoc/issue-89852.rs b/tests/rustdoc/pub-use-exported-macro-89852.rs similarity index 100% rename from tests/rustdoc/issue-89852.rs rename to tests/rustdoc/pub-use-exported-macro-89852.rs diff --git a/tests/rustdoc/issue-95633.rs b/tests/rustdoc/pub-use-primitive-document-private-items-95633.rs similarity index 100% rename from tests/rustdoc/issue-95633.rs rename to tests/rustdoc/pub-use-primitive-document-private-items-95633.rs diff --git a/tests/rustdoc/issue-95873.rs b/tests/rustdoc/pub-use-root-path-95873.rs similarity index 100% rename from tests/rustdoc/issue-95873.rs rename to tests/rustdoc/pub-use-root-path-95873.rs diff --git a/tests/rustdoc/issue-85454.rs b/tests/rustdoc/qpath-self-85454.rs similarity index 100% rename from tests/rustdoc/issue-85454.rs rename to tests/rustdoc/qpath-self-85454.rs diff --git a/tests/rustdoc/issue-98697.rs b/tests/rustdoc/reexport-with-anonymous-lifetime-98697.rs similarity index 100% rename from tests/rustdoc/issue-98697.rs rename to tests/rustdoc/reexport-with-anonymous-lifetime-98697.rs diff --git a/tests/rustdoc/issue-96381.rs b/tests/rustdoc/underscore-type-in-trait-impl-96381.rs similarity index 100% rename from tests/rustdoc/issue-96381.rs rename to tests/rustdoc/underscore-type-in-trait-impl-96381.rs From b5923a95a886588fd40fccd69f1ccca504234194 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 21 May 2024 21:21:26 -0700 Subject: [PATCH 06/11] Move tests into appropriate subdirectories --- .../pub-use-primitive-document-private-items-95633.rs | 1 + tests/rustdoc/{ => inline_cross}/auxiliary/issue-85454.rs | 0 .../auxiliary/reexport-with-anonymous-lifetime-98697.rs} | 0 tests/rustdoc/{ => inline_cross}/qpath-self-85454.rs | 0 .../reexport-with-anonymous-lifetime-98697.rs | 8 ++++---- .../blanket-impl-reexported-trait-94183.rs | 0 .../private-reexport-in-public-api-81141-2.rs | 0 .../private-reexport-in-public-api-81141.rs} | 0 .../private-reexport-in-public-api-generics-81141.rs | 0 .../private-reexport-in-public-api-hidden-81141.rs | 0 .../private-reexport-in-public-api-private-81141.rs | 0 .../reexported-macro-and-macro-export-sidebar-89852.rs} | 0 .../{ => synthetic_auto}/normalize-auto-trait-80233.rs | 0 13 files changed, 5 insertions(+), 4 deletions(-) rename tests/{rustdoc => rustdoc-ui}/pub-use-primitive-document-private-items-95633.rs (93%) rename tests/rustdoc/{ => inline_cross}/auxiliary/issue-85454.rs (100%) rename tests/rustdoc/{auxiliary/issue-98697-reexport-with-anonymous-lifetime.rs => inline_cross/auxiliary/reexport-with-anonymous-lifetime-98697.rs} (100%) rename tests/rustdoc/{ => inline_cross}/qpath-self-85454.rs (100%) rename tests/rustdoc/{ => inline_cross}/reexport-with-anonymous-lifetime-98697.rs (72%) rename tests/rustdoc/{ => inline_local}/blanket-impl-reexported-trait-94183.rs (100%) rename tests/rustdoc/{ => inline_local}/private-reexport-in-public-api-81141-2.rs (100%) rename tests/rustdoc/{private-export-in-public-api-81141.rs => inline_local/private-reexport-in-public-api-81141.rs} (100%) rename tests/rustdoc/{ => inline_local}/private-reexport-in-public-api-generics-81141.rs (100%) rename tests/rustdoc/{ => inline_local}/private-reexport-in-public-api-hidden-81141.rs (100%) rename tests/rustdoc/{ => inline_local}/private-reexport-in-public-api-private-81141.rs (100%) rename tests/rustdoc/{pub-use-exported-macro-89852.rs => inline_local/reexported-macro-and-macro-export-sidebar-89852.rs} (100%) rename tests/rustdoc/{ => synthetic_auto}/normalize-auto-trait-80233.rs (100%) diff --git a/tests/rustdoc/pub-use-primitive-document-private-items-95633.rs b/tests/rustdoc-ui/pub-use-primitive-document-private-items-95633.rs similarity index 93% rename from tests/rustdoc/pub-use-primitive-document-private-items-95633.rs rename to tests/rustdoc-ui/pub-use-primitive-document-private-items-95633.rs index 7f612a0b60ae4..d53a67cde8b43 100644 --- a/tests/rustdoc/pub-use-primitive-document-private-items-95633.rs +++ b/tests/rustdoc-ui/pub-use-primitive-document-private-items-95633.rs @@ -1,3 +1,4 @@ +//@ check-pass //@ compile-flags: --document-private-items // This ensures that no ICE is triggered when rustdoc is run on this code. diff --git a/tests/rustdoc/auxiliary/issue-85454.rs b/tests/rustdoc/inline_cross/auxiliary/issue-85454.rs similarity index 100% rename from tests/rustdoc/auxiliary/issue-85454.rs rename to tests/rustdoc/inline_cross/auxiliary/issue-85454.rs diff --git a/tests/rustdoc/auxiliary/issue-98697-reexport-with-anonymous-lifetime.rs b/tests/rustdoc/inline_cross/auxiliary/reexport-with-anonymous-lifetime-98697.rs similarity index 100% rename from tests/rustdoc/auxiliary/issue-98697-reexport-with-anonymous-lifetime.rs rename to tests/rustdoc/inline_cross/auxiliary/reexport-with-anonymous-lifetime-98697.rs diff --git a/tests/rustdoc/qpath-self-85454.rs b/tests/rustdoc/inline_cross/qpath-self-85454.rs similarity index 100% rename from tests/rustdoc/qpath-self-85454.rs rename to tests/rustdoc/inline_cross/qpath-self-85454.rs diff --git a/tests/rustdoc/reexport-with-anonymous-lifetime-98697.rs b/tests/rustdoc/inline_cross/reexport-with-anonymous-lifetime-98697.rs similarity index 72% rename from tests/rustdoc/reexport-with-anonymous-lifetime-98697.rs rename to tests/rustdoc/inline_cross/reexport-with-anonymous-lifetime-98697.rs index 545af512d3d02..fe6e5a39c8106 100644 --- a/tests/rustdoc/reexport-with-anonymous-lifetime-98697.rs +++ b/tests/rustdoc/inline_cross/reexport-with-anonymous-lifetime-98697.rs @@ -1,4 +1,4 @@ -//@ aux-build:issue-98697-reexport-with-anonymous-lifetime.rs +//@ aux-build:reexport-with-anonymous-lifetime-98697.rs //@ ignore-cross-compile #![crate_name = "foo"] @@ -7,12 +7,12 @@ // // https://github.com/rust-lang/rust/issues/98697 -extern crate issue_98697_reexport_with_anonymous_lifetime; +extern crate reexport_with_anonymous_lifetime_98697; // @has foo/fn.repro.html '//pre[@class="rust item-decl"]/code' 'fn repro()where F: Fn(&str)' // @!has foo/fn.repro.html '//pre[@class="rust item-decl"]/code' 'for<' -pub use issue_98697_reexport_with_anonymous_lifetime::repro; +pub use reexport_with_anonymous_lifetime_98697::repro; // @has foo/struct.Extra.html '//div[@id="trait-implementations-list"]//h3[@class="code-header"]' 'impl MyTrait<&Extra> for Extra' // @!has foo/struct.Extra.html '//div[@id="trait-implementations-list"]//h3[@class="code-header"]' 'impl<' -pub use issue_98697_reexport_with_anonymous_lifetime::Extra; +pub use reexport_with_anonymous_lifetime_98697::Extra; diff --git a/tests/rustdoc/blanket-impl-reexported-trait-94183.rs b/tests/rustdoc/inline_local/blanket-impl-reexported-trait-94183.rs similarity index 100% rename from tests/rustdoc/blanket-impl-reexported-trait-94183.rs rename to tests/rustdoc/inline_local/blanket-impl-reexported-trait-94183.rs diff --git a/tests/rustdoc/private-reexport-in-public-api-81141-2.rs b/tests/rustdoc/inline_local/private-reexport-in-public-api-81141-2.rs similarity index 100% rename from tests/rustdoc/private-reexport-in-public-api-81141-2.rs rename to tests/rustdoc/inline_local/private-reexport-in-public-api-81141-2.rs diff --git a/tests/rustdoc/private-export-in-public-api-81141.rs b/tests/rustdoc/inline_local/private-reexport-in-public-api-81141.rs similarity index 100% rename from tests/rustdoc/private-export-in-public-api-81141.rs rename to tests/rustdoc/inline_local/private-reexport-in-public-api-81141.rs diff --git a/tests/rustdoc/private-reexport-in-public-api-generics-81141.rs b/tests/rustdoc/inline_local/private-reexport-in-public-api-generics-81141.rs similarity index 100% rename from tests/rustdoc/private-reexport-in-public-api-generics-81141.rs rename to tests/rustdoc/inline_local/private-reexport-in-public-api-generics-81141.rs diff --git a/tests/rustdoc/private-reexport-in-public-api-hidden-81141.rs b/tests/rustdoc/inline_local/private-reexport-in-public-api-hidden-81141.rs similarity index 100% rename from tests/rustdoc/private-reexport-in-public-api-hidden-81141.rs rename to tests/rustdoc/inline_local/private-reexport-in-public-api-hidden-81141.rs diff --git a/tests/rustdoc/private-reexport-in-public-api-private-81141.rs b/tests/rustdoc/inline_local/private-reexport-in-public-api-private-81141.rs similarity index 100% rename from tests/rustdoc/private-reexport-in-public-api-private-81141.rs rename to tests/rustdoc/inline_local/private-reexport-in-public-api-private-81141.rs diff --git a/tests/rustdoc/pub-use-exported-macro-89852.rs b/tests/rustdoc/inline_local/reexported-macro-and-macro-export-sidebar-89852.rs similarity index 100% rename from tests/rustdoc/pub-use-exported-macro-89852.rs rename to tests/rustdoc/inline_local/reexported-macro-and-macro-export-sidebar-89852.rs diff --git a/tests/rustdoc/normalize-auto-trait-80233.rs b/tests/rustdoc/synthetic_auto/normalize-auto-trait-80233.rs similarity index 100% rename from tests/rustdoc/normalize-auto-trait-80233.rs rename to tests/rustdoc/synthetic_auto/normalize-auto-trait-80233.rs From 722b2ee17d846d9ba1a7478a5368a3bbaae3e665 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Wed, 22 May 2024 07:38:37 +0200 Subject: [PATCH 07/11] Remove unnecessary `.md` from the documentation sidebar --- src/doc/rustc/src/SUMMARY.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index 6f81495585707..4ef2fcebe9283 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -20,10 +20,10 @@ - [\*-apple-darwin](platform-support/apple-darwin.md) - [i686-apple-darwin](platform-support/i686-apple-darwin.md) - [x86_64h-apple-darwin](platform-support/x86_64h-apple-darwin.md) - - [arm64e-apple-darwin.md](platform-support/arm64e-apple-darwin.md) + - [arm64e-apple-darwin](platform-support/arm64e-apple-darwin.md) - [\*-apple-ios](platform-support/apple-ios.md) - [\*-apple-ios-macabi](platform-support/apple-ios-macabi.md) - - [arm64e-apple-ios.md](platform-support/arm64e-apple-ios.md) + - [arm64e-apple-ios](platform-support/arm64e-apple-ios.md) - [\*-apple-tvos](platform-support/apple-tvos.md) - [\*-apple-watchos](platform-support/apple-watchos.md) - [\*-apple-visionos](platform-support/apple-visionos.md) From 2c61c0085964a6e11c3ba51951abd71a7ff9066c Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 21 May 2024 15:16:09 +1000 Subject: [PATCH 08/11] Fix up whitespace in `compiler/rustc_macros/src/serialize.rs`. --- compiler/rustc_macros/src/serialize.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_macros/src/serialize.rs b/compiler/rustc_macros/src/serialize.rs index 5fa11d22f0e75..7b5dd1601c1f6 100644 --- a/compiler/rustc_macros/src/serialize.rs +++ b/compiler/rustc_macros/src/serialize.rs @@ -13,7 +13,7 @@ pub fn type_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2: quote! {} }; - s.add_impl_generic(parse_quote! {#decoder_ty: ::rustc_type_ir::codec::TyDecoder #bound }); + s.add_impl_generic(parse_quote! { #decoder_ty: ::rustc_type_ir::codec::TyDecoder #bound }); s.add_bounds(synstructure::AddBounds::Fields); s.underscore_const(true); @@ -34,7 +34,7 @@ pub fn meta_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2: pub fn decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream { let decoder_ty = quote! { __D }; - s.add_impl_generic(parse_quote! {#decoder_ty: ::rustc_span::SpanDecoder}); + s.add_impl_generic(parse_quote! { #decoder_ty: ::rustc_span::SpanDecoder }); s.add_bounds(synstructure::AddBounds::Generics); s.underscore_const(true); @@ -43,7 +43,7 @@ pub fn decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::Toke pub fn decodable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream { let decoder_ty = quote! { __D }; - s.add_impl_generic(parse_quote! {#decoder_ty: ::rustc_serialize::Decoder}); + s.add_impl_generic(parse_quote! { #decoder_ty: ::rustc_serialize::Decoder }); s.add_bounds(synstructure::AddBounds::Generics); s.underscore_const(true); @@ -120,7 +120,7 @@ fn decode_field(field: &syn::Field) -> proc_macro2::TokenStream { let __decoder = quote! { __decoder }; // Use the span of the field for the method call, so // that backtraces will point to the field. - quote_spanned! {field_span=> #decode_inner_method(#__decoder) } + quote_spanned! { field_span=> #decode_inner_method(#__decoder) } } pub fn type_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream { @@ -133,7 +133,7 @@ pub fn type_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2: }; let encoder_ty = quote! { __E }; - s.add_impl_generic(parse_quote! {#encoder_ty: ::rustc_type_ir::codec::TyEncoder #bound }); + s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_type_ir::codec::TyEncoder #bound }); s.add_bounds(synstructure::AddBounds::Fields); s.underscore_const(true); @@ -142,7 +142,7 @@ pub fn type_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2: pub fn meta_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream { if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") { - s.add_impl_generic(parse_quote! {'tcx}); + s.add_impl_generic(parse_quote! { 'tcx }); } s.add_impl_generic(parse_quote! { '__a }); let encoder_ty = quote! { EncodeContext<'__a, 'tcx> }; @@ -154,7 +154,7 @@ pub fn meta_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2: pub fn encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream { let encoder_ty = quote! { __E }; - s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_span::SpanEncoder}); + s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_span::SpanEncoder }); s.add_bounds(synstructure::AddBounds::Generics); s.underscore_const(true); @@ -163,7 +163,7 @@ pub fn encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::Toke pub fn encodable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream { let encoder_ty = quote! { __E }; - s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_serialize::Encoder}); + s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_serialize::Encoder }); s.add_bounds(synstructure::AddBounds::Generics); s.underscore_const(true); From 220f3ab825d135c82243fc83ebf6286d94cdab96 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 21 May 2024 15:12:50 +1000 Subject: [PATCH 09/11] Add a useful comment. For something that wasn't obvious to me. --- compiler/rustc_span/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index f83bacdcebe77..62209e3795fa1 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -33,6 +33,9 @@ #![feature(rustdoc_internals)] // tidy-alphabetical-end +// The code produced by the `Encodable`/`Decodable` derive macros refer to +// `rustc_span::Span{Encoder,Decoder}`. That's fine outside this crate, but doesn't work inside +// this crate without this line making `rustc_span` available. extern crate self as rustc_span; #[macro_use] From e60c1916e0d0ff0cad9d8fce049c3bc31eeb34f0 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 22 May 2024 07:51:27 +1000 Subject: [PATCH 10/11] Remove `#[macro_use]` extern crate tracing` from `rustc_span`. Because explicit macro imports are better than implicit macro imports. --- compiler/rustc_span/src/hygiene.rs | 1 + compiler/rustc_span/src/lib.rs | 4 +--- compiler/rustc_span/src/source_map.rs | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs index aa4bcefab9391..00ef17d630c5d 100644 --- a/compiler/rustc_span/src/hygiene.rs +++ b/compiler/rustc_span/src/hygiene.rs @@ -40,6 +40,7 @@ use std::cell::RefCell; use std::collections::hash_map::Entry; use std::fmt; use std::hash::Hash; +use tracing::{debug, trace}; /// A `SyntaxContext` represents a chain of pairs `(ExpnId, Transparency)` named "marks". #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 62209e3795fa1..b2ca01fe3b94c 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -38,13 +38,11 @@ // this crate without this line making `rustc_span` available. extern crate self as rustc_span; -#[macro_use] -extern crate tracing; - use rustc_data_structures::{outline, AtomicRef}; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; use rustc_serialize::opaque::{FileEncoder, MemDecoder}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; +use tracing::debug; mod caching_source_map_view; pub mod source_map; diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index 2093dcf0e8315..fb212d67997a7 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -16,6 +16,7 @@ use rustc_macros::{Decodable, Encodable}; use std::fs; use std::io::{self, BorrowedBuf, Read}; use std::path; +use tracing::{debug, instrument, trace}; #[cfg(test)] mod tests; From 8ee3d29cd93325db6f973358115f40ee1c785ef0 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Wed, 22 May 2024 00:56:57 -0700 Subject: [PATCH 11/11] Stop using `to_hir_binop` in codegen --- .../rustc_codegen_gcc/src/intrinsic/simd.rs | 13 ++++---- compiler/rustc_codegen_llvm/src/intrinsic.rs | 13 ++++---- compiler/rustc_codegen_ssa/src/base.rs | 32 +++++++++---------- compiler/rustc_codegen_ssa/src/mir/rvalue.rs | 13 ++++---- compiler/rustc_middle/src/mir/tcx.rs | 2 +- 5 files changed, 37 insertions(+), 36 deletions(-) diff --git a/compiler/rustc_codegen_gcc/src/intrinsic/simd.rs b/compiler/rustc_codegen_gcc/src/intrinsic/simd.rs index 0c7cffbe7308b..1625e6ecdb701 100644 --- a/compiler/rustc_codegen_gcc/src/intrinsic/simd.rs +++ b/compiler/rustc_codegen_gcc/src/intrinsic/simd.rs @@ -14,6 +14,7 @@ use rustc_codegen_ssa::mir::operand::OperandRef; use rustc_codegen_ssa::mir::place::PlaceRef; use rustc_codegen_ssa::traits::{BaseTypeMethods, BuilderMethods}; use rustc_hir as hir; +use rustc_middle::mir::BinOp; use rustc_middle::span_bug; use rustc_middle::ty::layout::HasTyCtxt; use rustc_middle::ty::{self, Ty}; @@ -122,12 +123,12 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( let in_ty = arg_tys[0]; let comparison = match name { - sym::simd_eq => Some(hir::BinOpKind::Eq), - sym::simd_ne => Some(hir::BinOpKind::Ne), - sym::simd_lt => Some(hir::BinOpKind::Lt), - sym::simd_le => Some(hir::BinOpKind::Le), - sym::simd_gt => Some(hir::BinOpKind::Gt), - sym::simd_ge => Some(hir::BinOpKind::Ge), + sym::simd_eq => Some(BinOp::Eq), + sym::simd_ne => Some(BinOp::Ne), + sym::simd_lt => Some(BinOp::Lt), + sym::simd_le => Some(BinOp::Le), + sym::simd_gt => Some(BinOp::Gt), + sym::simd_ge => Some(BinOp::Ge), _ => None, }; diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index 80e863af893e0..897132a8e9ccc 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -14,6 +14,7 @@ use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue}; use rustc_codegen_ssa::mir::place::PlaceRef; use rustc_codegen_ssa::traits::*; use rustc_hir as hir; +use rustc_middle::mir::BinOp; use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, LayoutOf}; use rustc_middle::ty::{self, GenericArgsRef, Ty}; use rustc_middle::{bug, span_bug}; @@ -1104,12 +1105,12 @@ fn generic_simd_intrinsic<'ll, 'tcx>( let in_ty = arg_tys[0]; let comparison = match name { - sym::simd_eq => Some(hir::BinOpKind::Eq), - sym::simd_ne => Some(hir::BinOpKind::Ne), - sym::simd_lt => Some(hir::BinOpKind::Lt), - sym::simd_le => Some(hir::BinOpKind::Le), - sym::simd_gt => Some(hir::BinOpKind::Gt), - sym::simd_ge => Some(hir::BinOpKind::Ge), + sym::simd_eq => Some(BinOp::Eq), + sym::simd_ne => Some(BinOp::Ne), + sym::simd_lt => Some(BinOp::Lt), + sym::simd_le => Some(BinOp::Le), + sym::simd_gt => Some(BinOp::Gt), + sym::simd_ge => Some(BinOp::Ge), _ => None, }; diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 877e5b75912ea..66bc5b6606ded 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -20,7 +20,6 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexSet}; use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry}; use rustc_data_structures::sync::par_map; use rustc_data_structures::unord::UnordMap; -use rustc_hir as hir; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::lang_items::LangItem; use rustc_metadata::EncodedMetadata; @@ -30,6 +29,7 @@ use rustc_middle::middle::debugger_visualizer::{DebuggerVisualizerFile, Debugger use rustc_middle::middle::exported_symbols; use rustc_middle::middle::exported_symbols::SymbolExportKind; use rustc_middle::middle::lang_items; +use rustc_middle::mir::BinOp; use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem}; use rustc_middle::query::Providers; use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout}; @@ -46,32 +46,32 @@ use std::time::{Duration, Instant}; use itertools::Itertools; -pub fn bin_op_to_icmp_predicate(op: hir::BinOpKind, signed: bool) -> IntPredicate { +pub fn bin_op_to_icmp_predicate(op: BinOp, signed: bool) -> IntPredicate { match op { - hir::BinOpKind::Eq => IntPredicate::IntEQ, - hir::BinOpKind::Ne => IntPredicate::IntNE, - hir::BinOpKind::Lt => { + BinOp::Eq => IntPredicate::IntEQ, + BinOp::Ne => IntPredicate::IntNE, + BinOp::Lt => { if signed { IntPredicate::IntSLT } else { IntPredicate::IntULT } } - hir::BinOpKind::Le => { + BinOp::Le => { if signed { IntPredicate::IntSLE } else { IntPredicate::IntULE } } - hir::BinOpKind::Gt => { + BinOp::Gt => { if signed { IntPredicate::IntSGT } else { IntPredicate::IntUGT } } - hir::BinOpKind::Ge => { + BinOp::Ge => { if signed { IntPredicate::IntSGE } else { @@ -86,14 +86,14 @@ pub fn bin_op_to_icmp_predicate(op: hir::BinOpKind, signed: bool) -> IntPredicat } } -pub fn bin_op_to_fcmp_predicate(op: hir::BinOpKind) -> RealPredicate { +pub fn bin_op_to_fcmp_predicate(op: BinOp) -> RealPredicate { match op { - hir::BinOpKind::Eq => RealPredicate::RealOEQ, - hir::BinOpKind::Ne => RealPredicate::RealUNE, - hir::BinOpKind::Lt => RealPredicate::RealOLT, - hir::BinOpKind::Le => RealPredicate::RealOLE, - hir::BinOpKind::Gt => RealPredicate::RealOGT, - hir::BinOpKind::Ge => RealPredicate::RealOGE, + BinOp::Eq => RealPredicate::RealOEQ, + BinOp::Ne => RealPredicate::RealUNE, + BinOp::Lt => RealPredicate::RealOLT, + BinOp::Le => RealPredicate::RealOLE, + BinOp::Gt => RealPredicate::RealOGT, + BinOp::Ge => RealPredicate::RealOGE, op => { bug!( "comparison_op_to_fcmp_predicate: expected comparison operator, \ @@ -110,7 +110,7 @@ pub fn compare_simd_types<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( rhs: Bx::Value, t: Ty<'tcx>, ret_ty: Bx::Type, - op: hir::BinOpKind, + op: BinOp, ) -> Bx::Value { let signed = match t.kind() { ty::Float(_) => { diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 00b28cbd0c68a..f9085f502d422 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -7,7 +7,6 @@ use crate::common::IntPredicate; use crate::traits::*; use crate::MemFlags; -use rustc_hir as hir; use rustc_middle::mir; use rustc_middle::ty::cast::{CastTy, IntTy}; use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout}; @@ -896,9 +895,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { | mir::BinOp::Le | mir::BinOp::Ge => { if is_float { - bx.fcmp(base::bin_op_to_fcmp_predicate(op.to_hir_binop()), lhs, rhs) + bx.fcmp(base::bin_op_to_fcmp_predicate(op), lhs, rhs) } else { - bx.icmp(base::bin_op_to_icmp_predicate(op.to_hir_binop(), is_signed), lhs, rhs) + bx.icmp(base::bin_op_to_icmp_predicate(op, is_signed), lhs, rhs) } } mir::BinOp::Cmp => { @@ -912,16 +911,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // `PartialOrd`, so only use it in debug for now. Once LLVM can handle it // better (see ), it'll // be worth trying it in optimized builds as well. - let is_gt = bx.icmp(pred(hir::BinOpKind::Gt), lhs, rhs); + let is_gt = bx.icmp(pred(mir::BinOp::Gt), lhs, rhs); let gtext = bx.zext(is_gt, bx.type_i8()); - let is_lt = bx.icmp(pred(hir::BinOpKind::Lt), lhs, rhs); + let is_lt = bx.icmp(pred(mir::BinOp::Lt), lhs, rhs); let ltext = bx.zext(is_lt, bx.type_i8()); bx.unchecked_ssub(gtext, ltext) } else { // These operations are those expected by `tests/codegen/integer-cmp.rs`, // from . - let is_lt = bx.icmp(pred(hir::BinOpKind::Lt), lhs, rhs); - let is_ne = bx.icmp(pred(hir::BinOpKind::Ne), lhs, rhs); + let is_lt = bx.icmp(pred(mir::BinOp::Lt), lhs, rhs); + let is_ne = bx.icmp(pred(mir::BinOp::Ne), lhs, rhs); let ge = bx.select( is_ne, bx.cx().const_i8(Ordering::Greater as i8), diff --git a/compiler/rustc_middle/src/mir/tcx.rs b/compiler/rustc_middle/src/mir/tcx.rs index e1ae2e0866675..c421c937dc36d 100644 --- a/compiler/rustc_middle/src/mir/tcx.rs +++ b/compiler/rustc_middle/src/mir/tcx.rs @@ -295,7 +295,7 @@ impl BorrowKind { } impl BinOp { - pub fn to_hir_binop(self) -> hir::BinOpKind { + pub(crate) fn to_hir_binop(self) -> hir::BinOpKind { match self { BinOp::Add => hir::BinOpKind::Add, BinOp::Sub => hir::BinOpKind::Sub,