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

Normalize when collecting TAITs in signature #116819

Closed
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 14 additions & 2 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,20 @@ impl<'tcx> TyCtxt<'tcx> {
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)) {
(
CheckRegions::Bound,
ty::ReFree(ty::FreeRegion {
bound_region: ty::BoundRegionKind::BrNamed(def_id, _),
..
})
| ty::ReLateBound(
_,
ty::BoundRegion {
kind: ty::BoundRegionKind::BrNamed(def_id, _), ..
},
),
) => {
if !seen_late.insert(def_id) {
return Err(NotUniqueParam::DuplicateParam(lt.into()));
}
}
Expand Down
242 changes: 149 additions & 93 deletions compiler/rustc_ty_utils/src/opaque_types.rs

Large diffs are not rendered by default.

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.
// 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.

Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
//! This test shows that a field type that is a projection that resolves to an opaque,
//! is not a defining use. While we could substitute the struct generics, that would
//! mean we would have to walk all substitutions of an `Foo`, which can quickly
//! degenerate into looking at an exponential number of types depending on the complexity
//! of a program.
// check-pass

#![feature(impl_trait_in_assoc_type)]

Expand All @@ -17,7 +13,6 @@ impl Trait for Bar {
type Assoc = impl std::fmt::Debug;
fn foo() -> Foo<Bar> {
Foo { field: () }
//~^ ERROR: mismatched types
}
}

Expand Down

This file was deleted.

4 changes: 1 addition & 3 deletions tests/ui/type-alias-impl-trait/higher_kinded_params2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! This test checks the behaviour of walking into binders
//! and normalizing something behind them actually works.
// check-pass

// edition: 2021

Expand All @@ -24,7 +23,6 @@ type Successors<'a> = impl std::fmt::Debug + 'a;
impl Terminator {
fn successors(&self, mut f: for<'x> fn(&'x ()) -> <&'x A as B>::C) -> Successors<'_> {
f = g;
//~^ ERROR item constrains opaque type that is not in its signature
}
}

Expand Down
15 changes: 0 additions & 15 deletions tests/ui/type-alias-impl-trait/higher_kinded_params2.stderr

This file was deleted.

1 change: 0 additions & 1 deletion tests/ui/type-alias-impl-trait/higher_kinded_params3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ impl Terminator {
fn successors(&self, mut f: for<'x> fn(&'x ()) -> <&'x A as B>::C) -> Successors<'_> {
f = g;
//~^ ERROR mismatched types
//~| ERROR item constrains opaque type that is not in its signature
}
}

Expand Down
15 changes: 1 addition & 14 deletions tests/ui/type-alias-impl-trait/higher_kinded_params3.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
error: item constrains opaque type that is not in its signature
--> $DIR/higher_kinded_params3.rs:26:13
|
LL | f = g;
| ^
|
= note: this item must mention the opaque type in its signature in order to be able to register hidden types
note: this item must mention the opaque type in its signature in order to be able to register hidden types
--> $DIR/higher_kinded_params3.rs:25:8
|
LL | fn successors(&self, mut f: for<'x> fn(&'x ()) -> <&'x A as B>::C) -> Successors<'_> {
| ^^^^^^^^^^

error[E0308]: mismatched types
--> $DIR/higher_kinded_params3.rs:26:9
|
Expand All @@ -23,6 +10,6 @@ LL | f = g;
= note: expected fn pointer `for<'x> fn(&'x ()) -> Tait<'x>`
found fn pointer `for<'a> fn(&'a ()) -> &'a ()`

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

For more information about this error, try `rustc --explain E0308`.
3 changes: 2 additions & 1 deletion tests/ui/type-alias-impl-trait/issue-70121.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// check-pass

#![feature(type_alias_impl_trait)]

pub type Successors<'a> = impl Iterator<Item = &'a ()>;
Expand All @@ -15,7 +17,6 @@ impl<'a> Tr for &'a () {
}

pub fn kazusa<'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/type-alias-impl-trait/issue-70121.stderr

This file was deleted.

Loading