-
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 diagnostics for ref mut z @ &mut Some(ref a)
uses _
as binding name
#67565
Comments
I feel like the internal use of I feel like internally, we should keep a strong separation between names that we get from the source code being compiled and names being generated by the compiler... |
I think this issue is about the narrow issue of why this happens in the case of |
@Centril Sure, but I think it stems from a larger problem of undisciplined use of |
@mark-i-m I don't mind fixing this by fixing the root cause, but can we discuss the bigger issue in a issue made for that and cc this one? |
InvestigationSource input:#![feature(bindings_after_at)]
fn foo() {
let ref mut _z @ ref _a = &mut 1;
**_z = 0;
} Results in the following MIR:fn foo() -> () {
let mut _0: (); // return place in scope 0 at foo.rs:5:10: 5:10
let _1: &mut &mut i32; // in scope 0 at foo.rs:6:9: 6:28
let _2: &&mut i32; // in scope 0 at foo.rs:6:22: 6:28
let mut _3: &mut i32; // in scope 0 at foo.rs:6:31: 6:37
let mut _4: i32; // in scope 0 at foo.rs:6:36: 6:37
scope 1 {
debug _z => _1; // in scope 1 at foo.rs:6:9: 6:28
debug _a => _2; // in scope 1 at foo.rs:6:22: 6:28
}
bb0: {
StorageLive(_3); // bb0[0]: scope 0 at foo.rs:6:31: 6:37
StorageLive(_4); // bb0[1]: scope 0 at foo.rs:6:36: 6:37
_4 = const 1i32; // bb0[2]: scope 0 at foo.rs:6:36: 6:37
// ty::Const
// + ty: i32
// + val: Value(Scalar(0x00000001))
// mir::Constant
// + span: foo.rs:6:36: 6:37
// + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) }
_3 = &mut _4; // bb0[3]: scope 0 at foo.rs:6:31: 6:37
StorageLive(_1); // bb0[4]: scope 0 at foo.rs:6:9: 6:28
_1 = &mut _3; // bb0[5]: scope 0 at foo.rs:6:9: 6:28
StorageLive(_2); // bb0[6]: scope 0 at foo.rs:6:22: 6:28
_2 = &_3; // bb0[7]: scope 0 at foo.rs:6:22: 6:28
(*(*_1)) = const 0i32; // bb0[8]: scope 1 at foo.rs:7:5: 7:13
// ty::Const
// + ty: i32
// + val: Value(Scalar(0x00000000))
// mir::Constant
// + span: foo.rs:7:12: 7:13
// + literal: Const { ty: i32, val: Value(Scalar(0x00000000)) }
_0 = (); // bb0[9]: scope 0 at foo.rs:5:10: 8:2
StorageDead(_2); // bb0[10]: scope 0 at foo.rs:8:1: 8:2
StorageDead(_1); // bb0[11]: scope 0 at foo.rs:8:1: 8:2
StorageDead(_4); // bb0[12]: scope 0 at foo.rs:8:1: 8:2
StorageDead(_3); // bb0[13]: scope 0 at foo.rs:8:1: 8:2
return; // bb0[14]: scope 0 at foo.rs:8:2: 8:2
}
} And we double check with some debug!("ast_block_stmts: local_decls={:#?}", this.local_decls);
debug!("ast_block_stmts: var_debug_info={:#?}", this.var_debug_info);
debug!("ast_block_stmts: var_indices={:#?}", this.var_indices); using [DEBUG rustc_mir_build::build::block] ast_block_stmts: local_decls=[
LocalDecl {
mutability: Mut,
local_info: Other,
internal: false,
is_block_tail: None,
ty: (),
user_ty: UserTypeProjections {
contents: [],
},
source_info: SourceInfo {
span: foo.rs:5:10: 5:10,
scope: scope[0],
},
},
LocalDecl {
mutability: Not,
local_info: User(
Set(
Var(
VarBindingForm {
binding_mode: BindByReference(
Not,
),
opt_ty_info: None,
opt_match_place: Some(
(
Some(
_3,
),
foo.rs:6:31: 6:37,
),
),
pat_span: foo.rs:6:9: 6:28,
},
),
),
),
internal: false,
is_block_tail: None,
ty: &mut &mut i32,
user_ty: UserTypeProjections {
contents: [],
},
source_info: SourceInfo {
span: foo.rs:6:9: 6:28,
scope: scope[0],
},
},
LocalDecl {
mutability: Not,
local_info: User(
Set(
Var(
VarBindingForm {
binding_mode: BindByReference(
Not,
),
opt_ty_info: None,
opt_match_place: Some(
(
Some(
_3,
),
foo.rs:6:31: 6:37,
),
),
pat_span: foo.rs:6:9: 6:28,
},
),
),
),
internal: false,
is_block_tail: None,
ty: &&mut i32,
user_ty: UserTypeProjections {
contents: [],
},
source_info: SourceInfo {
span: foo.rs:6:22: 6:28,
scope: scope[0],
},
},
LocalDecl {
mutability: Mut,
local_info: Other,
internal: false,
is_block_tail: None,
ty: &mut i32,
user_ty: UserTypeProjections {
contents: [],
},
source_info: SourceInfo {
span: foo.rs:6:31: 6:37,
scope: scope[0],
},
},
LocalDecl {
mutability: Mut,
local_info: Other,
internal: false,
is_block_tail: None,
ty: i32,
user_ty: UserTypeProjections {
contents: [],
},
source_info: SourceInfo {
span: foo.rs:6:36: 6:37,
scope: scope[0],
},
},
]
[DEBUG rustc_mir_build::build::block] ast_block_stmts: var_debug_info=[
VarDebugInfo {
name: "_z",
source_info: SourceInfo {
span: foo.rs:6:9: 6:28,
scope: scope[1],
},
place: _1,
},
VarDebugInfo {
name: "_a",
source_info: SourceInfo {
span: foo.rs:6:22: 6:28,
scope: scope[1],
},
place: _2,
},
]
[DEBUG rustc_mir_build::build::block] ast_block_stmts: var_indices={
HirId {
owner: DefIndex(4),
local_id: 1,
}: One(
_1,
),
HirId {
owner: DefIndex(4),
local_id: 2,
}: One(
_2,
),
} Borrow checking trace:The error comes from
We eventually end up in
and so it tries to compute The unchanged log output on master is:
|
Context: #66296 (comment)
The
_
below should bez
instead.cc @mark-i-m @pnkfelix @matthewjasper
cc #65490
Minimal reproducer:
The text was updated successfully, but these errors were encountered: