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

Rvalues are incorrectly expected to have unsized types. #20169

Closed
eddyb opened this issue Dec 23, 2014 · 0 comments · Fixed by #20083
Closed

Rvalues are incorrectly expected to have unsized types. #20169

eddyb opened this issue Dec 23, 2014 · 0 comments · Fixed by #20083

Comments

@eddyb
Copy link
Member

eddyb commented Dec 23, 2014

This appears to be a long-standing issue with blocks, recently exposed in match by #19769.
Original error by @steveklabnik (source code):

<std macros>:3:22: 3:40 error: mismatched types: expected `error::Error`, found `collections::string::String` (expected trait error::Error, found struct collections::string::String)
<std macros>:3         format_args!(::std::fmt::format, $($arg)*)
                                    ^~~~~~~~~~~~~~~~~~
note: in expansion of format_args!
<std macros>:3:9: 3:51 note: expansion site
<std macros>:1:1: 5:2 note: in expansion of format!
src/build.rs:113:36: 116:34 note: expansion site
src/build.rs:113:32: 116:45 error: the trait `core::kinds::Sized` is not implemented for the type `error::Error`
src/build.rs:113                     return Err(box format!("{}\n{}",
src/build.rs:114                                            String::from_utf8_lossy(output.output[]),
src/build.rs:115                                            String::from_utf8_lossy(output.error[]))
src/build.rs:116                                as Box<Error>);
src/build.rs:113:32: 116:45 note: only sized types can be made into objects
src/build.rs:113                     return Err(box format!("{}\n{}",
src/build.rs:114                                            String::from_utf8_lossy(output.output[]),
src/build.rs:115                                            String::from_utf8_lossy(output.error[]))
src/build.rs:116                                as Box<Error>);
src/build.rs:113:32: 116:45 error: the trait `error::Error` is not implemented for the type `error::Error`
src/build.rs:113                     return Err(box format!("{}\n{}",
src/build.rs:114                                            String::from_utf8_lossy(output.output[]),
src/build.rs:115                                            String::from_utf8_lossy(output.error[]))
src/build.rs:116                                as Box<Error>);
src/build.rs:113:32: 116:45 note: required for the cast to the object type `error::Error`
src/build.rs:113                     return Err(box format!("{}\n{}",
src/build.rs:114                                            String::from_utf8_lossy(output.output[]),
src/build.rs:115                                            String::from_utf8_lossy(output.error[]))
src/build.rs:116                                as Box<Error>);
<std macros>:3:22: 3:40 error: mismatched types: expected `error::Error`, found `collections::string::String` (expected trait error::Error, found struct collections::string::String)
<std macros>:3         format_args!(::std::fmt::format, $($arg)*)
                                    ^~~~~~~~~~~~~~~~~~
note: in expansion of format_args!
<std macros>:3:9: 3:51 note: expansion site
<std macros>:1:1: 5:2 note: in expansion of format!
src/build.rs:120:32: 120:80 note: expansion site
src/build.rs:120:28: 120:91 error: the trait `core::kinds::Sized` is not implemented for the type `error::Error`
src/build.rs:120                 return Err(box format!("Could not execute `rustdoc`: {}", e) as Box<Error>);
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/build.rs:120:28: 120:91 note: only sized types can be made into objects
src/build.rs:120                 return Err(box format!("Could not execute `rustdoc`: {}", e) as Box<Error>);
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/build.rs:120:28: 120:91 error: the trait `error::Error` is not implemented for the type `error::Error`
src/build.rs:120                 return Err(box format!("Could not execute `rustdoc`: {}", e) as Box<Error>);
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/build.rs:120:28: 120:91 note: required for the cast to the object type `error::Error`
src/build.rs:120                 return Err(box format!("Could not execute `rustdoc`: {}", e) as Box<Error>);
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

My own format_args experiments (#20136) were hit by this:

struct Cell<T>(T);
impl <T: Copy + std::fmt::Show> std::fmt::Show for Cell<T> {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        let dst = &mut *f;
        (|args| dst.write_fmt(args))(&::std::fmt::Arguments::new({
            #[inline]
            #[allow(dead_code)]
            static __STATIC_FMTSTR: &'static [&'static str] = &["Cell { value: ", " }"];
            __STATIC_FMTSTR
        }, &match (&self.0,) {
            (__arg0,) => [::std::fmt::argument(::std::fmt::Show::fmt, __arg0)]
        }))
    }
}
fmt-test0.rs:11:26: 11:79 error: mismatched types: expected `[core::fmt::Argument<'_>]`, found `[core::fmt::Argument<'_>, ..1]` (expected slice, found array of 1 elements)
fmt-test0.rs:11             (__arg0,) => [::std::fmt::argument(::std::fmt::Show::fmt, __arg0)]
                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bors added a commit that referenced this issue Dec 23, 2014
This fixes a few corner cases with expected type propagation, e.g.:
```rust
fn take_int_slice(_: &[int]) {}
take_int_slice(&if 1 < 0 { [ 0, 1 ] } else { [ 0, 1 ] });
```
```rust
<anon>:2:28: 2:36 error: mismatched types: expected `[int]`, found `[int, ..2]`
<anon>:2 take_int_slice(&if 1 < 0 { [ 0, 1 ] } else { [ 0, 1 ] });
                                    ^~~~~~~~
<anon>:2:46: 2:54 error: mismatched types: expected `[int]`, found `[int, ..2]`
<anon>:2 take_int_slice(&if 1 < 0 { [ 0, 1 ] } else { [ 0, 1 ] });
                                                      ^~~~~~~~
```
Right now we unpack the expected `&[int]` and pass down `[int]`, forcing
rvalue expressions to take unsized types, which causes mismatch errors.
Instead, I replaced that expectation with a weaker hint, for the unsized
cases - a hint is still required to infer the integer literals' types, above.

Fixes #20169.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant