Skip to content
Draft
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: 1 addition & 0 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
gate_all!(builtin_syntax, "`builtin #` syntax is unstable");
gate_all!(ergonomic_clones, "ergonomic clones are experimental");
gate_all!(explicit_tail_calls, "`become` expression is experimental");
gate_all!(explicit_ignored_bindings, "explicit `ignored` binding placeholders are experimental");
gate_all!(generic_const_items, "generic const items are experimental");
gate_all!(guard_patterns, "guard patterns are experimental", "consider using match arm guards");
gate_all!(default_field_values, "default values on fields are experimental");
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,8 @@ declare_features! (
(unstable, exhaustive_patterns, "1.13.0", Some(51085)),
/// Disallows `extern` without an explicit ABI.
(unstable, explicit_extern_abis, "1.88.0", Some(134986)),
/// Allows explicit `ignored` binding placeholders in patterns.
(unstable, explicit_ignored_bindings, "1.90.0", None),
/// Allows explicit tail calls via `become` expression.
(incomplete, explicit_tail_calls, "1.72.0", Some(112788)),
/// Allows using `#[export_stable]` which indicates that an item is exportable.
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,13 @@ impl<'a> Parser<'a> {
} else if self.eat_keyword(exp!(Underscore)) {
// Parse `_`
PatKind::Wild
} else if self.check_keyword(exp!(Ignored))
&& !self.look_ahead(1, |t| matches!(t.kind, token::PathSep | token::Bang))
{
self.bump();
// An explicit ignored binding placeholder `ignored`
self.psess.gated_spans.gate(sym::explicit_ignored_bindings, self.prev_token.span);
PatKind::Wild
} else if self.eat_keyword(exp!(Mut)) {
self.parse_pat_ident_mut()?
} else if self.eat_keyword(exp!(Ref)) {
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_parse/src/parser/token_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub enum TokenType {
KwFor,
KwGen,
KwIf,
KwIgnored,
KwImpl,
KwIn,
KwLet,
Expand Down Expand Up @@ -232,6 +233,7 @@ impl TokenType {
KwFor,
KwGen,
KwIf,
KwIgnored,
KwImpl,
KwIn,
KwLet,
Expand Down Expand Up @@ -307,6 +309,7 @@ impl TokenType {
TokenType::KwFor => Some(kw::For),
TokenType::KwGen => Some(kw::Gen),
TokenType::KwIf => Some(kw::If),
TokenType::KwIgnored => Some(kw::Ignored),
TokenType::KwImpl => Some(kw::Impl),
TokenType::KwIn => Some(kw::In),
TokenType::KwLet => Some(kw::Let),
Expand Down Expand Up @@ -521,6 +524,7 @@ macro_rules! exp {
(For) => { exp!(@kw, For, KwFor) };
(Gen) => { exp!(@kw, Gen, KwGen) };
(If) => { exp!(@kw, If, KwIf) };
(Ignored) => { exp!(@kw, Ignored, KwIgnored) };
(Impl) => { exp!(@kw, Impl, KwImpl) };
(In) => { exp!(@kw, In, KwIn) };
(Let) => { exp!(@kw, Let, KwLet) };
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ symbols! {
ContractEnsures: "contract_ensures",
ContractRequires: "contract_requires",
Default: "default",
Ignored: "ignored",
MacroRules: "macro_rules",
Raw: "raw",
Reuse: "reuse",
Expand Down Expand Up @@ -939,6 +940,7 @@ symbols! {
expf128,
explicit_extern_abis,
explicit_generic_args_with_impl_trait,
explicit_ignored_bindings,
explicit_tail_calls,
export_name,
export_stable,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Testing that explicit `ignored` placeholders need the feature gate

fn main() {
let (a, ignored) = (1, 2);
//~^ ERROR explicit `ignored` binding placeholders are experimental
let _ = a;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0658]: explicit `ignored` binding placeholders are experimental
--> $DIR/feature-gate-explicit-ignored-bindings.rs:4:13
|
LL | let (a, ignored) = (1, 2);
| ^^^^^^^
|
= help: add `#![feature(explicit_ignored_bindings)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: aborting due to previous error

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

19 changes: 19 additions & 0 deletions tests/ui/ignored-bindings/basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// check-pass
#![feature(explicit_ignored_bindings)]

fn main() {
let (a, ignored) = (1, 2);
let _ = a;

let (ignored, b) = (1, 2);
let _ = b;

let ((x, ignored), y) = ((1, 2), 3);
let _ = (x, y);

match (1, 2) {
(ignored, 2) => {}
_ => {}
}
}

1 change: 1 addition & 0 deletions tests/ui/parser/raw/raw-idents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ tests!(auto);
tests!(builtin);
tests!(catch);
tests!(default);
tests!(r#ignored);
tests!(macro_rules);
tests!(raw);
tests!(reuse);
Expand Down