from_over_into: Show suggestions for non-Self expanded paths

This commit is contained in:
Alex Macleod 2023-05-28 21:50:08 +00:00
parent 8d9e4272d6
commit c10876e6c5
5 changed files with 39 additions and 6 deletions

View File

@ -134,9 +134,10 @@ fn visit_path(&mut self, path: &Path<'tcx>, _id: HirId) {
kw::SelfUpper => self.upper.push(segment.ident.span), kw::SelfUpper => self.upper.push(segment.ident.span),
_ => continue, _ => continue,
} }
self.invalid |= segment.ident.span.from_expansion();
} }
self.invalid |= path.span.from_expansion();
if !self.invalid { if !self.invalid {
walk_path(self, path); walk_path(self, path);
} }

View File

@ -60,6 +60,15 @@ impl From<String> for A {
} }
} }
struct PathInExpansion;
impl From<PathInExpansion> for String {
fn from(val: PathInExpansion) -> Self {
// non self/Self paths in expansions are fine
panic!()
}
}
#[clippy::msrv = "1.40"] #[clippy::msrv = "1.40"]
fn msrv_1_40() { fn msrv_1_40() {
struct FromOverInto<T>(Vec<T>); struct FromOverInto<T>(Vec<T>);

View File

@ -60,6 +60,15 @@ fn from(s: String) -> A {
} }
} }
struct PathInExpansion;
impl Into<String> for PathInExpansion {
fn into(self) -> String {
// non self/Self paths in expansions are fine
panic!()
}
}
#[clippy::msrv = "1.40"] #[clippy::msrv = "1.40"]
fn msrv_1_40() { fn msrv_1_40() {
struct FromOverInto<T>(Vec<T>); struct FromOverInto<T>(Vec<T>);

View File

@ -59,7 +59,21 @@ LL ~ val.0
| |
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
--> $DIR/from_over_into.rs:78:5 --> $DIR/from_over_into.rs:65:1
|
LL | impl Into<String> for PathInExpansion {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `impl From<Local> for Foreign` is allowed by the orphan rules, for more information see
https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence
help: replace the `Into` implementation with `From<PathInExpansion>`
|
LL ~ impl From<PathInExpansion> for String {
LL ~ fn from(val: PathInExpansion) -> Self {
|
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
--> $DIR/from_over_into.rs:87:5
| |
LL | impl<T> Into<FromOverInto<T>> for Vec<T> { LL | impl<T> Into<FromOverInto<T>> for Vec<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -71,5 +85,5 @@ LL ~ fn from(val: Vec<T>) -> Self {
LL ~ FromOverInto(val) LL ~ FromOverInto(val)
| |
error: aborting due to 5 previous errors error: aborting due to 6 previous errors

View File

@ -3,14 +3,14 @@
struct InMacro(String); struct InMacro(String);
macro_rules! in_macro { macro_rules! in_macro {
($e:ident) => { () => {
$e Self::new()
}; };
} }
impl Into<InMacro> for String { impl Into<InMacro> for String {
fn into(self) -> InMacro { fn into(self) -> InMacro {
InMacro(in_macro!(self)) InMacro(in_macro!())
} }
} }