Skip to content
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

incorrect suggestion when skipping a module in a qualified reference #120074

Closed
folkertdev opened this issue Jan 17, 2024 · 2 comments · Fixed by #127203
Closed

incorrect suggestion when skipping a module in a qualified reference #120074

folkertdev opened this issue Jan 17, 2024 · 2 comments · Fixed by #127203
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@folkertdev
Copy link
Contributor

Code

fn main() {
    println!("Hello, {}!", crate::bar::do_the_thing);
}

pub mod foo {
    pub mod bar {
        pub fn do_the_thing() -> usize {
            42
        }
    }
}

Current output

error[E0433]: failed to resolve: unresolved import
 --> src/main.rs:4:35
  |
4 |     println!("Hello, {}!", crate::bar::do_the_thing);
  |                                   ^^^ unresolved import
  |
help: a similar path exists
  |
4 |     println!("Hello, {}!", crate::crate::foo::bar::do_the_thing);
  |                                   ~~~~~~~~~~~~~~~
help: consider importing this module
  |
1 + use crate::foo::bar;
  |
help: if you import `bar`, refer to it directly
  |
4 -     println!("Hello, {}!", crate::bar::do_the_thing);
4 +     println!("Hello, {}!", bar::do_the_thing);

Desired output

error[E0433]: failed to resolve: unresolved import
 --> src/main.rs:4:35
  |
4 |     println!("Hello, {}!", crate::bar::do_the_thing);
  |                                   ^^^ unresolved import
  |
help: a similar path exists
  |
4 |     println!("Hello, {}!", crate::foo::bar::do_the_thing);
  |                                   ~~~~~~~~
help: consider importing this module
  |
1 + use crate::foo::bar;
  |
help: if you import `bar`, refer to it directly
  |
4 -     println!("Hello, {}!", crate::bar::do_the_thing);
4 +     println!("Hello, {}!", bar::do_the_thing);

Rationale and extra context

just a minor formatting logic bug I think. If a module name is missing in the middle of a chain (here crate::bar::do_the_thing is used, but crate::foo::bar::do_the_thing is defined) the suggestion is the full path, not just the bit in the middle that is missing.

Other cases

you need 2 nested modules for this problem to show up. Just one nested module works fine.

Rust Version

rustc 1.75.0 (82e1608df 2023-12-21)
binary: rustc
commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112
commit-date: 2023-12-21
host: x86_64-unknown-linux-gnu
release: 1.75.0
LLVM version: 17.0.6

Anything else?

No response

@folkertdev folkertdev added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 17, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 17, 2024
@folkertdev
Copy link
Contributor Author

looks like this was fixed already, but it's not on nightly yet (or at least, not on play.rust-lang.org)

on commit 92d727796be7c882d2efbc06e08bbf4743cf29dc I see the correct output:

> rustc +stage1 main.rs
error[E0433]: failed to resolve: unresolved import
 --> main.rs:2:20
  |
2 |     let _ = crate::bar::do_the_thing;
  |                    ^^^ unresolved import
  |
help: a similar path exists
  |
2 |     let _ = crate::foo::bar::do_the_thing;
  |                    ~~~~~~~~
help: consider importing this module
  |
1 + use foo::bar;
  |
help: if you import `bar`, refer to it directly
  |
2 -     let _ = crate::bar::do_the_thing;
2 +     let _ = bar::do_the_thing;
  |

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0433`.

@chenyukang chenyukang self-assigned this Jan 28, 2024
@chenyukang
Copy link
Member

seems it still not be fixed in nightly.

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 12, 2024
@bors bors closed this as completed in 4d2a049 Jul 2, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jul 2, 2024
Rollup merge of rust-lang#127203 - chenyukang:yukang-fix-120074-import, r=Nadrieril

Fix import suggestion error when path segment failed not from starting

Fixes rust-lang#120074
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 12, 2024
…rt-ice, r=estebank

Fix import suggestion ice

Fixes rust-lang#127302

rust-lang#127302 only crash in edition 2015
rust-lang#120074 can only reproduced in edition 2021
so I added revisions in test file.
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Jul 12, 2024
…rt-ice, r=estebank

Fix import suggestion ice

Fixes rust-lang#127302

rust-lang#127302 only crash in edition 2015
rust-lang#120074 can only reproduced in edition 2021
so I added revisions in test file.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jul 13, 2024
Rollup merge of rust-lang#127310 - chenyukang:yukang-fix-suggest-import-ice, r=estebank

Fix import suggestion ice

Fixes rust-lang#127302

rust-lang#127302 only crash in edition 2015
rust-lang#120074 can only reproduced in edition 2021
so I added revisions in test file.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants