-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Note where implicit Sized requirement comes from #27964
Comments
I second this, it's extremely confusing. trait Reader{}
impl Reader for () {}
fn reader_for()-> Box<Reader> { Box::new(()) }
fn check_vec<R:Reader>(r:&R){} //R needs to be Reader+?Sized for some reason, but new rust programmers wont know that.
fn main() {
check_vec(&*reader_for());
//error: the trait `core::marker::Sized` is not implemented for the type `Reader`
//note: `Reader` does not have a constant size known at compile-time
//note: required by `check_vec`
} The user will not be able to figure out why the function requires Sized when they did not define it to require Sized and when none of its functionality depends on Sized. |
The original case has had no changes. The case in the last comment has the following output in #68377:
|
One from the user forum, playground: use std::error::Error;
fn library_function<F1, E1>(f1: F1) -> Result<(), E1>
where
F1: FnOnce() -> Result<(), E1>,
E1: Error, // <-remove this line -> compile
{
f1()
}
fn main() -> Result<(), Box<dyn Error>>
{
library_function( || Ok(()) )
} Error:
Analysis: Go figure why "library_function doesn't have a size known at compile time". I suppose the ideal here would be something like: |
@najamelan could you copy that comment as a new ticket? The original report will be closed by #69709 but yours won't be addressed by that PR, sadly. |
@estebank It's done. Thank you so much for working on diagnostics! |
Current output:
|
Output with #73261:
And the output when this ticket was created 😅:
|
…akis Suggest `?Sized` when applicable for ADTs Address rust-lang#71790, fix rust-lang#27964.
I was not aware that
Sized
is a default requirement for type parameters, so I was very confused why this code doesn't compile:I couldn't understand why compiler insists on having
Sized
for the innermost type, ifBox
doesn't care and makes the boxed type sized.The current explanation for E0277 doesn't cover this case specifically, and it doesn't mention the unusual
?Sized
syntax. It'd help me if, for example, the hint:made implied defaults explicitly spelled out:
and/or hinted how to fix it:
The text was updated successfully, but these errors were encountered: