-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: exclude extraction of code excluded by cfg
#18313
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
Merged
redsun82
merged 4 commits into
main
from
redsun82/rust-mute-warnings-in-uncompiled-blocks
Jan 8, 2025
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
218bc80
Rust: exclude extraction of code excluded by `cfg`
10d8aa4
Merge branch 'main' into redsun82/rust-mute-warnings-in-uncompiled-bl…
redsun82 ce2877d
Merge branch 'main' into redsun82/rust-mute-warnings-in-uncompiled-bl…
b481190
Rust: address review
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,4 @@ | ||||||||||||||||||||||||||||
| use super::mappings::{AddressableAst, AddressableHir, PathAst}; | ||||||||||||||||||||||||||||
| use crate::generated::MacroCall; | ||||||||||||||||||||||||||||
| use crate::generated::{self}; | ||||||||||||||||||||||||||||
| use crate::rust_analyzer::FileSemanticInformation; | ||||||||||||||||||||||||||||
| use crate::trap::{DiagnosticSeverity, TrapFile, TrapId}; | ||||||||||||||||||||||||||||
|
|
@@ -267,22 +266,22 @@ impl<'a> Translator<'a> { | |||||||||||||||||||||||||||
| expanded: SyntaxNode, | ||||||||||||||||||||||||||||
| ) -> Option<Label<generated::AstNode>> { | ||||||||||||||||||||||||||||
| match expand_to { | ||||||||||||||||||||||||||||
| ra_ap_hir_expand::ExpandTo::Statements => { | ||||||||||||||||||||||||||||
| ast::MacroStmts::cast(expanded).map(|x| self.emit_macro_stmts(x).into()) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| ra_ap_hir_expand::ExpandTo::Items => { | ||||||||||||||||||||||||||||
| ast::MacroItems::cast(expanded).map(|x| self.emit_macro_items(x).into()) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| ra_ap_hir_expand::ExpandTo::Statements => ast::MacroStmts::cast(expanded) | ||||||||||||||||||||||||||||
| .and_then(|x| self.emit_macro_stmts(x)) | ||||||||||||||||||||||||||||
| .map(Into::into), | ||||||||||||||||||||||||||||
| ra_ap_hir_expand::ExpandTo::Items => ast::MacroItems::cast(expanded) | ||||||||||||||||||||||||||||
| .and_then(|x| self.emit_macro_items(x)) | ||||||||||||||||||||||||||||
| .map(Into::into), | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| ra_ap_hir_expand::ExpandTo::Pattern => { | ||||||||||||||||||||||||||||
| ast::Pat::cast(expanded).map(|x| self.emit_pat(x).into()) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| ra_ap_hir_expand::ExpandTo::Type => { | ||||||||||||||||||||||||||||
| ast::Type::cast(expanded).map(|x| self.emit_type(x).into()) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| ra_ap_hir_expand::ExpandTo::Expr => { | ||||||||||||||||||||||||||||
| ast::Expr::cast(expanded).map(|x| self.emit_expr(x).into()) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| ra_ap_hir_expand::ExpandTo::Pattern => ast::Pat::cast(expanded) | ||||||||||||||||||||||||||||
| .and_then(|x| self.emit_pat(x)) | ||||||||||||||||||||||||||||
| .map(Into::into), | ||||||||||||||||||||||||||||
| ra_ap_hir_expand::ExpandTo::Type => ast::Type::cast(expanded) | ||||||||||||||||||||||||||||
| .and_then(|x| self.emit_type(x)) | ||||||||||||||||||||||||||||
| .map(Into::into), | ||||||||||||||||||||||||||||
| ra_ap_hir_expand::ExpandTo::Expr => ast::Expr::cast(expanded) | ||||||||||||||||||||||||||||
| .and_then(|x| self.emit_expr(x)) | ||||||||||||||||||||||||||||
| .map(Into::into), | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| pub(crate) fn extract_macro_call_expanded( | ||||||||||||||||||||||||||||
|
|
@@ -295,7 +294,7 @@ impl<'a> Translator<'a> { | |||||||||||||||||||||||||||
| let expand_to = ra_ap_hir_expand::ExpandTo::from_call_site(mcall); | ||||||||||||||||||||||||||||
| let kind = expanded.kind(); | ||||||||||||||||||||||||||||
| if let Some(value) = self.emit_expanded_as(expand_to, expanded) { | ||||||||||||||||||||||||||||
| MacroCall::emit_expanded(label, value, &mut self.trap.writer); | ||||||||||||||||||||||||||||
| generated::MacroCall::emit_expanded(label, value, &mut self.trap.writer); | ||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||
| let range = self.text_range_for_node(mcall); | ||||||||||||||||||||||||||||
| self.emit_parse_error(mcall, &SyntaxError::new( | ||||||||||||||||||||||||||||
|
|
@@ -559,4 +558,18 @@ impl<'a> Translator<'a> { | |||||||||||||||||||||||||||
| Some(()) | ||||||||||||||||||||||||||||
| })(); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| pub(crate) fn should_be_excluded(&self, item: &impl ast::HasAttrs) -> bool { | ||||||||||||||||||||||||||||
| let Some(sema) = self.semantics else { | ||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
| for attr in item.attrs() { | ||||||||||||||||||||||||||||
| if let Some((name, tokens)) = attr.as_simple_call() { | ||||||||||||||||||||||||||||
| if name == "cfg" && sema.check_cfg_attr(&tokens) == Some(false) { | ||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| false | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| for attr in item.attrs() { | |
| if let Some((name, tokens)) = attr.as_simple_call() { | |
| if name == "cfg" && sema.check_cfg_attr(&tokens) == Some(false) { | |
| return true; | |
| } | |
| } | |
| } | |
| false | |
| item.attrs().any(|attr| { | |
| attr.as_simple_call().is_some_and(|(name, tokens)| { | |
| name == "cfg" && sema.check_cfg_attr(&tokens) == Some(false) | |
| }) | |
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.