rust-lang/rust · error · InvalidCheck

{} doesn't support negative check

Error message

{} doesn't support negative check

What it means

Raised by htmldocck when a `files` directive is negated (prefixed with `!`). The `files` check is inherently non-negatable, so `//@ !files ...` is rejected as InvalidCheck before any filesystem check runs.

Source

Thrown at src/etc/htmldocck.py:553

            elif len(c.args) == 2 and "raw" in c.cmd:
                cerr = "`PATTERN` did not match"
                if c.negated:
                    cerr = "`PATTERN` unexpectedly matched"
                ret = check_string(cache.get_file(c.args[0]), c.args[1], regexp)
            # has/matches <path> <pat> <match> = XML tree test
            elif len(c.args) == 3 and "raw" not in c.cmd:
                cerr = "`XPATH PATTERN` did not match"
                if c.negated:
                    cerr = "`XPATH PATTERN` unexpectedly matched"
                ret = get_nb_matching_elements(cache, c, regexp, True) != 0
            else:
                raise InvalidCheck("Invalid number of {} arguments".format(c.cmd))

        elif c.cmd == "files":  # check files in given folder
            if len(c.args) != 2:  # files <folder path> <file list>
                raise InvalidCheck("Invalid number of {} arguments".format(c.cmd))
            elif c.negated:
                raise InvalidCheck("{} doesn't support negative check".format(c.cmd))
            ret = check_files_in_folder(c, cache, c.args[0], c.args[1])

        elif c.cmd == "count":  # count test
            if len(c.args) == 3:  # count <path> <pat> <count> = count test
                expected = int(c.args[2])
                found = get_tree_count(cache.get_tree(c.args[0]), c.args[1])
                cerr = "Expected {} occurrences but found {}".format(expected, found)
                ret = expected == found
            elif len(c.args) == 4:  # count <path> <pat> <text> <count> = count test
                expected = int(c.args[3])
                found = get_nb_matching_elements(cache, c, False, False)
                cerr = "Expected {} occurrences but found {}".format(expected, found)
                ret = found == expected
            else:
                raise InvalidCheck("Invalid number of {} arguments".format(c.cmd))

        elif c.cmd == "snapshot":  # snapshot test
            if len(c.args) == 3:  # snapshot <snapshot-name> <html-path> <xpath>

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. Remove the leading `!` from the files directive.
  2. If you need to assert a file is absent, use a different directive (e.g. has-dir / !has-dir) or restructure the test to assert the folder's expected positive contents.

Example fix

// before
//@ !files "out/html" "index.html"
// after
//@ files "out/html" "index.html"
Defensive patterns

Strategy: validation

Validate before calling

NON_NEGATABLE = {"files"}
if cmd in NON_NEGATABLE and negated:
    raise ValueError(f"{cmd} does not support the '!' negation prefix")

Prevention

When it happens

Trigger: Writing `//@ !files out/html "index.html"` in a rustdoc test. The `c.negated` flag is set by the leading `!` and the `elif c.negated` branch at line 552 raises unconditionally.

Common situations: Author assumes every htmldocck directive supports the `!` negation prefix used by has/matches and applies it to `files` by habit.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/de7da08f6fc8325c. Report an issue: GitHub.