From e23b035bbe7d3533d623c8658538249704fb4ab9 Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Sat, 17 Apr 2021 18:08:50 -0700 Subject: [PATCH 01/16] Reduce visual weight of attributes. --- src/librustdoc/html/render/mod.rs | 1 - src/librustdoc/html/static/rustdoc.css | 4 ++++ src/librustdoc/html/static/themes/ayu.css | 3 ++- src/librustdoc/html/static/themes/dark.css | 3 ++- src/librustdoc/html/static/themes/light.css | 3 ++- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index d10b612a73799..dcd2805aceb97 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -989,7 +989,6 @@ fn render_assoc_item( const ALLOWED_ATTRIBUTES: &[Symbol] = &[ sym::export_name, - sym::lang, sym::link_section, sym::must_use, sym::no_mangle, diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 427564cd7794a..570dabbd36105 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -967,6 +967,10 @@ a.test-arrow:hover{ color: inherit; } +.code-attribute { + font-weight: 300; +} + .collapse-toggle { font-weight: 300; position: absolute; diff --git a/src/librustdoc/html/static/themes/ayu.css b/src/librustdoc/html/static/themes/ayu.css index 5f6f3d66e5757..b0a8c41fb08d5 100644 --- a/src/librustdoc/html/static/themes/ayu.css +++ b/src/librustdoc/html/static/themes/ayu.css @@ -329,7 +329,8 @@ a.test-arrow:hover { color: #c5c5c5; } -.toggle-label { +.toggle-label, +.code-attribute { color: #999; } diff --git a/src/librustdoc/html/static/themes/dark.css b/src/librustdoc/html/static/themes/dark.css index 2ce6cf4cc45ca..b702dc4a937f8 100644 --- a/src/librustdoc/html/static/themes/dark.css +++ b/src/librustdoc/html/static/themes/dark.css @@ -274,7 +274,8 @@ a.test-arrow:hover{ background-color: #4e8bca; } -.toggle-label { +.toggle-label, +.code-attribute { color: #999; } diff --git a/src/librustdoc/html/static/themes/light.css b/src/librustdoc/html/static/themes/light.css index 31b3562cfcb06..566ed62a62861 100644 --- a/src/librustdoc/html/static/themes/light.css +++ b/src/librustdoc/html/static/themes/light.css @@ -267,7 +267,8 @@ a.test-arrow:hover{ background-color: #4e8bca; } -.toggle-label { +.toggle-label, +.code-attribute { color: #999; } From 18fbd3692fc441282f738e0fc0a5ee04f16aef53 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 17 Apr 2021 22:34:58 -0700 Subject: [PATCH 02/16] rustdoc: get rid of CURRENT_DEPTH --- src/librustdoc/html/format.rs | 83 ++++++++++++++------------- src/librustdoc/html/render/context.rs | 10 +--- src/librustdoc/html/render/mod.rs | 3 - 3 files changed, 44 insertions(+), 52 deletions(-) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index ca364b9f10365..e39652c6dd5de 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -7,6 +7,7 @@ use std::cell::Cell; use std::fmt; +use std::iter; use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::FxHashSet; @@ -16,12 +17,10 @@ use rustc_span::def_id::{DefId, CRATE_DEF_INDEX}; use rustc_target::spec::abi::Abi; use crate::clean::{self, utils::find_nearest_parent_module, PrimitiveType}; -use crate::formats::cache::Cache; use crate::formats::item_type::ItemType; use crate::html::escape::Escape; use crate::html::render::cache::ExternalLocation; use crate::html::render::Context; -use crate::html::render::CURRENT_DEPTH; crate trait Print { fn print(self, buffer: &mut Buffer); @@ -497,7 +496,7 @@ crate fn href_relative_parts<'a>(fqp: &'a [String], relative_to_fqp: &'a [String if f != r { let dissimilar_part_count = relative_to_fqp.len() - i; let fqp_module = fqp[i..fqp.len()].iter().map(String::as_str); - return std::iter::repeat("..").take(dissimilar_part_count).chain(fqp_module).collect(); + return iter::repeat("..").take(dissimilar_part_count).chain(fqp_module).collect(); } } // e.g. linking to std::sync::atomic from std::sync @@ -506,7 +505,7 @@ crate fn href_relative_parts<'a>(fqp: &'a [String], relative_to_fqp: &'a [String // e.g. linking to std::sync from std::sync::atomic } else if fqp.len() < relative_to_fqp.len() { let dissimilar_part_count = relative_to_fqp.len() - fqp.len(); - std::iter::repeat("..").take(dissimilar_part_count).collect() + iter::repeat("..").take(dissimilar_part_count).collect() // linking to the same module } else { Vec::new() @@ -555,13 +554,14 @@ fn primitive_link( f: &mut fmt::Formatter<'_>, prim: clean::PrimitiveType, name: &str, - m: &Cache, + cx: &Context<'_>, ) -> fmt::Result { + let m = &cx.cache(); let mut needs_termination = false; if !f.alternate() { match m.primitive_locations.get(&prim) { Some(&def_id) if def_id.is_local() => { - let len = CURRENT_DEPTH.with(|s| s.get()); + let len = cx.current.len(); let len = if len == 0 { 0 } else { len - 1 }; write!( f, @@ -572,20 +572,28 @@ fn primitive_link( needs_termination = true; } Some(&def_id) => { + let cname_str; let loc = match m.extern_locations[&def_id.krate] { - (ref cname, _, ExternalLocation::Remote(ref s)) => Some((cname, s.to_string())), + (ref cname, _, ExternalLocation::Remote(ref s)) => { + cname_str = cname.as_str(); + Some(vec![s.trim_end_matches('/'), &cname_str[..]]) + } (ref cname, _, ExternalLocation::Local) => { - let len = CURRENT_DEPTH.with(|s| s.get()); - Some((cname, "../".repeat(len))) + cname_str = cname.as_str(); + Some(if cx.current.first().map(|x| &x[..]) == Some(&cname_str[..]) { + iter::repeat("..").take(cx.current.len() - 1).collect() + } else { + let cname = iter::once(&cname_str[..]); + iter::repeat("..").take(cx.current.len()).chain(cname).collect() + }) } (.., ExternalLocation::Unknown) => None, }; - if let Some((cname, root)) = loc { + if let Some(loc) = loc { write!( f, - "", - root, - cname, + "", + loc.join("/"), prim.to_url_str() )?; needs_termination = true; @@ -660,7 +668,7 @@ fn fmt_type<'cx>( fmt::Display::fmt(&tybounds(param_names, cx), f) } clean::Infer => write!(f, "_"), - clean::Primitive(prim) => primitive_link(f, prim, prim.as_str(), &cx.cache()), + clean::Primitive(prim) => primitive_link(f, prim, prim.as_str(), cx), clean::BareFunction(ref decl) => { if f.alternate() { write!( @@ -679,46 +687,46 @@ fn fmt_type<'cx>( decl.unsafety.print_with_space(), print_abi_with_space(decl.abi) )?; - primitive_link(f, PrimitiveType::Fn, "fn", &cx.cache())?; + primitive_link(f, PrimitiveType::Fn, "fn", cx)?; write!(f, "{}", decl.decl.print(cx)) } } clean::Tuple(ref typs) => { match &typs[..] { - &[] => primitive_link(f, PrimitiveType::Unit, "()", &cx.cache()), + &[] => primitive_link(f, PrimitiveType::Unit, "()", cx), &[ref one] => { - primitive_link(f, PrimitiveType::Tuple, "(", &cx.cache())?; + primitive_link(f, PrimitiveType::Tuple, "(", cx)?; // Carry `f.alternate()` into this display w/o branching manually. fmt::Display::fmt(&one.print(cx), f)?; - primitive_link(f, PrimitiveType::Tuple, ",)", &cx.cache()) + primitive_link(f, PrimitiveType::Tuple, ",)", cx) } many => { - primitive_link(f, PrimitiveType::Tuple, "(", &cx.cache())?; + primitive_link(f, PrimitiveType::Tuple, "(", cx)?; for (i, item) in many.iter().enumerate() { if i != 0 { write!(f, ", ")?; } fmt::Display::fmt(&item.print(cx), f)?; } - primitive_link(f, PrimitiveType::Tuple, ")", &cx.cache()) + primitive_link(f, PrimitiveType::Tuple, ")", cx) } } } clean::Slice(ref t) => { - primitive_link(f, PrimitiveType::Slice, "[", &cx.cache())?; + primitive_link(f, PrimitiveType::Slice, "[", cx)?; fmt::Display::fmt(&t.print(cx), f)?; - primitive_link(f, PrimitiveType::Slice, "]", &cx.cache()) + primitive_link(f, PrimitiveType::Slice, "]", cx) } clean::Array(ref t, ref n) => { - primitive_link(f, PrimitiveType::Array, "[", &cx.cache())?; + primitive_link(f, PrimitiveType::Array, "[", cx)?; fmt::Display::fmt(&t.print(cx), f)?; if f.alternate() { - primitive_link(f, PrimitiveType::Array, &format!("; {}]", n), &cx.cache()) + primitive_link(f, PrimitiveType::Array, &format!("; {}]", n), cx) } else { - primitive_link(f, PrimitiveType::Array, &format!("; {}]", Escape(n)), &cx.cache()) + primitive_link(f, PrimitiveType::Array, &format!("; {}]", Escape(n)), cx) } } - clean::Never => primitive_link(f, PrimitiveType::Never, "!", &cx.cache()), + clean::Never => primitive_link(f, PrimitiveType::Never, "!", cx), clean::RawPointer(m, ref t) => { let m = match m { hir::Mutability::Mut => "mut", @@ -731,24 +739,19 @@ fn fmt_type<'cx>( f, clean::PrimitiveType::RawPointer, &format!("*{} {:#}", m, t.print(cx)), - &cx.cache(), + cx, ) } else { primitive_link( f, clean::PrimitiveType::RawPointer, &format!("*{} {}", m, t.print(cx)), - &cx.cache(), + cx, ) } } _ => { - primitive_link( - f, - clean::PrimitiveType::RawPointer, - &format!("*{} ", m), - &cx.cache(), - )?; + primitive_link(f, clean::PrimitiveType::RawPointer, &format!("*{} ", m), cx)?; fmt::Display::fmt(&t.print(cx), f) } } @@ -770,14 +773,14 @@ fn fmt_type<'cx>( f, PrimitiveType::Slice, &format!("{}{}{}[{:#}]", amp, lt, m, bt.print(cx)), - &cx.cache(), + cx, ) } else { primitive_link( f, PrimitiveType::Slice, &format!("{}{}{}[{}]", amp, lt, m, bt.print(cx)), - &cx.cache(), + cx, ) } } @@ -786,14 +789,14 @@ fn fmt_type<'cx>( f, PrimitiveType::Slice, &format!("{}{}{}[", amp, lt, m), - &cx.cache(), + cx, )?; if f.alternate() { write!(f, "{:#}", bt.print(cx))?; } else { write!(f, "{}", bt.print(cx))?; } - primitive_link(f, PrimitiveType::Slice, "]", &cx.cache()) + primitive_link(f, PrimitiveType::Slice, "]", cx) } } } @@ -807,7 +810,7 @@ fn fmt_type<'cx>( f, PrimitiveType::Reference, &format!("{}{}{}", amp, lt, m), - &cx.cache(), + cx, )?; fmt_type(&ty, f, use_absolute, cx) } @@ -1292,7 +1295,7 @@ impl clean::ImportSource { } let name = self.path.last_name(); if let hir::def::Res::PrimTy(p) = self.path.res { - primitive_link(f, PrimitiveType::from(p), &*name, &cx.cache())?; + primitive_link(f, PrimitiveType::from(p), &*name, cx)?; } else { write!(f, "{}", name)?; } diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index d866cf4f4cf04..05d2001385929 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -16,7 +16,7 @@ use rustc_span::{symbol::sym, Symbol}; use super::cache::{build_index, ExternalLocation}; use super::print_item::{full_path, item_path, print_item}; use super::write_shared::write_shared; -use super::{print_sidebar, settings, AllTypes, NameDoc, StylePath, BASIC_KEYWORDS, CURRENT_DEPTH}; +use super::{print_sidebar, settings, AllTypes, NameDoc, StylePath, BASIC_KEYWORDS}; use crate::clean::{self, AttributesExt}; use crate::config::RenderOptions; @@ -168,12 +168,6 @@ impl<'tcx> Context<'tcx> { } fn render_item(&self, it: &clean::Item, pushname: bool) -> String { - // A little unfortunate that this is done like this, but it sure - // does make formatting *a lot* nicer. - CURRENT_DEPTH.with(|slot| { - slot.set(self.current.len()); - }); - let mut title = if it.is_primitive() || it.is_keyword() { // No need to include the namespace for primitive types and keywords String::new() @@ -482,8 +476,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { cache: Rc::new(cache), }; - CURRENT_DEPTH.with(|s| s.set(0)); - // Write shared runs within a flock; disable thread dispatching of IO temporarily. Rc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(true); write_shared(&cx, &krate, index, &md_opts)?; diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index d10b612a73799..8b5e1aa1817d2 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -35,7 +35,6 @@ mod write_shared; crate use context::*; crate use write_shared::FILES_UNVERSIONED; -use std::cell::Cell; use std::collections::VecDeque; use std::default::Default; use std::fmt; @@ -209,8 +208,6 @@ crate struct StylePath { crate disabled: bool, } -thread_local!(crate static CURRENT_DEPTH: Cell = Cell::new(0)); - fn write_srclink(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer) { if let Some(l) = cx.src_href(item) { write!(buf, "[src]", l) From 4a15bd8eaff4f749113dc49bbcf877e34593726b Mon Sep 17 00:00:00 2001 From: Christiaan Dirkx Date: Fri, 20 Nov 2020 06:14:29 +0100 Subject: [PATCH 03/16] Add and insta-stabilize `std::io::ErrorKind::NotSupported` --- library/std/src/io/error.rs | 5 +++++ library/std/src/sys/unix/l4re.rs | 2 +- library/std/src/sys/unsupported/common.rs | 2 +- library/std/src/sys/unsupported/os.rs | 4 ++-- library/std/src/sys/windows/fs.rs | 2 +- library/std/src/sys/windows/net.rs | 2 +- 6 files changed, 11 insertions(+), 6 deletions(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 97c92aa350696..62727ec465daa 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -180,6 +180,10 @@ pub enum ErrorKind { /// read. #[stable(feature = "read_exact", since = "1.6.0")] UnexpectedEof, + + /// This operation is not supported on this platform. + #[stable(feature = "not_supported_error", since = "1.50.0")] + NotSupported, } impl ErrorKind { @@ -203,6 +207,7 @@ impl ErrorKind { ErrorKind::Interrupted => "operation interrupted", ErrorKind::Other => "other os error", ErrorKind::UnexpectedEof => "unexpected end of file", + ErrorKind::NotSupported => "not supported", } } } diff --git a/library/std/src/sys/unix/l4re.rs b/library/std/src/sys/unix/l4re.rs index d60a4b5591fae..6d2d1c5a84a3b 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_const(io::ErrorKind::Other, &"No networking available on L4Re.")); + return Err(io::Error::new_const(io::ErrorKind::NotSupported, &"No networking available on L4Re.")); }; } diff --git a/library/std/src/sys/unsupported/common.rs b/library/std/src/sys/unsupported/common.rs index 01e4fd3c994d4..9d18b83d563b0 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_const(std_io::ErrorKind::Other, &"operation not supported on this platform") + std_io::Error::new_const(std_io::ErrorKind::NotSupported, &"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 897927e7b79a7..bd94e2d629efb 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_const(io::ErrorKind::Other, &"cannot set env vars on this platform")) + Err(io::Error::new_const(io::ErrorKind::NotSupported, &"cannot set env vars on this platform")) } pub fn unsetenv(_: &OsStr) -> io::Result<()> { - Err(io::Error::new_const(io::ErrorKind::Other, &"cannot unset env vars on this platform")) + Err(io::Error::new_const(io::ErrorKind::NotSupported, &"cannot unset env vars on this platform")) } pub fn temp_dir() -> PathBuf { diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs index c6509db80c05b..ef68405b1033e 100644 --- a/library/std/src/sys/windows/fs.rs +++ b/library/std/src/sys/windows/fs.rs @@ -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_const(io::ErrorKind::Other, &"hard link are not supported on UWP")); + return Err(io::Error::new_const(io::ErrorKind::NotSupported, &"hard link are not supported on UWP")); } pub fn stat(path: &Path) -> io::Result { diff --git a/library/std/src/sys/windows/net.rs b/library/std/src/sys/windows/net.rs index e50adcb28a4b7..f6691ccd3e191 100644 --- a/library/std/src/sys/windows/net.rs +++ b/library/std/src/sys/windows/net.rs @@ -370,7 +370,7 @@ impl Socket { #[cfg(target_vendor = "uwp")] fn set_no_inherit(&self) -> io::Result<()> { - Err(io::Error::new_const(io::ErrorKind::Other, &"Unavailable on UWP")) + Err(io::Error::new_const(io::ErrorKind::NotSupported, &"Unavailable on UWP")) } pub fn shutdown(&self, how: Shutdown) -> io::Result<()> { From 9f589b023fd4e38b6c14b5b174a8e5814c822fb0 Mon Sep 17 00:00:00 2001 From: Christiaan Dirkx Date: Sat, 13 Feb 2021 00:00:54 +0100 Subject: [PATCH 04/16] Update `decode_error_kind` to decode os errors to `NotSupported` --- library/std/src/sys/unix/mod.rs | 1 + library/std/src/sys/vxworks/mod.rs | 1 + library/std/src/sys/wasi/mod.rs | 1 + library/std/src/sys/windows/mod.rs | 1 + 4 files changed, 4 insertions(+) diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs index 44328ffc22e5b..7b99e0fe1f941 100644 --- a/library/std/src/sys/unix/mod.rs +++ b/library/std/src/sys/unix/mod.rs @@ -148,6 +148,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { libc::EINVAL => ErrorKind::InvalidInput, libc::ETIMEDOUT => ErrorKind::TimedOut, libc::EEXIST => ErrorKind::AlreadyExists, + libc::ENOSYS => ErrorKind::NotSupported, // These two constants can have the same value on some systems, // but different values on others, so we can't use a match diff --git a/library/std/src/sys/vxworks/mod.rs b/library/std/src/sys/vxworks/mod.rs index c20edaa1a4778..95e4baf3a6de4 100644 --- a/library/std/src/sys/vxworks/mod.rs +++ b/library/std/src/sys/vxworks/mod.rs @@ -83,6 +83,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { libc::EINVAL => ErrorKind::InvalidInput, libc::ETIMEDOUT => ErrorKind::TimedOut, libc::EEXIST => ErrorKind::AlreadyExists, + libc::ENOSYS => ErrorKind::NotSupported, // These two constants can have the same value on some systems, // but different values on others, so we can't use a match diff --git a/library/std/src/sys/wasi/mod.rs b/library/std/src/sys/wasi/mod.rs index a0a37ef8316a8..c772fc0be69d1 100644 --- a/library/std/src/sys/wasi/mod.rs +++ b/library/std/src/sys/wasi/mod.rs @@ -78,6 +78,7 @@ pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind { wasi::ERRNO_TIMEDOUT => TimedOut, wasi::ERRNO_EXIST => AlreadyExists, wasi::ERRNO_AGAIN => WouldBlock, + wasi::ERRNO_NOSYS => NotSupported, _ => Other, } } diff --git a/library/std/src/sys/windows/mod.rs b/library/std/src/sys/windows/mod.rs index 0353c9811f15f..c8fada3c0c223 100644 --- a/library/std/src/sys/windows/mod.rs +++ b/library/std/src/sys/windows/mod.rs @@ -78,6 +78,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { | c::ERROR_IPSEC_IKE_TIMED_OUT | c::ERROR_RUNLEVEL_SWITCH_TIMEOUT | c::ERROR_RUNLEVEL_SWITCH_AGENT_TIMEOUT => return ErrorKind::TimedOut, + c::ERROR_CALL_NOT_IMPLEMENTED => return ErrorKind::NotSupported, _ => {} } From 86592b9939df4e5534ea37cda6bc0b7f7ca8b70e Mon Sep 17 00:00:00 2001 From: CDirkx Date: Tue, 23 Feb 2021 05:49:37 +0100 Subject: [PATCH 05/16] Bump since to 1.52.0 --- library/std/src/io/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 62727ec465daa..a300e5459a6bb 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -182,7 +182,7 @@ pub enum ErrorKind { UnexpectedEof, /// This operation is not supported on this platform. - #[stable(feature = "not_supported_error", since = "1.50.0")] + #[stable(feature = "not_supported_error", since = "1.52.0")] NotSupported, } From 1b5f117c47dcc1b041c686d4c6016ebf96006f06 Mon Sep 17 00:00:00 2001 From: Christiaan Dirkx Date: Fri, 26 Feb 2021 00:17:36 +0100 Subject: [PATCH 06/16] Use `NotSupported` in more places --- library/std/src/sys/hermit/fd.rs | 9 ++-- library/std/src/sys/hermit/mod.rs | 2 +- library/std/src/sys/hermit/net.rs | 78 +++++++++++++++---------------- library/std/src/sys/sgx/mod.rs | 2 +- library/std/src/sys/unix/fs.rs | 2 +- library/std/src/sys/unix/os.rs | 2 +- 6 files changed, 48 insertions(+), 47 deletions(-) diff --git a/library/std/src/sys/hermit/fd.rs b/library/std/src/sys/hermit/fd.rs index 1c0515a150398..c400f5f2c2e84 100644 --- a/library/std/src/sys/hermit/fd.rs +++ b/library/std/src/sys/hermit/fd.rs @@ -1,9 +1,10 @@ #![unstable(reason = "not public", issue = "none", feature = "fd")] -use crate::io::{self, ErrorKind, Read}; +use crate::io::{self, Read}; use crate::mem; use crate::sys::cvt; use crate::sys::hermit::abi; +use crate::sys::unsupported; use crate::sys_common::AsInner; #[derive(Debug)] @@ -46,7 +47,7 @@ impl FileDesc { self.duplicate_path(&[]) } pub fn duplicate_path(&self, _path: &[u8]) -> io::Result { - Err(io::Error::new_const(ErrorKind::Other, &"duplicate isn't supported")) + unsupported() } pub fn nonblocking(&self) -> io::Result { @@ -54,11 +55,11 @@ impl FileDesc { } pub fn set_cloexec(&self) -> io::Result<()> { - Err(io::Error::new_const(ErrorKind::Other, &"cloexec isn't supported")) + unsupported() } pub fn set_nonblocking(&self, _nonblocking: bool) -> io::Result<()> { - Err(io::Error::new_const(ErrorKind::Other, &"nonblocking isn't supported")) + unsupported() } } diff --git a/library/std/src/sys/hermit/mod.rs b/library/std/src/sys/hermit/mod.rs index 1ecda25c03de5..1fa929e48db0e 100644 --- a/library/std/src/sys/hermit/mod.rs +++ b/library/std/src/sys/hermit/mod.rs @@ -56,7 +56,7 @@ pub fn unsupported() -> crate::io::Result { pub fn unsupported_err() -> crate::io::Error { crate::io::Error::new_const( - crate::io::ErrorKind::Other, + crate::io::ErrorKind::NotSupported, &"operation not supported on HermitCore yet", ) } diff --git a/library/std/src/sys/hermit/net.rs b/library/std/src/sys/hermit/net.rs index 7053487ccfbe0..a9c09b6ceefae 100644 --- a/library/std/src/sys/hermit/net.rs +++ b/library/std/src/sys/hermit/net.rs @@ -166,7 +166,7 @@ impl TcpStream { } pub fn socket_addr(&self) -> io::Result { - Err(io::Error::new_const(ErrorKind::Other, &"socket_addr isn't supported")) + unsupported() } pub fn shutdown(&self, how: Shutdown) -> io::Result<()> { @@ -199,7 +199,7 @@ impl TcpStream { } pub fn take_error(&self) -> io::Result> { - Err(io::Error::new_const(ErrorKind::Other, &"take_error isn't supported")) + unsupported() } pub fn set_nonblocking(&self, mode: bool) -> io::Result<()> { @@ -247,27 +247,27 @@ impl TcpListener { } pub fn set_ttl(&self, _: u32) -> io::Result<()> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn ttl(&self) -> io::Result { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn set_only_v6(&self, _: bool) -> io::Result<()> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn only_v6(&self) -> io::Result { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn take_error(&self) -> io::Result> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn set_nonblocking(&self, _: bool) -> io::Result<()> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } } @@ -281,127 +281,127 @@ pub struct UdpSocket(abi::Handle); impl UdpSocket { pub fn bind(_: io::Result<&SocketAddr>) -> io::Result { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn peer_addr(&self) -> io::Result { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn socket_addr(&self) -> io::Result { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn recv_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn peek_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn send_to(&self, _: &[u8], _: &SocketAddr) -> io::Result { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn duplicate(&self) -> io::Result { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn set_read_timeout(&self, _: Option) -> io::Result<()> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn set_write_timeout(&self, _: Option) -> io::Result<()> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn read_timeout(&self) -> io::Result> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn write_timeout(&self) -> io::Result> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn set_broadcast(&self, _: bool) -> io::Result<()> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn broadcast(&self) -> io::Result { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn set_multicast_loop_v4(&self, _: bool) -> io::Result<()> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn multicast_loop_v4(&self) -> io::Result { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn set_multicast_ttl_v4(&self, _: u32) -> io::Result<()> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn multicast_ttl_v4(&self) -> io::Result { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn set_multicast_loop_v6(&self, _: bool) -> io::Result<()> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn multicast_loop_v6(&self) -> io::Result { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn join_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn join_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn leave_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn leave_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn set_ttl(&self, _: u32) -> io::Result<()> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn ttl(&self) -> io::Result { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn take_error(&self) -> io::Result> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn set_nonblocking(&self, _: bool) -> io::Result<()> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn recv(&self, _: &mut [u8]) -> io::Result { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn peek(&self, _: &mut [u8]) -> io::Result { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn send(&self, _: &[u8]) -> io::Result { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } pub fn connect(&self, _: io::Result<&SocketAddr>) -> io::Result<()> { - Err(io::Error::new_const(ErrorKind::Other, &"not supported")) + unsupported() } } diff --git a/library/std/src/sys/sgx/mod.rs b/library/std/src/sys/sgx/mod.rs index 3cd245f40d967..7636413fefbe2 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_const(ErrorKind::Other, &"operation not supported on SGX yet") + crate::io::Error::new_const(ErrorKind::NotSupported, &"operation not supported on SGX yet") } /// This function is used to implement various functions that doesn't exist, diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index 759565bab73f3..1113c7821b28c 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -366,7 +366,7 @@ impl FileAttr { } Err(io::Error::new_const( - io::ErrorKind::Other, + io::ErrorKind::NotSupported, &"creation time is not available on this platform \ currently", )) diff --git a/library/std/src/sys/unix/os.rs b/library/std/src/sys/unix/os.rs index ce2c4e88c7e5a..216bc3b5d6dcc 100644 --- a/library/std/src/sys/unix/os.rs +++ b/library/std/src/sys/unix/os.rs @@ -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_const(ErrorKind::Other, &"Not yet implemented!")) + Err(io::Error::new_const(ErrorKind::NotSupported, &"Not yet implemented!")) } #[cfg(target_os = "vxworks")] From af0dec279590a44d4542e13913606481084a4e9f Mon Sep 17 00:00:00 2001 From: Christiaan Dirkx Date: Fri, 19 Mar 2021 01:39:20 +0100 Subject: [PATCH 07/16] Rename `NotSupported` to `Unsupported` --- library/std/src/io/error.rs | 10 ++++++---- library/std/src/sys/hermit/mod.rs | 2 +- library/std/src/sys/sgx/mod.rs | 2 +- library/std/src/sys/unix/fs.rs | 2 +- library/std/src/sys/unix/l4re.rs | 5 ++++- library/std/src/sys/unix/mod.rs | 2 +- library/std/src/sys/unix/os.rs | 2 +- library/std/src/sys/unsupported/common.rs | 5 ++++- library/std/src/sys/unsupported/os.rs | 4 ++-- library/std/src/sys/vxworks/mod.rs | 2 +- library/std/src/sys/wasi/mod.rs | 2 +- library/std/src/sys/windows/fs.rs | 5 ++++- library/std/src/sys/windows/mod.rs | 2 +- library/std/src/sys/windows/net.rs | 2 +- 14 files changed, 29 insertions(+), 18 deletions(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index a300e5459a6bb..f9d45b9aafb77 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -181,9 +181,11 @@ pub enum ErrorKind { #[stable(feature = "read_exact", since = "1.6.0")] UnexpectedEof, - /// This operation is not supported on this platform. - #[stable(feature = "not_supported_error", since = "1.52.0")] - NotSupported, + /// This operation is unsupported on this platform. + /// + /// This means that the operation can never succeed. + #[stable(feature = "unsupported_error", since = "1.52.0")] + Unsupported, } impl ErrorKind { @@ -207,7 +209,7 @@ impl ErrorKind { ErrorKind::Interrupted => "operation interrupted", ErrorKind::Other => "other os error", ErrorKind::UnexpectedEof => "unexpected end of file", - ErrorKind::NotSupported => "not supported", + ErrorKind::Unsupported => "unsupported", } } } diff --git a/library/std/src/sys/hermit/mod.rs b/library/std/src/sys/hermit/mod.rs index 1fa929e48db0e..f8c1612d1ca03 100644 --- a/library/std/src/sys/hermit/mod.rs +++ b/library/std/src/sys/hermit/mod.rs @@ -56,7 +56,7 @@ pub fn unsupported() -> crate::io::Result { pub fn unsupported_err() -> crate::io::Error { crate::io::Error::new_const( - crate::io::ErrorKind::NotSupported, + crate::io::ErrorKind::Unsupported, &"operation not supported on HermitCore yet", ) } diff --git a/library/std/src/sys/sgx/mod.rs b/library/std/src/sys/sgx/mod.rs index 7636413fefbe2..da37d1aeb7e74 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_const(ErrorKind::NotSupported, &"operation not supported on SGX yet") + crate::io::Error::new_const(ErrorKind::Unsupported, &"operation not supported on SGX yet") } /// This function is used to implement various functions that doesn't exist, diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index 1113c7821b28c..16a7f727696ec 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -366,7 +366,7 @@ impl FileAttr { } Err(io::Error::new_const( - io::ErrorKind::NotSupported, + io::ErrorKind::Unsupported, &"creation time is not available on this platform \ currently", )) diff --git a/library/std/src/sys/unix/l4re.rs b/library/std/src/sys/unix/l4re.rs index 6d2d1c5a84a3b..3cf637c82285a 100644 --- a/library/std/src/sys/unix/l4re.rs +++ b/library/std/src/sys/unix/l4re.rs @@ -1,6 +1,9 @@ macro_rules! unimpl { () => { - return Err(io::Error::new_const(io::ErrorKind::NotSupported, &"No networking available on L4Re.")); + return Err(io::Error::new_const( + io::ErrorKind::Unsupported, + &"No networking available on L4Re.", + )); }; } diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs index 7b99e0fe1f941..6e44ac19c7b2c 100644 --- a/library/std/src/sys/unix/mod.rs +++ b/library/std/src/sys/unix/mod.rs @@ -148,7 +148,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { libc::EINVAL => ErrorKind::InvalidInput, libc::ETIMEDOUT => ErrorKind::TimedOut, libc::EEXIST => ErrorKind::AlreadyExists, - libc::ENOSYS => ErrorKind::NotSupported, + libc::ENOSYS => ErrorKind::Unsupported, // These two constants can have the same value on some systems, // but different values on others, so we can't use a match diff --git a/library/std/src/sys/unix/os.rs b/library/std/src/sys/unix/os.rs index 216bc3b5d6dcc..98e578c5255c7 100644 --- a/library/std/src/sys/unix/os.rs +++ b/library/std/src/sys/unix/os.rs @@ -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_const(ErrorKind::NotSupported, &"Not yet implemented!")) + Err(io::Error::new_const(ErrorKind::Unsupported, &"Not yet implemented!")) } #[cfg(target_os = "vxworks")] diff --git a/library/std/src/sys/unsupported/common.rs b/library/std/src/sys/unsupported/common.rs index 9d18b83d563b0..64ec50fa9ec00 100644 --- a/library/std/src/sys/unsupported/common.rs +++ b/library/std/src/sys/unsupported/common.rs @@ -18,7 +18,10 @@ pub fn unsupported() -> std_io::Result { } pub fn unsupported_err() -> std_io::Error { - std_io::Error::new_const(std_io::ErrorKind::NotSupported, &"operation not supported on this platform") + std_io::Error::new_const( + std_io::ErrorKind::Unsupported, + &"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 bd94e2d629efb..3754aebf45581 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_const(io::ErrorKind::NotSupported, &"cannot set env vars on this platform")) + Err(io::Error::new_const(io::ErrorKind::Unsupported, &"cannot set env vars on this platform")) } pub fn unsetenv(_: &OsStr) -> io::Result<()> { - Err(io::Error::new_const(io::ErrorKind::NotSupported, &"cannot unset env vars on this platform")) + Err(io::Error::new_const(io::ErrorKind::Unsupported, &"cannot unset env vars on this platform")) } pub fn temp_dir() -> PathBuf { diff --git a/library/std/src/sys/vxworks/mod.rs b/library/std/src/sys/vxworks/mod.rs index 95e4baf3a6de4..12d0147a12981 100644 --- a/library/std/src/sys/vxworks/mod.rs +++ b/library/std/src/sys/vxworks/mod.rs @@ -83,7 +83,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { libc::EINVAL => ErrorKind::InvalidInput, libc::ETIMEDOUT => ErrorKind::TimedOut, libc::EEXIST => ErrorKind::AlreadyExists, - libc::ENOSYS => ErrorKind::NotSupported, + libc::ENOSYS => ErrorKind::Unsupported, // These two constants can have the same value on some systems, // but different values on others, so we can't use a match diff --git a/library/std/src/sys/wasi/mod.rs b/library/std/src/sys/wasi/mod.rs index c772fc0be69d1..b7b640b174fa9 100644 --- a/library/std/src/sys/wasi/mod.rs +++ b/library/std/src/sys/wasi/mod.rs @@ -78,7 +78,7 @@ pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind { wasi::ERRNO_TIMEDOUT => TimedOut, wasi::ERRNO_EXIST => AlreadyExists, wasi::ERRNO_AGAIN => WouldBlock, - wasi::ERRNO_NOSYS => NotSupported, + wasi::ERRNO_NOSYS => Unsupported, _ => Other, } } diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs index ef68405b1033e..8e6bd76f85f06 100644 --- a/library/std/src/sys/windows/fs.rs +++ b/library/std/src/sys/windows/fs.rs @@ -802,7 +802,10 @@ 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_const(io::ErrorKind::NotSupported, &"hard link are not supported on UWP")); + return Err(io::Error::new_const( + io::ErrorKind::Unsupported, + &"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 c8fada3c0c223..973301af2d992 100644 --- a/library/std/src/sys/windows/mod.rs +++ b/library/std/src/sys/windows/mod.rs @@ -78,7 +78,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { | c::ERROR_IPSEC_IKE_TIMED_OUT | c::ERROR_RUNLEVEL_SWITCH_TIMEOUT | c::ERROR_RUNLEVEL_SWITCH_AGENT_TIMEOUT => return ErrorKind::TimedOut, - c::ERROR_CALL_NOT_IMPLEMENTED => return ErrorKind::NotSupported, + c::ERROR_CALL_NOT_IMPLEMENTED => return ErrorKind::Unsupported, _ => {} } diff --git a/library/std/src/sys/windows/net.rs b/library/std/src/sys/windows/net.rs index f6691ccd3e191..ad04afc0b6d8a 100644 --- a/library/std/src/sys/windows/net.rs +++ b/library/std/src/sys/windows/net.rs @@ -370,7 +370,7 @@ impl Socket { #[cfg(target_vendor = "uwp")] fn set_no_inherit(&self) -> io::Result<()> { - Err(io::Error::new_const(io::ErrorKind::NotSupported, &"Unavailable on UWP")) + Err(io::Error::new_const(io::ErrorKind::Unsupported, &"Unavailable on UWP")) } pub fn shutdown(&self, how: Shutdown) -> io::Result<()> { From 0895a693bdaf1472f2c8036abccaa78299ec71cf Mon Sep 17 00:00:00 2001 From: Christiaan Dirkx Date: Fri, 19 Mar 2021 20:48:48 +0100 Subject: [PATCH 08/16] Fix test `metadata_access_times` to also check for `Unsupported` --- library/std/src/fs/tests.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs index 5c969741592e6..ce8d3a56f7af4 100644 --- a/library/std/src/fs/tests.rs +++ b/library/std/src/fs/tests.rs @@ -1329,7 +1329,9 @@ fn metadata_access_times() { match (a.created(), b.created()) { (Ok(t1), Ok(t2)) => assert!(t1 <= t2), (Err(e1), Err(e2)) - if e1.kind() == ErrorKind::Other && e2.kind() == ErrorKind::Other => {} + if e1.kind() == ErrorKind::Other && e2.kind() == ErrorKind::Other + || e1.kind() == ErrorKind::Unsupported + && e2.kind() == ErrorKind::Unsupported => {} (a, b) => { panic!("creation time must be always supported or not supported: {:?} {:?}", a, b,) } From b42e52f2cce4bddaa6baef2010061347790ab420 Mon Sep 17 00:00:00 2001 From: CDirkx Date: Mon, 22 Mar 2021 00:29:17 +0100 Subject: [PATCH 09/16] Bump to 1.53.0 Co-authored-by: Mara Bos --- library/std/src/io/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index f9d45b9aafb77..9bed12bf2ae2b 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -184,7 +184,7 @@ pub enum ErrorKind { /// This operation is unsupported on this platform. /// /// This means that the operation can never succeed. - #[stable(feature = "unsupported_error", since = "1.52.0")] + #[stable(feature = "unsupported_error", since = "1.53.0")] Unsupported, } From 5b5afaefff5bdfc01911b9013318145466abec68 Mon Sep 17 00:00:00 2001 From: Christiaan Dirkx Date: Mon, 29 Mar 2021 12:35:16 +0200 Subject: [PATCH 10/16] Fix clippy test using `ErrorKind` --- src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed | 3 ++- src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs | 1 + src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed index fd754e4c794f6..129d82652d759 100644 --- a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed +++ b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed @@ -77,7 +77,7 @@ fn main() { let error_kind = ErrorKind::NotFound; match error_kind { ErrorKind::NotFound => {}, - ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | _ => {}, + ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | ErrorKind::Unsupported | _ => {}, } match error_kind { ErrorKind::NotFound => {}, @@ -98,6 +98,7 @@ fn main() { ErrorKind::Interrupted => {}, ErrorKind::Other => {}, ErrorKind::UnexpectedEof => {}, + ErrorKind::Unsupported => {}, _ => {}, } } diff --git a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs index 2dbf726d5d072..028ecb63e7e6d 100644 --- a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs +++ b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs @@ -98,6 +98,7 @@ fn main() { ErrorKind::Interrupted => {}, ErrorKind::Other => {}, ErrorKind::UnexpectedEof => {}, + ErrorKind::Unsupported => {}, _ => {}, } } diff --git a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr index a513a62c748d6..fd45cad00d6b5 100644 --- a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr +++ b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr @@ -32,7 +32,7 @@ error: wildcard matches known variants and will also match future added variants --> $DIR/wildcard_enum_match_arm.rs:80:9 | LL | _ => {}, - | ^ help: try this: `ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | _` + | ^ help: try this: `ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | ErrorKind::Unsupported | _` error: aborting due to 5 previous errors From 0c736e92a3575927d693b839f7ab537db7d6f84e Mon Sep 17 00:00:00 2001 From: Tor Hovland Date: Mon, 5 Apr 2021 20:57:49 +0200 Subject: [PATCH 11/16] Add stability tags to ImportItem. --- src/librustdoc/html/render/print_item.rs | 26 ++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 42b795030171b..e2c7a24406458 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -282,11 +282,29 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl } clean::ImportItem(ref import) => { + let (stab, stab_tags) = if let Some(def_id) = import.source.did { + // Just need an item with the correct def_id + let import_item = clean::Item { def_id, ..myitem.clone() }; + let stab = import_item.stability_class(cx.tcx()); + let stab_tags = Some(extra_info_tags(&import_item, item, cx.tcx())); + (stab, stab_tags) + } else { + (None, None) + }; + + let add = if stab.is_some() { " " } else { "" }; + write!( w, - "{}{}", - myitem.visibility.print_with_space(myitem.def_id, cx), - import.print(cx), + "\ + {vis}{imp}\ + {stab_tags}\ + ", + stab = stab.unwrap_or_default(), + add = add, + vis = myitem.visibility.print_with_space(myitem.def_id, cx), + imp = import.print(cx), + stab_tags = stab_tags.unwrap_or_default(), ); } @@ -320,7 +338,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl docs = MarkdownSummaryLine(&doc_value, &myitem.links(cx)).into_string(), class = myitem.type_(), add = add, - stab = stab.unwrap_or_else(String::new), + stab = stab.unwrap_or_default(), unsafety_flag = unsafety_flag, href = item_path(myitem.type_(), &myitem.name.unwrap().as_str()), title = [full_path(cx, myitem), myitem.type_().to_string()] From 41f49aac4e5cdade7e41e89c4ea83c79b00a7dce Mon Sep 17 00:00:00 2001 From: Tor Hovland Date: Thu, 8 Apr 2021 23:03:39 +0200 Subject: [PATCH 12/16] Added a test. --- src/test/rustdoc/issue-83832.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/test/rustdoc/issue-83832.rs diff --git a/src/test/rustdoc/issue-83832.rs b/src/test/rustdoc/issue-83832.rs new file mode 100644 index 0000000000000..93dff7c6ce645 --- /dev/null +++ b/src/test/rustdoc/issue-83832.rs @@ -0,0 +1,21 @@ +#![crate_name = "foo"] + +pub mod io { + #[deprecated(since = "0.1.8", note = "Use bar() instead")] + pub trait Reader {} + pub trait Writer {} +} + +// @has foo/mod1/index.html +pub mod mod1 { + // @has - '//code' 'pub use io::Reader;' + // @has - '//span' 'Deprecated' + pub use io::Reader; +} + +// @has foo/mod2/index.html +pub mod mod2 { + // @has - '//code' 'pub use io::Writer;' + // @!has - '//span' 'Deprecated' + pub use io::Writer; +} From 1e2ab998c378e3c9b532e811a8f93b6a65711f92 Mon Sep 17 00:00:00 2001 From: Tor Hovland Date: Tue, 13 Apr 2021 17:23:27 +0200 Subject: [PATCH 13/16] Give import items their own CSS class. --- src/librustdoc/html/render/print_item.rs | 2 +- src/librustdoc/html/static/rustdoc.css | 6 ++++-- src/librustdoc/html/static/themes/ayu.css | 3 ++- src/librustdoc/html/static/themes/dark.css | 3 ++- src/librustdoc/html/static/themes/light.css | 3 ++- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index e2c7a24406458..c37a21d1adef3 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -296,7 +296,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl write!( w, - "\ + "\ {vis}{imp}\ {stab_tags}\ ", diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 427564cd7794a..776a2b25ed04e 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -868,7 +868,8 @@ body.blur > :not(#help) { 0 -1px 0 black; } -.module-item .stab { +.module-item .stab, +.import-item .stab { border-radius: 3px; display: inline-block; font-size: 80%; @@ -879,7 +880,8 @@ body.blur > :not(#help) { vertical-align: text-bottom; } -.module-item.unstable { +.module-item.unstable, +.import-item.unstable { opacity: 0.65; } diff --git a/src/librustdoc/html/static/themes/ayu.css b/src/librustdoc/html/static/themes/ayu.css index 5f6f3d66e5757..e45f95c2b9990 100644 --- a/src/librustdoc/html/static/themes/ayu.css +++ b/src/librustdoc/html/static/themes/ayu.css @@ -252,7 +252,8 @@ details.rustdoc-toggle > summary::before { color: #929292; } -.module-item .stab { +.module-item .stab, +.import-item .stab { color: #000; } diff --git a/src/librustdoc/html/static/themes/dark.css b/src/librustdoc/html/static/themes/dark.css index 2ce6cf4cc45ca..31ec87d741562 100644 --- a/src/librustdoc/html/static/themes/dark.css +++ b/src/librustdoc/html/static/themes/dark.css @@ -217,7 +217,8 @@ details.rustdoc-toggle > summary::before { box-shadow: 0 0 8px 4px #078dd8; } -.module-item .stab { +.module-item .stab, +.import-item .stab { color: #ddd; } diff --git a/src/librustdoc/html/static/themes/light.css b/src/librustdoc/html/static/themes/light.css index 31b3562cfcb06..e3e19d2ca0139 100644 --- a/src/librustdoc/html/static/themes/light.css +++ b/src/librustdoc/html/static/themes/light.css @@ -215,7 +215,8 @@ details.rustdoc-toggle > summary::before { box-shadow: 0 0 8px #078dd8; } -.module-item .stab { +.module-item .stab, +.import-item .stab { color: #000; } From fca088ae23cd2f3ea261e1d0c04e799a2918bb6f Mon Sep 17 00:00:00 2001 From: Tor Hovland Date: Wed, 14 Apr 2021 20:49:08 +0200 Subject: [PATCH 14/16] Now also displays portability tags. --- src/librustdoc/clean/inline.rs | 1 + src/librustdoc/clean/types.rs | 1 + src/librustdoc/clean/utils.rs | 8 +++---- src/librustdoc/html/render/print_item.rs | 11 ++++++--- src/test/rustdoc/issue-83832.rs | 29 ++++++++++++++++++------ 5 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 277ec91f15ed7..598d6da390a3b 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -477,6 +477,7 @@ fn build_module( }], }, did: None, + attrs: None, }, true, )), diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 2b25c6a26bcc4..75c541a50ed59 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -2081,6 +2081,7 @@ crate enum ImportKind { crate struct ImportSource { crate path: Path, crate did: Option, + crate attrs: Option, } #[derive(Clone, Debug)] diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index c2a971d637513..898a5b0df5db2 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -468,10 +468,10 @@ crate fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId { } crate fn resolve_use_source(cx: &mut DocContext<'_>, path: Path) -> ImportSource { - ImportSource { - did: if path.res.opt_def_id().is_none() { None } else { Some(register_res(cx, path.res)) }, - path, - } + let did = if path.res.opt_def_id().is_none() { None } else { Some(register_res(cx, path.res)) }; + let attrs = did.map(|did| cx.tcx.get_attrs(did).clean(cx)); + + ImportSource { did, path, attrs } } crate fn enter_impl_trait(cx: &mut DocContext<'_>, f: F) -> R diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index c37a21d1adef3..045ff5b4b897b 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -282,9 +282,14 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl } clean::ImportItem(ref import) => { - let (stab, stab_tags) = if let Some(def_id) = import.source.did { - // Just need an item with the correct def_id - let import_item = clean::Item { def_id, ..myitem.clone() }; + let (stab, stab_tags) = if let (Some(def_id), Some(attrs)) = + (import.source.did, import.source.attrs.clone()) + { + let attrs = Box::new(attrs); + + // Just need an item with the correct def_id and attrs + let import_item = clean::Item { def_id, attrs, ..myitem.clone() }; + let stab = import_item.stability_class(cx.tcx()); let stab_tags = Some(extra_info_tags(&import_item, item, cx.tcx())); (stab, stab_tags) diff --git a/src/test/rustdoc/issue-83832.rs b/src/test/rustdoc/issue-83832.rs index 93dff7c6ce645..a00401fbe09f0 100644 --- a/src/test/rustdoc/issue-83832.rs +++ b/src/test/rustdoc/issue-83832.rs @@ -1,21 +1,36 @@ #![crate_name = "foo"] +#![feature(doc_cfg)] -pub mod io { +pub mod tag { #[deprecated(since = "0.1.8", note = "Use bar() instead")] - pub trait Reader {} - pub trait Writer {} + pub trait Deprecated {} + + #[doc(cfg(feature = "sync"))] + pub trait Portability {} + + pub trait Unstable {} } // @has foo/mod1/index.html pub mod mod1 { - // @has - '//code' 'pub use io::Reader;' + // @has - '//code' 'pub use tag::Deprecated;' // @has - '//span' 'Deprecated' - pub use io::Reader; + // @!has - '//span' 'sync' + pub use tag::Deprecated; } // @has foo/mod2/index.html pub mod mod2 { - // @has - '//code' 'pub use io::Writer;' + // @has - '//code' 'pub use tag::Portability;' + // @!has - '//span' 'Deprecated' + // @has - '//span' 'sync' + pub use tag::Portability; +} + +// @has foo/mod3/index.html +pub mod mod3 { + // @has - '//code' 'pub use tag::Unstable;' // @!has - '//span' 'Deprecated' - pub use io::Writer; + // @!has - '//span' 'sync' + pub use tag::Unstable; } From e2a77b3d46e09a263fbba0ad7b964781659e6f40 Mon Sep 17 00:00:00 2001 From: Tor Hovland Date: Wed, 14 Apr 2021 21:41:46 +0200 Subject: [PATCH 15/16] Test Deprecated, Portability, and Unstable. --- ...bility-tags-deprecated-and-portability.rs} | 18 +++++- ...stability-tags-unstable-and-portability.rs | 61 +++++++++++++++++++ 2 files changed, 76 insertions(+), 3 deletions(-) rename src/test/rustdoc/{issue-83832.rs => reexport-stability-tags-deprecated-and-portability.rs} (64%) create mode 100644 src/test/rustdoc/reexport-stability-tags-unstable-and-portability.rs diff --git a/src/test/rustdoc/issue-83832.rs b/src/test/rustdoc/reexport-stability-tags-deprecated-and-portability.rs similarity index 64% rename from src/test/rustdoc/issue-83832.rs rename to src/test/rustdoc/reexport-stability-tags-deprecated-and-portability.rs index a00401fbe09f0..a79d05904e31c 100644 --- a/src/test/rustdoc/issue-83832.rs +++ b/src/test/rustdoc/reexport-stability-tags-deprecated-and-portability.rs @@ -8,7 +8,11 @@ pub mod tag { #[doc(cfg(feature = "sync"))] pub trait Portability {} - pub trait Unstable {} + #[deprecated(since = "0.1.8", note = "Use bar() instead")] + #[doc(cfg(feature = "sync"))] + pub trait Both {} + + pub trait None {} } // @has foo/mod1/index.html @@ -29,8 +33,16 @@ pub mod mod2 { // @has foo/mod3/index.html pub mod mod3 { - // @has - '//code' 'pub use tag::Unstable;' + // @has - '//code' 'pub use tag::Both;' + // @has - '//span' 'Deprecated' + // @has - '//span' 'sync' + pub use tag::Both; +} + +// @has foo/mod4/index.html +pub mod mod4 { + // @has - '//code' 'pub use tag::None;' // @!has - '//span' 'Deprecated' // @!has - '//span' 'sync' - pub use tag::Unstable; + pub use tag::None; } diff --git a/src/test/rustdoc/reexport-stability-tags-unstable-and-portability.rs b/src/test/rustdoc/reexport-stability-tags-unstable-and-portability.rs new file mode 100644 index 0000000000000..ff8a910f59f98 --- /dev/null +++ b/src/test/rustdoc/reexport-stability-tags-unstable-and-portability.rs @@ -0,0 +1,61 @@ +#![crate_name = "foo"] +#![feature(doc_cfg)] +#![feature(staged_api)] +#![stable(feature = "rust1", since = "1.0.0")] + +#[stable(feature = "rust1", since = "1.0.0")] +pub mod tag { + #[unstable(feature = "humans", issue = "none")] + pub trait Unstable {} + + #[stable(feature = "rust1", since = "1.0.0")] + #[doc(cfg(feature = "sync"))] + pub trait Portability {} + + #[unstable(feature = "humans", issue = "none")] + #[doc(cfg(feature = "sync"))] + pub trait Both {} + + #[stable(feature = "rust1", since = "1.0.0")] + pub trait None {} +} + +// @has foo/mod1/index.html +#[stable(feature = "rust1", since = "1.0.0")] +pub mod mod1 { + // @has - '//code' 'pub use tag::Unstable;' + // @has - '//span' 'Experimental' + // @!has - '//span' 'sync' + #[stable(feature = "rust1", since = "1.0.0")] + pub use tag::Unstable; +} + +// @has foo/mod2/index.html +#[stable(feature = "rust1", since = "1.0.0")] +pub mod mod2 { + // @has - '//code' 'pub use tag::Portability;' + // @!has - '//span' 'Experimental' + // @has - '//span' 'sync' + #[stable(feature = "rust1", since = "1.0.0")] + pub use tag::Portability; +} + +// @has foo/mod3/index.html +#[stable(feature = "rust1", since = "1.0.0")] +pub mod mod3 { + // @has - '//code' 'pub use tag::Both;' + // @has - '//span' 'Experimental' + // @has - '//span' 'sync' + #[stable(feature = "rust1", since = "1.0.0")] + pub use tag::Both; +} + +// @has foo/mod4/index.html +#[stable(feature = "rust1", since = "1.0.0")] +pub mod mod4 { + // @has - '//code' 'pub use tag::None;' + // @!has - '//span' 'Experimental' + // @!has - '//span' 'sync' + #[stable(feature = "rust1", since = "1.0.0")] + pub use tag::None; +} From 3ecaf57b2940d733e92a285d5cff8c766d28f2e1 Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Sun, 18 Apr 2021 12:32:10 +0300 Subject: [PATCH 16/16] Slightly change wording and fix typo in vec/mod.rs --- library/alloc/src/vec/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 0dab0358d6e3d..1b78356fde5bc 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2041,7 +2041,7 @@ impl Vec { /// Safety: changing returned .2 (&mut usize) is considered the same as calling `.set_len(_)`. /// - /// This method is used to have unique access to all vec parts at once in `extend_from_within`. + /// This method provides unique access to all vec parts at once in `extend_from_within`. unsafe fn split_at_spare_mut_with_len( &mut self, ) -> (&mut [T], &mut [MaybeUninit], &mut usize) { @@ -2279,7 +2279,7 @@ impl ExtendFromWithinSpec for Vec { iter::zip(to_clone, spare) .map(|(src, dst)| dst.write(src.clone())) // Note: - // - Element was just initialized with `MaybeUninit::write`, so it's ok to increace len + // - Element was just initialized with `MaybeUninit::write`, so it's ok to increase len // - len is increased after each element to prevent leaks (see issue #82533) .for_each(|_| *len += 1); }