The path from a type to itself is Self

This commit is contained in:
Samuel Tardieu
2026-01-08 18:25:16 +01:00
parent bcf3c08230
commit fcccbf1d0c
4 changed files with 27 additions and 1 deletions
+2
View File
@@ -3256,6 +3256,8 @@ fn maybe_get_relative_path(from: &DefPath, to: &DefPath, max_super: usize) -> St
None
}
})))
} else if go_up_by == 0 && path.is_empty() {
String::from("Self")
} else {
join_path_syms(repeat_n(kw::Super, go_up_by).chain(path))
}
+9
View File
@@ -643,3 +643,12 @@ where
{
maybe.map(|x| visitor(x));
}
trait Issue16360: Sized {
fn method(&self);
fn ice_machine(array: [Self; 1]) {
array.iter().for_each(Self::method);
//~^ redundant_closure_for_method_calls
}
}
+9
View File
@@ -643,3 +643,12 @@ async fn issue13892<'a, T, F>(maybe: Option<&'a T>, visitor: F)
{
maybe.map(|x| visitor(x));
}
trait Issue16360: Sized {
fn method(&self);
fn ice_machine(array: [Self; 1]) {
array.iter().for_each(|item| item.method());
//~^ redundant_closure_for_method_calls
}
}
+7 -1
View File
@@ -256,5 +256,11 @@ error: redundant closure
LL | .map(|n| f(n))
| ^^^^^^^^ help: replace the closure with the function itself: `f`
error: aborting due to 42 previous errors
error: redundant closure
--> tests/ui/eta.rs:651:31
|
LL | array.iter().for_each(|item| item.method());
| ^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `Self::method`
error: aborting due to 43 previous errors