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
4 changes: 4 additions & 0 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,10 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
half_open_range_patterns_in_slices,
"half-open range patterns in slices are unstable"
);
gate_all!(
named_fn_trait_parameters,
"named parameters in parenthesized generic argument lists are experimental"
);

// `associated_const_equality` will be stabilized as part of `min_generic_const_args`.
for &span in spans.get(&sym::associated_const_equality).into_iter().flatten() {
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 @@ -662,6 +662,8 @@ declare_features! (
(unstable, naked_functions_rustic_abi, "1.88.0", Some(138997)),
/// Allows using `#[target_feature(enable = "...")]` on `#[naked]` on functions.
(unstable, naked_functions_target_feature, "1.86.0", Some(138568)),
/// Allows providing names to parameters of `impl Fn` etc
(unstable, named_fn_trait_parameters, "CURRENT_RUSTC_VERSION", Some(158499)),
/// Allows specifying the as-needed link modifier
(unstable, native_link_modifiers_as_needed, "1.53.0", Some(81490)),
/// Allow negative trait implementations.
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2075,14 +2075,6 @@ pub(crate) struct ExpectedFnPathFoundFnKeyword {
pub fn_token_span: Span,
}

#[derive(Diagnostic)]
#[diag("`Trait(...)` syntax does not support named parameters")]
pub(crate) struct FnPathFoundNamedParams {
#[primary_span]
#[suggestion("remove the parameter name", applicability = "machine-applicable", code = "")]
pub named_param_span: Span,
}

#[derive(Diagnostic)]
#[diag("`Trait(...)` syntax does not support c_variadic parameters")]
pub(crate) struct PathFoundCVariadicParams {
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_parse/src/parser/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use super::{Parser, Restrictions, TokenType};
use crate::ast::{PatKind, TyKind};
use crate::errors::{
self, AttributeOnEmptyType, AttributeOnGenericArg, ConstGenericWithoutBraces,
ConstGenericWithoutBracesSugg, FnPathFoundNamedParams, PathFoundAttributeInParams,
PathFoundCVariadicParams, PathSingleColon, PathTripleColon,
ConstGenericWithoutBracesSugg, PathFoundAttributeInParams, PathFoundCVariadicParams,
PathSingleColon, PathTripleColon,
};
use crate::exp;
use crate::parser::{
Expand Down Expand Up @@ -409,11 +409,11 @@ impl<'a> Parser<'a> {
req_body: false,
};
let param = p.parse_param_general(&mode, false, false);
param.map(move |param| {
param.map(|param| {
if !matches!(param.pat.kind, PatKind::Missing) {
dcx.emit_err(FnPathFoundNamedParams {
named_param_span: param.pat.span,
});
self.psess
.gated_spans
.gate(sym::named_fn_trait_parameters, param.pat.span);
}
if matches!(param.ty.kind, TyKind::CVarArgs) {
dcx.emit_err(PathFoundCVariadicParams { span: param.pat.span });
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::Session;
use crate::lint::{Lint, LintId};

/// Collected spans during parsing for places where a certain feature was
/// used and should be feature gated accordingly in `check_crate`.
/// used and should be feature gated accordingly in `check_crate` in `rustc_ast_passes`.
#[derive(Default)]
pub struct GatedSpans {
pub spans: Lock<FxHashMap<Symbol, Vec<Span>>>,
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 @@ -1378,6 +1378,7 @@ symbols! {
naked_functions_rustic_abi,
naked_functions_target_feature,
name,
named_fn_trait_parameters,
names,
native_link_modifiers,
native_link_modifiers_as_needed,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn parse_my_data(
data: &str,
log: impl Fn(msg: String),
//~^ ERROR named parameters in parenthesized generic argument lists are experimental [E0658]
) { }

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0658]: named parameters in parenthesized generic argument lists are experimental
--> $DIR/feature-gate-named-fn-trait-parameters.rs:3:18
|
LL | log: impl Fn(msg: String),
| ^^^
|
= note: see issue #158499 <https://github.com/rust-lang/rust/issues/158499> for more information
= help: add `#![feature(named_fn_trait_parameters)]` 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 1 previous error

For more information about this error, try `rustc --explain E0658`.
8 changes: 4 additions & 4 deletions tests/ui/fn/fn-trait-use-named-params-issue-140169.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
fn f1(_: fn(a: u8)) {}
fn f2(_: impl Fn(u8, vvvv: u8)) {} //~ ERROR `Trait(...)` syntax does not support named parameters
fn f3(_: impl Fn(aaaa: u8, u8)) {} //~ ERROR `Trait(...)` syntax does not support named parameters
fn f2(_: impl Fn(u8, vvvv: u8)) {} //~ ERROR named parameters in parenthesized generic argument lists are experimental
fn f3(_: impl Fn(aaaa: u8, u8)) {} //~ ERROR named parameters in parenthesized generic argument lists are experimental
fn f4(_: impl Fn(aaaa: u8, vvvv: u8)) {}
//~^ ERROR `Trait(...)` syntax does not support named parameters
//~| ERROR `Trait(...)` syntax does not support named parameters
//~^ ERROR named parameters in parenthesized generic argument lists are experimental
//~| ERROR named parameters in parenthesized generic argument lists are experimental
fn f5(_: impl Fn(u8, ...)) {}
//~^ ERROR `Trait(...)` syntax does not support c_variadic parameters
fn f6(_: impl Fn(u8, #[allow(unused_attributes)] u8)) {}
Expand Down
55 changes: 36 additions & 19 deletions tests/ui/fn/fn-trait-use-named-params-issue-140169.stderr
Original file line number Diff line number Diff line change
@@ -1,38 +1,55 @@
error: `Trait(...)` syntax does not support named parameters
error: `Trait(...)` syntax does not support c_variadic parameters
--> $DIR/fn-trait-use-named-params-issue-140169.rs:7:22
|
LL | fn f5(_: impl Fn(u8, ...)) {}
| ^^^ help: remove the `...`

error: `Trait(...)` syntax does not support attributes in parameters
--> $DIR/fn-trait-use-named-params-issue-140169.rs:9:22
|
LL | fn f6(_: impl Fn(u8, #[allow(unused_attributes)] u8)) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the attributes

error[E0658]: named parameters in parenthesized generic argument lists are experimental
--> $DIR/fn-trait-use-named-params-issue-140169.rs:2:22
|
LL | fn f2(_: impl Fn(u8, vvvv: u8)) {}
| ^^^^ help: remove the parameter name
| ^^^^
|
= note: see issue #158499 <https://github.com/rust-lang/rust/issues/158499> for more information
= help: add `#![feature(named_fn_trait_parameters)]` 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: `Trait(...)` syntax does not support named parameters
error[E0658]: named parameters in parenthesized generic argument lists are experimental
--> $DIR/fn-trait-use-named-params-issue-140169.rs:3:18
|
LL | fn f3(_: impl Fn(aaaa: u8, u8)) {}
| ^^^^ help: remove the parameter name
| ^^^^
|
= note: see issue #158499 <https://github.com/rust-lang/rust/issues/158499> for more information
= help: add `#![feature(named_fn_trait_parameters)]` 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: `Trait(...)` syntax does not support named parameters
error[E0658]: named parameters in parenthesized generic argument lists are experimental
--> $DIR/fn-trait-use-named-params-issue-140169.rs:4:18
|
LL | fn f4(_: impl Fn(aaaa: u8, vvvv: u8)) {}
| ^^^^ help: remove the parameter name
| ^^^^
|
= note: see issue #158499 <https://github.com/rust-lang/rust/issues/158499> for more information
= help: add `#![feature(named_fn_trait_parameters)]` 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: `Trait(...)` syntax does not support named parameters
error[E0658]: named parameters in parenthesized generic argument lists are experimental
--> $DIR/fn-trait-use-named-params-issue-140169.rs:4:28
|
LL | fn f4(_: impl Fn(aaaa: u8, vvvv: u8)) {}
| ^^^^ help: remove the parameter name

error: `Trait(...)` syntax does not support c_variadic parameters
--> $DIR/fn-trait-use-named-params-issue-140169.rs:7:22
| ^^^^
|
LL | fn f5(_: impl Fn(u8, ...)) {}
| ^^^ help: remove the `...`

error: `Trait(...)` syntax does not support attributes in parameters
--> $DIR/fn-trait-use-named-params-issue-140169.rs:9:22
|
LL | fn f6(_: impl Fn(u8, #[allow(unused_attributes)] u8)) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the attributes
= note: see issue #158499 <https://github.com/rust-lang/rust/issues/158499> for more information
= help: add `#![feature(named_fn_trait_parameters)]` 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 6 previous errors

For more information about this error, try `rustc --explain E0658`.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

fn main() {
unsafe {
dealloc(ptr2, Layout::(x: !)(1, 1)); //~ ERROR `Trait(...)` syntax does not support named parameters
dealloc(ptr2, Layout::(x: !)(1, 1)); //~ ERROR named parameters in parenthesized generic argument lists are experimental
//~^ ERROR cannot find function `dealloc` in this scope [E0425]
//~| ERROR cannot find value `ptr2` in this scope [E0425]
//~| ERROR the `!` type is experimental [E0658]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
error: `Trait(...)` syntax does not support named parameters
--> $DIR/diagnostics-parenthesized-type-arguments-ice-issue-122345.rs:5:32
|
LL | dealloc(ptr2, Layout::(x: !)(1, 1));
| ^ help: remove the parameter name

error[E0425]: cannot find function `dealloc` in this scope
--> $DIR/diagnostics-parenthesized-type-arguments-ice-issue-122345.rs:5:9
|
Expand All @@ -21,6 +15,16 @@ error[E0425]: cannot find value `ptr2` in this scope
LL | dealloc(ptr2, Layout::(x: !)(1, 1));
| ^^^^ not found in this scope

error[E0658]: named parameters in parenthesized generic argument lists are experimental
--> $DIR/diagnostics-parenthesized-type-arguments-ice-issue-122345.rs:5:32
|
LL | dealloc(ptr2, Layout::(x: !)(1, 1));
| ^
|
= note: see issue #158499 <https://github.com/rust-lang/rust/issues/158499> for more information
= help: add `#![feature(named_fn_trait_parameters)]` 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[E0658]: the `!` type is experimental
--> $DIR/diagnostics-parenthesized-type-arguments-ice-issue-122345.rs:5:35
|
Expand Down
Loading