{"record":{"id":"de7da08f6fc8325c","repo":"rust-lang/rust","slug":"doesn-t-support-negative-check","errorCode":null,"errorMessage":"{} doesn't support negative check","messagePattern":"(.+?) doesn't support negative check","errorType":"validation","errorClass":"InvalidCheck","httpStatus":null,"severity":"error","filePath":"src/etc/htmldocck.py","lineNumber":553,"sourceCode":"            elif len(c.args) == 2 and \"raw\" in c.cmd:\n                cerr = \"`PATTERN` did not match\"\n                if c.negated:\n                    cerr = \"`PATTERN` unexpectedly matched\"\n                ret = check_string(cache.get_file(c.args[0]), c.args[1], regexp)\n            # has/matches <path> <pat> <match> = XML tree test\n            elif len(c.args) == 3 and \"raw\" not in c.cmd:\n                cerr = \"`XPATH PATTERN` did not match\"\n                if c.negated:\n                    cerr = \"`XPATH PATTERN` unexpectedly matched\"\n                ret = get_nb_matching_elements(cache, c, regexp, True) != 0\n            else:\n                raise InvalidCheck(\"Invalid number of {} arguments\".format(c.cmd))\n\n        elif c.cmd == \"files\":  # check files in given folder\n            if len(c.args) != 2:  # files <folder path> <file list>\n                raise InvalidCheck(\"Invalid number of {} arguments\".format(c.cmd))\n            elif c.negated:\n                raise InvalidCheck(\"{} doesn't support negative check\".format(c.cmd))\n            ret = check_files_in_folder(c, cache, c.args[0], c.args[1])\n\n        elif c.cmd == \"count\":  # count test\n            if len(c.args) == 3:  # count <path> <pat> <count> = count test\n                expected = int(c.args[2])\n                found = get_tree_count(cache.get_tree(c.args[0]), c.args[1])\n                cerr = \"Expected {} occurrences but found {}\".format(expected, found)\n                ret = expected == found\n            elif len(c.args) == 4:  # count <path> <pat> <text> <count> = count test\n                expected = int(c.args[3])\n                found = get_nb_matching_elements(cache, c, False, False)\n                cerr = \"Expected {} occurrences but found {}\".format(expected, found)\n                ret = found == expected\n            else:\n                raise InvalidCheck(\"Invalid number of {} arguments\".format(c.cmd))\n\n        elif c.cmd == \"snapshot\":  # snapshot test\n            if len(c.args) == 3:  # snapshot <snapshot-name> <html-path> <xpath>","sourceCodeStart":535,"sourceCodeEnd":571,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/etc/htmldocck.py#L535-L571","documentation":"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.","triggerScenarios":"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.","commonSituations":"Author assumes every htmldocck directive supports the `!` negation prefix used by has/matches and applies it to `files` by habit.","solutions":["Remove the leading `!` from the files directive.","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."],"exampleFix":"// before\n//@ !files \"out/html\" \"index.html\"\n// after\n//@ files \"out/html\" \"index.html\"\n","handlingStrategy":"validation","validationCode":"NON_NEGATABLE = {\"files\"}\nif cmd in NON_NEGATABLE and negated:\n    raise ValueError(f\"{cmd} does not support the '!' negation prefix\")\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only has/matches/count/snapshot-style checks support `!`; treat `files` as positive-only.","If you need to assert absence, restructure the test rather than negating files."],"tags":["rustdoc","htmldocck","testing","negation"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}