@@ -1021,12 +1021,14 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
10211021 } ,
10221022 ) ;
10231023 let is_assoc_fn = self . self_type_is_available ( ) ;
1024+ let self_from_macro = "a `self` parameter, but a macro invocation can only \
1025+ access identifiers it receives from parameters";
10241026 if let Some ( ( fn_kind, span) ) = & self . diag_metadata . current_function {
10251027 // The current function has a `self` parameter, but we were unable to resolve
10261028 // a reference to `self`. This can only happen if the `self` identifier we
10271029 // are resolving came from a different hygiene context.
10281030 if fn_kind. decl ( ) . inputs . get ( 0 ) . is_some_and ( |p| p. is_self ( ) ) {
1029- err. span_label ( * span, "this function has a `self` parameter, but a macro invocation can only access identifiers it receives from parameters" ) ;
1031+ err. span_label ( * span, format ! ( "this function has {self_from_macro}" ) ) ;
10301032 } else {
10311033 let doesnt = if is_assoc_fn {
10321034 let ( span, sugg) = fn_kind
@@ -1068,14 +1070,18 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
10681070 }
10691071 }
10701072 } else if let Some ( item_kind) = self . diag_metadata . current_item {
1071- err. span_label (
1072- item_kind. ident . span ,
1073- format ! (
1074- "`self` not allowed in {} {}" ,
1075- item_kind. kind. article( ) ,
1076- item_kind. kind. descr( )
1077- ) ,
1078- ) ;
1073+ if matches ! ( item_kind. kind, ItemKind :: Delegation ( ..) ) {
1074+ err. span_label ( item_kind. span , format ! ( "delegation supports {self_from_macro}" ) ) ;
1075+ } else {
1076+ err. span_label (
1077+ item_kind. ident . span ,
1078+ format ! (
1079+ "`self` not allowed in {} {}" ,
1080+ item_kind. kind. article( ) ,
1081+ item_kind. kind. descr( )
1082+ ) ,
1083+ ) ;
1084+ }
10791085 }
10801086 true
10811087 }
0 commit comments