@@ -176,7 +176,7 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: DefId) {
176176 hir:: TraitItemKind :: Method ( ref sig, _) => Some ( sig) ,
177177 _ => None ,
178178 } ;
179- check_bare_self_trait_by_name ( tcx, & trait_item) ;
179+ check_object_unsafe_self_trait_by_name ( tcx, & trait_item) ;
180180 check_associated_item ( tcx, trait_item. hir_id , trait_item. span , method_sig) ;
181181}
182182
@@ -195,7 +195,7 @@ fn could_be_self(trait_name: Ident, ty: &hir::Ty<'_>) -> bool {
195195
196196/// Detect when an object unsafe trait is referring to itself in one of its associated items.
197197/// When this is done, suggest using `Self` instead.
198- fn check_bare_self_trait_by_name ( tcx : TyCtxt < ' _ > , item : & hir:: TraitItem < ' _ > ) {
198+ fn check_object_unsafe_self_trait_by_name ( tcx : TyCtxt < ' _ > , item : & hir:: TraitItem < ' _ > ) {
199199 let ( trait_name, trait_def_id) = match tcx. hir ( ) . get ( tcx. hir ( ) . get_parent_item ( item. hir_id ) ) {
200200 hir:: Node :: Item ( item) => match item. kind {
201201 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<'_>) {
230230 return ;
231231 }
232232 let sugg = trait_should_be_self. iter ( ) . map ( |span| ( * span, "Self" . to_string ( ) ) ) . collect ( ) ;
233- let mut err = tcx. sess . struct_span_err (
234- trait_should_be_self,
235- "associated item referring to unboxed trait object for its own trait" ,
236- ) ;
237- err. span_label ( trait_name. span , "in this trait" ) ;
238- err. multipart_suggestion (
239- "you might have meant to use `Self` to refer to the materialized type" ,
240- sugg,
241- Applicability :: MachineApplicable ,
242- ) ;
243- err. emit ( ) ;
233+ tcx. sess
234+ . struct_span_err (
235+ trait_should_be_self,
236+ "associated item referring to unboxed trait object for its own trait" ,
237+ )
238+ . span_label ( trait_name. span , "in this trait" )
239+ . multipart_suggestion (
240+ "you might have meant to use `Self` to refer to the implementing type" ,
241+ sugg,
242+ Applicability :: MachineApplicable ,
243+ )
244+ . emit ( ) ;
244245 }
245246}
246247
0 commit comments