Skip to content

Commit db492ec

Browse files
committed
Auto merge of #83432 - Dylan-DPC:rollup-4z5f6al, r=Dylan-DPC
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
2 parents 673d0db + 5c0d880 commit db492ec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+522
-295
lines changed

compiler/rustc_driver/src/lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,12 @@ Available lint options:
895895
let print_lints = |lints: Vec<&Lint>| {
896896
for lint in lints {
897897
let name = lint.name_lower().replace("_", "-");
898-
println!(" {} {:7.7} {}", padded(&name), lint.default_level.as_str(), lint.desc);
898+
println!(
899+
" {} {:7.7} {}",
900+
padded(&name),
901+
lint.default_level(sess.edition()).as_str(),
902+
lint.desc
903+
);
899904
}
900905
println!("\n");
901906
};

compiler/rustc_incremental/src/assert_dep_graph.rs

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ pub fn assert_dep_graph(tcx: TyCtxt<'_>) {
5757
dump_graph(tcx);
5858
}
5959

60+
if !tcx.sess.opts.debugging_opts.query_dep_graph {
61+
return;
62+
}
63+
6064
// if the `rustc_attrs` feature is not enabled, then the
6165
// attributes we are interested in cannot be present anyway, so
6266
// skip the walk.

compiler/rustc_incremental/src/persist/dirty_clean.rs

+4
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ impl Assertion {
148148
}
149149

150150
pub fn check_dirty_clean_annotations(tcx: TyCtxt<'_>) {
151+
if !tcx.sess.opts.debugging_opts.query_dep_graph {
152+
return;
153+
}
154+
151155
// can't add `#[rustc_dirty]` etc without opting in to this feature
152156
if !tcx.features().rustc_attrs {
153157
return;

compiler/rustc_passes/src/check_attr.rs

+20
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ impl CheckAttrVisitor<'tcx> {
9999
self.check_naked(hir_id, attr, span, target)
100100
} else if self.tcx.sess.check_name(attr, sym::rustc_legacy_const_generics) {
101101
self.check_rustc_legacy_const_generics(&attr, span, target, item)
102+
} else if self.tcx.sess.check_name(attr, sym::rustc_clean)
103+
|| self.tcx.sess.check_name(attr, sym::rustc_dirty)
104+
|| self.tcx.sess.check_name(attr, sym::rustc_if_this_changed)
105+
|| self.tcx.sess.check_name(attr, sym::rustc_then_this_would_need)
106+
{
107+
self.check_rustc_dirty_clean(&attr)
102108
} else {
103109
// lint-only checks
104110
if self.tcx.sess.check_name(attr, sym::cold) {
@@ -1012,6 +1018,20 @@ impl CheckAttrVisitor<'tcx> {
10121018
}
10131019
}
10141020

1021+
/// Checks that the dep-graph debugging attributes are only present when the query-dep-graph
1022+
/// option is passed to the compiler.
1023+
fn check_rustc_dirty_clean(&self, attr: &Attribute) -> bool {
1024+
if self.tcx.sess.opts.debugging_opts.query_dep_graph {
1025+
true
1026+
} else {
1027+
self.tcx
1028+
.sess
1029+
.struct_span_err(attr.span, "attribute requires -Z query-dep-graph to be enabled")
1030+
.emit();
1031+
false
1032+
}
1033+
}
1034+
10151035
/// Checks if `#[link_section]` is applied to a function or static.
10161036
fn check_link_section(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
10171037
match target {

compiler/rustc_session/src/session.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ impl Session {
863863
} else if self.target.requires_uwtable {
864864
true
865865
} else {
866-
self.opts.cg.force_unwind_tables.unwrap_or(false)
866+
self.opts.cg.force_unwind_tables.unwrap_or(self.target.default_uwtable)
867867
}
868868
}
869869

compiler/rustc_target/src/spec/android_base.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ pub fn opts() -> TargetOptions {
1212
base.dwarf_version = Some(2);
1313
base.position_independent_executables = true;
1414
base.has_elf_tls = false;
15-
base.requires_uwtable = true;
15+
// This is for backward compatibility, see https://github.com/rust-lang/rust/issues/49867
16+
// for context. (At that time, there was no `-C force-unwind-tables`, so the only solution
17+
// was to always emit `uwtable`).
18+
base.default_uwtable = true;
1619
base.crt_static_respected = false;
1720
base
1821
}

compiler/rustc_target/src/spec/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,10 @@ pub struct TargetOptions {
11111111
/// unwinders.
11121112
pub requires_uwtable: bool,
11131113

1114+
/// Whether or not to emit `uwtable` attributes on functions if `-C force-unwind-tables`
1115+
/// is not specified and `uwtable` is not required on this target.
1116+
pub default_uwtable: bool,
1117+
11141118
/// Whether or not SIMD types are passed by reference in the Rust ABI,
11151119
/// typically required if a target can be compiled with a mixed set of
11161120
/// target features. This is `true` by default, and `false` for targets like
@@ -1248,6 +1252,7 @@ impl Default for TargetOptions {
12481252
default_hidden_visibility: false,
12491253
emit_debug_gdb_scripts: true,
12501254
requires_uwtable: false,
1255+
default_uwtable: false,
12511256
simd_types_indirect: true,
12521257
limit_rdylib_exports: true,
12531258
override_export_symbols: None,
@@ -1711,6 +1716,7 @@ impl Target {
17111716
key!(default_hidden_visibility, bool);
17121717
key!(emit_debug_gdb_scripts, bool);
17131718
key!(requires_uwtable, bool);
1719+
key!(default_uwtable, bool);
17141720
key!(simd_types_indirect, bool);
17151721
key!(limit_rdylib_exports, bool);
17161722
key!(override_export_symbols, opt_list);
@@ -1947,6 +1953,7 @@ impl ToJson for Target {
19471953
target_option_val!(default_hidden_visibility);
19481954
target_option_val!(emit_debug_gdb_scripts);
19491955
target_option_val!(requires_uwtable);
1956+
target_option_val!(default_uwtable);
19501957
target_option_val!(simd_types_indirect);
19511958
target_option_val!(limit_rdylib_exports);
19521959
target_option_val!(override_export_symbols);

library/std/src/ffi/c_str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ impl fmt::Display for NulError {
10361036
impl From<NulError> for io::Error {
10371037
/// Converts a [`NulError`] into a [`io::Error`].
10381038
fn from(_: NulError) -> io::Error {
1039-
io::Error::new(io::ErrorKind::InvalidInput, "data provided contains a nul byte")
1039+
io::Error::new_const(io::ErrorKind::InvalidInput, &"data provided contains a nul byte")
10401040
}
10411041
}
10421042

library/std/src/fs.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2188,7 +2188,10 @@ impl DirBuilder {
21882188
match path.parent() {
21892189
Some(p) => self.create_dir_all(p)?,
21902190
None => {
2191-
return Err(io::Error::new(io::ErrorKind::Other, "failed to create whole tree"));
2191+
return Err(io::Error::new_const(
2192+
io::ErrorKind::Other,
2193+
&"failed to create whole tree",
2194+
));
21922195
}
21932196
}
21942197
match self.inner.mkdir(path) {

library/std/src/io/buffered/bufwriter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ impl<W: Write> BufWriter<W> {
164164

165165
match r {
166166
Ok(0) => {
167-
return Err(Error::new(
167+
return Err(Error::new_const(
168168
ErrorKind::WriteZero,
169-
"failed to write the buffered data",
169+
&"failed to write the buffered data",
170170
));
171171
}
172172
Ok(n) => guard.consume(n),

library/std/src/io/cursor.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ where
229229
self.pos = n;
230230
Ok(self.pos)
231231
}
232-
None => Err(Error::new(
232+
None => Err(Error::new_const(
233233
ErrorKind::InvalidInput,
234-
"invalid seek to a negative or overflowing position",
234+
&"invalid seek to a negative or overflowing position",
235235
)),
236236
}
237237
}
@@ -328,9 +328,9 @@ fn slice_write_vectored(
328328
// Resizing write implementation
329329
fn vec_write(pos_mut: &mut u64, vec: &mut Vec<u8>, buf: &[u8]) -> io::Result<usize> {
330330
let pos: usize = (*pos_mut).try_into().map_err(|_| {
331-
Error::new(
331+
Error::new_const(
332332
ErrorKind::InvalidInput,
333-
"cursor position exceeds maximum possible vector length",
333+
&"cursor position exceeds maximum possible vector length",
334334
)
335335
})?;
336336
// Make sure the internal buffer is as least as big as where we

library/std/src/io/error.rs

+26
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ impl fmt::Debug for Error {
6969
enum Repr {
7070
Os(i32),
7171
Simple(ErrorKind),
72+
// &str is a fat pointer, but &&str is a thin pointer.
73+
SimpleMessage(ErrorKind, &'static &'static str),
7274
Custom(Box<Custom>),
7375
}
7476

@@ -259,6 +261,18 @@ impl Error {
259261
Error { repr: Repr::Custom(Box::new(Custom { kind, error })) }
260262
}
261263

264+
/// Creates a new I/O error from a known kind of error as well as a
265+
/// constant message.
266+
///
267+
/// This function does not allocate.
268+
///
269+
/// This function should maybe change to
270+
/// `new_const<const MSG: &'static str>(kind: ErrorKind)`
271+
/// in the future, when const generics allow that.
272+
pub(crate) const fn new_const(kind: ErrorKind, message: &'static &'static str) -> Error {
273+
Self { repr: Repr::SimpleMessage(kind, message) }
274+
}
275+
262276
/// Returns an error representing the last OS error which occurred.
263277
///
264278
/// This function reads the value of `errno` for the target platform (e.g.
@@ -342,6 +356,7 @@ impl Error {
342356
Repr::Os(i) => Some(i),
343357
Repr::Custom(..) => None,
344358
Repr::Simple(..) => None,
359+
Repr::SimpleMessage(..) => None,
345360
}
346361
}
347362

@@ -377,6 +392,7 @@ impl Error {
377392
match self.repr {
378393
Repr::Os(..) => None,
379394
Repr::Simple(..) => None,
395+
Repr::SimpleMessage(..) => None,
380396
Repr::Custom(ref c) => Some(&*c.error),
381397
}
382398
}
@@ -448,6 +464,7 @@ impl Error {
448464
match self.repr {
449465
Repr::Os(..) => None,
450466
Repr::Simple(..) => None,
467+
Repr::SimpleMessage(..) => None,
451468
Repr::Custom(ref mut c) => Some(&mut *c.error),
452469
}
453470
}
@@ -484,6 +501,7 @@ impl Error {
484501
match self.repr {
485502
Repr::Os(..) => None,
486503
Repr::Simple(..) => None,
504+
Repr::SimpleMessage(..) => None,
487505
Repr::Custom(c) => Some(c.error),
488506
}
489507
}
@@ -512,6 +530,7 @@ impl Error {
512530
Repr::Os(code) => sys::decode_error_kind(code),
513531
Repr::Custom(ref c) => c.kind,
514532
Repr::Simple(kind) => kind,
533+
Repr::SimpleMessage(kind, _) => kind,
515534
}
516535
}
517536
}
@@ -527,6 +546,9 @@ impl fmt::Debug for Repr {
527546
.finish(),
528547
Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt),
529548
Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(),
549+
Repr::SimpleMessage(kind, &message) => {
550+
fmt.debug_struct("Error").field("kind", &kind).field("message", &message).finish()
551+
}
530552
}
531553
}
532554
}
@@ -541,6 +563,7 @@ impl fmt::Display for Error {
541563
}
542564
Repr::Custom(ref c) => c.error.fmt(fmt),
543565
Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()),
566+
Repr::SimpleMessage(_, &msg) => msg.fmt(fmt),
544567
}
545568
}
546569
}
@@ -551,6 +574,7 @@ impl error::Error for Error {
551574
fn description(&self) -> &str {
552575
match self.repr {
553576
Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(),
577+
Repr::SimpleMessage(_, &msg) => msg,
554578
Repr::Custom(ref c) => c.error.description(),
555579
}
556580
}
@@ -560,6 +584,7 @@ impl error::Error for Error {
560584
match self.repr {
561585
Repr::Os(..) => None,
562586
Repr::Simple(..) => None,
587+
Repr::SimpleMessage(..) => None,
563588
Repr::Custom(ref c) => c.error.cause(),
564589
}
565590
}
@@ -568,6 +593,7 @@ impl error::Error for Error {
568593
match self.repr {
569594
Repr::Os(..) => None,
570595
Repr::Simple(..) => None,
596+
Repr::SimpleMessage(..) => None,
571597
Repr::Custom(ref c) => c.error.source(),
572598
}
573599
}

library/std/src/io/error/tests.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
use super::{Custom, Error, ErrorKind, Repr};
22
use crate::error;
33
use crate::fmt;
4+
use crate::mem::size_of;
45
use crate::sys::decode_error_kind;
56
use crate::sys::os::error_string;
67

8+
#[test]
9+
fn test_size() {
10+
assert!(size_of::<Error>() <= size_of::<[usize; 2]>());
11+
}
12+
713
#[test]
814
fn test_debug_error() {
915
let code = 6;
@@ -51,3 +57,13 @@ fn test_downcasting() {
5157
let extracted = err.into_inner().unwrap();
5258
extracted.downcast::<TestError>().unwrap();
5359
}
60+
61+
#[test]
62+
fn test_const() {
63+
const E: Error = Error::new_const(ErrorKind::NotFound, &"hello");
64+
65+
assert_eq!(E.kind(), ErrorKind::NotFound);
66+
assert_eq!(E.to_string(), "hello");
67+
assert!(format!("{:?}", E).contains("\"hello\""));
68+
assert!(format!("{:?}", E).contains("NotFound"));
69+
}

library/std/src/io/impls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl Read for &[u8] {
263263
#[inline]
264264
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
265265
if buf.len() > self.len() {
266-
return Err(Error::new(ErrorKind::UnexpectedEof, "failed to fill whole buffer"));
266+
return Err(Error::new_const(ErrorKind::UnexpectedEof, &"failed to fill whole buffer"));
267267
}
268268
let (a, b) = self.split_at(buf.len());
269269

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

library/std/src/io/mod.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ where
333333
let ret = f(g.buf);
334334
if str::from_utf8(&g.buf[g.len..]).is_err() {
335335
ret.and_then(|_| {
336-
Err(Error::new(ErrorKind::InvalidData, "stream did not contain valid UTF-8"))
336+
Err(Error::new_const(ErrorKind::InvalidData, &"stream did not contain valid UTF-8"))
337337
})
338338
} else {
339339
g.len = g.buf.len();
@@ -429,7 +429,7 @@ pub(crate) fn default_read_exact<R: Read + ?Sized>(this: &mut R, mut buf: &mut [
429429
}
430430
}
431431
if !buf.is_empty() {
432-
Err(Error::new(ErrorKind::UnexpectedEof, "failed to fill whole buffer"))
432+
Err(Error::new_const(ErrorKind::UnexpectedEof, &"failed to fill whole buffer"))
433433
} else {
434434
Ok(())
435435
}
@@ -1437,7 +1437,10 @@ pub trait Write {
14371437
while !buf.is_empty() {
14381438
match self.write(buf) {
14391439
Ok(0) => {
1440-
return Err(Error::new(ErrorKind::WriteZero, "failed to write whole buffer"));
1440+
return Err(Error::new_const(
1441+
ErrorKind::WriteZero,
1442+
&"failed to write whole buffer",
1443+
));
14411444
}
14421445
Ok(n) => buf = &buf[n..],
14431446
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
@@ -1502,7 +1505,10 @@ pub trait Write {
15021505
while !bufs.is_empty() {
15031506
match self.write_vectored(bufs) {
15041507
Ok(0) => {
1505-
return Err(Error::new(ErrorKind::WriteZero, "failed to write whole buffer"));
1508+
return Err(Error::new_const(
1509+
ErrorKind::WriteZero,
1510+
&"failed to write whole buffer",
1511+
));
15061512
}
15071513
Ok(n) => bufs = IoSlice::advance(bufs, n),
15081514
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
@@ -1576,7 +1582,7 @@ pub trait Write {
15761582
if output.error.is_err() {
15771583
output.error
15781584
} else {
1579-
Err(Error::new(ErrorKind::Other, "formatter error"))
1585+
Err(Error::new_const(ErrorKind::Other, &"formatter error"))
15801586
}
15811587
}
15821588
}

0 commit comments

Comments
 (0)