Skip to content

Commit

Permalink
Rollup merge of rust-lang#120859 - nnethercote:fix-120856, r=oli-obk
Browse files Browse the repository at this point in the history
Loosen an assertion to account for stashed errors.

The meaning of this assertion changed in rust-lang#120828 when the meaning of `has_errors` changed to exclude stashed errors. Evidently the new meaning is too restrictive.

Fixes rust-lang#120856.

r? ``@oli-obk``
  • Loading branch information
matthiaskrgr committed Feb 10, 2024
2 parents be8bc1b + bb60ded commit 206669f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,8 @@ fn check_type_alias_type_params_are_used<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalD
let ty = tcx.type_of(def_id).instantiate_identity();
if ty.references_error() {
// If there is already another error, do not emit an error for not using a type parameter.
assert!(tcx.dcx().has_errors().is_some());
// Without the `stashed_err_count` part this can fail (#120856).
assert!(tcx.dcx().has_errors().is_some() || tcx.dcx().stashed_err_count() > 0);
return;
}

Expand Down
5 changes: 5 additions & 0 deletions tests/ui/typeck/issue-120856.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub type Archived<T> = <m::Alias as n::Trait>::Archived;
//~^ ERROR failed to resolve: use of undeclared crate or module `m`
//~| ERROR failed to resolve: use of undeclared crate or module `n`

fn main() {}
21 changes: 21 additions & 0 deletions tests/ui/typeck/issue-120856.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error[E0433]: failed to resolve: use of undeclared crate or module `n`
--> $DIR/issue-120856.rs:1:37
|
LL | pub type Archived<T> = <m::Alias as n::Trait>::Archived;
| ^
| |
| use of undeclared crate or module `n`
| help: a trait with a similar name exists: `Fn`

error[E0433]: failed to resolve: use of undeclared crate or module `m`
--> $DIR/issue-120856.rs:1:25
|
LL | pub type Archived<T> = <m::Alias as n::Trait>::Archived;
| ^
| |
| use of undeclared crate or module `m`
| help: a type parameter with a similar name exists: `T`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0433`.

0 comments on commit 206669f

Please sign in to comment.