Skip to content

Commit ddfa47f

Browse files
committed
Fix incorrect code
1 parent 07857f7 commit ddfa47f

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/librustc_typeck/check/demand.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
249249
None
250250
}
251251

252-
fn is_hir_id_from_struct_pattern_shorthand_field(&self, hir_id: hir::HirId) -> bool {
253-
let parent_id = self.tcx.hir().get_parent_node_by_hir_id(expr.hir_id);
254-
let mut is_struct_pat_shorthand_field = false;
252+
fn is_hir_id_from_struct_pattern_shorthand_field(&self, hir_id: hir::HirId, sp: Span) -> bool {
253+
let cm = self.sess().source_map();
254+
let parent_id = self.tcx.hir().get_parent_node_by_hir_id(hir_id);
255255
if let Some(parent) = self.tcx.hir().find_by_hir_id(parent_id) {
256256
// Account for fields
257257
if let Node::Expr(hir::Expr {
@@ -260,13 +260,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
260260
if let Ok(src) = cm.span_to_snippet(sp) {
261261
for field in fields {
262262
if field.ident.as_str() == src.as_str() && field.is_shorthand {
263-
is_struct_pat_shorthand_field = true;
264-
break;
263+
return true;
265264
}
266265
}
267266
}
268267
}
269-
};
268+
}
269+
false
270270
}
271271

272272
/// This function is used to determine potential "simple" improvements or users' errors and
@@ -297,8 +297,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
297297
return None;
298298
}
299299

300-
let mut is_struct_pat_shorthand_field =
301-
self.is_hir_id_from_struct_pattern_shorthand_field(expr.hir_id);
300+
let is_struct_pat_shorthand_field = self.is_hir_id_from_struct_pattern_shorthand_field(
301+
expr.hir_id,
302+
sp,
303+
);
302304

303305
match (&expected.sty, &checked_ty.sty) {
304306
(&ty::Ref(_, exp, _), &ty::Ref(_, check, _)) => match (&exp.sty, &check.sty) {

0 commit comments

Comments
 (0)