Skip to content

return statements in inlined functions just get moved over and try to return out of the outer function + generic types are discarded #15471

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

Open
antonilol opened this issue Aug 16, 2023 · 1 comment
Labels
A-assists C-bug Category: bug

Comments

@antonilol
Copy link

title,

code example

fn none<T>() -> Option<T> {
    return None;
}

pub fn main() {
    let a = none::<u32>();
}
  • inlining the none function replaces it with let a = { return None; };, which tries to return None in main
  • the generic type param T of none was first known to be u32, to preserve this information (and not end up with "type annotations needed for Option<T>") let a = None::<u32>; would work

rust-analyzer version: 0.4.1625-standalone

rustc version: rustc 1.71.1 (eb26296b5 2023-08-03)

relevant settings: none

@antonilol antonilol added the C-bug Category: bug label Aug 16, 2023
@antonilol antonilol changed the title return statements in inlined function just get moved over and try to return out of the outer function + generic types are discarded return statements in inlined functions just get moved over and try to return out of the outer function + generic types are discarded Aug 16, 2023
@TieWay59
Copy link

TieWay59 commented Jan 16, 2024

Also tested on: rust-analyzer version: 0.4.1808-standalone (a616c4d 2024-01-15)

fn main() {
    // let a = none::<u32>(); yeild:
    let a = {
        return None;
    };

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

No branches or pull requests

3 participants