diff options
| author | Michael Howell <michael@notriddle.com> | 2021-09-28 15:56:45 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2021-09-28 15:56:45 -0700 |
| commit | 105b60f2501fac061284ea7f5fbb8fb3f8134a92 (patch) | |
| tree | d8817bdb1bc03dae64918f8d203cbf7261f71304 /compiler | |
| parent | befdfb5c7113b3d82d973b1acfdcc2b0d9c14ab1 (diff) | |
feat(rustc_typeck): avoid erroring with "wrong number of generics" if there's other problems
As shown in the two test requirements that got updated, if there's other problems, then those other problems are probably the root cause of the incorrect generics count.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_hir/src/hir.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/astconv/generics.rs | 2 |
2 files changed, 11 insertions, 1 deletions
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 5655c4c0e97..d952d5a544d 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -384,6 +384,16 @@ impl GenericArgs<'_> { self.args.iter().any(|arg| matches!(arg, GenericArg::Type(_))) } + pub fn has_err(&self) -> bool { + self.args.iter().any(|arg| match arg { + GenericArg::Type(ty) => matches!(ty.kind, TyKind::Err), + _ => false, + }) || self.bindings.iter().any(|arg| match arg.kind { + TypeBindingKind::Equality { ty } => matches!(ty.kind, TyKind::Err), + _ => false, + }) + } + #[inline] pub fn num_type_params(&self) -> usize { self.args.iter().filter(|arg| matches!(arg, GenericArg::Type(_))).count() diff --git a/compiler/rustc_typeck/src/astconv/generics.rs b/compiler/rustc_typeck/src/astconv/generics.rs index fd0544a47bb..92fc18854ee 100644 --- a/compiler/rustc_typeck/src/astconv/generics.rs +++ b/compiler/rustc_typeck/src/astconv/generics.rs @@ -601,7 +601,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { def_id, ) .diagnostic() - .emit(); + .emit_unless(gen_args.has_err()); false }; |
