Rollup merge of #116379 - fmease:opaq-hid-inf-bnds-non-lt-bndrs, r=compiler-errors
non_lifetime_binders: fix ICE in lint opaque-hidden-inferred-bound Opaque types like `impl for<T> Trait<T>` would previously lead to an ICE. r? `@compiler-errors`
This commit is contained in:
commit
9143370868
3 changed files with 30 additions and 7 deletions
|
@ -37,8 +37,6 @@ declare_lint! {
|
||||||
/// type Assoc: Duh;
|
/// type Assoc: Duh;
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// struct Struct;
|
|
||||||
///
|
|
||||||
/// impl<F: Duh> Trait for F {
|
/// impl<F: Duh> Trait for F {
|
||||||
/// type Assoc = F;
|
/// type Assoc = F;
|
||||||
/// }
|
/// }
|
||||||
|
@ -53,12 +51,12 @@ declare_lint! {
|
||||||
/// {{produces}}
|
/// {{produces}}
|
||||||
///
|
///
|
||||||
/// In this example, `test` declares that the associated type `Assoc` for
|
/// In this example, `test` declares that the associated type `Assoc` for
|
||||||
/// `impl Trait` is `impl Sized`, which does not satisfy the `Send` bound
|
/// `impl Trait` is `impl Sized`, which does not satisfy the bound `Duh`
|
||||||
/// on the associated type.
|
/// on the associated type.
|
||||||
///
|
///
|
||||||
/// Although the hidden type, `i32` does satisfy this bound, we do not
|
/// Although the hidden type, `i32` does satisfy this bound, we do not
|
||||||
/// consider the return type to be well-formed with this lint. It can be
|
/// consider the return type to be well-formed with this lint. It can be
|
||||||
/// fixed by changing `Tait = impl Sized` into `Tait = impl Sized + Send`.
|
/// fixed by changing `Tait = impl Sized` into `Tait = impl Sized + Duh`.
|
||||||
pub OPAQUE_HIDDEN_INFERRED_BOUND,
|
pub OPAQUE_HIDDEN_INFERRED_BOUND,
|
||||||
Warn,
|
Warn,
|
||||||
"detects the use of nested `impl Trait` types in associated type bounds that are not general enough"
|
"detects the use of nested `impl Trait` types in associated type bounds that are not general enough"
|
||||||
|
@ -79,9 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
|
||||||
for (pred, pred_span) in
|
for (pred, pred_span) in
|
||||||
cx.tcx.explicit_item_bounds(def_id).instantiate_identity_iter_copied()
|
cx.tcx.explicit_item_bounds(def_id).instantiate_identity_iter_copied()
|
||||||
{
|
{
|
||||||
// Liberate bound regions in the predicate since we
|
let predicate = infcx.instantiate_binder_with_placeholders(pred.kind());
|
||||||
// don't actually care about lifetimes in this check.
|
|
||||||
let predicate = cx.tcx.liberate_late_bound_regions(def_id, pred.kind());
|
|
||||||
let ty::ClauseKind::Projection(proj) = predicate else {
|
let ty::ClauseKind::Projection(proj) = predicate else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
16
tests/ui/traits/non_lifetime_binders/on-rpit.rs
Normal file
16
tests/ui/traits/non_lifetime_binders/on-rpit.rs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
#![feature(non_lifetime_binders)]
|
||||||
|
//~^ WARN the feature `non_lifetime_binders` is incomplete
|
||||||
|
|
||||||
|
trait Trait<T: ?Sized> {}
|
||||||
|
|
||||||
|
impl<T: ?Sized> Trait<T> for i32 {}
|
||||||
|
|
||||||
|
fn produce() -> impl for<T> Trait<T> {
|
||||||
|
16
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = produce();
|
||||||
|
}
|
11
tests/ui/traits/non_lifetime_binders/on-rpit.stderr
Normal file
11
tests/ui/traits/non_lifetime_binders/on-rpit.stderr
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||||
|
--> $DIR/on-rpit.rs:3: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
|
||||||
|
|
||||||
|
warning: 1 warning emitted
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue