diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index cd468bcf4474e..2b3a538772ecb 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1338,10 +1338,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { pure_wrt_drop: false, bounds: hir_bounds, span: self.lower_span(span), - kind: hir::GenericParamKind::Type { - default: None, - synthetic: Some(hir::SyntheticTyParamKind::ImplTrait), - }, + kind: hir::GenericParamKind::Type { default: None, synthetic: true }, }); hir::TyKind::Path(hir::QPath::Resolved( @@ -1954,12 +1951,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { default: default.as_ref().map(|x| { self.lower_ty(x, ImplTraitContext::Disallowed(ImplTraitPosition::Other)) }), - synthetic: param - .attrs - .iter() - .filter(|attr| attr.has_name(sym::rustc_synthetic)) - .map(|_| hir::SyntheticTyParamKind::FromAttr) - .next(), + synthetic: false, }; (hir::ParamName::Plain(self.lower_ident(param.ident)), kind) diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 7212bbf38c7f2..74a637fde33fc 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -601,7 +601,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ TEST, rustc_expected_cgu_reuse, Normal, template!(List: r#"cfg = "...", module = "...", kind = "...""#), ), - rustc_attr!(TEST, rustc_synthetic, Normal, template!(Word)), rustc_attr!(TEST, rustc_symbol_name, Normal, template!(Word)), rustc_attr!(TEST, rustc_polymorphize_error, Normal, template!(Word)), rustc_attr!(TEST, rustc_def_path, Normal, template!(Word)), diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index e00c5789fe9c7..a4db57bfc1120 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -504,7 +504,7 @@ pub enum GenericParamKind<'hir> { }, Type { default: Option<&'hir Ty<'hir>>, - synthetic: Option, + synthetic: bool, }, Const { ty: &'hir Ty<'hir>, @@ -577,16 +577,6 @@ impl Generics<'hir> { } } -/// Synthetic type parameters are converted to another form during lowering; this allows -/// us to track the original form they had, and is useful for error messages. -#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, Debug)] -#[derive(HashStable_Generic)] -pub enum SyntheticTyParamKind { - ImplTrait, - // Created by the `#[rustc_synthetic]` attribute. - FromAttr, -} - /// A where-clause in a definition. #[derive(Debug, HashStable_Generic)] pub struct WhereClause<'hir> { diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs index 0f89581ae669c..f53f1871508d7 100644 --- a/compiler/rustc_middle/src/ty/generics.rs +++ b/compiler/rustc_middle/src/ty/generics.rs @@ -3,7 +3,6 @@ use crate::ty; use crate::ty::subst::{Subst, SubstsRef}; use rustc_ast as ast; use rustc_data_structures::fx::FxHashMap; -use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_span::symbol::Symbol; use rustc_span::Span; @@ -13,14 +12,8 @@ use super::{EarlyBoundRegion, InstantiatedPredicates, ParamConst, ParamTy, Predi #[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)] pub enum GenericParamDefKind { Lifetime, - Type { - has_default: bool, - object_lifetime_default: ObjectLifetimeDefault, - synthetic: Option, - }, - Const { - has_default: bool, - }, + Type { has_default: bool, object_lifetime_default: ObjectLifetimeDefault, synthetic: bool }, + Const { has_default: bool }, } impl GenericParamDefKind { @@ -202,15 +195,7 @@ impl<'tcx> Generics { /// Returns `true` if `params` has `impl Trait`. pub fn has_impl_trait(&'tcx self) -> bool { self.params.iter().any(|param| { - matches!( - param.kind, - ty::GenericParamDefKind::Type { - synthetic: Some( - hir::SyntheticTyParamKind::ImplTrait | hir::SyntheticTyParamKind::FromAttr, - ), - .. - } - ) + matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. }) }) } } diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 4acbb11b13f76..d506931b516e7 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1810,12 +1810,10 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { let (span, sugg) = if let Some(param) = generics.params.iter().find(|p| { !matches!( p.kind, - hir::GenericParamKind::Type { - synthetic: Some(hir::SyntheticTyParamKind::ImplTrait), - .. - } | hir::GenericParamKind::Lifetime { - kind: hir::LifetimeParamKind::Elided, - } + hir::GenericParamKind::Type { synthetic: true, .. } + | hir::GenericParamKind::Lifetime { + kind: hir::LifetimeParamKind::Elided, + } ) }) { (param.span.shrink_to_lo(), format!("{}, ", lifetime_ref)) @@ -2042,12 +2040,10 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { if let Some(param) = generics.params.iter().find(|p| { !matches!( p.kind, - hir::GenericParamKind::Type { - synthetic: Some(hir::SyntheticTyParamKind::ImplTrait), - .. - } | hir::GenericParamKind::Lifetime { - kind: hir::LifetimeParamKind::Elided - } + hir::GenericParamKind::Type { synthetic: true, .. } + | hir::GenericParamKind::Lifetime { + kind: hir::LifetimeParamKind::Elided + } ) }) { (param.span.shrink_to_lo(), "'a, ".to_string()) diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 99fa9f000944d..9992b1f31fefc 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1148,7 +1148,6 @@ symbols! { rustc_std_internal_symbol, rustc_strict_coherence, rustc_symbol_name, - rustc_synthetic, rustc_test_marker, rustc_then_this_would_need, rustc_trivial_field_reads, diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 0bf01afb575da..1ff31ff04a2b6 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -290,9 +290,10 @@ fn suggest_restriction( } else { // Trivial case: `T` needs an extra bound: `T: Bound`. let (sp, suggestion) = match ( - generics.params.iter().find(|p| { - !matches!(p.kind, hir::GenericParamKind::Type { synthetic: Some(_), .. }) - }), + generics + .params + .iter() + .find(|p| !matches!(p.kind, hir::GenericParamKind::Type { synthetic: true, .. })), super_traits, ) { (_, None) => predicate_constraint( diff --git a/compiler/rustc_typeck/src/astconv/generics.rs b/compiler/rustc_typeck/src/astconv/generics.rs index 2f187997b55de..e8bd038fed7a5 100644 --- a/compiler/rustc_typeck/src/astconv/generics.rs +++ b/compiler/rustc_typeck/src/astconv/generics.rs @@ -464,16 +464,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .params .iter() .filter(|param| { - matches!( - param.kind, - ty::GenericParamDefKind::Type { - synthetic: Some( - hir::SyntheticTyParamKind::ImplTrait - | hir::SyntheticTyParamKind::FromAttr - ), - .. - } - ) + matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. }) }) .count() } else { diff --git a/compiler/rustc_typeck/src/check/compare_method.rs b/compiler/rustc_typeck/src/check/compare_method.rs index cbfd8747ecf00..ef7c70960151d 100644 --- a/compiler/rustc_typeck/src/check/compare_method.rs +++ b/compiler/rustc_typeck/src/check/compare_method.rs @@ -607,10 +607,7 @@ fn compare_number_of_generics<'tcx>( .params .iter() .filter_map(|p| match p.kind { - GenericParamKind::Type { - synthetic: Some(hir::SyntheticTyParamKind::ImplTrait), - .. - } => Some(p.span), + GenericParamKind::Type { synthetic: true, .. } => Some(p.span), _ => None, }) .collect(); @@ -627,10 +624,7 @@ fn compare_number_of_generics<'tcx>( .params .iter() .filter_map(|p| match p.kind { - GenericParamKind::Type { - synthetic: Some(hir::SyntheticTyParamKind::ImplTrait), - .. - } => Some(p.span), + GenericParamKind::Type { synthetic: true, .. } => Some(p.span), _ => None, }) .collect(); @@ -823,7 +817,7 @@ fn compare_synthetic_generics<'tcx>( match (impl_synthetic, trait_synthetic) { // The case where the impl method uses `impl Trait` but the trait method uses // explicit generics - (Some(hir::SyntheticTyParamKind::ImplTrait), None) => { + (true, false) => { err.span_label(impl_span, "expected generic parameter, found `impl Trait`"); (|| { // try taking the name from the trait impl @@ -864,7 +858,7 @@ fn compare_synthetic_generics<'tcx>( } // The case where the trait method uses `impl Trait`, but the impl method uses // explicit generics. - (None, Some(hir::SyntheticTyParamKind::ImplTrait)) => { + (false, true) => { err.span_label(impl_span, "expected `impl Trait`, found generic parameter"); (|| { let impl_m = impl_m.def_id.as_local()?; diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 5c79a067e9f04..c9fa0fd72fc50 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -2025,7 +2025,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn point_at_param_definition(&self, err: &mut DiagnosticBuilder<'_>, param: ty::ParamTy) { let generics = self.tcx.generics_of(self.body_id.owner.to_def_id()); let generic_param = generics.type_param(¶m, self.tcx); - if let ty::GenericParamDefKind::Type { synthetic: Some(..), .. } = generic_param.kind { + if let ty::GenericParamDefKind::Type { synthetic: true, .. } = generic_param.kind { return; } let param_def_id = generic_param.def_id; diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index f96e9063c345c..6411c062feaf6 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -1494,7 +1494,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Node::GenericParam(param) => { let mut impl_trait = false; let has_bounds = - if let hir::GenericParamKind::Type { synthetic: Some(_), .. } = + if let hir::GenericParamKind::Type { synthetic: true, .. } = ¶m.kind { // We've found `fn foo(x: impl Trait)` instead of diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 2f427305782c5..209690ec5fc9a 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -1543,7 +1543,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics { kind: ty::GenericParamDefKind::Type { has_default: false, object_lifetime_default: rl::Set1::Empty, - synthetic: None, + synthetic: false, }, }); @@ -1673,7 +1673,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics { kind: ty::GenericParamDefKind::Type { has_default: false, object_lifetime_default: rl::Set1::Empty, - synthetic: None, + synthetic: false, }, })); } @@ -1690,7 +1690,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics { kind: ty::GenericParamDefKind::Type { has_default: false, object_lifetime_default: rl::Set1::Empty, - synthetic: None, + synthetic: false, }, }); } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 5ca532198f471..959dc5453374d 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -459,9 +459,7 @@ impl Clean for hir::Generics<'_> { // scans them first. fn is_impl_trait(param: &hir::GenericParam<'_>) -> bool { match param.kind { - hir::GenericParamKind::Type { synthetic, .. } => { - synthetic == Some(hir::SyntheticTyParamKind::ImplTrait) - } + hir::GenericParamKind::Type { synthetic, .. } => synthetic, _ => false, } } @@ -560,7 +558,7 @@ impl<'a, 'tcx> Clean for (&'a ty::Generics, ty::GenericPredicates<'tcx assert_eq!(param.index, 0); return None; } - if synthetic == Some(hir::SyntheticTyParamKind::ImplTrait) { + if synthetic { impl_trait.insert(param.index.into(), vec![]); return None; } diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 2dba52afcd9cd..fb08ced205d86 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1238,20 +1238,9 @@ impl WherePredicate { #[derive(Clone, PartialEq, Eq, Debug, Hash)] crate enum GenericParamDefKind { - Lifetime { - outlives: Vec, - }, - Type { - did: DefId, - bounds: Vec, - default: Option>, - synthetic: Option, - }, - Const { - did: DefId, - ty: Box, - default: Option>, - }, + Lifetime { outlives: Vec }, + Type { did: DefId, bounds: Vec, default: Option>, synthetic: bool }, + Const { did: DefId, ty: Box, default: Option> }, } impl GenericParamDefKind { @@ -1285,7 +1274,7 @@ impl GenericParamDef { crate fn is_synthetic_type_param(&self) -> bool { match self.kind { GenericParamDefKind::Lifetime { .. } | GenericParamDefKind::Const { .. } => false, - GenericParamDefKind::Type { ref synthetic, .. } => synthetic.is_some(), + GenericParamDefKind::Type { synthetic, .. } => synthetic, } } diff --git a/src/test/ui/synthetic-param.rs b/src/test/ui/synthetic-param.rs deleted file mode 100644 index e14697f5c3e97..0000000000000 --- a/src/test/ui/synthetic-param.rs +++ /dev/null @@ -1,28 +0,0 @@ -#![feature(rustc_attrs)] - -fn func<#[rustc_synthetic] T>(_: T) {} - -struct Foo; - -impl Foo { - pub fn func<#[rustc_synthetic] T>(_: T) {} -} - -struct Bar { - t: S -} - -impl Bar { - pub fn func<#[rustc_synthetic] T>(_: T) {} -} - -fn main() { - func::(42); //~ ERROR cannot provide explicit generic arguments - func(42); // Ok - - Foo::func::(42); //~ ERROR cannot provide explicit generic arguments - Foo::func(42); // Ok - - Bar::::func::(42); //~ ERROR cannot provide explicit generic arguments - Bar::::func(42); // Ok -} diff --git a/src/test/ui/synthetic-param.stderr b/src/test/ui/synthetic-param.stderr deleted file mode 100644 index 5cb9ad31fbfcc..0000000000000 --- a/src/test/ui/synthetic-param.stderr +++ /dev/null @@ -1,30 +0,0 @@ -error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position - --> $DIR/synthetic-param.rs:20:12 - | -LL | func::(42); - | ^^ 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[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position - --> $DIR/synthetic-param.rs:23:17 - | -LL | Foo::func::(42); - | ^^ 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[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position - --> $DIR/synthetic-param.rs:26:23 - | -LL | Bar::::func::(42); - | ^^ 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 3 previous errors - -For more information about this error, try `rustc --explain E0632`. diff --git a/src/tools/clippy/clippy_lints/src/types/borrowed_box.rs b/src/tools/clippy/clippy_lints/src/types/borrowed_box.rs index bdeff035e5ec9..63ad65b8afd9f 100644 --- a/src/tools/clippy/clippy_lints/src/types/borrowed_box.rs +++ b/src/tools/clippy/clippy_lints/src/types/borrowed_box.rs @@ -3,10 +3,8 @@ use clippy_utils::source::snippet; use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::{ - self as hir, GenericArg, GenericBounds, GenericParamKind, HirId, Lifetime, MutTy, Mutability, Node, QPath, - SyntheticTyParamKind, TyKind, -}; +use rustc_hir::{self as hir, GenericArg, GenericBounds, GenericParamKind}; +use rustc_hir::{HirId, Lifetime, MutTy, Mutability, Node, QPath, TyKind}; use rustc_lint::LateContext; use super::BORROWED_BOX; @@ -105,7 +103,7 @@ fn get_bounds_if_impl_trait<'tcx>(cx: &LateContext<'tcx>, qpath: &QPath<'_>, id: if let Some(did) = cx.qpath_res(qpath, id).opt_def_id(); if let Some(Node::GenericParam(generic_param)) = cx.tcx.hir().get_if_local(did); if let GenericParamKind::Type { synthetic, .. } = generic_param.kind; - if synthetic == Some(SyntheticTyParamKind::ImplTrait); + if synthetic; then { Some(generic_param.bounds) } else {