Skip to content

Commit eee3112

Browse files
committed
Auto merge of #10840 - Alexendoo:from-over-into-expanded-path, r=dswij
from_over_into: Show suggestions for non-Self expanded paths changelog: [`from_over_into`]: Show suggestions when the body contains macros not expanding to `Self` Currently any path in a macro expansion causes the suggestion to be hidden, meaning most macro calls cause it to be hidden Now it's only hidden if the expansion contains `Self`
2 parents 2dd452f + c10876e commit eee3112

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed

clippy_lints/src/from_over_into.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,10 @@ impl<'a, 'tcx> Visitor<'tcx> for SelfFinder<'a, 'tcx> {
134134
kw::SelfUpper => self.upper.push(segment.ident.span),
135135
_ => continue,
136136
}
137+
138+
self.invalid |= segment.ident.span.from_expansion();
137139
}
138140

139-
self.invalid |= path.span.from_expansion();
140141
if !self.invalid {
141142
walk_path(self, path);
142143
}

tests/ui/from_over_into.fixed

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ impl From<String> for A {
6060
}
6161
}
6262

63+
struct PathInExpansion;
64+
65+
impl From<PathInExpansion> for String {
66+
fn from(val: PathInExpansion) -> Self {
67+
// non self/Self paths in expansions are fine
68+
panic!()
69+
}
70+
}
71+
6372
#[clippy::msrv = "1.40"]
6473
fn msrv_1_40() {
6574
struct FromOverInto<T>(Vec<T>);

tests/ui/from_over_into.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ impl From<String> for A {
6060
}
6161
}
6262

63+
struct PathInExpansion;
64+
65+
impl Into<String> for PathInExpansion {
66+
fn into(self) -> String {
67+
// non self/Self paths in expansions are fine
68+
panic!()
69+
}
70+
}
71+
6372
#[clippy::msrv = "1.40"]
6473
fn msrv_1_40() {
6574
struct FromOverInto<T>(Vec<T>);

tests/ui/from_over_into.stderr

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,21 @@ LL ~ val.0
5959
|
6060

6161
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
62-
--> $DIR/from_over_into.rs:78:5
62+
--> $DIR/from_over_into.rs:65:1
63+
|
64+
LL | impl Into<String> for PathInExpansion {
65+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66+
|
67+
= help: `impl From<Local> for Foreign` is allowed by the orphan rules, for more information see
68+
https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence
69+
help: replace the `Into` implementation with `From<PathInExpansion>`
70+
|
71+
LL ~ impl From<PathInExpansion> for String {
72+
LL ~ fn from(val: PathInExpansion) -> Self {
73+
|
74+
75+
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
76+
--> $DIR/from_over_into.rs:87:5
6377
|
6478
LL | impl<T> Into<FromOverInto<T>> for Vec<T> {
6579
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -71,5 +85,5 @@ LL ~ fn from(val: Vec<T>) -> Self {
7185
LL ~ FromOverInto(val)
7286
|
7387

74-
error: aborting due to 5 previous errors
88+
error: aborting due to 6 previous errors
7589

tests/ui/from_over_into_unfixable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
struct InMacro(String);
44

55
macro_rules! in_macro {
6-
($e:ident) => {
7-
$e
6+
() => {
7+
Self::new()
88
};
99
}
1010

1111
impl Into<InMacro> for String {
1212
fn into(self) -> InMacro {
13-
InMacro(in_macro!(self))
13+
InMacro(in_macro!())
1414
}
1515
}
1616

0 commit comments

Comments
 (0)