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

Diff for: src/grammar/parser-lalr.y

+2-2
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); }

Diff for: src/librustc/hir/lowering.rs

+3-3
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() {

Diff for: src/librustc/hir/map/mod.rs

+1-1
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
}

Diff for: src/librustc/hir/mod.rs

+1-1
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

Diff for: src/librustc/hir/print.rs

+3-3
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| {

Diff for: src/librustc/middle/liveness.rs

+1-1
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);

Diff for: src/librustc/ty/context.rs

+1-1
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> {

Diff for: src/librustc/ty/sty.rs

+2-2
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

Diff for: src/librustc_lint/unused.rs

+1-1
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);

Diff for: src/librustc_mir/borrow_check/mutability_errors.rs

+1-1
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`.

Diff for: src/librustc_resolve/build_reduced_graph.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
145145
}
146146
_ => None,
147147
}.map(|ctxt| Segment::from_ident(Ident::new(
148-
keywords::CrateRoot.name(), use_tree.prefix.span.shrink_to_lo().with_ctxt(ctxt)
148+
keywords::PathRoot.name(), use_tree.prefix.span.shrink_to_lo().with_ctxt(ctxt)
149149
)));
150150

151151
let prefix = crate_root.into_iter().chain(prefix_iter).collect::<Vec<_>>();
152152
debug!("build_reduced_graph_for_use_tree: prefix={:?}", prefix);
153153

154154
let empty_for_self = |prefix: &[Segment]| {
155155
prefix.is_empty() ||
156-
prefix.len() == 1 && prefix[0].ident.name == keywords::CrateRoot.name()
156+
prefix.len() == 1 && prefix[0].ident.name == keywords::PathRoot.name()
157157
};
158158
match use_tree.kind {
159159
ast::UseTreeKind::Simple(rename, ..) => {
@@ -164,7 +164,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
164164

165165
if nested {
166166
// Correctly handle `self`
167-
if source.ident.name == keywords::SelfValue.name() {
167+
if source.ident.name == keywords::SelfLower.name() {
168168
type_ns_only = true;
169169

170170
if empty_for_self(&module_path) {
@@ -185,7 +185,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
185185
}
186186
} else {
187187
// Disallow `self`
188-
if source.ident.name == keywords::SelfValue.name() {
188+
if source.ident.name == keywords::SelfLower.name() {
189189
resolve_error(self,
190190
use_tree.span,
191191
ResolutionError::SelfImportsOnlyAllowedWithin);
@@ -205,7 +205,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
205205
// `crate_name` should not be interpreted as relative.
206206
module_path.push(Segment {
207207
ident: Ident {
208-
name: keywords::CrateRoot.name(),
208+
name: keywords::PathRoot.name(),
209209
span: source.ident.span,
210210
},
211211
id: Some(self.session.next_node_id()),
@@ -270,7 +270,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
270270
// Ensure there is at most one `self` in the list
271271
let self_spans = items.iter().filter_map(|&(ref use_tree, _)| {
272272
if let ast::UseTreeKind::Simple(..) = use_tree.kind {
273-
if use_tree.ident().name == keywords::SelfValue.name() {
273+
if use_tree.ident().name == keywords::SelfLower.name() {
274274
return Some(use_tree.span);
275275
}
276276
}
@@ -305,7 +305,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
305305
let new_span = prefix[prefix.len() - 1].ident.span;
306306
let tree = ast::UseTree {
307307
prefix: ast::Path::from_ident(
308-
Ident::new(keywords::SelfValue.name(), new_span)
308+
Ident::new(keywords::SelfLower.name(), new_span)
309309
),
310310
kind: ast::UseTreeKind::Simple(
311311
Some(Ident::new(keywords::Underscore.name().gensymed(), new_span)),
@@ -344,13 +344,13 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
344344
}
345345

346346
ItemKind::ExternCrate(orig_name) => {
347-
let module = if orig_name.is_none() && ident.name == keywords::SelfValue.name() {
347+
let module = if orig_name.is_none() && ident.name == keywords::SelfLower.name() {
348348
self.session
349349
.struct_span_err(item.span, "`extern crate self;` requires renaming")
350350
.span_suggestion(item.span, "try", "extern crate self as name;".into())
351351
.emit();
352352
return;
353-
} else if orig_name == Some(keywords::SelfValue.name()) {
353+
} else if orig_name == Some(keywords::SelfLower.name()) {
354354
if !self.session.features_untracked().extern_crate_self {
355355
emit_feature_err(&self.session.parse_sess, "extern_crate_self", item.span,
356356
GateIssue::Language, "`extern crate self` is unstable");
@@ -783,7 +783,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
783783
"an `extern crate` loading macros must be at the crate root");
784784
}
785785
if let ItemKind::ExternCrate(Some(orig_name)) = item.node {
786-
if orig_name == keywords::SelfValue.name() {
786+
if orig_name == keywords::SelfLower.name() {
787787
self.session.span_err(attr.span,
788788
"`macro_use` is not supported on `extern crate self`");
789789
}

Diff for: src/librustc_resolve/error_reporting.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
3030
match (path.get(0), path.get(1)) {
3131
// `{{root}}::ident::...` on both editions.
3232
// On 2015 `{{root}}` is usually added implicitly.
33-
(Some(fst), Some(snd)) if fst.ident.name == keywords::CrateRoot.name() &&
33+
(Some(fst), Some(snd)) if fst.ident.name == keywords::PathRoot.name() &&
3434
!snd.ident.is_path_segment_keyword() => {}
3535
// `ident::...` on 2018
3636
(Some(fst), _) if fst.ident.span.rust_2018() &&
@@ -61,7 +61,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
6161
parent_scope: &ParentScope<'b>,
6262
) -> Option<(Vec<Segment>, Option<String>)> {
6363
// Replace first ident with `self` and check if that is valid.
64-
path[0].ident.name = keywords::SelfValue.name();
64+
path[0].ident.name = keywords::SelfLower.name();
6565
let result = self.resolve_path(&path, None, parent_scope, false, span, CrateLint::No);
6666
debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result);
6767
if let PathResult::Module(..) = result {

0 commit comments

Comments
 (0)