@@ -544,15 +544,21 @@ class CheckCaptures extends Recheck, SymTransformer:
544544 useInfos += ((tree, cs, curEnv))
545545 end markFree
546546
547- /** If capability `c` refers to a parameter that is not @use declared, report an error.
547+ /** If capability `c` refers to a parameter that is not implicitly or explicitly
548+ * @use declared, report an error.
548549 */
549550 def checkUseDeclared (c : Capability , pos : SrcPos )(using Context ): Unit =
550551 c.paramPathRoot match
551552 case ref : NamedType if ! ref.symbol.isUseParam =>
552553 val what = if ref.isType then " Capture set parameter" else " Local reach capability"
554+ def mitigation =
555+ if ccConfig.allowUse
556+ then i " \n To allow this, the ${ref.symbol} should be declared with a @use annotation. "
557+ else if ! ref.isType then i " \n You could try to abstract the capabilities referred to by $c in a capset variable. "
558+ else " "
553559 report.error(
554- em """ $what $c leaks into capture scope of ${ownerStr(ref.symbol.owner)}.
555- |To allow this, the ${ref.symbol} should be declared with a @use annotation """ , pos)
560+ em " $what $c leaks into capture scope of ${ownerStr(ref.symbol.owner)}. $mitigation " ,
561+ pos)
556562 case _ =>
557563
558564 /** Include references captured by the called method in the current environment stack */
@@ -1785,7 +1791,7 @@ class CheckCaptures extends Recheck, SymTransformer:
17851791
17861792 override def checkInheritedTraitParameters : Boolean = false
17871793
1788- /** Check that overrides don't change the @use or @consume status of their parameters */
1794+ /** Check that overrides don't change the @use, @consume, or @reserve status of their parameters */
17891795 override def additionalChecks (member : Symbol , other : Symbol )(using Context ): Unit =
17901796 for
17911797 (params1, params2) <- member.rawParamss.lazyZip(other.rawParamss)
0 commit comments