Skip to content

Commit

Permalink
Auto merge of rust-lang#84501 - JohnTitor:rollup-wxu1thu, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 10 pull requests

Successful merges:

 - rust-lang#83990 (implement `TrustedRandomAccess` for `Take` iterator adapter)
 - rust-lang#84250 (bootstrap: use bash on illumos to run install scripts)
 - rust-lang#84320 (Use details tag for trait implementors.)
 - rust-lang#84436 (Make a few functions private)
 - rust-lang#84453 (Document From implementations for Waker and RawWaker)
 - rust-lang#84458 (Remove unnecessary fields and parameters in rustdoc)
 - rust-lang#84485 (Add some associated type bounds tests)
 - rust-lang#84489 (Mention FusedIterator case in Iterator::fuse doc)
 - rust-lang#84492 (rustdoc: Remove unnecessary dummy span)
 - rust-lang#84496 (Add some specialization tests)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Apr 24, 2021
2 parents a7aba58 + ec61abf commit e11a9fa
Show file tree
Hide file tree
Showing 44 changed files with 324 additions and 152 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ pub const fn default_lib_output() -> CrateType {
CrateType::Rlib
}

pub fn default_configuration(sess: &Session) -> CrateConfig {
fn default_configuration(sess: &Session) -> CrateConfig {
let end = &sess.target.endian;
let arch = &sess.target.arch;
let wordsz = sess.target.pointer_width.to_string();
Expand Down Expand Up @@ -892,7 +892,7 @@ pub fn build_configuration(sess: &Session, mut user_cfg: CrateConfig) -> CrateCo
user_cfg
}

pub fn build_target_config(opts: &Options, target_override: Option<Target>) -> Target {
pub(super) fn build_target_config(opts: &Options, target_override: Option<Target>) -> Target {
let target_result = target_override.map_or_else(|| Target::search(&opts.target_triple), Ok);
let target = target_result.unwrap_or_else(|e| {
early_error(
Expand Down
6 changes: 6 additions & 0 deletions library/alloc/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ pub trait Wake {

#[stable(feature = "wake_trait", since = "1.51.0")]
impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for Waker {
/// Use a `Wake`-able type as a `Waker`.
///
/// No heap allocations or atomic operations are used for this conversion.
fn from(waker: Arc<W>) -> Waker {
// SAFETY: This is safe because raw_waker safely constructs
// a RawWaker from Arc<W>.
Expand All @@ -96,6 +99,9 @@ impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for Waker {

#[stable(feature = "wake_trait", since = "1.51.0")]
impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for RawWaker {
/// Use a `Wake`-able type as a `RawWaker`.
///
/// No heap allocations or atomic operations are used for this conversion.
fn from(waker: Arc<W>) -> RawWaker {
raw_waker(waker)
}
Expand Down
23 changes: 22 additions & 1 deletion library/core/src/iter/adapters/take.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::cmp;
use crate::iter::{adapters::SourceIter, FusedIterator, InPlaceIterable, TrustedLen};
use crate::iter::{
adapters::zip::try_get_unchecked, adapters::SourceIter, FusedIterator, InPlaceIterable,
TrustedLen, TrustedRandomAccess,
};
use crate::ops::{ControlFlow, Try};

/// An iterator that only iterates over the first `n` iterations of `iter`.
Expand Down Expand Up @@ -111,6 +114,15 @@ where

self.try_fold(init, ok(fold)).unwrap()
}

unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> <I as Iterator>::Item
where
Self: TrustedRandomAccess,
{
// SAFETY: the caller must uphold the contract for
// `Iterator::__iterator_get_unchecked`.
unsafe { try_get_unchecked(&mut self.iter, idx) }
}
}

#[unstable(issue = "none", feature = "inplace_iteration")]
Expand Down Expand Up @@ -207,3 +219,12 @@ impl<I> FusedIterator for Take<I> where I: FusedIterator {}

#[unstable(feature = "trusted_len", issue = "37572")]
unsafe impl<I: TrustedLen> TrustedLen for Take<I> {}

#[doc(hidden)]
#[unstable(feature = "trusted_random_access", issue = "none")]
unsafe impl<I> TrustedRandomAccess for Take<I>
where
I: TrustedRandomAccess,
{
const MAY_HAVE_SIDE_EFFECT: bool = I::MAY_HAVE_SIDE_EFFECT;
}
5 changes: 5 additions & 0 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,12 @@ pub trait Iterator {
/// [`Some(T)`] again. `fuse()` adapts an iterator, ensuring that after a
/// [`None`] is given, it will always return [`None`] forever.
///
/// Note that the [`Fuse`] wrapper is a no-op on iterators that implement
/// the [`FusedIterator`] trait. `fuse()` may therefore behave incorrectly
/// if the [`FusedIterator`] trait is improperly implemented.
///
/// [`Some(T)`]: Some
/// [`FusedIterator`]: crate::iter::FusedIterator
///
/// # Examples
///
Expand Down
7 changes: 6 additions & 1 deletion src/bootstrap/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ use crate::Compiler;
use crate::builder::{Builder, RunConfig, ShouldRun, Step};
use crate::config::{Config, TargetSelection};

#[cfg(target_os = "illumos")]
const SHELL: &str = "bash";
#[cfg(not(target_os = "illumos"))]
const SHELL: &str = "sh";

fn install_sh(
builder: &Builder<'_>,
package: &str,
Expand All @@ -37,7 +42,7 @@ fn install_sh(
let empty_dir = builder.out.join("tmp/empty_dir");
t!(fs::create_dir_all(&empty_dir));

let mut cmd = Command::new("sh");
let mut cmd = Command::new(SHELL);
cmd.current_dir(&empty_dir)
.arg(sanitize_sh(&tarball.decompressed_output().join("install.sh")))
.arg(format!("--prefix={}", prepare_dir(prefix)))
Expand Down
35 changes: 12 additions & 23 deletions src/librustdoc/formats/renderer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_middle::ty::TyCtxt;
use rustc_span::{edition::Edition, Symbol};
use rustc_span::Symbol;

use crate::clean;
use crate::config::RenderOptions;
Expand All @@ -23,7 +23,6 @@ crate trait FormatRenderer<'tcx>: Sized {
fn init(
krate: clean::Crate,
options: RenderOptions,
edition: Edition,
cache: Cache,
tcx: TyCtxt<'tcx>,
) -> Result<(Self, clean::Crate), Error>;
Expand All @@ -35,19 +34,15 @@ crate trait FormatRenderer<'tcx>: Sized {
fn item(&mut self, item: clean::Item) -> Result<(), Error>;

/// Renders a module (should not handle recursing into children).
fn mod_item_in(&mut self, item: &clean::Item, item_name: &str) -> Result<(), Error>;
fn mod_item_in(&mut self, item: &clean::Item) -> Result<(), Error>;

/// Runs after recursively rendering all sub-items of a module.
fn mod_item_out(&mut self, item_name: &str) -> Result<(), Error>;
fn mod_item_out(&mut self) -> Result<(), Error> {
Ok(())
}

/// Post processing hook for cleanup and dumping output to files.
///
/// A handler is available if the renderer wants to report errors.
fn after_krate(
&mut self,
crate_name: Symbol,
diag: &rustc_errors::Handler,
) -> Result<(), Error>;
fn after_krate(&mut self) -> Result<(), Error>;

fn cache(&self) -> &Cache;
}
Expand All @@ -57,37 +52,31 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
krate: clean::Crate,
options: RenderOptions,
cache: Cache,
diag: &rustc_errors::Handler,
edition: Edition,
tcx: TyCtxt<'tcx>,
) -> Result<(), Error> {
let prof = &tcx.sess.prof;

let emit_crate = options.should_emit_crate();
let (mut format_renderer, krate) = prof
.extra_verbose_generic_activity("create_renderer", T::descr())
.run(|| T::init(krate, options, edition, cache, tcx))?;
.run(|| T::init(krate, options, cache, tcx))?;

if !emit_crate {
return Ok(());
}

// Render the crate documentation
let crate_name = krate.name;
let mut work = vec![(format_renderer.make_child_renderer(), krate.module)];

let unknown = Symbol::intern("<unknown item>");
while let Some((mut cx, item)) = work.pop() {
if item.is_mod() && T::RUN_ON_MODULE {
// modules are special because they add a namespace. We also need to
// recurse into the items of the module as well.
let name = item.name.as_ref().unwrap().to_string();
if name.is_empty() {
panic!("Unexpected module with empty name");
}
let _timer = prof.generic_activity_with_arg("render_mod_item", name.as_str());
let _timer =
prof.generic_activity_with_arg("render_mod_item", item.name.unwrap().to_string());

cx.mod_item_in(&item, &name)?;
cx.mod_item_in(&item)?;
let module = match *item.kind {
clean::StrippedItem(box clean::ModuleItem(m)) | clean::ModuleItem(m) => m,
_ => unreachable!(),
Expand All @@ -97,7 +86,7 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
work.push((cx.make_child_renderer(), it));
}

cx.mod_item_out(&name)?;
cx.mod_item_out()?;
// FIXME: checking `item.name.is_some()` is very implicit and leads to lots of special
// cases. Use an explicit match instead.
} else if item.name.is_some() && !item.is_extern_crate() {
Expand All @@ -106,5 +95,5 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
}
}
prof.extra_verbose_generic_activity("renderer_after_krate", T::descr())
.run(|| format_renderer.after_krate(crate_name, diag))
.run(|| format_renderer.after_krate())
}
29 changes: 14 additions & 15 deletions src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
use rustc_span::edition::Edition;
use rustc_span::source_map::FileName;
use rustc_span::{symbol::sym, Symbol};
use rustc_span::symbol::sym;

use super::cache::{build_index, ExternalLocation};
use super::print_item::{full_path, item_path, print_item};
Expand Down Expand Up @@ -111,8 +111,6 @@ crate struct SharedContext<'tcx> {
crate static_root_path: Option<String>,
/// The fs handle we are working with.
crate fs: DocFS,
/// The default edition used to parse doctests.
crate edition: Edition,
pub(super) codes: ErrorCodes,
pub(super) playground: Option<markdown::Playground>,
all: RefCell<AllTypes>,
Expand Down Expand Up @@ -141,6 +139,10 @@ impl SharedContext<'_> {
crate fn maybe_collapsed_doc_value<'a>(&self, item: &'a clean::Item) -> Option<String> {
if self.collapsed { item.collapsed_doc_value() } else { item.doc_value() }
}

crate fn edition(&self) -> Edition {
self.tcx.sess.edition()
}
}

impl<'tcx> Context<'tcx> {
Expand Down Expand Up @@ -346,7 +348,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
fn init(
mut krate: clean::Crate,
options: RenderOptions,
edition: Edition,
mut cache: Cache,
tcx: TyCtxt<'tcx>,
) -> Result<(Self, clean::Crate), Error> {
Expand Down Expand Up @@ -435,7 +436,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
resource_suffix,
static_root_path,
fs: DocFS::new(sender),
edition,
codes: ErrorCodes::from(unstable_features.is_nightly_build()),
playground,
all: RefCell::new(AllTypes::new()),
Expand Down Expand Up @@ -494,11 +494,8 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
}
}

fn after_krate(
&mut self,
crate_name: Symbol,
diag: &rustc_errors::Handler,
) -> Result<(), Error> {
fn after_krate(&mut self) -> Result<(), Error> {
let crate_name = self.tcx().crate_name(LOCAL_CRATE);
let final_file = self.dst.join(&*crate_name.as_str()).join("all.html");
let settings_file = self.dst.join("settings.html");

Expand Down Expand Up @@ -572,15 +569,16 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {

// Flush pending errors.
Rc::get_mut(&mut self.shared).unwrap().fs.close();
let nb_errors = self.shared.errors.iter().map(|err| diag.struct_err(&err).emit()).count();
let nb_errors =
self.shared.errors.iter().map(|err| self.tcx().sess.struct_err(&err).emit()).count();
if nb_errors > 0 {
Err(Error::new(io::Error::new(io::ErrorKind::Other, "I/O error"), ""))
} else {
Ok(())
}
}

fn mod_item_in(&mut self, item: &clean::Item, item_name: &str) -> Result<(), Error> {
fn mod_item_in(&mut self, item: &clean::Item) -> Result<(), Error> {
// Stripped modules survive the rustdoc passes (i.e., `strip-private`)
// if they contain impls for public types. These modules can also
// contain items such as publicly re-exported structures.
Expand All @@ -592,8 +590,9 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
self.render_redirect_pages = item.is_stripped();
}
let scx = &self.shared;
self.dst.push(item_name);
self.current.push(item_name.to_owned());
let item_name = item.name.as_ref().unwrap().to_string();
self.dst.push(&item_name);
self.current.push(item_name);

info!("Recursing into {}", self.dst.display());

Expand All @@ -619,7 +618,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
Ok(())
}

fn mod_item_out(&mut self, _item_name: &str) -> Result<(), Error> {
fn mod_item_out(&mut self) -> Result<(), Error> {
info!("Recursed; leaving {}", self.dst.display());

// Go back to where we were at
Expand Down
Loading

0 comments on commit e11a9fa

Please sign in to comment.