Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add incomplete feature gate for inherent associate types. #82516

Merged
merged 1 commit into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
15 changes: 0 additions & 15 deletions compiler/rustc_error_codes/src/error_codes/E0202.md

This file was deleted.

4 changes: 4 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
// -------------------------------------------------------------------------
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ symbols! {
index_mut,
infer_outlives_requirements,
infer_static_outlives_requirements,
inherent_associated_types,
inlateout,
inline,
inline_const,
Expand Down
17 changes: 13 additions & 4 deletions compiler/rustc_typeck/src/collect/type_of.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
}
7 changes: 0 additions & 7 deletions compiler/rustc_typeck/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 14 additions & 3 deletions src/test/ui/assoc-inherent.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
// Test associated types are, until #8995 is implemented, forbidden in inherent impls.
// Test that inherent associated types work with
// inherent_associated_types feature gate.

#![feature(inherent_associated_types)]
#![allow(incomplete_features)]

struct Foo;

impl Foo {
type Bar = isize; //~ERROR associated types are not yet supported in inherent impls (see #8995)
type Bar = isize;
}

fn main() {}
impl Foo {
type Baz; //~ ERROR associated type in `impl` without body
}

fn main() {
let x : Foo::Bar; //~ERROR ambiguous associated type
x = 0isize;
}
20 changes: 14 additions & 6 deletions src/test/ui/assoc-inherent.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
error[E0202]: associated types are not yet supported in inherent impls (see #8995)
--> $DIR/assoc-inherent.rs:6:5
error: associated type in `impl` without body
--> $DIR/assoc-inherent.rs:14:5
|
LL | type Bar = isize;
| ^^^^^^^^^^^^^^^^^
LL | type Baz;
| ^^^^^^^^-
| |
| help: provide a definition for the type: `= <type>;`

error: aborting due to previous error
error[E0223]: ambiguous associated type
--> $DIR/assoc-inherent.rs:18:13
|
LL | let x : Foo::Bar;
| ^^^^^^^^ help: use fully-qualified syntax: `<Foo as Trait>::Bar`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0202`.
For more information about this error, try `rustc --explain E0223`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Test that inherent associated types cannot be used when inherent_associated_types
// feature gate is not used.

struct Foo;

impl Foo {
type Bar = isize; //~ERROR inherent associated types are unstable
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0658]: inherent associated types are unstable
--> $DIR/feature-gate-inherent_associated_types.rs:7:5
|
LL | type Bar = isize;
| ^^^^^^^^^^^^^^^^^
|
= note: see issue #8995 <https://github.com/rust-lang/rust/issues/8995> for more information
= help: add `#![feature(inherent_associated_types)]` to the crate attributes to enable

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.
8 changes: 4 additions & 4 deletions src/test/ui/parser/impl-item-type-no-body-semantic-fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ struct X;
impl X {
type Y;
//~^ ERROR associated type in `impl` without body
//~| ERROR associated types are not yet supported in inherent impls
//~| ERROR inherent associated types are unstable
type Z: Ord;
//~^ ERROR associated type in `impl` without body
//~| ERROR bounds on `type`s in `impl`s have no effect
//~| ERROR associated types are not yet supported in inherent impls
//~| ERROR inherent associated types are unstable
type W: Ord where Self: Eq;
//~^ ERROR associated type in `impl` without body
//~| ERROR bounds on `type`s in `impl`s have no effect
//~| ERROR associated types are not yet supported in inherent impls
//~| ERROR inherent associated types are unstable
type W where Self: Eq;
//~^ ERROR associated type in `impl` without body
//~| ERROR associated types are not yet supported in inherent impls
//~| ERROR inherent associated types are unstable
}
22 changes: 17 additions & 5 deletions src/test/ui/parser/impl-item-type-no-body-semantic-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,42 @@ LL | #![feature(generic_associated_types)]
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information

error[E0202]: associated types are not yet supported in inherent impls (see #8995)
error[E0658]: inherent associated types are unstable
--> $DIR/impl-item-type-no-body-semantic-fail.rs:9:5
|
LL | type Y;
| ^^^^^^^
|
= note: see issue #8995 <https://github.com/rust-lang/rust/issues/8995> for more information
= help: add `#![feature(inherent_associated_types)]` to the crate attributes to enable

error[E0202]: associated types are not yet supported in inherent impls (see #8995)
error[E0658]: inherent associated types are unstable
--> $DIR/impl-item-type-no-body-semantic-fail.rs:12:5
|
LL | type Z: Ord;
| ^^^^^^^^^^^^
|
= note: see issue #8995 <https://github.com/rust-lang/rust/issues/8995> for more information
= help: add `#![feature(inherent_associated_types)]` to the crate attributes to enable

error[E0202]: associated types are not yet supported in inherent impls (see #8995)
error[E0658]: inherent associated types are unstable
--> $DIR/impl-item-type-no-body-semantic-fail.rs:16:5
|
LL | type W: Ord where Self: Eq;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #8995 <https://github.com/rust-lang/rust/issues/8995> for more information
= help: add `#![feature(inherent_associated_types)]` to the crate attributes to enable

error[E0202]: associated types are not yet supported in inherent impls (see #8995)
error[E0658]: inherent associated types are unstable
--> $DIR/impl-item-type-no-body-semantic-fail.rs:20:5
|
LL | type W where Self: Eq;
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #8995 <https://github.com/rust-lang/rust/issues/8995> for more information
= help: add `#![feature(inherent_associated_types)]` to the crate attributes to enable

error: aborting due to 10 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0202`.
For more information about this error, try `rustc --explain E0658`.