Skip to content

Commit d116767

Browse files
committed
review comment: change span argument
1 parent d2a781a commit d116767

File tree

6 files changed

+15
-10
lines changed

6 files changed

+15
-10
lines changed

Diff for: compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,6 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
642642
);
643643
let hir = tcx.hir();
644644
infcx.err_ctxt().note_type_err(
645-
cause.span,
646645
&mut diag,
647646
&cause,
648647
hir.get_if_local(impl_m.def_id)
@@ -654,6 +653,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
654653
}))),
655654
terr,
656655
false,
656+
None,
657657
);
658658
return Err(diag.emit());
659659
}
@@ -1062,7 +1062,6 @@ fn report_trait_method_mismatch<'tcx>(
10621062

10631063
cause.span = impl_err_span;
10641064
infcx.err_ctxt().note_type_err(
1065-
cause.span,
10661065
&mut diag,
10671066
&cause,
10681067
trait_err_span.map(|sp| (sp, Cow::from("type in trait"), false)),
@@ -1072,6 +1071,7 @@ fn report_trait_method_mismatch<'tcx>(
10721071
}))),
10731072
terr,
10741073
false,
1074+
None,
10751075
);
10761076

10771077
diag.emit()
@@ -1855,7 +1855,6 @@ fn compare_const_predicate_entailment<'tcx>(
18551855
});
18561856

18571857
infcx.err_ctxt().note_type_err(
1858-
cause.span,
18591858
&mut diag,
18601859
&cause,
18611860
trait_c_span.map(|span| (span, Cow::from("type in trait"), false)),
@@ -1865,6 +1864,7 @@ fn compare_const_predicate_entailment<'tcx>(
18651864
}))),
18661865
terr,
18671866
false,
1867+
None,
18681868
);
18691869
return Err(diag.emit());
18701870
};

Diff for: compiler/rustc_hir_analysis/src/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,6 @@ pub fn check_function_signature<'tcx>(
640640
let failure_code = cause.as_failure_code_diag(err, cause.span, vec![]);
641641
let mut diag = tcx.dcx().create_err(failure_code);
642642
err_ctxt.note_type_err(
643-
cause.span,
644643
&mut diag,
645644
&cause,
646645
None,
@@ -650,6 +649,7 @@ pub fn check_function_signature<'tcx>(
650649
}))),
651650
err,
652651
false,
652+
None,
653653
);
654654
return Err(diag.emit());
655655
}

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1141,13 +1141,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11411141
let trace = mk_trace(provided_span, (formal_ty, expected_ty), provided_ty);
11421142
if let Some(e) = error {
11431143
self.err_ctxt().note_type_err(
1144-
trace.cause.span,
11451144
&mut err,
11461145
&trace.cause,
11471146
None,
11481147
Some(self.param_env.and(trace.values)),
11491148
e,
11501149
true,
1150+
None,
11511151
);
11521152
}
11531153
}

Diff for: compiler/rustc_passes/src/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2462,7 +2462,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
24622462
}
24632463

24642464
infcx.err_ctxt().note_type_err(
2465-
cause.span,
24662465
&mut diag,
24672466
&cause,
24682467
None,
@@ -2472,6 +2471,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
24722471
}))),
24732472
terr,
24742473
false,
2474+
None,
24752475
);
24762476
diag.emit();
24772477
self.abort.set(true);

Diff for: compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1386,14 +1386,19 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
13861386
#[instrument(level = "debug", skip(self, diag, secondary_span, prefer_label))]
13871387
pub fn note_type_err(
13881388
&self,
1389-
span: Span,
13901389
diag: &mut Diag<'_>,
13911390
cause: &ObligationCause<'tcx>,
13921391
secondary_span: Option<(Span, Cow<'static, str>, bool)>,
13931392
mut values: Option<ty::ParamEnvAnd<'tcx, ValuePairs<'tcx>>>,
13941393
terr: TypeError<'tcx>,
13951394
prefer_label: bool,
1395+
override_span: Option<Span>,
13961396
) {
1397+
// We use `override_span` when we want the error to point at a `Span` other than
1398+
// `cause.span`. This is used in E0271, when a closure is passed in where the return type
1399+
// isn't what was expected. We want to point at the closure's return type (or expression),
1400+
// instead of the expression where the closure is passed as call argument.
1401+
let span = override_span.unwrap_or(cause.span);
13971402
// For some types of errors, expected-found does not make
13981403
// sense, so just ignore the values we were given.
13991404
if let TypeError::CyclicTy(_) = terr {
@@ -2052,13 +2057,13 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
20522057
);
20532058
let mut diag = self.dcx().create_err(failure_code);
20542059
self.note_type_err(
2055-
span,
20562060
&mut diag,
20572061
&trace.cause,
20582062
None,
20592063
Some(param_env.and(trace.values)),
20602064
terr,
20612065
false,
2066+
None,
20622067
);
20632068
diag
20642069
}

Diff for: compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -702,13 +702,13 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
702702
);
703703

704704
self.note_type_err(
705-
span,
706705
&mut diag,
707706
&obligation.cause,
708707
None,
709708
None,
710709
TypeError::Sorts(ty::error::ExpectedFound::new(expected_ty, ct_ty)),
711710
false,
711+
None,
712712
);
713713
diag
714714
}
@@ -1488,7 +1488,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
14881488
})();
14891489

14901490
self.note_type_err(
1491-
span,
14921491
&mut diag,
14931492
&obligation.cause,
14941493
secondary_span,
@@ -1500,6 +1499,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
15001499
}),
15011500
err,
15021501
false,
1502+
Some(span),
15031503
);
15041504
self.note_obligation_cause(&mut diag, obligation);
15051505
diag.emit()

0 commit comments

Comments
 (0)