-
Notifications
You must be signed in to change notification settings - Fork 1.8k
rust-analyzer flags an E0308 error when rustc does not, connected to Itertools::collect_tuple
#17039
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
I'll see if I can minimize this. |
https://github.com/sourcefrog/rust-analyzer-17039-repro has a self contained crate that reproduces the error. In that tree, With this slightly shorter code: fn known_map(path: &Path) -> Option<(&Ident, &Type, &Type)> {
let last = path.segments.last()?;
if let PathArguments::AngleBracketed(AngleBracketedGenericArguments { args, .. }) =
&last.arguments
{
if let Some((GenericArgument::Type(key_type), GenericArgument::Type(value_type))) =
args.iter().collect_tuple()
{
return Some((&last.ident, key_type, value_type));
}
}
None
} VSCode shows that rust-analyzer thinks that rust-analyzer thinks that If I break it into smaller statements like this then it seems to infer the right types let arg_iter = args.iter();
let tup: Option<(_, _)> = arg_iter.collect_tuple();
if let Some((GenericArgument::Type(key_type), GenericArgument::Type(value_type))) =
tup
{
return Some((&last.ident, key_type, value_type));
} However if the let arg_iter = args.iter();
if let Some((GenericArgument::Type(key_type), GenericArgument::Type(value_type))) =
arg_iter.collect_tuple()
{
return Some((&last.ident, key_type, value_type));
} I tried to remove the fn known_map(args: &[GenericArgument]) -> Option<(&Type, &Type)> {
let arg_iter = args.iter();
if let Some((GenericArgument::Type(key_type), GenericArgument::Type(value_type))) =
arg_iter.collect_tuple()
{
return Some((key_type, value_type));
}
None
} I'm not blocked on this; there are other ways to write it and I thought of some simpler things while experimenting here. I'm just filing in the hope the report is useful. |
struct Struct;
enum Enum {
Variant(Struct),
}
fn f() -> Option<(&Struct, &Struct)> {
use itertools::Itertools;
let arg_iter = vec![&Enum::Variant(Struct)].iter();
if let Some((Enum::Variant(thing), Enum::Variant(thing2))) = arg_iter.collect_tuple() {
return Some((thing, thing2));
}
None
} reproduces this. Now to get rid of the itertools dependency |
Itertools::collect_tuple
So it seems to be connected to fn collect_tuple<T>(mut self) -> Option<T>
where
Self: Sized + Iterator<Item = T::Item>,
T: traits::HomogeneousTuple {} I guess rustc and rust-analyzer infer different types for |
Slight readability improvements. Also slight reference-taking changes to go around the newly occuring issue rust-lang/rust-analyzer#17039 where needed.
rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)
0.3.1916-standalone
rustc version: (eg. output of
rustc -V
)rustc 1.77.1 (7cf61ebde 2024-03-27)
editor or extension: (eg. VSCode, Vim, Emacs, etc. For VSCode users, specify your extension version; for users of other editors, provide the distribution if applicable)
VSCode v0.3.1916
relevant settings: (eg. client settings, or environment variables like
CARGO
,RUSTC
,RUSTUP_HOME
orCARGO_HOME
)repository link (if public, optional): (eg. rust-analyzer)
sourcefrog/cargo-mutants@7901e6d
code snippet to reproduce:
Apply this patch to the commit shown above:
What I would expect is that either rustc and rust-analyzer both accept this, or they both reject it.
What happens is that
cargo build
passes (on today's stable, beta, and nightly), but rust-analyzer flags two errors:The text was updated successfully, but these errors were encountered: