Skip to content

rustc: Give a hint for missing self/super for imports & reduce number of redundant errors #14879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
312 changes: 177 additions & 135 deletions src/librustc/middle/resolve.rs

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/test/compile-fail-fulldeps/phase-syntax-doesnt-resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ extern crate macro_crate_test;

fn main() {
macro_crate_test::foo();
//~^ ERROR unresolved name
//~^^ ERROR use of undeclared module `macro_crate_test`
//~^^^ ERROR unresolved name `macro_crate_test::foo`.
//~^ ERROR failed to resolve. Use of undeclared module `macro_crate_test`
//~^^ ERROR unresolved name `macro_crate_test::foo`.
}
4 changes: 2 additions & 2 deletions src/test/compile-fail/import-from-missing.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -8,8 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern:failed to resolve import
use spam::{ham, eggs};
//~^ ERROR unresolved import `spam::eggs`. There is no `eggs` in `spam`

mod spam {
pub fn ham() { }
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/import.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern:failed to resolve import
use zed::bar;
use zed::baz;
//~^ ERROR unresolved import `zed::baz`. There is no `baz` in `zed`


mod zed {
Expand Down
6 changes: 3 additions & 3 deletions src/test/compile-fail/import2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -8,8 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use baz::zed::bar; //~ ERROR unresolved import
//~^ ERROR failed to resolve import
use baz::zed::bar;
//~^ ERROR unresolved import `baz::zed::bar`. Could not find `zed` in `baz`.


mod baz {}
Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail/issue-12612.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use foo::bar;

mod test {
use bar::foo;
//~^ ERROR: unresolved import
//~^^ ERROR: failed to resolve import
//~^ ERROR unresolved import `bar::foo`. Maybe a missing `extern crate bar`?
}

fn main() {}
Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail/issue-13404.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

use a::f;
use b::f;
//~^ ERROR: unresolved import
//~^^ ERROR: failed to resolve import
//~^ ERROR: unresolved import `b::f`. There is no `f` in `b`

mod a { pub fn f() {} }
mod b { }
Expand Down
8 changes: 3 additions & 5 deletions src/test/compile-fail/issue-1697.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -12,8 +12,6 @@

#![feature(globs)]

use unresolved::*; //~ ERROR unresolved import. maybe a missing
//~^ ERROR failed to resolve import
use unresolved::*; //~ ERROR unresolved import `unresolved::*`. Maybe a missing `extern crate unres

fn main() {
}
fn main() {}
11 changes: 4 additions & 7 deletions src/test/compile-fail/issue-2123.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -8,11 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use x = m::f; //~ ERROR failed to resolve import
//~^ unresolved import: there is no `f` in `m`
use x = m::f; //~ ERROR unresolved import `m::f`. There is no `f` in `m`

mod m {
}
mod m {}

fn main() {
}
fn main() {}
11 changes: 4 additions & 7 deletions src/test/compile-fail/issue-2937.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -8,11 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use x = m::f; //~ ERROR failed to resolve import
//~^ ERROR unresolved import: there is no `f` in `m`
use x = m::f; //~ ERROR unresolved import `m::f`. There is no `f` in `m`

mod m {
}
mod m {}

fn main() {
}
fn main() {}
5 changes: 2 additions & 3 deletions src/test/compile-fail/macro-inner-attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ test!(b,
#[qux]
fn main() {
a::bar();
//~^ ERROR use of undeclared module `a`
//~^^ ERROR unresolved name
//~^^^ ERROR unresolved name `a::bar`
//~^ ERROR failed to resolve. Use of undeclared module `a`
//~^^ ERROR unresolved name `a::bar`
b::bar();
}

9 changes: 4 additions & 5 deletions src/test/compile-fail/privacy2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -24,14 +24,13 @@ mod bar {
pub fn foo() {}

fn test1() {
use bar::foo; //~ ERROR: unresolved import
//~^ ERROR: failed to resolve
use bar::foo;
//~^ ERROR unresolved import `bar::foo`. There is no `foo` in `bar`
}

fn test2() {
use bar::glob::foo;
//~^ ERROR: there is no
//~^^ ERROR: failed to resolve
//~^ ERROR unresolved import `bar::glob::foo`. There is no `foo` in `bar::glob`
}

#[start] fn main(_: int, _: **u8) -> int { 3 }
Expand Down
6 changes: 3 additions & 3 deletions src/test/compile-fail/privacy3.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -25,8 +25,8 @@ mod bar {
pub fn foo() {}

fn test1() {
use bar::gpriv; //~ ERROR: unresolved import
//~^ ERROR: failed to resolve
use bar::gpriv;
//~^ ERROR unresolved import `bar::gpriv`. There is no `gpriv` in `bar`
gpriv();
}

Expand Down
27 changes: 27 additions & 0 deletions src/test/compile-fail/resolve_self_super_hint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2014 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.

mod a {
extern crate collections;
use collections::HashMap;
//~^ ERROR unresolved import `collections::HashMap`. Did you mean `self::collections`?
mod b {
use collections::HashMap;
//~^ ERROR unresolved import `collections::HashMap`. Did you mean `a::collections`?
mod c {
use collections::HashMap;
//~^ ERROR unresolved import `collections::HashMap`. Did you mean `a::collections`?
mod d {
use collections::HashMap;
//~^ ERROR unresolved import `collections::HashMap`. Did you mean `a::collections`?
}
}
}
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/super-at-top-level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use super::f; //~ ERROR failed to resolve import
use super::f; //~ ERROR unresolved import `super::f`

fn main() {
}
9 changes: 4 additions & 5 deletions src/test/compile-fail/unresolved-import.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -8,10 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use foo::bar; //~ ERROR unresolved import. maybe a missing `extern crate foo`?
//~^ ERROR failed to resolve import `foo::bar`
use x = bar::baz; //~ ERROR unresolved import: there is no `baz` in `bar`
//~^ ERROR failed to resolve import `bar::baz`
use foo::bar; //~ ERROR unresolved import `foo::bar`. Maybe a missing `extern crate foo`?

use x = bar::baz; //~ ERROR unresolved import `bar::baz`. There is no `baz` in `bar`

mod bar {
struct bar;
Expand Down
12 changes: 6 additions & 6 deletions src/test/compile-fail/use-from-trait-xc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

extern crate use_from_trait_xc;

use use_from_trait_xc::Trait::foo; //~ ERROR cannot import from a trait or type implementation
//~^ ERROR failed to resolve import
use use_from_trait_xc::Foo::new; //~ ERROR cannot import from a trait or type implementation
//~^ ERROR failed to resolve import
use use_from_trait_xc::Trait::foo;
//~^ ERROR unresolved import `use_from_trait_xc::Trait::foo`. Cannot import from a trait or type imp

fn main() {
}
use use_from_trait_xc::Foo::new;
//~^ ERROR unresolved import `use_from_trait_xc::Foo::new`. Cannot import from a trait or type imple

fn main() {}
8 changes: 4 additions & 4 deletions src/test/compile-fail/use-from-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use Trait::foo; //~ ERROR cannot import from a trait or type implementation
//~^ ERROR failed to resolve import
use Foo::new; //~ ERROR cannot import from a trait or type implementation
//~^ ERROR failed to resolve import
use Trait::foo;
//~^ ERROR unresolved import `Trait::foo`. Cannot import from a trait or type implementation
use Foo::new;
//~^ ERROR unresolved import `Foo::new`. Cannot import from a trait or type implementation

pub trait Trait {
fn foo();
Expand Down