Skip to content

Commit 133cec7

Browse files
authored
Rollup merge of rust-lang#139346 - compiler-errors:non-lifetime-binder-diag-hir-wf-check, r=oli-obk
Don't construct preds w escaping bound vars in `diagnostic_hir_wf_check` See comment inline. Fixes rust-lang#139330 r? oli-obk
2 parents dd682f7 + f343b9d commit 133cec7

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed

compiler/rustc_hir_analysis/src/hir_wf_check.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_infer::infer::TyCtxtInferExt;
44
use rustc_infer::traits::{ObligationCause, WellFormedLoc};
55
use rustc_middle::bug;
66
use rustc_middle::query::Providers;
7-
use rustc_middle::ty::{self, TyCtxt, TypingMode, fold_regions};
7+
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt, TypingMode, fold_regions};
88
use rustc_span::def_id::LocalDefId;
99
use rustc_trait_selection::traits::{self, ObligationCtxt};
1010
use tracing::debug;
@@ -77,6 +77,15 @@ fn diagnostic_hir_wf_check<'tcx>(
7777
let tcx_ty = fold_regions(self.tcx, tcx_ty, |r, _| {
7878
if r.is_bound() { self.tcx.lifetimes.re_erased } else { r }
7979
});
80+
81+
// We may be checking the WFness of a type in an opaque with a non-lifetime bound.
82+
// Perhaps we could rebind all the escaping bound vars, but they're coming from
83+
// arbitrary debruijn indices and aren't particularly important anyways, since they
84+
// are only coming from `feature(non_lifetime_binders)` anyways.
85+
if tcx_ty.has_escaping_bound_vars() {
86+
return;
87+
}
88+
8089
let cause = traits::ObligationCause::new(
8190
ty.span,
8291
self.def_id,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Make sure not to construct predicates with escaping bound vars in `diagnostic_hir_wf_check`.
2+
// Regression test for <https://github.com/rust-lang/rust/issues/139330>.
3+
4+
#![feature(non_lifetime_binders)]
5+
//~^ WARN the feature `non_lifetime_binders` is incomplete
6+
7+
trait A<T: ?Sized> {}
8+
impl<T: ?Sized> A<T> for () {}
9+
10+
trait B {}
11+
struct W<T: B>(T);
12+
13+
fn b() -> (W<()>, impl for<C> A<C>) { (W(()), ()) }
14+
//~^ ERROR the trait bound `(): B` is not satisfied
15+
//~| ERROR the trait bound `(): B` is not satisfied
16+
//~| ERROR the trait bound `(): B` is not satisfied
17+
18+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/diagnostic-hir-wf-check.rs:4:12
3+
|
4+
LL | #![feature(non_lifetime_binders)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error[E0277]: the trait bound `(): B` is not satisfied
11+
--> $DIR/diagnostic-hir-wf-check.rs:13:12
12+
|
13+
LL | fn b() -> (W<()>, impl for<C> A<C>) { (W(()), ()) }
14+
| ^^^^^ the trait `B` is not implemented for `()`
15+
|
16+
help: this trait has no implementations, consider adding one
17+
--> $DIR/diagnostic-hir-wf-check.rs:10:1
18+
|
19+
LL | trait B {}
20+
| ^^^^^^^
21+
note: required by a bound in `W`
22+
--> $DIR/diagnostic-hir-wf-check.rs:11:13
23+
|
24+
LL | struct W<T: B>(T);
25+
| ^ required by this bound in `W`
26+
27+
error[E0277]: the trait bound `(): B` is not satisfied
28+
--> $DIR/diagnostic-hir-wf-check.rs:13:42
29+
|
30+
LL | fn b() -> (W<()>, impl for<C> A<C>) { (W(()), ()) }
31+
| - ^^ the trait `B` is not implemented for `()`
32+
| |
33+
| required by a bound introduced by this call
34+
|
35+
help: this trait has no implementations, consider adding one
36+
--> $DIR/diagnostic-hir-wf-check.rs:10:1
37+
|
38+
LL | trait B {}
39+
| ^^^^^^^
40+
note: required by a bound in `W`
41+
--> $DIR/diagnostic-hir-wf-check.rs:11:13
42+
|
43+
LL | struct W<T: B>(T);
44+
| ^ required by this bound in `W`
45+
46+
error[E0277]: the trait bound `(): B` is not satisfied
47+
--> $DIR/diagnostic-hir-wf-check.rs:13:40
48+
|
49+
LL | fn b() -> (W<()>, impl for<C> A<C>) { (W(()), ()) }
50+
| ^^^^^ the trait `B` is not implemented for `()`
51+
|
52+
help: this trait has no implementations, consider adding one
53+
--> $DIR/diagnostic-hir-wf-check.rs:10:1
54+
|
55+
LL | trait B {}
56+
| ^^^^^^^
57+
note: required by a bound in `W`
58+
--> $DIR/diagnostic-hir-wf-check.rs:11:13
59+
|
60+
LL | struct W<T: B>(T);
61+
| ^ required by this bound in `W`
62+
63+
error: aborting due to 3 previous errors; 1 warning emitted
64+
65+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)