@@ -1021,12 +1021,14 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
1021
1021
} ,
1022
1022
) ;
1023
1023
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";
1024
1026
if let Some ( ( fn_kind, span) ) = & self . diag_metadata . current_function {
1025
1027
// The current function has a `self` parameter, but we were unable to resolve
1026
1028
// a reference to `self`. This can only happen if the `self` identifier we
1027
1029
// are resolving came from a different hygiene context.
1028
1030
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}" ) ) ;
1030
1032
} else {
1031
1033
let doesnt = if is_assoc_fn {
1032
1034
let ( span, sugg) = fn_kind
@@ -1068,14 +1070,18 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
1068
1070
}
1069
1071
}
1070
1072
} 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
+ }
1079
1085
}
1080
1086
true
1081
1087
}
0 commit comments