Point at path segment on module not found

Point at the correct path segment on a import statement where a module
doesn't exist.

New output:

```rust
error[E0432]: unresolved import `std::bar`
 --> <anon>:1:10
  |
1 | use std::bar::{foo1, foo2};
  |          ^^^ Could not find `bar` in `std`
```

instead of:

```rust
error[E0432]: unresolved import `std::bar::foo1`
 --> <anon>:1:16
  |
1 | use std::bar::{foo1, foo2};
  |                ^^^^ Could not find `bar` in `std`

error[E0432]: unresolved import `std::bar::foo2`
 --> <anon>:1:22
  |
1 | use std::bar::{foo1, foo2};
  |                      ^^^^ Could not find `bar` in `std`
```
This commit is contained in:
Esteban Küber 2017-07-23 15:15:45 -07:00
parent 6c949655de
commit 552ff07758
18 changed files with 194 additions and 129 deletions

View file

@ -13,7 +13,7 @@ mod a {}
macro_rules! m {
() => {
use a::$crate; //~ ERROR unresolved import `a::$crate`
use a::$crate::b; //~ ERROR unresolved import `a::$crate::b`
use a::$crate::b; //~ ERROR unresolved import `a::$crate`
type A = a::$crate; //~ ERROR cannot find type `$crate` in module `a`
}
}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use baz::zed::bar; //~ ERROR unresolved import `baz::zed::bar` [E0432]
use baz::zed::bar; //~ ERROR unresolved import `baz::zed` [E0432]
//~^ Could not find `zed` in `baz`
mod baz {}

View file

@ -10,7 +10,7 @@
// Testing that we don't fail abnormally after hitting the errors
use unresolved::*; //~ ERROR unresolved import `unresolved::*` [E0432]
use unresolved::*; //~ ERROR unresolved import `unresolved` [E0432]
//~^ Maybe a missing `extern crate unresolved;`?
fn main() {}

View file

@ -10,10 +10,10 @@
type Alias = ();
use Alias::*;
//~^ ERROR unresolved import `Alias::*` [E0432]
//~^ ERROR unresolved import `Alias` [E0432]
//~| Not a module `Alias`
use std::io::Result::*;
//~^ ERROR unresolved import `std::io::Result::*` [E0432]
//~^ ERROR unresolved import `std::io::Result` [E0432]
//~| Not a module `Result`
trait T {}

View file

@ -11,13 +11,10 @@
// Make sure that the spans of import errors are correct.
use abc::one_el;
//~^ ERROR 13:5: 13:16
//~^ ERROR 13:5: 13:8
use abc::{a, bbb, cccccc};
//~^ ERROR 15:11: 15:12
//~^^ ERROR 15:14: 15:17
//~^^^ ERROR 15:19: 15:25
//~^ ERROR 15:5: 15:8
use a_very_long_name::{el, el2};
//~^ ERROR 19:24: 19:26
//~^^ ERROR 19:28: 19:31
//~^ ERROR 17:5: 17:21
fn main() {}

View file

@ -13,19 +13,19 @@
mod a {
extern crate alloc;
use alloc::HashMap;
//~^ ERROR unresolved import `alloc::HashMap` [E0432]
//~^ ERROR unresolved import `alloc` [E0432]
//~| Did you mean `self::alloc`?
mod b {
use alloc::HashMap;
//~^ ERROR unresolved import `alloc::HashMap` [E0432]
//~^ ERROR unresolved import `alloc` [E0432]
//~| Did you mean `a::alloc`?
mod c {
use alloc::HashMap;
//~^ ERROR unresolved import `alloc::HashMap` [E0432]
//~^ ERROR unresolved import `alloc` [E0432]
//~| Did you mean `a::alloc`?
mod d {
use alloc::HashMap;
//~^ ERROR unresolved import `alloc::HashMap` [E0432]
//~^ ERROR unresolved import `alloc` [E0432]
//~| Did you mean `a::alloc`?
}
}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use super::f; //~ ERROR unresolved import `super::f` [E0432]
use super::f; //~ ERROR unresolved import `super` [E0432]
//~^ There are too many initial `super`s.
fn main() {

View file

@ -10,7 +10,7 @@
// ignore-tidy-linelength
use foo::bar; //~ ERROR unresolved import `foo::bar` [E0432]
use foo::bar; //~ ERROR unresolved import `foo` [E0432]
//~^ Maybe a missing `extern crate foo;`?
use bar::Baz as x; //~ ERROR unresolved import `bar::Baz` [E0432]
@ -41,7 +41,7 @@ mod m {
MyVariant
}
use MyEnum::*; //~ ERROR unresolved import `MyEnum::*` [E0432]
use MyEnum::*; //~ ERROR unresolved import `MyEnum` [E0432]
//~^ Did you mean `self::MyEnum`?
}
@ -50,7 +50,7 @@ mod items {
Variant
}
use Enum::*; //~ ERROR unresolved import `Enum::*` [E0432]
use Enum::*; //~ ERROR unresolved import `Enum` [E0432]
//~^ Did you mean `self::Enum`?
fn item() {}

View file

@ -22,13 +22,13 @@ use use_from_trait_xc::Trait::CONST;
//~^ ERROR `CONST` is not directly importable
use use_from_trait_xc::Foo::new; //~ ERROR struct `Foo` is private
//~^ ERROR unresolved import `use_from_trait_xc::Foo::new`
//~^ ERROR unresolved import `use_from_trait_xc::Foo`
use use_from_trait_xc::Foo::C; //~ ERROR struct `Foo` is private
//~^ ERROR unresolved import `use_from_trait_xc::Foo::C`
//~^ ERROR unresolved import `use_from_trait_xc::Foo`
use use_from_trait_xc::Bar::new as bnew;
//~^ ERROR unresolved import `use_from_trait_xc::Bar::new`
//~^ ERROR unresolved import `use_from_trait_xc::Bar`
use use_from_trait_xc::Baz::new as baznew;
//~^ ERROR unresolved import `use_from_trait_xc::Baz::new`

View file

@ -17,11 +17,11 @@ use Trait::C;
//~^ ERROR `C` is not directly importable
use Foo::new;
//~^ ERROR unresolved import `Foo::new` [E0432]
//~^ ERROR unresolved import `Foo` [E0432]
//~| Not a module `Foo`
use Foo::C2;
//~^ ERROR unresolved import `Foo::C2` [E0432]
//~^ ERROR unresolved import `Foo` [E0432]
//~| Not a module `Foo`
pub trait Trait {

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use foo::self; //~ ERROR unresolved import `foo::self`
use foo::self; //~ ERROR unresolved import `foo`
//~^ ERROR `self` imports are only allowed within a { } list
use std::mem::self;

View file

@ -2,7 +2,7 @@ error[E0433]: failed to resolve. Use of undeclared type or module `m`
--> $DIR/macro_path_as_generic_bound.rs:17:6
|
17 | foo!(m::m2::A);
| ^^^^^^^^ Use of undeclared type or module `m`
| ^ Use of undeclared type or module `m`
error: cannot continue compilation due to previous error

View file

@ -0,0 +1,13 @@
// 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.
use std::bar::{foo1, foo2};
fn main() {}

View file

@ -0,0 +1,8 @@
error[E0432]: unresolved import `std::bar`
--> $DIR/non-existing-module-import.rs:11:10
|
11 | use std::bar::{foo1, foo2};
| ^^^ Could not find `bar` in `std`
error: aborting due to previous error