Skip to content

WIP: Trust parameter env when projecting GATs #98742

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

Closed
wants to merge 2 commits into from
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
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,7 @@ fn confirm_param_env_candidate<'cx, 'tcx>(
match infcx.at(cause, param_env).eq(cache_projection, obligation_projection) {
Ok(InferOk { value: _, obligations }) => {
nested_obligations.extend(obligations);
assoc_ty_own_obligations(selcx, obligation, &mut nested_obligations);
// NDM 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 Down
3 changes: 3 additions & 0 deletions compiler/rustc_typeck/src/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,11 @@ fn compare_predicate_entailment<'tcx>(
let impl_m_own_bounds = impl_m_predicates.instantiate_own(tcx, impl_to_placeholder_substs);
for (predicate, span) in iter::zip(impl_m_own_bounds.predicates, impl_m_own_bounds.spans) {
let normalize_cause = traits::ObligationCause::misc(span, impl_m_hir_id);
debug!("predicate before normalization: {:?}", predicate);
let traits::Normalized { value: predicate, obligations } =
traits::normalize(&mut selcx, param_env, normalize_cause, predicate);
debug!("predicate after normalization: {:?}", predicate);
debug!("normalization obligations: {:#?}", obligations);

inh.register_predicates(obligations);
let cause = ObligationCause::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ use std::ops::Deref;
trait PointerFamily<U> {
type Pointer<T>: Deref<Target = T>;
//~^ ERROR generic associated types are unstable
type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
//~^ ERROR generic associated types are unstable
type Pointer2<T>: Deref<Target = T>
where
T: Clone,
U: Clone;
//~^^^^ ERROR generic associated types are unstable
//~| ERROR where clauses on associated types are unstable
}

Expand All @@ -15,12 +18,13 @@ impl PointerFamily<u32> for Foo {
//~^ ERROR generic associated types are unstable
type Pointer2<U32> = Box<U32>;
//~^ ERROR generic associated types are unstable
//~| ERROR the trait bound `U32: Clone` is not satisfied
}

trait Bar {
type Assoc where Self: Sized;
//~^ ERROR where clauses on associated types are unstable
type Assoc
where
Self: Sized;
//~^^^ ERROR where clauses on associated types are unstable
}

impl Bar for Foo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,29 @@ LL | type Pointer<T>: Deref<Target = T>;
error[E0658]: generic associated types are unstable
--> $DIR/feature-gate-generic_associated_types.rs:6:5
|
LL | type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | / type Pointer2<T>: Deref<Target = T>
LL | | where
LL | | T: Clone,
LL | | U: Clone;
| |_________________^
|
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable

error[E0658]: where clauses on associated types are unstable
--> $DIR/feature-gate-generic_associated_types.rs:6:5
|
LL | type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | / type Pointer2<T>: Deref<Target = T>
LL | | where
LL | | T: Clone,
LL | | U: Clone;
| |_________________^
|
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable

error[E0658]: generic associated types are unstable
--> $DIR/feature-gate-generic_associated_types.rs:14:5
--> $DIR/feature-gate-generic_associated_types.rs:17:5
|
LL | type Pointer<Usize> = Box<Usize>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -35,7 +41,7 @@ LL | type Pointer<Usize> = Box<Usize>;
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable

error[E0658]: generic associated types are unstable
--> $DIR/feature-gate-generic_associated_types.rs:16:5
--> $DIR/feature-gate-generic_associated_types.rs:19:5
|
LL | type Pointer2<U32> = Box<U32>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -44,35 +50,25 @@ LL | type Pointer2<U32> = Box<U32>;
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable

error[E0658]: where clauses on associated types are unstable
--> $DIR/feature-gate-generic_associated_types.rs:22:5
--> $DIR/feature-gate-generic_associated_types.rs:24:5
|
LL | type Assoc where Self: Sized;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | / type Assoc
LL | | where
LL | | Self: Sized;
| |____________________^
|
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable

error[E0658]: where clauses on associated types are unstable
--> $DIR/feature-gate-generic_associated_types.rs:27:5
--> $DIR/feature-gate-generic_associated_types.rs:31:5
|
LL | type Assoc = Foo where Self: Sized;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable

error[E0277]: the trait bound `U32: Clone` is not satisfied
--> $DIR/feature-gate-generic_associated_types.rs:16:26
|
LL | type Pointer2<U32> = Box<U32>;
| ^^^^^^^^ the trait `Clone` is not implemented for `U32`
|
help: consider restricting type parameter `U32`
|
LL | type Pointer2<U32: std::clone::Clone> = Box<U32>;
| +++++++++++++++++++

error: aborting due to 8 previous errors
error: aborting due to 7 previous errors

Some errors have detailed explanations: E0277, E0658.
For more information about an error, try `rustc --explain E0277`.
For more information about this error, try `rustc --explain E0658`.
9 changes: 4 additions & 5 deletions src/test/ui/generic-associated-types/bugs/issue-87755.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// check-fail
// known-bug: #87755

// This should pass.
// check-pass

#![feature(generic_associated_types)]

use std::fmt::Debug;

trait Foo {
type Ass where Self::Ass: Debug;
type Ass
where
Self::Ass: Debug;
}

#[derive(Debug)]
Expand Down
9 changes: 0 additions & 9 deletions src/test/ui/generic-associated-types/bugs/issue-87755.stderr

This file was deleted.

33 changes: 33 additions & 0 deletions src/test/ui/generic-associated-types/call-back-compat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// known-bug
// check-pass

#![feature(generic_associated_types)]

trait LendingIterator {
type Item<'a>
where
Self: 'a;
}

impl<'slice> LendingIterator for &'slice [u32] {
type Item<'a> = &'a [u32]
where
Self: 'a;
}

impl<'slice> LendingIterator for [u32] {
type Item<'a> = &'a [u32]
where
Self: 'a;
}

fn broke<T: ?Sized>() -> Option<&'static [u32]>
where
for<'a> T: LendingIterator<Item<'a> = &'a [u32]>,
{
None::<<T as LendingIterator>::Item<'static>>
// FIXME: Should not compile, but does, because we are trusting the where-clauses
// and don't have implied bounds.
}

fn main() {}
43 changes: 43 additions & 0 deletions src/test/ui/generic-associated-types/call-forall.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#![feature(generic_associated_types)]

trait LendingIterator {
type Item<'a>
where
Self: 'a;
}

impl<'slice> LendingIterator for &'slice [u32] {
type Item<'a> = &'a [u32]
where
Self: 'a;
}

impl<'slice> LendingIterator for [u32] {
type Item<'a> = &'a [u32]
where
Self: 'a;
}

fn call_me<T: ?Sized>()
where
for<'a> T: LendingIterator<Item<'a> = &'a [u32]>,
{
if false {
call_me::<T>();
}
}

fn ok_i_will1<'test>() {
// Gets an error because we cannot prove that, for all 'a, `&'test [u32]: 'a`.
//
// This is a bug -- what should happen is that there is an implied bound
// so that `for<'a>` really means "for all `'a` that make sense", in which case
// this ought to be provable.
call_me::<&'test [u32]>; //~ ERROR lifetime may not live long enough
}

fn ok_i_will2() {
// OK because, for all 'a, `[u32]: 'a`.
call_me::<[u32]>;
}
fn main() {}
11 changes: 11 additions & 0 deletions src/test/ui/generic-associated-types/call-forall.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: lifetime may not live long enough
--> $DIR/call-forall.rs:36:5
|
LL | fn ok_i_will1<'test>() {
| ----- lifetime `'test` defined here
...
LL | call_me::<&'test [u32]>;
| ^^^^^^^^^^^^^^^^^^^^^^^ requires that `'test` must outlive `'static`

error: aborting due to previous error

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Regression test from https://github.com/rust-lang/rust/pull/98109
//
// check-pass

#![feature(generic_associated_types)]

Expand All @@ -13,10 +15,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

This file was deleted.

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

#![feature(generic_associated_types)]
#![cfg_attr(extended, feature(generic_associated_types_extended))]
#![cfg_attr(extended, allow(incomplete_features))]

pub trait FromLendingIterator<A>: Sized {
fn from_iter<T: for<'x> LendingIterator<Item<'x> = A>>(iter: T) -> Self;
}

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
@@ -1,18 +1,13 @@
// revisions: base extended
//[base] check-fail
//[extended] check-pass
// check-pass

#![feature(generic_associated_types)]
#![cfg_attr(extended, feature(generic_associated_types_extended))]
#![cfg_attr(extended, allow(incomplete_features))]

pub trait FromLendingIterator<A>: Sized {
fn from_iter<T: for<'x> LendingIterator<Item<'x> = A>>(iter: T) -> Self;
}

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
@@ -1,15 +1,18 @@
#![feature(generic_associated_types)]

// Checking the interaction with this other feature
#![feature(associated_type_defaults)]

use std::fmt::{Display, Debug};
use std::fmt::{Debug, Display};

trait Foo {
type Assoc where Self: Sized;
type Assoc2<T> where T: Display;
type Assoc
where
Self: Sized;
type Assoc2<T>
where
T: Display;
type Assoc3<T>;
type WithDefault<'a, T: Debug + 'a>: ?Sized = dyn Iterator<Item=T>;
type WithDefault<'a, T: Debug + 'a>: ?Sized = dyn Iterator<Item = T>;
type NoGenerics;
}

Expand All @@ -18,10 +21,9 @@ struct Bar;
impl Foo for Bar {
type Assoc = usize;
type Assoc2<T> = Vec<T>;
//~^ ERROR `T` doesn't implement `std::fmt::Display`
type Assoc3<T> = Vec<T> where T: Iterator;
//~^ ERROR impl has stricter requirements than trait
type WithDefault<'a, T: Debug + 'a> = &'a dyn Iterator<Item=T>;
type WithDefault<'a, T: Debug + 'a> = &'a dyn Iterator<Item = T>;
type NoGenerics = ::std::cell::Cell<i32>;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
error[E0277]: `T` doesn't implement `std::fmt::Display`
--> $DIR/generic-associated-types-where.rs:20:22
|
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
help: consider restricting type parameter `T`
|
LL | type Assoc2<T: std::fmt::Display> = Vec<T>;
| +++++++++++++++++++

error[E0276]: impl has stricter requirements than trait
--> $DIR/generic-associated-types-where.rs:22:5
--> $DIR/generic-associated-types-where.rs:24:5
|
LL | type Assoc3<T>;
| --------------- definition of `Assoc3` from trait
...
LL | type Assoc3<T> = Vec<T> where T: Iterator;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: Iterator`

error: aborting due to 2 previous errors
error: aborting due to previous error

Some errors have detailed explanations: E0276, E0277.
For more information about an error, try `rustc --explain E0276`.
For more information about this error, try `rustc --explain E0276`.
Loading