@@ -22,6 +22,8 @@ import dotty.tools.dotc.core.Flags.flagsString
22
22
import dotty .tools .dotc .core .Flags
23
23
import dotty .tools .dotc .core .Names .Name
24
24
import dotty .tools .dotc .transform .MegaPhase .MiniPhase
25
+ import dotty .tools .dotc .core .Annotations
26
+ import dotty .tools .dotc .core .Definitions
25
27
26
28
27
29
@@ -307,20 +309,22 @@ object CheckUnused:
307
309
def registerDef (valOrDef : tpd.ValOrDefDef )(using Context ): Unit =
308
310
// register the annotations for usage
309
311
registerUsedAnnotation(valOrDef.symbol)
310
- if valOrDef.symbol.is(Param ) && ! isSyntheticMainParam(valOrDef.symbol) then
311
- if valOrDef.symbol.isOneOf(GivenOrImplicit ) then
312
- implicitParamInScope += valOrDef
313
- else
314
- explicitParamInScope += valOrDef
315
- else if currScopeType.top == ScopeType .Local then
316
- localDefInScope += valOrDef
317
- else if currScopeType.top == ScopeType .Template && valOrDef.symbol.is(Private , butNot = SelfName ) then
318
- privateDefInScope += valOrDef
312
+ if ! valOrDef.symbol.isUnusedAnnot then
313
+ if valOrDef.symbol.is(Param ) && ! isSyntheticMainParam(valOrDef.symbol) then
314
+ if valOrDef.symbol.isOneOf(GivenOrImplicit ) then
315
+ implicitParamInScope += valOrDef
316
+ else
317
+ explicitParamInScope += valOrDef
318
+ else if currScopeType.top == ScopeType .Local then
319
+ localDefInScope += valOrDef
320
+ else if currScopeType.top == ScopeType .Template && valOrDef.symbol.is(Private , butNot = SelfName ) then
321
+ privateDefInScope += valOrDef
319
322
320
323
/** Register pattern variable */
321
324
def registerPatVar (patvar : tpd.Bind )(using Context ): Unit =
322
325
registerUsedAnnotation(patvar.symbol)
323
- patVarsInScope += patvar
326
+ if ! patvar.symbol.isUnusedAnnot then
327
+ patVarsInScope += patvar
324
328
325
329
/** enter a new scope */
326
330
def pushScope (newScopeType : ScopeType ): Unit =
@@ -478,6 +482,10 @@ object CheckUnused:
478
482
selector.orElse(wildcard) // selector with name or wildcard (or given)
479
483
else
480
484
None
485
+
486
+ /** Annotated with @unused */
487
+ def isUnusedAnnot (using Context ): Boolean =
488
+ sym.annotations.exists(a => a.symbol == ctx.definitions.UnusedAnnot )
481
489
end UnusedData
482
490
483
491
private object UnusedData :
0 commit comments