Skip to content

Commit

Permalink
syntax: Rename some keywords
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
petrochenkov committed Dec 3, 2018
1 parent 101467c commit 08f8fae
Show file tree
Hide file tree
Showing 26 changed files with 83 additions and 83 deletions.
4 changes: 2 additions & 2 deletions src/grammar/parser-lalr.y
Expand Up @@ -741,14 +741,14 @@ fn_anon_params
;

fn_params_with_self
: '(' maybe_mut SELF maybe_ty_ascription maybe_comma_params ')' { $$ = mk_node("SelfValue", 3, $2, $4, $5); }
: '(' maybe_mut SELF maybe_ty_ascription maybe_comma_params ')' { $$ = mk_node("SelfLower", 3, $2, $4, $5); }
| '(' '&' maybe_mut SELF maybe_ty_ascription maybe_comma_params ')' { $$ = mk_node("SelfRegion", 3, $3, $5, $6); }
| '(' '&' lifetime maybe_mut SELF maybe_ty_ascription maybe_comma_params ')' { $$ = mk_node("SelfRegion", 4, $3, $4, $6, $7); }
| '(' maybe_params ')' { $$ = mk_node("SelfStatic", 1, $2); }
;

fn_anon_params_with_self
: '(' maybe_mut SELF maybe_ty_ascription maybe_comma_anon_params ')' { $$ = mk_node("SelfValue", 3, $2, $4, $5); }
: '(' maybe_mut SELF maybe_ty_ascription maybe_comma_anon_params ')' { $$ = mk_node("SelfLower", 3, $2, $4, $5); }
| '(' '&' maybe_mut SELF maybe_ty_ascription maybe_comma_anon_params ')' { $$ = mk_node("SelfRegion", 3, $3, $5, $6); }
| '(' '&' lifetime maybe_mut SELF maybe_ty_ascription maybe_comma_anon_params ')' { $$ = mk_node("SelfRegion", 4, $3, $4, $6, $7); }
| '(' maybe_anon_params ')' { $$ = mk_node("SelfStatic", 1, $2); }
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/hir/lowering.rs
Expand Up @@ -1201,7 +1201,7 @@ impl<'a> LoweringContext<'a> {
None,
P(hir::Path {
def: self.expect_full_def(t.id),
segments: hir_vec![hir::PathSegment::from_ident(keywords::SelfType.ident())],
segments: hir_vec![hir::PathSegment::from_ident(keywords::SelfUpper.ident())],
span: t.span,
}),
)),
Expand Down Expand Up @@ -2425,7 +2425,7 @@ impl<'a> LoweringContext<'a> {
// 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 == keywords::SelfType.name() {
let ident = if param.ident.name == keywords::SelfUpper.name() {
param.ident.gensym()
} else {
param.ident
Expand Down Expand Up @@ -2981,7 +2981,7 @@ impl<'a> LoweringContext<'a> {

// Correctly resolve `self` imports
if path.segments.len() > 1
&& path.segments.last().unwrap().ident.name == keywords::SelfValue.name()
&& path.segments.last().unwrap().ident.name == keywords::SelfLower.name()
{
let _ = path.segments.pop();
if rename.is_none() {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/mod.rs
Expand Up @@ -475,7 +475,7 @@ impl<'hir> Map<'hir> {

pub fn ty_param_name(&self, id: NodeId) -> Name {
match self.get(id) {
Node::Item(&Item { node: ItemKind::Trait(..), .. }) => keywords::SelfType.name(),
Node::Item(&Item { node: ItemKind::Trait(..), .. }) => keywords::SelfUpper.name(),
Node::GenericParam(param) => param.name.ident().name,
_ => bug!("ty_param_name: {} not a type parameter", self.node_to_string(id)),
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/mod.rs
Expand Up @@ -311,7 +311,7 @@ pub struct Path {

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

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/hir/print.rs
Expand Up @@ -1622,7 +1622,7 @@ impl<'a> State<'a> {
if i > 0 {
self.s.word("::")?
}
if segment.ident.name != keywords::CrateRoot.name() &&
if segment.ident.name != keywords::PathRoot.name() &&
segment.ident.name != keywords::DollarCrate.name() {
self.print_ident(segment.ident)?;
segment.with_generic_args(|generic_args| {
Expand All @@ -1636,7 +1636,7 @@ impl<'a> State<'a> {
}

pub fn print_path_segment(&mut self, segment: &hir::PathSegment) -> io::Result<()> {
if segment.ident.name != keywords::CrateRoot.name() &&
if segment.ident.name != keywords::PathRoot.name() &&
segment.ident.name != keywords::DollarCrate.name() {
self.print_ident(segment.ident)?;
segment.with_generic_args(|generic_args| {
Expand Down Expand Up @@ -1664,7 +1664,7 @@ impl<'a> State<'a> {
if i > 0 {
self.s.word("::")?
}
if segment.ident.name != keywords::CrateRoot.name() &&
if segment.ident.name != keywords::PathRoot.name() &&
segment.ident.name != keywords::DollarCrate.name() {
self.print_ident(segment.ident)?;
segment.with_generic_args(|generic_args| {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/liveness.rs
Expand Up @@ -1575,7 +1575,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
let sp = ident.span;
let var = self.variable(hir_id, sp);
// Ignore unused self.
if ident.name != keywords::SelfValue.name() {
if ident.name != keywords::SelfLower.name() {
if !self.warn_about_unused(sp, hir_id, entry_ln, var) {
if self.live_on_entry(entry_ln, var).is_none() {
self.report_dead_assign(hir_id, sp, var, true);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/context.rs
Expand Up @@ -2710,7 +2710,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

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

pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> Kind<'tcx> {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/sty.rs
Expand Up @@ -1020,7 +1020,7 @@ impl<'a, 'gcx, 'tcx> ParamTy {
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/unused.rs
Expand Up @@ -473,7 +473,7 @@ impl UnusedImportBraces {
match items[0].0.kind {
ast::UseTreeKind::Simple(rename, ..) => {
let orig_ident = items[0].0.prefix.segments.last().unwrap().ident;
if orig_ident.name == keywords::SelfValue.name() {
if orig_ident.name == keywords::SelfLower.name() {
return;
}
node_ident = rename.unwrap_or(orig_ident);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/mutability_errors.rs
Expand Up @@ -263,7 +263,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
// Deliberately fall into this case for all implicit self types,
// so that we don't fall in to the next case with them.
*kind == mir::ImplicitSelfKind::MutRef
} else if Some(keywords::SelfValue.name()) == local_decl.name {
} else if Some(keywords::SelfLower.name()) == local_decl.name {
// Otherwise, check if the name is the self kewyord - in which case
// we have an explicit self. Do the same thing in this case and check
// for a `self: &mut Self` to suggest removing the `&mut`.
Expand Down
20 changes: 10 additions & 10 deletions src/librustc_resolve/build_reduced_graph.rs
Expand Up @@ -145,15 +145,15 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
}
_ => None,
}.map(|ctxt| Segment::from_ident(Ident::new(
keywords::CrateRoot.name(), use_tree.prefix.span.shrink_to_lo().with_ctxt(ctxt)
keywords::PathRoot.name(), use_tree.prefix.span.shrink_to_lo().with_ctxt(ctxt)
)));

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

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

if nested {
// Correctly handle `self`
if source.ident.name == keywords::SelfValue.name() {
if source.ident.name == keywords::SelfLower.name() {
type_ns_only = true;

if empty_for_self(&module_path) {
Expand All @@ -185,7 +185,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
}
} else {
// Disallow `self`
if source.ident.name == keywords::SelfValue.name() {
if source.ident.name == keywords::SelfLower.name() {
resolve_error(self,
use_tree.span,
ResolutionError::SelfImportsOnlyAllowedWithin);
Expand All @@ -205,7 +205,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
// `crate_name` should not be interpreted as relative.
module_path.push(Segment {
ident: Ident {
name: keywords::CrateRoot.name(),
name: keywords::PathRoot.name(),
span: source.ident.span,
},
id: Some(self.session.next_node_id()),
Expand Down Expand Up @@ -270,7 +270,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
// Ensure there is at most one `self` in the list
let self_spans = items.iter().filter_map(|&(ref use_tree, _)| {
if let ast::UseTreeKind::Simple(..) = use_tree.kind {
if use_tree.ident().name == keywords::SelfValue.name() {
if use_tree.ident().name == keywords::SelfLower.name() {
return Some(use_tree.span);
}
}
Expand Down Expand Up @@ -305,7 +305,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
let new_span = prefix[prefix.len() - 1].ident.span;
let tree = ast::UseTree {
prefix: ast::Path::from_ident(
Ident::new(keywords::SelfValue.name(), new_span)
Ident::new(keywords::SelfLower.name(), new_span)
),
kind: ast::UseTreeKind::Simple(
Some(Ident::new(keywords::Underscore.name().gensymed(), new_span)),
Expand Down Expand Up @@ -344,13 +344,13 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
}

ItemKind::ExternCrate(orig_name) => {
let module = if orig_name.is_none() && ident.name == keywords::SelfValue.name() {
let module = if orig_name.is_none() && ident.name == keywords::SelfLower.name() {
self.session
.struct_span_err(item.span, "`extern crate self;` requires renaming")
.span_suggestion(item.span, "try", "extern crate self as name;".into())
.emit();
return;
} else if orig_name == Some(keywords::SelfValue.name()) {
} else if orig_name == Some(keywords::SelfLower.name()) {
if !self.session.features_untracked().extern_crate_self {
emit_feature_err(&self.session.parse_sess, "extern_crate_self", item.span,
GateIssue::Language, "`extern crate self` is unstable");
Expand Down Expand Up @@ -783,7 +783,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
"an `extern crate` loading macros must be at the crate root");
}
if let ItemKind::ExternCrate(Some(orig_name)) = item.node {
if orig_name == keywords::SelfValue.name() {
if orig_name == keywords::SelfLower.name() {
self.session.span_err(attr.span,
"`macro_use` is not supported on `extern crate self`");
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_resolve/error_reporting.rs
Expand Up @@ -30,7 +30,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
match (path.get(0), path.get(1)) {
// `{{root}}::ident::...` on both editions.
// On 2015 `{{root}}` is usually added implicitly.
(Some(fst), Some(snd)) if fst.ident.name == keywords::CrateRoot.name() &&
(Some(fst), Some(snd)) if fst.ident.name == keywords::PathRoot.name() &&
!snd.ident.is_path_segment_keyword() => {}
// `ident::...` on 2018
(Some(fst), _) if fst.ident.span.rust_2018() &&
Expand Down Expand Up @@ -61,7 +61,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
parent_scope: &ParentScope<'b>,
) -> Option<(Vec<Segment>, Option<String>)> {
// Replace first ident with `self` and check if that is valid.
path[0].ident.name = keywords::SelfValue.name();
path[0].ident.name = keywords::SelfLower.name();
let result = self.resolve_path(&path, None, parent_scope, false, span, CrateLint::No);
debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result);
if let PathResult::Module(..) = result {
Expand Down

0 comments on commit 08f8fae

Please sign in to comment.