Skip to content

Commit 5dab0c9

Browse files
committed
confirm assignment goes into the return place
1 parent 412c2e5 commit 5dab0c9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

compiler/rustc_lint/src/default_could_be_derived.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,15 +481,16 @@ fn check_path<'tcx>(
481481
let instance = Instance::try_resolve(cx.tcx, cx.typing_env(), default_fn_def_id, args);
482482

483483
let Ok(Some(instance)) = instance else { return false };
484-
// Get the MIR Body for the `<Ty as Default>::default()` function.
484+
// Get the MIR Body for the `<FieldTy as Default>::default()` function.
485485
// If it is a value or call (either fn or ctor), we compare its DefId against the one for the
486-
// resolution of the expression we had in the path.
486+
// resolution of the expression we had in the path. This lets us identify, for example, that
487+
// the body of `<Vec<T> as Default>::default()` is a `Vec::new()`, and the field was being
488+
// initialized to `Vec::new()` as well.
487489
let body = cx.tcx.instance_mir(instance.def);
488490
for block_data in body.basic_blocks.iter() {
489-
// FIXME: make another pass on this logic. For example we should be confirming that the
490-
// place we assign to is `_0`.
491491
if block_data.statements.len() == 1
492492
&& let mir::StatementKind::Assign(assign) = &block_data.statements[0].kind
493+
&& assign.0.local == mir::RETURN_PLACE
493494
&& let mir::Rvalue::Aggregate(kind, _places) = &assign.1
494495
&& let mir::AggregateKind::Adt(did, variant_index, _, _, _) = &**kind
495496
&& let def = cx.tcx.adt_def(did)

0 commit comments

Comments
 (0)