-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Lint for trait methods without bodies #2367
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
Lint for trait methods without bodies #2367
Conversation
I think this should some day be caught by the |
@oli-obk do we have a mechanisms for suggestions that just remove code? We could use that here. |
Right. Should be as simple as changing the |
This has the downside of only removing the attribute itself, not the line it was on. This is a bit tricky because technically attributes do not need to be on their own line so we can't unconditionally kill the line. Also, It'd be possible to add something like |
Hm, what does |
Something like this: let mut remove_span = attr.span;
let fmpos = cx.sess().codemap().lookup_byte_offset(remove_span.next_point().hi());
if let Some(ref src) = fmpos.fm.src {
let non_whitespace_offset = src[fmpos.pos.to_usize()..].find(|c| {
c != ' ' && c != '\t' && c != '\n'
});
if let Some(non_whitespace_offset) = non_whitespace_offset {
remove_span = remove_span.with_hi(remove_span.hi() + BytePos(non_whitespace_offset as u32))
}
} ? Would that be worth pulling it to a helping function and using it for |
I pushed a commit that suggests removing the attribute. Let me know what you think. |
The issue is that the normal diagnostics now also hilight the |
@oli-obk Would that be a blocker for merging this PR? |
Yes
No, because it'll only be done in the command line diagnostics, not the json diagnostics
Nope. We'll see the ui tests breaking when it gets fixed :) |
You need to rebase/merge the current master and update the ui tests again. Something changed with the error reporting |
As discussed in rust-lang/rust#47475 the #[inline] attribute is currently allowed on trait methods without bodies (i.e. without a default implementation). This is misleading as it could be interpreted as affecting the implementations of the trait method. Add a lint for any use of #[inline] on a trait method without a body. Fixes rust-lang/rust#47475
This adds a `suggest_remove_item` helper that will remove an item and all trailing whitespace. This should handle both attributes on the same line as the function and on a separate line; the function takes the position of the original attribute.
Thanks! |
As discussed in rust-lang/rust#47475 the #[inline] attribute is currently allowed on trait methods without bodies (i.e. without a default implementation). This is misleading as it could be interpreted
as affecting the implementations of the trait method. Add a lint for any use of #[inline] on a trait method without a body.
Fixes rust-lang/rust#47475