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

Don't check GAT bounds in normalization #117682

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2328,6 +2328,7 @@ pub(super) fn check_type_bounds<'tcx>(
let obligations: Vec<_> = tcx
.explicit_item_bounds(trait_ty.def_id)
.iter_instantiated_copied(tcx, rebased_args)
.chain(tcx.predicates_of(trait_ty.def_id).instantiate_own(tcx, rebased_args))
.map(|(concrete_ty_bound, span)| {
debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound);
traits::Obligation::new(tcx, mk_cause(span), param_env, concrete_ty_bound)
Expand Down
55 changes: 1 addition & 54 deletions compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2314,7 +2314,6 @@ fn confirm_param_env_candidate<'cx, 'tcx>(
) {
Ok(InferOk { value: _, obligations }) => {
nested_obligations.extend(obligations);
assoc_ty_own_obligations(selcx, obligation, &mut nested_obligations);
// FIXME(associated_const_equality): Handle consts here as well? Maybe this progress type should just take
// a term instead.
Progress { term: cache_entry.term, obligations: nested_obligations }
Expand All @@ -2337,7 +2336,7 @@ fn confirm_impl_candidate<'cx, 'tcx>(
) -> Progress<'tcx> {
let tcx = selcx.tcx();

let ImplSourceUserDefinedData { impl_def_id, args, mut nested } = impl_impl_source;
let ImplSourceUserDefinedData { impl_def_id, args, nested } = impl_impl_source;
let assoc_item_id = obligation.predicate.def_id;
let trait_def_id = tcx.trait_id_of_impl(impl_def_id).unwrap();

Expand Down Expand Up @@ -2384,62 +2383,10 @@ fn confirm_impl_candidate<'cx, 'tcx>(
);
Progress { term: err.into(), obligations: nested }
} else {
assoc_ty_own_obligations(selcx, obligation, &mut nested);
Progress { term: term.instantiate(tcx, args), obligations: nested }
}
}

// Get obligations corresponding to the predicates from the where-clause of the
// associated type itself.
fn assoc_ty_own_obligations<'cx, 'tcx>(
selcx: &mut SelectionContext<'cx, 'tcx>,
obligation: &ProjectionTyObligation<'tcx>,
nested: &mut Vec<PredicateObligation<'tcx>>,
) {
let tcx = selcx.tcx();
let predicates = tcx
.predicates_of(obligation.predicate.def_id)
.instantiate_own(tcx, obligation.predicate.args);
for (predicate, span) in predicates {
let normalized = normalize_with_depth_to(
selcx,
obligation.param_env,
obligation.cause.clone(),
obligation.recursion_depth + 1,
predicate,
nested,
);

let nested_cause = if matches!(
obligation.cause.code(),
super::CompareImplItemObligation { .. }
| super::CheckAssociatedTypeBounds { .. }
| super::AscribeUserTypeProvePredicate(..)
) {
obligation.cause.clone()
} else if span.is_dummy() {
ObligationCause::new(
obligation.cause.span,
obligation.cause.body_id,
super::ItemObligation(obligation.predicate.def_id),
)
} else {
ObligationCause::new(
obligation.cause.span,
obligation.cause.body_id,
super::BindingObligation(obligation.predicate.def_id, span),
)
};
nested.push(Obligation::with_depth(
tcx,
nested_cause,
obligation.recursion_depth + 1,
obligation.param_env,
normalized,
));
}
}

pub(crate) trait ProjectionCacheKeyExt<'cx, 'tcx>: Sized {
fn from_poly_projection_predicate(
selcx: &mut SelectionContext<'cx, 'tcx>,
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/generic-associated-types/bugs/hrtb-implied-1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// check-fail
// known-bug: unknown
// check-pass

// This gives us problems because `for<'a> I::Item<'a>: Debug` should mean "for
// all 'a where I::Item<'a> is WF", but really means "for all 'a possible"
Expand Down
20 changes: 0 additions & 20 deletions tests/ui/generic-associated-types/bugs/hrtb-implied-1.stderr

This file was deleted.

3 changes: 1 addition & 2 deletions tests/ui/generic-associated-types/bugs/hrtb-implied-2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// check-fail
// known-bug: unknown
// check-pass

// This gives us problems because `for<'a> I::Item<'a>: Debug` should mean "for
// all 'a where I::Item<'a> is WF", but really means "for all 'a possible"
Expand Down
22 changes: 0 additions & 22 deletions tests/ui/generic-associated-types/bugs/hrtb-implied-2.stderr

This file was deleted.

3 changes: 2 additions & 1 deletion tests/ui/generic-associated-types/bugs/hrtb-implied-3.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// check-pass

trait LendingIterator {
type Item<'a>
where
Expand All @@ -17,7 +19,6 @@ where

fn fails(iter: &str) {
trivial_bound(iter);
//~^ borrowed data escapes
}

fn main() {}
22 changes: 0 additions & 22 deletions tests/ui/generic-associated-types/bugs/hrtb-implied-3.stderr

This file was deleted.

6 changes: 2 additions & 4 deletions tests/ui/generic-associated-types/bugs/issue-87755.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// check-fail
// known-bug: #87755

// This should pass.
// issue: #87755
// check-pass

use std::fmt::Debug;

Expand Down
9 changes: 0 additions & 9 deletions tests/ui/generic-associated-types/bugs/issue-87755.stderr

This file was deleted.

5 changes: 1 addition & 4 deletions tests/ui/generic-associated-types/collectivity-regression.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Regression test from https://github.com/rust-lang/rust/pull/98109
// check-pass

pub trait Get {
type Value<'a>
Expand All @@ -11,10 +12,6 @@ where
for<'a> T: Get<Value<'a> = ()>,
{
|| {
//~^ `T` does not live long enough
//
// FIXME(#98437). This regressed at some point and
// probably should work.
let _x = x;
};
}
Expand Down
24 changes: 0 additions & 24 deletions tests/ui/generic-associated-types/collectivity-regression.stderr

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// revisions: base extended
//[base] check-fail
//[base] check-pass
//[extended] check-pass

#![cfg_attr(extended, feature(generic_associated_types_extended))]
Expand All @@ -11,7 +11,6 @@ pub trait FromLendingIterator<A>: Sized {

impl<A> FromLendingIterator<A> for Vec<A> {
fn from_iter<I: for<'x> LendingIterator<Item<'x> = A>>(mut iter: I) -> Self {
//[base]~^ impl has stricter
let mut v = vec![];
while let Some(item) = iter.next() {
v.push(item);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// revisions: base extended
//[base] check-fail
//[base] check-pass
//[extended] check-pass

#![cfg_attr(extended, feature(generic_associated_types_extended))]
Expand All @@ -11,7 +11,6 @@ pub trait FromLendingIterator<A>: Sized {

impl<A> FromLendingIterator<A> for Vec<A> {
fn from_iter<I: for<'x> LendingIterator<Item<'x> = A>>(mut iter: I) -> Self {
//[base]~^ impl has stricter
let mut v = vec![];
while let Some(item) = iter.next() {
v.push(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ LL | type Assoc2<T> = Vec<T>;
| ^^^^^^ `T` cannot be formatted with the default formatter
|
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
note: required by a bound in `Foo::Assoc2`
--> $DIR/generic-associated-types-where.rs:8:29
|
LL | type Assoc2<T> where T: Display;
| ^^^^^^^ required by this bound in `Foo::Assoc2`
help: consider restricting type parameter `T`
|
LL | type Assoc2<T: std::fmt::Display> = Vec<T>;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/generic-associated-types/issue-84931.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct StreamingSliceIter<'a, T> {
impl<'b, T: 'b> StreamingIter for StreamingSliceIter<'b, T> {
type Item<'a> = &'a mut T;
//~^ ERROR: the parameter type
//~| ERROR: does not fulfill the required lifetime
//~| ERROR lifetime bound not satisfied
fn next(&mut self) -> Option<&mut T> {
loop {}
}
Expand Down
18 changes: 8 additions & 10 deletions tests/ui/generic-associated-types/issue-84931.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,24 @@ help: consider adding an explicit lifetime bound
LL | type Item<'a> = &'a mut T where T: 'a;
| +++++++++++

error[E0477]: the type `StreamingSliceIter<'b, T>` does not fulfill the required lifetime
error[E0478]: lifetime bound not satisfied
--> $DIR/issue-84931.rs:14:21
|
LL | type Item<'a> where Self: 'a;
| ------------- definition of `Item` from trait
...
LL | type Item<'a> = &'a mut T;
| ^^^^^^^^^
|
note: type must outlive the lifetime `'a` as defined here
note: lifetime parameter instantiated with the lifetime `'b` as defined here
--> $DIR/issue-84931.rs:13:6
|
LL | impl<'b, T: 'b> StreamingIter for StreamingSliceIter<'b, T> {
| ^^
note: but lifetime parameter must outlive the lifetime `'a` as defined here
--> $DIR/issue-84931.rs:14:15
|
LL | type Item<'a> = &'a mut T;
| ^^
help: copy the `where` clause predicates from the trait
|
LL | type Item<'a> = &'a mut T where Self: 'a;
| ++++++++++++++

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0309, E0477.
Some errors have detailed explanations: E0309, E0478.
For more information about an error, try `rustc --explain E0309`.
2 changes: 1 addition & 1 deletion tests/ui/generic-associated-types/issue-90014.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait MakeFut {

impl MakeFut for &'_ mut () {
type Fut<'a> = impl Future<Output = ()>;
//~^ ERROR: the type `&mut ()` does not fulfill the required lifetime
//~^ ERROR lifetime bound not satisfied

fn make_fut<'a>(&'a self) -> Self::Fut<'a> {
async { () }
Expand Down
18 changes: 8 additions & 10 deletions tests/ui/generic-associated-types/issue-90014.stderr
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
error[E0477]: the type `&mut ()` does not fulfill the required lifetime
error[E0478]: lifetime bound not satisfied
--> $DIR/issue-90014.rs:15:20
|
LL | type Fut<'a>
| ------------ definition of `Fut` from trait
...
LL | type Fut<'a> = impl Future<Output = ()>;
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
note: type must outlive the lifetime `'a` as defined here
note: lifetime parameter instantiated with the anonymous lifetime as defined here
--> $DIR/issue-90014.rs:14:19
|
LL | impl MakeFut for &'_ mut () {
| ^^
note: but lifetime parameter must outlive the lifetime `'a` as defined here
--> $DIR/issue-90014.rs:15:14
|
LL | type Fut<'a> = impl Future<Output = ()>;
| ^^
help: copy the `where` clause predicates from the trait
|
LL | type Fut<'a> = impl Future<Output = ()> where Self: 'a;
| ++++++++++++++

error: aborting due to previous error

For more information about this error, try `rustc --explain E0477`.
For more information about this error, try `rustc --explain E0478`.
Loading
Loading