-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Inlining function defined in macro produces incorrect results (concatenated tokens). #12860
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
Comments
Additionally, when inlining methods defined in macros, struct Test;
macro_rules! define_method {
() => {
impl Test {
fn test_method_macro(&self) {
match self {
Test => println!("Test!")
}
}
}
};
}
define_method!();
fn main() {
Test.test_method_macro();
} becomes // ...
fn main() {
{
let ref this = Test; matchself{Test=>println!("Test!")}};
} when inlining |
I inserted a My (limited, possibly wrong) understanding of what is happening (for the whitespace problem, no idea about Maybe it would be easier to just insert whitespace between tokens which cannot be adjacent? This is probably also required for inlining functions defined in proc-macros to work, since in that case there is no "original whitespace" that could even be kept. Does rust-analyzer have a way to determine if a function was defined in a macro? rustc appears to have this (at least at some level), since if a function defined in a macro contains an error, it will say Footnotes
|
Yes, macro expansions have no whitespace. This is a recurring thing and currently we just check for whether things come from a macro expansion in whicch ase we do whitespace insertion via https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-db/src/syntax_helpers/insert_whitespace_into_node.rs |
Rust-analyzer's "Inline <function>" code action fails1 when the function to be inlined is defined in a macro.
Result when selecting
test_macro(true)
and running the "Inline `test_macro`" action: (at leastif
andx
should be separated)Result when selecting
test_free(true)
and running the "Inline `test_free`" action: (to show that the issue only happens for functions defined in macros)The problem also occurs in associated functions/methods. I originally ran into this error when trying to inline
usize::next_multiple_of
, which is defined in a macro.rust-analyzer version: (eg. output of "Rust Analyzer: Show RA Version" command)
rust-analyzer version: 0.4.1138-standalone (977e12a 2022-07-23)
("Pre-Release" version on VSCode)
(Also happens on normal version on VSCode, rust-analyzer version: 0.3.1131-standalone (897a7ec 2022-07-17))
rustc version: (eg. output of
rustc -V
)rustc 1.62.1 (e092d0b6b 2022-07-16)
relevant settings: (eg. client settings, or environment variables like
CARGO
,RUSTUP_HOME
orCARGO_HOME
)None that I am aware are relevant.
Footnotes
It succeeds but does not produce correct code if any sequential tokens need to be separated by spaces. ↩
The text was updated successfully, but these errors were encountered: