diff --git a/compiler/rustc_error_codes/src/error_codes/E0632.md b/compiler/rustc_error_codes/src/error_codes/E0632.md index 40840e894d6..7e0a5c71f5f 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0632.md +++ b/compiler/rustc_error_codes/src/error_codes/E0632.md @@ -1,9 +1,11 @@ +#### Note: this error code is no longer emitted by the compiler. + An explicit generic argument was provided when calling a function that uses `impl Trait` in argument position. Erroneous code example: -```compile_fail,E0632 +```ignore (no longer an error) fn foo(a: T, b: impl Clone) {} foo::(0i32, "abc".to_string()); diff --git a/compiler/rustc_error_messages/locales/en-US/typeck.ftl b/compiler/rustc_error_messages/locales/en-US/typeck.ftl index 95b348ec613..c61735a57e1 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 0abd45c621d..099c40b215d 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 1798bf8d428..35473b6e97a 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 dc4bc8fb55a..3fe4b5b46e0 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,8 +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 { GenericArgPosition::MethodCall @@ -406,10 +404,17 @@ 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; Self::check_generic_arg_count( - tcx, span, def_id, seg, generics, gen_args, gen_pos, has_self, infer_args, + tcx, + span, + def_id, + seg, + generics, + gen_args, + gen_pos, + has_self, + seg.infer_args, ) } @@ -431,19 +436,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 +611,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 a7f736fed14..67a3d4a4d02 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 479571d85fe..00000000000 --- 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.stderr b/src/test/ui/const-generics/impl-trait-with-const-arguments.stderr deleted file mode 100644 index 87e4ad50040..00000000000 --- 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/const-generics/impl-trait-with-const-arguments.rs b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/const-args.rs similarity index 72% rename from src/test/ui/const-generics/impl-trait-with-const-arguments.rs rename to src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/const-args.rs index 24ba393c17f..1aa23c60823 100644 --- a/src/test/ui/const-generics/impl-trait-with-const-arguments.rs +++ b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/const-args.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/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 832a3e3b7b1..3b1024d6126 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 2ae7745c725..c8b82783ea8 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 a6585bcf848..99e0931ab95 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 0e4d6986d46..00000000000 --- 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 a25c85faf4e..00000000000 --- 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 e2ee63821ae..987df499734 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 ffb0582fe8d..7249a36f5fe 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 b6701b68fd6..9d6db88d364 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 d1e5aa6c6b9..00000000000 --- 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 02c7fe8ff2c..00000000000 --- 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 deleted file mode 100644 index 4ac0a694cb1..00000000000 --- a/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.rs +++ /dev/null @@ -1,17 +0,0 @@ -use std::any::Any; -pub struct EventHandler { -} - -impl EventHandler -{ - pub fn handle_event(&mut self, _efunc: impl FnMut(T)) {} -} - -struct TestEvent(i32); - -fn main() { - let mut evt = EventHandler {}; - evt.handle_event::(|_evt| { - //~^ ERROR cannot provide explicit generic arguments - }); -} 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 deleted file mode 100644 index 84b98f71f4f..00000000000 --- a/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.stderr +++ /dev/null @@ -1,14 +0,0 @@ -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 - | -LL | evt.handle_event::(|_evt| { - | ^^^^^^^^^ ^^^^^^^^^^^^^ explicit generic argument not allowed - | | - | 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/inference/issue-83606.rs b/src/test/ui/inference/issue-83606.rs index be56a3020cc..eaaef3463dd 100644 --- a/src/test/ui/inference/issue-83606.rs +++ b/src/test/ui/inference/issue-83606.rs @@ -5,6 +5,6 @@ fn foo(_: impl std::fmt::Display) -> [usize; N] { } fn main() { - let _ = foo("foo"); //<- Do not suggest `foo::("foo");`! + let _ = foo("foo"); //~^ ERROR: type annotations needed for `[usize; _]` } diff --git a/src/test/ui/inference/issue-83606.stderr b/src/test/ui/inference/issue-83606.stderr index 4ffaf820b82..f5c84f96064 100644 --- a/src/test/ui/inference/issue-83606.stderr +++ b/src/test/ui/inference/issue-83606.stderr @@ -1,12 +1,12 @@ error[E0282]: type annotations needed for `[usize; _]` --> $DIR/issue-83606.rs:8:9 | -LL | let _ = foo("foo"); //<- Do not suggest `foo::("foo");`! +LL | let _ = foo("foo"); | ^ | help: consider giving this pattern a type, where the the value of const parameter `N` is specified | -LL | let _: [usize; _] = foo("foo"); //<- Do not suggest `foo::("foo");`! +LL | let _: [usize; _] = foo("foo"); | ++++++++++++ error: aborting due to previous error