Skip to content

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

Closed

Description

@eholk

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

Activity

  1. eholk commented on Aug 3, 2012

    @eholk
    ContributorAuthor

    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.

  2. catamorphism commented on Sep 6, 2012

    @catamorphism
    Contributor

    Reproduced again. I'll work on it.

  3. nikomatsakis commented on Sep 6, 2012

    @nikomatsakis
    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 :)

  4. added a commit that references this issue on Sep 6, 2012
  5. added a commit that references this issue on Jan 6, 2023
  6. added a commit that references this issue on Sep 22, 2025
  7. added a commit that references this issue on Aug 21, 2026
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

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions