-
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
nll should preserve user types in type ascription #54331
Comments
The first step to fix this is that we have to extend the HAIR to support user annotations. Currently we just remove rust/src/librustc_mir/hair/cx/expr.rs Line 721 in 79fcc58
So that means extending the HAIR rust/src/librustc_mir/hair/mod.rs Line 140 in 79fcc58
I imagine we would add a new variant like this: /// Type ascription
ExprType {
/// Type that the user gave to this expression
user_ty: CanonicalTy<'tcx>,
} We would then lower In order to populate it, we'll need to "preserve" the user-given type from the first round of type-checking. This is done via the rust/src/librustc_typeck/check/mod.rs Line 951 in 79fcc58
We would want to add similar code the rust/src/librustc_typeck/check/mod.rs Lines 4169 to 4173 in 79fcc58
Here, we want to add something like let c_ty = self.fcx.inh.infcx.canonicalize_response(&ty);
self.fcx.tables.borrow_mut().user_provided_tys_mut().insert(t.hir_id, c_ty); When we lower the rust/src/librustc_mir/hair/cx/block.rs Line 89 in 79fcc58
Here, the key would be the Then we have to modify the NLL type checker sort of like this code does: rust/src/librustc_mir/borrow_check/nll/type_check/mod.rs Lines 931 to 947 in 79fcc58
(In fact, I think we can then remove the |
Lower type ascriptions to HAIR and MIR Fixes #54331. r? @nikomatsakis
Spawned off from #47184. The following test case compiles, but it should not (playground):
The problem is that the "type ascription" expression is not preserving the full type that the user gave (
&'static u32
).The text was updated successfully, but these errors were encountered: