diff options
| author | Michael Goulet <michael@errs.io> | 2024-11-23 18:32:10 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-11-23 23:31:30 +0000 |
| commit | cfa8fcbf581c8c311e079b04517cbe979d9beb7b (patch) | |
| tree | ef8f35d148daf7787be7b284b2a7da5f8c0aa404 /compiler | |
| parent | 898ccdb75426f5fb5c58e8057a83d015640613b8 (diff) | |
| download | rust-cfa8fcbf581c8c311e079b04517cbe979d9beb7b.tar.gz rust-cfa8fcbf581c8c311e079b04517cbe979d9beb7b.zip | |
Dont create trait object if it has errors in it
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs index 0ca30dc601d..f6e227377b9 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs @@ -8,7 +8,8 @@ use rustc_lint_defs::builtin::UNUSED_ASSOCIATED_TYPE_BOUNDS; use rustc_middle::span_bug; use rustc_middle::ty::fold::BottomUpFolder; use rustc_middle::ty::{ - self, DynKind, ExistentialPredicateStableCmpExt as _, Ty, TyCtxt, TypeFoldable, Upcast, + self, DynKind, ExistentialPredicateStableCmpExt as _, Ty, TyCtxt, TypeFoldable, + TypeVisitableExt, Upcast, }; use rustc_span::{ErrorGuaranteed, Span}; use rustc_trait_selection::error_reporting::traits::report_dyn_incompatibility; @@ -103,6 +104,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { let guar = self.report_trait_object_with_no_traits_error(span, &trait_bounds); return Ty::new_error(tcx, guar); } + // Don't create a dyn trait if we have errors in the principal. + if let Err(guar) = trait_bounds.error_reported() { + return Ty::new_error(tcx, guar); + } // Check that there are no gross dyn-compatibility violations; // most importantly, that the supertraits don't contain `Self`, |
