Skip to content

Commit 8973b3e

Browse files
Bubble up ErrorGuaranteed from region constraints in method item compare
1 parent 6161758 commit 8973b3e

File tree

9 files changed

+24
-40
lines changed

9 files changed

+24
-40
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ fn check_opaque_meets_bounds<'tcx>(
468468
// Can have different predicates to their defining use
469469
hir::OpaqueTyOrigin::TyAlias => {
470470
let outlives_environment = OutlivesEnvironment::new(param_env);
471-
infcx.check_region_obligations_and_report_errors(
471+
let _ = infcx.check_region_obligations_and_report_errors(
472472
defining_use_anchor,
473473
&outlives_environment,
474474
);

compiler/rustc_hir_analysis/src/check/compare_method.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
589589
infcx.check_region_obligations_and_report_errors(
590590
impl_m.def_id.expect_local(),
591591
&outlives_environment,
592-
);
592+
)?;
593593

594594
let mut collected_tys = FxHashMap::default();
595595
for (def_id, (ty, substs)) in collector.types {
@@ -1617,9 +1617,9 @@ pub(crate) fn compare_impl_const_raw(
16171617
return Err(infcx.err_ctxt().report_fulfillment_errors(&errors, None));
16181618
}
16191619

1620-
// FIXME return `ErrorReported` if region obligations error?
16211620
let outlives_environment = OutlivesEnvironment::new(param_env);
1622-
infcx.check_region_obligations_and_report_errors(impl_const_item_def, &outlives_environment);
1621+
infcx.check_region_obligations_and_report_errors(impl_const_item_def, &outlives_environment)?;
1622+
16231623
Ok(())
16241624
}
16251625

@@ -1730,7 +1730,7 @@ fn compare_type_predicate_entailment<'tcx>(
17301730
infcx.check_region_obligations_and_report_errors(
17311731
impl_ty.def_id.expect_local(),
17321732
&outlives_environment,
1733-
);
1733+
)?;
17341734

17351735
Ok(())
17361736
}
@@ -1944,7 +1944,7 @@ pub fn check_type_bounds<'tcx>(
19441944
infcx.check_region_obligations_and_report_errors(
19451945
impl_ty.def_id.expect_local(),
19461946
&outlives_environment,
1947-
);
1947+
)?;
19481948

19491949
let constraints = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
19501950
for (key, value) in constraints {

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub(super) fn enter_wf_checking_ctxt<'tcx, F>(
115115
let outlives_environment =
116116
OutlivesEnvironment::with_bounds(param_env, Some(infcx), implied_bounds);
117117

118-
infcx.check_region_obligations_and_report_errors(body_def_id, &outlives_environment);
118+
let _ = infcx.check_region_obligations_and_report_errors(body_def_id, &outlives_environment);
119119
}
120120

121121
fn check_well_formed(tcx: TyCtxt<'_>, def_id: hir::OwnerId) {

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
325325

326326
// Finally, resolve all regions.
327327
let outlives_env = OutlivesEnvironment::new(param_env);
328-
infcx.check_region_obligations_and_report_errors(impl_did, &outlives_env);
328+
let _ = infcx.check_region_obligations_and_report_errors(impl_did, &outlives_env);
329329
}
330330
}
331331
_ => {
@@ -565,7 +565,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
565565

566566
// Finally, resolve all regions.
567567
let outlives_env = OutlivesEnvironment::new(param_env);
568-
infcx.check_region_obligations_and_report_errors(impl_did, &outlives_env);
568+
let _ = infcx.check_region_obligations_and_report_errors(impl_did, &outlives_env);
569569

570570
CoerceUnsizedInfo { custom_kind: kind }
571571
}

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn get_impl_substs(
182182

183183
let implied_bounds = infcx.implied_bounds_tys(param_env, impl1_hir_id, assumed_wf_types);
184184
let outlives_env = OutlivesEnvironment::with_bounds(param_env, Some(infcx), implied_bounds);
185-
infcx.check_region_obligations_and_report_errors(impl1_def_id, &outlives_env);
185+
let _ = infcx.check_region_obligations_and_report_errors(impl1_def_id, &outlives_env);
186186
let Ok(impl2_substs) = infcx.fully_resolve(impl2_substs) else {
187187
let span = tcx.def_span(impl1_def_id);
188188
tcx.sess.emit_err(SubstsOnOverriddenImpl { span });

compiler/rustc_infer/src/infer/mod.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
16931693
&self,
16941694
generic_param_scope: LocalDefId,
16951695
outlives_env: &OutlivesEnvironment<'tcx>,
1696-
) -> Option<ErrorGuaranteed> {
1696+
) -> Result<(), ErrorGuaranteed> {
16971697
let errors = self.resolve_regions(outlives_env);
16981698

16991699
if let None = self.tainted_by_errors() {
@@ -1705,9 +1705,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
17051705
self.report_region_errors(generic_param_scope, &errors);
17061706
}
17071707

1708-
(!errors.is_empty()).then(|| {
1709-
self.tcx.sess.delay_span_bug(rustc_span::DUMMY_SP, "error should have been emitted")
1710-
})
1708+
if errors.is_empty() {
1709+
Ok(())
1710+
} else {
1711+
Err(self
1712+
.tcx
1713+
.sess
1714+
.delay_span_bug(rustc_span::DUMMY_SP, "error should have been emitted"))
1715+
}
17111716
}
17121717

17131718
// [Note-Type-error-reporting]

compiler/rustc_infer/src/infer/outlives/obligations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl<'tcx> InferCtxt<'tcx> {
178178
&self,
179179
generic_param_scope: LocalDefId,
180180
outlives_env: &OutlivesEnvironment<'tcx>,
181-
) -> Option<ErrorGuaranteed> {
181+
) -> Result<(), ErrorGuaranteed> {
182182
self.process_registered_region_obligations(
183183
outlives_env.region_bound_pairs(),
184184
outlives_env.param_env,

src/test/ui/generic-associated-types/impl_bounds.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ impl<T> Foo for Fooy<T> {
1515
//~^ ERROR impl has stricter requirements than trait
1616
type B<'a, 'b> = (&'a(), &'b ()) where 'b: 'a;
1717
//~^ ERROR impl has stricter requirements than trait
18-
//~| ERROR lifetime bound not satisfied
1918
type C = String where Self: Copy;
2019
//~^ ERROR the trait bound `T: Copy` is not satisfied
2120
fn d() where Self: Copy {}

src/test/ui/generic-associated-types/impl_bounds.stderr

+4-24
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,8 @@ LL | type B<'a, 'b> where 'a: 'b;
1616
LL | type B<'a, 'b> = (&'a(), &'b ()) where 'b: 'a;
1717
| ^^ impl has extra requirement `'b: 'a`
1818

19-
error[E0478]: lifetime bound not satisfied
20-
--> $DIR/impl_bounds.rs:16:22
21-
|
22-
LL | type B<'a, 'b> where 'a: 'b;
23-
| -------------- definition of `B` from trait
24-
...
25-
LL | type B<'a, 'b> = (&'a(), &'b ()) where 'b: 'a;
26-
| ^^^^^^^^^^^^^^^ - help: try copying this clause from the trait: `, 'a: 'b`
27-
|
28-
note: lifetime parameter instantiated with the lifetime `'a` as defined here
29-
--> $DIR/impl_bounds.rs:16:12
30-
|
31-
LL | type B<'a, 'b> = (&'a(), &'b ()) where 'b: 'a;
32-
| ^^
33-
note: but lifetime parameter must outlive the lifetime `'b` as defined here
34-
--> $DIR/impl_bounds.rs:16:16
35-
|
36-
LL | type B<'a, 'b> = (&'a(), &'b ()) where 'b: 'a;
37-
| ^^
38-
3919
error[E0277]: the trait bound `T: Copy` is not satisfied
40-
--> $DIR/impl_bounds.rs:19:33
20+
--> $DIR/impl_bounds.rs:18:33
4121
|
4222
LL | type C = String where Self: Copy;
4323
| ^^^^ the trait `Copy` is not implemented for `T`
@@ -62,7 +42,7 @@ LL | impl<T: std::marker::Copy> Foo for Fooy<T> {
6242
| +++++++++++++++++++
6343

6444
error[E0277]: the trait bound `T: Copy` is not satisfied
65-
--> $DIR/impl_bounds.rs:21:24
45+
--> $DIR/impl_bounds.rs:20:24
6646
|
6747
LL | fn d() where Self: Copy {}
6848
| ^^^^ the trait `Copy` is not implemented for `T`
@@ -86,7 +66,7 @@ help: consider restricting type parameter `T`
8666
LL | impl<T: std::marker::Copy> Foo for Fooy<T> {
8767
| +++++++++++++++++++
8868

89-
error: aborting due to 5 previous errors
69+
error: aborting due to 4 previous errors
9070

91-
Some errors have detailed explanations: E0276, E0277, E0478.
71+
Some errors have detailed explanations: E0276, E0277.
9272
For more information about an error, try `rustc --explain E0276`.

0 commit comments

Comments
 (0)