Register member constraints on the final merged hidden type
Previously we did this per hidden type candiate, which didn't always have all the information available.
This commit is contained in:
parent
9110911353
commit
7bce50c01a
13 changed files with 62 additions and 96 deletions
|
@ -203,9 +203,16 @@ pub(crate) fn type_check<'mir, 'tcx>(
|
||||||
ConstraintCategory::OpaqueType,
|
ConstraintCategory::OpaqueType,
|
||||||
CustomTypeOp::new(
|
CustomTypeOp::new(
|
||||||
|infcx| {
|
|infcx| {
|
||||||
Ok(decl
|
let res = decl
|
||||||
.hidden_type(infcx, &cause, param_env)
|
.hidden_type(infcx, &cause, param_env)
|
||||||
.map_err(|e| e.0)?)
|
.map_err(|e| e.0)?;
|
||||||
|
infcx.register_member_constraints(
|
||||||
|
param_env,
|
||||||
|
opaque_type_key,
|
||||||
|
res.value.ty,
|
||||||
|
res.value.span,
|
||||||
|
);
|
||||||
|
Ok(res)
|
||||||
},
|
},
|
||||||
|| "opaque_type_map".to_string(),
|
|| "opaque_type_map".to_string(),
|
||||||
),
|
),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use rustc_infer::infer::nll_relate::{NormalizationStrategy, TypeRelating, TypeRelatingDelegate};
|
use rustc_infer::infer::nll_relate::{NormalizationStrategy, TypeRelating, TypeRelatingDelegate};
|
||||||
use rustc_infer::infer::NllRegionVariableOrigin;
|
use rustc_infer::infer::{InferOk, NllRegionVariableOrigin};
|
||||||
use rustc_infer::traits::ObligationCause;
|
use rustc_infer::traits::ObligationCause;
|
||||||
use rustc_middle::mir::ConstraintCategory;
|
use rustc_middle::mir::ConstraintCategory;
|
||||||
use rustc_middle::ty::relate::TypeRelation;
|
use rustc_middle::ty::relate::TypeRelation;
|
||||||
|
@ -136,7 +136,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn constrain_opaque_type(&mut self, a: Ty<'tcx>, b: Ty<'tcx>, a_is_expected: bool) {
|
fn register_opaque_type(&mut self, a: Ty<'tcx>, b: Ty<'tcx>, a_is_expected: bool) {
|
||||||
let param_env = self.param_env();
|
let param_env = self.param_env();
|
||||||
let span = self.span();
|
let span = self.span();
|
||||||
let def_id = self.type_checker.body.source.def_id().expect_local();
|
let def_id = self.type_checker.body.source.def_id().expect_local();
|
||||||
|
@ -148,39 +148,18 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
|
||||||
self.category,
|
self.category,
|
||||||
CustomTypeOp::new(
|
CustomTypeOp::new(
|
||||||
|infcx| {
|
|infcx| {
|
||||||
let (concrete_ty, opaque_type_key) =
|
Ok(InferOk {
|
||||||
match (a.kind(), b.kind(), a_is_expected) {
|
value: (),
|
||||||
(ty::Opaque(..), ty::Opaque(..), true) => {
|
obligations: vec![infcx.opaque_ty_obligation(
|
||||||
(b, a.expect_opaque_type())
|
a,
|
||||||
}
|
b,
|
||||||
(ty::Opaque(..), ty::Opaque(..), false) => {
|
a_is_expected,
|
||||||
(a, b.expect_opaque_type())
|
param_env,
|
||||||
}
|
cause,
|
||||||
(ty::Opaque(..), _, _) => (b, a.expect_opaque_type()),
|
)],
|
||||||
(_, ty::Opaque(..), _) => (a, b.expect_opaque_type()),
|
})
|
||||||
_ => span_bug!(
|
|
||||||
span,
|
|
||||||
"no opaque types in constrain_opaque_type {:?}, {:?}",
|
|
||||||
a,
|
|
||||||
b
|
|
||||||
),
|
|
||||||
};
|
|
||||||
let mut result = self.type_checker.infcx.constrain_opaque_type(
|
|
||||||
param_env,
|
|
||||||
opaque_type_key,
|
|
||||||
concrete_ty,
|
|
||||||
span,
|
|
||||||
)?;
|
|
||||||
result.obligations.push(infcx.opaque_ty_obligation(
|
|
||||||
a,
|
|
||||||
b,
|
|
||||||
a_is_expected,
|
|
||||||
param_env,
|
|
||||||
cause,
|
|
||||||
));
|
|
||||||
Ok(result)
|
|
||||||
},
|
},
|
||||||
|| "constrain_opaque_type".to_string(),
|
|| "register_opaque_type".to_string(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -723,7 +723,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn constrain_opaque_type(&mut self, a: Ty<'tcx>, b: Ty<'tcx>, a_is_expected: bool) {
|
fn register_opaque_type(&mut self, a: Ty<'tcx>, b: Ty<'tcx>, a_is_expected: bool) {
|
||||||
self.obligations.push(self.infcx.opaque_ty_obligation(
|
self.obligations.push(self.infcx.opaque_ty_obligation(
|
||||||
a,
|
a,
|
||||||
b,
|
b,
|
||||||
|
|
|
@ -90,7 +90,7 @@ pub trait TypeRelatingDelegate<'tcx> {
|
||||||
info: ty::VarianceDiagInfo<'tcx>,
|
info: ty::VarianceDiagInfo<'tcx>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn constrain_opaque_type(&mut self, a: Ty<'tcx>, b: Ty<'tcx>, a_is_expected: bool);
|
fn register_opaque_type(&mut self, a: Ty<'tcx>, b: Ty<'tcx>, a_is_expected: bool);
|
||||||
|
|
||||||
fn const_equate(&mut self, a: &'tcx ty::Const<'tcx>, b: &'tcx ty::Const<'tcx>);
|
fn const_equate(&mut self, a: &'tcx ty::Const<'tcx>, b: &'tcx ty::Const<'tcx>);
|
||||||
|
|
||||||
|
@ -591,7 +591,7 @@ where
|
||||||
(_, &ty::Opaque(..)) => (generalize(a, true)?, b),
|
(_, &ty::Opaque(..)) => (generalize(a, true)?, b),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
self.delegate.constrain_opaque_type(a, b, true);
|
self.delegate.register_opaque_type(a, b, true);
|
||||||
trace!(a = ?a.kind(), b = ?b.kind(), "opaque type instantiated");
|
trace!(a = ?a.kind(), b = ?b.kind(), "opaque type instantiated");
|
||||||
Ok(a)
|
Ok(a)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||||
use crate::infer::{InferCtxt, InferOk, InferResult};
|
use crate::infer::{InferCtxt, InferOk};
|
||||||
use crate::traits::{self, PredicateObligation, PredicateObligations};
|
use crate::traits::{self, PredicateObligation, PredicateObligations};
|
||||||
use hir::def_id::{DefId, LocalDefId};
|
use hir::def_id::{DefId, LocalDefId};
|
||||||
use hir::OpaqueTyOrigin;
|
use hir::OpaqueTyOrigin;
|
||||||
|
@ -379,13 +379,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
/// - `free_region_relations` -- something that can be used to relate
|
/// - `free_region_relations` -- something that can be used to relate
|
||||||
/// the free regions (`'a`) that appear in the impl trait.
|
/// the free regions (`'a`) that appear in the impl trait.
|
||||||
#[instrument(level = "debug", skip(self))]
|
#[instrument(level = "debug", skip(self))]
|
||||||
pub fn constrain_opaque_type(
|
pub fn register_member_constraints(
|
||||||
&self,
|
&self,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
opaque_type_key: OpaqueTypeKey<'tcx>,
|
opaque_type_key: OpaqueTypeKey<'tcx>,
|
||||||
concrete_ty: Ty<'tcx>,
|
concrete_ty: Ty<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> InferResult<'tcx, ()> {
|
) {
|
||||||
let def_id = opaque_type_key.def_id;
|
let def_id = opaque_type_key.def_id;
|
||||||
|
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
|
@ -445,7 +445,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
Ok(InferOk { value: (), obligations: vec![] })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn opaque_ty_obligation(
|
pub fn opaque_ty_obligation(
|
||||||
|
|
|
@ -33,7 +33,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
/// purpose of this function is to do that translation.
|
/// purpose of this function is to do that translation.
|
||||||
///
|
///
|
||||||
/// (*) C1 and C2 were introduced in the comments on
|
/// (*) C1 and C2 were introduced in the comments on
|
||||||
/// `constrain_opaque_type`. Read that comment for more context.
|
/// `register_member_constraints`. Read that comment for more context.
|
||||||
///
|
///
|
||||||
/// # Parameters
|
/// # Parameters
|
||||||
///
|
///
|
||||||
|
|
|
@ -14,16 +14,21 @@ LL | | }
|
||||||
= help: consider adding the following bound: `'a: 'b`
|
= help: consider adding the following bound: `'a: 'b`
|
||||||
|
|
||||||
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
|
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
|
||||||
--> $DIR/ret-impl-trait-one.rs:16:65
|
--> $DIR/ret-impl-trait-one.rs:16:80
|
||||||
|
|
|
|
||||||
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> {
|
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> {
|
||||||
| ^^^^^^^^^^^^^^
|
| ____________________________________--__________________________________________^
|
||||||
|
| | |
|
||||||
|
| | hidden type `(&'a u8, &'b u8)` captures the lifetime `'b` as defined here
|
||||||
|
LL | |
|
||||||
|
LL | | (a, b)
|
||||||
|
LL | | }
|
||||||
|
| |_^
|
||||||
|
|
|
|
||||||
note: hidden type `(&'a u8, &'<empty> u8)` captures lifetime smaller than the function body
|
help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound
|
||||||
--> $DIR/ret-impl-trait-one.rs:16:65
|
|
||||||
|
|
|
|
||||||
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> {
|
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b {
|
||||||
| ^^^^^^^^^^^^^^
|
| ++++
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
|
@ -11,16 +11,21 @@ LL | | }
|
||||||
| |_^ ...but data from `a` is returned here
|
| |_^ ...but data from `a` is returned here
|
||||||
|
|
||||||
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
|
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
|
||||||
--> $DIR/ret-impl-trait-one.rs:16:65
|
--> $DIR/ret-impl-trait-one.rs:16:80
|
||||||
|
|
|
|
||||||
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> {
|
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> {
|
||||||
| ^^^^^^^^^^^^^^
|
| ____________________________________--__________________________________________^
|
||||||
|
| | |
|
||||||
|
| | hidden type `(&'a u8, &'b u8)` captures the lifetime `'b` as defined here
|
||||||
|
LL | |
|
||||||
|
LL | | (a, b)
|
||||||
|
LL | | }
|
||||||
|
| |_^
|
||||||
|
|
|
|
||||||
note: hidden type `(&'a u8, &'<empty> u8)` captures lifetime smaller than the function body
|
help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound
|
||||||
--> $DIR/ret-impl-trait-one.rs:16:65
|
|
||||||
|
|
|
|
||||||
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> {
|
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b {
|
||||||
| ^^^^^^^^^^^^^^
|
| ++++
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@ where
|
||||||
// ```
|
// ```
|
||||||
if condition() { a } else { b }
|
if condition() { a } else { b }
|
||||||
//~^ ERROR hidden type for `impl Trait` captures lifetime that does not appear in bounds
|
//~^ ERROR hidden type for `impl Trait` captures lifetime that does not appear in bounds
|
||||||
//~| ERROR hidden type for `impl Trait` captures lifetime that does not appear in bounds
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn condition() -> bool {
|
fn condition() -> bool {
|
||||||
|
|
|
@ -12,20 +12,6 @@ help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'
|
||||||
LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> + 'b
|
LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> + 'b
|
||||||
| ++++
|
| ++++
|
||||||
|
|
||||||
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
|
error: aborting due to previous error
|
||||||
--> $DIR/ordinary-bounds-unrelated.rs:28:33
|
|
||||||
|
|
|
||||||
LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e>
|
|
||||||
| -- hidden type `Ordinary<'b>` captures the lifetime `'b` as defined here
|
|
||||||
...
|
|
||||||
LL | if condition() { a } else { b }
|
|
||||||
| ^
|
|
||||||
|
|
|
||||||
help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound
|
|
||||||
|
|
|
||||||
LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> + 'b
|
|
||||||
| ++++
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0700`.
|
For more information about this error, try `rustc --explain E0700`.
|
||||||
|
|
|
@ -30,7 +30,6 @@ fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b>
|
||||||
// We are forced to pick that '0 = 'e, because only 'e is outlived by *both* 'a and 'b.
|
// We are forced to pick that '0 = 'e, because only 'e is outlived by *both* 'a and 'b.
|
||||||
if condition() { a } else { b }
|
if condition() { a } else { b }
|
||||||
//~^ ERROR hidden type for `impl Trait` captures lifetime that does not appear in bounds
|
//~^ ERROR hidden type for `impl Trait` captures lifetime that does not appear in bounds
|
||||||
//~| ERROR hidden type for `impl Trait` captures lifetime that does not appear in bounds
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn condition() -> bool {
|
fn condition() -> bool {
|
||||||
|
|
|
@ -12,20 +12,6 @@ help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'
|
||||||
LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> + 'b
|
LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> + 'b
|
||||||
| ++++
|
| ++++
|
||||||
|
|
||||||
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
|
error: aborting due to previous error
|
||||||
--> $DIR/ordinary-bounds-unsuited.rs:31:33
|
|
||||||
|
|
|
||||||
LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b>
|
|
||||||
| -- hidden type `Ordinary<'b>` captures the lifetime `'b` as defined here
|
|
||||||
...
|
|
||||||
LL | if condition() { a } else { b }
|
|
||||||
| ^
|
|
||||||
|
|
|
||||||
help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound
|
|
||||||
|
|
|
||||||
LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> + 'b
|
|
||||||
| ++++
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0700`.
|
For more information about this error, try `rustc --explain E0700`.
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
|
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
|
||||||
--> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:8:37
|
--> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:8:48
|
||||||
|
|
|
|
||||||
LL | async fn f(self: Pin<&Self>) -> impl Clone { self }
|
LL | async fn f(self: Pin<&Self>) -> impl Clone { self }
|
||||||
| ^^^^^^^^^^
|
| - ^^^^^^^^
|
||||||
|
| |
|
||||||
|
| hidden type `Pin<&Foo>` captures the lifetime `'_` as defined here
|
||||||
|
|
|
|
||||||
note: hidden type `Pin<&'<empty> Foo>` captures lifetime smaller than the function body
|
help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound
|
||||||
--> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:8:37
|
|
||||||
|
|
|
|
||||||
LL | async fn f(self: Pin<&Self>) -> impl Clone { self }
|
LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
|
||||||
| ^^^^^^^^^^
|
| ++++
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue