Remove Diagnostic::expect_range and all consumers (#20322)

Replace usage with `range().unwrap_or_default()` or more appropriate
alternatives based on context.
This commit is contained in:
Amethyst Reese 2025-09-10 17:19:20 -07:00 committed by GitHub
parent 12c337c948
commit a3ec8ca9df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 53 additions and 63 deletions

View file

@ -383,17 +383,20 @@ Either ensure you always emit a fix or change `Violation::FIX_AVAILABILITY` to e
// Not strictly necessary but adds some coverage for this code path by overriding the
// noqa offset and the source file
let range = diagnostic.expect_range();
diagnostic.set_noqa_offset(directives.noqa_line_for.resolve(range.start()));
if let Some(range) = diagnostic.range() {
diagnostic.set_noqa_offset(directives.noqa_line_for.resolve(range.start()));
}
// This part actually is necessary to avoid long relative paths in snapshots.
for annotation in diagnostic.annotations_mut() {
let range = annotation.get_span().range().unwrap();
annotation.set_span(Span::from(source_code.clone()).with_range(range));
if let Some(range) = annotation.get_span().range() {
annotation.set_span(Span::from(source_code.clone()).with_range(range));
}
}
for sub in diagnostic.sub_diagnostics_mut() {
for annotation in sub.annotations_mut() {
let range = annotation.get_span().range().unwrap();
annotation.set_span(Span::from(source_code.clone()).with_range(range));
if let Some(range) = annotation.get_span().range() {
annotation.set_span(Span::from(source_code.clone()).with_range(range));
}
}
}