Skip to content
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

Kind checker is not aware of bounds on overloaded operators #2587

Closed
eholk opened this issue Jun 13, 2012 · 3 comments
Closed

Kind checker is not aware of bounds on overloaded operators #2587

eholk opened this issue Jun 13, 2012 · 3 comments
Labels
A-typesystem Area: The type system
Milestone

Comments

@eholk
Copy link
Contributor

eholk commented Jun 13, 2012

This leads to us copying things we shouldn't when the impl has a copy bound.

@eholk
Copy link
Contributor Author

eholk commented Aug 3, 2012

The problem seems to be here (in kind.rs):

fn check_copy_ex(cx: ctx, ex: @expr, implicit_copy: bool) {
    if ty::expr_is_lval(cx.method_map, ex) &&
       !cx.last_use_map.contains_key(ex.id) &&
       !is_nullary_variant(cx, ex) {
        let ty = ty::expr_ty(cx.tcx, ex);
        check_copy(cx, ex.id, ty, ex.span, implicit_copy);
    }
}

In the test case for #2548, the self argument is in last-use position, so this code doesn't count it as a copy. In cases of overloaded operators that require a copy bound, I'm not sure the last-use optimization is legal.

nikomatsakis added a commit that referenced this issue Aug 17, 2012
this will require more temporaries, but is probably less magical.
also, it means that borrowck matches trans better, so fewer crashes.
bonus.

Finally, stop warning about implicit copies when we are actually borrowing.

Also, one test (vec-res-add) stopped failing due to #2587, and hence I
added an xfail-test.

Fixes #3217, #2977, #3067
@ghost ghost assigned catamorphism Sep 6, 2012
@catamorphism
Copy link
Contributor

Reproduced again. I'll work on it.

@nikomatsakis
Copy link
Contributor

Here is the general sketch of a test case for this:



fn foo<T: copy>(+t: T) { ... }

fn bar<T>(+t: T) { ... }


fn main() {
   let v = something_noncopyable();
   foo::<SomethingNoncopyable>(move v); // BAD

   let w = something_noncopyable();
   bar(move w); // OK

   a + b
}

However, you have to rewrite it to use (1) overloaded operators, not function calls and (2) actual types :)

catamorphism added a commit that referenced this issue Sep 6, 2012
RalfJung pushed a commit to RalfJung/rust that referenced this issue Oct 22, 2022
add josh instructions

This explains how to sync Miri changes to and from rustc.
Aaron1011 pushed a commit to Aaron1011/rust that referenced this issue Jan 6, 2023
add josh instructions

This explains how to sync Miri changes to and from rustc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system
Projects
None yet
Development

No branches or pull requests

3 participants