{"record":{"id":"7a910eaca8303b26","repo":"rust-lang/rust","slug":"duplicated-file-in","errorCode":null,"errorMessage":"Duplicated file `{}` in {}","messagePattern":"Duplicated file `(.+?)` in (.+?)","errorType":"validation","errorClass":"InvalidCheck","httpStatus":null,"severity":"error","filePath":"src/etc/htmldocck.py","lineNumber":488,"sourceCode":"            cache.get_tree(c.args[0]), pat, c.args[2], regexp, stop_at_first\n        )\n\n\ndef check_files_in_folder(c, cache, folder, files):\n    files = files.strip()\n    if not files.startswith(\"[\") or not files.endswith(\"]\"):\n        raise InvalidCheck(\n            \"Expected list as second argument of {} (ie '[]')\".format(c.cmd)\n        )\n\n    folder = cache.get_absolute_path(folder)\n\n    # First we create a set of files to check if there are duplicates.\n    files = shlex.split(files[1:-1].replace(\",\", \"\"))\n    files_set = set()\n    for file in files:\n        if file in files_set:\n            raise InvalidCheck(\"Duplicated file `{}` in {}\".format(file, c.cmd))\n        files_set.add(file)\n    folder_set = set([f for f in os.listdir(folder) if f != \".\" and f != \"..\"])\n\n    # Then we remove entries from both sets (we clone `folder_set` so we can iterate it while\n    # removing its elements).\n    for entry in set(folder_set):\n        if entry in files_set:\n            files_set.remove(entry)\n            folder_set.remove(entry)\n\n    error = 0\n    if len(files_set) != 0:\n        print_err(\n            c.lineno,\n            c.context,\n            \"Entries not found in folder `{}`: `{}`\".format(folder, files_set),\n        )\n        error += 1","sourceCodeStart":470,"sourceCodeEnd":506,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/etc/htmldocck.py#L470-L506","documentation":"Raised as InvalidCheck by check_files_in_folder() when the same filename appears more than once in the bracketed list of a 'files' directive. The check builds a set and rejects duplicates before comparing against the directory contents, because a duplicate would otherwise cancel out a real missing/extra entry in the set arithmetic.","triggerScenarios":"Authoring `//@ files: mydir [a.html a.html b.html]` (a.html listed twice). The loop at htmldocck.py:486-489 detects the repeat.","commonSituations":"Copy-paste error when editing a file list; merging two lists without de-duplicating; refactoring a directive and forgetting to remove the old entry.","solutions":["Remove the duplicate entry from the bracketed list so each filename appears once.","Re-run the test to confirm the directive parses."],"exampleFix":"// before\n//@ files: mydir [a.html a.html b.html]\n\n// after\n//@ files: mydir [a.html b.html]","handlingStrategy":"validation","validationCode":"def no_duplicate_files(files_str: str) -> bool:\n    import shlex\n    inner = files_str.strip()[1:-1].replace(\",\", \"\")\n    entries = shlex.split(inner)\n    return len(entries) == len(set(entries))\n\nif not no_duplicate_files(files_arg):\n    raise SystemExit(f\"files directive contains duplicate entries: {files_arg!r}\")","typeGuard":"def has_unique_entries(files_str: str) -> bool:\n    import shlex\n    inner = files_str.strip()[1:-1].replace(\",\", \"\")\n    entries = shlex.split(inner)\n    return len(entries) == len(set(entries))","tryCatchPattern":"from srcetc_htmldocck import InvalidCheck\ntry:\n    check_files_in_folder(c, cache, folder, files)\nexcept InvalidCheck as e:\n    if \"Duplicated file\" in str(e):\n        logging.error(\"de-duplicate the files list before re-running\")\n    raise","preventionTips":["De-duplicate file lists when editing files directives.","Add a lint rule that rejects repeated entries inside the brackets.","Generate files lists programmatically rather than hand-editing to avoid copy-paste dupes."],"tags":["htmldocck","rustdoc","files-directive","test-template","duplicate"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}