Skip to content

Rvalues are incorrectly expected to have unsized types. #20169

Closed
@eddyb

Description

@eddyb

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)]
                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions