Skip to content

Commit f1f44b9

Browse files
authored
Rollup merge of rust-lang#96868 - nrc:turbo-stable, r=jhpratt,nbdd0121,nagisa
Stabilize explicit_generic_args_with_impl_trait This is a stabilisation PR for `explicit_generic_args_with_impl_trait`. * [tracking issue](rust-lang#83701) - [Stabilisation report](rust-lang#83701 (comment)) - [FCP entered](rust-lang#83701 (comment)) * [implementation PR](rust-lang#86176) * [Reference PR](rust-lang/reference#1212) * There is no mention of using the turbofish operator in the book (other than an entry in the operator list in the appendix), so there is no documentation to change/add there, unless we felt like we should add a section on using turbofish, but that seems orthogonal to `explicit_generic_args_with_impl_trait`
2 parents 75307c2 + 640a461 commit f1f44b9

23 files changed

+32
-222
lines changed

compiler/rustc_error_codes/src/error_codes/E0632.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
#### Note: this error code is no longer emitted by the compiler.
2+
13
An explicit generic argument was provided when calling a function that
24
uses `impl Trait` in argument position.
35

46
Erroneous code example:
57

6-
```compile_fail,E0632
8+
```ignore (no longer an error)
79
fn foo<T: Copy>(a: T, b: impl Clone) {}
810
911
foo::<i32>(0i32, "abc".to_string());

compiler/rustc_error_messages/locales/en-US/typeck.ftl

-6
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,6 @@ typeck-expected-return-type = expected `{$expected}` because of return type
9595
typeck-unconstrained-opaque-type = unconstrained opaque type
9696
.note = `{$name}` must be used in combination with a concrete type within the same module
9797
98-
typeck-explicit-generic-args-with-impl-trait =
99-
cannot provide explicit generic arguments when `impl Trait` is used in argument position
100-
.label = explicit generic argument not allowed
101-
.note = see issue #83701 <https://github.com/rust-lang/rust/issues/83701> for more information
102-
.help = add `#![feature(explicit_generic_args_with_impl_trait)]` to the crate attributes to enable
103-
10498
typeck-missing-type-params =
10599
the type {$parameterCount ->
106100
[one] parameter

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ declare_features! (
142142
(accepted, dyn_trait, "1.27.0", Some(44662), None),
143143
/// Allows integer match exhaustiveness checking (RFC 2591).
144144
(accepted, exhaustive_integer_patterns, "1.33.0", Some(50907), None),
145+
/// Allows explicit generic arguments specification with `impl Trait` present.
146+
(accepted, explicit_generic_args_with_impl_trait, "1.63.0", Some(83701), None),
145147
/// Allows arbitrary expressions in key-value attributes at parse time.
146148
(accepted, extended_key_value_attributes, "1.54.0", Some(78835), None),
147149
/// Allows resolving absolute paths as paths from other crates.

compiler/rustc_feature/src/active.rs

-2
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,6 @@ declare_features! (
383383
(active, exclusive_range_pattern, "1.11.0", Some(37854), None),
384384
/// Allows exhaustive pattern matching on types that contain uninhabited types.
385385
(active, exhaustive_patterns, "1.13.0", Some(51085), None),
386-
/// Allows explicit generic arguments specification with `impl Trait` present.
387-
(active, explicit_generic_args_with_impl_trait, "1.56.0", Some(83701), None),
388386
/// Allows defining `extern type`s.
389387
(active, extern_types, "1.23.0", Some(43467), None),
390388
/// Allows the use of `#[ffi_const]` on foreign functions.

compiler/rustc_typeck/src/astconv/generics.rs

+18-52
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::astconv::{
33
AstConv, CreateSubstsForGenericArgsCtxt, ExplicitLateBound, GenericArgCountMismatch,
44
GenericArgCountResult, GenericArgPosition,
55
};
6-
use crate::errors::{AssocTypeBindingNotAllowed, ExplicitGenericArgsWithImplTrait};
6+
use crate::errors::AssocTypeBindingNotAllowed;
77
use crate::structured_errors::{GenericArgsInfo, StructuredDiagnostic, WrongNumberOfGenericArgs};
88
use rustc_ast::ast::ParamKindOrd;
99
use rustc_errors::{struct_span_err, Applicability, Diagnostic, MultiSpan};
@@ -397,19 +397,24 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
397397
is_method_call: IsMethodCall,
398398
) -> GenericArgCountResult {
399399
let empty_args = hir::GenericArgs::none();
400-
let suppress_mismatch = Self::check_impl_trait(tcx, seg, generics);
401-
402400
let gen_args = seg.args.unwrap_or(&empty_args);
403401
let gen_pos = if is_method_call == IsMethodCall::Yes {
404402
GenericArgPosition::MethodCall
405403
} else {
406404
GenericArgPosition::Value
407405
};
408406
let has_self = generics.parent.is_none() && generics.has_self;
409-
let infer_args = seg.infer_args || suppress_mismatch;
410407

411408
Self::check_generic_arg_count(
412-
tcx, span, def_id, seg, generics, gen_args, gen_pos, has_self, infer_args,
409+
tcx,
410+
span,
411+
def_id,
412+
seg,
413+
generics,
414+
gen_args,
415+
gen_pos,
416+
has_self,
417+
seg.infer_args,
413418
)
414419
}
415420

@@ -431,19 +436,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
431436
let param_counts = gen_params.own_counts();
432437

433438
// Subtracting from param count to ensure type params synthesized from `impl Trait`
434-
// cannot be explicitly specified even with `explicit_generic_args_with_impl_trait`
435-
// feature enabled.
436-
let synth_type_param_count = if tcx.features().explicit_generic_args_with_impl_trait {
437-
gen_params
438-
.params
439-
.iter()
440-
.filter(|param| {
441-
matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. })
442-
})
443-
.count()
444-
} else {
445-
0
446-
};
439+
// cannot be explicitly specified.
440+
let synth_type_param_count = gen_params
441+
.params
442+
.iter()
443+
.filter(|param| {
444+
matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. })
445+
})
446+
.count();
447447
let named_type_param_count =
448448
param_counts.types - has_self as usize - synth_type_param_count;
449449
let infer_lifetimes =
@@ -611,40 +611,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
611611
}
612612
}
613613

614-
/// Report error if there is an explicit type parameter when using `impl Trait`.
615-
pub(crate) fn check_impl_trait(
616-
tcx: TyCtxt<'_>,
617-
seg: &hir::PathSegment<'_>,
618-
generics: &ty::Generics,
619-
) -> bool {
620-
if seg.infer_args || tcx.features().explicit_generic_args_with_impl_trait {
621-
return false;
622-
}
623-
624-
let impl_trait = generics.has_impl_trait();
625-
626-
if impl_trait {
627-
let spans = seg
628-
.args()
629-
.args
630-
.iter()
631-
.filter_map(|arg| match arg {
632-
GenericArg::Infer(_) | GenericArg::Type(_) | GenericArg::Const(_) => {
633-
Some(arg.span())
634-
}
635-
_ => None,
636-
})
637-
.collect::<Vec<_>>();
638-
639-
tcx.sess.emit_err(ExplicitGenericArgsWithImplTrait {
640-
spans,
641-
is_nightly_build: tcx.sess.is_nightly_build().then_some(()),
642-
});
643-
}
644-
645-
impl_trait
646-
}
647-
648614
/// Emits an error regarding forbidden type binding associations
649615
pub fn prohibit_assoc_ty_binding(tcx: TyCtxt<'_>, span: Span) {
650616
tcx.sess.emit_err(AssocTypeBindingNotAllowed { span });

compiler/rustc_typeck/src/errors.rs

-11
Original file line numberDiff line numberDiff line change
@@ -241,17 +241,6 @@ pub struct UnconstrainedOpaqueType {
241241
pub name: Symbol,
242242
}
243243

244-
#[derive(SessionDiagnostic)]
245-
#[error(code = "E0632", slug = "typeck-explicit-generic-args-with-impl-trait")]
246-
#[note]
247-
pub struct ExplicitGenericArgsWithImplTrait {
248-
#[primary_span]
249-
#[label]
250-
pub spans: Vec<Span>,
251-
#[help]
252-
pub is_nightly_build: Option<()>,
253-
}
254-
255244
pub struct MissingTypeParams {
256245
pub span: Span,
257246
pub def_span: Span,

src/doc/unstable-book/src/language-features/explicit-generic-args-with-impl-trait.md

-53
This file was deleted.

src/test/ui/const-generics/impl-trait-with-const-arguments.stderr

-12
This file was deleted.

src/test/ui/const-generics/impl-trait-with-const-arguments.rs src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/const-args.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// check-pass
2+
13
trait Usizer {
24
fn m(self) -> usize;
35
}
@@ -16,5 +18,4 @@ impl Usizer for Usizable {
1618

1719
fn main() {
1820
assert_eq!(f::<4usize>(Usizable), 20usize);
19-
//~^ ERROR cannot provide explicit generic arguments when `impl Trait` is used in argument position
2021
}

src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(explicit_generic_args_with_impl_trait)]
2-
31
fn foo<T: ?Sized>(_f: impl AsRef<T>) {}
42

53
fn main() {

src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0107]: this function takes 1 generic argument but 2 generic arguments were supplied
2-
--> $DIR/explicit-generic-args-for-impl.rs:6:5
2+
--> $DIR/explicit-generic-args-for-impl.rs:4:5
33
|
44
LL | foo::<str, String>("".to_string());
55
| ^^^ ------ help: remove this generic argument
66
| |
77
| expected 1 generic argument
88
|
99
note: function defined here, with 1 generic parameter: `T`
10-
--> $DIR/explicit-generic-args-for-impl.rs:3:4
10+
--> $DIR/explicit-generic-args-for-impl.rs:1:4
1111
|
1212
LL | fn foo<T: ?Sized>(_f: impl AsRef<T>) {}
1313
| ^^^ -

src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// check-pass
22

3-
#![feature(explicit_generic_args_with_impl_trait)]
4-
53
fn foo<T: ?Sized>(_f: impl AsRef<T>) {}
64

75
fn main() {

src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/feature-gate.rs

-7
This file was deleted.

src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/feature-gate.stderr

-12
This file was deleted.

src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/issue-87718.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// check-pass
22

3-
#![feature(explicit_generic_args_with_impl_trait)]
4-
53
fn f<T: ?Sized>(_: impl AsRef<T>, _: impl AsRef<T>) {}
64

75
fn main() {

src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/not-enough-args.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(explicit_generic_args_with_impl_trait)]
2-
31
fn f<T: ?Sized, U: ?Sized>(_: impl AsRef<T>, _: impl AsRef<U>) {}
42

53
fn main() {

src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/not-enough-args.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0107]: this function takes 2 generic arguments but 1 generic argument was supplied
2-
--> $DIR/not-enough-args.rs:6:5
2+
--> $DIR/not-enough-args.rs:4:5
33
|
44
LL | f::<[u8]>("a", b"a");
55
| ^ ---- supplied 1 generic argument
66
| |
77
| expected 2 generic arguments
88
|
99
note: function defined here, with 2 generic parameters: `T`, `U`
10-
--> $DIR/not-enough-args.rs:3:4
10+
--> $DIR/not-enough-args.rs:1:4
1111
|
1212
LL | fn f<T: ?Sized, U: ?Sized>(_: impl AsRef<T>, _: impl AsRef<U>) {}
1313
| ^ - -

src/test/ui/impl-trait/issues/universal-issue-48703.rs

-7
This file was deleted.

src/test/ui/impl-trait/issues/universal-issue-48703.stderr

-12
This file was deleted.

src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.rs

-17
This file was deleted.

src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.stderr

-14
This file was deleted.

src/test/ui/inference/issue-83606.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ fn foo<const N: usize>(_: impl std::fmt::Display) -> [usize; N] {
55
}
66

77
fn main() {
8-
let _ = foo("foo"); //<- Do not suggest `foo::<N>("foo");`!
8+
let _ = foo("foo");
99
//~^ ERROR: type annotations needed for `[usize; _]`
1010
}

0 commit comments

Comments
 (0)