-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Do not ICE when combining unsized locals and async #64527
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -669,28 +669,43 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> { | |
let place_ty: Ty<'tcx> = place | ||
.ty(&self.local_decls, self.tcx) | ||
.ty; | ||
if let Ok(place_layout) = self.tcx.layout_of(self.param_env.and(place_ty)) { | ||
if let Some(value) = self.const_prop(rval, place_layout, statement.source_info) { | ||
if let Place { | ||
base: PlaceBase::Local(local), | ||
projection: box [], | ||
} = *place { | ||
trace!("checking whether {:?} can be stored to {:?}", value, local); | ||
if self.can_const_prop[local] { | ||
trace!("storing {:?} to {:?}", value, local); | ||
assert!(self.get_const(local).is_none()); | ||
self.set_const(local, value); | ||
|
||
if self.should_const_prop() { | ||
self.replace_with_const( | ||
rval, | ||
value, | ||
statement.source_info, | ||
); | ||
|
||
match self.tcx.layout_of(self.param_env.and(place_ty)) { | ||
Ok(place_layout) => { | ||
if let Some(value) = self.const_prop( | ||
rval, | ||
place_layout, | ||
statement.source_info, | ||
) { | ||
if let Place { | ||
base: PlaceBase::Local(local), | ||
projection: box [], | ||
} = *place { | ||
trace!("checking whether {:?} can be stored to {:?}", value, local); | ||
if self.can_const_prop[local] { | ||
trace!("storing {:?} to {:?}", value, local); | ||
assert!(self.get_const(local).is_none()); | ||
self.set_const(local, value); | ||
|
||
if self.should_const_prop() { | ||
self.replace_with_const( | ||
rval, | ||
value, | ||
statement.source_info, | ||
); | ||
} | ||
} | ||
} | ||
} | ||
Err(LayoutError::Unsized(_ty)) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could add an |
||
let sp = statement.source_info.span; // async fn block | ||
self.tcx.sess.struct_span_err( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uhm; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea I think it's totally fine to just keep doing what the old code did and ignore errors. They may be occuring because we're in a generic function and may be bogus for specific concrete types There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we close this PR then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well; we cannot merge this PR as-is I think but maybe we can morph the PR into something else. You can always open a new one tho... up to you. :) |
||
sp, | ||
"unsized values can't be used in `async` functions", | ||
).span_label(sp, "contains unsized values") | ||
.emit(); | ||
} | ||
Err(_) => {} | ||
} | ||
} | ||
self.super_statement(statement, location); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// edition:2018 | ||
|
||
#![feature(unsized_locals)] | ||
#![feature(gen_future)] | ||
|
||
use std::future::poll_with_tls_context; | ||
use std::pin::Pin; | ||
use std::fmt::Display; | ||
|
||
async fn foo2() {} | ||
|
||
async fn foo(x: Box<dyn Display>) { //~ ERROR unsized values can't be used in `async` functions | ||
let x = *x; | ||
foo2().await; | ||
println!("hello {}", &x); | ||
} | ||
|
||
fn main() { | ||
let mut a = foo(Box::new(5)); | ||
let b = unsafe { | ||
Pin::new_unchecked(&mut a) | ||
}; | ||
match poll_with_tls_context(b) { | ||
_ => () | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error: unsized values can't be used in `async` functions | ||
--> $DIR/unsized-locals.rs:12:35 | ||
| | ||
LL | async fn foo(x: Box<dyn Display>) { | ||
| ___________________________________^ | ||
LL | | let x = *x; | ||
LL | | foo2().await; | ||
LL | | println!("hello {}", &x); | ||
LL | | } | ||
| |_^ contains unsized values | ||
|
||
error: aborting due to previous error | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An unsized type isnt generic, so returning TooGeneric doesnt make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that's also why this entire approach looks odd... a generic type will eventually be monomorphized, so that's a program that cannot be executed now but can be executed later. But if the type is unsized now it will always be unsized, right, so why does it make any sense to delay the error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea that should just be reported via the machinery below, which should simplify the rest