rustc_trait_selection/error_reporting/infer/nice_region_error/
placeholder_relation.rs1use rustc_data_structures::intern::Interned;
2use rustc_errors::Diag;
3use rustc_middle::ty::{self, RePlaceholder, Region};
4
5use crate::error_reporting::infer::nice_region_error::NiceRegionError;
6use crate::errors::PlaceholderRelationLfNotSatisfied;
7use crate::infer::{RegionResolutionError, SubregionOrigin};
8
9impl<'tcx> NiceRegionError<'_, 'tcx> {
10 pub(super) fn try_report_placeholder_relation(&self) -> Option<Diag<'tcx>> {
12 match &self.error {
13 Some(RegionResolutionError::ConcreteFailure(
14 SubregionOrigin::RelateRegionParamBound(span, _),
15 Region(Interned(
16 RePlaceholder(ty::Placeholder {
17 bound: ty::BoundRegion { kind: sub_name, .. },
18 ..
19 }),
20 _,
21 )),
22 Region(Interned(
23 RePlaceholder(ty::Placeholder {
24 bound: ty::BoundRegion { kind: sup_name, .. },
25 ..
26 }),
27 _,
28 )),
29 )) => {
30 let span = *span;
31 let (sub_span, sub_symbol) = match sub_name {
32 ty::BoundRegionKind::Named(def_id, symbol) => {
33 (Some(self.tcx().def_span(def_id)), Some(symbol))
34 }
35 ty::BoundRegionKind::Anon | ty::BoundRegionKind::ClosureEnv => (None, None),
36 };
37 let (sup_span, sup_symbol) = match sup_name {
38 ty::BoundRegionKind::Named(def_id, symbol) => {
39 (Some(self.tcx().def_span(def_id)), Some(symbol))
40 }
41 ty::BoundRegionKind::Anon | ty::BoundRegionKind::ClosureEnv => (None, None),
42 };
43 let diag = match (sub_span, sup_span, sub_symbol, sup_symbol) {
44 (Some(sub_span), Some(sup_span), Some(&sub_symbol), Some(&sup_symbol)) => {
45 PlaceholderRelationLfNotSatisfied::HasBoth {
46 span,
47 sub_span,
48 sup_span,
49 sub_symbol,
50 sup_symbol,
51 note: (),
52 }
53 }
54 (Some(sub_span), Some(sup_span), _, Some(&sup_symbol)) => {
55 PlaceholderRelationLfNotSatisfied::HasSup {
56 span,
57 sub_span,
58 sup_span,
59 sup_symbol,
60 note: (),
61 }
62 }
63 (Some(sub_span), Some(sup_span), Some(&sub_symbol), _) => {
64 PlaceholderRelationLfNotSatisfied::HasSub {
65 span,
66 sub_span,
67 sup_span,
68 sub_symbol,
69 note: (),
70 }
71 }
72 (Some(sub_span), Some(sup_span), _, _) => {
73 PlaceholderRelationLfNotSatisfied::HasNone {
74 span,
75 sub_span,
76 sup_span,
77 note: (),
78 }
79 }
80 _ => PlaceholderRelationLfNotSatisfied::OnlyPrimarySpan { span, note: () },
81 };
82 Some(self.tcx().dcx().create_err(diag))
83 }
84 _ => None,
85 }
86 }
87}