diff options
| author | bors <bors@rust-lang.org> | 2017-12-28 16:16:46 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-12-28 16:16:46 +0000 |
| commit | 06c8b385d1d51c1cee4fb8c463028e0e6fafeb4e (patch) | |
| tree | 9d508bc4a1c9ee7b85cb62eb630a6bf8b4d675f1 | |
| parent | 4352c11dd0975679e25130fa2ba2d563c43edd79 (diff) | |
| parent | 8d49d113e55e89d9fca0277172250a60cea3a735 (diff) | |
| download | rust-06c8b385d1d51c1cee4fb8c463028e0e6fafeb4e.tar.gz rust-06c8b385d1d51c1cee4fb8c463028e0e6fafeb4e.zip | |
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.
| -rw-r--r-- | src/librustc/hir/lowering.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/issue-46576.rs | 31 | ||||
| -rw-r--r-- | src/test/ui/issue-46576.stderr | 14 | ||||
| -rw-r--r-- | src/test/ui/lint-output-format-2.stderr | 4 |
4 files changed, 48 insertions, 3 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index e435f14470c..1f7e7000d65 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -2051,7 +2051,7 @@ impl<'a> LoweringContext<'a> { .chain(path.segments.iter()) .cloned() .collect(), - span: path.span.to(prefix.span), + span: path.span }; // Correctly resolve `self` imports diff --git a/src/test/ui/issue-46576.rs b/src/test/ui/issue-46576.rs new file mode 100644 index 00000000000..80f15eb4cac --- /dev/null +++ b/src/test/ui/issue-46576.rs @@ -0,0 +1,31 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![allow(dead_code)] +#![deny(unused_imports)] + +use std::fs::File; +use std::io::{BufRead, BufReader, Read}; +//~^ ERROR unused import: `BufRead` + +pub fn read_from_file(path: &str) { + let file = File::open(&path).unwrap(); + let mut reader = BufReader::new(file); + let mut s = String::new(); + reader.read_to_string(&mut s).unwrap(); +} + +pub fn read_lines(s: &str) { + for _line in s.lines() { + + } +} + +fn main() {} diff --git a/src/test/ui/issue-46576.stderr b/src/test/ui/issue-46576.stderr new file mode 100644 index 00000000000..d73da19ebdd --- /dev/null +++ b/src/test/ui/issue-46576.stderr @@ -0,0 +1,14 @@ +error: unused import: `BufRead` + --> $DIR/issue-46576.rs:15:15 + | +15 | use std::io::{BufRead, BufReader, Read}; + | ^^^^^^^ + | +note: lint level defined here + --> $DIR/issue-46576.rs:12:9 + | +12 | #![deny(unused_imports)] + | ^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/lint-output-format-2.stderr b/src/test/ui/lint-output-format-2.stderr index d8c67c760db..75e7e1f42ff 100644 --- a/src/test/ui/lint-output-format-2.stderr +++ b/src/test/ui/lint-output-format-2.stderr @@ -1,8 +1,8 @@ warning: use of deprecated item 'lint_output_format::foo': text - --> $DIR/lint-output-format-2.rs:20:5 + --> $DIR/lint-output-format-2.rs:20:26 | 20 | use lint_output_format::{foo, bar}; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ | = note: #[warn(deprecated)] on by default |
