@@ -542,16 +542,21 @@ class CheckCaptures extends Recheck, SymTransformer:
542542 useInfos += ((tree, cs, curEnv))
543543 end markFree
544544
545- /** If capability `c` refers to a parameter that is not @use declared, report an error.
545+ /** If capability `c` refers to a parameter that is not implicitly or explicitly
546+ * @use declared, report an error.
546547 */
547548 def checkUseDeclared (c : Capability , pos : SrcPos )(using Context ): Unit =
548549 c.paramPathRoot match
549550 case ref : NamedType if ! ref.symbol.isUseParam =>
550551 val what = if ref.isType then " Capture set parameter" else " Local reach capability"
551- val owner = ref.symbol.owner
552+ def mitigation =
553+ if ccConfig.allowUse
554+ then i " \n To allow this, the ${ref.symbol} should be declared with a @use annotation. "
555+ else if ! ref.isType then i " \n You could try to abstract the capabilities referred to by $c in a capset variable. "
556+ else " "
552557 report.error(
553- em """ $what $c leaks into capture scope ${owner.qualString(" of" )}.
554- |To allow this, the ${ref.symbol} should be declared with a @use annotation """ , pos)
558+ em " $what $c leaks into capture scope ${owner.qualString(" of" )}. $mitigation " ,
559+ pos)
555560 case _ =>
556561
557562 /** Include references captured by the called method in the current environment stack */
@@ -1751,7 +1756,7 @@ class CheckCaptures extends Recheck, SymTransformer:
17511756
17521757 override def checkInheritedTraitParameters : Boolean = false
17531758
1754- /** Check that overrides don't change the @use or @consume status of their parameters */
1759+ /** Check that overrides don't change the @use, @consume, or @reserve status of their parameters */
17551760 override def additionalChecks (member : Symbol , other : Symbol )(using Context ): Unit =
17561761 for
17571762 (params1, params2) <- member.rawParamss.lazyZip(other.rawParamss)
0 commit comments