Skip to content

make easier/possible to detect derive attributes after expansion #45216

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

Open
zackmdavis opened this issue Oct 11, 2017 · 4 comments
Open

make easier/possible to detect derive attributes after expansion #45216

zackmdavis opened this issue Oct 11, 2017 · 4 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@zackmdavis
Copy link
Member

zackmdavis commented Oct 11, 2017

In the spirit of #44942, it would be nice if the missing_debug_implementations and missing_copy_implementations lints suggested adding a derive attribute (in the case where one does not already exist) or adding Debug (respectively Copy) to the list of traits in the derive attribute (in the case where it already exists). (This mostly for the sake of RLS and other tools, but the span highlighting is pretty, too.) But while the lints (obviously, necessarily) know how to look up whether the trait has been implemented, it's not clear how to make them detect an existing derive attribute (and its span): cx.tcx.get_attrs doesn't work because we apparently strip off the attribute during expansion (it looks like this happens twice, which is confusing: 1 2). But I can't modify the expansion code because I'm still not smart enough to understand it.

@TimNN TimNN added C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 17, 2017
@zackmdavis
Copy link
Member Author

Stripping derive has also created problems elsewhere.

@zackmdavis
Copy link
Member Author

cc @oli-obk @jseyfried ?

@jseyfried
Copy link
Contributor

I think it would be reasonable to avoid stripping derives.

@zackmdavis

it looks like this happens twice, which is confusing: 1 [2](https://github.com/rust-lang/rust/blob/cbf5d39cca/src/libsyntax/ext/derive.rs#L25-L27

The second link is only stripping empty derives and erroneous derives (after emitting an error/warning) -- the second match arm is the successful case and retains the derive. Feel free to ping me on IRC to discuss how to proceed.

@Enselic
Copy link
Member

Enselic commented Oct 3, 2023

Triage: Currently the suggestion looks like this:

#![warn(missing_debug_implementations)]

#[derive(Clone)]
pub struct MissingDebug;

fn main() {
}
warning: type does not implement `Debug`; consider adding `#[derive(Debug)]` or a manual implementation
 --> src/main.rs:4:1
  |
4 | pub struct MissingDebug;
  | ^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![warn(missing_debug_implementations)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

If I understand this issue correctly, it is about enabling the suggestion to be more specific by taking into account currently present derives. Maybe something like:

warning: type does not implement Debug; consider adding Debug to #[derive(Clone, ...)] or a manual implementation

@Enselic Enselic added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-feature-request Category: A feature request, i.e: not implemented / a PR. 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