Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 557126c

Browse files
authored
Merge pull request #225 from Muscraft/fix-span-to-lines
fix: Make span_to_lines return at least one line
2 parents a1f58cd + 3d4d913 commit 557126c

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

‎src/renderer/source_map.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<'a> SourceMap<'a> {
124124
if start >= line_info.end_byte {
125125
continue;
126126
}
127-
if end <= line_info.start_byte {
127+
if end < line_info.start_byte {
128128
break;
129129
}
130130
lines.push(line_info);

‎tests/rustc_tests.rs‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,3 +2964,82 @@ LL | /// This is a long line that contains a <http://link.com>
29642964
.term_width(10);
29652965
assert_data_eq!(renderer.render(input), expected);
29662966
}
2967+
2968+
#[test]
2969+
fn array_into_iter() {
2970+
let source1 = r#"#![allow(unused)]
2971+
fn main() {
2972+
[1, 2, 3].into_iter().for_each(|n| { *n; });
2973+
}
2974+
"#;
2975+
let source2 = r#"[1, 2, 3].into_iter().for_each(|n| { *n; });
2976+
"#;
2977+
2978+
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";
2979+
let long_title2 = "for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>";
2980+
let long_title3 = "or use `IntoIterator::into_iter(..)` instead of `.into_iter()` to explicitly iterate by value";
2981+
2982+
let input = Level::WARNING
2983+
.header(long_title1)
2984+
.group(
2985+
Group::new()
2986+
.element(
2987+
Snippet::source(source1)
2988+
.origin("lint_example.rs")
2989+
.fold(true)
2990+
.annotation(AnnotationKind::Primary.span(40..49)),
2991+
)
2992+
.element(Level::WARNING.title("this changes meaning in Rust 2021"))
2993+
.element(Level::NOTE.title(long_title2))
2994+
.element(Level::NOTE.title("`#[warn(array_into_iter)]` on by default")),
2995+
)
2996+
.group(
2997+
Group::new()
2998+
.element(
2999+
Level::HELP.title("use `.iter()` instead of `.into_iter()` to avoid ambiguity"),
3000+
)
3001+
.element(
3002+
Snippet::source(source2)
3003+
.origin("lint_example.rs")
3004+
.line_start(3)
3005+
.fold(true)
3006+
.patch(Patch::new(10..19, "iter")),
3007+
),
3008+
)
3009+
.group(
3010+
Group::new()
3011+
.element(Level::HELP.title(long_title3))
3012+
.element(
3013+
Snippet::source(source2)
3014+
.origin("lint_example.rs")
3015+
.line_start(3)
3016+
.fold(true)
3017+
.patch(Patch::new(0..0, "IntoIterator::into_iter("))
3018+
.patch(Patch::new(9..21, ")")),
3019+
),
3020+
);
3021+
3022+
let expected = str![[r#"
3023+
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
3024+
--> lint_example.rs:3:11
3025+
|
3026+
3 | [1, 2, 3].into_iter().for_each(|n| { *n; });
3027+
| ^^^^^^^^^
3028+
|
3029+
= warning: this changes meaning in Rust 2021
3030+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
3031+
= note: `#[warn(array_into_iter)]` on by default
3032+
help: use `.iter()` instead of `.into_iter()` to avoid ambiguity
3033+
|
3034+
3 - [1, 2, 3].into_iter().for_each(|n| { *n; });
3035+
3 + [1, 2, 3].iter().for_each(|n| { *n; });
3036+
|
3037+
help: or use `IntoIterator::into_iter(..)` instead of `.into_iter()` to explicitly iterate by value
3038+
|
3039+
3 - [1, 2, 3].into_iter().for_each(|n| { *n; });
3040+
3 + IntoIterator::into_iter([1, 2, 3]).for_each(|n| { *n; });
3041+
|
3042+
"#]];
3043+
let renderer = Renderer::plain();
3044+
assert_data_eq!(renderer.render(input), expected);
3045+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /