Move IntercrateAmbiguityCause to librustc_trait_selection.
This commit is contained in:
parent
e288d05012
commit
2baefd3206
2 changed files with 41 additions and 41 deletions
|
@ -253,44 +253,3 @@ impl<'tcx> From<OverflowError> for SelectionError<'tcx> {
|
||||||
SelectionError::Overflow
|
SelectionError::Overflow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub enum IntercrateAmbiguityCause {
|
|
||||||
DownstreamCrate { trait_desc: String, self_desc: Option<String> },
|
|
||||||
UpstreamCrateUpdate { trait_desc: String, self_desc: Option<String> },
|
|
||||||
ReservationImpl { message: String },
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntercrateAmbiguityCause {
|
|
||||||
/// Emits notes when the overlap is caused by complex intercrate ambiguities.
|
|
||||||
/// See #23980 for details.
|
|
||||||
pub fn add_intercrate_ambiguity_hint(&self, err: &mut rustc_errors::DiagnosticBuilder<'_>) {
|
|
||||||
err.note(&self.intercrate_ambiguity_hint());
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn intercrate_ambiguity_hint(&self) -> String {
|
|
||||||
match self {
|
|
||||||
&IntercrateAmbiguityCause::DownstreamCrate { ref trait_desc, ref self_desc } => {
|
|
||||||
let self_desc = if let &Some(ref ty) = self_desc {
|
|
||||||
format!(" for type `{}`", ty)
|
|
||||||
} else {
|
|
||||||
String::new()
|
|
||||||
};
|
|
||||||
format!("downstream crates may implement trait `{}`{}", trait_desc, self_desc)
|
|
||||||
}
|
|
||||||
&IntercrateAmbiguityCause::UpstreamCrateUpdate { ref trait_desc, ref self_desc } => {
|
|
||||||
let self_desc = if let &Some(ref ty) = self_desc {
|
|
||||||
format!(" for type `{}`", ty)
|
|
||||||
} else {
|
|
||||||
String::new()
|
|
||||||
};
|
|
||||||
format!(
|
|
||||||
"upstream crates may add a new impl of trait `{}`{} \
|
|
||||||
in future versions",
|
|
||||||
trait_desc, self_desc
|
|
||||||
)
|
|
||||||
}
|
|
||||||
&IntercrateAmbiguityCause::ReservationImpl { ref message } => message.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -51,6 +51,47 @@ pub use rustc_middle::traits::select::*;
|
||||||
mod candidate_assembly;
|
mod candidate_assembly;
|
||||||
mod confirmation;
|
mod confirmation;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum IntercrateAmbiguityCause {
|
||||||
|
DownstreamCrate { trait_desc: String, self_desc: Option<String> },
|
||||||
|
UpstreamCrateUpdate { trait_desc: String, self_desc: Option<String> },
|
||||||
|
ReservationImpl { message: String },
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntercrateAmbiguityCause {
|
||||||
|
/// Emits notes when the overlap is caused by complex intercrate ambiguities.
|
||||||
|
/// See #23980 for details.
|
||||||
|
pub fn add_intercrate_ambiguity_hint(&self, err: &mut rustc_errors::DiagnosticBuilder<'_>) {
|
||||||
|
err.note(&self.intercrate_ambiguity_hint());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn intercrate_ambiguity_hint(&self) -> String {
|
||||||
|
match self {
|
||||||
|
&IntercrateAmbiguityCause::DownstreamCrate { ref trait_desc, ref self_desc } => {
|
||||||
|
let self_desc = if let &Some(ref ty) = self_desc {
|
||||||
|
format!(" for type `{}`", ty)
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
};
|
||||||
|
format!("downstream crates may implement trait `{}`{}", trait_desc, self_desc)
|
||||||
|
}
|
||||||
|
&IntercrateAmbiguityCause::UpstreamCrateUpdate { ref trait_desc, ref self_desc } => {
|
||||||
|
let self_desc = if let &Some(ref ty) = self_desc {
|
||||||
|
format!(" for type `{}`", ty)
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
};
|
||||||
|
format!(
|
||||||
|
"upstream crates may add a new impl of trait `{}`{} \
|
||||||
|
in future versions",
|
||||||
|
trait_desc, self_desc
|
||||||
|
)
|
||||||
|
}
|
||||||
|
&IntercrateAmbiguityCause::ReservationImpl { ref message } => message.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct SelectionContext<'cx, 'tcx> {
|
pub struct SelectionContext<'cx, 'tcx> {
|
||||||
infcx: &'cx InferCtxt<'cx, 'tcx>,
|
infcx: &'cx InferCtxt<'cx, 'tcx>,
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue