Skip to content

Commit eace82c

Browse files
committed
review comment
1 parent a17e8cf commit eace82c

File tree

2 files changed

+31
-39
lines changed

2 files changed

+31
-39
lines changed

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3462,52 +3462,46 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
34623462

34633463
/// This method is called after we have encountered a missing field error to recursively
34643464
/// search for the field
3465+
#[instrument(skip(self, matches, mod_id, hir_id), level = "debug")]
34653466
pub(crate) fn check_for_nested_field_satisfying_condition_for_diag(
34663467
&self,
34673468
span: Span,
34683469
matches: &impl Fn(Ident, Ty<'tcx>) -> bool,
3469-
candidate_field: (Ident, Ty<'tcx>),
3470+
(candidate_name, candidate_ty): (Ident, Ty<'tcx>),
34703471
mut field_path: Vec<Ident>,
34713472
mod_id: DefId,
34723473
hir_id: HirId,
34733474
) -> Option<Vec<Ident>> {
3474-
debug!(
3475-
"check_for_nested_field_satisfying(span: {:?}, candidate_field: {:?}, field_path: {:?}",
3476-
span, candidate_field, field_path
3477-
);
3478-
34793475
if field_path.len() > 3 {
34803476
// For compile-time reasons and to avoid infinite recursion we only check for fields
34813477
// up to a depth of three
3482-
None
3483-
} else {
3484-
field_path.push(candidate_field.0);
3485-
let field_ty = candidate_field.1;
3486-
if matches(candidate_field.0, field_ty) {
3487-
return Some(field_path);
3488-
} else {
3489-
for nested_fields in self.get_field_candidates_considering_privacy_for_diag(
3490-
span, field_ty, mod_id, hir_id,
3478+
return None;
3479+
}
3480+
field_path.push(candidate_name);
3481+
if matches(candidate_name, candidate_ty) {
3482+
return Some(field_path);
3483+
}
3484+
for nested_fields in self.get_field_candidates_considering_privacy_for_diag(
3485+
span,
3486+
candidate_ty,
3487+
mod_id,
3488+
hir_id,
3489+
) {
3490+
// recursively search fields of `candidate_field` if it's a ty::Adt
3491+
for field in nested_fields {
3492+
if let Some(field_path) = self.check_for_nested_field_satisfying_condition_for_diag(
3493+
span,
3494+
matches,
3495+
field,
3496+
field_path.clone(),
3497+
mod_id,
3498+
hir_id,
34913499
) {
3492-
// recursively search fields of `candidate_field` if it's a ty::Adt
3493-
for field in nested_fields {
3494-
if let Some(field_path) = self
3495-
.check_for_nested_field_satisfying_condition_for_diag(
3496-
span,
3497-
matches,
3498-
field,
3499-
field_path.clone(),
3500-
mod_id,
3501-
hir_id,
3502-
)
3503-
{
3504-
return Some(field_path);
3505-
}
3506-
}
3500+
return Some(field_path);
35073501
}
35083502
}
3509-
None
35103503
}
3504+
None
35113505
}
35123506

35133507
fn check_expr_index(

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3585,7 +3585,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
35853585
self.tcx.lang_items().deref_trait(),
35863586
self.tcx.lang_items().deref_mut_trait(),
35873587
self.tcx.lang_items().drop_trait(),
3588-
self.tcx.lang_items().pin_type(),
35893588
self.tcx.get_diagnostic_item(sym::AsRef),
35903589
];
35913590
// Try alternative arbitrary self types that could fulfill this call.
@@ -3720,8 +3719,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
37203719
&& !alt_rcvr_sugg
37213720
// `T: !Unpin`
37223721
&& !unpin
3723-
// The method isn't `as_ref`, as it would provide a wrong suggestion for `Pin`.
3724-
&& sym::as_ref != item_name.name
37253722
// Either `Pin::as_ref` or `Pin::as_mut`.
37263723
&& let Some(pin_call) = pin_call
37273724
// Search for `item_name` as a method accessible on `Pin<T>`.
@@ -3735,12 +3732,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
37353732
// We skip some common traits that we don't want to consider because autoderefs
37363733
// would take care of them.
37373734
&& !skippable.contains(&Some(pick.item.container_id(self.tcx)))
3738-
&& !skippable.contains(&pick.item.impl_container(self.tcx).and_then(|did| {
3739-
match self.tcx.type_of(did).instantiate_identity().kind() {
3740-
ty::Adt(def, _) => Some(def.did()),
3741-
_ => None,
3735+
// Do not suggest pinning when the method is directly on `Pin`.
3736+
&& pick.item.impl_container(self.tcx).map_or(true, |did| {
3737+
match self.tcx.type_of(did).skip_binder().kind() {
3738+
ty::Adt(def, _) => Some(def.did()) != self.tcx.lang_items().pin_type(),
3739+
_ => true,
37423740
}
3743-
}))
3741+
})
37443742
// We don't want to go through derefs.
37453743
&& pick.autoderefs == 0
37463744
// Check that the method of the same name that was found on the new `Pin<T>`

0 commit comments

Comments
 (0)