Skip to content

Commit

Permalink
Auto merge of #83432 - Dylan-DPC:rollup-4z5f6al, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 9 pull requests

Successful merges:

 - #83051 (Sidebar trait items order)
 - #83313 (Only enable assert_dep_graph when query-dep-graph is enabled.)
 - #83353 (Add internal io::Error::new_const to avoid allocations.)
 - #83391 (Allow not emitting `uwtable` on Android)
 - #83392 (Change `-W help` to display edition level.)
 - #83393 (Codeblock tooltip position)
 - #83399 (rustdoc: Record crate name instead of using `None`)
 - #83405 (Slight visual improvements to warning boxes in the docs)
 - #83415 (Remove unnecessary `Option` wrapping around `Crate.module`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Mar 24, 2021
2 parents 673d0db + 5c0d880 commit db492ec
Show file tree
Hide file tree
Showing 77 changed files with 522 additions and 295 deletions.
7 changes: 6 additions & 1 deletion compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,12 @@ Available lint options:
let print_lints = |lints: Vec<&Lint>| {
for lint in lints {
let name = lint.name_lower().replace("_", "-");
println!(" {} {:7.7} {}", padded(&name), lint.default_level.as_str(), lint.desc);
println!(
" {} {:7.7} {}",
padded(&name),
lint.default_level(sess.edition()).as_str(),
lint.desc
);
}
println!("\n");
};
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_incremental/src/assert_dep_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ pub fn assert_dep_graph(tcx: TyCtxt<'_>) {
dump_graph(tcx);
}

if !tcx.sess.opts.debugging_opts.query_dep_graph {
return;
}

// if the `rustc_attrs` feature is not enabled, then the
// attributes we are interested in cannot be present anyway, so
// skip the walk.
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_incremental/src/persist/dirty_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ impl Assertion {
}

pub fn check_dirty_clean_annotations(tcx: TyCtxt<'_>) {
if !tcx.sess.opts.debugging_opts.query_dep_graph {
return;
}

// can't add `#[rustc_dirty]` etc without opting in to this feature
if !tcx.features().rustc_attrs {
return;
Expand Down
20 changes: 20 additions & 0 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ impl CheckAttrVisitor<'tcx> {
self.check_naked(hir_id, attr, span, target)
} else if self.tcx.sess.check_name(attr, sym::rustc_legacy_const_generics) {
self.check_rustc_legacy_const_generics(&attr, span, target, item)
} else if self.tcx.sess.check_name(attr, sym::rustc_clean)
|| self.tcx.sess.check_name(attr, sym::rustc_dirty)
|| self.tcx.sess.check_name(attr, sym::rustc_if_this_changed)
|| self.tcx.sess.check_name(attr, sym::rustc_then_this_would_need)
{
self.check_rustc_dirty_clean(&attr)
} else {
// lint-only checks
if self.tcx.sess.check_name(attr, sym::cold) {
Expand Down Expand Up @@ -1012,6 +1018,20 @@ impl CheckAttrVisitor<'tcx> {
}
}

/// Checks that the dep-graph debugging attributes are only present when the query-dep-graph
/// option is passed to the compiler.
fn check_rustc_dirty_clean(&self, attr: &Attribute) -> bool {
if self.tcx.sess.opts.debugging_opts.query_dep_graph {
true
} else {
self.tcx
.sess
.struct_span_err(attr.span, "attribute requires -Z query-dep-graph to be enabled")
.emit();
false
}
}

/// Checks if `#[link_section]` is applied to a function or static.
fn check_link_section(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
match target {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ impl Session {
} else if self.target.requires_uwtable {
true
} else {
self.opts.cg.force_unwind_tables.unwrap_or(false)
self.opts.cg.force_unwind_tables.unwrap_or(self.target.default_uwtable)
}
}

Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_target/src/spec/android_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ pub fn opts() -> TargetOptions {
base.dwarf_version = Some(2);
base.position_independent_executables = true;
base.has_elf_tls = false;
base.requires_uwtable = true;
// This is for backward compatibility, see https://github.com/rust-lang/rust/issues/49867
// for context. (At that time, there was no `-C force-unwind-tables`, so the only solution
// was to always emit `uwtable`).
base.default_uwtable = true;
base.crt_static_respected = false;
base
}
7 changes: 7 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,10 @@ pub struct TargetOptions {
/// unwinders.
pub requires_uwtable: bool,

/// Whether or not to emit `uwtable` attributes on functions if `-C force-unwind-tables`
/// is not specified and `uwtable` is not required on this target.
pub default_uwtable: bool,

/// Whether or not SIMD types are passed by reference in the Rust ABI,
/// typically required if a target can be compiled with a mixed set of
/// target features. This is `true` by default, and `false` for targets like
Expand Down Expand Up @@ -1248,6 +1252,7 @@ impl Default for TargetOptions {
default_hidden_visibility: false,
emit_debug_gdb_scripts: true,
requires_uwtable: false,
default_uwtable: false,
simd_types_indirect: true,
limit_rdylib_exports: true,
override_export_symbols: None,
Expand Down Expand Up @@ -1711,6 +1716,7 @@ impl Target {
key!(default_hidden_visibility, bool);
key!(emit_debug_gdb_scripts, bool);
key!(requires_uwtable, bool);
key!(default_uwtable, bool);
key!(simd_types_indirect, bool);
key!(limit_rdylib_exports, bool);
key!(override_export_symbols, opt_list);
Expand Down Expand Up @@ -1947,6 +1953,7 @@ impl ToJson for Target {
target_option_val!(default_hidden_visibility);
target_option_val!(emit_debug_gdb_scripts);
target_option_val!(requires_uwtable);
target_option_val!(default_uwtable);
target_option_val!(simd_types_indirect);
target_option_val!(limit_rdylib_exports);
target_option_val!(override_export_symbols);
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ impl fmt::Display for NulError {
impl From<NulError> for io::Error {
/// Converts a [`NulError`] into a [`io::Error`].
fn from(_: NulError) -> io::Error {
io::Error::new(io::ErrorKind::InvalidInput, "data provided contains a nul byte")
io::Error::new_const(io::ErrorKind::InvalidInput, &"data provided contains a nul byte")
}
}

Expand Down
5 changes: 4 additions & 1 deletion library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2188,7 +2188,10 @@ impl DirBuilder {
match path.parent() {
Some(p) => self.create_dir_all(p)?,
None => {
return Err(io::Error::new(io::ErrorKind::Other, "failed to create whole tree"));
return Err(io::Error::new_const(
io::ErrorKind::Other,
&"failed to create whole tree",
));
}
}
match self.inner.mkdir(path) {
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/io/buffered/bufwriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ impl<W: Write> BufWriter<W> {

match r {
Ok(0) => {
return Err(Error::new(
return Err(Error::new_const(
ErrorKind::WriteZero,
"failed to write the buffered data",
&"failed to write the buffered data",
));
}
Ok(n) => guard.consume(n),
Expand Down
8 changes: 4 additions & 4 deletions library/std/src/io/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ where
self.pos = n;
Ok(self.pos)
}
None => Err(Error::new(
None => Err(Error::new_const(
ErrorKind::InvalidInput,
"invalid seek to a negative or overflowing position",
&"invalid seek to a negative or overflowing position",
)),
}
}
Expand Down Expand Up @@ -328,9 +328,9 @@ fn slice_write_vectored(
// Resizing write implementation
fn vec_write(pos_mut: &mut u64, vec: &mut Vec<u8>, buf: &[u8]) -> io::Result<usize> {
let pos: usize = (*pos_mut).try_into().map_err(|_| {
Error::new(
Error::new_const(
ErrorKind::InvalidInput,
"cursor position exceeds maximum possible vector length",
&"cursor position exceeds maximum possible vector length",
)
})?;
// Make sure the internal buffer is as least as big as where we
Expand Down
26 changes: 26 additions & 0 deletions library/std/src/io/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ impl fmt::Debug for Error {
enum Repr {
Os(i32),
Simple(ErrorKind),
// &str is a fat pointer, but &&str is a thin pointer.
SimpleMessage(ErrorKind, &'static &'static str),
Custom(Box<Custom>),
}

Expand Down Expand Up @@ -259,6 +261,18 @@ impl Error {
Error { repr: Repr::Custom(Box::new(Custom { kind, error })) }
}

/// Creates a new I/O error from a known kind of error as well as a
/// constant message.
///
/// This function does not allocate.
///
/// This function should maybe change to
/// `new_const<const MSG: &'static str>(kind: ErrorKind)`
/// in the future, when const generics allow that.
pub(crate) const fn new_const(kind: ErrorKind, message: &'static &'static str) -> Error {
Self { repr: Repr::SimpleMessage(kind, message) }
}

/// Returns an error representing the last OS error which occurred.
///
/// This function reads the value of `errno` for the target platform (e.g.
Expand Down Expand Up @@ -342,6 +356,7 @@ impl Error {
Repr::Os(i) => Some(i),
Repr::Custom(..) => None,
Repr::Simple(..) => None,
Repr::SimpleMessage(..) => None,
}
}

Expand Down Expand Up @@ -377,6 +392,7 @@ impl Error {
match self.repr {
Repr::Os(..) => None,
Repr::Simple(..) => None,
Repr::SimpleMessage(..) => None,
Repr::Custom(ref c) => Some(&*c.error),
}
}
Expand Down Expand Up @@ -448,6 +464,7 @@ impl Error {
match self.repr {
Repr::Os(..) => None,
Repr::Simple(..) => None,
Repr::SimpleMessage(..) => None,
Repr::Custom(ref mut c) => Some(&mut *c.error),
}
}
Expand Down Expand Up @@ -484,6 +501,7 @@ impl Error {
match self.repr {
Repr::Os(..) => None,
Repr::Simple(..) => None,
Repr::SimpleMessage(..) => None,
Repr::Custom(c) => Some(c.error),
}
}
Expand Down Expand Up @@ -512,6 +530,7 @@ impl Error {
Repr::Os(code) => sys::decode_error_kind(code),
Repr::Custom(ref c) => c.kind,
Repr::Simple(kind) => kind,
Repr::SimpleMessage(kind, _) => kind,
}
}
}
Expand All @@ -527,6 +546,9 @@ impl fmt::Debug for Repr {
.finish(),
Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt),
Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(),
Repr::SimpleMessage(kind, &message) => {
fmt.debug_struct("Error").field("kind", &kind).field("message", &message).finish()
}
}
}
}
Expand All @@ -541,6 +563,7 @@ impl fmt::Display for Error {
}
Repr::Custom(ref c) => c.error.fmt(fmt),
Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()),
Repr::SimpleMessage(_, &msg) => msg.fmt(fmt),
}
}
}
Expand All @@ -551,6 +574,7 @@ impl error::Error for Error {
fn description(&self) -> &str {
match self.repr {
Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(),
Repr::SimpleMessage(_, &msg) => msg,
Repr::Custom(ref c) => c.error.description(),
}
}
Expand All @@ -560,6 +584,7 @@ impl error::Error for Error {
match self.repr {
Repr::Os(..) => None,
Repr::Simple(..) => None,
Repr::SimpleMessage(..) => None,
Repr::Custom(ref c) => c.error.cause(),
}
}
Expand All @@ -568,6 +593,7 @@ impl error::Error for Error {
match self.repr {
Repr::Os(..) => None,
Repr::Simple(..) => None,
Repr::SimpleMessage(..) => None,
Repr::Custom(ref c) => c.error.source(),
}
}
Expand Down
16 changes: 16 additions & 0 deletions library/std/src/io/error/tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
use super::{Custom, Error, ErrorKind, Repr};
use crate::error;
use crate::fmt;
use crate::mem::size_of;
use crate::sys::decode_error_kind;
use crate::sys::os::error_string;

#[test]
fn test_size() {
assert!(size_of::<Error>() <= size_of::<[usize; 2]>());
}

#[test]
fn test_debug_error() {
let code = 6;
Expand Down Expand Up @@ -51,3 +57,13 @@ fn test_downcasting() {
let extracted = err.into_inner().unwrap();
extracted.downcast::<TestError>().unwrap();
}

#[test]
fn test_const() {
const E: Error = Error::new_const(ErrorKind::NotFound, &"hello");

assert_eq!(E.kind(), ErrorKind::NotFound);
assert_eq!(E.to_string(), "hello");
assert!(format!("{:?}", E).contains("\"hello\""));
assert!(format!("{:?}", E).contains("NotFound"));
}
4 changes: 2 additions & 2 deletions library/std/src/io/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl Read for &[u8] {
#[inline]
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
if buf.len() > self.len() {
return Err(Error::new(ErrorKind::UnexpectedEof, "failed to fill whole buffer"));
return Err(Error::new_const(ErrorKind::UnexpectedEof, &"failed to fill whole buffer"));
}
let (a, b) = self.split_at(buf.len());

Expand Down Expand Up @@ -345,7 +345,7 @@ impl Write for &mut [u8] {
if self.write(data)? == data.len() {
Ok(())
} else {
Err(Error::new(ErrorKind::WriteZero, "failed to write whole buffer"))
Err(Error::new_const(ErrorKind::WriteZero, &"failed to write whole buffer"))
}
}

Expand Down
16 changes: 11 additions & 5 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ where
let ret = f(g.buf);
if str::from_utf8(&g.buf[g.len..]).is_err() {
ret.and_then(|_| {
Err(Error::new(ErrorKind::InvalidData, "stream did not contain valid UTF-8"))
Err(Error::new_const(ErrorKind::InvalidData, &"stream did not contain valid UTF-8"))
})
} else {
g.len = g.buf.len();
Expand Down Expand Up @@ -429,7 +429,7 @@ pub(crate) fn default_read_exact<R: Read + ?Sized>(this: &mut R, mut buf: &mut [
}
}
if !buf.is_empty() {
Err(Error::new(ErrorKind::UnexpectedEof, "failed to fill whole buffer"))
Err(Error::new_const(ErrorKind::UnexpectedEof, &"failed to fill whole buffer"))
} else {
Ok(())
}
Expand Down Expand Up @@ -1437,7 +1437,10 @@ pub trait Write {
while !buf.is_empty() {
match self.write(buf) {
Ok(0) => {
return Err(Error::new(ErrorKind::WriteZero, "failed to write whole buffer"));
return Err(Error::new_const(
ErrorKind::WriteZero,
&"failed to write whole buffer",
));
}
Ok(n) => buf = &buf[n..],
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
Expand Down Expand Up @@ -1502,7 +1505,10 @@ pub trait Write {
while !bufs.is_empty() {
match self.write_vectored(bufs) {
Ok(0) => {
return Err(Error::new(ErrorKind::WriteZero, "failed to write whole buffer"));
return Err(Error::new_const(
ErrorKind::WriteZero,
&"failed to write whole buffer",
));
}
Ok(n) => bufs = IoSlice::advance(bufs, n),
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
Expand Down Expand Up @@ -1576,7 +1582,7 @@ pub trait Write {
if output.error.is_err() {
output.error
} else {
Err(Error::new(ErrorKind::Other, "formatter error"))
Err(Error::new_const(ErrorKind::Other, &"formatter error"))
}
}
}
Expand Down
Loading

0 comments on commit db492ec

Please sign in to comment.