1
Fork 0

Add feature gate for inherent associate types.

This commit is contained in:
Olivier FAURE 2021-02-25 14:09:52 +01:00
parent 89d32eb1ea
commit 4f4e15d5eb
12 changed files with 89 additions and 45 deletions

View file

@ -1,4 +1,3 @@
use crate::errors::AssocTypeOnInherentImpl;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{Applicability, ErrorReported, StashKey};
use rustc_hir as hir;
@ -294,7 +293,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
}
ImplItemKind::TyAlias(ref ty) => {
if tcx.impl_trait_ref(tcx.hir().get_parent_did(hir_id).to_def_id()).is_none() {
report_assoc_ty_on_inherent_impl(tcx, item.span);
check_feature_inherent_assoc_ty(tcx, item.span);
}
icx.to_ty(ty)
@ -746,6 +745,16 @@ fn infer_placeholder_type(
})
}
fn report_assoc_ty_on_inherent_impl(tcx: TyCtxt<'_>, span: Span) {
tcx.sess.emit_err(AssocTypeOnInherentImpl { span });
fn check_feature_inherent_assoc_ty(tcx: TyCtxt<'_>, span: Span) {
if !tcx.features().inherent_associated_types {
use rustc_session::parse::feature_err;
use rustc_span::symbol::sym;
feature_err(
&tcx.sess.parse_sess,
sym::inherent_associated_types,
span,
"inherent associated types are unstable",
)
.emit();
}
}

View file

@ -82,13 +82,6 @@ pub struct CopyImplOnTypeWithDtor {
pub span: Span,
}
#[derive(SessionDiagnostic)]
#[error = "E0202"]
pub struct AssocTypeOnInherentImpl {
#[message = "associated types are not yet supported in inherent impls (see #8995)"]
pub span: Span,
}
#[derive(SessionDiagnostic)]
#[error = "E0203"]
pub struct MultipleRelaxedDefaultBounds {