Skip to content

Normalize when collecting TAITs in signature #116819

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
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
13 changes: 2 additions & 11 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ pub enum CheckRegions {
/// Only permit early bound regions. This is useful for Adts which
/// can never have late bound regions.
OnlyEarlyBound,
/// Permit both late bound and early bound regions. Use this for functions,
/// which frequently have late bound regions.
Bound,
}

#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -464,21 +461,15 @@ impl<'tcx> TyCtxt<'tcx> {
ignore_regions: CheckRegions,
) -> Result<(), NotUniqueParam<'tcx>> {
let mut seen = GrowableBitSet::default();
let mut seen_late = FxHashSet::default();
for arg in args {
match arg.unpack() {
GenericArgKind::Lifetime(lt) => match (ignore_regions, lt.kind()) {
(CheckRegions::Bound, ty::ReLateBound(di, reg)) => {
if !seen_late.insert((di, reg)) {
return Err(NotUniqueParam::DuplicateParam(lt.into()));
}
}
(CheckRegions::OnlyEarlyBound | CheckRegions::Bound, ty::ReEarlyBound(p)) => {
(CheckRegions::OnlyEarlyBound, ty::ReEarlyBound(p)) => {
if !seen.insert(p.index) {
return Err(NotUniqueParam::DuplicateParam(lt.into()));
}
}
(CheckRegions::OnlyEarlyBound | CheckRegions::Bound, _) => {
(CheckRegions::OnlyEarlyBound, _) => {
return Err(NotUniqueParam::NotParam(lt.into()));
}
(CheckRegions::No, _) => {}
Expand Down
307 changes: 164 additions & 143 deletions compiler/rustc_ty_utils/src/opaque_types.rs

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions tests/ui/generic-associated-types/issue-88595.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
error: non-defining opaque type use in defining scope
--> $DIR/issue-88595.rs:21:23
--> $DIR/issue-88595.rs:21:35
|
LL | fn a(&'a self) -> Self::B<'a> {}
| ^^^^^^^^^^^ generic argument `'a` used twice
| ^^
|
note: for this opaque type
--> $DIR/issue-88595.rs:19:18
note: lifetime used multiple times
--> $DIR/issue-88595.rs:18:6
|
LL | impl<'a> A<'a> for C {
| ^^
LL | type B<'b> = impl Clone;
| ^^^^^^^^^^
| ^^

error: aborting due to previous error

6 changes: 6 additions & 0 deletions tests/ui/generic-associated-types/issue-90014-tait.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
//! This test is reporting the wrong error. We need
//! more inherent associated type tests that use opaque types
//! in general. Some variant of this test should compile successfully.

// known-bug: unknown
// edition:2018
// failure-status: 101
// normalize-stderr-test "note: .*\n\n" -> ""
// normalize-stderr-test "thread 'rustc' panicked.*\n.*\n" -> ""
// normalize-stderr-test "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: "
// rustc-env:RUST_BACKTRACE=0

#![feature(impl_trait_in_assoc_type, inherent_associated_types)]
#![allow(incomplete_features)]
Expand Down
46 changes: 31 additions & 15 deletions tests/ui/generic-associated-types/issue-90014-tait.stderr
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
error[E0308]: mismatched types
--> $DIR/issue-90014-tait.rs:18:9
error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error[E0391]: cycle detected when computing function signature of `<impl at $DIR/issue-90014-tait.rs:20:1: 20:13>::make_fut`
--> $DIR/issue-90014-tait.rs:23:5
|
LL | type Fut<'a> = impl Future<Output = ()>;
| ------------------------ the expected future
LL |
LL | fn make_fut<'a>(&'a self) -> Self::Fut<'a> {
| ------------- expected `Foo<'_>::Fut<'a>` because of return type
LL | async { () }
| ^^^^^^^^^^^^ expected future, found `async` block
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires computing the variances of `Foo`...
--> $DIR/issue-90014-tait.rs:18:1
|
LL | struct Foo<'a>(&'a mut ());
| ^^^^^^^^^^^^^^
= note: ...which requires computing the variances for items in this crate...
= note: ...which again requires computing function signature of `<impl at $DIR/issue-90014-tait.rs:20:1: 20:13>::make_fut`, completing the cycle
note: cycle used when collecting item types in top-level module
--> $DIR/issue-90014-tait.rs:1:1
|
= note: expected opaque type `Foo<'_>::Fut<'a>`
found `async` block `{async block@$DIR/issue-90014-tait.rs:18:9: 18:21}`
note: this item must have the opaque type in its signature in order to be able to register hidden types
--> $DIR/issue-90014-tait.rs:17:8
LL | / //! This test is reporting the wrong error. We need
LL | | //! more inherent associated type tests that use opaque types
LL | | //! in general. Some variant of this test should compile successfully.
LL | |
... |
LL | |
LL | | fn main() {}
| |____________^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
note: delayed at compiler/rustc_query_system/src/query/job.rs:602:16 - disabled backtrace
--> $DIR/issue-90014-tait.rs:23:5
|
LL | fn make_fut<'a>(&'a self) -> Self::Fut<'a> {
| ^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error
query stack during panic:
end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
For more information about this error, try `rustc --explain E0391`.
4 changes: 1 addition & 3 deletions tests/ui/lint/issue-99387.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Test that we don't follow through projections to find
//! opaque types.
Comment on lines -1 to -2
Copy link
Contributor

Choose a reason for hiding this comment

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

Change the comments to explain what the test is testing now (same for all the other tests)

// check-pass

#![feature(type_alias_impl_trait)]
#![allow(private_interfaces)]
Expand All @@ -19,7 +18,6 @@ impl<'a> Tr for &'a () {
}

pub fn ohno<'a>() -> <&'a () as Tr>::Item {
//~^ ERROR item constrains opaque type that is not in its signature
None.into_iter()
}

Expand Down
15 changes: 0 additions & 15 deletions tests/ui/lint/issue-99387.stderr

This file was deleted.

1 change: 0 additions & 1 deletion tests/ui/type-alias-impl-trait/bound_reduction2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ trait Trait<U> {}
impl<W> Trait<W> for () {}

fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
//~^ ERROR non-defining opaque type use
()
//~^ ERROR expected generic type parameter, found `<T as TraitWithAssoc>::Assoc`
}
16 changes: 2 additions & 14 deletions tests/ui/type-alias-impl-trait/bound_reduction2.stderr
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
error[E0792]: non-defining opaque type use in defining scope
--> $DIR/bound_reduction2.rs:15:46
|
LL | fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
| ^^^^^^^^^^^^^ argument `<T as TraitWithAssoc>::Assoc` is not a generic parameter
|
note: for this opaque type
--> $DIR/bound_reduction2.rs:9:15
|
LL | type Foo<V> = impl Trait<V>;
| ^^^^^^^^^^^^^

error[E0792]: expected generic type parameter, found `<T as TraitWithAssoc>::Assoc`
--> $DIR/bound_reduction2.rs:17:5
--> $DIR/bound_reduction2.rs:16:5
|
LL | type Foo<V> = impl Trait<V>;
| - this generic parameter must be used with a generic type parameter
...
LL | ()
| ^^

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

For more information about this error, try `rustc --explain E0792`.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ fn main() {}
type Two<'a, 'b> = impl std::fmt::Debug;

fn one<'a>(t: &'a ()) -> Two<'a, 'a> {
//~^ ERROR non-defining opaque type use
t
//~^ ERROR non-defining opaque type use
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_lifetime_param.rs:7:26
|
LL | fn one<'a>(t: &'a ()) -> Two<'a, 'a> {
| ^^^^^^^^^^^ generic argument `'a` used twice
|
note: for this opaque type
--> $DIR/generic_duplicate_lifetime_param.rs:5:20
|
LL | type Two<'a, 'b> = impl std::fmt::Debug;
| ^^^^^^^^^^^^^^^^^^^^

error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_lifetime_param.rs:9:5
--> $DIR/generic_duplicate_lifetime_param.rs:8:5
|
LL | t
| ^
Expand All @@ -22,5 +10,5 @@ note: lifetime used multiple times
LL | type Two<'a, 'b> = impl std::fmt::Debug;
| ^^ ^^

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

3 changes: 0 additions & 3 deletions tests/ui/type-alias-impl-trait/generic_duplicate_param_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,16 @@ type TwoLifetimes<'a, 'b> = impl Debug;
type TwoConsts<const X: usize, const Y: usize> = impl Debug;

fn one_ty<T: Debug>(t: T) -> TwoTys<T, T> {
//~^ ERROR non-defining opaque type use in defining scope
t
//~^ ERROR non-defining opaque type use in defining scope
}

fn one_lifetime<'a>(t: &'a u32) -> TwoLifetimes<'a, 'a> {
//~^ ERROR non-defining opaque type use in defining scope
t
//~^ ERROR non-defining opaque type use in defining scope
}

fn one_const<const N: usize>(t: *mut [u8; N]) -> TwoConsts<N, N> {
//~^ ERROR non-defining opaque type use in defining scope
t
//~^ ERROR non-defining opaque type use in defining scope
}
44 changes: 4 additions & 40 deletions tests/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use.rs:21:30
|
LL | fn one_ty<T: Debug>(t: T) -> TwoTys<T, T> {
| ^^^^^^^^^^^^ generic argument `T` used twice
|
note: for this opaque type
--> $DIR/generic_duplicate_param_use.rs:15:21
|
LL | type TwoTys<T, U> = impl Debug;
| ^^^^^^^^^^

error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use.rs:23:5
--> $DIR/generic_duplicate_param_use.rs:22:5
|
LL | t
| ^
Expand All @@ -23,19 +11,7 @@ LL | type TwoTys<T, U> = impl Debug;
| ^ ^

error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use.rs:27:36
|
LL | fn one_lifetime<'a>(t: &'a u32) -> TwoLifetimes<'a, 'a> {
| ^^^^^^^^^^^^^^^^^^^^ generic argument `'a` used twice
|
note: for this opaque type
--> $DIR/generic_duplicate_param_use.rs:17:29
|
LL | type TwoLifetimes<'a, 'b> = impl Debug;
| ^^^^^^^^^^

error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use.rs:29:5
--> $DIR/generic_duplicate_param_use.rs:27:5
|
LL | t
| ^
Expand All @@ -47,19 +23,7 @@ LL | type TwoLifetimes<'a, 'b> = impl Debug;
| ^^ ^^

error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use.rs:33:50
|
LL | fn one_const<const N: usize>(t: *mut [u8; N]) -> TwoConsts<N, N> {
| ^^^^^^^^^^^^^^^ generic argument `N` used twice
|
note: for this opaque type
--> $DIR/generic_duplicate_param_use.rs:19:50
|
LL | type TwoConsts<const X: usize, const Y: usize> = impl Debug;
| ^^^^^^^^^^

error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use.rs:35:5
--> $DIR/generic_duplicate_param_use.rs:32:5
|
LL | t
| ^
Expand All @@ -70,5 +34,5 @@ note: constant used multiple times
LL | type TwoConsts<const X: usize, const Y: usize> = impl Debug;
| ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^

error: aborting due to 6 previous errors
error: aborting due to 3 previous errors

3 changes: 0 additions & 3 deletions tests/ui/type-alias-impl-trait/generic_nondefining_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@ type OneConst<const X: usize> = impl Debug;
// Not defining uses, because they doesn't define *all* possible generics.

fn concrete_ty() -> OneTy<u32> {
//~^ ERROR: non-defining opaque type use in defining scope
5u32
//~^ ERROR: expected generic type parameter, found `u32`
}

fn concrete_lifetime() -> OneLifetime<'static> {
//~^ ERROR: non-defining opaque type use in defining scope
6u32
//~^ ERROR: expected generic lifetime parameter, found `'static`
}

fn concrete_const() -> OneConst<{ 123 }> {
//~^ ERROR: non-defining opaque type use in defining scope
7u32
//~^ ERROR: expected generic constant parameter, found `123`
}
Loading