Rollup merge of #145235 - compiler-errors:comment, r=BoxyUwU
Minor `[const]` tweaks Self explanatory
This commit is contained in:
commit
8f1202cef2
4 changed files with 2 additions and 61 deletions
|
|
@ -390,45 +390,13 @@ fn check_predicates<'tcx>(
|
|||
|
||||
let mut res = Ok(());
|
||||
for (clause, span) in impl1_predicates {
|
||||
if !impl2_predicates.iter().any(|pred2| trait_predicates_eq(clause.as_predicate(), *pred2))
|
||||
{
|
||||
if !impl2_predicates.iter().any(|&pred2| clause.as_predicate() == pred2) {
|
||||
res = res.and(check_specialization_on(tcx, clause, span))
|
||||
}
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
/// Checks if some predicate on the specializing impl (`predicate1`) is the same
|
||||
/// as some predicate on the base impl (`predicate2`).
|
||||
///
|
||||
/// This basically just checks syntactic equivalence, but is a little more
|
||||
/// forgiving since we want to equate `T: Tr` with `T: [const] Tr` so this can work:
|
||||
///
|
||||
/// ```ignore (illustrative)
|
||||
/// #[rustc_specialization_trait]
|
||||
/// trait Specialize { }
|
||||
///
|
||||
/// impl<T: Bound> Tr for T { }
|
||||
/// impl<T: [const] Bound + Specialize> const Tr for T { }
|
||||
/// ```
|
||||
///
|
||||
/// However, we *don't* want to allow the reverse, i.e., when the bound on the
|
||||
/// specializing impl is not as const as the bound on the base impl:
|
||||
///
|
||||
/// ```ignore (illustrative)
|
||||
/// impl<T: [const] Bound> const Tr for T { }
|
||||
/// impl<T: Bound + Specialize> const Tr for T { } // should be T: [const] Bound
|
||||
/// ```
|
||||
///
|
||||
/// So we make that check in this function and try to raise a helpful error message.
|
||||
fn trait_predicates_eq<'tcx>(
|
||||
predicate1: ty::Predicate<'tcx>,
|
||||
predicate2: ty::Predicate<'tcx>,
|
||||
) -> bool {
|
||||
// FIXME(const_trait_impl)
|
||||
predicate1 == predicate2
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(tcx))]
|
||||
fn check_specialization_on<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
|
|
|
|||
|
|
@ -910,7 +910,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
// const stability checking here too, I guess.
|
||||
if self.tcx.is_conditionally_const(callee_did) {
|
||||
let q = self.tcx.const_conditions(callee_did);
|
||||
// FIXME(const_trait_impl): Use this span with a better cause code.
|
||||
for (idx, (cond, pred_span)) in
|
||||
q.instantiate(self.tcx, callee_args).into_iter().enumerate()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ use super::on_unimplemented::{AppendConstMessage, OnUnimplementedNote};
|
|||
use super::suggestions::get_explanation_based_on_obligation;
|
||||
use super::{
|
||||
ArgKind, CandidateSimilarity, FindExprBySpan, GetSafeTransmuteErrorAndReason, ImplCandidate,
|
||||
UnsatisfiedConst,
|
||||
};
|
||||
use crate::error_reporting::TypeErrCtxt;
|
||||
use crate::error_reporting::infer::TyCategory;
|
||||
|
|
@ -374,13 +373,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
let UnsatisfiedConst(unsatisfied_const) = self
|
||||
.maybe_add_note_for_unsatisfied_const(
|
||||
leaf_trait_predicate,
|
||||
&mut err,
|
||||
span,
|
||||
);
|
||||
|
||||
if let Some((msg, span)) = type_def {
|
||||
err.span_label(span, msg);
|
||||
}
|
||||
|
|
@ -506,7 +498,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
span,
|
||||
is_fn_trait,
|
||||
suggested,
|
||||
unsatisfied_const,
|
||||
);
|
||||
|
||||
// Changing mutability doesn't make a difference to whether we have
|
||||
|
|
@ -2716,7 +2707,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
span: Span,
|
||||
is_fn_trait: bool,
|
||||
suggested: bool,
|
||||
unsatisfied_const: bool,
|
||||
) {
|
||||
let body_def_id = obligation.cause.body_id;
|
||||
let span = if let ObligationCauseCode::BinOp { rhs_span: Some(rhs_span), .. } =
|
||||
|
|
@ -2763,10 +2753,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
self.tcx.def_span(trait_def_id),
|
||||
crate::fluent_generated::trait_selection_trait_has_no_impls,
|
||||
);
|
||||
} else if !suggested
|
||||
&& !unsatisfied_const
|
||||
&& trait_predicate.polarity() == ty::PredicatePolarity::Positive
|
||||
{
|
||||
} else if !suggested && trait_predicate.polarity() == ty::PredicatePolarity::Positive {
|
||||
// Can't show anything else useful, try to find similar impls.
|
||||
let impl_candidates = self.find_similar_impl_candidates(trait_predicate);
|
||||
if !self.report_similar_impl_candidates(
|
||||
|
|
@ -2878,17 +2865,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn maybe_add_note_for_unsatisfied_const(
|
||||
&self,
|
||||
_trait_predicate: ty::PolyTraitPredicate<'tcx>,
|
||||
_err: &mut Diag<'_>,
|
||||
_span: Span,
|
||||
) -> UnsatisfiedConst {
|
||||
let unsatisfied_const = UnsatisfiedConst(false);
|
||||
// FIXME(const_trait_impl)
|
||||
unsatisfied_const
|
||||
}
|
||||
|
||||
fn report_closure_error(
|
||||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
|
|
|
|||
|
|
@ -51,8 +51,6 @@ enum GetSafeTransmuteErrorAndReason {
|
|||
Error { err_msg: String, safe_transmute_explanation: Option<String> },
|
||||
}
|
||||
|
||||
struct UnsatisfiedConst(pub bool);
|
||||
|
||||
/// Crude way of getting back an `Expr` from a `Span`.
|
||||
pub struct FindExprBySpan<'hir> {
|
||||
pub span: Span,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue