Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify secondary_span and swap_secondary_and_primary args in note_type_err #131753

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,14 +592,13 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
&cause,
hir.get_if_local(impl_m.def_id)
.and_then(|node| node.fn_decl())
.map(|decl| (decl.output.span(), Cow::from("return type in trait"))),
.map(|decl| (decl.output.span(), Cow::from("return type in trait"), false)),
jieyouxu marked this conversation as resolved.
Show resolved Hide resolved
Some(infer::ValuePairs::Terms(ExpectedFound {
expected: trait_return_ty.into(),
found: impl_return_ty.into(),
})),
terr,
false,
false,
);
return Err(diag.emit());
}
Expand Down Expand Up @@ -1018,14 +1017,13 @@ fn report_trait_method_mismatch<'tcx>(
infcx.err_ctxt().note_type_err(
&mut diag,
&cause,
trait_err_span.map(|sp| (sp, Cow::from("type in trait"))),
trait_err_span.map(|sp| (sp, Cow::from("type in trait"), false)),
Some(infer::ValuePairs::PolySigs(ExpectedFound {
expected: ty::Binder::dummy(trait_sig),
found: ty::Binder::dummy(impl_sig),
})),
terr,
false,
false,
);

diag.emit()
Expand Down Expand Up @@ -1825,14 +1823,13 @@ fn compare_const_predicate_entailment<'tcx>(
infcx.err_ctxt().note_type_err(
&mut diag,
&cause,
trait_c_span.map(|span| (span, Cow::from("type in trait"))),
trait_c_span.map(|span| (span, Cow::from("type in trait"), false)),
Some(infer::ValuePairs::Terms(ExpectedFound {
expected: trait_ty.into(),
found: impl_ty.into(),
})),
terr,
false,
false,
);
return Err(diag.emit());
};
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,6 @@ pub fn check_function_signature<'tcx>(
})),
err,
false,
false,
);
return Err(diag.emit());
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
None,
Some(trace.values),
e,
false,
true,
);
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2302,7 +2302,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
})),
terr,
false,
false,
);
diag.emit();
self.abort.set(true);
Expand Down
18 changes: 7 additions & 11 deletions compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,18 +1127,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
/// the message in `secondary_span` as the primary label, and apply the message that would
/// otherwise be used for the primary label on the `secondary_span` `Span`. This applies on
/// E0271, like `tests/ui/issues/issue-39970.stderr`.
#[instrument(
level = "debug",
skip(self, diag, secondary_span, swap_secondary_and_primary, prefer_label)
)]
#[instrument(level = "debug", skip(self, diag, secondary_span, prefer_label))]
pub fn note_type_err(
&self,
diag: &mut Diag<'_>,
cause: &ObligationCause<'tcx>,
secondary_span: Option<(Span, Cow<'static, str>)>,
secondary_span: Option<(Span, Cow<'static, str>, bool)>,
mut values: Option<ValuePairs<'tcx>>,
terr: TypeError<'tcx>,
swap_secondary_and_primary: bool,
prefer_label: bool,
) {
let span = cause.span();
Expand Down Expand Up @@ -1304,7 +1300,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
diag.span_note(span, msg);
}
};
if let Some((sp, msg)) = secondary_span {
if let Some((secondary_span, secondary_msg, swap_secondary_and_primary)) = secondary_span {
if swap_secondary_and_primary {
let terr = if let Some(infer::ValuePairs::Terms(ExpectedFound {
expected, ..
Expand All @@ -1314,11 +1310,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
} else {
terr.to_string(self.tcx)
};
label_or_note(sp, terr);
label_or_note(span, msg);
label_or_note(secondary_span, terr);
label_or_note(span, secondary_msg);
} else {
label_or_note(span, terr.to_string(self.tcx));
label_or_note(sp, msg);
label_or_note(secondary_span, secondary_msg);
}
} else if let Some(values) = values
&& let Some((e, f)) = values.ty()
Expand Down Expand Up @@ -1788,7 +1784,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
self.type_error_additional_suggestions(&trace, terr),
);
let mut diag = self.dcx().create_err(failure_code);
self.note_type_err(&mut diag, &trace.cause, None, Some(trace.values), terr, false, false);
self.note_type_err(&mut diag, &trace.cause, None, Some(trace.values), terr, false);
diag
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
None,
TypeError::Sorts(ty::error::ExpectedFound::new(true, expected_ty, ct_ty)),
false,
false,
);
diag
}
Expand Down Expand Up @@ -1435,6 +1434,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
cx.into_buffer()
}
))),
true,
)),
_ => None,
}
Expand All @@ -1452,7 +1452,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
))
}),
err,
true,
false,
);
self.note_obligation_cause(&mut diag, obligation);
Expand Down
Loading