mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-16 17:03:35 +00:00
Remove normalization from opaque_types_defined_by
This commit is contained in:
parent
4c99872efe
commit
907f97e411
@ -2,16 +2,12 @@ use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
use rustc_hir::{def::DefKind, def_id::LocalDefId};
|
||||
use rustc_hir::{intravisit, CRATE_HIR_ID};
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::traits::ObligationCause;
|
||||
use rustc_middle::ty::util::{CheckRegions, NotUniqueParam};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{TypeSuperVisitable, TypeVisitable, TypeVisitor};
|
||||
use rustc_span::def_id::CRATE_DEF_ID;
|
||||
use rustc_span::Span;
|
||||
use rustc_trait_selection::traits::check_substs_compatible;
|
||||
use rustc_trait_selection::traits::ObligationCtxt;
|
||||
use std::ops::ControlFlow;
|
||||
|
||||
use crate::errors::{DuplicateArg, NotParam};
|
||||
@ -139,20 +135,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
|
||||
rustc_hir::OpaqueTyOrigin::FnReturn(_)
|
||||
| rustc_hir::OpaqueTyOrigin::AsyncFn(_) => {}
|
||||
rustc_hir::OpaqueTyOrigin::TyAlias { in_assoc_ty } => {
|
||||
if in_assoc_ty {
|
||||
// Only associated items can be defining for opaque types in associated types.
|
||||
if let Some(parent) = self.parent() {
|
||||
let mut current = alias_ty.def_id.expect_local();
|
||||
while current != parent && current != CRATE_DEF_ID {
|
||||
current = self.tcx.local_parent(current);
|
||||
}
|
||||
if current != parent {
|
||||
return ControlFlow::Continue(());
|
||||
}
|
||||
} else {
|
||||
return ControlFlow::Continue(());
|
||||
}
|
||||
} else {
|
||||
if !in_assoc_ty {
|
||||
if !self.check_tait_defining_scope(alias_ty.def_id.expect_local()) {
|
||||
return ControlFlow::Continue(());
|
||||
}
|
||||
@ -246,28 +229,6 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Normalize trivial projections.
|
||||
let mut infcx = self.tcx.infer_ctxt();
|
||||
let infcx = infcx.build();
|
||||
let t = if t.has_escaping_bound_vars() {
|
||||
let (t, _mapped_regions, _mapped_types, _mapped_consts) =
|
||||
rustc_trait_selection::traits::project::BoundVarReplacer::replace_bound_vars(
|
||||
&infcx,
|
||||
&mut self.universes,
|
||||
t,
|
||||
);
|
||||
t
|
||||
} else {
|
||||
t
|
||||
};
|
||||
let ocx = ObligationCtxt::new(&infcx);
|
||||
let cause = ObligationCause::dummy_with_span(self.span());
|
||||
let normalized = ocx.normalize(&cause, self.tcx.param_env(self.item), t);
|
||||
trace!(?normalized);
|
||||
if normalized != t {
|
||||
normalized.visit_with(self)?;
|
||||
}
|
||||
}
|
||||
ty::Adt(def, _) if def.did().is_local() => {
|
||||
if !self.seen.insert(def.did().expect_local()) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
// check-pass
|
||||
//! Test that we don't follow through projections to find
|
||||
//! opaque types.
|
||||
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![allow(private_in_public)]
|
||||
@ -18,6 +19,7 @@ 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()
|
||||
}
|
||||
|
||||
|
15
tests/ui/lint/issue-99387.stderr
Normal file
15
tests/ui/lint/issue-99387.stderr
Normal file
@ -0,0 +1,15 @@
|
||||
error: item constrains opaque type that is not in its signature
|
||||
--> $DIR/issue-99387.rs:21:22
|
||||
|
|
||||
LL | pub fn ohno<'a>() -> <&'a () as Tr>::Item {
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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/issue-99387.rs:21:8
|
||||
|
|
||||
LL | pub fn ohno<'a>() -> <&'a () as Tr>::Item {
|
||||
| ^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -3,8 +3,6 @@
|
||||
|
||||
// edition: 2021
|
||||
|
||||
// check-pass
|
||||
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
trait B {
|
||||
@ -26,6 +24,7 @@ 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
|
||||
}
|
||||
}
|
||||
|
||||
|
15
tests/ui/type-alias-impl-trait/higher_kinded_params2.stderr
Normal file
15
tests/ui/type-alias-impl-trait/higher_kinded_params2.stderr
Normal file
@ -0,0 +1,15 @@
|
||||
error: item constrains opaque type that is not in its signature
|
||||
--> $DIR/higher_kinded_params2.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_params2.rs:25:8
|
||||
|
|
||||
LL | fn successors(&self, mut f: for<'x> fn(&'x ()) -> <&'x A as B>::C) -> Successors<'_> {
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -23,9 +23,9 @@ 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<'_> {
|
||||
//~^ ERROR non-defining opaque type use in defining scope
|
||||
f = g;
|
||||
//~^ ERROR mismatched types
|
||||
//~| ERROR item constrains opaque type that is not in its signature
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,18 @@
|
||||
error[E0792]: non-defining opaque type use in defining scope
|
||||
--> $DIR/higher_kinded_params3.rs:25:33
|
||||
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<'_> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument `'x` is not a generic parameter
|
||||
|
|
||||
note: for this opaque type
|
||||
--> $DIR/higher_kinded_params3.rs:18:17
|
||||
|
|
||||
LL | type Tait<'a> = impl std::fmt::Debug + 'a;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/higher_kinded_params3.rs:27:9
|
||||
--> $DIR/higher_kinded_params3.rs:26:9
|
||||
|
|
||||
LL | type Tait<'a> = impl std::fmt::Debug + 'a;
|
||||
| ------------------------- the expected opaque type
|
||||
@ -24,5 +25,4 @@ LL | f = g;
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0308, E0792.
|
||||
For more information about an error, try `rustc --explain E0308`.
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
|
@ -1,5 +1,3 @@
|
||||
// check-pass
|
||||
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
pub type Successors<'a> = impl Iterator<Item = &'a ()>;
|
||||
@ -17,6 +15,7 @@ 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()
|
||||
}
|
||||
|
||||
|
15
tests/ui/type-alias-impl-trait/issue-70121.stderr
Normal file
15
tests/ui/type-alias-impl-trait/issue-70121.stderr
Normal file
@ -0,0 +1,15 @@
|
||||
error: item constrains opaque type that is not in its signature
|
||||
--> $DIR/issue-70121.rs:17:24
|
||||
|
|
||||
LL | pub fn kazusa<'a>() -> <&'a () as Tr>::Item {
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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/issue-70121.rs:17:8
|
||||
|
|
||||
LL | pub fn kazusa<'a>() -> <&'a () as Tr>::Item {
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user