diff --git a/Cargo.lock b/Cargo.lock index e5a7b7d9b6056..5ed7981bb5207 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -287,11 +287,10 @@ dependencies = [ "cargo-platform", "cargo-test-macro", "cargo-test-support", + "cargo-util", "clap", - "core-foundation", "crates-io", "crossbeam-utils 0.8.0", - "crypto-hash", "curl", "curl-sys", "env_logger 0.8.1", @@ -313,7 +312,6 @@ dependencies = [ "libgit2-sys", "log", "memchr", - "miow 0.3.6", "num_cpus", "opener", "openssl", @@ -322,12 +320,10 @@ dependencies = [ "rand 0.8.3", "rustc-workspace-hack", "rustfix", - "same-file", "semver 0.10.0", "serde", "serde_ignored", "serde_json", - "shell-escape", "strip-ansi-escapes", "tar", "tempfile", @@ -396,8 +392,9 @@ version = "0.1.0" name = "cargo-test-support" version = "0.1.0" dependencies = [ - "cargo", + "anyhow", "cargo-test-macro", + "cargo-util", "filetime", "flate2", "git2", @@ -410,6 +407,26 @@ dependencies = [ "url 2.1.1", ] +[[package]] +name = "cargo-util" +version = "0.1.0" +dependencies = [ + "anyhow", + "core-foundation", + "crypto-hash", + "filetime", + "hex 0.4.2", + "jobserver", + "libc", + "log", + "miow 0.3.6", + "same-file", + "shell-escape", + "tempfile", + "walkdir", + "winapi 0.3.9", +] + [[package]] name = "cargo_metadata" version = "0.8.2" @@ -2765,9 +2782,9 @@ checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" [[package]] name = "proc-macro2" -version = "1.0.19" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" +checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" dependencies = [ "unicode-xid", ] @@ -4793,18 +4810,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.118" +version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800" +checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.118" +version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df" +checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d" dependencies = [ "proc-macro2", "quote", @@ -5100,9 +5117,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.38" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e69abc24912995b3038597a7a593be5053eb0fb44f3cc5beec0deb421790c1f4" +checksum = "3fd9d1e9976102a03c542daa2eff1b43f9d72306342f3f8b3ed5fb8908195d6f" dependencies = [ "proc-macro2", "quote", diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 25a78041c0007..e527d55fc2a4f 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -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"); }; diff --git a/compiler/rustc_driver/src/pretty.rs b/compiler/rustc_driver/src/pretty.rs index 5512bd74453e5..1544c9758387f 100644 --- a/compiler/rustc_driver/src/pretty.rs +++ b/compiler/rustc_driver/src/pretty.rs @@ -471,21 +471,6 @@ pub fn print_after_hir_lowering<'tcx>( format!("{:#?}", krate) }), - ThirTree => { - let mut out = String::new(); - abort_on_err(rustc_typeck::check_crate(tcx), tcx.sess); - debug!("pretty printing THIR tree"); - for did in tcx.body_owners() { - let hir = tcx.hir(); - let body = hir.body(hir.body_owned_by(hir.local_def_id_to_hir_id(did))); - let arena = thir::Arena::default(); - let thir = - thir::build_thir(tcx, ty::WithOptConstParam::unknown(did), &arena, &body.value); - let _ = writeln!(out, "{:?}:\n{:#?}\n", did, thir); - } - out - } - _ => unreachable!(), }; @@ -501,18 +486,40 @@ fn print_with_analysis( ppm: PpMode, ofile: Option<&Path>, ) -> Result<(), ErrorReported> { - let mut out = Vec::new(); - tcx.analysis(LOCAL_CRATE)?; - match ppm { - Mir => write_mir_pretty(tcx, None, &mut out).unwrap(), - MirCFG => write_mir_graphviz(tcx, None, &mut out).unwrap(), + let out = match ppm { + Mir => { + let mut out = Vec::new(); + write_mir_pretty(tcx, None, &mut out).unwrap(); + String::from_utf8(out).unwrap() + } + + MirCFG => { + let mut out = Vec::new(); + write_mir_graphviz(tcx, None, &mut out).unwrap(); + String::from_utf8(out).unwrap() + } + + ThirTree => { + let mut out = String::new(); + abort_on_err(rustc_typeck::check_crate(tcx), tcx.sess); + debug!("pretty printing THIR tree"); + for did in tcx.body_owners() { + let hir = tcx.hir(); + let body = hir.body(hir.body_owned_by(hir.local_def_id_to_hir_id(did))); + let arena = thir::Arena::default(); + let thir = + thir::build_thir(tcx, ty::WithOptConstParam::unknown(did), &arena, &body.value); + let _ = writeln!(out, "{:?}:\n{:#?}\n", did, thir); + } + out + } + _ => unreachable!(), - } + }; - let out = std::str::from_utf8(&out).unwrap(); - write_or_print(out, ofile); + write_or_print(&out, ofile); Ok(()) } diff --git a/compiler/rustc_incremental/src/assert_dep_graph.rs b/compiler/rustc_incremental/src/assert_dep_graph.rs index f1f69f1510bf1..a080b0ce3395c 100644 --- a/compiler/rustc_incremental/src/assert_dep_graph.rs +++ b/compiler/rustc_incremental/src/assert_dep_graph.rs @@ -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. diff --git a/compiler/rustc_incremental/src/persist/dirty_clean.rs b/compiler/rustc_incremental/src/persist/dirty_clean.rs index 0b544b8ab415e..cb089a728eee0 100644 --- a/compiler/rustc_incremental/src/persist/dirty_clean.rs +++ b/compiler/rustc_incremental/src/persist/dirty_clean.rs @@ -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; diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index d91d0e1765bbf..85add83f88bf7 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -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) { @@ -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 { diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 75078a1231163..8d47ddca18824 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2274,7 +2274,7 @@ impl PpMode { pub fn needs_analysis(&self) -> bool { use PpMode::*; - matches!(*self, Mir | MirCFG) + matches!(*self, Mir | MirCFG | ThirTree) } } diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs index 8a4c69b5ac8f9..5a939cc24f5d6 100644 --- a/compiler/rustc_typeck/src/check/upvar.rs +++ b/compiler/rustc_typeck/src/check/upvar.rs @@ -30,7 +30,6 @@ //! then mean that all later passes would have to check for these figments //! and report an error, and it just seems like more mess in the end.) -use super::writeback::Resolver; use super::FnCtxt; use crate::expr_use_visitor as euv; @@ -42,7 +41,6 @@ use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_infer::infer::UpvarRegion; use rustc_middle::hir::place::{Place, PlaceBase, PlaceWithHirId, Projection, ProjectionKind}; use rustc_middle::mir::FakeReadCause; -use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::{self, Ty, TyCtxt, TypeckResults, UpvarSubsts}; use rustc_session::lint; use rustc_span::sym; @@ -167,7 +165,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let closure_hir_id = self.tcx.hir().local_def_id_to_hir_id(local_def_id); if should_do_migration_analysis(self.tcx, closure_hir_id) { - self.perform_2229_migration_anaysis(closure_def_id, capture_clause, span, body); + self.perform_2229_migration_anaysis(closure_def_id, capture_clause, span); } // We now fake capture information for all variables that are mentioned within the closure @@ -467,13 +465,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { closure_def_id: DefId, capture_clause: hir::CaptureBy, span: Span, - body: &'tcx hir::Body<'tcx>, ) { let need_migrations = self.compute_2229_migrations( closure_def_id, span, capture_clause, - body, self.typeck_results.borrow().closure_min_captures.get(&closure_def_id), ); @@ -511,19 +507,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { closure_def_id: DefId, closure_span: Span, closure_clause: hir::CaptureBy, - body: &'tcx hir::Body<'tcx>, min_captures: Option<&ty::RootVariableMinCaptureList<'tcx>>, ) -> Vec { - fn resolve_ty>( - fcx: &FnCtxt<'_, 'tcx>, - span: Span, - body: &'tcx hir::Body<'tcx>, - ty: T, - ) -> T { - let mut resolver = Resolver::new(fcx, &span, body); - ty.fold_with(&mut resolver) - } - let upvars = if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) { upvars } else { @@ -533,7 +518,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut need_migrations = Vec::new(); for (&var_hir_id, _) in upvars.iter() { - let ty = resolve_ty(self, closure_span, body, self.node_ty(var_hir_id)); + let ty = self.infcx.resolve_vars_if_possible(self.node_ty(var_hir_id)); if !ty.needs_drop(self.tcx, self.tcx.param_env(closure_def_id.expect_local())) { continue; diff --git a/compiler/rustc_typeck/src/check/writeback.rs b/compiler/rustc_typeck/src/check/writeback.rs index 9a183ed9e629e..e472add6e80f3 100644 --- a/compiler/rustc_typeck/src/check/writeback.rs +++ b/compiler/rustc_typeck/src/check/writeback.rs @@ -675,7 +675,7 @@ impl Locatable for hir::HirId { /// The Resolver. This is the type folding engine that detects /// unresolved types and so forth. -crate struct Resolver<'cx, 'tcx> { +struct Resolver<'cx, 'tcx> { tcx: TyCtxt<'tcx>, infcx: &'cx InferCtxt<'cx, 'tcx>, span: &'cx dyn Locatable, @@ -686,7 +686,7 @@ crate struct Resolver<'cx, 'tcx> { } impl<'cx, 'tcx> Resolver<'cx, 'tcx> { - crate fn new( + fn new( fcx: &'cx FnCtxt<'cx, 'tcx>, span: &'cx dyn Locatable, body: &'tcx hir::Body<'tcx>, diff --git a/library/std/src/ffi/c_str.rs b/library/std/src/ffi/c_str.rs index 945bfda1b7874..687ed61b95961 100644 --- a/library/std/src/ffi/c_str.rs +++ b/library/std/src/ffi/c_str.rs @@ -1036,7 +1036,7 @@ impl fmt::Display for NulError { impl From 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") } } diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 43119c36cfec7..ccbc69a975c32 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -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) { diff --git a/library/std/src/io/buffered/bufwriter.rs b/library/std/src/io/buffered/bufwriter.rs index 65bc2fcf00ae0..80f98bbbad366 100644 --- a/library/std/src/io/buffered/bufwriter.rs +++ b/library/std/src/io/buffered/bufwriter.rs @@ -164,9 +164,9 @@ impl BufWriter { 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), diff --git a/library/std/src/io/cursor.rs b/library/std/src/io/cursor.rs index bbee2cc98425e..9021b47006538 100644 --- a/library/std/src/io/cursor.rs +++ b/library/std/src/io/cursor.rs @@ -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", )), } } @@ -328,9 +328,9 @@ fn slice_write_vectored( // Resizing write implementation fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result { 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 diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index ba0f0a0cd714a..2122aa755e157 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -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), } @@ -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(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. @@ -342,6 +356,7 @@ impl Error { Repr::Os(i) => Some(i), Repr::Custom(..) => None, Repr::Simple(..) => None, + Repr::SimpleMessage(..) => None, } } @@ -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), } } @@ -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), } } @@ -484,6 +501,7 @@ impl Error { match self.repr { Repr::Os(..) => None, Repr::Simple(..) => None, + Repr::SimpleMessage(..) => None, Repr::Custom(c) => Some(c.error), } } @@ -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, } } } @@ -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() + } } } } @@ -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), } } } @@ -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(), } } @@ -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(), } } @@ -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(), } } diff --git a/library/std/src/io/error/tests.rs b/library/std/src/io/error/tests.rs index 0cce9368c8089..5098a46313de3 100644 --- a/library/std/src/io/error/tests.rs +++ b/library/std/src/io/error/tests.rs @@ -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::() <= size_of::<[usize; 2]>()); +} + #[test] fn test_debug_error() { let code = 6; @@ -51,3 +57,13 @@ fn test_downcasting() { let extracted = err.into_inner().unwrap(); extracted.downcast::().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")); +} diff --git a/library/std/src/io/impls.rs b/library/std/src/io/impls.rs index 9870cfc4c95c3..6891bd8a66437 100644 --- a/library/std/src/io/impls.rs +++ b/library/std/src/io/impls.rs @@ -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()); @@ -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")) } } diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 6abb300054af8..5316305a30370 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -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(); @@ -429,7 +429,7 @@ pub(crate) fn default_read_exact(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(()) } @@ -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 => {} @@ -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 => {} @@ -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")) } } } diff --git a/library/std/src/io/tests.rs b/library/std/src/io/tests.rs index a85dd0d982715..2b14e16150317 100644 --- a/library/std/src/io/tests.rs +++ b/library/std/src/io/tests.rs @@ -152,12 +152,12 @@ fn take_eof() { impl Read for R { fn read(&mut self, _: &mut [u8]) -> io::Result { - Err(io::Error::new(io::ErrorKind::Other, "")) + Err(io::Error::new_const(io::ErrorKind::Other, &"")) } } impl BufRead for R { fn fill_buf(&mut self) -> io::Result<&[u8]> { - Err(io::Error::new(io::ErrorKind::Other, "")) + Err(io::Error::new_const(io::ErrorKind::Other, &"")) } fn consume(&mut self, _amt: usize) {} } diff --git a/library/std/src/net/mod.rs b/library/std/src/net/mod.rs index d4b1552fec5ff..d814e9b25ba9a 100644 --- a/library/std/src/net/mod.rs +++ b/library/std/src/net/mod.rs @@ -88,6 +88,6 @@ where } } Err(last_err.unwrap_or_else(|| { - Error::new(ErrorKind::InvalidInput, "could not resolve to any addresses") + Error::new_const(ErrorKind::InvalidInput, &"could not resolve to any addresses") })) } diff --git a/library/std/src/net/udp.rs b/library/std/src/net/udp.rs index 2377a76a33de9..b9af5992dffdf 100644 --- a/library/std/src/net/udp.rs +++ b/library/std/src/net/udp.rs @@ -173,7 +173,7 @@ impl UdpSocket { pub fn send_to(&self, buf: &[u8], addr: A) -> io::Result { match addr.to_socket_addrs()?.next() { Some(addr) => self.0.send_to(buf, &addr), - None => Err(Error::new(ErrorKind::InvalidInput, "no addresses to send data to")), + None => Err(Error::new_const(ErrorKind::InvalidInput, &"no addresses to send data to")), } } diff --git a/library/std/src/sys/hermit/fd.rs b/library/std/src/sys/hermit/fd.rs index 97d1a38b41ab1..1c0515a150398 100644 --- a/library/std/src/sys/hermit/fd.rs +++ b/library/std/src/sys/hermit/fd.rs @@ -46,7 +46,7 @@ impl FileDesc { self.duplicate_path(&[]) } pub fn duplicate_path(&self, _path: &[u8]) -> io::Result { - Err(io::Error::new(ErrorKind::Other, "duplicate isn't supported")) + Err(io::Error::new_const(ErrorKind::Other, &"duplicate isn't supported")) } pub fn nonblocking(&self) -> io::Result { @@ -54,11 +54,11 @@ impl FileDesc { } pub fn set_cloexec(&self) -> io::Result<()> { - Err(io::Error::new(ErrorKind::Other, "cloexec isn't supported")) + Err(io::Error::new_const(ErrorKind::Other, &"cloexec isn't supported")) } pub fn set_nonblocking(&self, _nonblocking: bool) -> io::Result<()> { - Err(io::Error::new(ErrorKind::Other, "nonblocking isn't supported")) + Err(io::Error::new_const(ErrorKind::Other, &"nonblocking isn't supported")) } } diff --git a/library/std/src/sys/hermit/fs.rs b/library/std/src/sys/hermit/fs.rs index 1807655e97170..0f33282fa8370 100644 --- a/library/std/src/sys/hermit/fs.rs +++ b/library/std/src/sys/hermit/fs.rs @@ -226,7 +226,7 @@ impl OpenOptions { (false, _, true) => Ok(O_WRONLY | O_APPEND), (true, _, true) => Ok(O_RDWR | O_APPEND), (false, false, false) => { - Err(io::Error::new(ErrorKind::InvalidInput, "invalid access mode")) + Err(io::Error::new_const(ErrorKind::InvalidInput, &"invalid access mode")) } } } @@ -236,12 +236,18 @@ impl OpenOptions { (true, false) => {} (false, false) => { if self.truncate || self.create || self.create_new { - return Err(io::Error::new(ErrorKind::InvalidInput, "invalid creation mode")); + return Err(io::Error::new_const( + ErrorKind::InvalidInput, + &"invalid creation mode", + )); } } (_, true) => { if self.truncate && !self.create_new { - return Err(io::Error::new(ErrorKind::InvalidInput, "invalid creation mode")); + return Err(io::Error::new_const( + ErrorKind::InvalidInput, + &"invalid creation mode", + )); } } } diff --git a/library/std/src/sys/hermit/mod.rs b/library/std/src/sys/hermit/mod.rs index 17a51abeb0ef6..1ecda25c03de5 100644 --- a/library/std/src/sys/hermit/mod.rs +++ b/library/std/src/sys/hermit/mod.rs @@ -55,7 +55,10 @@ pub fn unsupported() -> crate::io::Result { } pub fn unsupported_err() -> crate::io::Error { - crate::io::Error::new(crate::io::ErrorKind::Other, "operation not supported on HermitCore yet") + crate::io::Error::new_const( + crate::io::ErrorKind::Other, + &"operation not supported on HermitCore yet", + ) } // This enum is used as the storage for a bunch of types which can't actually diff --git a/library/std/src/sys/hermit/net.rs b/library/std/src/sys/hermit/net.rs index 8a788a9265f63..7053487ccfbe0 100644 --- a/library/std/src/sys/hermit/net.rs +++ b/library/std/src/sys/hermit/net.rs @@ -14,7 +14,10 @@ use crate::time::Duration; /// if not, starts it. pub fn init() -> io::Result<()> { if abi::network_init() < 0 { - return Err(io::Error::new(ErrorKind::Other, "Unable to initialize network interface")); + return Err(io::Error::new_const( + ErrorKind::Other, + &"Unable to initialize network interface", + )); } Ok(()) @@ -47,9 +50,10 @@ impl TcpStream { match abi::tcpstream::connect(addr.ip().to_string().as_bytes(), addr.port(), None) { Ok(handle) => Ok(TcpStream(Arc::new(Socket(handle)))), - _ => { - Err(io::Error::new(ErrorKind::Other, "Unable to initiate a connection on a socket")) - } + _ => Err(io::Error::new_const( + ErrorKind::Other, + &"Unable to initiate a connection on a socket", + )), } } @@ -60,15 +64,16 @@ impl TcpStream { Some(duration.as_millis() as u64), ) { Ok(handle) => Ok(TcpStream(Arc::new(Socket(handle)))), - _ => { - Err(io::Error::new(ErrorKind::Other, "Unable to initiate a connection on a socket")) - } + _ => Err(io::Error::new_const( + ErrorKind::Other, + &"Unable to initiate a connection on a socket", + )), } } pub fn set_read_timeout(&self, duration: Option) -> io::Result<()> { abi::tcpstream::set_read_timeout(*self.0.as_inner(), duration.map(|d| d.as_millis() as u64)) - .map_err(|_| io::Error::new(ErrorKind::Other, "Unable to set timeout value")) + .map_err(|_| io::Error::new_const(ErrorKind::Other, &"Unable to set timeout value")) } pub fn set_write_timeout(&self, duration: Option) -> io::Result<()> { @@ -76,26 +81,28 @@ impl TcpStream { *self.0.as_inner(), duration.map(|d| d.as_millis() as u64), ) - .map_err(|_| io::Error::new(ErrorKind::Other, "Unable to set timeout value")) + .map_err(|_| io::Error::new_const(ErrorKind::Other, &"Unable to set timeout value")) } pub fn read_timeout(&self) -> io::Result> { - let duration = abi::tcpstream::get_read_timeout(*self.0.as_inner()) - .map_err(|_| io::Error::new(ErrorKind::Other, "Unable to determine timeout value"))?; + let duration = abi::tcpstream::get_read_timeout(*self.0.as_inner()).map_err(|_| { + io::Error::new_const(ErrorKind::Other, &"Unable to determine timeout value") + })?; Ok(duration.map(|d| Duration::from_millis(d))) } pub fn write_timeout(&self) -> io::Result> { - let duration = abi::tcpstream::get_write_timeout(*self.0.as_inner()) - .map_err(|_| io::Error::new(ErrorKind::Other, "Unable to determine timeout value"))?; + let duration = abi::tcpstream::get_write_timeout(*self.0.as_inner()).map_err(|_| { + io::Error::new_const(ErrorKind::Other, &"Unable to determine timeout value") + })?; Ok(duration.map(|d| Duration::from_millis(d))) } pub fn peek(&self, buf: &mut [u8]) -> io::Result { abi::tcpstream::peek(*self.0.as_inner(), buf) - .map_err(|_| io::Error::new(ErrorKind::Other, "set_nodelay failed")) + .map_err(|_| io::Error::new_const(ErrorKind::Other, &"set_nodelay failed")) } pub fn read(&self, buffer: &mut [u8]) -> io::Result { @@ -107,7 +114,7 @@ impl TcpStream { for i in ioslice.iter_mut() { let ret = abi::tcpstream::read(*self.0.as_inner(), &mut i[0..]) - .map_err(|_| io::Error::new(ErrorKind::Other, "Unable to read on socket"))?; + .map_err(|_| io::Error::new_const(ErrorKind::Other, &"Unable to read on socket"))?; if ret != 0 { size += ret; @@ -130,8 +137,9 @@ impl TcpStream { let mut size: usize = 0; for i in ioslice.iter() { - size += abi::tcpstream::write(*self.0.as_inner(), i) - .map_err(|_| io::Error::new(ErrorKind::Other, "Unable to write on socket"))?; + size += abi::tcpstream::write(*self.0.as_inner(), i).map_err(|_| { + io::Error::new_const(ErrorKind::Other, &"Unable to write on socket") + })?; } Ok(size) @@ -144,13 +152,13 @@ impl TcpStream { pub fn peer_addr(&self) -> io::Result { let (ipaddr, port) = abi::tcpstream::peer_addr(*self.0.as_inner()) - .map_err(|_| io::Error::new(ErrorKind::Other, "peer_addr failed"))?; + .map_err(|_| io::Error::new_const(ErrorKind::Other, &"peer_addr failed"))?; let saddr = match ipaddr { Ipv4(ref addr) => SocketAddr::new(IpAddr::V4(Ipv4Addr::from(addr.0)), port), Ipv6(ref addr) => SocketAddr::new(IpAddr::V6(Ipv6Addr::from(addr.0)), port), _ => { - return Err(io::Error::new(ErrorKind::Other, "peer_addr failed")); + return Err(io::Error::new_const(ErrorKind::Other, &"peer_addr failed")); } }; @@ -158,12 +166,12 @@ impl TcpStream { } pub fn socket_addr(&self) -> io::Result { - Err(io::Error::new(ErrorKind::Other, "socket_addr isn't supported")) + Err(io::Error::new_const(ErrorKind::Other, &"socket_addr isn't supported")) } pub fn shutdown(&self, how: Shutdown) -> io::Result<()> { abi::tcpstream::shutdown(*self.0.as_inner(), how as i32) - .map_err(|_| io::Error::new(ErrorKind::Other, "unable to shutdown socket")) + .map_err(|_| io::Error::new_const(ErrorKind::Other, &"unable to shutdown socket")) } pub fn duplicate(&self) -> io::Result { @@ -172,31 +180,31 @@ impl TcpStream { pub fn set_nodelay(&self, mode: bool) -> io::Result<()> { abi::tcpstream::set_nodelay(*self.0.as_inner(), mode) - .map_err(|_| io::Error::new(ErrorKind::Other, "set_nodelay failed")) + .map_err(|_| io::Error::new_const(ErrorKind::Other, &"set_nodelay failed")) } pub fn nodelay(&self) -> io::Result { abi::tcpstream::nodelay(*self.0.as_inner()) - .map_err(|_| io::Error::new(ErrorKind::Other, "nodelay failed")) + .map_err(|_| io::Error::new_const(ErrorKind::Other, &"nodelay failed")) } pub fn set_ttl(&self, tll: u32) -> io::Result<()> { abi::tcpstream::set_tll(*self.0.as_inner(), tll) - .map_err(|_| io::Error::new(ErrorKind::Other, "unable to set TTL")) + .map_err(|_| io::Error::new_const(ErrorKind::Other, &"unable to set TTL")) } pub fn ttl(&self) -> io::Result { abi::tcpstream::get_tll(*self.0.as_inner()) - .map_err(|_| io::Error::new(ErrorKind::Other, "unable to get TTL")) + .map_err(|_| io::Error::new_const(ErrorKind::Other, &"unable to get TTL")) } pub fn take_error(&self) -> io::Result> { - Err(io::Error::new(ErrorKind::Other, "take_error isn't supported")) + Err(io::Error::new_const(ErrorKind::Other, &"take_error isn't supported")) } pub fn set_nonblocking(&self, mode: bool) -> io::Result<()> { abi::tcpstream::set_nonblocking(*self.0.as_inner(), mode) - .map_err(|_| io::Error::new(ErrorKind::Other, "unable to set blocking mode")) + .map_err(|_| io::Error::new_const(ErrorKind::Other, &"unable to set blocking mode")) } } @@ -222,12 +230,12 @@ impl TcpListener { pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> { let (handle, ipaddr, port) = abi::tcplistener::accept(self.0.port()) - .map_err(|_| io::Error::new(ErrorKind::Other, "accept failed"))?; + .map_err(|_| io::Error::new_const(ErrorKind::Other, &"accept failed"))?; let saddr = match ipaddr { Ipv4(ref addr) => SocketAddr::new(IpAddr::V4(Ipv4Addr::from(addr.0)), port), Ipv6(ref addr) => SocketAddr::new(IpAddr::V6(Ipv6Addr::from(addr.0)), port), _ => { - return Err(io::Error::new(ErrorKind::Other, "accept failed")); + return Err(io::Error::new_const(ErrorKind::Other, &"accept failed")); } }; @@ -239,27 +247,27 @@ impl TcpListener { } pub fn set_ttl(&self, _: u32) -> io::Result<()> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn ttl(&self) -> io::Result { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn set_only_v6(&self, _: bool) -> io::Result<()> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn only_v6(&self) -> io::Result { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn take_error(&self) -> io::Result> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn set_nonblocking(&self, _: bool) -> io::Result<()> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } } @@ -273,127 +281,127 @@ pub struct UdpSocket(abi::Handle); impl UdpSocket { pub fn bind(_: io::Result<&SocketAddr>) -> io::Result { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn peer_addr(&self) -> io::Result { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn socket_addr(&self) -> io::Result { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn recv_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn peek_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn send_to(&self, _: &[u8], _: &SocketAddr) -> io::Result { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn duplicate(&self) -> io::Result { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn set_read_timeout(&self, _: Option) -> io::Result<()> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn set_write_timeout(&self, _: Option) -> io::Result<()> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn read_timeout(&self) -> io::Result> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn write_timeout(&self) -> io::Result> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn set_broadcast(&self, _: bool) -> io::Result<()> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn broadcast(&self) -> io::Result { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn set_multicast_loop_v4(&self, _: bool) -> io::Result<()> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn multicast_loop_v4(&self) -> io::Result { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn set_multicast_ttl_v4(&self, _: u32) -> io::Result<()> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn multicast_ttl_v4(&self) -> io::Result { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn set_multicast_loop_v6(&self, _: bool) -> io::Result<()> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn multicast_loop_v6(&self) -> io::Result { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn join_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn join_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn leave_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn leave_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn set_ttl(&self, _: u32) -> io::Result<()> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn ttl(&self) -> io::Result { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn take_error(&self) -> io::Result> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn set_nonblocking(&self, _: bool) -> io::Result<()> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn recv(&self, _: &mut [u8]) -> io::Result { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn peek(&self, _: &mut [u8]) -> io::Result { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn send(&self, _: &[u8]) -> io::Result { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } pub fn connect(&self, _: io::Result<&SocketAddr>) -> io::Result<()> { - Err(io::Error::new(ErrorKind::Other, "not supported")) + Err(io::Error::new_const(ErrorKind::Other, &"not supported")) } } diff --git a/library/std/src/sys/hermit/stdio.rs b/library/std/src/sys/hermit/stdio.rs index 82304dd6dc293..6bff13ca92cca 100644 --- a/library/std/src/sys/hermit/stdio.rs +++ b/library/std/src/sys/hermit/stdio.rs @@ -40,7 +40,7 @@ impl io::Write for Stdout { unsafe { len = abi::write(1, data.as_ptr() as *const u8, data.len()) } if len < 0 { - Err(io::Error::new(io::ErrorKind::Other, "Stdout is not able to print")) + Err(io::Error::new_const(io::ErrorKind::Other, &"Stdout is not able to print")) } else { Ok(len as usize) } @@ -52,7 +52,7 @@ impl io::Write for Stdout { unsafe { len = abi::write(1, data.as_ptr() as *const u8, data.len()) } if len < 0 { - Err(io::Error::new(io::ErrorKind::Other, "Stdout is not able to print")) + Err(io::Error::new_const(io::ErrorKind::Other, &"Stdout is not able to print")) } else { Ok(len as usize) } @@ -81,7 +81,7 @@ impl io::Write for Stderr { unsafe { len = abi::write(2, data.as_ptr() as *const u8, data.len()) } if len < 0 { - Err(io::Error::new(io::ErrorKind::Other, "Stderr is not able to print")) + Err(io::Error::new_const(io::ErrorKind::Other, &"Stderr is not able to print")) } else { Ok(len as usize) } @@ -93,7 +93,7 @@ impl io::Write for Stderr { unsafe { len = abi::write(2, data.as_ptr() as *const u8, data.len()) } if len < 0 { - Err(io::Error::new(io::ErrorKind::Other, "Stderr is not able to print")) + Err(io::Error::new_const(io::ErrorKind::Other, &"Stderr is not able to print")) } else { Ok(len as usize) } diff --git a/library/std/src/sys/hermit/thread.rs b/library/std/src/sys/hermit/thread.rs index 7bd71e120de40..f35a3a8a80fc5 100644 --- a/library/std/src/sys/hermit/thread.rs +++ b/library/std/src/sys/hermit/thread.rs @@ -37,7 +37,7 @@ impl Thread { // The thread failed to start and as a result p was not consumed. Therefore, it is // safe to reconstruct the box so that it gets deallocated. drop(Box::from_raw(p)); - Err(io::Error::new(io::ErrorKind::Other, "Unable to create thread!")) + Err(io::Error::new_const(io::ErrorKind::Other, &"Unable to create thread!")) } else { Ok(Thread { tid: tid }) }; diff --git a/library/std/src/sys/sgx/mod.rs b/library/std/src/sys/sgx/mod.rs index b10bed621dbad..3cd245f40d967 100644 --- a/library/std/src/sys/sgx/mod.rs +++ b/library/std/src/sys/sgx/mod.rs @@ -50,7 +50,7 @@ pub fn unsupported() -> crate::io::Result { } pub fn unsupported_err() -> crate::io::Error { - crate::io::Error::new(ErrorKind::Other, "operation not supported on SGX yet") + crate::io::Error::new_const(ErrorKind::Other, &"operation not supported on SGX yet") } /// This function is used to implement various functions that doesn't exist, @@ -61,9 +61,9 @@ pub fn unsupported_err() -> crate::io::Error { pub fn sgx_ineffective(v: T) -> crate::io::Result { static SGX_INEFFECTIVE_ERROR: AtomicBool = AtomicBool::new(false); if SGX_INEFFECTIVE_ERROR.load(Ordering::Relaxed) { - Err(crate::io::Error::new( + Err(crate::io::Error::new_const( ErrorKind::Other, - "operation can't be trusted to have any effect on SGX", + &"operation can't be trusted to have any effect on SGX", )) } else { Ok(v) diff --git a/library/std/src/sys/sgx/net.rs b/library/std/src/sys/sgx/net.rs index 3dd8267921e5e..c0c5d55548c5f 100644 --- a/library/std/src/sys/sgx/net.rs +++ b/library/std/src/sys/sgx/net.rs @@ -97,9 +97,9 @@ impl TcpStream { pub fn connect_timeout(addr: &SocketAddr, dur: Duration) -> io::Result { if dur == Duration::default() { - return Err(io::Error::new( + return Err(io::Error::new_const( io::ErrorKind::InvalidInput, - "cannot set a 0 duration timeout", + &"cannot set a 0 duration timeout", )); } Self::connect(Ok(addr)) // FIXME: ignoring timeout @@ -108,9 +108,9 @@ impl TcpStream { pub fn set_read_timeout(&self, dur: Option) -> io::Result<()> { match dur { Some(dur) if dur == Duration::default() => { - return Err(io::Error::new( + return Err(io::Error::new_const( io::ErrorKind::InvalidInput, - "cannot set a 0 duration timeout", + &"cannot set a 0 duration timeout", )); } _ => sgx_ineffective(()), @@ -120,9 +120,9 @@ impl TcpStream { pub fn set_write_timeout(&self, dur: Option) -> io::Result<()> { match dur { Some(dur) if dur == Duration::default() => { - return Err(io::Error::new( + return Err(io::Error::new_const( io::ErrorKind::InvalidInput, - "cannot set a 0 duration timeout", + &"cannot set a 0 duration timeout", )); } _ => sgx_ineffective(()), diff --git a/library/std/src/sys/unix/android.rs b/library/std/src/sys/unix/android.rs index ea05ee3d7cedf..cf6aa31b7cfe3 100644 --- a/library/std/src/sys/unix/android.rs +++ b/library/std/src/sys/unix/android.rs @@ -96,7 +96,7 @@ pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> { Some(f) => cvt_r(|| f(fd, size as i64)).map(drop), None => { if size > i32::MAX as u64 { - Err(io::Error::new(io::ErrorKind::InvalidInput, "cannot truncate >2GB")) + Err(io::Error::new_const(io::ErrorKind::InvalidInput, &"cannot truncate >2GB")) } else { cvt_r(|| ftruncate(fd, size as i32)).map(drop) } @@ -123,7 +123,7 @@ pub unsafe fn cvt_pread64( if let Ok(o) = offset.try_into() { cvt(pread(fd, buf, count, o)) } else { - Err(io::Error::new(io::ErrorKind::InvalidInput, "cannot pread >2GB")) + Err(io::Error::new_const(io::ErrorKind::InvalidInput, &"cannot pread >2GB")) } }) } @@ -141,7 +141,7 @@ pub unsafe fn cvt_pwrite64( if let Ok(o) = offset.try_into() { cvt(pwrite(fd, buf, count, o)) } else { - Err(io::Error::new(io::ErrorKind::InvalidInput, "cannot pwrite >2GB")) + Err(io::Error::new_const(io::ErrorKind::InvalidInput, &"cannot pwrite >2GB")) } }) } diff --git a/library/std/src/sys/unix/ext/fs.rs b/library/std/src/sys/unix/ext/fs.rs index 21bdfe29578bf..9a982a4acd9e2 100644 --- a/library/std/src/sys/unix/ext/fs.rs +++ b/library/std/src/sys/unix/ext/fs.rs @@ -109,7 +109,7 @@ pub trait FileExt { } } if !buf.is_empty() { - Err(io::Error::new(io::ErrorKind::UnexpectedEof, "failed to fill whole buffer")) + Err(io::Error::new_const(io::ErrorKind::UnexpectedEof, &"failed to fill whole buffer")) } else { Ok(()) } @@ -191,9 +191,9 @@ pub trait FileExt { while !buf.is_empty() { match self.write_at(buf, offset) { Ok(0) => { - return Err(io::Error::new( + return Err(io::Error::new_const( io::ErrorKind::WriteZero, - "failed to write whole buffer", + &"failed to write whole buffer", )); } Ok(n) => { diff --git a/library/std/src/sys/unix/ext/net/addr.rs b/library/std/src/sys/unix/ext/net/addr.rs index 1f9036242eb59..6e7d1f1678a9e 100644 --- a/library/std/src/sys/unix/ext/net/addr.rs +++ b/library/std/src/sys/unix/ext/net/addr.rs @@ -29,16 +29,16 @@ pub(super) unsafe fn sockaddr_un(path: &Path) -> io::Result<(libc::sockaddr_un, let bytes = path.as_os_str().as_bytes(); if bytes.contains(&0) { - return Err(io::Error::new( + return Err(io::Error::new_const( io::ErrorKind::InvalidInput, - "paths may not contain interior null bytes", + &"paths may not contain interior null bytes", )); } if bytes.len() >= addr.sun_path.len() { - return Err(io::Error::new( + return Err(io::Error::new_const( io::ErrorKind::InvalidInput, - "path must be shorter than SUN_LEN", + &"path must be shorter than SUN_LEN", )); } for (dst, src) in addr.sun_path.iter_mut().zip(bytes.iter()) { @@ -118,9 +118,9 @@ impl SocketAddr { // linux returns zero bytes of address len = sun_path_offset(&addr) as libc::socklen_t; // i.e., zero-length address } else if addr.sun_family != libc::AF_UNIX as libc::sa_family_t { - return Err(io::Error::new( + return Err(io::Error::new_const( io::ErrorKind::InvalidInput, - "file descriptor did not correspond to a Unix socket", + &"file descriptor did not correspond to a Unix socket", )); } diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index d1b0ad9e5f847..f25a6280cd076 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -357,17 +357,17 @@ impl FileAttr { tv_nsec: ext.stx_btime.tv_nsec as _, })) } else { - Err(io::Error::new( + Err(io::Error::new_const( io::ErrorKind::Other, - "creation time is not available for the filesystem", + &"creation time is not available for the filesystem", )) }; } } - Err(io::Error::new( + Err(io::Error::new_const( io::ErrorKind::Other, - "creation time is not available on this platform \ + &"creation time is not available on this platform \ currently", )) } @@ -1156,9 +1156,9 @@ fn open_from(from: &Path) -> io::Result<(crate::fs::File, crate::fs::Metadata)> let reader = File::open(from)?; let metadata = reader.metadata()?; if !metadata.is_file() { - return Err(Error::new( + return Err(Error::new_const( ErrorKind::InvalidInput, - "the source path is not an existing regular file", + &"the source path is not an existing regular file", )); } Ok((reader, metadata)) diff --git a/library/std/src/sys/unix/l4re.rs b/library/std/src/sys/unix/l4re.rs index a2912387108e1..d60a4b5591fae 100644 --- a/library/std/src/sys/unix/l4re.rs +++ b/library/std/src/sys/unix/l4re.rs @@ -1,6 +1,6 @@ macro_rules! unimpl { () => { - return Err(io::Error::new(io::ErrorKind::Other, "No networking available on L4Re.")); + return Err(io::Error::new_const(io::ErrorKind::Other, &"No networking available on L4Re.")); }; } diff --git a/library/std/src/sys/unix/net.rs b/library/std/src/sys/unix/net.rs index 587ffe15981d5..e6b61062d15ff 100644 --- a/library/std/src/sys/unix/net.rs +++ b/library/std/src/sys/unix/net.rs @@ -139,9 +139,9 @@ impl Socket { let mut pollfd = libc::pollfd { fd: self.0.raw(), events: libc::POLLOUT, revents: 0 }; if timeout.as_secs() == 0 && timeout.subsec_nanos() == 0 { - return Err(io::Error::new( + return Err(io::Error::new_const( io::ErrorKind::InvalidInput, - "cannot set a 0 duration timeout", + &"cannot set a 0 duration timeout", )); } @@ -150,7 +150,7 @@ impl Socket { loop { let elapsed = start.elapsed(); if elapsed >= timeout { - return Err(io::Error::new(io::ErrorKind::TimedOut, "connection timed out")); + return Err(io::Error::new_const(io::ErrorKind::TimedOut, &"connection timed out")); } let timeout = timeout - elapsed; @@ -177,7 +177,10 @@ impl Socket { // for POLLHUP rather than read readiness if pollfd.revents & libc::POLLHUP != 0 { let e = self.take_error()?.unwrap_or_else(|| { - io::Error::new(io::ErrorKind::Other, "no error set after POLLHUP") + io::Error::new_const( + io::ErrorKind::Other, + &"no error set after POLLHUP", + ) }); return Err(e); } @@ -318,9 +321,9 @@ impl Socket { let timeout = match dur { Some(dur) => { if dur.as_secs() == 0 && dur.subsec_nanos() == 0 { - return Err(io::Error::new( + return Err(io::Error::new_const( io::ErrorKind::InvalidInput, - "cannot set a 0 duration timeout", + &"cannot set a 0 duration timeout", )); } diff --git a/library/std/src/sys/unix/os.rs b/library/std/src/sys/unix/os.rs index 1d1118aa69434..4a077e2151ed9 100644 --- a/library/std/src/sys/unix/os.rs +++ b/library/std/src/sys/unix/os.rs @@ -287,9 +287,9 @@ pub fn current_exe() -> io::Result { 0, ))?; if path_len <= 1 { - return Err(io::Error::new( + return Err(io::Error::new_const( io::ErrorKind::Other, - "KERN_PROC_PATHNAME sysctl returned zero-length string", + &"KERN_PROC_PATHNAME sysctl returned zero-length string", )); } let mut path: Vec = Vec::with_capacity(path_len); @@ -310,9 +310,9 @@ pub fn current_exe() -> io::Result { if curproc_exe.is_file() { return crate::fs::read_link(curproc_exe); } - Err(io::Error::new( + Err(io::Error::new_const( io::ErrorKind::Other, - "/proc/curproc/exe doesn't point to regular file.", + &"/proc/curproc/exe doesn't point to regular file.", )) } sysctl().or_else(|_| procfs()) @@ -329,7 +329,7 @@ pub fn current_exe() -> io::Result { cvt(libc::sysctl(mib, 4, argv.as_mut_ptr() as *mut _, &mut argv_len, ptr::null_mut(), 0))?; argv.set_len(argv_len as usize); if argv[0].is_null() { - return Err(io::Error::new(io::ErrorKind::Other, "no current exe available")); + return Err(io::Error::new_const(io::ErrorKind::Other, &"no current exe available")); } let argv0 = CStr::from_ptr(argv[0]).to_bytes(); if argv0[0] == b'.' || argv0.iter().any(|b| *b == b'/') { @@ -343,9 +343,9 @@ pub fn current_exe() -> io::Result { #[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))] pub fn current_exe() -> io::Result { match crate::fs::read_link("/proc/self/exe") { - Err(ref e) if e.kind() == io::ErrorKind::NotFound => Err(io::Error::new( + Err(ref e) if e.kind() == io::ErrorKind::NotFound => Err(io::Error::new_const( io::ErrorKind::Other, - "no /proc/self/exe available. Is /proc mounted?", + &"no /proc/self/exe available. Is /proc mounted?", )), other => other, } @@ -431,7 +431,7 @@ pub fn current_exe() -> io::Result { _get_next_image_info(0, &mut cookie, &mut info, mem::size_of::() as i32); if result != 0 { use crate::io::ErrorKind; - Err(io::Error::new(ErrorKind::Other, "Error getting executable path")) + Err(io::Error::new_const(ErrorKind::Other, &"Error getting executable path")) } else { let name = CStr::from_ptr(info.name.as_ptr()).to_bytes(); Ok(PathBuf::from(OsStr::from_bytes(name))) @@ -447,7 +447,7 @@ pub fn current_exe() -> io::Result { #[cfg(any(target_os = "fuchsia", target_os = "l4re"))] pub fn current_exe() -> io::Result { use crate::io::ErrorKind; - Err(io::Error::new(ErrorKind::Other, "Not yet implemented!")) + Err(io::Error::new_const(ErrorKind::Other, &"Not yet implemented!")) } #[cfg(target_os = "vxworks")] diff --git a/library/std/src/sys/unix/process/process_fuchsia.rs b/library/std/src/sys/unix/process/process_fuchsia.rs index 0d4703d7f503a..b19ad4ccdc777 100644 --- a/library/std/src/sys/unix/process/process_fuchsia.rs +++ b/library/std/src/sys/unix/process/process_fuchsia.rs @@ -22,9 +22,9 @@ impl Command { let envp = self.capture_env(); if self.saw_nul() { - return Err(io::Error::new( + return Err(io::Error::new_const( io::ErrorKind::InvalidInput, - "nul byte found in provided data", + &"nul byte found in provided data", )); } @@ -37,7 +37,10 @@ impl Command { pub fn exec(&mut self, default: Stdio) -> io::Error { if self.saw_nul() { - return io::Error::new(io::ErrorKind::InvalidInput, "nul byte found in provided data"); + return io::Error::new_const( + io::ErrorKind::InvalidInput, + &"nul byte found in provided data", + ); } match self.setup_io(default, true) { @@ -182,9 +185,9 @@ impl Process { ))?; } if actual != 1 { - return Err(io::Error::new( + return Err(io::Error::new_const( io::ErrorKind::InvalidData, - "Failed to get exit status of process", + &"Failed to get exit status of process", )); } Ok(ExitStatus(proc_info.return_code)) @@ -220,9 +223,9 @@ impl Process { ))?; } if actual != 1 { - return Err(io::Error::new( + return Err(io::Error::new_const( io::ErrorKind::InvalidData, - "Failed to get exit status of process", + &"Failed to get exit status of process", )); } Ok(Some(ExitStatus(proc_info.return_code))) diff --git a/library/std/src/sys/unix/process/process_unix.rs b/library/std/src/sys/unix/process/process_unix.rs index 47aaca82af946..01f1318fe8078 100644 --- a/library/std/src/sys/unix/process/process_unix.rs +++ b/library/std/src/sys/unix/process/process_unix.rs @@ -28,7 +28,10 @@ impl Command { let envp = self.capture_env(); if self.saw_nul() { - return Err(io::Error::new(ErrorKind::InvalidInput, "nul byte found in provided data")); + return Err(io::Error::new_const( + ErrorKind::InvalidInput, + &"nul byte found in provided data", + )); } let (ours, theirs) = self.setup_io(default, needs_stdin)?; @@ -118,7 +121,10 @@ impl Command { let envp = self.capture_env(); if self.saw_nul() { - return io::Error::new(ErrorKind::InvalidInput, "nul byte found in provided data"); + return io::Error::new_const( + ErrorKind::InvalidInput, + &"nul byte found in provided data", + ); } match self.setup_io(default, true) { @@ -442,9 +448,9 @@ impl Process { // and used for another process, and we probably shouldn't be killing // random processes, so just return an error. if self.status.is_some() { - Err(Error::new( + Err(Error::new_const( ErrorKind::InvalidInput, - "invalid argument: can't kill an exited process", + &"invalid argument: can't kill an exited process", )) } else { cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(drop) diff --git a/library/std/src/sys/unsupported/common.rs b/library/std/src/sys/unsupported/common.rs index 2cdd9c4d19e6e..01e4fd3c994d4 100644 --- a/library/std/src/sys/unsupported/common.rs +++ b/library/std/src/sys/unsupported/common.rs @@ -18,7 +18,7 @@ pub fn unsupported() -> std_io::Result { } pub fn unsupported_err() -> std_io::Error { - std_io::Error::new(std_io::ErrorKind::Other, "operation not supported on this platform") + std_io::Error::new_const(std_io::ErrorKind::Other, &"operation not supported on this platform") } pub fn decode_error_kind(_code: i32) -> crate::io::ErrorKind { diff --git a/library/std/src/sys/unsupported/os.rs b/library/std/src/sys/unsupported/os.rs index 0615780c24212..897927e7b79a7 100644 --- a/library/std/src/sys/unsupported/os.rs +++ b/library/std/src/sys/unsupported/os.rs @@ -80,11 +80,11 @@ pub fn getenv(_: &OsStr) -> io::Result> { } pub fn setenv(_: &OsStr, _: &OsStr) -> io::Result<()> { - Err(io::Error::new(io::ErrorKind::Other, "cannot set env vars on this platform")) + Err(io::Error::new_const(io::ErrorKind::Other, &"cannot set env vars on this platform")) } pub fn unsetenv(_: &OsStr) -> io::Result<()> { - Err(io::Error::new(io::ErrorKind::Other, "cannot unset env vars on this platform")) + Err(io::Error::new_const(io::ErrorKind::Other, &"cannot unset env vars on this platform")) } pub fn temp_dir() -> PathBuf { diff --git a/library/std/src/sys/vxworks/process/process_vxworks.rs b/library/std/src/sys/vxworks/process/process_vxworks.rs index 69adbcdddc971..295452327eb70 100644 --- a/library/std/src/sys/vxworks/process/process_vxworks.rs +++ b/library/std/src/sys/vxworks/process/process_vxworks.rs @@ -22,7 +22,10 @@ impl Command { let envp = self.capture_env(); if self.saw_nul() { - return Err(io::Error::new(ErrorKind::InvalidInput, "nul byte found in provided data")); + return Err(io::Error::new_const( + ErrorKind::InvalidInput, + &"nul byte found in provided data", + )); } let (ours, theirs) = self.setup_io(default, needs_stdin)?; let mut p = Process { pid: 0, status: None }; @@ -134,9 +137,9 @@ impl Process { // and used for another process, and we probably shouldn't be killing // random processes, so just return an error. if self.status.is_some() { - Err(Error::new( + Err(Error::new_const( ErrorKind::InvalidInput, - "invalid argument: can't kill an exited process", + &"invalid argument: can't kill an exited process", )) } else { cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(drop) diff --git a/library/std/src/sys/wasi/ext/fs.rs b/library/std/src/sys/wasi/ext/fs.rs index 6472642f03499..ba4057bd34ca2 100644 --- a/library/std/src/sys/wasi/ext/fs.rs +++ b/library/std/src/sys/wasi/ext/fs.rs @@ -85,7 +85,7 @@ pub trait FileExt { } } if !buf.is_empty() { - Err(io::Error::new(io::ErrorKind::UnexpectedEof, "failed to fill whole buffer")) + Err(io::Error::new_const(io::ErrorKind::UnexpectedEof, &"failed to fill whole buffer")) } else { Ok(()) } @@ -151,9 +151,9 @@ pub trait FileExt { while !buf.is_empty() { match self.write_at(buf, offset) { Ok(0) => { - return Err(io::Error::new( + return Err(io::Error::new_const( io::ErrorKind::WriteZero, - "failed to write whole buffer", + &"failed to write whole buffer", )); } Ok(n) => { @@ -532,5 +532,5 @@ pub fn symlink_path, U: AsRef>(old_path: P, new_path: U) -> } fn osstr2str(f: &OsStr) -> io::Result<&str> { - f.to_str().ok_or_else(|| io::Error::new(io::ErrorKind::Other, "input must be utf-8")) + f.to_str().ok_or_else(|| io::Error::new_const(io::ErrorKind::Other, &"input must be utf-8")) } diff --git a/library/std/src/sys/wasi/fs.rs b/library/std/src/sys/wasi/fs.rs index 63c22136273fb..1ec3ff6a10f9a 100644 --- a/library/std/src/sys/wasi/fs.rs +++ b/library/std/src/sys/wasi/fs.rs @@ -670,7 +670,7 @@ fn open_parent(p: &Path) -> io::Result<(ManuallyDrop, PathBuf)> { } pub fn osstr2str(f: &OsStr) -> io::Result<&str> { - f.to_str().ok_or_else(|| io::Error::new(io::ErrorKind::Other, "input must be utf-8")) + f.to_str().ok_or_else(|| io::Error::new_const(io::ErrorKind::Other, &"input must be utf-8")) } pub fn copy(from: &Path, to: &Path) -> io::Result { diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs index 307a47678c6a2..c6509db80c05b 100644 --- a/library/std/src/sys/windows/fs.rs +++ b/library/std/src/sys/windows/fs.rs @@ -513,9 +513,9 @@ impl File { ) } _ => { - return Err(io::Error::new( + return Err(io::Error::new_const( io::ErrorKind::Other, - "Unsupported reparse point type", + &"Unsupported reparse point type", )); } }; @@ -802,7 +802,7 @@ pub fn link(original: &Path, link: &Path) -> io::Result<()> { #[cfg(target_vendor = "uwp")] pub fn link(_original: &Path, _link: &Path) -> io::Result<()> { - return Err(io::Error::new(io::ErrorKind::Other, "hard link are not supported on UWP")); + return Err(io::Error::new_const(io::ErrorKind::Other, &"hard link are not supported on UWP")); } pub fn stat(path: &Path) -> io::Result { diff --git a/library/std/src/sys/windows/mod.rs b/library/std/src/sys/windows/mod.rs index fcbff59dec007..0353c9811f15f 100644 --- a/library/std/src/sys/windows/mod.rs +++ b/library/std/src/sys/windows/mod.rs @@ -130,9 +130,9 @@ pub fn to_u16s>(s: S) -> crate::io::Result> { fn inner(s: &OsStr) -> crate::io::Result> { let mut maybe_result: Vec = s.encode_wide().collect(); if unrolled_find_u16s(0, &maybe_result).is_some() { - return Err(crate::io::Error::new( + return Err(crate::io::Error::new_const( ErrorKind::InvalidInput, - "strings passed to WinAPI cannot contain NULs", + &"strings passed to WinAPI cannot contain NULs", )); } maybe_result.push(0); diff --git a/library/std/src/sys/windows/net.rs b/library/std/src/sys/windows/net.rs index 9e74454bc2335..e50adcb28a4b7 100644 --- a/library/std/src/sys/windows/net.rs +++ b/library/std/src/sys/windows/net.rs @@ -136,9 +136,9 @@ impl Socket { } if timeout.as_secs() == 0 && timeout.subsec_nanos() == 0 { - return Err(io::Error::new( + return Err(io::Error::new_const( io::ErrorKind::InvalidInput, - "cannot set a 0 duration timeout", + &"cannot set a 0 duration timeout", )); } @@ -164,7 +164,7 @@ impl Socket { unsafe { cvt(c::select(1, ptr::null_mut(), &mut writefds, &mut errorfds, &timeout))? }; match n { - 0 => Err(io::Error::new(io::ErrorKind::TimedOut, "connection timed out")), + 0 => Err(io::Error::new_const(io::ErrorKind::TimedOut, &"connection timed out")), _ => { if writefds.fd_count != 1 { if let Some(e) = self.take_error()? { @@ -339,9 +339,9 @@ impl Socket { Some(dur) => { let timeout = sys::dur2timeout(dur); if timeout == 0 { - return Err(io::Error::new( + return Err(io::Error::new_const( io::ErrorKind::InvalidInput, - "cannot set a 0 duration timeout", + &"cannot set a 0 duration timeout", )); } timeout @@ -370,7 +370,7 @@ impl Socket { #[cfg(target_vendor = "uwp")] fn set_no_inherit(&self) -> io::Result<()> { - Err(io::Error::new(io::ErrorKind::Other, "Unavailable on UWP")) + Err(io::Error::new_const(io::ErrorKind::Other, &"Unavailable on UWP")) } pub fn shutdown(&self, how: Shutdown) -> io::Result<()> { diff --git a/library/std/src/sys/windows/process.rs b/library/std/src/sys/windows/process.rs index 83d37795ee5c1..30bbfdd0dd1e2 100644 --- a/library/std/src/sys/windows/process.rs +++ b/library/std/src/sys/windows/process.rs @@ -62,7 +62,7 @@ impl AsRef for EnvKey { fn ensure_no_nuls>(str: T) -> io::Result { if str.as_ref().encode_wide().any(|b| b == 0) { - Err(io::Error::new(ErrorKind::InvalidInput, "nul byte found in provided data")) + Err(io::Error::new_const(ErrorKind::InvalidInput, &"nul byte found in provided data")) } else { Ok(str) } diff --git a/library/std/src/sys/windows/stdio.rs b/library/std/src/sys/windows/stdio.rs index ff214497166be..be3141e46a1cc 100644 --- a/library/std/src/sys/windows/stdio.rs +++ b/library/std/src/sys/windows/stdio.rs @@ -68,9 +68,9 @@ fn write(handle_id: c::DWORD, data: &[u8]) -> io::Result { let utf8 = match str::from_utf8(&data[..len]) { Ok(s) => s, Err(ref e) if e.valid_up_to() == 0 => { - return Err(io::Error::new( + return Err(io::Error::new_const( io::ErrorKind::InvalidData, - "Windows stdio in console mode does not support writing non-UTF-8 byte sequences", + &"Windows stdio in console mode does not support writing non-UTF-8 byte sequences", )); } Err(e) => str::from_utf8(&data[..e.valid_up_to()]).unwrap(), @@ -149,9 +149,9 @@ impl io::Read for Stdin { if buf.len() == 0 { return Ok(0); } else if buf.len() < 4 { - return Err(io::Error::new( + return Err(io::Error::new_const( io::ErrorKind::InvalidInput, - "Windows stdin in console mode does not support a buffer too small to \ + &"Windows stdin in console mode does not support a buffer too small to \ guarantee holding one arbitrary UTF-8 character (4 bytes)", )); } @@ -243,9 +243,9 @@ fn utf16_to_utf8(utf16: &[u16], utf8: &mut [u8]) -> io::Result { } Err(_) => { // We can't really do any better than forget all data and return an error. - return Err(io::Error::new( + return Err(io::Error::new_const( io::ErrorKind::InvalidData, - "Windows stdin in console mode does not support non-UTF-16 input; \ + &"Windows stdin in console mode does not support non-UTF-16 input; \ encountered unpaired surrogate", )); } diff --git a/library/std/src/sys_common/fs.rs b/library/std/src/sys_common/fs.rs index 6bdb26cd078ed..92d0cc60850c6 100644 --- a/library/std/src/sys_common/fs.rs +++ b/library/std/src/sys_common/fs.rs @@ -9,9 +9,9 @@ pub fn copy(from: &Path, to: &Path) -> io::Result { let metadata = reader.metadata()?; if !metadata.is_file() { - return Err(Error::new( + return Err(Error::new_const( ErrorKind::InvalidInput, - "the source path is not an existing regular file", + &"the source path is not an existing regular file", )); } diff --git a/library/std/src/sys_common/net.rs b/library/std/src/sys_common/net.rs index 38ba0d2fbdb6b..d5f29c4a43970 100644 --- a/library/std/src/sys_common/net.rs +++ b/library/std/src/sys_common/net.rs @@ -108,7 +108,7 @@ pub fn sockaddr_to_addr(storage: &c::sockaddr_storage, len: usize) -> io::Result *(storage as *const _ as *const c::sockaddr_in6) }))) } - _ => Err(Error::new(ErrorKind::InvalidInput, "invalid argument")), + _ => Err(Error::new_const(ErrorKind::InvalidInput, &"invalid argument")), } } @@ -171,7 +171,7 @@ impl TryFrom<&str> for LookupHost { ($e:expr, $msg:expr) => { match $e { Some(r) => r, - None => return Err(io::Error::new(io::ErrorKind::InvalidInput, $msg)), + None => return Err(io::Error::new_const(io::ErrorKind::InvalidInput, &$msg)), } }; } diff --git a/library/std/src/thread/available_concurrency.rs b/library/std/src/thread/available_concurrency.rs index 64a5f89890a31..e8cdde8801459 100644 --- a/library/std/src/thread/available_concurrency.rs +++ b/library/std/src/thread/available_concurrency.rs @@ -64,7 +64,7 @@ cfg_if::cfg_if! { sysinfo.dwNumberOfProcessors as usize }; match res { - 0 => Err(io::Error::new(io::ErrorKind::NotFound, "The number of hardware threads is not known for the target platform")), + 0 => Err(io::Error::new_const(io::ErrorKind::NotFound, &"The number of hardware threads is not known for the target platform")), cpus => Ok(unsafe { NonZeroUsize::new_unchecked(cpus) }), } } @@ -81,7 +81,7 @@ cfg_if::cfg_if! { fn available_concurrency_internal() -> io::Result { match unsafe { libc::sysconf(libc::_SC_NPROCESSORS_ONLN) } { -1 => Err(io::Error::last_os_error()), - 0 => Err(io::Error::new(io::ErrorKind::NotFound, "The number of hardware threads is not known for the target platform")), + 0 => Err(io::Error::new_const(io::ErrorKind::NotFound, &"The number of hardware threads is not known for the target platform")), cpus => Ok(unsafe { NonZeroUsize::new_unchecked(cpus as usize) }), } } @@ -114,7 +114,7 @@ cfg_if::cfg_if! { if res == -1 { return Err(io::Error::last_os_error()); } else if cpus == 0 { - return Err(io::Error::new(io::ErrorKind::NotFound, "The number of hardware threads is not known for the target platform")); + return Err(io::Error::new_const(io::ErrorKind::NotFound, &"The number of hardware threads is not known for the target platform")); } } Ok(unsafe { NonZeroUsize::new_unchecked(cpus as usize) }) @@ -142,7 +142,7 @@ cfg_if::cfg_if! { if res == -1 { return Err(io::Error::last_os_error()); } else if cpus == 0 { - return Err(io::Error::new(io::ErrorKind::NotFound, "The number of hardware threads is not known for the target platform")); + return Err(io::Error::new_const(io::ErrorKind::NotFound, &"The number of hardware threads is not known for the target platform")); } Ok(unsafe { NonZeroUsize::new_unchecked(cpus as usize) }) @@ -150,7 +150,7 @@ cfg_if::cfg_if! { } else { // FIXME: implement on vxWorks, Redox, HermitCore, Haiku, l4re fn available_concurrency_internal() -> io::Result { - Err(io::Error::new(io::ErrorKind::NotFound, "The number of hardware threads is not known for the target platform")) + Err(io::Error::new_const(io::ErrorKind::NotFound, &"The number of hardware threads is not known for the target platform")) } } } diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index d0e058c7dda75..9052e5954200f 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -110,7 +110,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { }; Some(Item { - source: Span::dummy(), + span: Span::dummy(), name: None, attrs: Default::default(), visibility: Inherited, diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 4e4e1e5cbce2f..6e7164457ceb6 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -102,7 +102,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { .collect(); impls.push(Item { - source: self.cx.tcx.def_span(impl_def_id).clean(self.cx), + span: self.cx.tcx.def_span(impl_def_id).clean(self.cx), name: None, attrs: Default::default(), visibility: Inherited, diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 47a74238a7a3d..0d32c14c3be9b 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -459,7 +459,7 @@ fn build_module( items.push(clean::Item { name: None, attrs: box clean::Attributes::default(), - source: clean::Span::dummy(), + span: clean::Span::dummy(), def_id: DefId::local(CRATE_DEF_INDEX), visibility: clean::Public, kind: box clean::ImportItem(clean::Import::new_simple( diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 17a961a5f6655..e5fe1159928d5 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -235,7 +235,7 @@ impl Clean for doctree::Module<'_> { ModuleItem(Module { is_crate: self.is_crate, items }), cx, ); - Item { source: span.clean(cx), ..what_rustc_thinks } + Item { span: span.clean(cx), ..what_rustc_thinks } } } @@ -2132,7 +2132,7 @@ fn clean_extern_crate( vec![Item { name: Some(name), attrs: box attrs.clean(cx), - source: krate.span.clean(cx), + span: krate.span.clean(cx), def_id: crate_def_id, visibility: krate.vis.clean(cx), kind: box ExternCrateItem { src: orig_name }, diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 840a42c2b8aab..3dd27933471be 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -81,12 +81,14 @@ crate struct ExternalCrate { /// directly to the AST's concept of an item; it's a strict superset. #[derive(Clone)] crate struct Item { - /// Stringified span - crate source: Span, - /// Not everything has a name. E.g., impls + crate span: Span, + /// The name of this item. + /// Optional because not every item has a name, e.g. impls. crate name: Option, crate attrs: Box, crate visibility: Visibility, + /// Information about this item that is specific to what kind of item it is. + /// E.g., struct vs enum vs function. crate kind: Box, crate def_id: DefId, } @@ -100,7 +102,7 @@ impl fmt::Debug for Item { let def_id: &dyn fmt::Debug = if self.is_fake() { &"**FAKE**" } else { &self.def_id }; fmt.debug_struct("Item") - .field("source", &self.source) + .field("source", &self.span) .field("name", &self.name) .field("attrs", &self.attrs) .field("kind", &self.kind) @@ -165,7 +167,7 @@ impl Item { debug!("name={:?}, def_id={:?}", name, def_id); // `span_if_local()` lies about functions and only gives the span of the function signature - let source = def_id.as_local().map_or_else( + let span = def_id.as_local().map_or_else( || cx.tcx.def_span(def_id), |local| { let hir = cx.tcx.hir(); @@ -177,7 +179,7 @@ impl Item { def_id, kind: box kind, name, - source: source.clean(cx), + span: span.clean(cx), attrs, visibility: cx.tcx.visibility(def_id).clean(cx), } @@ -559,6 +561,8 @@ impl<'a> FromIterator<&'a DocFragment> for String { } } +/// The attributes on an [`Item`], including attributes like `#[derive(...)]` and `#[inline]`, +/// as well as doc comments. #[derive(Clone, Debug, Default)] crate struct Attributes { crate doc_strings: Vec, @@ -1798,8 +1802,13 @@ impl From for PrimitiveType { #[derive(Copy, Clone, Debug)] crate enum Visibility { + /// `pub` Public, + /// Visibility inherited from parent. + /// + /// For example, this is the visibility of private items and of enum variants. Inherited, + /// `pub(crate)`, `pub(super)`, or `pub(in path::to::somewhere)` Restricted(DefId), } @@ -1848,7 +1857,8 @@ crate enum Variant { Struct(VariantStruct), } -/// Small wrapper around `rustc_span::Span` that adds helper methods and enforces calling `source_callsite`. +/// Small wrapper around [`rustc_span::Span]` that adds helper methods +/// and enforces calling [`rustc_span::Span::source_callsite()`]. #[derive(Clone, Debug)] crate struct Span(rustc_span::Span); @@ -1860,12 +1870,12 @@ impl Span { Self(sp.source_callsite()) } - crate fn dummy() -> Self { - Self(rustc_span::DUMMY_SP) + crate fn inner(&self) -> rustc_span::Span { + self.0 } - crate fn span(&self) -> rustc_span::Span { - self.0 + crate fn dummy() -> Self { + Self(rustc_span::DUMMY_SP) } crate fn is_dummy(&self) -> bool { diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 864fbccbcc451..05993d8df6036 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -228,15 +228,15 @@ impl<'tcx> Context<'tcx> { /// may happen, for example, with externally inlined items where the source /// of their crate documentation isn't known. pub(super) fn src_href(&self, item: &clean::Item) -> Option { - if item.source.is_dummy() { + if item.span.is_dummy() { return None; } let mut root = self.root_path(); let mut path = String::new(); - let cnum = item.source.cnum(self.sess()); + let cnum = item.span.cnum(self.sess()); // We can safely ignore synthetic `SourceFile`s. - let file = match item.source.filename(self.sess()) { + let file = match item.span.filename(self.sess()) { FileName::Real(ref path) => path.local_path().to_path_buf(), _ => return None, }; @@ -270,8 +270,8 @@ impl<'tcx> Context<'tcx> { (&*symbol, &path) }; - let loline = item.source.lo(self.sess()).line; - let hiline = item.source.hi(self.sess()).line; + let loline = item.span.lo(self.sess()).line; + let hiline = item.span.hi(self.sess()).line; let lines = if loline == hiline { loline.to_string() } else { format!("{}-{}", loline, hiline) }; Some(format!( diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 6cdd3838023e6..c3c4c4952b3b4 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -937,7 +937,7 @@ fn item_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Mac Some("macro"), None, None, - it.source.span().edition(), + it.span.inner().edition(), ); }); document(w, cx, it, None) diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index 689cda76cc094..1b6a82fed1170 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -41,11 +41,11 @@ impl DocFolder for SourceCollector<'_, '_> { // then we need to render it out to the filesystem. if self.scx.include_sources // skip all synthetic "files" - && item.source.filename(self.sess()).is_real() + && item.span.filename(self.sess()).is_real() // skip non-local files - && item.source.cnum(self.sess()) == LOCAL_CRATE + && item.span.cnum(self.sess()) == LOCAL_CRATE { - let filename = item.source.filename(self.sess()); + let filename = item.span.filename(self.sess()); // If it turns out that we couldn't read this file, then we probably // can't read any of the files (generating html output from json or // something like that), so just don't include sources for the diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index a65b4ce3a0373..6c90fd7c9eed8 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -858,6 +858,15 @@ body.blur > :not(#help) { font-size: 1.5em; } +/* Black one-pixel outline around emoji shapes */ +.emoji { + text-shadow: + 1px 0 0 black, + -1px 0 0 black, + 0 1px 0 black, + 0 -1px 0 black; +} + .module-item .stab { border-radius: 3px; display: inline-block; @@ -1353,7 +1362,7 @@ h4 > .notable-traits { to prevent an overlay between the "collapse toggle" and the information tooltip. However, it's not needed with smaller screen width because the doc/code block is always put "one line" below. */ - .information:first-child > .tooltip { + .docblock > .information:first-child > .tooltip { margin-top: 16px; } } diff --git a/src/librustdoc/html/static/themes/dark.css b/src/librustdoc/html/static/themes/dark.css index 88ac3252bb4b2..cf2d28bb43feb 100644 --- a/src/librustdoc/html/static/themes/dark.css +++ b/src/librustdoc/html/static/themes/dark.css @@ -220,8 +220,8 @@ a.test-arrow { } .stab.unstable { background: #FFF5D6; border-color: #FFC600; color: #2f2f2f; } -.stab.deprecated { background: #F3DFFF; border-color: #7F0087; color: #2f2f2f; } -.stab.portability { background: #C4ECFF; border-color: #7BA5DB; color: #2f2f2f; } +.stab.deprecated { background: #ffc4c4; border-color: #db7b7b; color: #2f2f2f; } +.stab.portability { background: #F3DFFF; border-color: #b07bdb; color: #2f2f2f; } .stab.portability > code { background: none; } #help > div { diff --git a/src/librustdoc/html/static/themes/light.css b/src/librustdoc/html/static/themes/light.css index 9bc21102aaae6..7bf6793809c90 100644 --- a/src/librustdoc/html/static/themes/light.css +++ b/src/librustdoc/html/static/themes/light.css @@ -218,8 +218,8 @@ a.test-arrow { } .stab.unstable { background: #FFF5D6; border-color: #FFC600; } -.stab.deprecated { background: #F3DFFF; border-color: #7F0087; } -.stab.portability { background: #C4ECFF; border-color: #7BA5DB; } +.stab.deprecated { background: #ffc4c4; border-color: #db7b7b; } +.stab.portability { background: #F3DFFF; border-color: #b07bdb; } .stab.portability > code { background: none; } #help > div { diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 063d8aab1ec3e..073209c2468a0 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -24,7 +24,7 @@ use std::collections::HashSet; impl JsonRenderer<'_> { pub(super) fn convert_item(&self, item: clean::Item) -> Option { let deprecation = item.deprecation(self.tcx); - let clean::Item { source, name, attrs, kind, visibility, def_id } = item; + let clean::Item { span, name, attrs, kind, visibility, def_id } = item; let inner = match *kind { clean::StrippedItem(_) => return None, x => from_clean_item_kind(x, self.tcx, &name), @@ -33,7 +33,7 @@ impl JsonRenderer<'_> { id: from_def_id(def_id), crate_id: def_id.krate.as_u32(), name: name.map(|sym| sym.to_string()), - source: self.convert_span(source), + span: self.convert_span(span), visibility: self.convert_visibility(visibility), docs: attrs.collapsed_doc_value(), links: attrs @@ -503,13 +503,13 @@ impl From for Import { use clean::ImportKind::*; match import.kind { Simple(s) => Import { - span: import.source.path.whole_name(), + source: import.source.path.whole_name(), name: s.to_string(), id: import.source.did.map(from_def_id), glob: false, }, Glob => Import { - span: import.source.path.whole_name(), + source: import.source.path.whole_name(), name: import.source.path.last_name().to_string(), id: import.source.did.map(from_def_id), glob: true, diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index b762fd7e18bd7..c1dbb5dd33a96 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -109,7 +109,7 @@ impl JsonRenderer<'tcx> { .map(Clone::clone), visibility: types::Visibility::Public, inner: types::ItemEnum::Trait(trait_item.clone().into()), - source: None, + span: None, docs: Default::default(), links: Default::default(), attrs: Default::default(), @@ -246,7 +246,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { ) }) .collect(), - format_version: 4, + format_version: 5, }; let mut p = self.out_path.clone(); p.push(output.index.get(&output.root).unwrap().name.clone().unwrap()); diff --git a/src/librustdoc/passes/calculate_doc_coverage.rs b/src/librustdoc/passes/calculate_doc_coverage.rs index 0e975128628ac..a2f8eb3772efd 100644 --- a/src/librustdoc/passes/calculate_doc_coverage.rs +++ b/src/librustdoc/passes/calculate_doc_coverage.rs @@ -212,7 +212,7 @@ impl<'a, 'b> fold::DocFolder for CoverageCalculator<'a, 'b> { return Some(i); } clean::ImplItem(ref impl_) => { - let filename = i.source.filename(self.ctx.sess()); + let filename = i.span.filename(self.ctx.sess()); if let Some(ref tr) = impl_.trait_ { debug!( "impl {:#} for {:#} in {}", @@ -243,7 +243,7 @@ impl<'a, 'b> fold::DocFolder for CoverageCalculator<'a, 'b> { None, ); - let filename = i.source.filename(self.ctx.sess()); + let filename = i.span.filename(self.ctx.sess()); let has_doc_example = tests.found_tests != 0; let hir_id = self.ctx.tcx.hir().local_def_id_to_hir_id(i.def_id.expect_local()); let (level, source) = self.ctx.tcx.lint_level_at_node(MISSING_DOCS, hir_id); diff --git a/src/librustdoc/passes/check_code_block_syntax.rs b/src/librustdoc/passes/check_code_block_syntax.rs index 98886139f3088..f98f524ca4072 100644 --- a/src/librustdoc/passes/check_code_block_syntax.rs +++ b/src/librustdoc/passes/check_code_block_syntax.rs @@ -86,7 +86,7 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> { // We couldn't calculate the span of the markdown block that had the error, so our // diagnostics are going to be a bit lacking. let mut diag = self.cx.sess().struct_span_warn( - super::span_of_attrs(&item.attrs).unwrap_or(item.source.span()), + super::span_of_attrs(&item.attrs).unwrap_or(item.span.inner()), "doc comment contains an invalid Rust code block", ); @@ -110,7 +110,7 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> { impl<'a, 'tcx> DocFolder for SyntaxChecker<'a, 'tcx> { fn fold_item(&mut self, item: clean::Item) -> Option { if let Some(dox) = &item.attrs.collapsed_doc_value() { - let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span()); + let sp = span_of_attrs(&item.attrs).unwrap_or(item.span.inner()); let extra = crate::html::markdown::ExtraInfo::new_did(self.cx.tcx, item.def_id, sp); for code_block in markdown::rust_code_blocks(&dox, &extra) { self.check_rust_syntax(&item, &dox, code_block); diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index ec5994b762b8a..499931f7e9631 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -1226,9 +1226,7 @@ impl LinkCollector<'_, '_> { &ori_link.range, &item.attrs, ) - .unwrap_or_else(|| { - span_of_attrs(&item.attrs).unwrap_or(item.source.span()) - }); + .unwrap_or_else(|| span_of_attrs(&item.attrs).unwrap_or(item.span.inner())); rustc_session::parse::feature_err( &self.cx.tcx.sess.parse_sess, @@ -1693,7 +1691,7 @@ fn report_diagnostic( }; let attrs = &item.attrs; - let sp = span_of_attrs(attrs).unwrap_or(item.source.span()); + let sp = span_of_attrs(attrs).unwrap_or(item.span.inner()); tcx.struct_span_lint_hir(lint, hir_id, sp, |lint| { let mut diag = lint.build(msg); diff --git a/src/librustdoc/passes/doc_test_lints.rs b/src/librustdoc/passes/doc_test_lints.rs index 951258db9e2a2..b36358489900e 100644 --- a/src/librustdoc/passes/doc_test_lints.rs +++ b/src/librustdoc/passes/doc_test_lints.rs @@ -97,7 +97,7 @@ crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) { if tests.found_tests == 0 && cx.tcx.sess.is_nightly_build() { if should_have_doc_example(cx, &item) { debug!("reporting error for {:?} (hir_id={:?})", item, hir_id); - let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span()); + let sp = span_of_attrs(&item.attrs).unwrap_or(item.span.inner()); cx.tcx.struct_span_lint_hir( crate::lint::MISSING_DOC_CODE_EXAMPLES, hir_id, @@ -109,7 +109,7 @@ crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) { cx.tcx.struct_span_lint_hir( crate::lint::PRIVATE_DOC_TESTS, hir_id, - span_of_attrs(&item.attrs).unwrap_or(item.source.span()), + span_of_attrs(&item.attrs).unwrap_or(item.span.inner()), |lint| lint.build("documentation test in private item").emit(), ); } diff --git a/src/librustdoc/passes/html_tags.rs b/src/librustdoc/passes/html_tags.rs index 23364b6fec9d1..881feb0d87a47 100644 --- a/src/librustdoc/passes/html_tags.rs +++ b/src/librustdoc/passes/html_tags.rs @@ -181,7 +181,7 @@ impl<'a, 'tcx> DocFolder for InvalidHtmlTagsLinter<'a, 'tcx> { let sp = match super::source_span_for_markdown_range(tcx, &dox, range, &item.attrs) { Some(sp) => sp, - None => span_of_attrs(&item.attrs).unwrap_or(item.source.span()), + None => span_of_attrs(&item.attrs).unwrap_or(item.span.inner()), }; tcx.struct_span_lint_hir(crate::lint::INVALID_HTML_TAGS, hir_id, sp, |lint| { lint.build(msg).emit() diff --git a/src/librustdoc/passes/non_autolinks.rs b/src/librustdoc/passes/non_autolinks.rs index 16ad940c62717..9761a78577dea 100644 --- a/src/librustdoc/passes/non_autolinks.rs +++ b/src/librustdoc/passes/non_autolinks.rs @@ -72,7 +72,7 @@ impl<'a, 'tcx> DocFolder for NonAutolinksLinter<'a, 'tcx> { let report_diag = |cx: &DocContext<'_>, msg: &str, url: &str, range: Range| { let sp = super::source_span_for_markdown_range(cx.tcx, &dox, &range, &item.attrs) .or_else(|| span_of_attrs(&item.attrs)) - .unwrap_or(item.source.span()); + .unwrap_or(item.span.inner()); cx.tcx.struct_span_lint_hir(crate::lint::NON_AUTOLINKS, hir_id, sp, |lint| { lint.build(msg) .span_suggestion( diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 4e7794fe61064..72a4d9a183011 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -64,7 +64,7 @@ pub struct Item { pub name: Option, /// The source location of this item (absent if it came from a macro expansion or inline /// assembly). - pub source: Option, + pub span: Option, /// By default all documented items are public, but you can tell rustdoc to output private items /// so this field is needed to differentiate. pub visibility: Visibility, @@ -461,7 +461,7 @@ pub struct Impl { #[serde(rename_all = "snake_case")] pub struct Import { /// The full path being imported. - pub span: String, + pub source: String, /// May be different from the last segment of `source` when renaming imports: /// `use source as name;` pub name: String, diff --git a/src/test/incremental/ich_nested_items.rs b/src/test/incremental/ich_nested_items.rs index aabdaa664112f..4f5f6169f36bf 100644 --- a/src/test/incremental/ich_nested_items.rs +++ b/src/test/incremental/ich_nested_items.rs @@ -3,6 +3,7 @@ // revisions: cfail1 cfail2 // build-pass (FIXME(62277): could be check-pass?) +// compile-flags: -Z query-dep-graph #![crate_type = "rlib"] #![feature(rustc_attrs)] diff --git a/src/test/incremental/ich_resolve_results.rs b/src/test/incremental/ich_resolve_results.rs index 19df2972f8942..1fb0f8aa84d11 100644 --- a/src/test/incremental/ich_resolve_results.rs +++ b/src/test/incremental/ich_resolve_results.rs @@ -2,6 +2,7 @@ // `use` to something different. // revisions: rpass1 rpass2 rpass3 +// compile-flags: -Z query-dep-graph #![feature(rustc_attrs)] diff --git a/src/test/incremental/spans_significant_w_panic.rs b/src/test/incremental/spans_significant_w_panic.rs index 2574ef5199c86..37728af95164f 100644 --- a/src/test/incremental/spans_significant_w_panic.rs +++ b/src/test/incremental/spans_significant_w_panic.rs @@ -3,7 +3,7 @@ // revisions:rpass1 rpass2 -// compile-flags: -C overflow-checks=on +// compile-flags: -C overflow-checks=on -Z query-dep-graph #![feature(rustc_attrs)] diff --git a/src/test/rustdoc-gui/check_info_sign_position.goml b/src/test/rustdoc-gui/check_info_sign_position.goml new file mode 100644 index 0000000000000..9aa72a3ad53e7 --- /dev/null +++ b/src/test/rustdoc-gui/check_info_sign_position.goml @@ -0,0 +1,9 @@ +goto: file://|DOC_PATH|/index.html +goto: ./fn.check_list_code_block.html +// If the codeblock is the first element of the docblock, the information tooltip must have +// have some top margin to avoid going over the toggle (the "[+]"). +assert: (".docblock > .information > .compile_fail", { "margin-top": "16px" }) +// Checks that the other codeblocks don't have this top margin. +assert: ("ol > li > .information > .compile_fail", { "margin-top": "0px" }) +assert: ("ol > li > .information > .ignore", { "margin-top": "0px" }) +assert: (".docblock > .information > .ignore", { "margin-top": "0px" }) diff --git a/src/test/rustdoc-gui/lib.rs b/src/test/rustdoc-gui/lib.rs index 15d8dcc6e8444..4c3007e49d93e 100644 --- a/src/test/rustdoc-gui/lib.rs +++ b/src/test/rustdoc-gui/lib.rs @@ -57,16 +57,26 @@ pub trait AnotherOne { fn func3(); } +/// ```compile_fail +/// whatever +/// ``` +/// /// Check for "i" signs in lists! /// /// 1. elem 1 -/// 2.test 1 -/// ```compile_fail -/// fn foo() {} -/// ``` +/// 2. test 1 +/// ```compile_fail +/// fn foo() {} +/// ``` /// 3. elem 3 /// 4. ```ignore (it's a test) /// fn foo() {} /// ``` /// 5. elem 5 +/// +/// Final one: +/// +/// ```ignore (still a test) +/// let x = 12; +/// ``` pub fn check_list_code_block() {} diff --git a/src/test/rustdoc-json/nested.rs b/src/test/rustdoc-json/nested.rs index 5bb66f7f6fd7c..b0e717d8a86ba 100644 --- a/src/test/rustdoc-json/nested.rs +++ b/src/test/rustdoc-json/nested.rs @@ -24,7 +24,7 @@ pub mod l1 { // @has - "$.index[*][?(@.name=='l3')].inner.items[*]" $l4_id pub struct L4; } - // @is nested.json "$.index[*][?(@.inner.span=='l3::L4')].kind" \"import\" - // @is - "$.index[*][?(@.inner.span=='l3::L4')].inner.glob" false + // @is nested.json "$.index[*][?(@.inner.source=='l3::L4')].kind" \"import\" + // @is - "$.index[*][?(@.inner.source=='l3::L4')].inner.glob" false pub use l3::L4; } diff --git a/src/test/rustdoc-json/reexport/rename_public.rs b/src/test/rustdoc-json/reexport/rename_public.rs index 8c2d7200d0c01..2dd438d223058 100644 --- a/src/test/rustdoc-json/reexport/rename_public.rs +++ b/src/test/rustdoc-json/reexport/rename_public.rs @@ -13,5 +13,5 @@ pub mod inner { // @set import_id = - "$.index[*][?(@.inner.name=='NewName')].id" // @!has - "$.index[*][?(@.inner.name=='Public')]" // @has - "$.index[*][?(@.name=='rename_public')].inner.items[*]" $import_id -// @is - "$.index[*][?(@.inner.name=='NewName')].inner.span" \"inner::Public\" +// @is - "$.index[*][?(@.inner.name=='NewName')].inner.source" \"inner::Public\" pub use inner::Public as NewName; diff --git a/src/test/rustdoc-json/reexport/simple_public.rs b/src/test/rustdoc-json/reexport/simple_public.rs index 0c97a2e7b40a2..2e4de301f6f11 100644 --- a/src/test/rustdoc-json/reexport/simple_public.rs +++ b/src/test/rustdoc-json/reexport/simple_public.rs @@ -14,5 +14,5 @@ pub mod inner { // @set import_id = - "$.index[*][?(@.inner.name=='Public')].id" // @has - "$.index[*][?(@.name=='simple_public')].inner.items[*]" $import_id -// @is - "$.index[*][?(@.inner.name=='Public')].inner.span" \"inner::Public\" +// @is - "$.index[*][?(@.inner.name=='Public')].inner.source" \"inner::Public\" pub use inner::Public; diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/issue-78720.rs b/src/test/ui/closures/2229_closure_analysis/migrations/issue-78720.rs new file mode 100644 index 0000000000000..3a6af00254c5a --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/migrations/issue-78720.rs @@ -0,0 +1,10 @@ +// run-pass + +#![warn(disjoint_capture_drop_reorder)] + +fn main() { + if let a = "" { + //~^ WARNING: irrefutable `if let` pattern + drop(|_: ()| drop(a)); + } +} diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/issue-78720.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/issue-78720.stderr new file mode 100644 index 0000000000000..7e5da949cb299 --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/migrations/issue-78720.stderr @@ -0,0 +1,15 @@ +warning: irrefutable `if let` pattern + --> $DIR/issue-78720.rs:6:5 + | +LL | / if let a = "" { +LL | | +LL | | drop(|_: ()| drop(a)); +LL | | } + | |_____^ + | + = note: `#[warn(irrefutable_let_patterns)]` on by default + = note: this pattern will always match, so the `if let` is useless + = help: consider replacing the `if let` with a `let` + +warning: 1 warning emitted + diff --git a/src/test/ui/dep-graph/dep-graph-check-attr.rs b/src/test/ui/dep-graph/dep-graph-check-attr.rs new file mode 100644 index 0000000000000..1026efc1b1dbe --- /dev/null +++ b/src/test/ui/dep-graph/dep-graph-check-attr.rs @@ -0,0 +1,20 @@ +// Test that using rustc_clean/dirty/if_this_changed/then_this_would_need +// are forbidden when `-Z query-dep-graph` is not enabled. + +#![feature(rustc_attrs)] +#![allow(dead_code)] +#![allow(unused_variables)] + +#[rustc_dirty(hir_owner)] //~ ERROR attribute requires -Z query-dep-graph +fn main() {} + +#[rustc_if_this_changed(hir_owner)] //~ ERROR attribute requires -Z query-dep-graph +struct Foo { + f: T, +} + +#[rustc_clean(hir_owner)] //~ ERROR attribute requires -Z query-dep-graph +type TypeAlias = Foo; + +#[rustc_then_this_would_need(variances_of)] //~ ERROR attribute requires -Z query-dep-graph +trait Use {} diff --git a/src/test/ui/dep-graph/dep-graph-check-attr.stderr b/src/test/ui/dep-graph/dep-graph-check-attr.stderr new file mode 100644 index 0000000000000..945a4237c1298 --- /dev/null +++ b/src/test/ui/dep-graph/dep-graph-check-attr.stderr @@ -0,0 +1,26 @@ +error: attribute requires -Z query-dep-graph to be enabled + --> $DIR/dep-graph-check-attr.rs:8:1 + | +LL | #[rustc_dirty(hir_owner)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: attribute requires -Z query-dep-graph to be enabled + --> $DIR/dep-graph-check-attr.rs:11:1 + | +LL | #[rustc_if_this_changed(hir_owner)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: attribute requires -Z query-dep-graph to be enabled + --> $DIR/dep-graph-check-attr.rs:16:1 + | +LL | #[rustc_clean(hir_owner)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: attribute requires -Z query-dep-graph to be enabled + --> $DIR/dep-graph-check-attr.rs:19:1 + | +LL | #[rustc_then_this_would_need(variances_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors + diff --git a/src/test/ui/issues/issue-83048.rs b/src/test/ui/issues/issue-83048.rs new file mode 100644 index 0000000000000..520ae974398b4 --- /dev/null +++ b/src/test/ui/issues/issue-83048.rs @@ -0,0 +1,5 @@ +// compile-flags: -Z unpretty=thir-tree + +pub fn main() { + break; //~ ERROR: `break` outside of a loop [E0268] +} diff --git a/src/test/ui/issues/issue-83048.stderr b/src/test/ui/issues/issue-83048.stderr new file mode 100644 index 0000000000000..62d67d75844a4 --- /dev/null +++ b/src/test/ui/issues/issue-83048.stderr @@ -0,0 +1,9 @@ +error[E0268]: `break` outside of a loop + --> $DIR/issue-83048.rs:4:5 + | +LL | break; + | ^^^^^ cannot `break` outside of a loop + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0268`. diff --git a/src/tools/cargo b/src/tools/cargo index 90691f2bfe9a5..58a9613144372 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 90691f2bfe9a50291a98983b1ed2feab51d5ca55 +Subproject commit 58a961314437258065e23cb6316dfc121d96fb71