]> git.lizzy.rs Git - rust.git/commitdiff
review comments
authorEsteban Küber <esteban@kuber.com.ar>
Sat, 25 Jan 2020 22:28:23 +0000 (14:28 -0800)
committerEsteban Küber <esteban@kuber.com.ar>
Sun, 2 Feb 2020 19:52:34 +0000 (11:52 -0800)
src/librustc_typeck/check/wfcheck.rs
src/test/ui/suggestions/object-unsafe-trait-should-use-self.stderr

index faeaedce8d00d211b11b8a4f876a7079291c34af..214e7d066eabc9714f656edd7ce528adb0061f49 100644 (file)
@@ -176,7 +176,7 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: DefId) {
         hir::TraitItemKind::Method(ref sig, _) => Some(sig),
         _ => None,
     };
-    check_bare_self_trait_by_name(tcx, &trait_item);
+    check_object_unsafe_self_trait_by_name(tcx, &trait_item);
     check_associated_item(tcx, trait_item.hir_id, trait_item.span, method_sig);
 }
 
@@ -195,7 +195,7 @@ fn could_be_self(trait_name: Ident, ty: &hir::Ty<'_>) -> bool {
 
 /// Detect when an object unsafe trait is referring to itself in one of its associated items.
 /// When this is done, suggest using `Self` instead.
-fn check_bare_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem<'_>) {
+fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem<'_>) {
     let (trait_name, trait_def_id) = match tcx.hir().get(tcx.hir().get_parent_item(item.hir_id)) {
         hir::Node::Item(item) => match item.kind {
             hir::ItemKind::Trait(..) => (item.ident, tcx.hir().local_def_id(item.hir_id)),
@@ -230,17 +230,18 @@ fn check_bare_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem<'_>) {
             return;
         }
         let sugg = trait_should_be_self.iter().map(|span| (*span, "Self".to_string())).collect();
-        let mut err = tcx.sess.struct_span_err(
-            trait_should_be_self,
-            "associated item referring to unboxed trait object for its own trait",
-        );
-        err.span_label(trait_name.span, "in this trait");
-        err.multipart_suggestion(
-            "you might have meant to use `Self` to refer to the materialized type",
-            sugg,
-            Applicability::MachineApplicable,
-        );
-        err.emit();
+        tcx.sess
+            .struct_span_err(
+                trait_should_be_self,
+                "associated item referring to unboxed trait object for its own trait",
+            )
+            .span_label(trait_name.span, "in this trait")
+            .multipart_suggestion(
+                "you might have meant to use `Self` to refer to the implementing type",
+                sugg,
+                Applicability::MachineApplicable,
+            )
+            .emit();
     }
 }
 
index 70d069d2aa29b66b6968d7a7bdf7b91c41c7955f..f1c1a6bb9728b9ed2d2275e4996372b1521c51c6 100644 (file)
@@ -6,7 +6,7 @@ LL | trait A: Sized {
 LL |     fn f(a: A) -> A;
    |             ^     ^
    |
-help: you might have meant to use `Self` to refer to the materialized type
+help: you might have meant to use `Self` to refer to the implementing type
    |
 LL |     fn f(a: Self) -> Self;
    |             ^^^^     ^^^^
@@ -29,7 +29,7 @@ LL | trait B {
 LL |     fn f(a: B) -> B;
    |             ^     ^
    |
-help: you might have meant to use `Self` to refer to the materialized type
+help: you might have meant to use `Self` to refer to the implementing type
    |
 LL |     fn f(a: Self) -> Self;
    |             ^^^^     ^^^^