Skip to content

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

Closed
@kythyria

Description

@kythyria

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions