about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2021-11-18 13:25:27 +0800
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2021-11-18 14:32:29 +0800
commit91e02177a1f41aa4f3260fef40caef1fdaf3cc20 (patch)
treeb8fb248ea69ebf05437613542bea6ee745b8454d
parent6414e0b5b308d3ae27da83c6a25098cc8aadc1a9 (diff)
downloadrust-91e02177a1f41aa4f3260fef40caef1fdaf3cc20.tar.gz
rust-91e02177a1f41aa4f3260fef40caef1fdaf3cc20.zip
rustc: Remove `#[rustc_synthetic]`
This function parameter attribute was introduced in https://github.com/rust-lang/rust/pull/44866 as an intermediate step in implementing `impl Trait`, it's not necessary or used anywhere by itself.
-rw-r--r--compiler/rustc_ast_lowering/src/lib.rs12
-rw-r--r--compiler/rustc_feature/src/builtin_attrs.rs1
-rw-r--r--compiler/rustc_hir/src/hir.rs12
-rw-r--r--compiler/rustc_middle/src/ty/generics.rs21
-rw-r--r--compiler/rustc_resolve/src/late/diagnostics.rs20
-rw-r--r--compiler/rustc_span/src/symbol.rs1
-rw-r--r--compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs7
-rw-r--r--compiler/rustc_typeck/src/astconv/generics.rs11
-rw-r--r--compiler/rustc_typeck/src/check/compare_method.rs14
-rw-r--r--compiler/rustc_typeck/src/check/expr.rs2
-rw-r--r--compiler/rustc_typeck/src/check/method/suggest.rs2
-rw-r--r--compiler/rustc_typeck/src/collect.rs6
-rw-r--r--src/librustdoc/clean/mod.rs6
-rw-r--r--src/librustdoc/clean/types.rs19
-rw-r--r--src/test/ui/synthetic-param.rs28
-rw-r--r--src/test/ui/synthetic-param.stderr30
-rw-r--r--src/tools/clippy/clippy_lints/src/types/borrowed_box.rs8
17 files changed, 37 insertions, 163 deletions
diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs
index 79464a75172..fef6e87bfdb 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 7212bbf38c7..74a637fde33 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 e00c5789fe9..a4db57bfc11 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<SyntheticTyParamKind>,
+        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 0f89581ae66..f53f1871508 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<hir::SyntheticTyParamKind>,
-    },
-    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 4acbb11b13f..d506931b516 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 99fa9f00094..9992b1f31fe 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 0bf01afb575..1ff31ff04a2 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 2f187997b55..e8bd038fed7 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 cbfd8747ecf..ef7c7096015 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 5c79a067e9f..c9fa0fd72fc 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(&param, 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 661ced952c7..655e99369d2 100644
--- a/compiler/rustc_typeck/src/check/method/suggest.rs
+++ b/compiler/rustc_typeck/src/check/method/suggest.rs
@@ -1490,7 +1490,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, .. } =
                                     &param.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 2f427305782..209690ec5fc 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 70401065689..26a67ce9f9d 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -456,9 +456,7 @@ impl Clean<Generics> 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,
             }
         }
@@ -557,7 +555,7 @@ impl<'a, 'tcx> Clean<Generics> 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 2dba52afcd9..fb08ced205d 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<Lifetime>,
-    },
-    Type {
-        did: DefId,
-        bounds: Vec<GenericBound>,
-        default: Option<Box<Type>>,
-        synthetic: Option<hir::SyntheticTyParamKind>,
-    },
-    Const {
-        did: DefId,
-        ty: Box<Type>,
-        default: Option<Box<String>>,
-    },
+    Lifetime { outlives: Vec<Lifetime> },
+    Type { did: DefId, bounds: Vec<GenericBound>, default: Option<Box<Type>>, synthetic: bool },
+    Const { did: DefId, ty: Box<Type>, default: Option<Box<String>> },
 }
 
 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 e14697f5c3e..00000000000
--- 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<S> {
-    t: S
-}
-
-impl<S> Bar<S> {
-    pub fn func<#[rustc_synthetic] T>(_: T) {}
-}
-
-fn main() {
-    func::<u8>(42); //~ ERROR cannot provide explicit generic arguments
-    func(42); // Ok
-
-    Foo::func::<u8>(42); //~ ERROR cannot provide explicit generic arguments
-    Foo::func(42); // Ok
-
-    Bar::<i8>::func::<u8>(42); //~ ERROR cannot provide explicit generic arguments
-    Bar::<i8>::func(42); // Ok
-}
diff --git a/src/test/ui/synthetic-param.stderr b/src/test/ui/synthetic-param.stderr
deleted file mode 100644
index 5cb9ad31fbf..00000000000
--- 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::<u8>(42);
-   |            ^^ explicit generic argument not allowed
-   |
-   = note: see issue #83701 <https://github.com/rust-lang/rust/issues/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::<u8>(42);
-   |                 ^^ explicit generic argument not allowed
-   |
-   = note: see issue #83701 <https://github.com/rust-lang/rust/issues/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::<i8>::func::<u8>(42);
-   |                       ^^ explicit generic argument not allowed
-   |
-   = note: see issue #83701 <https://github.com/rust-lang/rust/issues/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 bdeff035e5e..63ad65b8afd 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 {