Skip to content

Commit d2e4f44

Browse files
committed
review comment: change span argument
1 parent f43a874 commit d2e4f44

File tree

6 files changed

+15
-10
lines changed

6 files changed

+15
-10
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,6 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
618618
);
619619
let hir = tcx.hir();
620620
infcx.err_ctxt().note_type_err(
621-
cause.span,
622621
&mut diag,
623622
&cause,
624623
hir.get_if_local(impl_m.def_id)
@@ -630,6 +629,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
630629
}))),
631630
terr,
632631
false,
632+
None,
633633
);
634634
return Err(diag.emit());
635635
}
@@ -1048,7 +1048,6 @@ fn report_trait_method_mismatch<'tcx>(
10481048

10491049
cause.span = impl_err_span;
10501050
infcx.err_ctxt().note_type_err(
1051-
cause.span,
10521051
&mut diag,
10531052
&cause,
10541053
trait_err_span.map(|sp| (sp, Cow::from("type in trait"), false)),
@@ -1058,6 +1057,7 @@ fn report_trait_method_mismatch<'tcx>(
10581057
}))),
10591058
terr,
10601059
false,
1060+
None,
10611061
);
10621062

10631063
diag.emit()
@@ -1846,7 +1846,6 @@ fn compare_const_predicate_entailment<'tcx>(
18461846
});
18471847

18481848
infcx.err_ctxt().note_type_err(
1849-
cause.span,
18501849
&mut diag,
18511850
&cause,
18521851
trait_c_span.map(|span| (span, Cow::from("type in trait"), false)),
@@ -1856,6 +1855,7 @@ fn compare_const_predicate_entailment<'tcx>(
18561855
}))),
18571856
terr,
18581857
false,
1858+
None,
18591859
);
18601860
return Err(diag.emit());
18611861
};

compiler/rustc_hir_analysis/src/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,6 @@ pub fn check_function_signature<'tcx>(
643643
let failure_code = cause.as_failure_code_diag(err, cause.span, vec![]);
644644
let mut diag = tcx.dcx().create_err(failure_code);
645645
err_ctxt.note_type_err(
646-
cause.span,
647646
&mut diag,
648647
&cause,
649648
None,
@@ -653,6 +652,7 @@ pub fn check_function_signature<'tcx>(
653652
}))),
654653
err,
655654
false,
655+
None,
656656
);
657657
return Err(diag.emit());
658658
}

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1113,13 +1113,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11131113
let trace = mk_trace(provided_span, (formal_ty, expected_ty), provided_ty);
11141114
if let Some(e) = error {
11151115
self.err_ctxt().note_type_err(
1116-
trace.cause.span,
11171116
&mut err,
11181117
&trace.cause,
11191118
None,
11201119
Some(self.param_env.and(trace.values)),
11211120
e,
11221121
true,
1122+
None,
11231123
);
11241124
}
11251125
}

compiler/rustc_passes/src/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22922292
}
22932293

22942294
infcx.err_ctxt().note_type_err(
2295-
cause.span,
22962295
&mut diag,
22972296
&cause,
22982297
None,
@@ -2302,6 +2301,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23022301
}))),
23032302
terr,
23042303
false,
2304+
None,
23052305
);
23062306
diag.emit();
23072307
self.abort.set(true);

compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1141,14 +1141,19 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
11411141
#[instrument(level = "debug", skip(self, diag, secondary_span, prefer_label))]
11421142
pub fn note_type_err(
11431143
&self,
1144-
span: Span,
11451144
diag: &mut Diag<'_>,
11461145
cause: &ObligationCause<'tcx>,
11471146
secondary_span: Option<(Span, Cow<'static, str>, bool)>,
11481147
mut values: Option<ty::ParamEnvAnd<'tcx, ValuePairs<'tcx>>>,
11491148
terr: TypeError<'tcx>,
11501149
prefer_label: bool,
1150+
override_span: Option<Span>,
11511151
) {
1152+
// We use `override_span` when we want the error to point at a `Span` other than
1153+
// `cause.span`. This is used in E0271, when a closure is passed in where the return type
1154+
// isn't what was expected. We want to point at the closure's return type (or expression),
1155+
// instead of the expression where the closure is passed as call argument.
1156+
let span = override_span.unwrap_or(cause.span);
11521157
// For some types of errors, expected-found does not make
11531158
// sense, so just ignore the values we were given.
11541159
if let TypeError::CyclicTy(_) = terr {
@@ -1799,13 +1804,13 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
17991804
);
18001805
let mut diag = self.dcx().create_err(failure_code);
18011806
self.note_type_err(
1802-
span,
18031807
&mut diag,
18041808
&trace.cause,
18051809
None,
18061810
Some(param_env.and(trace.values)),
18071811
terr,
18081812
false,
1813+
None,
18091814
);
18101815
diag
18111816
}

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -718,13 +718,13 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
718718
);
719719

720720
self.note_type_err(
721-
span,
722721
&mut diag,
723722
&obligation.cause,
724723
None,
725724
None,
726725
TypeError::Sorts(ty::error::ExpectedFound::new(true, expected_ty, ct_ty)),
727726
false,
727+
None,
728728
);
729729
diag
730730
}
@@ -1471,7 +1471,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
14711471
})();
14721472

14731473
self.note_type_err(
1474-
span,
14751474
&mut diag,
14761475
&obligation.cause,
14771476
secondary_span,
@@ -1484,6 +1483,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
14841483
}),
14851484
err,
14861485
false,
1486+
Some(span),
14871487
);
14881488
self.note_obligation_cause(&mut diag, obligation);
14891489
diag.emit()

0 commit comments

Comments
 (0)