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

diagnostics should prefer naming items through the extern prelude instead of doc-hidden type aliases #127011

Closed
lolbinarycat opened this issue Jun 26, 2024 · 2 comments · Fixed by #139364
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lolbinarycat
Copy link
Contributor

lolbinarycat commented Jun 26, 2024

Code

#![crate_type = "proc-macro"]

// note: `quote` is in Cargo.toml
use proc_macro::TokenStream;
use syn::Lit;

#[proc_macro]
pub fn macro1(input: TokenStream) -> TokenStream {
    let x = syn::parse_macro_input!(input as Lit);
    x.into_token_stream()
}

Current output

error[E0599]: no method named `into_token_stream` found for enum `syn::Lit` in the current scope
  --> src/lib.rs:10:7
   |
10 |     x.into_token_stream()
   |       ^^^^^^^^^^^^^^^^^
   |
   = help: items from traits can only be used if the trait is in scope
help: trait `ToTokens` which provides `into_token_stream` is implemented but not in scope; perhaps you want to import it
   |
3  + use syn::__private::ToTokens;
   |
help: there is a method `to_token_stream` with a similar name
   |
10 |     x.to_token_stream()
   |       ~~~~~~~~~~~~~~~

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

Desired output

error[E0599]: no method named `into_token_stream` found for enum `syn::Lit` in the current scope
  --> src/lib.rs:10:7
   |
10 |     x.into_token_stream()
   |       ^^^^^^^^^^^^^^^^^
   |
   = help: items from traits can only be used if the trait is in scope
help: trait `ToTokens` which provides `into_token_stream` is implemented but not in scope; perhaps you want to import it
   |
3  + use ::quote::ToTokens;
   |
help: there is a method `to_token_stream` with a similar name
   |
10 |     x.to_token_stream()
   |       ~~~~~~~~~~~~~~~

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

Rationale and extra context

diagnostics should avoid referencing #[doc(hidden)] items if at all possible. ideally it would suggest adding quote to the extern prelude if it wasn't there already, but that is tricky when rustc doesn't know anything about how dependencies are managed.

Other cases

No response

Rust Version

rustc 1.80.0-nightly (debd22da6 2024-05-29)
binary: rustc
commit-hash: debd22da66cfa97c74040ebf68e420672ac8560e
commit-date: 2024-05-29
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.6

Anything else?

No response

@lolbinarycat lolbinarycat 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 Jun 26, 2024
@lolbinarycat lolbinarycat added D-confusing Diagnostics: Confusing error or lint that should be reworked. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. labels Mar 3, 2025
@lolbinarycat
Copy link
Contributor Author

lolbinarycat commented Mar 3, 2025

Another case of this is reccomending items through crate:: instead of through the extern prelude.

#![no_std]

extern crate alloc;

use alloc::vec::Vec;

mod foo {
    fn f() {
        let _ = Vec::new();
    }
}
error[E0433]: failed to resolve: use of undeclared type `Vec`
 --> src/lib.rs:9:17
  |
9 |         let _ = Vec::new();
  |                 ^^^ use of undeclared type `Vec`
  |
help: consider importing one of these structs
  |
8 +     use crate::Vec;
  |
8 +     use alloc::vec::Vec;
  |
8 +     use allocator_api2::vec::Vec;
  |
8 +     use heapless::Vec;
  |
    and 1 other candidate

@Kohei316
Copy link
Contributor

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 9, 2025
…n, r=nnethercote

Make the compiler suggest actual paths instead of visible paths if the visible paths are through any doc hidden path.

close rust-lang#127011
Currently, when emitting a diagnostic about a valid trait, the compiler suggestes using visible paths of the trait even if they are through a doc hidden path. This PR updates the compiler to suggest actual paths in these cases.
@bors bors closed this as completed in 7494bd9 Apr 9, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 9, 2025
Rollup merge of rust-lang#139364 - Kohei316:feat/doc-hidden-suggestion, r=nnethercote

Make the compiler suggest actual paths instead of visible paths if the visible paths are through any doc hidden path.

close rust-lang#127011
Currently, when emitting a diagnostic about a valid trait, the compiler suggestes using visible paths of the trait even if they are through a doc hidden path. This PR updates the compiler to suggest actual paths in these cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
2 participants