-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
inline assist not working properly on Hash::hash
#16471
Comments
I'd like to work on this ticket; it seems simple enough for a starter issue. I have a test in |
Leaving the formatting issue aside for now, this does not reproduce either of the remaining issues: fn _write_u64(s: &mut u64, x: u64) {
*s += x;
}
fn _hash_nonmacro(inner_self_: &u64, state: &mut u64) {
_write_u64(state, *inner_self_)
}
fn _hash2_nonmacro(self_: &u64, state: &mut u64) {
// works fine
_hash_nonmacro(&self_, state);
} The fn _write_u64(s: &mut u64, x: u64) {
*s += x;
}
macro_rules! impl_write {
($(($ty:ident, $meth:ident),)*) => {$(
fn _hash(inner_self_: &u64, state: &mut u64) {
$meth(state, *inner_self_)
}
)*}
}
impl_write! { (u64, _write_u64), }
fn _hash2(self_: &u64, state: &mut u64) {
$0_hash(&self_, state);
} |
It looks like
which is missing spaces both after |
Macro expanded source lacks almost all whitespace because its not relevant in macro expansions. We need to fix the output up in the assist, there is some helper function for that somewhere but I forgot what its called. |
I can take a look in |
@rustbot claim |
To be added back later once we have a fix. See rust-lang#16471 and rust-lang#16497 (comment).
…ated-method, r=Veykril Fix incorrect inlining of functions that come from MBE macros Partial fix for #16471. As a reminder, there are two issues there: 1. missing whitespace in parameter types (the first test) 2. the `self` parameter not being replaced by `this` in the function body (the second test) The first part is fixed in this PR. See [this comment](#16497 (comment)) for the second.
The missing whitespace has been fixed by #16497; this assist should no longer produce invalid syntax (but the occurrence of |
@rustbot claim |
I have fixed both the second problem ( For the third question, the problem also lies in the expansion of macro. Should we assume an indent setting of 4 spaces when expanding macros for the third question? (Currently it is set to 2 spaces.) If we change it, it will affect other test cases which involving macro expansions. |
I hate that 😅. |
r-a currently assumes an indentation of 4 spaces for everything so that is fine |
fix: use 4 spaces for indentation in macro expansion Partial fix for #16471. In the previous code, the indentation produced by macro expansion was set to 2 spaces. This PR modifies it to 4 spaces for the sake of consistency.
got this bug again (rust-analyzer version: 0.4.1951-standalone) inlining let _ = [].iter().all(|&a: &i32| a == 2); gives this: let _ = {
let this = &mut [].iter();
let mutf = |&a: &i32| a == 2;
while let Some(x) = self.next(){
if!f(x){
return false;
}
}true
};
also, the |
rust-analyzer version: 0.4.1810-standalone
rustc version: rustc 1.75.0 (82e1608df 2023-12-21)
relevant settings: None
with this code,
place the cursor on
hash
inself.value.hash(state);
and apply the inline function assistthis is the result:
&mutH
should be&mut H
*self
should be*this
state.write_u64(*self)
only with 2, this is automatically fixed with the formatter but still doesnt look nicethe cause could be that the
Hash
impl foru64
is macro generated, but i dont know exactlyThe text was updated successfully, but these errors were encountered: