diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:11:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:12:43 +0000 |
commit | cf94bdc0742c13e2a0cac864c478b8626b266e1b (patch) | |
tree | 044670aa50cc5e2b4229aa0b6b3df6676730c0a6 /src/tools/clippy/tests/ui/from_over_into.rs | |
parent | Adding debian version 1.65.0+dfsg1-2. (diff) | |
download | rustc-cf94bdc0742c13e2a0cac864c478b8626b266e1b.tar.xz rustc-cf94bdc0742c13e2a0cac864c478b8626b266e1b.zip |
Merging upstream version 1.66.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/tools/clippy/tests/ui/from_over_into.rs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/from_over_into.rs b/src/tools/clippy/tests/ui/from_over_into.rs index 292d0924f..d30f3c3fc 100644 --- a/src/tools/clippy/tests/ui/from_over_into.rs +++ b/src/tools/clippy/tests/ui/from_over_into.rs @@ -1,4 +1,8 @@ +// run-rustfix + +#![feature(custom_inner_attributes)] #![warn(clippy::from_over_into)] +#![allow(unused)] // this should throw an error struct StringWrapper(String); @@ -9,6 +13,44 @@ impl Into<StringWrapper> for String { } } +struct SelfType(String); + +impl Into<SelfType> for String { + fn into(self) -> SelfType { + SelfType(Self::new()) + } +} + +#[derive(Default)] +struct X; + +impl X { + const FOO: &'static str = "a"; +} + +struct SelfKeywords; + +impl Into<SelfKeywords> for X { + fn into(self) -> SelfKeywords { + let _ = Self::default(); + let _ = Self::FOO; + let _: Self = self; + + SelfKeywords + } +} + +struct ExplicitPaths(bool); + +impl core::convert::Into<bool> for crate::ExplicitPaths { + fn into(mut self) -> bool { + let in_closure = || self.0; + + self.0 = false; + self.0 + } +} + // this is fine struct A(String); @@ -18,4 +60,28 @@ impl From<String> for A { } } +fn msrv_1_40() { + #![clippy::msrv = "1.40"] + + struct FromOverInto<T>(Vec<T>); + + impl<T> Into<FromOverInto<T>> for Vec<T> { + fn into(self) -> FromOverInto<T> { + FromOverInto(self) + } + } +} + +fn msrv_1_41() { + #![clippy::msrv = "1.41"] + + struct FromOverInto<T>(Vec<T>); + + impl<T> Into<FromOverInto<T>> for Vec<T> { + fn into(self) -> FromOverInto<T> { + FromOverInto(self) + } + } +} + fn main() {} |