Skip to content

weak type inference on late-bound lifetime within Option  #15112

Closed
@pnkfelix

Description

@pnkfelix

Spawned off of #10846 and #15061 (comment)

Example code:

fn main() {
    fn test1(_x: Option< <'a> |y: &'a int|>) {}
    fn test2(_x: Option< |y: &'static int|>) {}
    #[cfg(show_bug)]
    fn siegelord_fn() { test1(Some(|_y      | {})); }
    #[cfg(not(show_bug))]
    fn siegelord_fn() { test1(Some(|_y: &int| {})); }
    fn static_serfn() { test2(Some(|_y      | {})); }

    siegelord_fn();
    static_serfn();
}

Transcript of results:

% ./objdir-dbgopt/x86_64-apple-darwin/stage1/bin/rustc bar.rs 
% ./objdir-dbgopt/x86_64-apple-darwin/stage1/bin/rustc --cfg show_bug bar.rs 
bar.rs:5:31: 5:50 error: mismatched types: expected `core::option::Option<|&'a int|>` but found `core::option::Option<|<generic #1>|>` (expected concrete lifetime, but found bound lifetime parameter 'a)
bar.rs:5     fn siegelord_fn() { test1(Some(|_y      | {})); }
                                       ^~~~~~~~~~~~~~~~~~~
note: expected concrete lifetime is lifetime ReInfer(ReSkolemized(0u, BrNamed(syntax::ast::DefId{krate: 0u32, node: 20u32}, 59u32)))
error: aborting due to previous error
% 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions