Warn on unused imports?

FeepingCreature feepingcreature at gmail.com
Tue Sep 25 13:03:30 UTC 2018


I'm playing with a branch of DMD that would warn on unused 
imports:

https://github.com/FeepingCreature/dmd/tree/feature/Issue-3507-warn-on-unused-imports

Two problems have arisen.

First:

import std.stdio;

void foo(T)() { writeln("Hello World"); }

foo.d: Warning: unused import

To be fair, it's not *wrong*: if you remove the import, the 
module itself compiles just fine. In any case, it's trivial to 
instead move the import into the template.

The real problem is this:

import std.format;

class TestException(T) : FormatException { }

Now I can't move the import inside the template, because it's 
needed at the point of instantiation, but not inside the template 
scope *per se*.

I could require the class to be written as

template TestException(T) {
   import std.format;
   class TestException : FormatException { }
}

but that's kind of terrible.

I've been working around this for now, with import std.format : 
FormatException, but I'm not really happy with it.

Any ideas?


More information about the Digitalmars-d mailing list