Skip to content

Commit 28faa0f

Browse files
authored
Merge pull request #15520 from som-snytt/build/silence-unsafe-usage
2 parents 5a8a61d + 87da3e2 commit 28faa0f

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

compiler/src/dotty/tools/dotc/profile/Profiler.scala

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dotty.tools.dotc.profile
22

3+
import scala.annotation.*
34
import scala.language.unsafeNulls
45

56
import java.io.{FileWriter, PrintWriter}
@@ -123,6 +124,7 @@ private [profile] class RealProfiler(reporter : ProfileReporter)(using Context)
123124
}
124125
private def readHeapUsage() = RealProfiler.memoryMx.getHeapMemoryUsage.getUsed
125126

127+
@nowarn
126128
private def doGC: Unit = {
127129
System.gc()
128130
System.runFinalization()

library/src/scala/runtime/LazyVals.scala

+5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package scala.runtime
22

3+
import scala.annotation.*
4+
35
/**
46
* Helper methods used in thread-safe lazy vals.
57
*/
68
object LazyVals {
9+
@nowarn
710
private[this] val unsafe: sun.misc.Unsafe =
811
classOf[sun.misc.Unsafe].getDeclaredFields.nn.find { field =>
912
field.nn.getType == classOf[sun.misc.Unsafe] && {
@@ -100,13 +103,15 @@ object LazyVals {
100103
}
101104

102105
def getOffset(clz: Class[_], name: String): Long = {
106+
@nowarn
103107
val r = unsafe.objectFieldOffset(clz.getDeclaredField(name))
104108
if (debug)
105109
println(s"getOffset($clz, $name) = $r")
106110
r
107111
}
108112

109113
def getOffsetStatic(field: java.lang.reflect.Field) =
114+
@nowarn
110115
val r = unsafe.objectFieldOffset(field)
111116
if (debug)
112117
println(s"getOffset(${field.getDeclaringClass}, ${field.getName}) = $r")

project/Build.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,10 @@ object Build {
169169
"-feature",
170170
"-deprecation",
171171
"-unchecked",
172-
"-Xfatal-warnings",
172+
//"-Wconf:cat=deprecation&msg=Unsafe:s", // example usage
173+
"-Xfatal-warnings", // -Werror in modern usage
173174
"-encoding", "UTF8",
174-
"-language:implicitConversions"
175+
"-language:implicitConversions",
175176
),
176177

177178
(Compile / compile / javacOptions) ++= Seq("-Xlint:unchecked", "-Xlint:deprecation"),

0 commit comments

Comments
 (0)