{"record":{"id":"7398fc79577f009a","repo":"astral-sh/ruff","slug":"ranges-must-be-inserted-in-sorted-order","errorCode":null,"errorMessage":"Ranges must be inserted in sorted order","messagePattern":"Ranges must be inserted in sorted order","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_linter/src/noqa.rs","lineNumber":1352,"sourceCode":"            }\n        });\n\n        if let Ok(index) = index {\n            self.ranges[index].end()\n        } else {\n            offset\n        }\n    }\n\n    pub(crate) fn push_mapping(&mut self, range: TextRange) {\n        if let Some(last_range) = self.ranges.last_mut() {\n            // Strictly sorted insertion\n            if last_range.end() < range.start() {\n                // OK\n            } else if range.end() < last_range.start() {\n                // Incoming range is strictly before the last range which violates\n                // the function's contract.\n                panic!(\"Ranges must be inserted in sorted order\")\n            } else {\n                // Here, it's guaranteed that `last_range` and `range` overlap\n                // in some way. We want to merge them into a single range.\n                *last_range = last_range.cover(range);\n                return;\n            }\n        }\n\n        self.ranges.push(range);\n    }\n}\n\nimpl FromIterator<TextRange> for NoqaMapping {\n    fn from_iter<T: IntoIterator<Item = TextRange>>(iter: T) -> Self {\n        let mut mappings = NoqaMapping::default();\n\n        for range in iter {\n            mappings.push_mapping(range);","sourceCodeStart":1334,"sourceCodeEnd":1370,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_linter/src/noqa.rs#L1334-L1370","documentation":"Panics in push_mapping when a new TextRange is inserted before the last range already in the list. The mapping structure requires strictly sorted, non-overlapping ranges; an out-of-order push means an upstream caller violated that contract, not bad user input.","triggerScenarios":"Thrown at crates/ruff_linter/src/noqa.rs:1352 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure callers of push_mapping emit ranges in ascending start order","Add a debug assertion or sort merge at the call site before pushing"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}