1
Fork 0

Rollup merge of #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](https://github.com/rust-lang/rust/issues/83701)
  - [Stabilisation report](https://github.com/rust-lang/rust/issues/83701#issuecomment-1109949897)
  - [FCP entered](https://github.com/rust-lang/rust/issues/83701#issuecomment-1120285703)
* [implementation PR](https://github.com/rust-lang/rust/pull/86176)
* [Reference PR](https://github.com/rust-lang/reference/pull/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`
This commit is contained in:
Dylan DPC 2022-06-11 07:42:12 +02:00 committed by GitHub
commit f1f44b9e4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 32 additions and 222 deletions

View file

@ -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::<Vec<_>>();
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 });

View file

@ -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<Span>,
#[help]
pub is_nightly_build: Option<()>,
}
pub struct MissingTypeParams {
pub span: Span,
pub def_span: Span,