-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Open
Labels
A-type-systemArea: Type systemArea: Type systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
This piece of code can't compile:
fn main()
{
let y = &mut 2i32;
{
let x = y;
*x = 3;
}
println!("{}", y);
}
But, if we add the type annotation, it compiles:
fn main()
{
let y = &mut 2i32;
{
let x: &mut i32 = y;
*x = 3;
}
println!("{}", y);
}
I guess the later form triggers "auto-deref" mechanism, which equals to:
let x = &mut *y;
But this behaviour is still very confusing. Type annotation or not doesn't change the type of x
at all. Type of x
is always &mut i32
. But they lead to different compile result. I have no idea whether should we fix it.
tyilo
Metadata
Metadata
Assignees
Labels
A-type-systemArea: Type systemArea: Type systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.