-
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
Check Sizedness of return type in WF #136274
base: master
Are you sure you want to change the base?
Conversation
ObligationCauseCode::SizedReturnType, | ||
); | ||
// We checked the root's signature during wfcheck, but not the child. | ||
// We checked the root's ret ty during wfcheck, but not the child. | ||
if fcx.tcx.is_typeck_child(fn_def_id.to_def_id()) { |
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.
I have no idea why I duplicated this sized check... we were checking Sized
twice here for typeck children.
@@ -186,8 +186,6 @@ fn typeck_with_inspect<'tcx>( | |||
let wf_code = ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(def_id))); | |||
fcx.register_wf_obligation(expected_type.into(), body.value.span, wf_code); | |||
|
|||
fcx.require_type_is_sized(expected_type, body.value.span, ObligationCauseCode::ConstSized); |
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.
This is redundant. We already check sizedness in wfcheck for statics and consts!
@@ -1789,25 +1789,13 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | |||
} else { | |||
("dyn ", span.shrink_to_lo()) | |||
}; | |||
let alternatively = if visitor |
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.
This logic only exists to avoid suggesting turning -> dyn Trait
into -> impl Trait
if there are multiple returns with different types.... but it didn't even erase regions so:
fn test() -> dyn Any {
if false {
return &2;
}
&1
}
Currently says:
= help: if there were a single returned type, you could use `impl Trait` instead
😭
let ty = self.resolve_vars_if_possible(returned_ty); | ||
if ty.references_error() { | ||
// don't print out the [type error] here | ||
err.downgrade_to_delayed_bug(); |
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.
This downgrade was very much not useful.
// don't print out the [type error] here | ||
err.downgrade_to_delayed_bug(); | ||
} else { | ||
err.span_label(expr.span, format!("this returned value is of type `{ty}`")); |
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.
We don't really need this span. The fact that the return type is not sized is not a result of the return exprs...
@@ -26,6 +26,26 @@ help: alternatively, consider constraining `foo` so it does not apply to trait o | |||
LL | fn foo() -> Self where Self: Sized; | |||
| +++++++++++++++++ | |||
|
|||
error[E0746]: return type cannot have an unboxed trait object |
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.
TODO: I should change this to be "cannot be a trait object without pointer indirection"... or something.
--> $DIR/opaque-type-unsatisfied-bound.rs:15:16 | ||
| | ||
LL | fn weird0() -> impl Sized + !Sized {} | ||
| ^^^^^^^^^^^^^^^^^^^ the trait bound `(): !Sized` is not satisfied | ||
| ^^^^^^^^^^^^^^^^^^^ types differ |
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.
Absolutely no idea why this error message changed...
@@ -3,6 +3,6 @@ | |||
#![feature(negative_bounds, unboxed_closures)] | |||
|
|||
fn produce() -> impl !Fn<(u32,)> {} | |||
//~^ ERROR the trait bound `(): !Fn(u32)` is not satisfied | |||
//~^ ERROR type mismatch resolving |
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.
Or this one...
The job Click to see the possible cause of the failure (guessed by this bot)
|
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.
👍
nit
ObligationCause::new(span, def_id, traits::ObligationCauseCode::SizedReturnType), | ||
wfcx.param_env, | ||
ty, | ||
tcx.require_lang_item(LangItem::Sized, None), |
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.
tcx.require_lang_item(LangItem::Sized, None), | |
tcx.require_lang_item(LangItem::Sized, Some(span)), |
?
Still need to clean this up a bit. This should fix rust-lang/trait-system-refactor-initiative#150.
r? lcnr