Skip to content

Commit a7d71ed

Browse files
authored
Rollup merge of rust-lang#147670 - lcnr:no-ok-ret-guar, r=BoxyUwU
some `ErrorGuaranteed` cleanups If we've got an `ErrorGuaranteed`, use it.
2 parents 91cf9b3 + 4dfbf11 commit a7d71ed

File tree

4 files changed

+16
-37
lines changed

4 files changed

+16
-37
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,9 +1651,7 @@ fn check_method_receiver<'tcx>(
16511651

16521652
// If the receiver already has errors reported, consider it valid to avoid
16531653
// unnecessary errors (#58712).
1654-
if receiver_ty.references_error() {
1655-
return Ok(());
1656-
}
1654+
receiver_ty.error_reported()?;
16571655

16581656
let arbitrary_self_types_level = if tcx.features().arbitrary_self_types_pointers() {
16591657
Some(ArbitrarySelfTypesLevel::WithPointers)

compiler/rustc_hir_analysis/src/coherence/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ fn check_impl<'tcx>(
3939

4040
// Skip impls where one of the self type is an error type.
4141
// This occurs with e.g., resolve failures (#30589).
42-
if trait_ref.references_error() {
43-
return Ok(());
44-
}
42+
trait_ref.error_reported()?;
4543

4644
enforce_trait_manually_implementable(tcx, impl_def_id, trait_ref.def_id, trait_def)
4745
.and(enforce_empty_impls_for_marker_traits(tcx, impl_def_id, trait_ref.def_id, trait_def))
@@ -188,9 +186,9 @@ fn check_object_overlap<'tcx>(
188186
) -> Result<(), ErrorGuaranteed> {
189187
let trait_def_id = trait_ref.def_id;
190188

191-
if trait_ref.references_error() {
189+
if let Err(guar) = trait_ref.error_reported() {
192190
debug!("coherence: skipping impl {:?} with error {:?}", impl_def_id, trait_ref);
193-
return Ok(());
191+
return Err(guar);
194192
}
195193

196194
// check for overlap with the automatic `impl Trait for dyn Trait`

compiler/rustc_hir_analysis/src/impl_wf_check.rs

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,10 @@ pub(crate) fn enforce_impl_lifetime_params_are_constrained(
7676
impl_def_id: LocalDefId,
7777
) -> Result<(), ErrorGuaranteed> {
7878
let impl_self_ty = tcx.type_of(impl_def_id).instantiate_identity();
79-
if impl_self_ty.references_error() {
80-
// Don't complain about unconstrained type params when self ty isn't known due to errors.
81-
// (#36836)
82-
tcx.dcx().span_delayed_bug(
83-
tcx.def_span(impl_def_id),
84-
format!(
85-
"potentially unconstrained type parameters weren't evaluated: {impl_self_ty:?}",
86-
),
87-
);
88-
// This is super fishy, but our current `rustc_hir_analysis::check_crate` pipeline depends on
89-
// `type_of` having been called much earlier, and thus this value being read from cache.
90-
// Compilation must continue in order for other important diagnostics to keep showing up.
91-
return Ok(());
92-
}
79+
80+
// Don't complain about unconstrained type params when self ty isn't known due to errors.
81+
// (#36836)
82+
impl_self_ty.error_reported()?;
9383

9484
let impl_generics = tcx.generics_of(impl_def_id);
9585
let impl_predicates = tcx.predicates_of(impl_def_id);
@@ -174,20 +164,11 @@ pub(crate) fn enforce_impl_non_lifetime_params_are_constrained(
174164
impl_def_id: LocalDefId,
175165
) -> Result<(), ErrorGuaranteed> {
176166
let impl_self_ty = tcx.type_of(impl_def_id).instantiate_identity();
177-
if impl_self_ty.references_error() {
178-
// Don't complain about unconstrained type params when self ty isn't known due to errors.
179-
// (#36836)
180-
tcx.dcx().span_delayed_bug(
181-
tcx.def_span(impl_def_id),
182-
format!(
183-
"potentially unconstrained type parameters weren't evaluated: {impl_self_ty:?}",
184-
),
185-
);
186-
// This is super fishy, but our current `rustc_hir_analysis::check_crate` pipeline depends on
187-
// `type_of` having been called much earlier, and thus this value being read from cache.
188-
// Compilation must continue in order for other important diagnostics to keep showing up.
189-
return Ok(());
190-
}
167+
168+
// Don't complain about unconstrained type params when self ty isn't known due to errors.
169+
// (#36836)
170+
impl_self_ty.error_reported()?;
171+
191172
let impl_generics = tcx.generics_of(impl_def_id);
192173
let impl_predicates = tcx.predicates_of(impl_def_id);
193174
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).map(ty::EarlyBinder::instantiate_identity);

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
685685
});
686686
let ty =
687687
self.check_expr_with_expectation_and_needs(oprnd, hint, Needs::maybe_mut_place(mutbl));
688+
if let Err(guar) = ty.error_reported() {
689+
return Ty::new_error(self.tcx, guar);
690+
}
688691

689692
match kind {
690-
_ if ty.references_error() => Ty::new_misc_error(self.tcx),
691693
hir::BorrowKind::Raw => {
692694
self.check_named_place_expr(oprnd);
693695
Ty::new_ptr(self.tcx, ty, mutbl)

0 commit comments

Comments
 (0)