-
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
rustc_layout(debug) does not complain about nonsense types #115676
Comments
As a hack, we could treat a type alias with |
As fmease alluded above, if you're just looking for a convenient way to test the layout of arbitrary types, and don't want to accidentally compute the layout of meaningless types, you should probably just use the I don't know if it's necessarily worth it to validate these usages in general. It's a rustc attr after all. |
I was thinking there might be an easy function to call that does whatever happens to a type alias when it is used somewhere that requires WF.
|
Hmm, I guess we can just call |
No, it would at least require spinning up an inference + obligation context and checking a wf goal and reporting a meaningful error if the type being layout'd is not WF. But I don't think it's really even worth that effort. |
Ah, fair. The reason I ran into this is that with |
We could emit delay span bugs immediately if |
Then we'll still just get ICEs, that doesn't sound great. These are delayed for a reason, after all. |
Hmm... why do we do this on its own instead of also returning an |
I figured out how to do WF-checking, it's not even hard: pub fn ensure_wf<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: Ty<'tcx>) -> bool {
let pred = ty::ClauseKind::WellFormed(ty.into());
let obligation = traits::Obligation::new(tcx, traits::ObligationCause::dummy(), param_env, pred);
let infcx = tcx.infer_ctxt().build();
matches!(infcx.evaluate_obligation_no_overflow(&obligation), traits::EvaluationResult::EvaluatedToOk)
} However this doesn't print the nice error messages I was hoping for that explain why this isn't WF. Is there an easy way to do that? |
You can look at the implementation of |
I still think this is the easiest solution The bug is that we're not wfchecking type aliases, this will check them |
I'm not sure of the ramifications of this, but subtly changing the semantics of the type alias doesn't seem like a good undocumented side-effect of a debugging macro. That's the kind of thing that introduces the strangest heisenbugs. |
The solution with the least amount of code changes would be to call Full lazy type aliases would also mean computing the variances, producing a weak projection ( This also wouldn't affect downstream users of the Emitting |
The only thing it can do is fail compilation because they are not WF, right? So that's fine then. #115712 fixes the problem for me. |
Actually this bug was reported before but fixed in an ad-hoc way that didn't resolve the underlying cause: #85103. |
I tried this code:
This should complain about using an unsized type in a way that doesn't work. Instead, it prints some layout.
Probably the rustc_layout logic needs to fire of some sort of query to ensure the type is well-formed, or something like that? I know type aliases only get WF-checked "on use", and it seems somehow this attribute doesn't count as a use. How can we make it count as a use?
Cc @oli-obk @lcnr
The text was updated successfully, but these errors were encountered: