From d137b7ac1173e3bbed6a3d4dfb02c741b64077db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 25 Jan 2020 14:28:23 -0800 Subject: [PATCH] review comments --- src/librustc_typeck/check/wfcheck.rs | 27 ++++++++++--------- ...object-unsafe-trait-should-use-self.stderr | 4 +-- 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; | ^^^^ ^^^^