about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2020-01-25 14:28:23 -0800
committerEsteban Küber <esteban@kuber.com.ar>2020-02-02 11:52:34 -0800
commitd137b7ac1173e3bbed6a3d4dfb02c741b64077db (patch)
treea5b7cd6dfbcef1d2734831beb08d3d7b6b03c1a4
parent0eb29d1a441a47ea45970c01332ebe157dba7039 (diff)
downloadrust-d137b7ac1173e3bbed6a3d4dfb02c741b64077db.tar.gz
rust-d137b7ac1173e3bbed6a3d4dfb02c741b64077db.zip
review comments
-rw-r--r--src/librustc_typeck/check/wfcheck.rs27
-rw-r--r--src/test/ui/suggestions/object-unsafe-trait-should-use-self.stderr4
2 files changed, 16 insertions, 15 deletions
diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs
index faeaedce8d0..214e7d066ea 100644
--- a/src/librustc_typeck/check/wfcheck.rs
+++ b/src/librustc_typeck/check/wfcheck.rs
@@ -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();
     }
 }
 
diff --git a/src/test/ui/suggestions/object-unsafe-trait-should-use-self.stderr b/src/test/ui/suggestions/object-unsafe-trait-should-use-self.stderr
index 70d069d2aa2..f1c1a6bb972 100644
--- a/src/test/ui/suggestions/object-unsafe-trait-should-use-self.stderr
+++ b/src/test/ui/suggestions/object-unsafe-trait-should-use-self.stderr
@@ -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;
    |             ^^^^     ^^^^