Skip to content

Commit 06c8b38

Browse files
committed
Auto merge of #47021 - shssoichiro:46576-Incorrect-Span-Imports, r=estebank
Pass correct span when lowering grouped imports Solves incorrect diagnostics for unused or deprecated imports. Closes #46576. Deprecated imports had an existing test which asserted the incorrect span. That test has been corrected as part of this commit.
2 parents 4352c11 + 8d49d11 commit 06c8b38

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

src/librustc/hir/lowering.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2051,7 +2051,7 @@ impl<'a> LoweringContext<'a> {
20512051
.chain(path.segments.iter())
20522052
.cloned()
20532053
.collect(),
2054-
span: path.span.to(prefix.span),
2054+
span: path.span
20552055
};
20562056

20572057
// Correctly resolve `self` imports

src/test/ui/issue-46576.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![allow(dead_code)]
12+
#![deny(unused_imports)]
13+
14+
use std::fs::File;
15+
use std::io::{BufRead, BufReader, Read};
16+
//~^ ERROR unused import: `BufRead`
17+
18+
pub fn read_from_file(path: &str) {
19+
let file = File::open(&path).unwrap();
20+
let mut reader = BufReader::new(file);
21+
let mut s = String::new();
22+
reader.read_to_string(&mut s).unwrap();
23+
}
24+
25+
pub fn read_lines(s: &str) {
26+
for _line in s.lines() {
27+
28+
}
29+
}
30+
31+
fn main() {}

src/test/ui/issue-46576.stderr

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unused import: `BufRead`
2+
--> $DIR/issue-46576.rs:15:15
3+
|
4+
15 | use std::io::{BufRead, BufReader, Read};
5+
| ^^^^^^^
6+
|
7+
note: lint level defined here
8+
--> $DIR/issue-46576.rs:12:9
9+
|
10+
12 | #![deny(unused_imports)]
11+
| ^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+

src/test/ui/lint-output-format-2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
warning: use of deprecated item 'lint_output_format::foo': text
2-
--> $DIR/lint-output-format-2.rs:20:5
2+
--> $DIR/lint-output-format-2.rs:20:26
33
|
44
20 | use lint_output_format::{foo, bar};
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^
66
|
77
= note: #[warn(deprecated)] on by default
88

0 commit comments

Comments
 (0)