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

provide suggestions for typoed attributes #49270

Closed
matthiaskrgr opened this issue Mar 22, 2018 · 2 comments
Closed

provide suggestions for typoed attributes #49270

matthiaskrgr opened this issue Mar 22, 2018 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

#[marco_use]
extern crate clap

It would be nice to have typo suggestions for mistyped attributes.
Maybe something like

 --> src/main.rs:1:1
  |
1 | #[marco_use]
  | ^^^^^^^^^^^^
  |
  = help: add #![feature(custom_attribute)] to the crate attributes to enable
  = help: you could try the attribute 'macro_use'
@abonander
Copy link
Contributor

What attributes should this search for? Built-ins only? Imported proc-macro attributes?

@pietroalbini pietroalbini added C-enhancement Category: An issue proposing an enhancement or a PR with one. 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 Mar 27, 2018
@HeroicKatora
Copy link
Contributor

HeroicKatora commented Sep 3, 2018

A mechanism similar to the current suggestions for unscoped methods would suggest itself. With the added difficulty that of course macros are not available through explicit import (or the prelude), I would prefer have the compiler mention which instance of #[macro_use] is responsible for the suggest macro but I don't think this is required in most instances.

The main issue I had with the current mechanism are that the warning becomes

error[E0658]: The attribute `tests` is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
 --> src/lib.rs:1:1
  |
1 | #[tests]
  | ^^^^^^^^

error: aborting due to previous error

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

where E0658 only refers to switching to nightly and adding additional feature gates.

An unstable feature was used.

Erroneous code example:

[…]

If you're using a stable or a beta version of rustc, you won't be able to use
any unstable features. In order to do so, please switch to a nightly version of
rustc (by using rustup).

This particular explanation does not seem helpful in that situation and only creates more confusion. The offered description simply does not apply, no unstable feature has been used, else the compiler would suggest a concrete feature gate as well (right?).

Centril added a commit to Centril/rust that referenced this issue Jan 28, 2019
add typo suggestion to unknown attribute error

Provides a suggestion using Levenshtein distance to suggest built-in attributes and attribute macros.

Fixes rust-lang#49270.
@bors bors closed this as completed in d3bb907 Jan 29, 2019
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 C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants