From ee04de08d3caf1ba334c31290e45a94088902afb Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Tue, 7 Jun 2022 19:53:05 -0400 Subject: [PATCH] Stabilize `explicit_generic_args_with_impl_trait` --- .../locales/en-US/typeck.ftl | 6 -- compiler/rustc_feature/src/accepted.rs | 2 + compiler/rustc_feature/src/active.rs | 2 - compiler/rustc_typeck/src/astconv/generics.rs | 60 ++++--------------- compiler/rustc_typeck/src/errors.rs | 11 ---- .../explicit-generic-args-with-impl-trait.md | 53 ---------------- .../impl-trait-with-const-arguments.rs | 3 +- .../impl-trait-with-const-arguments.stderr | 12 ---- .../explicit-generic-args-for-impl.rs | 2 - .../explicit-generic-args-for-impl.stderr | 4 +- .../explicit-generic-args.rs | 2 - .../feature-gate.rs | 7 --- .../feature-gate.stderr | 12 ---- .../issue-87718.rs | 2 - .../not-enough-args.rs | 2 - .../not-enough-args.stderr | 4 +- .../issues/universal-issue-48703.rs | 7 --- .../issues/universal-issue-48703.stderr | 12 ---- ...iversal-turbofish-in-method-issue-50950.rs | 2 +- ...sal-turbofish-in-method-issue-50950.stderr | 20 ++++--- 20 files changed, 31 insertions(+), 194 deletions(-) delete mode 100644 src/doc/unstable-book/src/language-features/explicit-generic-args-with-impl-trait.md delete mode 100644 src/test/ui/const-generics/impl-trait-with-const-arguments.stderr delete mode 100644 src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/feature-gate.rs delete mode 100644 src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/feature-gate.stderr delete mode 100644 src/test/ui/impl-trait/issues/universal-issue-48703.rs delete mode 100644 src/test/ui/impl-trait/issues/universal-issue-48703.stderr diff --git a/compiler/rustc_error_messages/locales/en-US/typeck.ftl b/compiler/rustc_error_messages/locales/en-US/typeck.ftl index 95b348ec6135..c61735a57e16 100644 --- a/compiler/rustc_error_messages/locales/en-US/typeck.ftl +++ b/compiler/rustc_error_messages/locales/en-US/typeck.ftl @@ -95,12 +95,6 @@ typeck-expected-return-type = expected `{$expected}` because of return type typeck-unconstrained-opaque-type = unconstrained opaque type .note = `{$name}` must be used in combination with a concrete type within the same module -typeck-explicit-generic-args-with-impl-trait = - cannot provide explicit generic arguments when `impl Trait` is used in argument position - .label = explicit generic argument not allowed - .note = see issue #83701 for more information - .help = add `#![feature(explicit_generic_args_with_impl_trait)]` to the crate attributes to enable - typeck-missing-type-params = the type {$parameterCount -> [one] parameter diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs index 048039343a7a..6bff2a1365b6 100644 --- a/compiler/rustc_feature/src/accepted.rs +++ b/compiler/rustc_feature/src/accepted.rs @@ -142,6 +142,8 @@ declare_features! ( (accepted, dyn_trait, "1.27.0", Some(44662), None), /// Allows integer match exhaustiveness checking (RFC 2591). (accepted, exhaustive_integer_patterns, "1.33.0", Some(50907), None), + /// Allows explicit generic arguments specification with `impl Trait` present. + (accepted, explicit_generic_args_with_impl_trait, "1.63.0", Some(83701), None), /// Allows arbitrary expressions in key-value attributes at parse time. (accepted, extended_key_value_attributes, "1.54.0", Some(78835), None), /// Allows resolving absolute paths as paths from other crates. diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 1466e8dfc92e..ad15d4bb8421 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -383,8 +383,6 @@ declare_features! ( (active, exclusive_range_pattern, "1.11.0", Some(37854), None), /// Allows exhaustive pattern matching on types that contain uninhabited types. (active, exhaustive_patterns, "1.13.0", Some(51085), None), - /// Allows explicit generic arguments specification with `impl Trait` present. - (active, explicit_generic_args_with_impl_trait, "1.56.0", Some(83701), None), /// Allows defining `extern type`s. (active, extern_types, "1.23.0", Some(43467), None), /// Allows the use of `#[ffi_const]` on foreign functions. diff --git a/compiler/rustc_typeck/src/astconv/generics.rs b/compiler/rustc_typeck/src/astconv/generics.rs index dc4bc8fb55a1..cbfeaf11d4c9 100644 --- a/compiler/rustc_typeck/src/astconv/generics.rs +++ b/compiler/rustc_typeck/src/astconv/generics.rs @@ -3,7 +3,7 @@ use crate::astconv::{ AstConv, CreateSubstsForGenericArgsCtxt, ExplicitLateBound, GenericArgCountMismatch, GenericArgCountResult, GenericArgPosition, }; -use crate::errors::{AssocTypeBindingNotAllowed, ExplicitGenericArgsWithImplTrait}; +use crate::errors::AssocTypeBindingNotAllowed; use crate::structured_errors::{GenericArgsInfo, StructuredDiagnostic, WrongNumberOfGenericArgs}; use rustc_ast::ast::ParamKindOrd; use rustc_errors::{struct_span_err, Applicability, Diagnostic, MultiSpan}; @@ -397,7 +397,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { is_method_call: IsMethodCall, ) -> GenericArgCountResult { let empty_args = hir::GenericArgs::none(); - let suppress_mismatch = Self::check_impl_trait(tcx, seg, generics); let gen_args = seg.args.unwrap_or(&empty_args); let gen_pos = if is_method_call == IsMethodCall::Yes { @@ -406,7 +405,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { GenericArgPosition::Value }; let has_self = generics.parent.is_none() && generics.has_self; - let infer_args = seg.infer_args || suppress_mismatch; + let infer_args = seg.infer_args; Self::check_generic_arg_count( tcx, span, def_id, seg, generics, gen_args, gen_pos, has_self, infer_args, @@ -431,19 +430,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let param_counts = gen_params.own_counts(); // Subtracting from param count to ensure type params synthesized from `impl Trait` - // cannot be explicitly specified even with `explicit_generic_args_with_impl_trait` - // feature enabled. - let synth_type_param_count = if tcx.features().explicit_generic_args_with_impl_trait { - gen_params - .params - .iter() - .filter(|param| { - matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. }) - }) - .count() - } else { - 0 - }; + // cannot be explicitly specified. + let synth_type_param_count = gen_params + .params + .iter() + .filter(|param| { + matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. }) + }) + .count(); let named_type_param_count = param_counts.types - has_self as usize - synth_type_param_count; let infer_lifetimes = @@ -611,40 +605,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } } - /// Report error if there is an explicit type parameter when using `impl Trait`. - pub(crate) fn check_impl_trait( - tcx: TyCtxt<'_>, - seg: &hir::PathSegment<'_>, - generics: &ty::Generics, - ) -> bool { - if seg.infer_args || tcx.features().explicit_generic_args_with_impl_trait { - return false; - } - - let impl_trait = generics.has_impl_trait(); - - if impl_trait { - let spans = seg - .args() - .args - .iter() - .filter_map(|arg| match arg { - GenericArg::Infer(_) | GenericArg::Type(_) | GenericArg::Const(_) => { - Some(arg.span()) - } - _ => None, - }) - .collect::>(); - - tcx.sess.emit_err(ExplicitGenericArgsWithImplTrait { - spans, - is_nightly_build: tcx.sess.is_nightly_build().then_some(()), - }); - } - - impl_trait - } - /// Emits an error regarding forbidden type binding associations pub fn prohibit_assoc_ty_binding(tcx: TyCtxt<'_>, span: Span) { tcx.sess.emit_err(AssocTypeBindingNotAllowed { span }); diff --git a/compiler/rustc_typeck/src/errors.rs b/compiler/rustc_typeck/src/errors.rs index a7f736fed14a..67a3d4a4d020 100644 --- a/compiler/rustc_typeck/src/errors.rs +++ b/compiler/rustc_typeck/src/errors.rs @@ -241,17 +241,6 @@ pub struct UnconstrainedOpaqueType { pub name: Symbol, } -#[derive(SessionDiagnostic)] -#[error(code = "E0632", slug = "typeck-explicit-generic-args-with-impl-trait")] -#[note] -pub struct ExplicitGenericArgsWithImplTrait { - #[primary_span] - #[label] - pub spans: Vec, - #[help] - pub is_nightly_build: Option<()>, -} - pub struct MissingTypeParams { pub span: Span, pub def_span: Span, diff --git a/src/doc/unstable-book/src/language-features/explicit-generic-args-with-impl-trait.md b/src/doc/unstable-book/src/language-features/explicit-generic-args-with-impl-trait.md deleted file mode 100644 index 479571d85fe0..000000000000 --- a/src/doc/unstable-book/src/language-features/explicit-generic-args-with-impl-trait.md +++ /dev/null @@ -1,53 +0,0 @@ -# `explicit_generic_args_with_impl_trait` - -The tracking issue for this feature is: [#83701] - -[#83701]: https://github.com/rust-lang/rust/issues/83701 - ------------------------- - -The `explicit_generic_args_with_impl_trait` feature gate lets you specify generic arguments even -when `impl Trait` is used in argument position. - -A simple example is: - -```rust -#![feature(explicit_generic_args_with_impl_trait)] - -fn foo(_f: impl AsRef) {} - -fn main() { - foo::("".to_string()); -} -``` - -This is currently rejected: - -```text -error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position - --> src/main.rs:6:11 - | -6 | foo::("".to_string()); - | ^^^ explicit generic argument not allowed - -``` - -However it would compile if `explicit_generic_args_with_impl_trait` is enabled. - -Note that the synthetic type parameters from `impl Trait` are still implicit and you -cannot explicitly specify these: - -```rust,compile_fail -#![feature(explicit_generic_args_with_impl_trait)] - -fn foo(_f: impl AsRef) {} -fn bar>(_f: F) {} - -fn main() { - bar::("".to_string()); // Okay - bar::("".to_string()); // Okay - - foo::("".to_string()); // Okay - foo::("".to_string()); // Error, you cannot specify `impl Trait` explicitly -} -``` diff --git a/src/test/ui/const-generics/impl-trait-with-const-arguments.rs b/src/test/ui/const-generics/impl-trait-with-const-arguments.rs index 24ba393c17f2..1aa23c608234 100644 --- a/src/test/ui/const-generics/impl-trait-with-const-arguments.rs +++ b/src/test/ui/const-generics/impl-trait-with-const-arguments.rs @@ -1,3 +1,5 @@ +// check-pass + trait Usizer { fn m(self) -> usize; } @@ -16,5 +18,4 @@ impl Usizer for Usizable { fn main() { assert_eq!(f::<4usize>(Usizable), 20usize); -//~^ ERROR cannot provide explicit generic arguments when `impl Trait` is used in argument position } diff --git a/src/test/ui/const-generics/impl-trait-with-const-arguments.stderr b/src/test/ui/const-generics/impl-trait-with-const-arguments.stderr deleted file mode 100644 index 87e4ad500404..000000000000 --- a/src/test/ui/const-generics/impl-trait-with-const-arguments.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position - --> $DIR/impl-trait-with-const-arguments.rs:18:20 - | -LL | assert_eq!(f::<4usize>(Usizable), 20usize); - | ^^^^^^ explicit generic argument not allowed - | - = note: see issue #83701 for more information - = help: add `#![feature(explicit_generic_args_with_impl_trait)]` to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0632`. diff --git a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.rs b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.rs index 832a3e3b7b10..3b1024d61265 100644 --- a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.rs +++ b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.rs @@ -1,5 +1,3 @@ -#![feature(explicit_generic_args_with_impl_trait)] - fn foo(_f: impl AsRef) {} fn main() { diff --git a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr index 2ae7745c725c..c8b82783ea84 100644 --- a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr +++ b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr @@ -1,5 +1,5 @@ error[E0107]: this function takes 1 generic argument but 2 generic arguments were supplied - --> $DIR/explicit-generic-args-for-impl.rs:6:5 + --> $DIR/explicit-generic-args-for-impl.rs:4:5 | LL | foo::("".to_string()); | ^^^ ------ help: remove this generic argument @@ -7,7 +7,7 @@ LL | foo::("".to_string()); | expected 1 generic argument | note: function defined here, with 1 generic parameter: `T` - --> $DIR/explicit-generic-args-for-impl.rs:3:4 + --> $DIR/explicit-generic-args-for-impl.rs:1:4 | LL | fn foo(_f: impl AsRef) {} | ^^^ - diff --git a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args.rs b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args.rs index a6585bcf8486..99e0931ab950 100644 --- a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args.rs +++ b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args.rs @@ -1,7 +1,5 @@ // check-pass -#![feature(explicit_generic_args_with_impl_trait)] - fn foo(_f: impl AsRef) {} fn main() { diff --git a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/feature-gate.rs b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/feature-gate.rs deleted file mode 100644 index 0e4d6986d46e..000000000000 --- a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/feature-gate.rs +++ /dev/null @@ -1,7 +0,0 @@ -// gate-test-explicit_generic_args_with_impl_trait - -fn foo(_f: impl AsRef) {} - -fn main() { - foo::("".to_string()); //~ ERROR E0632 -} diff --git a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/feature-gate.stderr b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/feature-gate.stderr deleted file mode 100644 index a25c85faf4e3..000000000000 --- a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/feature-gate.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position - --> $DIR/feature-gate.rs:6:11 - | -LL | foo::("".to_string()); - | ^^^ explicit generic argument not allowed - | - = note: see issue #83701 for more information - = help: add `#![feature(explicit_generic_args_with_impl_trait)]` to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0632`. diff --git a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/issue-87718.rs b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/issue-87718.rs index e2ee63821ae7..987df4997342 100644 --- a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/issue-87718.rs +++ b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/issue-87718.rs @@ -1,7 +1,5 @@ // check-pass -#![feature(explicit_generic_args_with_impl_trait)] - fn f(_: impl AsRef, _: impl AsRef) {} fn main() { diff --git a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/not-enough-args.rs b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/not-enough-args.rs index ffb0582fe8df..7249a36f5fe7 100644 --- a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/not-enough-args.rs +++ b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/not-enough-args.rs @@ -1,5 +1,3 @@ -#![feature(explicit_generic_args_with_impl_trait)] - fn f(_: impl AsRef, _: impl AsRef) {} fn main() { diff --git a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/not-enough-args.stderr b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/not-enough-args.stderr index b6701b68fd6c..9d6db88d3643 100644 --- a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/not-enough-args.stderr +++ b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/not-enough-args.stderr @@ -1,5 +1,5 @@ error[E0107]: this function takes 2 generic arguments but 1 generic argument was supplied - --> $DIR/not-enough-args.rs:6:5 + --> $DIR/not-enough-args.rs:4:5 | LL | f::<[u8]>("a", b"a"); | ^ ---- supplied 1 generic argument @@ -7,7 +7,7 @@ LL | f::<[u8]>("a", b"a"); | expected 2 generic arguments | note: function defined here, with 2 generic parameters: `T`, `U` - --> $DIR/not-enough-args.rs:3:4 + --> $DIR/not-enough-args.rs:1:4 | LL | fn f(_: impl AsRef, _: impl AsRef) {} | ^ - - diff --git a/src/test/ui/impl-trait/issues/universal-issue-48703.rs b/src/test/ui/impl-trait/issues/universal-issue-48703.rs deleted file mode 100644 index d1e5aa6c6b91..000000000000 --- a/src/test/ui/impl-trait/issues/universal-issue-48703.rs +++ /dev/null @@ -1,7 +0,0 @@ -use std::fmt::Debug; - -fn foo(x: impl Debug) { } - -fn main() { - foo::('a'); //~ ERROR cannot provide explicit generic arguments -} diff --git a/src/test/ui/impl-trait/issues/universal-issue-48703.stderr b/src/test/ui/impl-trait/issues/universal-issue-48703.stderr deleted file mode 100644 index 02c7fe8ff2c4..000000000000 --- a/src/test/ui/impl-trait/issues/universal-issue-48703.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position - --> $DIR/universal-issue-48703.rs:6:11 - | -LL | foo::('a'); - | ^^^^^^ explicit generic argument not allowed - | - = note: see issue #83701 for more information - = help: add `#![feature(explicit_generic_args_with_impl_trait)]` to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0632`. diff --git a/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.rs b/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.rs index 4ac0a694cb14..325c40a01c6a 100644 --- a/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.rs +++ b/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.rs @@ -12,6 +12,6 @@ struct TestEvent(i32); fn main() { let mut evt = EventHandler {}; evt.handle_event::(|_evt| { - //~^ ERROR cannot provide explicit generic arguments + //~^ ERROR takes 1 generic argument but 2 generic arguments were supplied }); } diff --git a/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.stderr b/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.stderr index 84b98f71f4f0..1765e7c59163 100644 --- a/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.stderr +++ b/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.stderr @@ -1,14 +1,18 @@ -error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position - --> $DIR/universal-turbofish-in-method-issue-50950.rs:14:24 +error[E0107]: this associated function takes 1 generic argument but 2 generic arguments were supplied + --> $DIR/universal-turbofish-in-method-issue-50950.rs:14:9 | LL | evt.handle_event::(|_evt| { - | ^^^^^^^^^ ^^^^^^^^^^^^^ explicit generic argument not allowed - | | - | explicit generic argument not allowed + | ^^^^^^^^^^^^ ------------- help: remove this generic argument + | | + | expected 1 generic argument | - = note: see issue #83701 for more information - = help: add `#![feature(explicit_generic_args_with_impl_trait)]` to the crate attributes to enable +note: associated function defined here, with 1 generic parameter: `T` + --> $DIR/universal-turbofish-in-method-issue-50950.rs:7:12 + | +LL | pub fn handle_event(&mut self, _efunc: impl FnMut(T)) {} + | ^^^^^^^^^^^^ - + = note: `impl Trait` cannot be explicitly specified as a generic argument error: aborting due to previous error -For more information about this error, try `rustc --explain E0632`. +For more information about this error, try `rustc --explain E0107`.