mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Rollup merge of #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 #139330 r? oli-obk
This commit is contained in:
commit
133cec7363
@ -4,7 +4,7 @@ use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_infer::traits::{ObligationCause, WellFormedLoc};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::ty::{self, TyCtxt, TypingMode, fold_regions};
|
||||
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt, TypingMode, fold_regions};
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_trait_selection::traits::{self, ObligationCtxt};
|
||||
use tracing::debug;
|
||||
@ -77,6 +77,15 @@ fn diagnostic_hir_wf_check<'tcx>(
|
||||
let tcx_ty = fold_regions(self.tcx, tcx_ty, |r, _| {
|
||||
if r.is_bound() { self.tcx.lifetimes.re_erased } else { r }
|
||||
});
|
||||
|
||||
// We may be checking the WFness of a type in an opaque with a non-lifetime bound.
|
||||
// Perhaps we could rebind all the escaping bound vars, but they're coming from
|
||||
// arbitrary debruijn indices and aren't particularly important anyways, since they
|
||||
// are only coming from `feature(non_lifetime_binders)` anyways.
|
||||
if tcx_ty.has_escaping_bound_vars() {
|
||||
return;
|
||||
}
|
||||
|
||||
let cause = traits::ObligationCause::new(
|
||||
ty.span,
|
||||
self.def_id,
|
||||
|
@ -0,0 +1,18 @@
|
||||
// Make sure not to construct predicates with escaping bound vars in `diagnostic_hir_wf_check`.
|
||||
// Regression test for <https://github.com/rust-lang/rust/issues/139330>.
|
||||
|
||||
#![feature(non_lifetime_binders)]
|
||||
//~^ WARN the feature `non_lifetime_binders` is incomplete
|
||||
|
||||
trait A<T: ?Sized> {}
|
||||
impl<T: ?Sized> A<T> for () {}
|
||||
|
||||
trait B {}
|
||||
struct W<T: B>(T);
|
||||
|
||||
fn b() -> (W<()>, impl for<C> A<C>) { (W(()), ()) }
|
||||
//~^ ERROR the trait bound `(): B` is not satisfied
|
||||
//~| ERROR the trait bound `(): B` is not satisfied
|
||||
//~| ERROR the trait bound `(): B` is not satisfied
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,65 @@
|
||||
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/diagnostic-hir-wf-check.rs:4:12
|
||||
|
|
||||
LL | #![feature(non_lifetime_binders)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
|
||||
error[E0277]: the trait bound `(): B` is not satisfied
|
||||
--> $DIR/diagnostic-hir-wf-check.rs:13:12
|
||||
|
|
||||
LL | fn b() -> (W<()>, impl for<C> A<C>) { (W(()), ()) }
|
||||
| ^^^^^ the trait `B` is not implemented for `()`
|
||||
|
|
||||
help: this trait has no implementations, consider adding one
|
||||
--> $DIR/diagnostic-hir-wf-check.rs:10:1
|
||||
|
|
||||
LL | trait B {}
|
||||
| ^^^^^^^
|
||||
note: required by a bound in `W`
|
||||
--> $DIR/diagnostic-hir-wf-check.rs:11:13
|
||||
|
|
||||
LL | struct W<T: B>(T);
|
||||
| ^ required by this bound in `W`
|
||||
|
||||
error[E0277]: the trait bound `(): B` is not satisfied
|
||||
--> $DIR/diagnostic-hir-wf-check.rs:13:42
|
||||
|
|
||||
LL | fn b() -> (W<()>, impl for<C> A<C>) { (W(()), ()) }
|
||||
| - ^^ the trait `B` is not implemented for `()`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
help: this trait has no implementations, consider adding one
|
||||
--> $DIR/diagnostic-hir-wf-check.rs:10:1
|
||||
|
|
||||
LL | trait B {}
|
||||
| ^^^^^^^
|
||||
note: required by a bound in `W`
|
||||
--> $DIR/diagnostic-hir-wf-check.rs:11:13
|
||||
|
|
||||
LL | struct W<T: B>(T);
|
||||
| ^ required by this bound in `W`
|
||||
|
||||
error[E0277]: the trait bound `(): B` is not satisfied
|
||||
--> $DIR/diagnostic-hir-wf-check.rs:13:40
|
||||
|
|
||||
LL | fn b() -> (W<()>, impl for<C> A<C>) { (W(()), ()) }
|
||||
| ^^^^^ the trait `B` is not implemented for `()`
|
||||
|
|
||||
help: this trait has no implementations, consider adding one
|
||||
--> $DIR/diagnostic-hir-wf-check.rs:10:1
|
||||
|
|
||||
LL | trait B {}
|
||||
| ^^^^^^^
|
||||
note: required by a bound in `W`
|
||||
--> $DIR/diagnostic-hir-wf-check.rs:11:13
|
||||
|
|
||||
LL | struct W<T: B>(T);
|
||||
| ^ required by this bound in `W`
|
||||
|
||||
error: aborting due to 3 previous errors; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
Loading…
Reference in New Issue
Block a user