Skip to content

Commit a94beac

Browse files
Resolve anon const's parent generics to opaque's parent
1 parent 213ad10 commit a94beac

File tree

6 files changed

+31
-28
lines changed

6 files changed

+31
-28
lines changed

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,8 @@ pub(super) fn explicit_predicates_of<'tcx>(
463463
} else {
464464
if matches!(def_kind, DefKind::AnonConst) && tcx.features().generic_const_exprs {
465465
let hir_id = tcx.local_def_id_to_hir_id(def_id);
466+
// FIXME(generic_const_exprs): The parenting of this def id is sketchy.
467+
// That should be fixed.
466468
let parent_def_id = tcx.hir().get_parent_item(hir_id);
467469

468470
if let Some(defaulted_param_def_id) =
@@ -529,14 +531,13 @@ pub(super) fn explicit_predicates_of<'tcx>(
529531
//
530532
// To fix this, we call `explicit_predicates_of` directly on `foo`, the parent's parent.
531533

532-
// In the above example this is `foo::{opaque#0}` or `impl Iterator`
533-
let parent_hir_id = tcx.local_def_id_to_hir_id(parent_def_id.def_id);
534-
535-
// In the above example this is the function `foo`
536-
let item_def_id = tcx.hir().get_parent_item(parent_hir_id);
534+
let (hir::OpaqueTyOrigin::FnReturn(item_owner_def_id)
535+
| hir::OpaqueTyOrigin::AsyncFn(item_owner_def_id)
536+
| hir::OpaqueTyOrigin::TyAlias { parent: item_owner_def_id, .. }) =
537+
tcx.opaque_type_origin(parent_def_id.def_id);
537538

538539
// In the above code example we would be calling `explicit_predicates_of(foo)` here
539-
return tcx.explicit_predicates_of(item_def_id);
540+
return tcx.explicit_predicates_of(item_owner_def_id);
540541
}
541542
}
542543
gather_explicit_predicates_of(tcx, def_id)

tests/crashes/118403.rs

-8
This file was deleted.

tests/crashes/121574-2.rs

-8
This file was deleted.

tests/crashes/121574.rs

-6
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ check-pass
2+
3+
#![feature(generic_const_exprs)]
4+
//~^ WARN the feature `generic_const_exprs` is incomplete and may not be safe to use
5+
6+
pub fn y<'a, U: 'a>() -> impl IntoIterator<Item = impl IntoIterator<Item = [u8; { 1 + 2 }]> + 'a> {
7+
[[[1, 2, 3]]]
8+
}
9+
// Make sure that the `predicates_of` for `{ 1 + 2 }` don't mention the duplicated lifetimes of
10+
// the *outer* iterator. Whether they should mention the duplicated lifetimes of the *inner*
11+
// iterator are another question, but not really something we need to answer immediately.
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/double-opaque-parent-predicates.rs:3:12
3+
|
4+
LL | #![feature(generic_const_exprs)]
5+
| ^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+

0 commit comments

Comments
 (0)