Skip to content

fix: Make span_to_lines return at least one line #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/renderer/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<'a> SourceMap<'a> {
if start >= line_info.end_byte {
continue;
}
if end <= line_info.start_byte {
if end < line_info.start_byte {
break;
}
lines.push(line_info);
Expand Down
79 changes: 79 additions & 0 deletions tests/rustc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2964,3 +2964,82 @@ LL | /// This is a long line that contains a <http://link.com>
.term_width(10);
assert_data_eq!(renderer.render(input), expected);
}

#[test]
fn array_into_iter() {
let source1 = r#"#![allow(unused)]
fn main() {
[1, 2, 3].into_iter().for_each(|n| { *n; });
}
"#;
let source2 = r#"[1, 2, 3].into_iter().for_each(|n| { *n; });
"#;

let long_title1 ="this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to `<[T; N] as IntoIterator>::into_iter` in Rust 2021";
let long_title2 = "for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>";
let long_title3 = "or use `IntoIterator::into_iter(..)` instead of `.into_iter()` to explicitly iterate by value";

let input = Level::WARNING
.header(long_title1)
.group(
Group::new()
.element(
Snippet::source(source1)
.origin("lint_example.rs")
.fold(true)
.annotation(AnnotationKind::Primary.span(40..49)),
)
.element(Level::WARNING.title("this changes meaning in Rust 2021"))
.element(Level::NOTE.title(long_title2))
.element(Level::NOTE.title("`#[warn(array_into_iter)]` on by default")),
)
.group(
Group::new()
.element(
Level::HELP.title("use `.iter()` instead of `.into_iter()` to avoid ambiguity"),
)
.element(
Snippet::source(source2)
.origin("lint_example.rs")
.line_start(3)
.fold(true)
.patch(Patch::new(10..19, "iter")),
),
)
.group(
Group::new()
.element(Level::HELP.title(long_title3))
.element(
Snippet::source(source2)
.origin("lint_example.rs")
.line_start(3)
.fold(true)
.patch(Patch::new(0..0, "IntoIterator::into_iter("))
.patch(Patch::new(9..21, ")")),
),
);

let expected = str![[r#"
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to `<[T; N] as IntoIterator>::into_iter` in Rust 2021
--> lint_example.rs:3:11
|
3 | [1, 2, 3].into_iter().for_each(|n| { *n; });
| ^^^^^^^^^
|
= warning: this changes meaning in Rust 2021
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
= note: `#[warn(array_into_iter)]` on by default
help: use `.iter()` instead of `.into_iter()` to avoid ambiguity
|
3 - [1, 2, 3].into_iter().for_each(|n| { *n; });
3 + [1, 2, 3].iter().for_each(|n| { *n; });
|
help: or use `IntoIterator::into_iter(..)` instead of `.into_iter()` to explicitly iterate by value
|
3 - [1, 2, 3].into_iter().for_each(|n| { *n; });
3 + IntoIterator::into_iter([1, 2, 3]).for_each(|n| { *n; });
|
"#]];
let renderer = Renderer::plain();
assert_data_eq!(renderer.render(input), expected);
}