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

Confusing and/or incorrect error with non-copyable types and FRU #4719

Closed
brson opened this issue Feb 1, 2013 · 3 comments
Closed

Confusing and/or incorrect error with non-copyable types and FRU #4719

brson opened this issue Feb 1, 2013 · 3 comments
Labels
A-type-system Area: Type system
Milestone

Comments

@brson
Copy link
Contributor

brson commented Feb 1, 2013

struct NonCopyable {
    x: (),
    f: NonCopyable2
}

struct NonCopyable2 {
    g: ()
}

impl NonCopyable2: Drop {
    fn finalize(&self) { }
}

fn main() {
    let a = NonCopyable { x: (), f: NonCopyable2 { g: () } };
    let b = NonCopyable {
        x: (),
        .. a
    };
}
/home/brian/dev/rust/src/test/run-pass/test.rs:16:8: 16:11 warning: unused variable: `b`
/home/brian/dev/rust/src/test/run-pass/test.rs:16     let b = NonCopyable {
                                                          ^~~
/home/brian/dev/rust/src/test/run-pass/test.rs:16:12: 16:23 error: copying a noncopyable value
/home/brian/dev/rust/src/test/run-pass/test.rs:16     let b = NonCopyable {
                                                              ^~~~~~~~~~~
error: aborting due to previous error

One of the fields in a is noncopyable and doesn't get moved into b. I think this should work as written, but if not then the error message should be better.

@nikomatsakis
Copy link
Contributor

Hmm, you know, a couple things:

  • The message is wrong but not for the reason you suggest. You are copying the field f from a which is non-copyable.
  • However, in fact I believe that a should be being moved here, which means that you are actually moving the field f from a which should be ok.

When doing my recent patch, I removed most of these "copyability" checks from kind.rs for this reason (that is, those copies would not actually be moves if the type were non-copyable) but I left this one. However, I think there is no need at all to check whether the base is non-copyable.

@nikomatsakis
Copy link
Contributor

So to be clear: I agree there should be no error reported here (clearly, though, if we were to report an error, we are using the wrong span).

nikomatsakis added a commit to nikomatsakis/rust that referenced this issue Feb 7, 2013
@nikomatsakis
Copy link
Contributor

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

2 participants