]> git.lizzy.rs Git - rust.git/commitdiff
fixed missing trait method suggests incorrect code (self parameter not named self)
authorDuddino <rezziandrea106@gmail.com>
Thu, 16 Apr 2020 09:28:49 +0000 (11:28 +0200)
committerDuddino <rezziandrea106@gmail.com>
Thu, 16 Apr 2020 11:23:01 +0000 (13:23 +0200)
src/librustc_typeck/check/mod.rs
src/test/ui/missing/missing-items/auxiliary/m1.rs
src/test/ui/missing/missing-items/m2.stderr

index ca6bd21fefd39aa276b4fce028f10376722fcbca..77540ecde6cfe647f7d3e2846ef79f1a2aba0278 100644 (file)
@@ -2251,26 +2251,33 @@ fn fn_sig_suggestion(
     sig: &ty::FnSig<'_>,
     ident: Ident,
     predicates: ty::GenericPredicates<'_>,
+    assoc: &ty::AssocItem,
 ) -> String {
     let args = sig
         .inputs()
         .iter()
-        .map(|ty| {
+        .enumerate()
+        .map(|(i, ty)| {
             Some(match ty.kind {
-                ty::Param(param) if param.name == kw::SelfUpper => "self".to_string(),
-                ty::Ref(reg, ref_ty, mutability) => {
+                ty::Param(_) if assoc.fn_has_self_parameter && i == 0 => "self".to_string(),
+                ty::Ref(reg, _ref_ty, mutability) => {
                     let reg = match &format!("{}", reg)[..] {
                         "'_" | "" => String::new(),
                         reg => format!("{} ", reg),
                     };
-                    match ref_ty.kind {
-                        ty::Param(param) if param.name == kw::SelfUpper => {
-                            format!("&{}{}self", reg, mutability.prefix_str())
-                        }
-                        _ => format!("_: {:?}", ty),
+                    if assoc.fn_has_self_parameter && i == 0 {
+                        format!("&{}{}self", reg, mutability.prefix_str())
+                    }else {
+                        format!("_: {:?}", ty)
+                    }
+                }
+                _ => {
+                    if assoc.fn_has_self_parameter && i == 0 {
+                        format!("self: {:?}", ty)
+                    } else {
+                        format!("_: {:?}", ty)
                     }
                 }
-                _ => format!("_: {:?}", ty),
             })
         })
         .chain(std::iter::once(if sig.c_variadic { Some("...".to_string()) } else { None }))
@@ -2309,6 +2316,7 @@ fn suggestion_signature(assoc: &ty::AssocItem, tcx: TyCtxt<'_>) -> String {
                 tcx.fn_sig(assoc.def_id).skip_binder(),
                 assoc.ident,
                 tcx.predicates_of(assoc.def_id),
+                assoc,
             )
         }
         ty::AssocKind::Type => format!("type {} = Type;", assoc.ident),
index 7705066760c50f31a98b5785af7a5f4ec270762a..177506d917637678cf2de02e0b0494dff27fc0a1 100644 (file)
@@ -2,4 +2,7 @@ pub trait X {
     const CONSTANT: u32;
     type Type;
     fn method(&self, s: String) -> Self::Type;
+    fn method2(self: Box<Self>, s: String) -> Self::Type;
+    fn method3(other: &Self, s: String) -> Self::Type;
+    fn method4(&self, other: &Self) -> Self::Type;
 }
index 094782099f6ed6f1159a3fb2ef2723944016492b..3231836bc88d516d336cac968ef0900ab3a0cca7 100644 (file)
@@ -1,12 +1,15 @@
-error[E0046]: not all trait items implemented, missing: `CONSTANT`, `Type`, `method`
+error[E0046]: not all trait items implemented, missing: `CONSTANT`, `Type`, `method`, `method2`, `method3`, `method4`
   --> $DIR/m2.rs:9:1
    |
 LL | impl m1::X for X {
-   | ^^^^^^^^^^^^^^^^ missing `CONSTANT`, `Type`, `method` in implementation
+   | ^^^^^^^^^^^^^^^^ missing `CONSTANT`, `Type`, `method`, `method2`, `method3`, `method4` 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!() }`
 
 error: aborting due to previous error