Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore RPIT duplicated lifetimes in opaque_types_defined_by #117371

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// Checks whether each generic argument is simply a unique generic parameter.
pub fn uses_unique_generic_params(
self,
args: GenericArgsRef<'tcx>,
args: &[ty::GenericArg<'tcx>],
ignore_regions: CheckRegions,
) -> Result<(), NotUniqueParam<'tcx>> {
let mut seen = GrowableBitSet::default();
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_ty_utils/src/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,14 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {

self.opaques.push(alias_ty.def_id.expect_local());

match self.tcx.uses_unique_generic_params(alias_ty.args, CheckRegions::Bound) {
let parent_count = self.tcx.generics_of(alias_ty.def_id).parent_count;
// Only check that the parent generics of the TAIT/RPIT are unique.
// the args owned by the opaque are going to always be duplicate
// lifetime params for RPITs, and empty for TAITs.
match self
.tcx
.uses_unique_generic_params(&alias_ty.args[..parent_count], CheckRegions::Bound)
{
Ok(()) => {
// FIXME: implement higher kinded lifetime bounds on nested opaque types. They are not
// supported at all, so this is sound to do, but once we want to support them, you'll
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// check-pass

#![feature(type_alias_impl_trait)]

type Opaque<'lt> = impl Sized + 'lt;

fn test<'a>(
arg: impl Iterator<Item = &'a u8>,
) -> impl Iterator<Item = Opaque<'a>> {
arg
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// check-pass
// edition: 2021

#![feature(type_alias_impl_trait)]

struct Foo<'a>(&'a ());

impl<'a> Foo<'a> {
async fn new() -> () {
type T = impl Sized;
let _: T = ();
}
}

fn main() {}
Loading