Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 907f97e

Browse files
committed
Remove normalization from opaque_types_defined_by
1 parent 4c99872 commit 907f97e

File tree

9 files changed

+64
-58
lines changed

9 files changed

+64
-58
lines changed

compiler/rustc_ty_utils/src/opaque_types.rs

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@ use rustc_data_structures::fx::FxHashSet;
22
use rustc_hir::intravisit::Visitor;
33
use rustc_hir::{def::DefKind, def_id::LocalDefId};
44
use rustc_hir::{intravisit, CRATE_HIR_ID};
5-
use rustc_infer::infer::TyCtxtInferExt;
65
use rustc_middle::query::Providers;
7-
use rustc_middle::traits::ObligationCause;
86
use rustc_middle::ty::util::{CheckRegions, NotUniqueParam};
9-
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
7+
use rustc_middle::ty::{self, Ty, TyCtxt};
108
use rustc_middle::ty::{TypeSuperVisitable, TypeVisitable, TypeVisitor};
11-
use rustc_span::def_id::CRATE_DEF_ID;
129
use rustc_span::Span;
1310
use rustc_trait_selection::traits::check_substs_compatible;
14-
use rustc_trait_selection::traits::ObligationCtxt;
1511
use std::ops::ControlFlow;
1612

1713
use crate::errors::{DuplicateArg, NotParam};
@@ -139,20 +135,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
139135
rustc_hir::OpaqueTyOrigin::FnReturn(_)
140136
| rustc_hir::OpaqueTyOrigin::AsyncFn(_) => {}
141137
rustc_hir::OpaqueTyOrigin::TyAlias { in_assoc_ty } => {
142-
if in_assoc_ty {
143-
// Only associated items can be defining for opaque types in associated types.
144-
if let Some(parent) = self.parent() {
145-
let mut current = alias_ty.def_id.expect_local();
146-
while current != parent && current != CRATE_DEF_ID {
147-
current = self.tcx.local_parent(current);
148-
}
149-
if current != parent {
150-
return ControlFlow::Continue(());
151-
}
152-
} else {
153-
return ControlFlow::Continue(());
154-
}
155-
} else {
138+
if !in_assoc_ty {
156139
if !self.check_tait_defining_scope(alias_ty.def_id.expect_local()) {
157140
return ControlFlow::Continue(());
158141
}
@@ -246,28 +229,6 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
246229
}
247230
}
248231
}
249-
250-
// Normalize trivial projections.
251-
let mut infcx = self.tcx.infer_ctxt();
252-
let infcx = infcx.build();
253-
let t = if t.has_escaping_bound_vars() {
254-
let (t, _mapped_regions, _mapped_types, _mapped_consts) =
255-
rustc_trait_selection::traits::project::BoundVarReplacer::replace_bound_vars(
256-
&infcx,
257-
&mut self.universes,
258-
t,
259-
);
260-
t
261-
} else {
262-
t
263-
};
264-
let ocx = ObligationCtxt::new(&infcx);
265-
let cause = ObligationCause::dummy_with_span(self.span());
266-
let normalized = ocx.normalize(&cause, self.tcx.param_env(self.item), t);
267-
trace!(?normalized);
268-
if normalized != t {
269-
normalized.visit_with(self)?;
270-
}
271232
}
272233
ty::Adt(def, _) if def.did().is_local() => {
273234
if !self.seen.insert(def.did().expect_local()) {

tests/ui/lint/issue-99387.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// check-pass
1+
//! Test that we don't follow through projections to find
2+
//! opaque types.
23
34
#![feature(type_alias_impl_trait)]
45
#![allow(private_in_public)]
@@ -18,6 +19,7 @@ impl<'a> Tr for &'a () {
1819
}
1920

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

tests/ui/lint/issue-99387.stderr

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: item constrains opaque type that is not in its signature
2+
--> $DIR/issue-99387.rs:21:22
3+
|
4+
LL | pub fn ohno<'a>() -> <&'a () as Tr>::Item {
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: this item must mention the opaque type in its signature in order to be able to register hidden types
8+
note: this item must mention the opaque type in its signature in order to be able to register hidden types
9+
--> $DIR/issue-99387.rs:21:8
10+
|
11+
LL | pub fn ohno<'a>() -> <&'a () as Tr>::Item {
12+
| ^^^^
13+
14+
error: aborting due to previous error
15+

tests/ui/type-alias-impl-trait/higher_kinded_params2.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
44
// edition: 2021
55

6-
// check-pass
7-
86
#![feature(type_alias_impl_trait)]
97

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: item constrains opaque type that is not in its signature
2+
--> $DIR/higher_kinded_params2.rs:26:13
3+
|
4+
LL | f = g;
5+
| ^
6+
|
7+
= note: this item must mention the opaque type in its signature in order to be able to register hidden types
8+
note: this item must mention the opaque type in its signature in order to be able to register hidden types
9+
--> $DIR/higher_kinded_params2.rs:25:8
10+
|
11+
LL | fn successors(&self, mut f: for<'x> fn(&'x ()) -> <&'x A as B>::C) -> Successors<'_> {
12+
| ^^^^^^^^^^
13+
14+
error: aborting due to previous error
15+

tests/ui/type-alias-impl-trait/higher_kinded_params3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ type Successors<'a> = impl std::fmt::Debug + 'a;
2323

2424
impl Terminator {
2525
fn successors(&self, mut f: for<'x> fn(&'x ()) -> <&'x A as B>::C) -> Successors<'_> {
26-
//~^ ERROR non-defining opaque type use in defining scope
2726
f = g;
2827
//~^ ERROR mismatched types
28+
//~| ERROR item constrains opaque type that is not in its signature
2929
}
3030
}
3131

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
error[E0792]: non-defining opaque type use in defining scope
2-
--> $DIR/higher_kinded_params3.rs:25:33
1+
error: item constrains opaque type that is not in its signature
2+
--> $DIR/higher_kinded_params3.rs:26:13
33
|
4-
LL | fn successors(&self, mut f: for<'x> fn(&'x ()) -> <&'x A as B>::C) -> Successors<'_> {
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument `'x` is not a generic parameter
4+
LL | f = g;
5+
| ^
66
|
7-
note: for this opaque type
8-
--> $DIR/higher_kinded_params3.rs:18:17
7+
= note: this item must mention the opaque type in its signature in order to be able to register hidden types
8+
note: this item must mention the opaque type in its signature in order to be able to register hidden types
9+
--> $DIR/higher_kinded_params3.rs:25:8
910
|
10-
LL | type Tait<'a> = impl std::fmt::Debug + 'a;
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
11+
LL | fn successors(&self, mut f: for<'x> fn(&'x ()) -> <&'x A as B>::C) -> Successors<'_> {
12+
| ^^^^^^^^^^
1213

1314
error[E0308]: mismatched types
14-
--> $DIR/higher_kinded_params3.rs:27:9
15+
--> $DIR/higher_kinded_params3.rs:26:9
1516
|
1617
LL | type Tait<'a> = impl std::fmt::Debug + 'a;
1718
| ------------------------- the expected opaque type
@@ -24,5 +25,4 @@ LL | f = g;
2425

2526
error: aborting due to 2 previous errors
2627

27-
Some errors have detailed explanations: E0308, E0792.
28-
For more information about an error, try `rustc --explain E0308`.
28+
For more information about this error, try `rustc --explain E0308`.

tests/ui/type-alias-impl-trait/issue-70121.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// check-pass
2-
31
#![feature(type_alias_impl_trait)]
42

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

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: item constrains opaque type that is not in its signature
2+
--> $DIR/issue-70121.rs:17:24
3+
|
4+
LL | pub fn kazusa<'a>() -> <&'a () as Tr>::Item {
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: this item must mention the opaque type in its signature in order to be able to register hidden types
8+
note: this item must mention the opaque type in its signature in order to be able to register hidden types
9+
--> $DIR/issue-70121.rs:17:8
10+
|
11+
LL | pub fn kazusa<'a>() -> <&'a () as Tr>::Item {
12+
| ^^^^^^
13+
14+
error: aborting due to previous error
15+

0 commit comments

Comments
 (0)