-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
borrowed pointers should be compared #3289
Comments
This certainly shouldn't compile. You can't compare two things that have different types (if you really want to compare the two pointers, you can use The first example looks like a bug, but @nikomatsakis should say for sure. |
I agree you can't compile with fn do_cmp(a: ~int, b: @int) because the two pointers will reference two regions of memory and the test will always be false. However, we can pass a shared bowed pointer to a function which expect a borrowed pointer so we should be able to do the comparison. I didn't found in the documentation a way to convert explicitly a shared pointer to a borrowed pointer. For example, we should be able to do something like this: |
The first example ought to work, I think, it's a bug in the type inferencer. Basically it should ensure that if you have an expression |
Regarding an explicit conversion to a borrowed pointer, the explicit way to write it for |
Perhaps this should be supported inherently. In the meantime, we have |
Reading the type check code, I see that there was a special bit of code for doing |
The example compiles, also with "b: @int" in the prototype. I think this bug can be closed? |
Agreed. |
Miri has used the `target/miri` subdirectory since 2021 to keep itself separate from non-miri builds, so this should not be necessary. See commit 6a18683 Since the items are no longer a sequence of steps to do in order ("first, make sure that ..."), switch to an unordered list while we're at it. Closes rust-lang#3289
Stop recommending cargo clean in README Miri has used the `target/miri` subdirectory since 2021 to keep itself separate from non-miri builds, so this should not be necessary. See commit 6a18683 Since the items are no longer a sequence of steps to do in order ("first, make sure that ..."), switch to an unordered list while we're at it. Closes rust-lang#3289
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)
The text was updated successfully, but these errors were encountered: