diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-12-04 18:23:43 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-04 18:23:43 +0100 |
| commit | ea4e7192ac02b3dea9cf3c680bd0a252076c1133 (patch) | |
| tree | 194a26e75800022cae3ffbe224b50cadd589b428 /compiler/rustc_hir_analysis | |
| parent | 553db5faeea0d5e7aa944706cd833bc93600d632 (diff) | |
| parent | a91c36139a5aeef66483de18117788d3c85b8b9d (diff) | |
| download | rust-ea4e7192ac02b3dea9cf3c680bd0a252076c1133.tar.gz rust-ea4e7192ac02b3dea9cf3c680bd0a252076c1133.zip | |
Rollup merge of #133850 - oli-obk:push-xryukktpyooq, r=compiler-errors
Avoid `opaque type not constrained` errors in the presence of other errors pulled out of https://github.com/rust-lang/rust/pull/128440 These errors carry no new information if the opaque type was actually used in a constraining (but erroneous) way somewhere.
Diffstat (limited to 'compiler/rustc_hir_analysis')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs b/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs index fcea0052546..66255829dcf 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs @@ -226,13 +226,18 @@ impl TaitConstraintLocator<'_> { constrained = true; if !opaque_types_defined_by.contains(&self.def_id) { - self.tcx.dcx().emit_err(TaitForwardCompat { + let guar = self.tcx.dcx().emit_err(TaitForwardCompat { span: hidden_type.span, item_span: self .tcx .def_ident_span(item_def_id) .unwrap_or_else(|| self.tcx.def_span(item_def_id)), }); + // Avoid "opaque type not constrained" errors on the opaque itself. + self.found = Some(ty::OpaqueHiddenType { + span: DUMMY_SP, + ty: Ty::new_error(self.tcx, guar), + }); } let concrete_type = self.tcx.erase_regions(hidden_type.remap_generic_params_to_declaration_params( @@ -248,7 +253,7 @@ impl TaitConstraintLocator<'_> { if !constrained { debug!("no constraints in typeck results"); if opaque_types_defined_by.contains(&self.def_id) { - self.tcx.dcx().emit_err(TaitForwardCompat2 { + let guar = self.tcx.dcx().emit_err(TaitForwardCompat2 { span: self .tcx .def_ident_span(item_def_id) @@ -256,6 +261,11 @@ impl TaitConstraintLocator<'_> { opaque_type_span: self.tcx.def_span(self.def_id), opaque_type: self.tcx.def_path_str(self.def_id), }); + // Avoid "opaque type not constrained" errors on the opaque itself. + self.found = Some(ty::OpaqueHiddenType { + span: DUMMY_SP, + ty: Ty::new_error(self.tcx, guar), + }); } return; }; |
