mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-09 05:23:07 +00:00
Use self instead of the actual self ty
This commit is contained in:
parent
e10262ca0a
commit
4745d34bc3
@ -29,6 +29,18 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
|
|||||||
let trait_m_to_impl_m_args = impl_m_args.rebase_onto(tcx, impl_def_id, impl_trait_ref.args);
|
let trait_m_to_impl_m_args = impl_m_args.rebase_onto(tcx, impl_def_id, impl_trait_ref.args);
|
||||||
let bound_trait_m_sig = tcx.fn_sig(trait_m.def_id).instantiate(tcx, trait_m_to_impl_m_args);
|
let bound_trait_m_sig = tcx.fn_sig(trait_m.def_id).instantiate(tcx, trait_m_to_impl_m_args);
|
||||||
let trait_m_sig = tcx.liberate_late_bound_regions(impl_m.def_id, bound_trait_m_sig);
|
let trait_m_sig = tcx.liberate_late_bound_regions(impl_m.def_id, bound_trait_m_sig);
|
||||||
|
// replace the self type of the trait ref with `Self` so that diagnostics render better.
|
||||||
|
let trait_m_sig_with_self_for_diag = tcx.liberate_late_bound_regions(
|
||||||
|
impl_m.def_id,
|
||||||
|
tcx.fn_sig(trait_m.def_id).instantiate(
|
||||||
|
tcx,
|
||||||
|
tcx.mk_args_from_iter(
|
||||||
|
[tcx.types.self_param.into()]
|
||||||
|
.into_iter()
|
||||||
|
.chain(trait_m_to_impl_m_args.iter().skip(1)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
let Ok(hidden_tys) = tcx.collect_return_position_impl_trait_in_trait_tys(impl_m.def_id) else {
|
let Ok(hidden_tys) = tcx.collect_return_position_impl_trait_in_trait_tys(impl_m.def_id) else {
|
||||||
// Error already emitted, no need to delay another.
|
// Error already emitted, no need to delay another.
|
||||||
@ -51,7 +63,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
|
|||||||
let ty::Alias(ty::Opaque, impl_opaque) = *hidden_ty.kind() else {
|
let ty::Alias(ty::Opaque, impl_opaque) = *hidden_ty.kind() else {
|
||||||
report_mismatched_rpitit_signature(
|
report_mismatched_rpitit_signature(
|
||||||
tcx,
|
tcx,
|
||||||
trait_m_sig,
|
trait_m_sig_with_self_for_diag,
|
||||||
trait_m.def_id,
|
trait_m.def_id,
|
||||||
impl_m.def_id,
|
impl_m.def_id,
|
||||||
None,
|
None,
|
||||||
@ -70,7 +82,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
|
|||||||
}) {
|
}) {
|
||||||
report_mismatched_rpitit_signature(
|
report_mismatched_rpitit_signature(
|
||||||
tcx,
|
tcx,
|
||||||
trait_m_sig,
|
trait_m_sig_with_self_for_diag,
|
||||||
trait_m.def_id,
|
trait_m.def_id,
|
||||||
impl_m.def_id,
|
impl_m.def_id,
|
||||||
None,
|
None,
|
||||||
@ -163,7 +175,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
|
|||||||
if !trait_bounds.contains(&clause) {
|
if !trait_bounds.contains(&clause) {
|
||||||
report_mismatched_rpitit_signature(
|
report_mismatched_rpitit_signature(
|
||||||
tcx,
|
tcx,
|
||||||
trait_m_sig,
|
trait_m_sig_with_self_for_diag,
|
||||||
trait_m.def_id,
|
trait_m.def_id,
|
||||||
impl_m.def_id,
|
impl_m.def_id,
|
||||||
Some(span),
|
Some(span),
|
||||||
|
@ -24,8 +24,8 @@ LL | fn iter(&self) -> impl 'a + Iterator<Item = I::Item<'a>> {
|
|||||||
= note: `#[warn(refining_impl_trait)]` on by default
|
= note: `#[warn(refining_impl_trait)]` on by default
|
||||||
help: replace the return type so that it matches the trait
|
help: replace the return type so that it matches the trait
|
||||||
|
|
|
|
||||||
LL | fn iter(&self) -> impl Iterator<Item = <&'a I as Iterable>::Item<'_>> + '_ {
|
LL | fn iter(&self) -> impl Iterator<Item = <Self as Iterable>::Item<'_>> + '_ {
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
error: aborting due to previous error; 1 warning emitted
|
error: aborting due to previous error; 1 warning emitted
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user