-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #88838 - FabianWolff:issue-88472, r=estebank
Do not suggest importing inaccessible items Fixes #88472. For this example: ```rust mod a { struct Foo; } mod b { type Bar = Foo; } ``` rustc currently emits: ``` error[E0412]: cannot find type `Foo` in this scope --> test.rs:6:16 | 6 | type Bar = Foo; | ^^^ not found in this scope | help: consider importing this struct | 6 | use a::Foo; | ``` this is incorrect, as applying this suggestion leads to ``` error[E0603]: struct `Foo` is private --> test.rs:6:12 | 6 | use a::Foo; | ^^^ private struct | note: the struct `Foo` is defined here --> test.rs:2:5 | 2 | struct Foo; | ^^^^^^^^^^^ ``` With my changes, I get: ``` error[E0412]: cannot find type `Foo` in this scope --> test.rs:6:16 | 6 | type Bar = Foo; | ^^^ not found in this scope | = note: this struct exists but is inaccessible: a::Foo ``` As for the wildcard mentioned in #88472, I would argue that the warning is actually correct, since the import _is_ unused. I think the real issue is the wrong suggestion, which I have fixed here.
- Loading branch information
Showing
11 changed files
with
264 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Regression test for #88472, where a suggestion was issued to | ||
// import an inaccessible struct. | ||
|
||
#![warn(unused_imports)] | ||
//~^ NOTE: the lint level is defined here | ||
|
||
mod a { | ||
struct Foo; | ||
//~^ NOTE: struct `a::Foo` exists but is inaccessible | ||
//~| NOTE: not accessible | ||
} | ||
|
||
mod b { | ||
use crate::a::*; | ||
//~^ WARNING: unused import | ||
type Bar = Foo; | ||
//~^ ERROR: cannot find type `Foo` in this scope [E0412] | ||
//~| NOTE: not found in this scope | ||
} | ||
|
||
mod c { | ||
enum Eee {} | ||
//~^ NOTE: these enums exist but are inaccessible | ||
//~| NOTE: `c::Eee`: not accessible | ||
|
||
mod d { | ||
enum Eee {} | ||
//~^ NOTE: `c::d::Eee`: not accessible | ||
} | ||
} | ||
|
||
mod e { | ||
type Baz = Eee; | ||
//~^ ERROR: cannot find type `Eee` in this scope [E0412] | ||
//~| NOTE: not found in this scope | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.