zonyitoo/context-rs

Make the Context::load back to diverging function

zonyitoo opened this issue · 5 comments

Because of #3 , the -> ! mark was removed from the definition of Context::load, but I just use the latest nightly version of rustc, it seems that it won't generate any warning right now. So I think it is a good time to bing that back.

Here is the test code:

extern crate context;

use context::Context;

fn main() {
    let mut flag = Box::new(false);

    let mut context = Context::empty();
    Context::save(&mut context);

    if !*flag {
        *flag = true;
        println!("Modifing the flag ...");
        Context::load(&context);
    }

    println!("Now it becomes true");
}

Rustc version

rustc 1.5.0-nightly (9d3e79ad3 2015-10-10)

@Xudong-Huang @dpc Are you guys both agree with this change?

dpc commented

👍

well, in generator library, I add a "return val instruction" after the load() function
this would give the compiler a chance to check if the val is the correct type to yield.

with diverging load, this check can't be done. very confused, but this is the best way that I can think.

go ahead with your changes, or you can add another function signature for the non-diverging version.

if this is not acceptable, I have to keep my own branch.

dpc commented

The fact is load() never returns. That's exactly what -> ! is for. The previous error/warning was a compiler bug.

@Xudong-Huang : I don't understand what exactly you're doing. Can you point to some code? It seems to me that either:

  • there should be some #[allow(something)] for whatever you're doing
  • it should be possible to use unsafe to trick compiler into accepting whatever is happening (maybe by wrapping Context::load() into another function or something like this.

@Xudong-Huang I am confused, too. Even you have written return val instruction after the Context::load function, it will never have a chance to run.