Rollup merge of #133325 - compiler-errors:const-spec, r=lcnr,fee1-dead
Reimplement `~const` trait specialization Reimplement const specialization. We need this for `PartialEq` constification :) r? lcnr
This commit is contained in:
commit
8aa5853b58
14 changed files with 274 additions and 74 deletions
|
@ -113,8 +113,6 @@ hir_analysis_const_param_ty_impl_on_unsized =
|
|||
the trait `ConstParamTy` may not be implemented for this type
|
||||
.label = type is not `Sized`
|
||||
|
||||
hir_analysis_const_specialize = cannot specialize on const impl with non-const impl
|
||||
|
||||
hir_analysis_copy_impl_on_non_adt =
|
||||
the trait `Copy` cannot be implemented for this type
|
||||
.label = type is not a structure or enumeration
|
||||
|
|
|
@ -1079,13 +1079,6 @@ pub(crate) struct EmptySpecialization {
|
|||
pub base_impl_span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(hir_analysis_const_specialize)]
|
||||
pub(crate) struct ConstSpecialize {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(hir_analysis_static_specialize)]
|
||||
pub(crate) struct StaticSpecialize {
|
||||
|
|
|
@ -66,7 +66,6 @@
|
|||
//! on traits with methods can.
|
||||
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
|
||||
|
@ -134,7 +133,6 @@ fn check_always_applicable(
|
|||
unconstrained_parent_impl_args(tcx, impl2_def_id, impl2_args)
|
||||
};
|
||||
|
||||
res = res.and(check_constness(tcx, impl1_def_id, impl2_node, span));
|
||||
res = res.and(check_static_lifetimes(tcx, &parent_args, span));
|
||||
res = res.and(check_duplicate_params(tcx, impl1_args, parent_args, span));
|
||||
res = res.and(check_predicates(tcx, impl1_def_id, impl1_args, impl2_node, impl2_args, span));
|
||||
|
@ -157,30 +155,6 @@ fn check_has_items(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Check that the specializing impl `impl1` is at least as const as the base
|
||||
/// impl `impl2`
|
||||
fn check_constness(
|
||||
tcx: TyCtxt<'_>,
|
||||
impl1_def_id: LocalDefId,
|
||||
impl2_node: Node,
|
||||
span: Span,
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
if impl2_node.is_from_trait() {
|
||||
// This isn't a specialization
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let impl1_constness = tcx.constness(impl1_def_id.to_def_id());
|
||||
let impl2_constness = tcx.constness(impl2_node.def_id());
|
||||
|
||||
if let hir::Constness::Const = impl2_constness {
|
||||
if let hir::Constness::NotConst = impl1_constness {
|
||||
return Err(tcx.dcx().emit_err(errors::ConstSpecialize { span }));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Given a specializing impl `impl1`, and the base impl `impl2`, returns two
|
||||
/// generic parameters `(S1, S2)` that equate their trait references.
|
||||
/// The returned types are expressed in terms of the generics of `impl1`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue