Skip to content

Commit 3c873cf

Browse files
committed
More doc
1 parent 6953056 commit 3c873cf

File tree

4 files changed

+56
-18
lines changed

4 files changed

+56
-18
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

+5-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ private sealed trait WarningSettings:
233233
"patterns",
234234
default = List(),
235235
descr =
236-
s"""Configure compiler warnings.
236+
raw"""Configure compiler warnings.
237237
|Syntax: -Wconf:<filters>:<action>,<filters>:<action>,...
238238
|multiple <filters> are combined with &, i.e., <filter>&...&<filter>
239239
|
@@ -254,6 +254,9 @@ private sealed trait WarningSettings:
254254
| - Source location: src=regex
255255
| The regex is evaluated against the full source path.
256256
|
257+
| - Origin of warning: origin=regex
258+
| The regex must match the full name (`package.Class.method`) of the deprecated entity.
259+
|
257260
|In verbose warning mode the compiler prints matching filters for warnings.
258261
|Verbose mode can be enabled globally using `-Wconf:any:verbose`, or locally
259262
|using the @nowarn annotation (example: `@nowarn("v") def test = try 1`).
@@ -273,6 +276,7 @@ private sealed trait WarningSettings:
273276
|Examples:
274277
| - change every warning into an error: -Wconf:any:error
275278
| - silence deprecations: -Wconf:cat=deprecation:s
279+
| - silence a deprecation: -Wconf:origin=java\.lang\.Thread\.getId:s
276280
| - silence warnings in src_managed directory: -Wconf:src=src_managed/.*:s
277281
|
278282
|Note: on the command-line you might need to quote configurations containing `*` or `&`

compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala

+22-17
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import util.{ SourcePosition, NoSourcePosition }
1515
import util.Chars.{ LF, CR, FF, SU }
1616
import scala.annotation.switch
1717

18-
import scala.collection.mutable
18+
import scala.collection.mutable.StringBuilder
1919

2020
trait MessageRendering {
2121
import Highlight.*
@@ -209,22 +209,27 @@ trait MessageRendering {
209209
sb.toString
210210
}
211211

212-
private def appendFilterHelp(dia: Diagnostic, sb: mutable.StringBuilder): Unit =
213-
import dia.*
212+
private def appendFilterHelp(dia: Diagnostic, sb: StringBuilder): Unit =
213+
import dia.msg
214214
val hasId = msg.errorId.errorNumber >= 0
215-
val category = dia match {
216-
case _: UncheckedWarning => "unchecked"
217-
case _: DeprecationWarning => "deprecation"
218-
case _: FeatureWarning => "feature"
219-
case _ => ""
220-
}
221-
if (hasId || category.nonEmpty)
222-
sb.append(EOL).append("Matching filters for @nowarn or -Wconf:")
223-
if (hasId)
224-
sb.append(EOL).append(" - id=E").append(msg.errorId.errorNumber)
225-
sb.append(EOL).append(" - name=").append(msg.errorId.productPrefix.stripSuffix("ID"))
226-
if (category.nonEmpty)
227-
sb.append(EOL).append(" - cat=").append(category)
215+
val (category, origin) = dia match
216+
case _: UncheckedWarning => ("unchecked", "")
217+
case w: DeprecationWarning => ("deprecation", w.origin)
218+
case _: FeatureWarning => ("feature", "")
219+
case _ => ("", "")
220+
var entitled = false
221+
def addHelp(what: String)(value: String): Unit =
222+
if !entitled then
223+
sb.append(EOL).append("Matching filters for @nowarn or -Wconf:")
224+
entitled = true
225+
sb.append(EOL).append(" - ").append(what).append(value)
226+
if hasId then
227+
addHelp("id=E")(msg.errorId.errorNumber.toString)
228+
addHelp("name=")(msg.errorId.productPrefix.stripSuffix("ID"))
229+
if category.nonEmpty then
230+
addHelp("cat=")(category)
231+
if origin.nonEmpty then
232+
addHelp("origin=")(origin)
228233

229234
/** The whole message rendered from `msg` */
230235
def messageAndPos(dia: Diagnostic)(using Context): String = {
@@ -236,7 +241,7 @@ trait MessageRendering {
236241
else 0
237242
given Level = Level(level)
238243
given Offset = Offset(maxLineNumber.toString.length + 2)
239-
val sb = mutable.StringBuilder()
244+
val sb = StringBuilder()
240245
val posString = posStr(pos, msg, diagnosticLevel(dia))
241246
if (posString.nonEmpty) sb.append(posString).append(EOL)
242247
if (pos.exists) {
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- Deprecation Warning: tests/warn/deprecated-origin-verbose.scala:12:18 -----------------------------------------------
2+
12 | class D extends C // warn
3+
| ^
4+
| class C in package p is deprecated since 1.0: Old style
5+
Matching filters for @nowarn or -Wconf:
6+
- cat=deprecation
7+
- origin=p.C
8+
-- Deprecation Warning: tests/warn/deprecated-origin-verbose.scala:13:20 -----------------------------------------------
9+
13 | class Oil extends Crude // warn
10+
| ^^^^^
11+
| class Crude in package p is deprecated since 1.0: Bad style
12+
Matching filters for @nowarn or -Wconf:
13+
- cat=deprecation
14+
- origin=p.Crude
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//> using options -deprecation -Wconf:any:verbose
2+
3+
package p:
4+
@deprecated("Old style", since="1.0")
5+
class C
6+
@deprecated("Bad style", since="1.0")
7+
class Crude
8+
9+
package q:
10+
import annotation.*
11+
import p.*
12+
class D extends C // warn
13+
class Oil extends Crude // warn
14+
@nowarn("""origin=p\.Crude""")
15+
class Language extends Crude // nowarn obvs

0 commit comments

Comments
 (0)