diff options
| author | mejrs <59372212+mejrs@users.noreply.github.com> | 2025-05-17 12:50:37 +0200 |
|---|---|---|
| committer | mejrs <59372212+mejrs@users.noreply.github.com> | 2025-05-17 12:50:37 +0200 |
| commit | c9b6ccc11ce82c753702716f57f786acf322e64f (patch) | |
| tree | 4fb04c0d00754ab0b9c8974ecc7783d08f76abde | |
| parent | c4e05e53d19b550a358ee8b2e29ecd5a11075800 (diff) | |
| download | rust-c9b6ccc11ce82c753702716f57f786acf322e64f.tar.gz rust-c9b6ccc11ce82c753702716f57f786acf322e64f.zip | |
Switch library rustc_unimplemented to use `Self` and `This`
| -rw-r--r-- | library/core/src/convert/mod.rs | 2 | ||||
| -rw-r--r-- | library/core/src/fmt/mod.rs | 10 | ||||
| -rw-r--r-- | library/core/src/iter/traits/collect.rs | 33 | ||||
| -rw-r--r-- | library/core/src/iter/traits/iterator.rs | 4 | ||||
| -rw-r--r-- | library/core/src/marker.rs | 50 | ||||
| -rw-r--r-- | library/core/src/ops/arith.rs | 4 | ||||
| -rw-r--r-- | library/core/src/ops/function.rs | 6 | ||||
| -rw-r--r-- | library/core/src/ops/index.rs | 6 | ||||
| -rw-r--r-- | library/core/src/ops/try_trait.rs | 18 | ||||
| -rw-r--r-- | library/core/src/slice/index.rs | 2 | ||||
| -rw-r--r-- | library/std/src/process.rs | 2 |
11 files changed, 67 insertions, 70 deletions
diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs index e1b10e1074d..aeafc1be359 100644 --- a/library/core/src/convert/mod.rs +++ b/library/core/src/convert/mod.rs @@ -575,7 +575,7 @@ pub trait Into<T>: Sized { #[rustc_diagnostic_item = "From"] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_on_unimplemented(on( - all(_Self = "&str", T = "alloc::string::String"), + all(Self = "&str", T = "alloc::string::String"), note = "to coerce a `{T}` into a `{Self}`, use `&*` as a prefix", ))] #[doc(search_unbox)] diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 4f7f8a5b84d..5978cb660f6 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -856,10 +856,10 @@ impl Display for Arguments<'_> { on( crate_local, label = "`{Self}` cannot be formatted using `{{:?}}`", - note = "add `#[derive(Debug)]` to `{Self}` or manually `impl {Debug} for {Self}`" + note = "add `#[derive(Debug)]` to `{Self}` or manually `impl {This} for {Self}`" ), - message = "`{Self}` doesn't implement `{Debug}`", - label = "`{Self}` cannot be formatted using `{{:?}}` because it doesn't implement `{Debug}`" + message = "`{Self}` doesn't implement `{This}`", + label = "`{Self}` cannot be formatted using `{{:?}}` because it doesn't implement `{This}`" )] #[doc(alias = "{:?}")] #[rustc_diagnostic_item = "Debug"] @@ -969,12 +969,12 @@ pub use macros::Debug; /// ``` #[rustc_on_unimplemented( on( - any(_Self = "std::path::Path", _Self = "std::path::PathBuf"), + any(Self = "std::path::Path", Self = "std::path::PathBuf"), label = "`{Self}` cannot be formatted with the default formatter; call `.display()` on it", note = "call `.display()` or `.to_string_lossy()` to safely print paths, \ as they may contain non-Unicode data" ), - message = "`{Self}` doesn't implement `{Display}`", + message = "`{Self}` doesn't implement `{This}`", label = "`{Self}` cannot be formatted with the default formatter", note = "in format strings you may be able to use `{{:?}}` (or {{:#?}} for pretty-print) instead" )] diff --git a/library/core/src/iter/traits/collect.rs b/library/core/src/iter/traits/collect.rs index 97bb21c8a36..3bc9cff8072 100644 --- a/library/core/src/iter/traits/collect.rs +++ b/library/core/src/iter/traits/collect.rs @@ -97,32 +97,32 @@ use super::TrustedLen; #[stable(feature = "rust1", since = "1.0.0")] #[rustc_on_unimplemented( on( - _Self = "&[{A}]", + Self = "&[{A}]", message = "a slice of type `{Self}` cannot be built since we need to store the elements somewhere", label = "try explicitly collecting into a `Vec<{A}>`", ), on( - all(A = "{integer}", any(_Self = "&[{integral}]",)), + all(A = "{integer}", any(Self = "&[{integral}]",)), message = "a slice of type `{Self}` cannot be built since we need to store the elements somewhere", label = "try explicitly collecting into a `Vec<{A}>`", ), on( - _Self = "[{A}]", + Self = "[{A}]", message = "a slice of type `{Self}` cannot be built since `{Self}` has no definite size", label = "try explicitly collecting into a `Vec<{A}>`", ), on( - all(A = "{integer}", any(_Self = "[{integral}]",)), + all(A = "{integer}", any(Self = "[{integral}]",)), message = "a slice of type `{Self}` cannot be built since `{Self}` has no definite size", label = "try explicitly collecting into a `Vec<{A}>`", ), on( - _Self = "[{A}; _]", + Self = "[{A}; _]", message = "an array of type `{Self}` cannot be built directly from an iterator", label = "try collecting into a `Vec<{A}>`, then using `.try_into()`", ), on( - all(A = "{integer}", any(_Self = "[{integral}; _]",)), + all(A = "{integer}", any(Self = "[{integral}; _]",)), message = "an array of type `{Self}` cannot be built directly from an iterator", label = "try collecting into a `Vec<{A}>`, then using `.try_into()`", ), @@ -239,41 +239,38 @@ pub trait FromIterator<A>: Sized { #[rustc_diagnostic_item = "IntoIterator"] #[rustc_on_unimplemented( on( - _Self = "core::ops::range::RangeTo<Idx>", + Self = "core::ops::range::RangeTo<Idx>", label = "if you meant to iterate until a value, add a starting value", note = "`..end` is a `RangeTo`, which cannot be iterated on; you might have meant to have a \ bounded `Range`: `0..end`" ), on( - _Self = "core::ops::range::RangeToInclusive<Idx>", + Self = "core::ops::range::RangeToInclusive<Idx>", label = "if you meant to iterate until a value (including it), add a starting value", note = "`..=end` is a `RangeToInclusive`, which cannot be iterated on; you might have meant \ to have a bounded `RangeInclusive`: `0..=end`" ), on( - _Self = "[]", + Self = "[]", label = "`{Self}` is not an iterator; try calling `.into_iter()` or `.iter()`" ), - on(_Self = "&[]", label = "`{Self}` is not an iterator; try calling `.iter()`"), + on(Self = "&[]", label = "`{Self}` is not an iterator; try calling `.iter()`"), on( - _Self = "alloc::vec::Vec<T, A>", + Self = "alloc::vec::Vec<T, A>", label = "`{Self}` is not an iterator; try calling `.into_iter()` or `.iter()`" ), + on(Self = "&str", label = "`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`"), on( - _Self = "&str", + Self = "alloc::string::String", label = "`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`" ), on( - _Self = "alloc::string::String", - label = "`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`" - ), - on( - _Self = "{integral}", + Self = "{integral}", note = "if you want to iterate between `start` until a value `end`, use the exclusive range \ syntax `start..end` or the inclusive range syntax `start..=end`" ), on( - _Self = "{float}", + Self = "{float}", note = "if you want to iterate between `start` until a value `end`, use the exclusive range \ syntax `start..end` or the inclusive range syntax `start..=end`" ), diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index d1e71f0e60f..cf85bdb1352 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -22,11 +22,11 @@ fn _assert_is_dyn_compatible(_: &dyn Iterator<Item = ()>) {} #[stable(feature = "rust1", since = "1.0.0")] #[rustc_on_unimplemented( on( - _Self = "core::ops::range::RangeTo<Idx>", + Self = "core::ops::range::RangeTo<Idx>", note = "you might have meant to use a bounded `Range`" ), on( - _Self = "core::ops::range::RangeToInclusive<Idx>", + Self = "core::ops::range::RangeToInclusive<Idx>", note = "you might have meant to use a bounded `RangeInclusive`" ), label = "`{Self}` is not an iterator", diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index f33b8d188d8..700fb0f386e 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -550,72 +550,72 @@ pub trait BikeshedGuaranteedNoDrop {} #[lang = "sync"] #[rustc_on_unimplemented( on( - _Self = "core::cell::once::OnceCell<T>", + Self = "core::cell::once::OnceCell<T>", note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::OnceLock` instead" ), on( - _Self = "core::cell::Cell<u8>", + Self = "core::cell::Cell<u8>", note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicU8` instead", ), on( - _Self = "core::cell::Cell<u16>", + Self = "core::cell::Cell<u16>", note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicU16` instead", ), on( - _Self = "core::cell::Cell<u32>", + Self = "core::cell::Cell<u32>", note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicU32` instead", ), on( - _Self = "core::cell::Cell<u64>", + Self = "core::cell::Cell<u64>", note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicU64` instead", ), on( - _Self = "core::cell::Cell<usize>", + Self = "core::cell::Cell<usize>", note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicUsize` instead", ), on( - _Self = "core::cell::Cell<i8>", + Self = "core::cell::Cell<i8>", note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicI8` instead", ), on( - _Self = "core::cell::Cell<i16>", + Self = "core::cell::Cell<i16>", note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicI16` instead", ), on( - _Self = "core::cell::Cell<i32>", + Self = "core::cell::Cell<i32>", note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicI32` instead", ), on( - _Self = "core::cell::Cell<i64>", + Self = "core::cell::Cell<i64>", note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicI64` instead", ), on( - _Self = "core::cell::Cell<isize>", + Self = "core::cell::Cell<isize>", note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicIsize` instead", ), on( - _Self = "core::cell::Cell<bool>", + Self = "core::cell::Cell<bool>", note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicBool` instead", ), on( all( - _Self = "core::cell::Cell<T>", - not(_Self = "core::cell::Cell<u8>"), - not(_Self = "core::cell::Cell<u16>"), - not(_Self = "core::cell::Cell<u32>"), - not(_Self = "core::cell::Cell<u64>"), - not(_Self = "core::cell::Cell<usize>"), - not(_Self = "core::cell::Cell<i8>"), - not(_Self = "core::cell::Cell<i16>"), - not(_Self = "core::cell::Cell<i32>"), - not(_Self = "core::cell::Cell<i64>"), - not(_Self = "core::cell::Cell<isize>"), - not(_Self = "core::cell::Cell<bool>") + Self = "core::cell::Cell<T>", + not(Self = "core::cell::Cell<u8>"), + not(Self = "core::cell::Cell<u16>"), + not(Self = "core::cell::Cell<u32>"), + not(Self = "core::cell::Cell<u64>"), + not(Self = "core::cell::Cell<usize>"), + not(Self = "core::cell::Cell<i8>"), + not(Self = "core::cell::Cell<i16>"), + not(Self = "core::cell::Cell<i32>"), + not(Self = "core::cell::Cell<i64>"), + not(Self = "core::cell::Cell<isize>"), + not(Self = "core::cell::Cell<bool>") ), note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock`", ), on( - _Self = "core::cell::RefCell<T>", + Self = "core::cell::RefCell<T>", note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` instead", ), message = "`{Self}` cannot be shared between threads safely", diff --git a/library/core/src/ops/arith.rs b/library/core/src/ops/arith.rs index 54d79beca95..098ce4531f0 100644 --- a/library/core/src/ops/arith.rs +++ b/library/core/src/ops/arith.rs @@ -67,8 +67,8 @@ #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_ops", issue = "90080")] #[rustc_on_unimplemented( - on(all(_Self = "{integer}", Rhs = "{float}"), message = "cannot add a float to an integer",), - on(all(_Self = "{float}", Rhs = "{integer}"), message = "cannot add an integer to a float",), + on(all(Self = "{integer}", Rhs = "{float}"), message = "cannot add a float to an integer",), + on(all(Self = "{float}", Rhs = "{integer}"), message = "cannot add an integer to a float",), message = "cannot add `{Rhs}` to `{Self}`", label = "no implementation for `{Self} + {Rhs}`", append_const_msg diff --git a/library/core/src/ops/function.rs b/library/core/src/ops/function.rs index e9014458b48..df48c104410 100644 --- a/library/core/src/ops/function.rs +++ b/library/core/src/ops/function.rs @@ -62,7 +62,7 @@ use crate::marker::Tuple; note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}`" ), on( - _Self = "unsafe fn", + Self = "unsafe fn", note = "unsafe function cannot be called generically without an unsafe block", // SAFETY: tidy is not smart enough to tell that the below unsafe block is a string label = "call the function in a closure: `|| unsafe {{ /* code */ }}`" @@ -149,7 +149,7 @@ pub trait Fn<Args: Tuple>: FnMut<Args> { note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}`" ), on( - _Self = "unsafe fn", + Self = "unsafe fn", note = "unsafe function cannot be called generically without an unsafe block", // SAFETY: tidy is not smart enough to tell that the below unsafe block is a string label = "call the function in a closure: `|| unsafe {{ /* code */ }}`" @@ -228,7 +228,7 @@ pub trait FnMut<Args: Tuple>: FnOnce<Args> { note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}`" ), on( - _Self = "unsafe fn", + Self = "unsafe fn", note = "unsafe function cannot be called generically without an unsafe block", // SAFETY: tidy is not smart enough to tell that the below unsafe block is a string label = "call the function in a closure: `|| unsafe {{ /* code */ }}`" diff --git a/library/core/src/ops/index.rs b/library/core/src/ops/index.rs index 46e19bed43a..8092fa9eb2f 100644 --- a/library/core/src/ops/index.rs +++ b/library/core/src/ops/index.rs @@ -144,17 +144,17 @@ pub trait Index<Idx: ?Sized> { #[lang = "index_mut"] #[rustc_on_unimplemented( on( - _Self = "&str", + Self = "&str", note = "you can use `.chars().nth()` or `.bytes().nth()` see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>" ), on( - _Self = "str", + Self = "str", note = "you can use `.chars().nth()` or `.bytes().nth()` see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>" ), on( - _Self = "alloc::string::String", + Self = "alloc::string::String", note = "you can use `.chars().nth()` or `.bytes().nth()` see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>" ), diff --git a/library/core/src/ops/try_trait.rs b/library/core/src/ops/try_trait.rs index 3ba2957526f..bac8ffb074b 100644 --- a/library/core/src/ops/try_trait.rs +++ b/library/core/src/ops/try_trait.rs @@ -117,12 +117,12 @@ use crate::ops::ControlFlow; on( all(from_desugaring = "TryBlock"), message = "a `try` block must return `Result` or `Option` \ - (or another type that implements `{Try}`)", + (or another type that implements `{This}`)", label = "could not wrap the final value of the block as `{Self}` doesn't implement `Try`", ), on( all(from_desugaring = "QuestionMark"), - message = "the `?` operator can only be applied to values that implement `{Try}`", + message = "the `?` operator can only be applied to values that implement `{This}`", label = "the `?` operator cannot be applied to type `{Self}`" ) )] @@ -226,7 +226,7 @@ pub trait Try: FromResidual { on( all( from_desugaring = "QuestionMark", - _Self = "core::result::Result<T, E>", + Self = "core::result::Result<T, E>", R = "core::option::Option<core::convert::Infallible>", ), message = "the `?` operator can only be used on `Result`s, not `Option`s, \ @@ -237,7 +237,7 @@ pub trait Try: FromResidual { on( all( from_desugaring = "QuestionMark", - _Self = "core::result::Result<T, E>", + Self = "core::result::Result<T, E>", ), // There's a special error message in the trait selection code for // `From` in `?`, so this is not shown for result-in-result errors, @@ -250,7 +250,7 @@ pub trait Try: FromResidual { on( all( from_desugaring = "QuestionMark", - _Self = "core::option::Option<T>", + Self = "core::option::Option<T>", R = "core::result::Result<T, E>", ), message = "the `?` operator can only be used on `Option`s, not `Result`s, \ @@ -261,7 +261,7 @@ pub trait Try: FromResidual { on( all( from_desugaring = "QuestionMark", - _Self = "core::option::Option<T>", + Self = "core::option::Option<T>", ), // `Option`-in-`Option` always works, as there's only one possible // residual, so this can also be phrased strongly. @@ -273,7 +273,7 @@ pub trait Try: FromResidual { on( all( from_desugaring = "QuestionMark", - _Self = "core::ops::control_flow::ControlFlow<B, C>", + Self = "core::ops::control_flow::ControlFlow<B, C>", R = "core::ops::control_flow::ControlFlow<B, C>", ), message = "the `?` operator in {ItemContext} that returns `ControlFlow<B, _>` \ @@ -285,7 +285,7 @@ pub trait Try: FromResidual { on( all( from_desugaring = "QuestionMark", - _Self = "core::ops::control_flow::ControlFlow<B, C>", + Self = "core::ops::control_flow::ControlFlow<B, C>", // `R` is not a `ControlFlow`, as that case was matched previously ), message = "the `?` operator can only be used on `ControlFlow`s \ @@ -297,7 +297,7 @@ pub trait Try: FromResidual { all(from_desugaring = "QuestionMark"), message = "the `?` operator can only be used in {ItemContext} \ that returns `Result` or `Option` \ - (or another type that implements `{FromResidual}`)", + (or another type that implements `{This}`)", label = "cannot use the `?` operator in {ItemContext} that returns `{Self}`", parent_label = "this function should return `Result` or `Option` to accept `?`" ), diff --git a/library/core/src/slice/index.rs b/library/core/src/slice/index.rs index aafa19c0dd3..409bad9f061 100644 --- a/library/core/src/slice/index.rs +++ b/library/core/src/slice/index.rs @@ -161,7 +161,7 @@ mod private_slice_index { #[rustc_on_unimplemented( on(T = "str", label = "string indices are ranges of `usize`",), on( - all(any(T = "str", T = "&str", T = "alloc::string::String"), _Self = "{integer}"), + all(any(T = "str", T = "&str", T = "alloc::string::String"), Self = "{integer}"), note = "you can use `.chars().nth()` or `.bytes().nth()`\n\ for more information, see chapter 8 in The Book: \ <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>" diff --git a/library/std/src/process.rs b/library/std/src/process.rs index df6b9a6e563..359e2082072 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -2532,7 +2532,7 @@ pub fn id() -> u32 { #[rustc_on_unimplemented(on( cause = "MainFunctionType", message = "`main` has invalid return type `{Self}`", - label = "`main` can only return types that implement `{Termination}`" + label = "`main` can only return types that implement `{This}`" ))] pub trait Termination { /// Is called to get the representation of the value as status code. |
