Skip to content

Commit 908aa47

Browse files
authored
Unrolled build for rust-lang#130123
Rollup merge of rust-lang#130123 - FedericoBruzzone:master, r=compiler-errors Report the `note` when specified in `diagnostic::on_unimplemented` Before this PR the `note` field was completely ignored for some reason, now it is shown (I think) correctly during the hir typechecking phase. 1. Report the `note` when specified in `diagnostic::on_unimplemented` 2. Added a test for unimplemented trait diagnostic 3. Added a test for custom unimplemented trait diagnostic Close rust-lang#130084 P.S. This is my first PR to rustc.
2 parents 5bce6d4 + 4cecf42 commit 908aa47

File tree

4 files changed

+62
-5
lines changed

4 files changed

+62
-5
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13171317
let actual_prefix = rcvr_ty.prefix_string(self.tcx);
13181318
info!("unimplemented_traits.len() == {}", unimplemented_traits.len());
13191319
let mut long_ty_file = None;
1320-
let (primary_message, label) = if unimplemented_traits.len() == 1
1320+
let (primary_message, label, notes) = if unimplemented_traits.len() == 1
13211321
&& unimplemented_traits_only
13221322
{
13231323
unimplemented_traits
@@ -1327,16 +1327,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13271327
if trait_ref.self_ty().references_error() || rcvr_ty.references_error()
13281328
{
13291329
// Avoid crashing.
1330-
return (None, None);
1330+
return (None, None, Vec::new());
13311331
}
1332-
let OnUnimplementedNote { message, label, .. } = self
1332+
let OnUnimplementedNote { message, label, notes, .. } = self
13331333
.err_ctxt()
13341334
.on_unimplemented_note(trait_ref, &obligation, &mut long_ty_file);
1335-
(message, label)
1335+
(message, label, notes)
13361336
})
13371337
.unwrap()
13381338
} else {
1339-
(None, None)
1339+
(None, None, Vec::new())
13401340
};
13411341
let primary_message = primary_message.unwrap_or_else(|| {
13421342
format!(
@@ -1363,6 +1363,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13631363
"the following trait bounds were not satisfied:\n{bound_list}"
13641364
));
13651365
}
1366+
for note in notes {
1367+
err.note(note);
1368+
}
1369+
13661370
suggested_derive = self.suggest_derive(&mut err, unsatisfied_predicates);
13671371

13681372
unsatisfied_bounds = true;

tests/ui/methods/suggest-convert-ptr-to-ref.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ note: the method `to_string` exists on the type `&u8`
1111
= note: the following trait bounds were not satisfied:
1212
`*const u8: std::fmt::Display`
1313
which is required by `*const u8: ToString`
14+
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
1415

1516
error[E0599]: `*mut u8` doesn't implement `std::fmt::Display`
1617
--> $DIR/suggest-convert-ptr-to-ref.rs:8:22
@@ -25,6 +26,7 @@ note: the method `to_string` exists on the type `&&mut u8`
2526
= note: the following trait bounds were not satisfied:
2627
`*mut u8: std::fmt::Display`
2728
which is required by `*mut u8: ToString`
29+
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
2830

2931
error[E0599]: no method named `make_ascii_lowercase` found for raw pointer `*mut u8` in the current scope
3032
--> $DIR/suggest-convert-ptr-to-ref.rs:9:7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#[diagnostic::on_unimplemented(message = "my message", label = "my label", note = "my note")]
2+
pub trait ProviderLt {}
3+
4+
pub trait ProviderExt {
5+
fn request<R>(&self) {
6+
todo!()
7+
}
8+
}
9+
10+
impl<T: ?Sized + ProviderLt> ProviderExt for T {}
11+
12+
struct B;
13+
14+
fn main() {
15+
B.request();
16+
//~^ my message [E0599]
17+
//~| my label
18+
//~| my note
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error[E0599]: my message
2+
--> $DIR/custom-on-unimplemented-diagnostic.rs:15:7
3+
|
4+
LL | struct B;
5+
| -------- method `request` not found for this struct because it doesn't satisfy `B: ProviderExt` or `B: ProviderLt`
6+
...
7+
LL | B.request();
8+
| ^^^^^^^ my label
9+
|
10+
note: trait bound `B: ProviderLt` was not satisfied
11+
--> $DIR/custom-on-unimplemented-diagnostic.rs:10:18
12+
|
13+
LL | impl<T: ?Sized + ProviderLt> ProviderExt for T {}
14+
| ^^^^^^^^^^ ----------- -
15+
| |
16+
| unsatisfied trait bound introduced here
17+
= note: my note
18+
note: the trait `ProviderLt` must be implemented
19+
--> $DIR/custom-on-unimplemented-diagnostic.rs:2:1
20+
|
21+
LL | pub trait ProviderLt {}
22+
| ^^^^^^^^^^^^^^^^^^^^
23+
= help: items from traits can only be used if the trait is implemented and in scope
24+
note: `ProviderExt` defines an item `request`, perhaps you need to implement it
25+
--> $DIR/custom-on-unimplemented-diagnostic.rs:4:1
26+
|
27+
LL | pub trait ProviderExt {
28+
| ^^^^^^^^^^^^^^^^^^^^^
29+
30+
error: aborting due to 1 previous error
31+
32+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)