Skip to content

borrowed pointers should be compared #3289

Closed
@Vincent-Belliard

Description

@Vincent-Belliard

The following example try to compare two pointers:

fn do_cmp(a: &int, b: &int) {
io::println("do_cmp");
if a == b { io::println("same ref"); }
}

fn main() {
let a = @10;
let b = @10;
do_cmp(a, b);
do_cmp(a, a);
}

We have the following message:
try.rs:3:12: 3:13 error: mismatched types: expected &int but found &int (the anonymous lifetime #2 defined on the block at 1:28 does not necessarily outlive the anonymous lifetime #1 defined on the block at 1:28)
try.rs:3 if a == b { io::println("same ref"); }
^
error: aborting due to previous error

I think that it should compile. I think it should also compile if we have this prototype:
fn do_cmp(a: &int, b: @int)

Metadata

Metadata

Assignees

Labels

A-lifetimesArea: Lifetimes / regions

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions