Skip to content

Chains of tuple access are incorrectly typed unless broken up #10560

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
kythyria opened this issue Oct 17, 2021 · 1 comment · Fixed by #12149
Closed

Chains of tuple access are incorrectly typed unless broken up #10560

kythyria opened this issue Oct 17, 2021 · 1 comment · Fixed by #12149
Labels
C-bug Category: bug

Comments

@kythyria
Copy link

VSCode: 1.61.1
OS: Windows 10
Rust-analyser: 0.2.776

This code compiles, but is handled incorrectly by RA:

use std::rc::Rc;
use std::collections::HashMap;

struct DocumentData {
    tables: Vec<TableData>
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct TableId(usize);

struct TableData {
    everything_else_hash: HashMap<String, String>
}

pub struct TableRef(Rc<DocumentData>, TableId);
impl TableRef {
    pub fn get_item_bug(&self, item: &String) -> Option<String> {
        let tid = self.1.0;
        self.0.tables[tid].everything_else_hash.get(item).map(Clone::clone)
    }

    pub fn get_item_correct(&self, item: &String) -> Option<String> {
        let ti = self.1;
        let tid = ti.0;
        self.0.tables[tid].everything_else_hash.get(item).map(Clone::clone)
    }
}

Specifically, in get_item_bug:

  • Tooltip of tid reads let tid: Rc<DocumentData> (should be usize)
  • everything_else_hash and get are displayed with the "nonexistent item" formatting (should be field and method respectively)
  • Their tooltips read {unknown} and highlight the entire line up to that point.
  • map is incorrectly listed as being Iterator::map rather than Option::map

None of get_item_correct has this, nor does rustc itself report any errors

@Veykril
Copy link
Member

Veykril commented Oct 17, 2021

Probably a dupe of #1109

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants