Skip to content

Commit 08f8fae

Browse files
committed
syntax: Rename some keywords
`CrateRoot` -> `PathRoot`, `::` doesn't necessarily mean crate root now `SelfValue` -> `SelfLower`, `SelfType` -> `SelfUpper`, both `self` and `Self` can be used in type and value namespaces now
1 parent 101467c commit 08f8fae

File tree

26 files changed

+83
-83
lines changed

26 files changed

+83
-83
lines changed

src/grammar/parser-lalr.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,14 +741,14 @@ fn_anon_params
741741
;
742742

743743
fn_params_with_self
744-
: '(' maybe_mut SELF maybe_ty_ascription maybe_comma_params ')' { $$ = mk_node("SelfValue", 3, $2, $4, $5); }
744+
: '(' maybe_mut SELF maybe_ty_ascription maybe_comma_params ')' { $$ = mk_node("SelfLower", 3, $2, $4, $5); }
745745
| '(' '&' maybe_mut SELF maybe_ty_ascription maybe_comma_params ')' { $$ = mk_node("SelfRegion", 3, $3, $5, $6); }
746746
| '(' '&' lifetime maybe_mut SELF maybe_ty_ascription maybe_comma_params ')' { $$ = mk_node("SelfRegion", 4, $3, $4, $6, $7); }
747747
| '(' maybe_params ')' { $$ = mk_node("SelfStatic", 1, $2); }
748748
;
749749

750750
fn_anon_params_with_self
751-
: '(' maybe_mut SELF maybe_ty_ascription maybe_comma_anon_params ')' { $$ = mk_node("SelfValue", 3, $2, $4, $5); }
751+
: '(' maybe_mut SELF maybe_ty_ascription maybe_comma_anon_params ')' { $$ = mk_node("SelfLower", 3, $2, $4, $5); }
752752
| '(' '&' maybe_mut SELF maybe_ty_ascription maybe_comma_anon_params ')' { $$ = mk_node("SelfRegion", 3, $3, $5, $6); }
753753
| '(' '&' lifetime maybe_mut SELF maybe_ty_ascription maybe_comma_anon_params ')' { $$ = mk_node("SelfRegion", 4, $3, $4, $6, $7); }
754754
| '(' maybe_anon_params ')' { $$ = mk_node("SelfStatic", 1, $2); }

src/librustc/hir/lowering.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ impl<'a> LoweringContext<'a> {
12011201
None,
12021202
P(hir::Path {
12031203
def: self.expect_full_def(t.id),
1204-
segments: hir_vec![hir::PathSegment::from_ident(keywords::SelfType.ident())],
1204+
segments: hir_vec![hir::PathSegment::from_ident(keywords::SelfUpper.ident())],
12051205
span: t.span,
12061206
}),
12071207
)),
@@ -2425,7 +2425,7 @@ impl<'a> LoweringContext<'a> {
24252425
// Don't expose `Self` (recovered "keyword used as ident" parse error).
24262426
// `rustc::ty` expects `Self` to be only used for a trait's `Self`.
24272427
// Instead, use gensym("Self") to create a distinct name that looks the same.
2428-
let ident = if param.ident.name == keywords::SelfType.name() {
2428+
let ident = if param.ident.name == keywords::SelfUpper.name() {
24292429
param.ident.gensym()
24302430
} else {
24312431
param.ident
@@ -2981,7 +2981,7 @@ impl<'a> LoweringContext<'a> {
29812981

29822982
// Correctly resolve `self` imports
29832983
if path.segments.len() > 1
2984-
&& path.segments.last().unwrap().ident.name == keywords::SelfValue.name()
2984+
&& path.segments.last().unwrap().ident.name == keywords::SelfLower.name()
29852985
{
29862986
let _ = path.segments.pop();
29872987
if rename.is_none() {

src/librustc/hir/map/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ impl<'hir> Map<'hir> {
475475

476476
pub fn ty_param_name(&self, id: NodeId) -> Name {
477477
match self.get(id) {
478-
Node::Item(&Item { node: ItemKind::Trait(..), .. }) => keywords::SelfType.name(),
478+
Node::Item(&Item { node: ItemKind::Trait(..), .. }) => keywords::SelfUpper.name(),
479479
Node::GenericParam(param) => param.name.ident().name,
480480
_ => bug!("ty_param_name: {} not a type parameter", self.node_to_string(id)),
481481
}

src/librustc/hir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ pub struct Path {
311311

312312
impl Path {
313313
pub fn is_global(&self) -> bool {
314-
!self.segments.is_empty() && self.segments[0].ident.name == keywords::CrateRoot.name()
314+
!self.segments.is_empty() && self.segments[0].ident.name == keywords::PathRoot.name()
315315
}
316316
}
317317

src/librustc/hir/print.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@ impl<'a> State<'a> {
16221622
if i > 0 {
16231623
self.s.word("::")?
16241624
}
1625-
if segment.ident.name != keywords::CrateRoot.name() &&
1625+
if segment.ident.name != keywords::PathRoot.name() &&
16261626
segment.ident.name != keywords::DollarCrate.name() {
16271627
self.print_ident(segment.ident)?;
16281628
segment.with_generic_args(|generic_args| {
@@ -1636,7 +1636,7 @@ impl<'a> State<'a> {
16361636
}
16371637

16381638
pub fn print_path_segment(&mut self, segment: &hir::PathSegment) -> io::Result<()> {
1639-
if segment.ident.name != keywords::CrateRoot.name() &&
1639+
if segment.ident.name != keywords::PathRoot.name() &&
16401640
segment.ident.name != keywords::DollarCrate.name() {
16411641
self.print_ident(segment.ident)?;
16421642
segment.with_generic_args(|generic_args| {
@@ -1664,7 +1664,7 @@ impl<'a> State<'a> {
16641664
if i > 0 {
16651665
self.s.word("::")?
16661666
}
1667-
if segment.ident.name != keywords::CrateRoot.name() &&
1667+
if segment.ident.name != keywords::PathRoot.name() &&
16681668
segment.ident.name != keywords::DollarCrate.name() {
16691669
self.print_ident(segment.ident)?;
16701670
segment.with_generic_args(|generic_args| {

src/librustc/middle/liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
15751575
let sp = ident.span;
15761576
let var = self.variable(hir_id, sp);
15771577
// Ignore unused self.
1578-
if ident.name != keywords::SelfValue.name() {
1578+
if ident.name != keywords::SelfLower.name() {
15791579
if !self.warn_about_unused(sp, hir_id, entry_ln, var) {
15801580
if self.live_on_entry(entry_ln, var).is_none() {
15811581
self.report_dead_assign(hir_id, sp, var, true);

src/librustc/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2710,7 +2710,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
27102710

27112711
#[inline]
27122712
pub fn mk_self_type(self) -> Ty<'tcx> {
2713-
self.mk_ty_param(0, keywords::SelfType.name().as_interned_str())
2713+
self.mk_ty_param(0, keywords::SelfUpper.name().as_interned_str())
27142714
}
27152715

27162716
pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> Kind<'tcx> {

src/librustc/ty/sty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ impl<'a, 'gcx, 'tcx> ParamTy {
10201020
}
10211021

10221022
pub fn for_self() -> ParamTy {
1023-
ParamTy::new(0, keywords::SelfType.name().as_interned_str())
1023+
ParamTy::new(0, keywords::SelfUpper.name().as_interned_str())
10241024
}
10251025

10261026
pub fn for_def(def: &ty::GenericParamDef) -> ParamTy {
@@ -1035,7 +1035,7 @@ impl<'a, 'gcx, 'tcx> ParamTy {
10351035
// FIXME(#50125): Ignoring `Self` with `idx != 0` might lead to weird behavior elsewhere,
10361036
// but this should only be possible when using `-Z continue-parse-after-error` like
10371037
// `compile-fail/issue-36638.rs`.
1038-
self.name == keywords::SelfType.name().as_str() && self.idx == 0
1038+
self.name == keywords::SelfUpper.name().as_str() && self.idx == 0
10391039
}
10401040
}
10411041

src/librustc_lint/unused.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ impl UnusedImportBraces {
473473
match items[0].0.kind {
474474
ast::UseTreeKind::Simple(rename, ..) => {
475475
let orig_ident = items[0].0.prefix.segments.last().unwrap().ident;
476-
if orig_ident.name == keywords::SelfValue.name() {
476+
if orig_ident.name == keywords::SelfLower.name() {
477477
return;
478478
}
479479
node_ident = rename.unwrap_or(orig_ident);

src/librustc_mir/borrow_check/mutability_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
263263
// Deliberately fall into this case for all implicit self types,
264264
// so that we don't fall in to the next case with them.
265265
*kind == mir::ImplicitSelfKind::MutRef
266-
} else if Some(keywords::SelfValue.name()) == local_decl.name {
266+
} else if Some(keywords::SelfLower.name()) == local_decl.name {
267267
// Otherwise, check if the name is the self kewyord - in which case
268268
// we have an explicit self. Do the same thing in this case and check
269269
// for a `self: &mut Self` to suggest removing the `&mut`.

0 commit comments

Comments
 (0)