Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
13 changes: 13 additions & 0 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,19 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}
false
}
ast::AssocItemKind::Const(_) => {
if let (AssocCtxt::Trait, true) =
(ctxt, i.attrs.iter().any(|attr| attr.has_name(sym::type_const)))
{
gate!(
&self,
associated_type_defaults,
i.span,
"associated type defaults are unstable"
);
}
false
}
_ => false,
};
if let ast::Defaultness::Default(_) = i.kind.defaultness() {
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/feature-gates/type-const-associated-default.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//compile fail
#![feature(min_generic_const_args)]

trait Trait {
#[type_const]
const N: usize = 10;
}

fn main(){
}
22 changes: 22 additions & 0 deletions tests/ui/feature-gates/type-const-associated-default.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error[E0658]: associated type defaults are unstable
--> $DIR/type-const-associated-default.rs:6:5
|
LL | const N: usize = 10;
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #29661 <https://github.com/rust-lang/rust/issues/29661> for more information
= help: add `#![feature(associated_type_defaults)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

warning: the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/type-const-associated-default.rs:2:12
|
LL | #![feature(min_generic_const_args)]
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #132980 <https://github.com/rust-lang/rust/issues/132980> for more information
= note: `#[warn(incomplete_features)]` on by default

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

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