1 use crate::infer
::lexical_region_resolve
::RegionResolutionError
;
2 use crate::infer
::lexical_region_resolve
::RegionResolutionError
::*;
3 use crate::infer
::InferCtxt
;
4 use rustc_errors
::{DiagnosticBuilder, ErrorReported}
;
5 use rustc_middle
::ty
::{self, TyCtxt}
;
6 use rustc_span
::source_map
::Span
;
8 mod different_lifetimes
;
9 pub mod find_anon_type
;
10 mod mismatched_static_lifetime
;
11 mod named_anon_conflict
;
12 mod placeholder_error
;
13 mod static_impl_trait
;
14 mod trait_impl_difference
;
17 impl<'cx
, 'tcx
> InferCtxt
<'cx
, 'tcx
> {
18 pub fn try_report_nice_region_error(&self, error
: &RegionResolutionError
<'tcx
>) -> bool
{
19 NiceRegionError
::new(self, error
.clone()).try_report().is_some()
23 pub struct NiceRegionError
<'cx
, 'tcx
> {
24 infcx
: &'cx InferCtxt
<'cx
, 'tcx
>,
25 error
: Option
<RegionResolutionError
<'tcx
>>,
26 regions
: Option
<(Span
, ty
::Region
<'tcx
>, ty
::Region
<'tcx
>)>,
29 impl<'cx
, 'tcx
> NiceRegionError
<'cx
, 'tcx
> {
30 pub fn new(infcx
: &'cx InferCtxt
<'cx
, 'tcx
>, error
: RegionResolutionError
<'tcx
>) -> Self {
31 Self { infcx, error: Some(error), regions: None }
35 infcx
: &'cx InferCtxt
<'cx
, 'tcx
>,
37 sub
: ty
::Region
<'tcx
>,
38 sup
: ty
::Region
<'tcx
>,
40 Self { infcx, error: None, regions: Some((span, sub, sup)) }
43 fn tcx(&self) -> TyCtxt
<'tcx
> {
47 pub fn try_report_from_nll(&self) -> Option
<DiagnosticBuilder
<'tcx
>> {
48 // Due to the improved diagnostics returned by the MIR borrow checker, only a subset of
49 // the nice region errors are required when running under the MIR borrow checker.
50 self.try_report_named_anon_conflict().or_else(|| self.try_report_placeholder_conflict())
53 pub fn try_report(&self) -> Option
<ErrorReported
> {
54 self.try_report_from_nll()
59 .or_else(|| self.try_report_impl_not_conforming_to_trait())
60 .or_else(|| self.try_report_anon_anon_conflict())
61 .or_else(|| self.try_report_static_impl_trait())
62 .or_else(|| self.try_report_mismatched_static_lifetime())
65 pub fn regions(&self) -> Option
<(Span
, ty
::Region
<'tcx
>, ty
::Region
<'tcx
>)> {
66 match (&self.error
, self.regions
) {
67 (Some(ConcreteFailure(origin
, sub
, sup
)), None
) => Some((origin
.span(), sub
, sup
)),
68 (Some(SubSupConflict(_
, _
, origin
, sub
, _
, sup
)), None
) => {
69 Some((origin
.span(), sub
, sup
))
71 (None
, Some((span
, sub
, sup
))) => Some((span
, sub
, sup
)),