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

@ -103,7 +103,6 @@ E0198: include_str!("./error_codes/E0198.md"),
E0199: include_str!("./error_codes/E0199.md"),
E0200: include_str!("./error_codes/E0200.md"),
E0201: include_str!("./error_codes/E0201.md"),
E0202: include_str!("./error_codes/E0202.md"),
E0203: include_str!("./error_codes/E0203.md"),
E0204: include_str!("./error_codes/E0204.md"),
E0205: include_str!("./error_codes/E0205.md"),

View file

@ -1,15 +0,0 @@
Inherent associated types were part of [RFC 195] but are not yet implemented.
See [the tracking issue][iss8995] for the status of this implementation.
Erroneous code example:
```compile_fail,E0202
struct Foo;
impl Foo {
type Bar = isize; // error!
}
```
[RFC 195]: https://github.com/rust-lang/rfcs/blob/master/text/0195-associated-items.md
[iss8995]: https://github.com/rust-lang/rust/issues/8995

View file

@ -641,6 +641,9 @@ declare_features! (
/// Allows `pub` on `macro_rules` items.
(active, pub_macro_rules, "1.52.0", Some(78855), None),
/// Allows associated types in inherent impls.
(active, inherent_associated_types, "1.52.0", Some(8995), None),
// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
// -------------------------------------------------------------------------
@ -666,6 +669,7 @@ pub const INCOMPLETE_FEATURES: &[Symbol] = &[
sym::unsized_locals,
sym::capture_disjoint_fields,
sym::const_generics_defaults,
sym::inherent_associated_types,
];
/// Some features are not allowed to be used together at the same time, if

View file

@ -627,6 +627,7 @@ symbols! {
index_mut,
infer_outlives_requirements,
infer_static_outlives_requirements,
inherent_associated_types,
inlateout,
inline,
inline_const,

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 {