Skip to content

Commit ec25d6d

Browse files
committed
Don't cancel stashed TraitMissingMethod errors.
This gives one extra error message on two tests, but is necessary to fix bigger problems caused by the cancellation of stashed errors. (Note: why not just avoid stashing altogether? Because that resulted in additional output changes.)
1 parent c4ec196 commit ec25d6d

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -879,17 +879,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
879879
);
880880
}
881881

882-
// emit or cancel the diagnostic for bare traits
882+
// Emit the diagnostic for bare traits. (We used to cancel for slightly better
883+
// error messages, but cancelling stashed diagnostics is no longer allowed because
884+
// it causes problems when tracking whether errors have actually occurred.)
883885
if span.edition().at_least_rust_2021()
884886
&& let Some(diag) =
885887
self.dcx().steal_diagnostic(qself.span, StashKey::TraitMissingMethod)
886888
{
887-
if trait_missing_method {
888-
// cancel the diag for bare traits when meeting `MyTrait::missing_method`
889-
diag.cancel();
890-
} else {
891-
diag.emit();
892-
}
889+
diag.emit();
893890
}
894891

895892
if item_name.name != kw::Empty {

tests/ui/resolve/issue-111312.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ trait Has {
77
trait HasNot {}
88

99
fn main() {
10-
HasNot::has(); //~ ERROR
10+
HasNot::has();
11+
//~^ ERROR trait objects must include the `dyn` keyword
12+
//~| ERROR no function or associated item named `has` found for trait `HasNot`
1113
}

tests/ui/resolve/issue-111312.stderr

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
error[E0782]: trait objects must include the `dyn` keyword
2+
--> $DIR/issue-111312.rs:10:5
3+
|
4+
LL | HasNot::has();
5+
| ^^^^^^
6+
|
7+
help: add `dyn` keyword before this trait
8+
|
9+
LL | <dyn HasNot>::has();
10+
| ++++ +
11+
112
error[E0599]: no function or associated item named `has` found for trait `HasNot`
213
--> $DIR/issue-111312.rs:10:13
314
|
@@ -10,6 +21,7 @@ note: `Has` defines an item `has`
1021
LL | trait Has {
1122
| ^^^^^^^^^
1223

13-
error: aborting due to 1 previous error
24+
error: aborting due to 2 previous errors
1425

15-
For more information about this error, try `rustc --explain E0599`.
26+
Some errors have detailed explanations: E0599, E0782.
27+
For more information about an error, try `rustc --explain E0599`.

tests/ui/resolve/issue-111727.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//@ edition: 2021
22

33
fn main() {
4-
std::any::Any::create(); //~ ERROR
4+
std::any::Any::create();
5+
//~^ ERROR trait objects must include the `dyn` keyword
6+
//~| ERROR no function or associated item named `create` found for trait `Any`
57
}

tests/ui/resolve/issue-111727.stderr

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1+
error[E0782]: trait objects must include the `dyn` keyword
2+
--> $DIR/issue-111727.rs:4:5
3+
|
4+
LL | std::any::Any::create();
5+
| ^^^^^^^^^^^^^
6+
|
7+
help: add `dyn` keyword before this trait
8+
|
9+
LL | <dyn std::any::Any>::create();
10+
| ++++ +
11+
112
error[E0599]: no function or associated item named `create` found for trait `Any`
213
--> $DIR/issue-111727.rs:4:20
314
|
415
LL | std::any::Any::create();
516
| ^^^^^^ function or associated item not found in `Any`
617

7-
error: aborting due to 1 previous error
18+
error: aborting due to 2 previous errors
819

9-
For more information about this error, try `rustc --explain E0599`.
20+
Some errors have detailed explanations: E0599, E0782.
21+
For more information about an error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)