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

Add "diagnostic items" which behave like lang items #39131

Closed
Manishearth opened this issue Jan 17, 2017 · 2 comments · Fixed by #60966
Closed

Add "diagnostic items" which behave like lang items #39131

Manishearth opened this issue Jan 17, 2017 · 2 comments · Fixed by #60966
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Manishearth
Copy link
Member

Manishearth commented Jan 17, 2017

It would be nice to have a (rustc-only) system of that lets us annotate structs with things like #[diagnostic_item="String"].

This lets us improve the diagnostics in special cases involving that type (e.g. #39116 (comment)). Clippy currently string-compares the path to do this, but that's hacky and I would rather we avoided that code in rustc.

It's something that would only get hit when we have an error case, so we probably can just store these in a hash map or something.

cc @jonathandturner @nikomatsakis

@brson brson added I-wishlist T-lang Relevant to the language team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Jan 18, 2017
@Mark-Simulacrum Mark-Simulacrum added C-feature-request Category: A feature request, i.e: not implemented / a PR. A-diagnostics Area: Messages for errors, warnings, and lints and removed I-wishlist labels Jul 26, 2017
@Manishearth
Copy link
Member Author

More details in #58070 (comment)

cc @oli-obk @phansch

@Manishearth
Copy link
Member Author

Copying over the relevant comment:

We add a new attribute to the compiler: #[diagnostic = "debug_trait"] and similar so we can stop checking for lang items and instead just check for diagnostic-specific items.

This will be a bit more involved. Essentially we need to

  1. duplicate the get_lang_items query. Though I don't think there's any point in having a method per diagnostic item.
  2. So I suggest we just make the query return a FxHashMap<Symbol, NodeId>.
  3. We can then build a wrapper method on the TyCtxt that maps a &str to an Option<NodeId> for user convenience
  4. Throw the new attribute on a bunch of types (basically go through https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/utils/paths.rs and just flag all the things in that list)
  5. see if there are any rustc diagnostics that could benefit from this
  6. replace all uses of util/path.rs with a use of the &str -> Option<NodeId> method
  7. complain to @oli-obk that they didn't think this through and there's uses of util/path.rs that do something different
  8. figure out if we need any of this in EarlyLintPasses and make them LateLintPasses
  9. see 7.

@Manishearth Manishearth added the A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. label Apr 7, 2019
@oli-obk oli-obk added E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Apr 8, 2019
@bors bors closed this as completed in c7d4df0 Aug 30, 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 A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. 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