mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Split into several messages
This commit is contained in:
parent
6c19c08140
commit
71d24da665
@ -184,25 +184,64 @@ infer_explicit_lifetime_required_sugg = add explicit lifetime `{$named}` to {$id
|
|||||||
*[param_type] type
|
*[param_type] type
|
||||||
}
|
}
|
||||||
|
|
||||||
infer_actual_impl_expl_expected = {$leading_ellipsis ->
|
infer_actual_impl_expl_expected_signature_two = {$leading_ellipsis ->
|
||||||
[true] ...
|
[true] ...
|
||||||
*[false] {""}
|
*[false] {""}
|
||||||
}{$kind ->
|
}closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...
|
||||||
[signature] closure with signature `{$ty_or_sig}` must implement `{$trait_path}`
|
infer_actual_impl_expl_expected_signature_any = {$leading_ellipsis ->
|
||||||
[passive] `{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`
|
[true] ...
|
||||||
*[other] `{$ty_or_sig}` must implement `{$trait_path}`
|
*[false] {""}
|
||||||
}{$lt_kind ->
|
}closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for any lifetime `'{$lifetime_1}`...
|
||||||
[two] , for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...
|
infer_actual_impl_expl_expected_signature_some = {$leading_ellipsis ->
|
||||||
[any] , for any lifetime `'{$lifetime_1}`...
|
[true] ...
|
||||||
[some] , for some specific lifetime `'{lifetime_1}`...
|
*[false] {""}
|
||||||
*[nothing] {""}
|
}closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for some specific lifetime `'{lifetime_1}`...
|
||||||
}
|
infer_actual_impl_expl_expected_signature_nothing = {$leading_ellipsis ->
|
||||||
|
[true] ...
|
||||||
|
*[false] {""}
|
||||||
|
}closure with signature `{$ty_or_sig}` must implement `{$trait_path}`
|
||||||
|
infer_actual_impl_expl_expected_passive_two = {$leading_ellipsis ->
|
||||||
|
[true] ...
|
||||||
|
*[false] {""}
|
||||||
|
}`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...
|
||||||
|
infer_actual_impl_expl_expected_passive_any = {$leading_ellipsis ->
|
||||||
|
[true] ...
|
||||||
|
*[false] {""}
|
||||||
|
}`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for any lifetime `'{$lifetime_1}`...
|
||||||
|
infer_actual_impl_expl_expected_passive_some = {$leading_ellipsis ->
|
||||||
|
[true] ...
|
||||||
|
*[false] {""}
|
||||||
|
}`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for some specific lifetime `'{lifetime_1}`...
|
||||||
|
infer_actual_impl_expl_expected_passive_nothing = {$leading_ellipsis ->
|
||||||
|
[true] ...
|
||||||
|
*[false] {""}
|
||||||
|
}`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`
|
||||||
|
infer_actual_impl_expl_expected_other_two = {$leading_ellipsis ->
|
||||||
|
[true] ...
|
||||||
|
*[false] {""}
|
||||||
|
}`{$ty_or_sig}` must implement `{$trait_path}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...
|
||||||
|
infer_actual_impl_expl_expected_other_any = {$leading_ellipsis ->
|
||||||
|
[true] ...
|
||||||
|
*[false] {""}
|
||||||
|
}`{$ty_or_sig}` must implement `{$trait_path}`, for any lifetime `'{$lifetime_1}`...
|
||||||
|
infer_actual_impl_expl_expected_other_some = {$leading_ellipsis ->
|
||||||
|
[true] ...
|
||||||
|
*[false] {""}
|
||||||
|
}`{$ty_or_sig}` must implement `{$trait_path}`, for some specific lifetime `'{lifetime_1}`...
|
||||||
|
infer_actual_impl_expl_expected_other_nothing = {$leading_ellipsis ->
|
||||||
|
[true] ...
|
||||||
|
*[false] {""}
|
||||||
|
}`{$ty_or_sig}` must implement `{$trait_path}`
|
||||||
|
|
||||||
infer_actual_impl_expl_but_actually = {$kind_2 ->
|
infer_actual_impl_expl_but_actually_implements_trait = ...but it actually implements `{$trait_path_2}`{$has_lifetime ->
|
||||||
[implements_trait] ...but it actually implements `{$trait_path_2}`
|
[true] , for some specific lifetime `'{$lifetime}`
|
||||||
[implemented_for_ty] ...but `{$trait_path_2}` is actually implemented for the type `{$ty}`
|
*[false] {""}
|
||||||
*[ty_implements] ...but `{$ty}` actually implements `{$trait_path_2}`
|
}
|
||||||
}{$has_lifetime ->
|
infer_actual_impl_expl_but_actually_implemented_for_ty = ...but `{$trait_path_2}` is actually implemented for the type `{$ty}`{$has_lifetime ->
|
||||||
|
[true] , for some specific lifetime `'{$lifetime}`
|
||||||
|
*[false] {""}
|
||||||
|
}
|
||||||
|
infer_actual_impl_expl_but_actually_ty_implements = ...but `{$ty}` actually implements `{$trait_path_2}`{$has_lifetime ->
|
||||||
[true] , for some specific lifetime `'{$lifetime}`
|
[true] , for some specific lifetime `'{$lifetime}`
|
||||||
*[false] {""}
|
*[false] {""}
|
||||||
}
|
}
|
||||||
|
@ -544,25 +544,177 @@ pub struct ExplicitLifetimeRequired<'a> {
|
|||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
pub enum ActualImplExplNotes {
|
pub enum ActualImplExplNotes {
|
||||||
// Field names have to be different across all variants
|
// Field names have to be different across Expected* and ButActually variants
|
||||||
#[note(infer::actual_impl_expl_expected)]
|
#[note(infer::actual_impl_expl_expected_signature_two)]
|
||||||
Expected {
|
ExpectedSignatureTwo {
|
||||||
leading_ellipsis: bool,
|
leading_ellipsis: bool,
|
||||||
kind: &'static str,
|
|
||||||
ty_or_sig: String,
|
ty_or_sig: String,
|
||||||
trait_path: String,
|
trait_path: String,
|
||||||
lt_kind: &'static str,
|
|
||||||
lifetime_1: usize,
|
lifetime_1: usize,
|
||||||
lifetime_2: usize,
|
lifetime_2: usize,
|
||||||
},
|
},
|
||||||
#[note(infer::actual_impl_expl_but_actually)]
|
#[note(infer::actual_impl_expl_expected_signature_any)]
|
||||||
ButActually {
|
ExpectedSignatureAny {
|
||||||
kind_2: &'static str,
|
leading_ellipsis: bool,
|
||||||
|
ty_or_sig: String,
|
||||||
|
trait_path: String,
|
||||||
|
lifetime_1: usize,
|
||||||
|
},
|
||||||
|
#[note(infer::actual_impl_expl_expected_signature_some)]
|
||||||
|
ExpectedSignatureSome {
|
||||||
|
leading_ellipsis: bool,
|
||||||
|
ty_or_sig: String,
|
||||||
|
trait_path: String,
|
||||||
|
lifetime_1: usize,
|
||||||
|
},
|
||||||
|
#[note(infer::actual_impl_expl_expected_signature_nothing)]
|
||||||
|
ExpectedSignatureNothing { leading_ellipsis: bool, ty_or_sig: String, trait_path: String },
|
||||||
|
#[note(infer::actual_impl_expl_expected_passive_two)]
|
||||||
|
ExpectedPassiveTwo {
|
||||||
|
leading_ellipsis: bool,
|
||||||
|
ty_or_sig: String,
|
||||||
|
trait_path: String,
|
||||||
|
lifetime_1: usize,
|
||||||
|
lifetime_2: usize,
|
||||||
|
},
|
||||||
|
#[note(infer::actual_impl_expl_expected_passive_any)]
|
||||||
|
ExpectedPassiveAny {
|
||||||
|
leading_ellipsis: bool,
|
||||||
|
ty_or_sig: String,
|
||||||
|
trait_path: String,
|
||||||
|
lifetime_1: usize,
|
||||||
|
},
|
||||||
|
#[note(infer::actual_impl_expl_expected_passive_some)]
|
||||||
|
ExpectedPassiveSome {
|
||||||
|
leading_ellipsis: bool,
|
||||||
|
ty_or_sig: String,
|
||||||
|
trait_path: String,
|
||||||
|
lifetime_1: usize,
|
||||||
|
},
|
||||||
|
#[note(infer::actual_impl_expl_expected_passive_nothing)]
|
||||||
|
ExpectedPassiveNothing { leading_ellipsis: bool, ty_or_sig: String, trait_path: String },
|
||||||
|
#[note(infer::actual_impl_expl_expected_other_two)]
|
||||||
|
ExpectedOtherTwo {
|
||||||
|
leading_ellipsis: bool,
|
||||||
|
ty_or_sig: String,
|
||||||
|
trait_path: String,
|
||||||
|
lifetime_1: usize,
|
||||||
|
lifetime_2: usize,
|
||||||
|
},
|
||||||
|
#[note(infer::actual_impl_expl_expected_other_any)]
|
||||||
|
ExpectedOtherAny {
|
||||||
|
leading_ellipsis: bool,
|
||||||
|
ty_or_sig: String,
|
||||||
|
trait_path: String,
|
||||||
|
lifetime_1: usize,
|
||||||
|
},
|
||||||
|
#[note(infer::actual_impl_expl_expected_other_some)]
|
||||||
|
ExpectedOtherSome {
|
||||||
|
leading_ellipsis: bool,
|
||||||
|
ty_or_sig: String,
|
||||||
|
trait_path: String,
|
||||||
|
lifetime_1: usize,
|
||||||
|
},
|
||||||
|
#[note(infer::actual_impl_expl_expected_other_nothing)]
|
||||||
|
ExpectedOtherNothing { leading_ellipsis: bool, ty_or_sig: String, trait_path: String },
|
||||||
|
#[note(infer::actual_impl_expl_but_actually_implements_trait)]
|
||||||
|
ButActuallyImplementsTrait { trait_path_2: String, has_lifetime: bool, lifetime: usize },
|
||||||
|
#[note(infer::actual_impl_expl_but_actually_implemented_for_ty)]
|
||||||
|
ButActuallyImplementedForTy {
|
||||||
trait_path_2: String,
|
trait_path_2: String,
|
||||||
has_lifetime: bool,
|
has_lifetime: bool,
|
||||||
lifetime: usize,
|
lifetime: usize,
|
||||||
ty: String,
|
ty: String,
|
||||||
},
|
},
|
||||||
|
#[note(infer::actual_impl_expl_but_actually_ty_implements)]
|
||||||
|
ButActuallyTyImplements {
|
||||||
|
trait_path_2: String,
|
||||||
|
has_lifetime: bool,
|
||||||
|
lifetime: usize,
|
||||||
|
ty: String,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum ActualImplExpectedKind {
|
||||||
|
Signature,
|
||||||
|
Passive,
|
||||||
|
Other,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum ActualImplExpectedLifetimeKind {
|
||||||
|
Two,
|
||||||
|
Any,
|
||||||
|
Some,
|
||||||
|
Nothing,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActualImplExplNotes {
|
||||||
|
pub fn new_expected(
|
||||||
|
kind: ActualImplExpectedKind,
|
||||||
|
lt_kind: ActualImplExpectedLifetimeKind,
|
||||||
|
leading_ellipsis: bool,
|
||||||
|
ty_or_sig: String,
|
||||||
|
trait_path: String,
|
||||||
|
lifetime_1: usize,
|
||||||
|
lifetime_2: usize,
|
||||||
|
) -> Self {
|
||||||
|
match (kind, lt_kind) {
|
||||||
|
(ActualImplExpectedKind::Signature, ActualImplExpectedLifetimeKind::Two) => {
|
||||||
|
Self::ExpectedSignatureTwo {
|
||||||
|
leading_ellipsis,
|
||||||
|
ty_or_sig,
|
||||||
|
trait_path,
|
||||||
|
lifetime_1,
|
||||||
|
lifetime_2,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(ActualImplExpectedKind::Signature, ActualImplExpectedLifetimeKind::Any) => {
|
||||||
|
Self::ExpectedSignatureAny { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
|
||||||
|
}
|
||||||
|
(ActualImplExpectedKind::Signature, ActualImplExpectedLifetimeKind::Some) => {
|
||||||
|
Self::ExpectedSignatureSome { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
|
||||||
|
}
|
||||||
|
(ActualImplExpectedKind::Signature, ActualImplExpectedLifetimeKind::Nothing) => {
|
||||||
|
Self::ExpectedSignatureNothing { leading_ellipsis, ty_or_sig, trait_path }
|
||||||
|
}
|
||||||
|
(ActualImplExpectedKind::Passive, ActualImplExpectedLifetimeKind::Two) => {
|
||||||
|
Self::ExpectedPassiveTwo {
|
||||||
|
leading_ellipsis,
|
||||||
|
ty_or_sig,
|
||||||
|
trait_path,
|
||||||
|
lifetime_1,
|
||||||
|
lifetime_2,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(ActualImplExpectedKind::Passive, ActualImplExpectedLifetimeKind::Any) => {
|
||||||
|
Self::ExpectedPassiveAny { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
|
||||||
|
}
|
||||||
|
(ActualImplExpectedKind::Passive, ActualImplExpectedLifetimeKind::Some) => {
|
||||||
|
Self::ExpectedPassiveSome { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
|
||||||
|
}
|
||||||
|
(ActualImplExpectedKind::Passive, ActualImplExpectedLifetimeKind::Nothing) => {
|
||||||
|
Self::ExpectedPassiveNothing { leading_ellipsis, ty_or_sig, trait_path }
|
||||||
|
}
|
||||||
|
(ActualImplExpectedKind::Other, ActualImplExpectedLifetimeKind::Two) => {
|
||||||
|
Self::ExpectedOtherTwo {
|
||||||
|
leading_ellipsis,
|
||||||
|
ty_or_sig,
|
||||||
|
trait_path,
|
||||||
|
lifetime_1,
|
||||||
|
lifetime_2,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(ActualImplExpectedKind::Other, ActualImplExpectedLifetimeKind::Any) => {
|
||||||
|
Self::ExpectedOtherAny { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
|
||||||
|
}
|
||||||
|
(ActualImplExpectedKind::Other, ActualImplExpectedLifetimeKind::Some) => {
|
||||||
|
Self::ExpectedOtherSome { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
|
||||||
|
}
|
||||||
|
(ActualImplExpectedKind::Other, ActualImplExpectedLifetimeKind::Nothing) => {
|
||||||
|
Self::ExpectedOtherNothing { leading_ellipsis, ty_or_sig, trait_path }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
use crate::errors::{ActualImplExplNotes, TraitPlaceholderMismatch};
|
use crate::errors::{
|
||||||
|
ActualImplExpectedKind, ActualImplExpectedLifetimeKind, ActualImplExplNotes,
|
||||||
|
TraitPlaceholderMismatch,
|
||||||
|
};
|
||||||
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
|
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
|
||||||
use crate::infer::lexical_region_resolve::RegionResolutionError;
|
use crate::infer::lexical_region_resolve::RegionResolutionError;
|
||||||
use crate::infer::ValuePairs;
|
use crate::infer::ValuePairs;
|
||||||
@ -414,52 +417,54 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
(
|
(
|
||||||
"signature",
|
ActualImplExpectedKind::Signature,
|
||||||
closure_sig.to_string(),
|
closure_sig.to_string(),
|
||||||
expected_trait_ref.map(|tr| tr.print_only_trait_path()).to_string(),
|
expected_trait_ref.map(|tr| tr.print_only_trait_path()).to_string(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
"other",
|
ActualImplExpectedKind::Other,
|
||||||
self_ty.to_string(),
|
self_ty.to_string(),
|
||||||
expected_trait_ref.map(|tr| tr.print_only_trait_path()).to_string(),
|
expected_trait_ref.map(|tr| tr.print_only_trait_path()).to_string(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if passive_voice {
|
} else if passive_voice {
|
||||||
(
|
(
|
||||||
"passive",
|
ActualImplExpectedKind::Passive,
|
||||||
expected_trait_ref.map(|tr| tr.self_ty()).to_string(),
|
expected_trait_ref.map(|tr| tr.self_ty()).to_string(),
|
||||||
expected_trait_ref.map(|tr| tr.print_only_trait_path()).to_string(),
|
expected_trait_ref.map(|tr| tr.print_only_trait_path()).to_string(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
"other",
|
ActualImplExpectedKind::Other,
|
||||||
expected_trait_ref.map(|tr| tr.self_ty()).to_string(),
|
expected_trait_ref.map(|tr| tr.self_ty()).to_string(),
|
||||||
expected_trait_ref.map(|tr| tr.print_only_trait_path()).to_string(),
|
expected_trait_ref.map(|tr| tr.print_only_trait_path()).to_string(),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
let (lt_kind, lifetime_1, lifetime_2) = match (has_sub, has_sup) {
|
let (lt_kind, lifetime_1, lifetime_2) = match (has_sub, has_sup) {
|
||||||
(Some(n1), Some(n2)) => ("two", std::cmp::min(n1, n2), std::cmp::max(n1, n2)),
|
(Some(n1), Some(n2)) => {
|
||||||
(Some(n), _) | (_, Some(n)) => ("any", n, 0),
|
(ActualImplExpectedLifetimeKind::Two, std::cmp::min(n1, n2), std::cmp::max(n1, n2))
|
||||||
|
}
|
||||||
|
(Some(n), _) | (_, Some(n)) => (ActualImplExpectedLifetimeKind::Any, n, 0),
|
||||||
(None, None) => {
|
(None, None) => {
|
||||||
if let Some(n) = expected_has_vid {
|
if let Some(n) = expected_has_vid {
|
||||||
("some", n, 0)
|
(ActualImplExpectedLifetimeKind::Some, n, 0)
|
||||||
} else {
|
} else {
|
||||||
("nothing", 0, 0)
|
(ActualImplExpectedLifetimeKind::Nothing, 0, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let note_1 = ActualImplExplNotes::Expected {
|
let note_1 = ActualImplExplNotes::new_expected(
|
||||||
leading_ellipsis,
|
|
||||||
kind,
|
kind,
|
||||||
|
lt_kind,
|
||||||
|
leading_ellipsis,
|
||||||
ty_or_sig,
|
ty_or_sig,
|
||||||
trait_path,
|
trait_path,
|
||||||
lt_kind,
|
|
||||||
lifetime_1,
|
lifetime_1,
|
||||||
lifetime_2,
|
lifetime_2,
|
||||||
};
|
);
|
||||||
|
|
||||||
let mut actual_trait_ref = highlight_trait_ref(actual_trait_ref);
|
let mut actual_trait_ref = highlight_trait_ref(actual_trait_ref);
|
||||||
actual_trait_ref.highlight.maybe_highlighting_region(vid, actual_has_vid);
|
actual_trait_ref.highlight.maybe_highlighting_region(vid, actual_has_vid);
|
||||||
@ -471,19 +476,26 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||||||
|
|
||||||
let trait_path_2 = actual_trait_ref.map(|tr| tr.print_only_trait_path()).to_string();
|
let trait_path_2 = actual_trait_ref.map(|tr| tr.print_only_trait_path()).to_string();
|
||||||
let ty = actual_trait_ref.map(|tr| tr.self_ty()).to_string();
|
let ty = actual_trait_ref.map(|tr| tr.self_ty()).to_string();
|
||||||
let kind_2 = if same_self_type {
|
|
||||||
"implements_trait"
|
|
||||||
} else if passive_voice {
|
|
||||||
"implemented_for_ty"
|
|
||||||
} else {
|
|
||||||
"ty_implements"
|
|
||||||
};
|
|
||||||
|
|
||||||
let has_lifetime = actual_has_vid.is_some();
|
let has_lifetime = actual_has_vid.is_some();
|
||||||
let lifetime = actual_has_vid.unwrap_or_default();
|
let lifetime = actual_has_vid.unwrap_or_default();
|
||||||
|
|
||||||
let note_2 =
|
let note_2 = if same_self_type {
|
||||||
ActualImplExplNotes::ButActually { kind_2, trait_path_2, ty, has_lifetime, lifetime };
|
ActualImplExplNotes::ButActuallyImplementsTrait { trait_path_2, has_lifetime, lifetime }
|
||||||
|
} else if passive_voice {
|
||||||
|
ActualImplExplNotes::ButActuallyImplementedForTy {
|
||||||
|
trait_path_2,
|
||||||
|
ty,
|
||||||
|
has_lifetime,
|
||||||
|
lifetime,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ActualImplExplNotes::ButActuallyTyImplements {
|
||||||
|
trait_path_2,
|
||||||
|
ty,
|
||||||
|
has_lifetime,
|
||||||
|
lifetime,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
vec![note_1, note_2]
|
vec![note_1, note_2]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user