Skip to content

Commit f36f78f

Browse files
author
Duddino
committed
Fixed issue with self: &Box<Self>
1 parent ad105ef commit f36f78f

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/librustc_typeck/check/mod.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -2260,13 +2260,19 @@ fn fn_sig_suggestion(
22602260
.map(|(i, ty)| {
22612261
Some(match ty.kind {
22622262
ty::Param(_) if assoc.fn_has_self_parameter && i == 0 => "self".to_string(),
2263-
ty::Ref(reg, _ref_ty, mutability) => {
2263+
ty::Ref(reg, ref_ty, mutability) if i == 0 => {
22642264
let reg = match &format!("{}", reg)[..] {
22652265
"'_" | "" => String::new(),
22662266
reg => format!("{} ", reg),
22672267
};
2268-
if assoc.fn_has_self_parameter && i == 0 {
2269-
format!("&{}{}self", reg, mutability.prefix_str())
2268+
if assoc.fn_has_self_parameter {
2269+
match ref_ty.kind {
2270+
ty::Param(param) if param.name == kw::SelfUpper => {
2271+
format!("&{}{}self", reg, mutability.prefix_str())
2272+
}
2273+
2274+
_ => format!("self: {}", ty),
2275+
}
22702276
} else {
22712277
format!("_: {:?}", ty)
22722278
}

src/test/ui/missing/missing-items/auxiliary/m1.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ pub trait X {
55
fn method2(self: Box<Self>, s: String) -> Self::Type;
66
fn method3(other: &Self, s: String) -> Self::Type;
77
fn method4(&self, other: &Self) -> Self::Type;
8+
fn method5(self: &Box<Self>) -> Self::Type;
89
}

src/test/ui/missing/missing-items/m2.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
error[E0046]: not all trait items implemented, missing: `CONSTANT`, `Type`, `method`, `method2`, `method3`, `method4`
1+
error[E0046]: not all trait items implemented, missing: `CONSTANT`, `Type`, `method`, `method2`, `method3`, `method4`, `method5`
22
--> $DIR/m2.rs:9:1
33
|
44
LL | impl m1::X for X {
5-
| ^^^^^^^^^^^^^^^^ missing `CONSTANT`, `Type`, `method`, `method2`, `method3`, `method4` in implementation
5+
| ^^^^^^^^^^^^^^^^ missing `CONSTANT`, `Type`, `method`, `method2`, `method3`, `method4`, `method5` in implementation
66
|
77
= help: implement the missing item: `const CONSTANT: u32 = 42;`
88
= help: implement the missing item: `type Type = Type;`
99
= help: implement the missing item: `fn method(&self, _: std::string::String) -> <Self as m1::X>::Type { todo!() }`
1010
= help: implement the missing item: `fn method2(self: std::boxed::Box<Self>, _: std::string::String) -> <Self as m1::X>::Type { todo!() }`
1111
= help: implement the missing item: `fn method3(_: &Self, _: std::string::String) -> <Self as m1::X>::Type { todo!() }`
1212
= help: implement the missing item: `fn method4(&self, _: &Self) -> <Self as m1::X>::Type { todo!() }`
13+
= help: implement the missing item: `fn method5(self: &std::boxed::Box<Self>) -> <Self as m1::X>::Type { todo!() }`
1314

1415
error: aborting due to previous error
1516

0 commit comments

Comments
 (0)