Skip to content

Unconstrained region variables when making str-ptr-ptr hash and eq #3283

Closed

Description

@pcwalton

Test case:

pure fn view_hash(s: & &str) -> uint {
    hash::hash_str(*s) as uint
}

pure fn view_eq(a: & &str, b: & &str) -> bool {
    str::eq_slice(*a, *b)
}

fn main() {
    let map = send_map::linear::linear_map(view_hash, view_eq);
    map.insert("foo", ());
}

Errors:

/home/pcwalton/Source/rust/build/test.rs:11:58: 11:65 error: Unconstrained region variable #3
/home/pcwalton/Source/rust/build/test.rs:11         let map = send_map::linear::linear_map(view_hash, view_eq);
                                                                                                      ^~~~~~~
/home/pcwalton/Source/rust/build/test.rs:11:58: 11:65 error: Unconstrained region variable #4
/home/pcwalton/Source/rust/build/test.rs:11         let map = send_map::linear::linear_map(view_hash, view_eq);

If the functions become inline lambdas, the problem goes away.

@nikomatsakis, any ideas?

Activity

  1. bblum commented on Aug 26, 2012

    @bblum
    Contributor

    I was fiddling around with regioned stack closures, trying to see if it'd ever mean something to return one, and ran into the same error for the first time:

    fn foo(+blk: fn(+p: &a/fn() -> &a/fn())) {
        let mut state = 0;
        let statep = &mut state;
        do blk {
            || { *statep = 1; }
        }
    }
    fn main() {
        do foo |p| { p()() }
    }
    
    
    frames.rs:1:0: 1:0 error: Unconstrained region variable #8
    frames.rs:1 fn foo(+blk: fn(+p: &a/fn() -> &a/fn())) {
                ^
    frames.rs:1:0: 1:0 error: Unconstrained region variable #10
    frames.rs:1 fn foo(+blk: fn(+p: &a/fn() -> &a/fn())) {
                ^
    
  2. catamorphism commented on Dec 7, 2012

    @catamorphism
    Contributor

    @pcwalton 's example no longer works since the linear_map function being used is now trait-based, rather than taking functions explicitly. I get a different error with @bblum's example:

    /Users/tchevalier/rust2/src/test/run-pass/issue-3283.rs:4:11: 6:5 error: mismatched types: expected `&fn()` but found `@fn()` (expected & closure, found @ closure)
    /Users/tchevalier/rust2/src/test/run-pass/issue-3283.rs:4     do blk {
    /Users/tchevalier/rust2/src/test/run-pass/issue-3283.rs:5         || { *statep = 1; }
    /Users/tchevalier/rust2/src/test/run-pass/issue-3283.rs:6     }
    

    I don't know if that's right or not.

  3. catamorphism commented on Mar 20, 2013

    @catamorphism
    Contributor

    bblum's example compiles now (if you add a & before the fn type of blk), and pcwalton's example won't compile now for other reasons. So I'm considering this done. Reopen if you have a repro case

  4. catamorphism commented on Mar 25, 2013

    @catamorphism
    Contributor

    bblum's example compiled and ran just fine on my Mac, but segfaulted on the Linux and Windows bots. I don't have time right now to figure out why, so I'm checking it in xfailed.

  5. nikomatsakis commented on Mar 29, 2013

    @nikomatsakis
    Contributor

    I think this system should not type check. This is probably a bug in how we are handling region closures (I know there is work to be done there, not sure what bug #, let me fish it up).

  6. nikomatsakis commented on Mar 29, 2013

    @nikomatsakis
    Contributor

    Dup of issue #3696, I think.

  7. added a commit that references this issue on Feb 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regions

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions