Skip to content

Hygiene not taken into account for name resolution (wrong type inference with izip!) #11681

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

Closed
flodiebold opened this issue Mar 11, 2022 · 1 comment · Fixed by #18264
Closed
Labels
A-hygiene A-macro macro expansion A-ty type system / type inference / traits / method resolution C-bug Category: bug

Comments

@flodiebold
Copy link
Member

In this line:
https://github.com./rust-analyzer/rust-analyzer/blob/69e5bd5a2532cfe47e5517d720eb70cbf3f4a908/crates/ide_assists/src/handlers/inline_call.rs#L347
we infer the wrong type for expr, namely we infer Vec<PathExpr>. The reason for this seems to be our expansion of the izip!(params, param_use_nodes, arguments) macro call:

$crate::__std_iter::IntoIterator::into_iter(params).zip(param_use_nodes).zip(arguments).map(|((a,b),b)|(a,b,b))

note the .map(|((a,b),b)| (a,b,b)). This seems to be a hygiene issue, where the different bs come from different macro expansions and so we need to consider hygiene to correctly resolve them.

Part of #8961.

@flodiebold flodiebold added A-ty type system / type inference / traits / method resolution A-macro macro expansion C-bug Category: bug labels Mar 11, 2022
@lnicola
Copy link
Member

lnicola commented Jun 20, 2024

Another example from #17448:

use itertools::izip;

fn main() {
    let mut yp_sn = vec![0;5];
    let yp = vec![0;5];
    let x = vec![0;5];
    for (x, yp_sn, _yp) in izip!(x, yp_sn.iter_mut(), yp) {
        *yp_sn = x;
    }
}

, which triggers a false positive cannot mutate immutable variable. Most likely will be fixed by adding hygiene, but it's still worth testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-hygiene A-macro macro expansion A-ty type system / type inference / traits / method resolution C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants