From 5ef202520f9c4c87dd6218bbfbbf57587e88f8be Mon Sep 17 00:00:00 2001 From: Andrea Nall Date: Mon, 15 Feb 2021 02:27:20 +0000 Subject: [PATCH 1/3] add diagnostic items Add diagnostic items to the following types: OsString (os_string_type) PathBuf (path_buf_type) Owned (to_owned_trait) As well as the to_vec method on slice/[T] --- compiler/rustc_span/src/symbol.rs | 4 ++++ library/alloc/src/borrow.rs | 1 + library/alloc/src/slice.rs | 1 + library/std/src/ffi/os_str.rs | 1 + library/std/src/path.rs | 1 + 5 files changed, 8 insertions(+) diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 1c37a6b2aca18..de6210d1893de 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -796,6 +796,7 @@ symbols! { options, or, or_patterns, + os_string_type, other, out, overlapping_marker_traits, @@ -824,6 +825,7 @@ symbols! { pat2018, pat2021, path, + path_buf_type, pattern_parentheses, phantom_data, pin, @@ -1084,6 +1086,7 @@ symbols! { slice, slice_alloc, slice_patterns, + slice_to_vec_method, slice_u8, slice_u8_alloc, slicing_syntax, @@ -1159,6 +1162,7 @@ symbols! { then_with, thread, thread_local, + to_owned_trait, tool_attributes, tool_lints, trace_macros, diff --git a/library/alloc/src/borrow.rs b/library/alloc/src/borrow.rs index adf996fc78275..2fa349e3a4f41 100644 --- a/library/alloc/src/borrow.rs +++ b/library/alloc/src/borrow.rs @@ -32,6 +32,7 @@ where /// to `T`. The `ToOwned` trait generalizes `Clone` to construct owned data /// from any borrow of a given type. #[stable(feature = "rust1", since = "1.0.0")] +#[cfg_attr(not(test), rustc_diagnostic_item = "to_owned_trait")] pub trait ToOwned { /// The resulting type after obtaining ownership. #[stable(feature = "rust1", since = "1.0.0")] diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index cb015b949305c..f8cc6a4587777 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -442,6 +442,7 @@ impl [T] { /// // Here, `s` and `x` can be modified independently. /// ``` #[rustc_conversion_suggestion] + #[rustc_diagnostic_item = "slice_to_vec_method"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn to_vec(&self) -> Vec diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index c9c8f68cd9cce..c1629d8b8f95e 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -71,6 +71,7 @@ use crate::sys_common::{AsInner, FromInner, IntoInner}; /// [`CStr`]: crate::ffi::CStr /// [conversions]: super#conversions #[derive(Clone)] +#[cfg_attr(not(test), rustc_diagnostic_item = "os_string_type")] #[stable(feature = "rust1", since = "1.0.0")] pub struct OsString { inner: Buf, diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 1889e54933867..66135a719be17 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -1066,6 +1066,7 @@ impl FusedIterator for Ancestors<'_> {} /// /// Which method works best depends on what kind of situation you're in. #[derive(Clone)] +#[cfg_attr(not(test), rustc_diagnostic_item = "path_buf_type")] #[stable(feature = "rust1", since = "1.0.0")] // FIXME: // `PathBuf::as_mut_vec` current implementation relies From c6bb62810ae226b35e0181d8c4efc6d0377d196d Mon Sep 17 00:00:00 2001 From: Andrea Nall Date: Mon, 15 Feb 2021 22:58:03 +0000 Subject: [PATCH 2/3] requested/proposed changes --- compiler/rustc_span/src/symbol.rs | 7 +++---- library/alloc/src/borrow.rs | 2 +- library/alloc/src/slice.rs | 2 +- library/std/src/ffi/os_str.rs | 2 +- library/std/src/path.rs | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index de6210d1893de..83b13e7d93c11 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -169,10 +169,12 @@ symbols! { Option, Ord, Ordering, + OsString, Output, Param, PartialEq, PartialOrd, + PathBuf, Pending, Pin, Poll, @@ -198,6 +200,7 @@ symbols! { StructuralPartialEq, Sync, Target, + ToOwned, Try, Ty, TyCtxt, @@ -796,7 +799,6 @@ symbols! { options, or, or_patterns, - os_string_type, other, out, overlapping_marker_traits, @@ -825,7 +827,6 @@ symbols! { pat2018, pat2021, path, - path_buf_type, pattern_parentheses, phantom_data, pin, @@ -1086,7 +1087,6 @@ symbols! { slice, slice_alloc, slice_patterns, - slice_to_vec_method, slice_u8, slice_u8_alloc, slicing_syntax, @@ -1162,7 +1162,6 @@ symbols! { then_with, thread, thread_local, - to_owned_trait, tool_attributes, tool_lints, trace_macros, diff --git a/library/alloc/src/borrow.rs b/library/alloc/src/borrow.rs index 2fa349e3a4f41..cec322518190e 100644 --- a/library/alloc/src/borrow.rs +++ b/library/alloc/src/borrow.rs @@ -32,7 +32,7 @@ where /// to `T`. The `ToOwned` trait generalizes `Clone` to construct owned data /// from any borrow of a given type. #[stable(feature = "rust1", since = "1.0.0")] -#[cfg_attr(not(test), rustc_diagnostic_item = "to_owned_trait")] +#[cfg_attr(not(test), rustc_diagnostic_item = "ToOwned")] pub trait ToOwned { /// The resulting type after obtaining ownership. #[stable(feature = "rust1", since = "1.0.0")] diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index f8cc6a4587777..839f742f1afa7 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -220,6 +220,7 @@ mod hack { } #[lang = "slice_alloc"] +#[cfg_attr(not(test), rustc_diagnostic_item = "slice")] #[cfg(not(test))] impl [T] { /// Sorts the slice. @@ -442,7 +443,6 @@ impl [T] { /// // Here, `s` and `x` can be modified independently. /// ``` #[rustc_conversion_suggestion] - #[rustc_diagnostic_item = "slice_to_vec_method"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn to_vec(&self) -> Vec diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index c1629d8b8f95e..6af5adf4cd860 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -71,7 +71,7 @@ use crate::sys_common::{AsInner, FromInner, IntoInner}; /// [`CStr`]: crate::ffi::CStr /// [conversions]: super#conversions #[derive(Clone)] -#[cfg_attr(not(test), rustc_diagnostic_item = "os_string_type")] +#[cfg_attr(not(test), rustc_diagnostic_item = "OsString")] #[stable(feature = "rust1", since = "1.0.0")] pub struct OsString { inner: Buf, diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 66135a719be17..759b233c7c138 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -1066,7 +1066,7 @@ impl FusedIterator for Ancestors<'_> {} /// /// Which method works best depends on what kind of situation you're in. #[derive(Clone)] -#[cfg_attr(not(test), rustc_diagnostic_item = "path_buf_type")] +#[cfg_attr(not(test), rustc_diagnostic_item = "PathBuf")] #[stable(feature = "rust1", since = "1.0.0")] // FIXME: // `PathBuf::as_mut_vec` current implementation relies From 67fcaaaa7a9c393926e25db600a9976137425d68 Mon Sep 17 00:00:00 2001 From: Andrea Nall Date: Tue, 16 Feb 2021 02:32:21 +0000 Subject: [PATCH 3/3] a few more diagnostic items --- compiler/rustc_span/src/symbol.rs | 3 +++ library/alloc/src/borrow.rs | 2 +- library/alloc/src/string.rs | 1 + library/std/src/ffi/os_str.rs | 1 + library/std/src/path.rs | 1 + 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 83b13e7d93c11..1137a83bc77da 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -169,11 +169,13 @@ symbols! { Option, Ord, Ordering, + OsStr, OsString, Output, Param, PartialEq, PartialOrd, + Path, PathBuf, Pending, Pin, @@ -201,6 +203,7 @@ symbols! { Sync, Target, ToOwned, + ToString, Try, Ty, TyCtxt, diff --git a/library/alloc/src/borrow.rs b/library/alloc/src/borrow.rs index cec322518190e..bdb2d67347e43 100644 --- a/library/alloc/src/borrow.rs +++ b/library/alloc/src/borrow.rs @@ -31,8 +31,8 @@ where /// implementing the `Clone` trait. But `Clone` works only for going from `&T` /// to `T`. The `ToOwned` trait generalizes `Clone` to construct owned data /// from any borrow of a given type. -#[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "ToOwned")] +#[stable(feature = "rust1", since = "1.0.0")] pub trait ToOwned { /// The resulting type after obtaining ownership. #[stable(feature = "rust1", since = "1.0.0")] diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index 3218b3535c970..00fd1c2908b82 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -2174,6 +2174,7 @@ impl FromStr for String { /// implementation for free. /// /// [`Display`]: fmt::Display +#[cfg_attr(not(test), rustc_diagnostic_item = "ToString")] #[stable(feature = "rust1", since = "1.0.0")] pub trait ToString { /// Converts the given value to a `String`. diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index 6af5adf4cd860..13c8022820bc3 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -90,6 +90,7 @@ pub struct OsString { /// /// [`&str`]: str /// [conversions]: super#conversions +#[cfg_attr(not(test), rustc_diagnostic_item = "OsStr")] #[stable(feature = "rust1", since = "1.0.0")] // FIXME: // `OsStr::from_inner` current implementation relies diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 759b233c7c138..afb28518b727d 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -1720,6 +1720,7 @@ impl AsRef for PathBuf { /// let extension = path.extension(); /// assert_eq!(extension, Some(OsStr::new("txt"))); /// ``` +#[cfg_attr(not(test), rustc_diagnostic_item = "Path")] #[stable(feature = "rust1", since = "1.0.0")] // FIXME: // `Path::new` current implementation relies