Skip to content

Commit 9143370

Browse files
authored
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`
2 parents 5dd9313 + 3f0a327 commit 9143370

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ declare_lint! {
3737
/// type Assoc: Duh;
3838
/// }
3939
///
40-
/// struct Struct;
41-
///
4240
/// impl<F: Duh> Trait for F {
4341
/// type Assoc = F;
4442
/// }
@@ -53,12 +51,12 @@ declare_lint! {
5351
/// {{produces}}
5452
///
5553
/// In this example, `test` declares that the associated type `Assoc` for
56-
/// `impl Trait` is `impl Sized`, which does not satisfy the `Send` bound
54+
/// `impl Trait` is `impl Sized`, which does not satisfy the bound `Duh`
5755
/// on the associated type.
5856
///
5957
/// Although the hidden type, `i32` does satisfy this bound, we do not
6058
/// consider the return type to be well-formed with this lint. It can be
61-
/// fixed by changing `Tait = impl Sized` into `Tait = impl Sized + Send`.
59+
/// fixed by changing `Tait = impl Sized` into `Tait = impl Sized + Duh`.
6260
pub OPAQUE_HIDDEN_INFERRED_BOUND,
6361
Warn,
6462
"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 {
7977
for (pred, pred_span) in
8078
cx.tcx.explicit_item_bounds(def_id).instantiate_identity_iter_copied()
8179
{
82-
// Liberate bound regions in the predicate since we
83-
// don't actually care about lifetimes in this check.
84-
let predicate = cx.tcx.liberate_late_bound_regions(def_id, pred.kind());
80+
let predicate = infcx.instantiate_binder_with_placeholders(pred.kind());
8581
let ty::ClauseKind::Projection(proj) = predicate else {
8682
continue;
8783
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// check-pass
2+
3+
#![feature(non_lifetime_binders)]
4+
//~^ WARN the feature `non_lifetime_binders` is incomplete
5+
6+
trait Trait<T: ?Sized> {}
7+
8+
impl<T: ?Sized> Trait<T> for i32 {}
9+
10+
fn produce() -> impl for<T> Trait<T> {
11+
16
12+
}
13+
14+
fn main() {
15+
let _ = produce();
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/on-rpit.rs:3: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+
warning: 1 warning emitted
11+

0 commit comments

Comments
 (0)