]> git.lizzy.rs Git - rust.git/commitdiff
Don't gensym `Self` parameters
authorMatthew Jasper <mjjasper1@gmail.com>
Sun, 7 Jul 2019 15:38:49 +0000 (16:38 +0100)
committerMatthew Jasper <mjjasper1@gmail.com>
Sun, 11 Aug 2019 14:00:42 +0000 (15:00 +0100)
src/librustc/hir/lowering.rs
src/librustc_typeck/collect.rs

index 591ceaf28a6c6f2aca017e717e2624015d84a1fc..cc213cfccd40a717353ce41b0cf87ca5893dd946 100644 (file)
@@ -2886,15 +2886,6 @@ fn lower_generic_param(&mut self,
                 (param_name, kind)
             }
             GenericParamKind::Type { ref default, .. } => {
-                // Don't expose `Self` (recovered "keyword used as ident" parse error).
-                // `rustc::ty` expects `Self` to be only used for a trait's `Self`.
-                // Instead, use `gensym("Self")` to create a distinct name that looks the same.
-                let ident = if param.ident.name == kw::SelfUpper {
-                    param.ident.gensym()
-                } else {
-                    param.ident
-                };
-
                 let add_bounds = add_bounds.get(&param.id).map_or(&[][..], |x| &x);
                 if !add_bounds.is_empty() {
                     let params = self.lower_param_bounds(add_bounds, itctx.reborrow()).into_iter();
@@ -2913,7 +2904,7 @@ fn lower_generic_param(&mut self,
                                           .next(),
                 };
 
-                (hir::ParamName::Plain(ident), kind)
+                (hir::ParamName::Plain(param.ident), kind)
             }
             GenericParamKind::Const { ref ty } => {
                 (hir::ParamName::Plain(param.ident), hir::GenericParamKind::Const {
index 0f0568907c64679e4b3dcd3f295cb63b746cf108..7010664722d510967969e5ddadf4b7e4d0f371cb 100644 (file)
@@ -1011,13 +1011,6 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::Generics {
                         synthetic,
                         ..
                     } => {
-                        if param.name.ident().name == kw::SelfUpper {
-                            span_bug!(
-                                param.span,
-                                "`Self` should not be the name of a regular parameter"
-                            );
-                        }
-
                         if !allow_defaults && default.is_some() {
                             if !tcx.features().default_type_parameter_fallback {
                                 tcx.lint_hir(
@@ -1041,13 +1034,6 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::Generics {
                         }
                     }
                     GenericParamKind::Const { .. } => {
-                        if param.name.ident().name == kw::SelfUpper {
-                            span_bug!(
-                                param.span,
-                                "`Self` should not be the name of a regular parameter",
-                            );
-                        }
-
                         ty::GenericParamDefKind::Const
                     }
                     _ => return None,
@@ -1569,7 +1555,7 @@ fn check(&mut self, def_id: DefId) {
                                     &format!(
                                         "defining opaque type use restricts opaque \
                                          type by using the generic parameter `{}` twice",
-                                        p.name
+                                        p,
                                     ),
                                 );
                                 return;