Skip to content

'inline function' assist does not take as Self casts into account #16091

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
antonilol opened this issue Dec 11, 2023 · 2 comments · Fixed by #16114
Closed

'inline function' assist does not take as Self casts into account #16091

antonilol opened this issue Dec 11, 2023 · 2 comments · Fixed by #16114
Labels
C-bug Category: bug

Comments

@antonilol
Copy link

rust-analyzer version: 0.4.1765-standalone

rustc version: rustc 1.74.0 (79e9716c9 2023-11-13)

relevant settings: None

before:

struct MyStruct {
    number: usize,
}

impl MyStruct {
    fn new(number: usize) -> Self {
        Self { number } as Self
    }
}

// example 1
let s = MyStruct::new(123);

// example 2
let n = u64::from(123u32);

after (actual):

struct MyStruct {
    number: usize,
}

impl MyStruct {
    fn new(number: usize) -> Self {
        Self { number } as Self
    }
}

// example 1
let s = {
    let number = 123;
    MyStruct { number } as Self
};

// example 2
let n = {
    let small = 123u32;
    small as Self
};

after (expected):

struct MyStruct {
    number: usize,
}

impl MyStruct {
    fn new(number: usize) -> Self {
        Self { number } as Self
    }
}

// example 1
let s = {
    let number = 123;
    MyStruct { number } as MyStruct
};

// example 2
let n = {
    let small = 123u32;
    small as u64
};

Self should be changed to what the Self type was in the function (MyStruct or u64 here)

found after reporting #16090, might have the exact same fix but i have little experience here with the codebase

@roife
Copy link
Member

roife commented Dec 13, 2023

I have submitted a PR that addressed this issue

@bors bors closed this as completed in 306defa Jan 2, 2024
@antonilol
Copy link
Author

thanks, can confirm this is fixed

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