mirror of
https://github.com/rust-lang/rust
synced 2024-10-05 08:10:32 +00:00
address review comment
This commit is contained in:
parent
6d23ee8430
commit
26954f60ff
|
@ -313,6 +313,18 @@ fn note_function_argument_obligation(
|
|||
predicate: ty::Predicate<'tcx>,
|
||||
call_hir_id: HirId,
|
||||
);
|
||||
|
||||
fn look_for_iterator_item_mistakes(
|
||||
&self,
|
||||
assocs_in_this_method: &[Option<(Span, (DefId, Ty<'tcx>))>],
|
||||
typeck_results: &TypeckResults<'tcx>,
|
||||
type_diffs: &[TypeError<'tcx>],
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
path_segment: &hir::PathSegment<'_>,
|
||||
args: &[hir::Expr<'_>],
|
||||
err: &mut Diagnostic,
|
||||
);
|
||||
|
||||
fn point_at_chain(
|
||||
&self,
|
||||
expr: &hir::Expr<'_>,
|
||||
|
@ -321,6 +333,7 @@ fn point_at_chain(
|
|||
param_env: ty::ParamEnv<'tcx>,
|
||||
err: &mut Diagnostic,
|
||||
);
|
||||
|
||||
fn probe_assoc_types_at_expr(
|
||||
&self,
|
||||
type_diffs: &[TypeError<'tcx>],
|
||||
|
@ -3592,39 +3605,24 @@ fn suggest_option_method_if_applicable(
|
|||
}
|
||||
}
|
||||
|
||||
fn point_at_chain(
|
||||
fn look_for_iterator_item_mistakes(
|
||||
&self,
|
||||
expr: &hir::Expr<'_>,
|
||||
assocs_in_this_method: &[Option<(Span, (DefId, Ty<'tcx>))>],
|
||||
typeck_results: &TypeckResults<'tcx>,
|
||||
type_diffs: Vec<TypeError<'tcx>>,
|
||||
type_diffs: &[TypeError<'tcx>],
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
path_segment: &hir::PathSegment<'_>,
|
||||
args: &[hir::Expr<'_>],
|
||||
err: &mut Diagnostic,
|
||||
) {
|
||||
let mut primary_spans = vec![];
|
||||
let mut span_labels = vec![];
|
||||
|
||||
let tcx = self.tcx;
|
||||
|
||||
let mut print_root_expr = true;
|
||||
let mut assocs = vec![];
|
||||
let mut expr = expr;
|
||||
let mut prev_ty = self.resolve_vars_if_possible(
|
||||
typeck_results.expr_ty_adjusted_opt(expr).unwrap_or(Ty::new_misc_error(tcx)),
|
||||
);
|
||||
while let hir::ExprKind::MethodCall(path_segment, rcvr_expr, args, span) = expr.kind {
|
||||
// Point at every method call in the chain with the resulting type.
|
||||
// vec![1, 2, 3].iter().map(mapper).sum<i32>()
|
||||
// ^^^^^^ ^^^^^^^^^^^
|
||||
expr = rcvr_expr;
|
||||
let assocs_in_this_method =
|
||||
self.probe_assoc_types_at_expr(&type_diffs, span, prev_ty, expr.hir_id, param_env);
|
||||
// Special case for iterator chains, we look at potential failures of `Iterator::Item`
|
||||
// not being `: Clone` and `Iterator::map` calls with spurious trailing `;`.
|
||||
for entry in &assocs_in_this_method {
|
||||
for entry in assocs_in_this_method {
|
||||
let Some((_span, (def_id, ty))) = entry else {
|
||||
continue;
|
||||
};
|
||||
for diff in &type_diffs {
|
||||
for diff in type_diffs {
|
||||
let Sorts(expected_found) = diff else {
|
||||
continue;
|
||||
};
|
||||
|
@ -3708,6 +3706,43 @@ fn point_at_chain(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn point_at_chain(
|
||||
&self,
|
||||
expr: &hir::Expr<'_>,
|
||||
typeck_results: &TypeckResults<'tcx>,
|
||||
type_diffs: Vec<TypeError<'tcx>>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
err: &mut Diagnostic,
|
||||
) {
|
||||
let mut primary_spans = vec![];
|
||||
let mut span_labels = vec![];
|
||||
|
||||
let tcx = self.tcx;
|
||||
|
||||
let mut print_root_expr = true;
|
||||
let mut assocs = vec![];
|
||||
let mut expr = expr;
|
||||
let mut prev_ty = self.resolve_vars_if_possible(
|
||||
typeck_results.expr_ty_adjusted_opt(expr).unwrap_or(Ty::new_misc_error(tcx)),
|
||||
);
|
||||
while let hir::ExprKind::MethodCall(path_segment, rcvr_expr, args, span) = expr.kind {
|
||||
// Point at every method call in the chain with the resulting type.
|
||||
// vec![1, 2, 3].iter().map(mapper).sum<i32>()
|
||||
// ^^^^^^ ^^^^^^^^^^^
|
||||
expr = rcvr_expr;
|
||||
let assocs_in_this_method =
|
||||
self.probe_assoc_types_at_expr(&type_diffs, span, prev_ty, expr.hir_id, param_env);
|
||||
self.look_for_iterator_item_mistakes(
|
||||
&assocs_in_this_method,
|
||||
typeck_results,
|
||||
&type_diffs,
|
||||
param_env,
|
||||
path_segment,
|
||||
args,
|
||||
err,
|
||||
);
|
||||
assocs.push(assocs_in_this_method);
|
||||
prev_ty = self.resolve_vars_if_possible(
|
||||
typeck_results.expr_ty_adjusted_opt(expr).unwrap_or(Ty::new_misc_error(tcx)),
|
||||
|
|
Loading…
Reference in a new issue