Skip to content

Commit 075beca

Browse files
committed
Handle line and column references in nonexistent_path_in_comment
Fixes #1609
1 parent dc4ac80 commit 075beca

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

examples/supplementary/nonexistent_path_in_comment/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn check_comment(cx: &LateContext<'_>, span: Span, comment_text: &str, filename:
140140
};
141141

142142
for caps in PATH_REGEX.captures_iter(comment_text) {
143-
let path_str = &caps[0];
143+
let mut path_str = &caps[0];
144144

145145
if path_str.chars().filter(|&c| c == '/').count() < MIN_PATH_SEPARATORS {
146146
continue;
@@ -150,6 +150,12 @@ fn check_comment(cx: &LateContext<'_>, span: Span, comment_text: &str, filename:
150150
continue;
151151
}
152152

153+
// smoelius: Strip line and column references.
154+
let last_slash = path_str.rfind('/').unwrap();
155+
if let Some(index) = path_str[last_slash..].find(':') {
156+
path_str = &path_str[..last_slash + index];
157+
}
158+
153159
let full_path = base_dir.join(path_str);
154160

155161
if full_path.exists() {
@@ -163,7 +169,7 @@ fn check_comment(cx: &LateContext<'_>, span: Span, comment_text: &str, filename:
163169
}
164170

165171
let path_start = caps.get(0).unwrap().start();
166-
let path_end = caps.get(0).unwrap().end();
172+
let path_end = path_start + path_str.len();
167173
let path_span = Span::new(
168174
span.lo() + BytePos(path_start as u32),
169175
span.lo() + BytePos(path_end as u32),

examples/supplementary/nonexistent_path_in_comment/ui/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,13 @@
2020
// Negative test: urls
2121
// This is a url: https://github.com/trailofbits/dylint
2222

23+
// Nonexistent path with line and column reference
24+
// See ../nonexistent/path/file.rs:1:1
25+
26+
// Don't strip back to a colon before the last slash
27+
// See ../nonexistent:directory:with:colons/file.rs:1:1
28+
29+
// Negative test: existing path with line and column reference
30+
// See ../src/lib.rs:1:1
31+
2332
fn main() {}

examples/supplementary/nonexistent_path_in_comment/ui/main.stderr

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ LL | // The span ./ido/not/exist.rs only points to the path
1515
|
1616
= help: verify the path is correct or remove the reference
1717

18+
warning: referenced path does not exist
19+
--> $DIR/main.rs:24:8
20+
|
21+
LL | // See ../nonexistent/path/file.rs:1:1
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
23+
|
24+
= help: verify the path is correct or remove the reference
25+
26+
warning: referenced path does not exist
27+
--> $DIR/main.rs:27:8
28+
|
29+
LL | // See ../nonexistent:directory:with:colons/file.rs:1:1
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31+
|
32+
= help: verify the path is correct or remove the reference
33+
1834
warning: referenced path does not exist
1935
--> $DIR/main.rs:8:8
2036
|
@@ -23,5 +39,5 @@ LL | See ../another/nonexistent/path/file.go
2339
|
2440
= help: verify the path is correct or remove the reference
2541

26-
warning: 3 warnings emitted
42+
warning: 5 warnings emitted
2743

0 commit comments

Comments
 (0)