From 8d49d113e55e89d9fca0277172250a60cea3a735 Mon Sep 17 00:00:00 2001 From: Josh Holmer Date: Thu, 21 Dec 2017 13:15:15 -0500 Subject: 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. --- src/librustc/hir/lowering.rs | 2 +- src/test/ui/issue-46576.rs | 31 +++++++++++++++++++++++++++++++ src/test/ui/issue-46576.stderr | 14 ++++++++++++++ src/test/ui/lint-output-format-2.stderr | 4 ++-- 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/issue-46576.rs create mode 100644 src/test/ui/issue-46576.stderr diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 6fc35e5302d..4de556b0e9d 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 or the MIT license +// , 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 -- cgit 1.4.1-3-g733a5