Skip to content

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

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
pnkfelix opened this issue Jun 23, 2014 · 2 comments
Closed

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

pnkfelix opened this issue Jun 23, 2014 · 2 comments
Labels
A-type-system Area: Type system

Comments

@pnkfelix
Copy link
Member

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
% 
@pnkfelix
Copy link
Member Author

Niko had some ideas on friday for ways we might try to improve things here.

Some of them were integrated into more long-term cleanup of the type-inference code, such as moving to a cleaner model of constraint generation + solving. Others were, for lack of a better term, "hacks" that we might adopt in the short-term, such as attempting to unify the return types of call-expressions first (that is, before doing type inference for the argument expressions), and using the constraints garnered from that to inform the types inferred for the arguments.

@pnkfelix pnkfelix changed the title type inference is weak on 2nd order closure within Option with late-bound lifetimes type inference is weak on closure with late-bound lifetime within Option Jun 23, 2014
@pnkfelix pnkfelix changed the title type inference is weak on closure with late-bound lifetime within Option weak type inference on closure with late-bound lifetime within Option Jun 23, 2014
@pnkfelix pnkfelix changed the title weak type inference on closure with late-bound lifetime within Option weak type inference on late-bound lifetime within Option Jun 23, 2014
@steveklabnik
Copy link
Member

https://botbot.me/mozilla/rust/2015-02-11/?msg=31713574&page=1

@huonw: steveklabnik: seems to work now

bors added a commit to rust-lang-ci/rust that referenced this issue Jul 17, 2023
Support manual impl of fn traits in mir interpreter

Increases passed tests from 48 to 49 :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

2 participants