Flip the order of binder instantiation for better diagnostics
This commit is contained in:
parent
d567e4f8b6
commit
473c88dfb6
4 changed files with 14 additions and 23 deletions
|
@ -651,11 +651,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
|
||||||
let impl_sig = ocx.normalize(
|
let impl_sig = ocx.normalize(
|
||||||
&norm_cause,
|
&norm_cause,
|
||||||
param_env,
|
param_env,
|
||||||
infcx.instantiate_binder_with_fresh_vars(
|
tcx.liberate_late_bound_regions(impl_m.def_id, tcx.fn_sig(impl_m.def_id).subst_identity()),
|
||||||
return_span,
|
|
||||||
infer::HigherRankedType,
|
|
||||||
tcx.fn_sig(impl_m.def_id).subst_identity(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
impl_sig.error_reported()?;
|
impl_sig.error_reported()?;
|
||||||
let impl_return_ty = impl_sig.output();
|
let impl_return_ty = impl_sig.output();
|
||||||
|
@ -665,9 +661,10 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
|
||||||
// them with inference variables.
|
// them with inference variables.
|
||||||
// We will use these inference variables to collect the hidden types of RPITITs.
|
// We will use these inference variables to collect the hidden types of RPITITs.
|
||||||
let mut collector = ImplTraitInTraitCollector::new(&ocx, return_span, param_env, impl_m_def_id);
|
let mut collector = ImplTraitInTraitCollector::new(&ocx, return_span, param_env, impl_m_def_id);
|
||||||
let unnormalized_trait_sig = tcx
|
let unnormalized_trait_sig = infcx
|
||||||
.liberate_late_bound_regions(
|
.instantiate_binder_with_fresh_vars(
|
||||||
impl_m.def_id,
|
return_span,
|
||||||
|
infer::HigherRankedType,
|
||||||
tcx.fn_sig(trait_m.def_id).subst(tcx, trait_to_placeholder_substs),
|
tcx.fn_sig(trait_m.def_id).subst(tcx, trait_to_placeholder_substs),
|
||||||
)
|
)
|
||||||
.fold_with(&mut collector);
|
.fold_with(&mut collector);
|
||||||
|
@ -760,8 +757,8 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
|
||||||
|
|
||||||
let mut collected_tys = FxHashMap::default();
|
let mut collected_tys = FxHashMap::default();
|
||||||
for (def_id, (ty, substs)) in collected_types {
|
for (def_id, (ty, substs)) in collected_types {
|
||||||
match infcx.fully_resolve(ty) {
|
match infcx.fully_resolve((ty, substs)) {
|
||||||
Ok(ty) => {
|
Ok((ty, substs)) => {
|
||||||
// `ty` contains free regions that we created earlier while liberating the
|
// `ty` contains free regions that we created earlier while liberating the
|
||||||
// trait fn signature. However, projection normalization expects `ty` to
|
// trait fn signature. However, projection normalization expects `ty` to
|
||||||
// contains `def_id`'s early-bound regions.
|
// contains `def_id`'s early-bound regions.
|
||||||
|
|
|
@ -5,7 +5,7 @@ LL | fn early<'late, T>(_: &'late ()) {}
|
||||||
| - ^^^^^^^^^
|
| - ^^^^^^^^^
|
||||||
| | |
|
| | |
|
||||||
| | expected type parameter `T`, found `()`
|
| | expected type parameter `T`, found `()`
|
||||||
| | help: change the parameter type to match the trait: `&'early T`
|
| | help: change the parameter type to match the trait: `&T`
|
||||||
| this type parameter
|
| this type parameter
|
||||||
|
|
|
|
||||||
note: type in trait
|
note: type in trait
|
||||||
|
@ -13,8 +13,8 @@ note: type in trait
|
||||||
|
|
|
|
||||||
LL | fn early<'early, T>(x: &'early T) -> impl Sized;
|
LL | fn early<'early, T>(x: &'early T) -> impl Sized;
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
= note: expected signature `fn(&'early T)`
|
= note: expected signature `fn(&T)`
|
||||||
found signature `fn(&())`
|
found signature `fn(&'late ())`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,15 @@
|
||||||
error: return type captures more lifetimes than trait definition
|
error: return type captures more lifetimes than trait definition
|
||||||
--> $DIR/signature-mismatch.rs:17:47
|
--> $DIR/signature-mismatch.rs:17:47
|
||||||
|
|
|
|
||||||
LL | fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>;
|
|
||||||
| - this lifetime was captured
|
|
||||||
...
|
|
||||||
LL | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
|
LL | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| -- this lifetime was captured ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
note: hidden type must only reference lifetimes captured by this impl trait
|
note: hidden type must only reference lifetimes captured by this impl trait
|
||||||
--> $DIR/signature-mismatch.rs:11:40
|
--> $DIR/signature-mismatch.rs:11:40
|
||||||
|
|
|
|
||||||
LL | fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>;
|
LL | fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
= note: hidden type inferred to be `impl Future<Output = Vec<u8>> + '_`
|
= note: hidden type inferred to be `impl Future<Output = Vec<u8>> + 'a`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,15 @@
|
||||||
error: return type captures more lifetimes than trait definition
|
error: return type captures more lifetimes than trait definition
|
||||||
--> $DIR/signature-mismatch.rs:17:47
|
--> $DIR/signature-mismatch.rs:17:47
|
||||||
|
|
|
|
||||||
LL | fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>;
|
|
||||||
| - this lifetime was captured
|
|
||||||
...
|
|
||||||
LL | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
|
LL | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| -- this lifetime was captured ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
note: hidden type must only reference lifetimes captured by this impl trait
|
note: hidden type must only reference lifetimes captured by this impl trait
|
||||||
--> $DIR/signature-mismatch.rs:11:40
|
--> $DIR/signature-mismatch.rs:11:40
|
||||||
|
|
|
|
||||||
LL | fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>;
|
LL | fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
= note: hidden type inferred to be `impl Future<Output = Vec<u8>> + '_`
|
= note: hidden type inferred to be `impl Future<Output = Vec<u8>> + 'a`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue