Skip to content

Commit

Permalink
Fixed issue with self: &Box<Self>
Browse files Browse the repository at this point in the history
  • Loading branch information
Duddino committed Apr 16, 2020
1 parent ad105ef commit f36f78f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -2260,13 +2260,19 @@ fn fn_sig_suggestion(
.map(|(i, ty)| {
Some(match ty.kind {
ty::Param(_) if assoc.fn_has_self_parameter && i == 0 => "self".to_string(),
ty::Ref(reg, _ref_ty, mutability) => {
ty::Ref(reg, ref_ty, mutability) if i == 0 => {
let reg = match &format!("{}", reg)[..] {
"'_" | "" => String::new(),
reg => format!("{} ", reg),
};
if assoc.fn_has_self_parameter && i == 0 {
format!("&{}{}self", reg, mutability.prefix_str())
if assoc.fn_has_self_parameter {
match ref_ty.kind {
ty::Param(param) if param.name == kw::SelfUpper => {
format!("&{}{}self", reg, mutability.prefix_str())
}

_ => format!("self: {}", ty),
}
} else {
format!("_: {:?}", ty)
}
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/missing/missing-items/auxiliary/m1.rs
Expand Up @@ -5,4 +5,5 @@ pub trait X {
fn method2(self: Box<Self>, s: String) -> Self::Type;
fn method3(other: &Self, s: String) -> Self::Type;
fn method4(&self, other: &Self) -> Self::Type;
fn method5(self: &Box<Self>) -> Self::Type;
}
5 changes: 3 additions & 2 deletions src/test/ui/missing/missing-items/m2.stderr
@@ -1,15 +1,16 @@
error[E0046]: not all trait items implemented, missing: `CONSTANT`, `Type`, `method`, `method2`, `method3`, `method4`
error[E0046]: not all trait items implemented, missing: `CONSTANT`, `Type`, `method`, `method2`, `method3`, `method4`, `method5`
--> $DIR/m2.rs:9:1
|
LL | impl m1::X for X {
| ^^^^^^^^^^^^^^^^ missing `CONSTANT`, `Type`, `method`, `method2`, `method3`, `method4` in implementation
| ^^^^^^^^^^^^^^^^ missing `CONSTANT`, `Type`, `method`, `method2`, `method3`, `method4`, `method5` in implementation
|
= help: implement the missing item: `const CONSTANT: u32 = 42;`
= help: implement the missing item: `type Type = Type;`
= help: implement the missing item: `fn method(&self, _: std::string::String) -> <Self as m1::X>::Type { todo!() }`
= help: implement the missing item: `fn method2(self: std::boxed::Box<Self>, _: std::string::String) -> <Self as m1::X>::Type { todo!() }`
= help: implement the missing item: `fn method3(_: &Self, _: std::string::String) -> <Self as m1::X>::Type { todo!() }`
= help: implement the missing item: `fn method4(&self, _: &Self) -> <Self as m1::X>::Type { todo!() }`
= help: implement the missing item: `fn method5(self: &std::boxed::Box<Self>) -> <Self as m1::X>::Type { todo!() }`

error: aborting due to previous error

Expand Down

0 comments on commit f36f78f

Please sign in to comment.