-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Ignore disallowed_types
in foreign macros
#12571
base: master
Are you sure you want to change the base?
Ignore disallowed_types
in foreign macros
#12571
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @xFrednet (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
@@ -66,6 +68,11 @@ impl DisallowedTypes { | |||
} | |||
|
|||
fn check_res_emit(&self, cx: &LateContext<'_>, res: &Res, span: Span) { | |||
if in_external_macro(cx.sess(), span) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in_external_macro
is kinda... buggy? I assume, it doesn't detects macros with spanned quote for some reason.
So, if you have a macro defined like this:
#[proc_macro_attribute]
pub fn use_std_hash_map(_args: TokenStream, input: TokenStream) -> TokenStream {
let mut item = syn::parse_macro_input!(input as syn::ItemFn);
let span = item.block.brace_token.span;
let block = item.block;
item.block = syn::parse_quote_spanned! {
span =>
{
let _ = std::collections::HashMap::<i32, i32>::default();
}
};
quote! {#item}.into()
}
It still triggers this lint, I think you'll need a clippy_utils::is_from_proc_macro
check additionally.
Is this change motivated by some kind of "real" example? I think it would be reasonable that users might still want to be warned when macro-generated code uses a disallowed type? For example a program intended to be compiled to webassembly might want to disallow |
In my case I had this issue with struct InternalApi {
...
}
#[OpenApi(tag = "super::ApiTags::Tables")]
impl InternalApi {
...
} The problem is usage of disallowed types generated by the macro. And the only way to ignore it is to set May be we could add an attribute |
I'd suggest adding a configuration value instead. Something like |
changelog: [
disallowed_types
]: do not trigger in foreign macros