Closed
Description
rust-analyzer version: 0.3.1334-standalone (74ae2dd 2022-12-25)
rustc version: rustc 1.67.0-nightly
relevant settings: None?
Description
In a particular context, type inference fails and RA does not show the type of a variable assigned to a function's return value. This is caused by the presence of a use
statement in a function.
Steps to reproduce
- Inside an outer function definition...
- Define one struct,
S1
- And give
S1
a methodget_pair(self)
that returns a 2-tuple - Define a second struct,
S2
, that contains an instance ofS1
- And give
S2
a method that both 1. has ause
statement and 2. callss1.get_pair()
Bug
The presence of the use
statement causes type inference of the return type of s1.get_pair()
to fail
Code snippet
As far as I know this snippet is minimal.
fn f() {
struct S1;
impl S1 {
fn get_one(self) -> i32 {
0
}
fn get_pair(self) -> (i32, i32) {
(0, 0)
}
}
struct S2 {
s1: S1,
}
impl S2 {
fn no_fail_1(self) -> i32 {
use std::path;
let x = self.s1.get_one(); // let x: i32
x
}
fn no_fail_2(self) -> i32 {
let pair = self.s1.get_pair(); // let pair: (i32, i32)
pair.0
}
fn fail(self) -> i32 {
use std::path;
let pair = self.s1.get_pair(); // let pair: {unknown}
pair.0
}
}
}