Skip to content

Commit

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

Successful merges:

 - rust-lang#79655 (Add Vec visualization to understand capacity)
 - rust-lang#80172 (Use consistent punctuation for 'Prelude contents' docs)
 - rust-lang#80429 (Add regression test for mutual recursion in obligation forest)
 - rust-lang#80601 (Improve grammar in documentation of format strings)
 - rust-lang#81046 (Improve unknown external crate error)
 - rust-lang#81178 (Visit only terminators when removing landing pads)
 - rust-lang#81179 (Fix broken links with `--document-private-items` in the standard library)
 - rust-lang#81184 (Remove unnecessary `after_run` function)
 - rust-lang#81185 (Fix ICE in mir when evaluating SizeOf on unsized type)
 - rust-lang#81187 (Fix typo in counters.rs)
 - rust-lang#81219 (Document security implications of std::env::temp_dir)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jan 21, 2021
2 parents 339e196 + d6c7a79 commit a243ad2
Show file tree
Hide file tree
Showing 27 changed files with 256 additions and 86 deletions.
11 changes: 7 additions & 4 deletions compiler/rustc_mir/src/interpret/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
NullaryOp(mir::NullOp::SizeOf, ty) => {
let ty = self.subst_from_current_frame_and_normalize_erasing_regions(ty);
let layout = self.layout_of(ty)?;
assert!(
!layout.is_unsized(),
"SizeOf nullary MIR operator called for unsized type"
);
if layout.is_unsized() {
// FIXME: This should be a span_bug (#80742)
self.tcx.sess.delay_span_bug(
self.frame().current_span(),
&format!("SizeOf nullary MIR operator called for unsized type {}", ty),
);
}
self.write_scalar(Scalar::from_machine_usize(layout.size.bytes(), self), dest)?;
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
MirPhase::Const,
&[&[
&add_moves_for_packed_drops::AddMovesForPackedDrops,
&no_landing_pads::NoLandingPads::new(tcx),
&no_landing_pads::NoLandingPads,
&remove_noop_landing_pads::RemoveNoopLandingPads,
&simplify::SimplifyCfg::new("make_shim"),
&add_call_guards::CriticalCallEdges,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/coverage/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl CoverageCounters {
}

/// Activate the `DebugCounters` data structures, to provide additional debug formatting
/// features when formating `CoverageKind` (counter) values.
/// features when formatting `CoverageKind` (counter) values.
pub fn enable_debug(&mut self) {
self.debug_counters.enable();
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir/src/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,15 @@ fn run_post_borrowck_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tc

let post_borrowck_cleanup: &[&dyn MirPass<'tcx>] = &[
// Remove all things only needed by analysis
&no_landing_pads::NoLandingPads::new(tcx),
&no_landing_pads::NoLandingPads,
&simplify_branches::SimplifyBranches::new("initial"),
&remove_noop_landing_pads::RemoveNoopLandingPads,
&cleanup_post_borrowck::CleanupNonCodegenStatements,
&simplify::SimplifyCfg::new("early-opt"),
// These next passes must be executed together
&add_call_guards::CriticalCallEdges,
&elaborate_drops::ElaborateDrops,
&no_landing_pads::NoLandingPads::new(tcx),
&no_landing_pads::NoLandingPads,
// AddMovesForPackedDrops needs to run after drop
// elaboration.
&add_moves_for_packed_drops::AddMovesForPackedDrops,
Expand Down
27 changes: 6 additions & 21 deletions compiler/rustc_mir/src/transform/no_landing_pads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,27 @@
//! specified.

use crate::transform::MirPass;
use rustc_middle::mir::visit::MutVisitor;
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;
use rustc_target::spec::PanicStrategy;

pub struct NoLandingPads<'tcx> {
tcx: TyCtxt<'tcx>,
}

impl<'tcx> NoLandingPads<'tcx> {
pub fn new(tcx: TyCtxt<'tcx>) -> Self {
NoLandingPads { tcx }
}
}
pub struct NoLandingPads;

impl<'tcx> MirPass<'tcx> for NoLandingPads<'tcx> {
impl<'tcx> MirPass<'tcx> for NoLandingPads {
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
no_landing_pads(tcx, body)
}
}

pub fn no_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
if tcx.sess.panic_strategy() == PanicStrategy::Abort {
NoLandingPads::new(tcx).visit_body(body);
}
}

impl<'tcx> MutVisitor<'tcx> for NoLandingPads<'tcx> {
fn tcx(&self) -> TyCtxt<'tcx> {
self.tcx
if tcx.sess.panic_strategy() != PanicStrategy::Abort {
return;
}

fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, location: Location) {
for block in body.basic_blocks_mut() {
let terminator = block.terminator_mut();
if let Some(unwind) = terminator.kind.unwind_mut() {
unwind.take();
}
self.super_terminator(terminator, location);
}
}
7 changes: 7 additions & 0 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ impl<'a> PathSource<'a> {
// "function" here means "anything callable" rather than `DefKind::Fn`,
// this is not precise but usually more helpful than just "value".
Some(ExprKind::Call(call_expr, _)) => match &call_expr.kind {
// the case of `::some_crate()`
ExprKind::Path(_, path)
if path.segments.len() == 2
&& path.segments[0].ident.name == kw::PathRoot =>
{
"external crate"
}
ExprKind::Path(_, path) => {
let mut msg = "function";
if let Some(segment) = path.segments.iter().last() {
Expand Down
14 changes: 10 additions & 4 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2485,20 +2485,26 @@ impl<'a> Resolver<'a> {
(format!("use of undeclared crate or module `{}`", ident), None)
}
} else {
let mut msg =
format!("could not find `{}` in `{}`", ident, path[i - 1].ident);
let parent = path[i - 1].ident.name;
let parent = if parent == kw::PathRoot {
"crate root".to_owned()
} else {
format!("`{}`", parent)
};

let mut msg = format!("could not find `{}` in {}", ident, parent);
if ns == TypeNS || ns == ValueNS {
let ns_to_try = if ns == TypeNS { ValueNS } else { TypeNS };
if let FindBindingResult::Binding(Ok(binding)) =
find_binding_in_ns(self, ns_to_try)
{
let mut found = |what| {
msg = format!(
"expected {}, found {} `{}` in `{}`",
"expected {}, found {} `{}` in {}",
ns.descr(),
what,
ident,
path[i - 1].ident
parent
)
};
if binding.module().is_some() {
Expand Down
9 changes: 5 additions & 4 deletions library/alloc/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,21 +282,22 @@
//! `%`. The actual grammar for the formatting syntax is:
//!
//! ```text
//! format_string := <text> [ maybe-format <text> ] *
//! maybe-format := '{' '{' | '}' '}' | <format>
//! format_string := text [ maybe_format text ] *
//! maybe_format := '{' '{' | '}' '}' | format
//! format := '{' [ argument ] [ ':' format_spec ] '}'
//! argument := integer | identifier
//!
//! format_spec := [[fill]align][sign]['#']['0'][width]['.' precision][type]
//! format_spec := [[fill]align][sign]['#']['0'][width]['.' precision]type
//! fill := character
//! align := '<' | '^' | '>'
//! sign := '+' | '-'
//! width := count
//! precision := count | '*'
//! type := identifier | '?' | ''
//! type := '' | '?' | 'x?' | 'X?' | identifier
//! count := parameter | integer
//! parameter := argument '$'
//! ```
//! In the above grammar, `text` may not contain any `'{'` or `'}'` characters.
//!
//! # Formatting traits
//!
Expand Down
22 changes: 22 additions & 0 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,27 @@ mod spec_extend;
/// you would see if you coerced it to a slice), followed by [`capacity`]` -
/// `[`len`] logically uninitialized, contiguous elements.
///
/// A vector containing the elements `'a'` and `'b'` with capacity 4 can be
/// visualized as below. The top part is the `Vec` struct, it contains a
/// pointer to the head of the allocation in the heap, length and capacity.
/// The bottom part is the allocation on the heap, a contiguous memory block.
///
/// ```text
/// ptr len capacity
/// +--------+--------+--------+
/// | 0x0123 | 2 | 4 |
/// +--------+--------+--------+
/// |
/// v
/// Heap +--------+--------+--------+--------+
/// | 'a' | 'b' | uninit | uninit |
/// +--------+--------+--------+--------+
/// ```
///
/// - **uninit** represents memory that is not initialized, see [`MaybeUninit`].
/// - Note: the ABI is not stable and `Vec` makes no guarantees about its memory
/// layout (including the order of fields).
///
/// `Vec` will never perform a "small optimization" where elements are actually
/// stored on the stack for two reasons:
///
Expand Down Expand Up @@ -345,6 +366,7 @@ mod spec_extend;
/// [`push`]: Vec::push
/// [`insert`]: Vec::insert
/// [`reserve`]: Vec::reserve
/// [`MaybeUninit`]: core::mem::MaybeUninit
/// [owned slice]: Box
/// [slice]: ../../std/primitive.slice.html
/// [`&`]: ../../std/primitive.reference.html
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/vec/spec_from_iter_nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{SpecExtend, Vec};

/// Another specialization trait for Vec::from_iter
/// necessary to manually prioritize overlapping specializations
/// see [`SpecFromIter`] for details.
/// see [`SpecFromIter`](super::SpecFromIter) for details.
pub(super) trait SpecFromIterNested<T, I> {
fn from_iter(iter: I) -> Self;
}
Expand Down
15 changes: 9 additions & 6 deletions library/std/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,13 @@ pub fn home_dir() -> Option<PathBuf> {

/// Returns the path of a temporary directory.
///
/// The temporary directory may be shared among users, or between processes
/// with different privileges; thus, the creation of any files or directories
/// in the temporary directory must use a secure method to create a uniquely
/// named file. Creating a file or directory with a fixed or predictable name
/// may result in "insecure temporary file" security vulnerabilities. Consider
/// using a crate that securely creates temporary files or directories.
///
/// # Unix
///
/// Returns the value of the `TMPDIR` environment variable if it is
Expand All @@ -580,14 +587,10 @@ pub fn home_dir() -> Option<PathBuf> {
///
/// ```no_run
/// use std::env;
/// use std::fs::File;
///
/// fn main() -> std::io::Result<()> {
/// fn main() {
/// let mut dir = env::temp_dir();
/// dir.push("foo.txt");
///
/// let f = File::create(dir)?;
/// Ok(())
/// println!("Temporary directory: {}", dir.display());
/// }
/// ```
#[stable(feature = "env", since = "1.0.0")]
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/io/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! The I/O Prelude
//! The I/O Prelude.
//!
//! The purpose of this module is to alleviate imports of many common I/O traits
//! by adding a glob import to the top of I/O heavy modules:
Expand Down
28 changes: 14 additions & 14 deletions library/std/src/prelude/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! The Rust Prelude.
//! # The Rust Prelude
//!
//! Rust comes with a variety of things in its standard library. However, if
//! you had to manually import every single thing that you used, it would be
Expand Down Expand Up @@ -28,35 +28,35 @@
//! The current version of the prelude (version 1) lives in
//! [`std::prelude::v1`], and re-exports the following:
//!
//! * [`std::marker`]::{[`Copy`], [`Send`], [`Sized`], [`Sync`], [`Unpin`]},
//! * [`std::marker`]::{[`Copy`], [`Send`], [`Sized`], [`Sync`], [`Unpin`]}:
//! marker traits that indicate fundamental properties of types.
//! * [`std::ops`]::{[`Drop`], [`Fn`], [`FnMut`], [`FnOnce`]}, various
//! * [`std::ops`]::{[`Drop`], [`Fn`], [`FnMut`], [`FnOnce`]}: various
//! operations for both destructors and overloading `()`.
//! * [`std::mem`]::[`drop`][`mem::drop`], a convenience function for explicitly
//! * [`std::mem`]::[`drop`][`mem::drop`]: a convenience function for explicitly
//! dropping a value.
//! * [`std::boxed`]::[`Box`], a way to allocate values on the heap.
//! * [`std::borrow`]::[`ToOwned`], the conversion trait that defines
//! * [`std::boxed`]::[`Box`]: a way to allocate values on the heap.
//! * [`std::borrow`]::[`ToOwned`]: the conversion trait that defines
//! [`to_owned`], the generic method for creating an owned type from a
//! borrowed type.
//! * [`std::clone`]::[`Clone`], the ubiquitous trait that defines
//! * [`std::clone`]::[`Clone`]: the ubiquitous trait that defines
//! [`clone`][`Clone::clone`], the method for producing a copy of a value.
//! * [`std::cmp`]::{[`PartialEq`], [`PartialOrd`], [`Eq`], [`Ord`] }, the
//! * [`std::cmp`]::{[`PartialEq`], [`PartialOrd`], [`Eq`], [`Ord`]}: the
//! comparison traits, which implement the comparison operators and are often
//! seen in trait bounds.
//! * [`std::convert`]::{[`AsRef`], [`AsMut`], [`Into`], [`From`]}, generic
//! * [`std::convert`]::{[`AsRef`], [`AsMut`], [`Into`], [`From`]}: generic
//! conversions, used by savvy API authors to create overloaded methods.
//! * [`std::default`]::[`Default`], types that have default values.
//! * [`std::iter`]::{[`Iterator`], [`Extend`], [`IntoIterator`]
//! [`DoubleEndedIterator`], [`ExactSizeIterator`]}, iterators of various
//! * [`std::iter`]::{[`Iterator`], [`Extend`], [`IntoIterator`],
//! [`DoubleEndedIterator`], [`ExactSizeIterator`]}: iterators of various
//! kinds.
//! * [`std::option`]::[`Option`]::{[`self`][`Option`], [`Some`], [`None`]}, a
//! type which expresses the presence or absence of a value. This type is so
//! commonly used, its variants are also exported.
//! * [`std::result`]::[`Result`]::{[`self`][`Result`], [`Ok`], [`Err`]}, a type
//! * [`std::result`]::[`Result`]::{[`self`][`Result`], [`Ok`], [`Err`]}: a type
//! for functions that may succeed or fail. Like [`Option`], its variants are
//! exported as well.
//! * [`std::string`]::{[`String`], [`ToString`]}, heap allocated strings.
//! * [`std::vec`]::[`Vec`], a growable, heap-allocated vector.
//! * [`std::string`]::{[`String`], [`ToString`]}: heap-allocated strings.
//! * [`std::vec`]::[`Vec`]: a growable, heap-allocated vector.
//!
//! [`mem::drop`]: crate::mem::drop
//! [`std::borrow`]: crate::borrow
Expand Down
15 changes: 9 additions & 6 deletions src/librustdoc/formats/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ crate trait FormatRenderer<'tcx>: Clone {
fn mod_item_out(&mut self, item_name: &str) -> Result<(), Error>;

/// Post processing hook for cleanup and dumping output to files.
fn after_krate(&mut self, krate: &clean::Crate, cache: &Cache) -> Result<(), Error>;

/// Called after everything else to write out errors.
fn after_run(&mut self, diag: &rustc_errors::Handler) -> Result<(), Error>;
///
/// A handler is available if the renderer wants to report errors.
fn after_krate(
&mut self,
krate: &clean::Crate,
cache: &Cache,
diag: &rustc_errors::Handler,
) -> Result<(), Error>;
}

/// Main method for rendering a crate.
Expand Down Expand Up @@ -104,6 +108,5 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
}
}

format_renderer.after_krate(&krate, &cache)?;
format_renderer.after_run(diag)
format_renderer.after_krate(&krate, &cache, diag)
}
27 changes: 15 additions & 12 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,17 +523,12 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
Ok((cx, krate))
}

fn after_run(&mut self, diag: &rustc_errors::Handler) -> Result<(), Error> {
Arc::get_mut(&mut self.shared).unwrap().fs.close();
let nb_errors = self.errors.iter().map(|err| diag.struct_err(&err).emit()).count();
if nb_errors > 0 {
Err(Error::new(io::Error::new(io::ErrorKind::Other, "I/O error"), ""))
} else {
Ok(())
}
}

fn after_krate(&mut self, krate: &clean::Crate, cache: &Cache) -> Result<(), Error> {
fn after_krate(
&mut self,
krate: &clean::Crate,
cache: &Cache,
diag: &rustc_errors::Handler,
) -> Result<(), Error> {
let final_file = self.dst.join(&*krate.name.as_str()).join("all.html");
let settings_file = self.dst.join("settings.html");
let crate_name = krate.name;
Expand Down Expand Up @@ -596,7 +591,15 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
&style_files,
);
self.shared.fs.write(&settings_file, v.as_bytes())?;
Ok(())

// Flush pending errors.
Arc::get_mut(&mut self.shared).unwrap().fs.close();
let nb_errors = self.errors.iter().map(|err| diag.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(
Expand Down
Loading

0 comments on commit a243ad2

Please sign in to comment.