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

Fix GAT lifetime bounds #64756

Closed
Closed
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
4 changes: 2 additions & 2 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,12 +790,12 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
}
Type(ref bounds, ref ty) => {
let generics = &trait_item.generics;
let mut index = self.next_early_index();
let index = self.next_early_index();
debug!("visit_ty: index = {}", index);
let mut non_lifetime_count = 0;
let lifetimes = generics.params.iter().filter_map(|param| match param.kind {
GenericParamKind::Lifetime { .. } => {
Some(Region::early(&self.tcx.hir(), &mut index, param))
Some(Region::late(&self.tcx.hir(), param))
}
GenericParamKind::Type { .. } |
GenericParamKind::Const { .. } => {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2450,11 +2450,11 @@ impl<'tcx> Bounds<'tcx> {

sized_predicate.into_iter().chain(
self.region_bounds.iter().map(|&(region_bound, span)| {
// Account for the binder being introduced below; no need to shift `param_ty`
// because, at present at least, it can only refer to early-bound regions.
let region_bound = ty::fold::shift_region(tcx, region_bound, 1);
// Because of GAT bounds, param_ty may have late-bound regions.
let param_ty = ty::fold::shift_vars(tcx, &param_ty, 1);
let outlives = ty::OutlivesPredicate(param_ty, region_bound);
(ty::Binder::dummy(outlives).to_predicate(), span)
(ty::Binder::bind(outlives).to_predicate(), span)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was flying blind here, and just tried to implement what the previous comment said, with a bit of trial and error. If someone who knows this code could review this that'd be appreciated.

}).chain(
self.trait_bounds.iter().map(|&(bound_trait_ref, span)| {
(bound_trait_ref.to_predicate(), span)
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/rfc1598-generic-associated-types/lifetime_bound.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// check-pass

// rust-lang/rust#62521: Do not ICE when a generic lifetime is used
// in the type's bound.

#![feature(generic_associated_types)]
//~^ WARNING the feature `generic_associated_types` is incomplete

trait Foo {
type PublicKey<'a>: From<&'a [u8]>;
}

trait Bar {
type Item<'a>: 'a;
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
warning: the feature `generic_associated_types` is incomplete and may cause the compiler to crash
--> $DIR/lifetime_bound.rs:6:12
|
LL | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default