Rollup merge of #125774 - mu001999-contrib:fix/125757, r=compiler-errors

Avoid unwrap diag.code directly in note_and_explain_type_err

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->

Fixes #125757
This commit is contained in:
Matthias Krüger 2024-05-31 08:50:23 +02:00 committed by GitHub
commit 4aafc1175e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 57 additions and 2 deletions

View file

@ -182,7 +182,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
diag.span_label(p_span, format!("{expected}this type parameter"));
}
diag.help("type parameters must be constrained to match other types");
if tcx.sess.teach(diag.code.unwrap()) {
if diag.code.is_some_and(|code| tcx.sess.teach(code)) {
diag.help(
"given a type parameter `T` and a method `foo`:
```
@ -663,7 +663,7 @@ impl<T> Trait<T> for X {
https://doc.rust-lang.org/book/ch19-03-advanced-traits.html",
);
}
if tcx.sess.teach(diag.code.unwrap()) {
if diag.code.is_some_and(|code| tcx.sess.teach(code)) {
diag.help(
"given an associated type `T` and a method `foo`:
```