|
1 | 1 | use crate::constrained_generic_params::{identify_constrained_generic_params, Parameter};
|
| 2 | +use hir::def::DefKind; |
2 | 3 | use rustc_ast as ast;
|
3 | 4 | use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
4 | 5 | use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed};
|
@@ -1530,6 +1531,49 @@ fn check_fn_or_method<'tcx>(
|
1530 | 1531 | );
|
1531 | 1532 |
|
1532 | 1533 | check_where_clauses(wfcx, span, def_id);
|
| 1534 | + |
| 1535 | + check_return_position_impl_trait_in_trait_bounds( |
| 1536 | + tcx, |
| 1537 | + wfcx, |
| 1538 | + def_id, |
| 1539 | + sig.output(), |
| 1540 | + hir_decl.output.span(), |
| 1541 | + ); |
| 1542 | +} |
| 1543 | + |
| 1544 | +/// Basically `check_associated_type_bounds`, but separated for now and should be |
| 1545 | +/// deduplicated when RPITITs get lowered into real associated items. |
| 1546 | +fn check_return_position_impl_trait_in_trait_bounds<'tcx>( |
| 1547 | + tcx: TyCtxt<'tcx>, |
| 1548 | + wfcx: &WfCheckingCtxt<'_, 'tcx>, |
| 1549 | + fn_def_id: LocalDefId, |
| 1550 | + fn_output: Ty<'tcx>, |
| 1551 | + span: Span, |
| 1552 | +) { |
| 1553 | + if let Some(assoc_item) = tcx.opt_associated_item(fn_def_id.to_def_id()) |
| 1554 | + && assoc_item.container == ty::AssocItemContainer::TraitContainer |
| 1555 | + { |
| 1556 | + for arg in fn_output.walk() { |
| 1557 | + if let ty::GenericArgKind::Type(ty) = arg.unpack() |
| 1558 | + && let ty::Projection(proj) = ty.kind() |
| 1559 | + && tcx.def_kind(proj.item_def_id) == DefKind::ImplTraitPlaceholder |
| 1560 | + && tcx.impl_trait_in_trait_parent(proj.item_def_id) == fn_def_id.to_def_id() |
| 1561 | + { |
| 1562 | + let bounds = wfcx.tcx().explicit_item_bounds(proj.item_def_id); |
| 1563 | + let wf_obligations = bounds.iter().flat_map(|&(bound, bound_span)| { |
| 1564 | + let normalized_bound = wfcx.normalize(span, None, bound); |
| 1565 | + traits::wf::predicate_obligations( |
| 1566 | + wfcx.infcx, |
| 1567 | + wfcx.param_env, |
| 1568 | + wfcx.body_id, |
| 1569 | + normalized_bound, |
| 1570 | + bound_span, |
| 1571 | + ) |
| 1572 | + }); |
| 1573 | + wfcx.register_obligations(wf_obligations); |
| 1574 | + } |
| 1575 | + } |
| 1576 | + } |
1533 | 1577 | }
|
1534 | 1578 |
|
1535 | 1579 | const HELP_FOR_SELF_TYPE: &str = "consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, \
|
|
0 commit comments