Skip to content

Commit 17c6efa

Browse files
Disentangle hir node match logic in adjust_fulfillment_errors
1 parent 4af7fa7 commit 17c6efa

File tree

1 file changed

+65
-46
lines changed

1 file changed

+65
-46
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

+65-46
Original file line numberDiff line numberDiff line change
@@ -94,71 +94,82 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9494
self.find_ambiguous_parameter_in(def_id, error.root_obligation.predicate);
9595
}
9696

97-
let (expr, qpath) = match self.tcx.hir_node(hir_id) {
98-
hir::Node::Expr(expr) => {
99-
if self.closure_span_overlaps_error(error, expr.span) {
97+
match self.tcx.hir_node(hir_id) {
98+
hir::Node::Expr(&hir::Expr { kind: hir::ExprKind::Path(qpath), span, .. }) => {
99+
if self.closure_span_overlaps_error(error, span) {
100100
return false;
101101
}
102-
let qpath =
103-
if let hir::ExprKind::Path(qpath) = expr.kind { Some(qpath) } else { None };
104102

105-
(Some(&expr.kind), qpath)
106-
}
107-
hir::Node::Ty(hir::Ty { kind: hir::TyKind::Path(qpath), .. }) => (None, Some(*qpath)),
108-
_ => return false,
109-
};
103+
if let Some(param) = predicate_self_type_to_point_at
104+
&& self.point_at_path_if_possible(error, def_id, param, &qpath)
105+
{
106+
return true;
107+
}
110108

111-
if let Some(qpath) = qpath {
112-
// Prefer pointing at the turbofished arg that corresponds to the
113-
// self type of the failing predicate over anything else.
114-
if let Some(param) = predicate_self_type_to_point_at
115-
&& self.point_at_path_if_possible(error, def_id, param, &qpath)
116-
{
117-
return true;
118-
}
109+
if let hir::Node::Expr(hir::Expr {
110+
kind: hir::ExprKind::Call(callee, args),
111+
hir_id: call_hir_id,
112+
span: call_span,
113+
..
114+
}) = self.tcx.parent_hir_node(hir_id)
115+
&& callee.hir_id == hir_id
116+
{
117+
if self.closure_span_overlaps_error(error, *call_span) {
118+
return false;
119+
}
119120

120-
if let hir::Node::Expr(hir::Expr {
121-
kind: hir::ExprKind::Call(callee, args),
122-
hir_id: call_hir_id,
123-
span: call_span,
124-
..
125-
}) = self.tcx.parent_hir_node(hir_id)
126-
&& callee.hir_id == hir_id
127-
{
128-
if self.closure_span_overlaps_error(error, *call_span) {
129-
return false;
121+
for param in
122+
[param_to_point_at, fallback_param_to_point_at, self_param_to_point_at]
123+
.into_iter()
124+
.flatten()
125+
{
126+
if self.blame_specific_arg_if_possible(
127+
error,
128+
def_id,
129+
param,
130+
*call_hir_id,
131+
callee.span,
132+
None,
133+
args,
134+
) {
135+
return true;
136+
}
137+
}
130138
}
131139

132140
for param in [param_to_point_at, fallback_param_to_point_at, self_param_to_point_at]
133141
.into_iter()
134142
.flatten()
135143
{
136-
if self.blame_specific_arg_if_possible(
137-
error,
138-
def_id,
139-
param,
140-
*call_hir_id,
141-
callee.span,
142-
None,
143-
args,
144-
) {
144+
if self.point_at_path_if_possible(error, def_id, param, &qpath) {
145145
return true;
146146
}
147147
}
148148
}
149-
150-
for param in [param_to_point_at, fallback_param_to_point_at, self_param_to_point_at]
149+
hir::Node::Ty(hir::Ty { kind: hir::TyKind::Path(qpath), .. }) => {
150+
for param in [
151+
predicate_self_type_to_point_at,
152+
param_to_point_at,
153+
fallback_param_to_point_at,
154+
self_param_to_point_at,
155+
]
151156
.into_iter()
152157
.flatten()
153-
{
154-
if self.point_at_path_if_possible(error, def_id, param, &qpath) {
155-
return true;
158+
{
159+
if self.point_at_path_if_possible(error, def_id, param, &qpath) {
160+
return true;
161+
}
156162
}
157163
}
158-
}
164+
hir::Node::Expr(&hir::Expr {
165+
kind: hir::ExprKind::MethodCall(segment, receiver, args, ..),
166+
span,
167+
..
168+
}) => {
169+
if self.closure_span_overlaps_error(error, span) {
170+
return false;
171+
}
159172

160-
match expr {
161-
Some(hir::ExprKind::MethodCall(segment, receiver, args, ..)) => {
162173
if let Some(param) = predicate_self_type_to_point_at
163174
&& self.point_at_generic_if_possible(error, def_id, param, segment)
164175
{
@@ -208,7 +219,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
208219
return true;
209220
}
210221
}
211-
Some(hir::ExprKind::Struct(qpath, fields, ..)) => {
222+
hir::Node::Expr(&hir::Expr {
223+
kind: hir::ExprKind::Struct(qpath, fields, ..),
224+
span,
225+
..
226+
}) => {
227+
if self.closure_span_overlaps_error(error, span) {
228+
return false;
229+
}
230+
212231
if let Res::Def(DefKind::Struct | DefKind::Variant, variant_def_id) =
213232
self.typeck_results.borrow().qpath_res(qpath, hir_id)
214233
{

0 commit comments

Comments
 (0)