mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-12 06:18:51 +00:00
@@ -58,6 +58,10 @@
|
||||
- The Nim compiler now does not recompile the Nim project via ``nim c -r`` if
|
||||
no dependent Nim file changed. This feature can be overridden by
|
||||
the ``--forceBuild`` command line option.
|
||||
- The Nim compiler now warns about unused module imports. You can use a
|
||||
top level ``{.used.}`` pragma in the module that you want to be importable
|
||||
without producing this warning.
|
||||
|
||||
|
||||
### Compiler changes
|
||||
|
||||
|
||||
@@ -97,3 +97,4 @@ proc initDefines*(symbols: StringTableRef) =
|
||||
|
||||
defineSymbol("nimFixedOwned")
|
||||
defineSymbol("nimHasStyleChecks")
|
||||
defineSymbol("nimHasUsed")
|
||||
|
||||
@@ -50,7 +50,6 @@ proc partialInitModule(result: PSym; graph: ModuleGraph; fileIdx: FileIndex; fil
|
||||
setLen(graph.modules, int(fileIdx) + 1)
|
||||
graph.modules[result.position] = result
|
||||
|
||||
incl(result.flags, sfUsed)
|
||||
initStrTable(result.tab)
|
||||
strTableAdd(result.tab, result) # a module knows itself
|
||||
strTableAdd(packSym.tab, result)
|
||||
|
||||
@@ -49,7 +49,7 @@ const
|
||||
wDeprecated,
|
||||
wFloatChecks, wInfChecks, wNanChecks, wPragma, wEmit, wUnroll,
|
||||
wLinearScanEnd, wPatterns, wTrMacros, wEffects, wNoForward, wReorder, wComputedGoto,
|
||||
wInjectStmt, wDeprecated, wExperimental, wThis}
|
||||
wInjectStmt, wDeprecated, wExperimental, wThis, wUsed}
|
||||
lambdaPragmas* = {FirstCallConv..LastCallConv, wImportc, wExportc, wNodecl,
|
||||
wNoSideEffect, wSideEffect, wNoreturn, wDynlib, wHeader,
|
||||
wDeprecated, wExtern, wThread, wImportCpp, wImportObjC, wAsmNoStackFrame,
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
|
||||
# This module implements the renderer of the standard Nim representation.
|
||||
|
||||
when defined(nimHasUsed):
|
||||
# 'import renderer' is so useful for debugging
|
||||
# that Nim shouldn't produce a warning for that:
|
||||
{.used.}
|
||||
|
||||
import
|
||||
lexer, options, idents, strutils, ast, msgs, lineinfos
|
||||
|
||||
|
||||
@@ -614,7 +614,8 @@ proc myProcess(context: PPassContext, n: PNode): PNode =
|
||||
|
||||
proc reportUnusedModules(c: PContext) =
|
||||
for i in 0..high(c.unusedImports):
|
||||
message(c.config, c.unusedImports[i][1], warnUnusedImportX, c.unusedImports[i][0].name.s)
|
||||
if sfUsed notin c.unusedImports[i][0].flags:
|
||||
message(c.config, c.unusedImports[i][1], warnUnusedImportX, c.unusedImports[i][0].name.s)
|
||||
|
||||
proc myClose(graph: ModuleGraph; context: PPassContext, n: PNode): PNode =
|
||||
var c = PContext(context)
|
||||
|
||||
@@ -6276,6 +6276,17 @@ is particularly useful when the symbol was generated by a macro:
|
||||
implementArithOps(int)
|
||||
echoAdd 3, 5
|
||||
|
||||
``used`` can also be used as a top level statement to mark a module as "used".
|
||||
This prevents the "Unused import" warning:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
# module: debughelper.nim
|
||||
when defined(nimHasUsed):
|
||||
# 'import debughelper' is so useful for debugging
|
||||
# that Nim shouldn't produce a warning for that import,
|
||||
# even if currently unused:
|
||||
{.used.}
|
||||
|
||||
|
||||
experimental pragma
|
||||
|
||||
3
tests/tools/dontmentionme.nim
Normal file
3
tests/tools/dontmentionme.nim
Normal file
@@ -0,0 +1,3 @@
|
||||
{.used.}
|
||||
|
||||
proc nothing* = echo "nothing to see here"
|
||||
@@ -10,7 +10,7 @@ tunused_imports.nim(25, 8) Warning: imported and not used: 'strutils' [UnusedImp
|
||||
|
||||
{.warning: "BEGIN".}
|
||||
|
||||
import net
|
||||
import net, dontmentionme
|
||||
|
||||
echo AF_UNIX
|
||||
|
||||
|
||||
Reference in New Issue
Block a user