Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #83432

Merged
merged 29 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f398a49
Add test for io::Error's size.
m-ou-se Mar 21, 2021
2da9856
Add internal io::Error::new_const tot avoid allocations.
m-ou-se Mar 21, 2021
9678362
Add test for io::Error::new_const.
m-ou-se Mar 21, 2021
7b71719
Use io::Error::new_const everywhere to avoid allocations.
m-ou-se Mar 21, 2021
6bbcc5b
Fix typos
m-ou-se Mar 21, 2021
219603a
Only enable assert_dep_graph when query-dep-graph is enabled.
cjgillot Mar 20, 2021
45583e5
Change `-W help` to display edition level.
ehuss Mar 22, 2021
1aad7e7
Err if the debugging options are not passed.
cjgillot Mar 22, 2021
f900ee3
Allow not emitting `uwtable` on Android
Mar 22, 2021
494e29d
Fix codeblock tooltip position
GuillaumeGomez Mar 22, 2021
6c80deb
Add GUI test to enforce tooltip position
GuillaumeGomez Mar 22, 2021
72a180e
rustdoc: Record crate name instead of using `None`
camelid Mar 23, 2021
c9ae359
Don't push the crate name onto the `Cache.stack`
camelid Mar 23, 2021
4fa187f
Slight visual improvements to warning boxes in the docs
wooster0 Mar 23, 2021
5e81325
Fix sidebar trait items sort
GuillaumeGomez Mar 12, 2021
7245903
Add test to enforce sidebar trait items order
GuillaumeGomez Mar 12, 2021
801ee83
Use &str instead of String
GuillaumeGomez Mar 23, 2021
31447f6
Fix comment.
cjgillot Mar 23, 2021
68244fc
Remove unnecessary `Option` wrapping around `Crate.module`
camelid Mar 23, 2021
a7f902b
Remove another unnecessary `Option`
camelid Mar 23, 2021
f134ca3
Rollup merge of #83051 - GuillaumeGomez:sidebar-trait-items-order, r=…
Dylan-DPC Mar 24, 2021
2f611da
Rollup merge of #83313 - cjgillot:assert, r=michaelwoerister
Dylan-DPC Mar 24, 2021
a42e62f
Rollup merge of #83353 - m-ou-se:io-error-avoid-alloc, r=nagisa
Dylan-DPC Mar 24, 2021
30db261
Rollup merge of #83391 - hyd-dev:uwtable, r=alexcrichton
Dylan-DPC Mar 24, 2021
2b53ec3
Rollup merge of #83392 - ehuss:w-help-edition, r=varkor
Dylan-DPC Mar 24, 2021
8c1c7a7
Rollup merge of #83393 - GuillaumeGomez:codeblock-tooltip-position, r…
Dylan-DPC Mar 24, 2021
3d645a3
Rollup merge of #83399 - camelid:rustdoc-priv-link-from-crate, r=jyn514
Dylan-DPC Mar 24, 2021
7843771
Rollup merge of #83405 - r00ster91:deprecated_emoji, r=GuillaumeGomez
Dylan-DPC Mar 24, 2021
5c0d880
Rollup merge of #83415 - camelid:remove-crate-module-option, r=jyn514
Dylan-DPC Mar 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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