From 7afe6f52e4448d7523877f652e567542f02b974e Mon Sep 17 00:00:00 2001 From: The8472 Date: Wed, 3 Nov 2021 20:47:00 +0100 Subject: [PATCH 1/4] Make RawVec private to alloc RawVec was previously exposed for compiler-internal use (libarena specifically) in 1acbb0a9350560d951359cc359361b87992a6f2b Since it is unstable, doc-hidden and has no associated tracking issue it was never meant for public use. And since it is no longer used outside alloc itself it can be made private again. Also remove some functions that are dead due to lack of internal users. --- library/alloc/src/lib.rs | 3 +- library/alloc/src/raw_vec.rs | 61 +++--------------------------------- 2 files changed, 6 insertions(+), 58 deletions(-) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 34d2cfc8e2c5b..2614c221042e5 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -173,6 +173,8 @@ extern crate test; #[macro_use] mod macros; +mod raw_vec; + // Heaps provided for low-level allocation strategies pub mod alloc; @@ -191,7 +193,6 @@ mod boxed { pub mod borrow; pub mod collections; pub mod fmt; -pub mod raw_vec; pub mod rc; pub mod slice; pub mod str; diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 75dbd4678bb47..4ab38c802a159 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -1,5 +1,4 @@ -#![unstable(feature = "raw_vec_internals", reason = "implementation detail", issue = "none")] -#![doc(hidden)] +#![unstable(feature = "raw_vec_internals", reason = "unstable const warnings", issue = "none")] use core::alloc::LayoutError; use core::cmp; @@ -50,7 +49,7 @@ enum AllocInit { /// `usize::MAX`. This means that you need to be careful when round-tripping this type with a /// `Box<[T]>`, since `capacity()` won't yield the length. #[allow(missing_debug_implementations)] -pub struct RawVec { +pub(crate) struct RawVec { ptr: Unique, cap: usize, alloc: A, @@ -87,7 +86,7 @@ impl RawVec { /// # Aborts /// /// Aborts on OOM. - #[cfg(not(no_global_oom_handling))] + #[cfg(not(any(no_global_oom_handling, test)))] #[must_use] #[inline] pub fn with_capacity(capacity: usize) -> Self { @@ -95,25 +94,12 @@ impl RawVec { } /// Like `with_capacity`, but guarantees the buffer is zeroed. - #[cfg(not(no_global_oom_handling))] + #[cfg(not(any(no_global_oom_handling, test)))] #[must_use] #[inline] pub fn with_capacity_zeroed(capacity: usize) -> Self { Self::with_capacity_zeroed_in(capacity, Global) } - - /// Reconstitutes a `RawVec` from a pointer and capacity. - /// - /// # Safety - /// - /// The `ptr` must be allocated (on the system heap), and with the given `capacity`. - /// The `capacity` cannot exceed `isize::MAX` for sized types. (only a concern on 32-bit - /// systems). ZST vectors may have a capacity up to `usize::MAX`. - /// If the `ptr` and `capacity` come from a `RawVec`, then this is guaranteed. - #[inline] - pub unsafe fn from_raw_parts(ptr: *mut T, capacity: usize) -> Self { - unsafe { Self::from_raw_parts_in(ptr, capacity, Global) } - } } impl RawVec { @@ -154,14 +140,6 @@ impl RawVec { Self::allocate_in(capacity, AllocInit::Zeroed, alloc) } - /// Converts a `Box<[T]>` into a `RawVec`. - pub fn from_box(slice: Box<[T], A>) -> Self { - unsafe { - let (slice, alloc) = Box::into_raw_with_allocator(slice); - RawVec::from_raw_parts_in(slice.as_mut_ptr(), slice.len(), alloc) - } - } - /// Converts the entire buffer into `Box<[MaybeUninit]>` with the specified `len`. /// /// Note that this will correctly reconstitute any `cap` changes @@ -290,37 +268,6 @@ impl RawVec { /// # Aborts /// /// Aborts on OOM. - /// - /// # Examples - /// - /// ``` - /// # #![feature(raw_vec_internals)] - /// # extern crate alloc; - /// # use std::ptr; - /// # use alloc::raw_vec::RawVec; - /// struct MyVec { - /// buf: RawVec, - /// len: usize, - /// } - /// - /// impl MyVec { - /// pub fn push_all(&mut self, elems: &[T]) { - /// self.buf.reserve(self.len, elems.len()); - /// // reserve would have aborted or panicked if the len exceeded - /// // `isize::MAX` so this is safe to do unchecked now. - /// for x in elems { - /// unsafe { - /// ptr::write(self.buf.ptr().add(self.len), x.clone()); - /// } - /// self.len += 1; - /// } - /// } - /// } - /// # fn main() { - /// # let mut vector = MyVec { buf: RawVec::new(), len: 0 }; - /// # vector.push_all(&[1, 3, 5, 7, 9]); - /// # } - /// ``` #[cfg(not(no_global_oom_handling))] #[inline] pub fn reserve(&mut self, len: usize, additional: usize) { From cdafe9953938150b8ad296a472a8416d64d1b5ec Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Mon, 8 Nov 2021 01:45:10 +0000 Subject: [PATCH 2/4] Add more missing methods to `IntraLinkCrateLoader` This helps with (but does not fix) https://github.com/rust-lang/rust/issues/84738. I tested on https://github.com/jyn514/objr/commit/edcee7b8124abf0e4c63873e8422ff81beb11ebb and still hit ICEs. --- .../passes/collect_intra_doc_links/early.rs | 31 ++++++++++++++++--- .../rustdoc-ui/intra-doc/auxiliary/dep1.rs | 1 + .../rustdoc-ui/intra-doc/auxiliary/dep2.rs | 1 + .../rustdoc-ui/intra-doc/auxiliary/dep3.rs | 1 + .../rustdoc-ui/intra-doc/auxiliary/dep4.rs | 1 + .../rustdoc-ui/intra-doc/extern-crate-load.rs | 26 ++++++++++++++++ 6 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 src/test/rustdoc-ui/intra-doc/auxiliary/dep1.rs create mode 100644 src/test/rustdoc-ui/intra-doc/auxiliary/dep2.rs create mode 100644 src/test/rustdoc-ui/intra-doc/auxiliary/dep3.rs create mode 100644 src/test/rustdoc-ui/intra-doc/auxiliary/dep4.rs create mode 100644 src/test/rustdoc-ui/intra-doc/extern-crate-load.rs diff --git a/src/librustdoc/passes/collect_intra_doc_links/early.rs b/src/librustdoc/passes/collect_intra_doc_links/early.rs index 565bcb8bd1340..4cebf741e2002 100644 --- a/src/librustdoc/passes/collect_intra_doc_links/early.rs +++ b/src/librustdoc/passes/collect_intra_doc_links/early.rs @@ -1,3 +1,4 @@ +use ast::visit; use rustc_ast as ast; use rustc_hir::def::Namespace::TypeNS; use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID}; @@ -16,7 +17,7 @@ crate fn load_intra_link_crates(resolver: Resolver, krate: &ast::Crate) -> Resol let mut loader = IntraLinkCrateLoader { current_mod: CRATE_DEF_ID, resolver }; // `walk_crate` doesn't visit the crate itself for some reason. loader.load_links_in_attrs(&krate.attrs, krate.span); - ast::visit::walk_crate(&mut loader, krate); + visit::walk_crate(&mut loader, krate); loader.resolver } @@ -54,7 +55,12 @@ impl IntraLinkCrateLoader { } } -impl ast::visit::Visitor<'_> for IntraLinkCrateLoader { +impl visit::Visitor<'_> for IntraLinkCrateLoader { + fn visit_foreign_item(&mut self, item: &ast::ForeignItem) { + self.load_links_in_attrs(&item.attrs, item.span); + visit::walk_foreign_item(self, item) + } + fn visit_item(&mut self, item: &ast::Item) { use rustc_ast_lowering::ResolverAstLowering; @@ -64,12 +70,29 @@ impl ast::visit::Visitor<'_> for IntraLinkCrateLoader { let old_mod = mem::replace(&mut self.current_mod, new_mod); self.load_links_in_attrs(&item.attrs, item.span); - ast::visit::walk_item(self, item); + visit::walk_item(self, item); self.current_mod = old_mod; } else { self.load_links_in_attrs(&item.attrs, item.span); - ast::visit::walk_item(self, item); + visit::walk_item(self, item); } } + + // NOTE: if doc-comments are ever allowed on function parameters, this will have to implement `visit_param` too. + + fn visit_assoc_item(&mut self, item: &ast::AssocItem, ctxt: visit::AssocCtxt) { + self.load_links_in_attrs(&item.attrs, item.span); + visit::walk_assoc_item(self, item, ctxt) + } + + fn visit_field_def(&mut self, field: &ast::FieldDef) { + self.load_links_in_attrs(&field.attrs, field.span); + visit::walk_field_def(self, field) + } + + fn visit_variant(&mut self, v: &ast::Variant) { + self.load_links_in_attrs(&v.attrs, v.span); + visit::walk_variant(self, v) + } } diff --git a/src/test/rustdoc-ui/intra-doc/auxiliary/dep1.rs b/src/test/rustdoc-ui/intra-doc/auxiliary/dep1.rs new file mode 100644 index 0000000000000..d11c69f812a8d --- /dev/null +++ b/src/test/rustdoc-ui/intra-doc/auxiliary/dep1.rs @@ -0,0 +1 @@ +// intentionally empty diff --git a/src/test/rustdoc-ui/intra-doc/auxiliary/dep2.rs b/src/test/rustdoc-ui/intra-doc/auxiliary/dep2.rs new file mode 100644 index 0000000000000..d11c69f812a8d --- /dev/null +++ b/src/test/rustdoc-ui/intra-doc/auxiliary/dep2.rs @@ -0,0 +1 @@ +// intentionally empty diff --git a/src/test/rustdoc-ui/intra-doc/auxiliary/dep3.rs b/src/test/rustdoc-ui/intra-doc/auxiliary/dep3.rs new file mode 100644 index 0000000000000..d11c69f812a8d --- /dev/null +++ b/src/test/rustdoc-ui/intra-doc/auxiliary/dep3.rs @@ -0,0 +1 @@ +// intentionally empty diff --git a/src/test/rustdoc-ui/intra-doc/auxiliary/dep4.rs b/src/test/rustdoc-ui/intra-doc/auxiliary/dep4.rs new file mode 100644 index 0000000000000..d11c69f812a8d --- /dev/null +++ b/src/test/rustdoc-ui/intra-doc/auxiliary/dep4.rs @@ -0,0 +1 @@ +// intentionally empty diff --git a/src/test/rustdoc-ui/intra-doc/extern-crate-load.rs b/src/test/rustdoc-ui/intra-doc/extern-crate-load.rs new file mode 100644 index 0000000000000..438c56aa516a9 --- /dev/null +++ b/src/test/rustdoc-ui/intra-doc/extern-crate-load.rs @@ -0,0 +1,26 @@ +// check-pass +// aux-crate:dep1=dep1.rs +// aux-crate:dep2=dep2.rs +// aux-crate:dep3=dep3.rs +// aux-crate:dep4=dep4.rs +#![deny(rustdoc::broken_intra_doc_links)] + +pub trait Trait { + /// [dep1] + type Item; +} + +pub struct S { + /// [dep2] + pub x: usize, +} + +extern "C" { + /// [dep3] + pub fn printf(); +} + +pub enum E { + /// [dep4] + A +} From 51345a83aaa99d1ec1a64e09c4e3280051e9cfa2 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Mon, 1 Nov 2021 23:01:39 +0000 Subject: [PATCH 3/4] Go back to loading all external crates unconditionally This *continues* to cause regressions. This code will be unnecessary once access to the resolver happens fully before creating the tyctxt (#83761), so load all crates unconditionally for now. --- src/librustdoc/core.rs | 36 ++++++++++++++++++++++++++++++++++-- src/librustdoc/lib.rs | 3 ++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index b7251e8f57151..089ffb1dc26aa 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -16,13 +16,15 @@ use rustc_middle::hir::map::Map; use rustc_middle::middle::privacy::AccessLevels; use rustc_middle::ty::{ParamEnv, Ty, TyCtxt}; use rustc_resolve as resolve; +use rustc_resolve::Namespace::TypeNS; use rustc_session::config::{self, CrateType, ErrorOutputType}; use rustc_session::lint; use rustc_session::DiagnosticOutput; use rustc_session::Session; +use rustc_span::def_id::CRATE_DEF_INDEX; use rustc_span::source_map; use rustc_span::symbol::sym; -use rustc_span::Span; +use rustc_span::{Span, DUMMY_SP}; use std::cell::RefCell; use std::lazy::SyncLazy; @@ -299,13 +301,43 @@ crate fn create_config( } crate fn create_resolver<'a>( + externs: config::Externs, queries: &Queries<'a>, sess: &Session, ) -> Rc> { let (krate, resolver, _) = &*abort_on_err(queries.expansion(), sess).peek(); let resolver = resolver.clone(); - crate::passes::collect_intra_doc_links::load_intra_link_crates(resolver, krate) + let resolver = crate::passes::collect_intra_doc_links::load_intra_link_crates(resolver, krate); + + // FIXME: somehow rustdoc is still missing crates even though we loaded all + // the known necessary crates. Load them all unconditionally until we find a way to fix this. + // DO NOT REMOVE THIS without first testing on the reproducer in + // https://github.com/jyn514/objr/commit/edcee7b8124abf0e4c63873e8422ff81beb11ebb + let extern_names: Vec = externs + .iter() + .filter(|(_, entry)| entry.add_prelude) + .map(|(name, _)| name) + .cloned() + .collect(); + resolver.borrow_mut().access(|resolver| { + sess.time("load_extern_crates", || { + for extern_name in &extern_names { + debug!("loading extern crate {}", extern_name); + if let Err(()) = resolver + .resolve_str_path_error( + DUMMY_SP, + extern_name, + TypeNS, + LocalDefId { local_def_index: CRATE_DEF_INDEX }.to_def_id(), + ) { + warn!("unable to resolve external crate {} (do you have an unused `--extern` crate?)", extern_name) + } + } + }); + }); + + resolver } crate fn run_global_ctxt( diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 7eeb9d1fcaa55..90ada38323886 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -755,6 +755,7 @@ fn main_options(options: config::Options) -> MainResult { let default_passes = options.default_passes; let output_format = options.output_format; // FIXME: fix this clone (especially render_options) + let externs = options.externs.clone(); let manual_passes = options.manual_passes.clone(); let render_options = options.render_options.clone(); let scrape_examples_options = options.scrape_examples_options.clone(); @@ -773,7 +774,7 @@ fn main_options(options: config::Options) -> MainResult { // We need to hold on to the complete resolver, so we cause everything to be // cloned for the analysis passes to use. Suboptimal, but necessary in the // current architecture. - let resolver = core::create_resolver(queries, sess); + let resolver = core::create_resolver(externs, queries, sess); if sess.has_errors() { sess.fatal("Compilation failed, aborting rustdoc"); From 33663274934b356c352e0967e2a5b18fc3ee494e Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Mon, 8 Nov 2021 04:37:28 +0000 Subject: [PATCH 4/4] Change paths for `dist` command to match the components they generate Before, you could have the confusing situation where the command to generate a component had no relation to the name of that component (e.g. the `rustc` component was generated with `src/librustc`). This changes the name to make them match up. --- src/bootstrap/CHANGELOG.md | 1 + src/bootstrap/dist.rs | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/bootstrap/CHANGELOG.md b/src/bootstrap/CHANGELOG.md index 2f99e36aef219..2bc7ffb0c50c7 100644 --- a/src/bootstrap/CHANGELOG.md +++ b/src/bootstrap/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - `llvm-libunwind` now accepts `in-tree` (formerly true), `system` or `no` (formerly false) [#77703](https://github.com/rust-lang/rust/pull/77703) - The options `infodir`, `localstatedir`, and `gpg-password-file` are no longer allowed in config.toml. Previously, they were ignored without warning. Note that `infodir` and `localstatedir` are still accepted by `./configure`, with a warning. [#82451](https://github.com/rust-lang/rust/pull/82451) - Add options for enabling overflow checks, one for std (`overflow-checks-std`) and one for everything else (`overflow-checks`). Both default to false. +- Change the names for `dist` commmands to match the component they generate. [#90684](https://github.com/rust-lang/rust/pull/90684) ### Non-breaking changes diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index a799732adde9d..09ea84a083eb2 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -64,7 +64,7 @@ impl Step for Docs { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let default = run.builder.config.docs; - run.path("src/doc").default_condition(default) + run.path("rust-docs").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -275,7 +275,7 @@ impl Step for Mingw { const DEFAULT: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.never() + run.path("rust-mingw") } fn make_run(run: RunConfig<'_>) { @@ -316,7 +316,7 @@ impl Step for Rustc { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("src/librustc") + run.path("rustc") } fn make_run(run: RunConfig<'_>) { @@ -572,7 +572,7 @@ impl Step for Std { const DEFAULT: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("library/std") + run.path("rust-std") } fn make_run(run: RunConfig<'_>) { @@ -686,7 +686,7 @@ impl Step for Analysis { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let default = should_build_extended_tool(&run.builder, "analysis"); - run.path("analysis").default_condition(default) + run.path("rust-analysis").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -821,7 +821,7 @@ impl Step for Src { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("src") + run.path("rust-src") } fn make_run(run: RunConfig<'_>) { @@ -874,7 +874,7 @@ impl Step for PlainSourceTarball { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let builder = run.builder; - run.path("src").default_condition(builder.config.rust_dist_src) + run.path("rustc-src").default_condition(builder.config.rust_dist_src) } fn make_run(run: RunConfig<'_>) { @@ -2120,7 +2120,7 @@ impl Step for BuildManifest { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("src/tools/build-manifest") + run.path("build-manifest") } fn make_run(run: RunConfig<'_>) { @@ -2152,7 +2152,7 @@ impl Step for ReproducibleArtifacts { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("reproducible") + run.path("reproducible-artifacts") } fn make_run(run: RunConfig<'_>) {