-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Import trait help message is incorrect #114884
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Span of the import suggestion needs to be adjusted. |
@rustbot claim |
When I try to compile this snippet: extern crate rustc_index;
use rustc_index::{vec::Idx};
fn main() { } with my locally built
Running @compiler-errors Can you please help me resolve this problem?
|
@gurry please reproduce this issue using another way that doesn't rely on rustc-internal crates. The only part that matters is the |
Yes, I first tried with a |
The issue reproduces with the following self contained snippet: pub mod mod1 {
pub trait TraitA {}
}
pub mod mod2 {
mod sub_mod {
use mod1::TraitA;
}
}
use mod2::{sub_mod::TraitA};
fn main() { } resulting in the following diagnostic:
The immediate cause of the issue is the below argument to rust/compiler/rustc_resolve/src/diagnostics.rs Line 1668 in c40cfcf
Specifically, the problem is with At first glance the solution is to simply set 11 | use mod2::{mod1::TraitA};
| ~~~~~~~~~~~~ to this: 11 | use mod1::TraitA;
| ~~~~~~~~~~~~ However, it will fail for multi-child paths such as 11 | use mod1::TraitA, SomeOtherType};
| ~~~~~~~~~~~~~~~~~~ Therefore what we may need is a smarter approach which can:
11 | - use mod2::{TraitA, SomeOtherType};
11 | + use mod2::SomeOtherType;
12 | + use mod1::TraitA; It may also be an option to just stick with the simpler approach of correcting What are you thoughts @compiler-errors ? |
@rustbot claim |
Triage: no change
|
avoid overlapping privacy suggestion for single nested imports Fixes rust-lang#114884 This PR aims to avoid confusion inside braces for import suggestions. r? `@petrochenkov`
Rollup merge of rust-lang#121190 - bvanjoi:fix-114884, r=petrochenkov avoid overlapping privacy suggestion for single nested imports Fixes rust-lang#114884 This PR aims to avoid confusion inside braces for import suggestions. r? ``@petrochenkov``
Uh oh!
There was an error while loading. Please reload this page.
Code
Current output
(The rustc_private error is irrelevant)
Desired output
The suggestion to import
rustc_index::{rustc_index::Idx};
is obviously wrong. It should berustc_index::{Idx};
(or evenrustc_index::Idx
).The text was updated successfully, but these errors were encountered: