Skip to content

Commit d536c17

Browse files
committed
why fail?
1 parent 0b411c8 commit d536c17

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -151,28 +151,29 @@ impl<'tcx> BorrowExplanation<'tcx> {
151151
}
152152
}
153153
}
154-
let (dtor_desc, type_desc) = match ty.kind() {
154+
let (dtor_code, type_code, type_desc) = match ty.kind() {
155155
// If type is an ADT that implements Drop, then
156156
// simplify output by reporting just the ADT name.
157157
ty::Adt(adt, _substs) if adt.has_dtor(tcx) && !adt.is_box() => {
158-
("`Drop` code", format!("type `{}`", tcx.def_path_str(adt.did())))
158+
(0, 0, format!(" `{}`", tcx.def_path_str(adt.did()).to_string()))
159159
}
160160

161161
// Otherwise, just report the whole type (and use
162162
// the intentionally fuzzy phrase "destructor")
163-
ty::Closure(..) => ("destructor", "closure".to_owned()),
164-
ty::Generator(..) => ("destructor", "generator".to_owned()),
163+
ty::Closure(..) => (1, 1, "".to_owned()),
164+
ty::Generator(..) => (1, 2, "".to_owned()),
165165

166-
_ => ("destructor", format!("type `{}`", local_decl.ty)),
166+
_ => (1, 0, format!(" `{}`", local_decl.ty.to_string())),
167167
};
168168

169169
match local_names[dropped_local] {
170170
Some(local_name) if !local_decl.from_compiler_desugaring() => {
171171
err.subdiagnostic(UsedLaterDropped::UsedHere {
172172
borrow_desc: br_desc,
173173
local_name,
174-
type_desc: &type_desc,
175-
dtor_desc,
174+
type_desc,
175+
type_code,
176+
dtor_code,
176177
span: body.source_info(drop_loc).span,
177178
});
178179
if should_note_order {
@@ -186,8 +187,9 @@ impl<'tcx> BorrowExplanation<'tcx> {
186187
});
187188
err.subdiagnostic(UsedLaterDropped::MightUsedHere {
188189
borrow_desc: br_desc,
189-
type_desc: &type_desc,
190-
dtor_desc,
190+
type_desc,
191+
type_code,
192+
dtor_code,
191193
span: body.source_info(drop_loc).span,
192194
});
193195
if let Some(info) = &local_decl.is_block_tail {

compiler/rustc_borrowck/src/session_diagnostics.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ pub(crate) enum UsedLaterDropped<'a> {
189189
UsedHere {
190190
borrow_desc: &'a str,
191191
local_name: Symbol,
192-
type_desc: &'a str,
193-
dtor_desc: &'a str,
192+
dtor_code: u8,
193+
type_code: u8,
194+
type_desc: String,
194195
#[primary_span]
195196
span: Span,
196197
},
@@ -205,8 +206,9 @@ pub(crate) enum UsedLaterDropped<'a> {
205206
#[label(borrowck::drop_temporary_might_cause_borrow_use)]
206207
MightUsedHere {
207208
borrow_desc: &'a str,
208-
type_desc: &'a str,
209-
dtor_desc: &'a str,
209+
dtor_code: u8,
210+
type_code: u8,
211+
type_desc: String,
210212
#[primary_span]
211213
span: Span,
212214
},

compiler/rustc_error_messages/locales/en-US/borrowck.ftl

+16-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,14 @@ borrowck_drop_local_might_cause_borrow =
9292
[immutable] immutable {""}
9393
[first] first {""}
9494
*[other] {""}
95-
}borrow might be used here, when `{$local_name}` is dropped and runs the {$dtor_desc} for {$type_desc}
95+
}borrow might be used here, when `{$local_name}` is dropped and runs the {$dtor_code ->
96+
[0] `Drop` code
97+
*[1] destructor
98+
} for {$type_code ->
99+
[1] closure
100+
[2] generator
101+
*[0] type
102+
}{$type_desc}
96103
97104
borrowck_var_dropped_in_wrong_order =
98105
values in a scope are dropped in the opposite order they are defined
@@ -110,7 +117,14 @@ borrowck_drop_temporary_might_cause_borrow_use = ... and the {$borrow_desc ->
110117
[immutable] immutable {""}
111118
[first] first {""}
112119
*[other] {""}
113-
}borrow might be used here, when that temporary is dropped and runs the {$dtor_desc} for {$type_desc}
120+
}borrow might be used here, when that temporary is dropped and runs the {$dtor_code ->
121+
[0] `Drop` code
122+
*[1] destructor
123+
} for {$type_code ->
124+
[1] closure
125+
[2] generator
126+
*[0] type
127+
}{$type_desc}
114128
115129
borrowck_consider_add_semicolon =
116130
consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped

0 commit comments

Comments
 (0)