Skip to content

Commit

Permalink
Don't cancel stashed TraitMissingMethod errors.
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
nnethercote committed Feb 27, 2024
1 parent a1b356a commit ebcba20
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
11 changes: 4 additions & 7 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,17 +879,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
}

// emit or cancel the diagnostic for bare traits
// Emit the diagnostic for bare traits. (We used to cancel for slightly better
// error messages, but cancelling stashed diagnostics is no longer allowed because
// it causes problems when tracking whether errors have actually occurred.)
if span.edition().at_least_rust_2021()
&& let Some(diag) =
self.dcx().steal_diagnostic(qself.span, StashKey::TraitMissingMethod)
{
if trait_missing_method {
// cancel the diag for bare traits when meeting `MyTrait::missing_method`
diag.cancel();
} else {
diag.emit();
}
diag.emit();
}

if item_name.name != kw::Empty {
Expand Down
4 changes: 3 additions & 1 deletion tests/ui/resolve/issue-111312.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ trait Has {
trait HasNot {}

fn main() {
HasNot::has(); //~ ERROR
HasNot::has();
//~^ ERROR trait objects must include the `dyn` keyword
//~| ERROR no function or associated item named `has` found for trait `HasNot`
}
16 changes: 14 additions & 2 deletions tests/ui/resolve/issue-111312.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/issue-111312.rs:10:5
|
LL | HasNot::has();
| ^^^^^^
|
help: add `dyn` keyword before this trait
|
LL | <dyn HasNot>::has();
| ++++ +

error[E0599]: no function or associated item named `has` found for trait `HasNot`
--> $DIR/issue-111312.rs:10:13
|
Expand All @@ -10,6 +21,7 @@ note: `Has` defines an item `has`
LL | trait Has {
| ^^^^^^^^^

error: aborting due to 1 previous error
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0599`.
Some errors have detailed explanations: E0599, E0782.
For more information about an error, try `rustc --explain E0599`.
4 changes: 3 additions & 1 deletion tests/ui/resolve/issue-111727.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//@ edition: 2021

fn main() {
std::any::Any::create(); //~ ERROR
std::any::Any::create();
//~^ ERROR trait objects must include the `dyn` keyword
//~| ERROR no function or associated item named `create` found for trait `Any`
}
16 changes: 14 additions & 2 deletions tests/ui/resolve/issue-111727.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/issue-111727.rs:4:5
|
LL | std::any::Any::create();
| ^^^^^^^^^^^^^
|
help: add `dyn` keyword before this trait
|
LL | <dyn std::any::Any>::create();
| ++++ +

error[E0599]: no function or associated item named `create` found for trait `Any`
--> $DIR/issue-111727.rs:4:20
|
LL | std::any::Any::create();
| ^^^^^^ function or associated item not found in `Any`

error: aborting due to 1 previous error
error: aborting due to 2 previous errors

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

0 comments on commit ebcba20

Please sign in to comment.