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
This commit is contained in:
parent
101467c152
commit
08f8faedd0
26 changed files with 83 additions and 83 deletions
|
@ -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); }
|
||||
|
|
|
@ -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,
|
||||
}),
|
||||
)),
|
||||
|
@ -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
|
||||
|
@ -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() {
|
||||
|
|
|
@ -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)),
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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| {
|
||||
|
@ -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| {
|
||||
|
@ -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| {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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`.
|
||||
|
|
|
@ -145,7 +145,7 @@ 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<_>>();
|
||||
|
@ -153,7 +153,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
|
|||
|
||||
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, ..) => {
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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()),
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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)),
|
||||
|
@ -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");
|
||||
|
@ -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`");
|
||||
}
|
||||
|
|
|
@ -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() &&
|
||||
|
@ -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 {
|
||||
|
|
|
@ -769,7 +769,7 @@ impl<'a, 'tcx, 'cl> Visitor<'tcx> for Resolver<'a, 'cl> {
|
|||
self.smart_resolve_path(ty.id, qself.as_ref(), path, PathSource::Type);
|
||||
}
|
||||
TyKind::ImplicitSelf => {
|
||||
let self_ty = keywords::SelfType.ident();
|
||||
let self_ty = keywords::SelfUpper.ident();
|
||||
let def = self.resolve_ident_in_lexical_scope(self_ty, TypeNS, Some(ty.id), ty.span)
|
||||
.map_or(Def::Err, |d| d.def());
|
||||
self.record_def(ty.id, PathResolution::new(def));
|
||||
|
@ -1679,7 +1679,7 @@ impl<'a, 'cl> hir::lowering::Resolver for Resolver<'a, 'cl> {
|
|||
components: &[&str],
|
||||
is_value: bool
|
||||
) -> hir::Path {
|
||||
let segments = iter::once(keywords::CrateRoot.ident())
|
||||
let segments = iter::once(keywords::PathRoot.ident())
|
||||
.chain(
|
||||
crate_root.into_iter()
|
||||
.chain(components.iter().cloned())
|
||||
|
@ -1721,7 +1721,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
|
|||
let path = if path_str.starts_with("::") {
|
||||
ast::Path {
|
||||
span,
|
||||
segments: iter::once(keywords::CrateRoot.ident())
|
||||
segments: iter::once(keywords::PathRoot.ident())
|
||||
.chain({
|
||||
path_str.split("::").skip(1).map(Ident::from_str)
|
||||
})
|
||||
|
@ -2036,7 +2036,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
|||
let record_used = record_used_id.is_some();
|
||||
assert!(ns == TypeNS || ns == ValueNS);
|
||||
if ns == TypeNS {
|
||||
ident.span = if ident.name == keywords::SelfType.name() {
|
||||
ident.span = if ident.name == keywords::SelfUpper.name() {
|
||||
// FIXME(jseyfried) improve `Self` hygiene
|
||||
ident.span.with_ctxt(SyntaxContext::empty())
|
||||
} else {
|
||||
|
@ -2649,7 +2649,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
|||
let mut self_type_rib = Rib::new(NormalRibKind);
|
||||
|
||||
// plain insert (no renaming, types are not currently hygienic....)
|
||||
self_type_rib.bindings.insert(keywords::SelfType.ident(), self_def);
|
||||
self_type_rib.bindings.insert(keywords::SelfUpper.ident(), self_def);
|
||||
self.ribs[TypeNS].push(self_type_rib);
|
||||
f(self);
|
||||
self.ribs[TypeNS].pop();
|
||||
|
@ -2660,7 +2660,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
|||
{
|
||||
let self_def = Def::SelfCtor(impl_id);
|
||||
let mut self_type_rib = Rib::new(NormalRibKind);
|
||||
self_type_rib.bindings.insert(keywords::SelfType.ident(), self_def);
|
||||
self_type_rib.bindings.insert(keywords::SelfUpper.ident(), self_def);
|
||||
self.ribs[ValueNS].push(self_type_rib);
|
||||
f(self);
|
||||
self.ribs[ValueNS].pop();
|
||||
|
@ -3146,7 +3146,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
|||
let item_span = path.last().unwrap().ident.span;
|
||||
let (mod_prefix, mod_str) = if path.len() == 1 {
|
||||
(String::new(), "this scope".to_string())
|
||||
} else if path.len() == 2 && path[0].ident.name == keywords::CrateRoot.name() {
|
||||
} else if path.len() == 2 && path[0].ident.name == keywords::PathRoot.name() {
|
||||
(String::new(), "the crate root".to_string())
|
||||
} else {
|
||||
let mod_path = &path[..path.len() - 1];
|
||||
|
@ -3515,13 +3515,13 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
|||
}
|
||||
|
||||
fn self_type_is_available(&mut self, span: Span) -> bool {
|
||||
let binding = self.resolve_ident_in_lexical_scope(keywords::SelfType.ident(),
|
||||
let binding = self.resolve_ident_in_lexical_scope(keywords::SelfUpper.ident(),
|
||||
TypeNS, None, span);
|
||||
if let Some(LexicalScopeBinding::Def(def)) = binding { def != Def::Err } else { false }
|
||||
}
|
||||
|
||||
fn self_value_is_available(&mut self, self_span: Span, path_span: Span) -> bool {
|
||||
let ident = Ident::new(keywords::SelfValue.name(), self_span);
|
||||
let ident = Ident::new(keywords::SelfLower.name(), self_span);
|
||||
let binding = self.resolve_ident_in_lexical_scope(ident, ValueNS, None, path_span);
|
||||
if let Some(LexicalScopeBinding::Def(def)) = binding { def != Def::Err } else { false }
|
||||
}
|
||||
|
@ -3673,7 +3673,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
|||
};
|
||||
|
||||
if path.len() > 1 && !global_by_default && result.base_def() != Def::Err &&
|
||||
path[0].ident.name != keywords::CrateRoot.name() &&
|
||||
path[0].ident.name != keywords::PathRoot.name() &&
|
||||
path[0].ident.name != keywords::DollarCrate.name() {
|
||||
let unqualified_result = {
|
||||
match self.resolve_path_without_parent_scope(
|
||||
|
@ -3755,7 +3755,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
|||
let name = ident.name;
|
||||
|
||||
allow_super &= ns == TypeNS &&
|
||||
(name == keywords::SelfValue.name() ||
|
||||
(name == keywords::SelfLower.name() ||
|
||||
name == keywords::Super.name());
|
||||
|
||||
if ns == TypeNS {
|
||||
|
@ -3779,24 +3779,24 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
|||
return PathResult::Failed(ident.span, msg, false);
|
||||
}
|
||||
if i == 0 {
|
||||
if name == keywords::SelfValue.name() {
|
||||
if name == keywords::SelfLower.name() {
|
||||
let mut ctxt = ident.span.ctxt().modern();
|
||||
module = Some(ModuleOrUniformRoot::Module(
|
||||
self.resolve_self(&mut ctxt, self.current_module)));
|
||||
continue;
|
||||
}
|
||||
if name == keywords::Extern.name() ||
|
||||
name == keywords::CrateRoot.name() && ident.span.rust_2018() {
|
||||
name == keywords::PathRoot.name() && ident.span.rust_2018() {
|
||||
module = Some(ModuleOrUniformRoot::ExternPrelude);
|
||||
continue;
|
||||
}
|
||||
if name == keywords::CrateRoot.name() &&
|
||||
if name == keywords::PathRoot.name() &&
|
||||
ident.span.rust_2015() && self.session.rust_2018() {
|
||||
// `::a::b` from 2015 macro on 2018 global edition
|
||||
module = Some(ModuleOrUniformRoot::CrateRootAndExternPrelude);
|
||||
continue;
|
||||
}
|
||||
if name == keywords::CrateRoot.name() ||
|
||||
if name == keywords::PathRoot.name() ||
|
||||
name == keywords::Crate.name() ||
|
||||
name == keywords::DollarCrate.name() {
|
||||
// `::a::b`, `crate::a::b` or `$crate::a::b`
|
||||
|
@ -3809,12 +3809,12 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
|||
|
||||
// Report special messages for path segment keywords in wrong positions.
|
||||
if ident.is_path_segment_keyword() && i != 0 {
|
||||
let name_str = if name == keywords::CrateRoot.name() {
|
||||
let name_str = if name == keywords::PathRoot.name() {
|
||||
"crate root".to_string()
|
||||
} else {
|
||||
format!("`{}`", name)
|
||||
};
|
||||
let msg = if i == 1 && path[0].ident.name == keywords::CrateRoot.name() {
|
||||
let msg = if i == 1 && path[0].ident.name == keywords::PathRoot.name() {
|
||||
format!("global paths cannot start with {}", name_str)
|
||||
} else {
|
||||
format!("{} in paths can only be used in start position", name_str)
|
||||
|
@ -3944,7 +3944,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
|||
|
||||
// We're only interested in `use` paths which should start with
|
||||
// `{{root}}` or `extern` currently.
|
||||
if first_name != keywords::Extern.name() && first_name != keywords::CrateRoot.name() {
|
||||
if first_name != keywords::Extern.name() && first_name != keywords::PathRoot.name() {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -3953,7 +3953,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
|||
Some(Segment { ident, .. }) if ident.name == keywords::Crate.name() => return,
|
||||
// Otherwise go below to see if it's an extern crate
|
||||
Some(_) => {}
|
||||
// If the path has length one (and it's `CrateRoot` most likely)
|
||||
// If the path has length one (and it's `PathRoot` most likely)
|
||||
// then we don't know whether we're gonna be importing a crate or an
|
||||
// item in our crate. Defer this lint to elsewhere
|
||||
None => return,
|
||||
|
@ -4740,7 +4740,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
|||
} else {
|
||||
let ctxt = ident.span.ctxt();
|
||||
Some(Segment::from_ident(Ident::new(
|
||||
keywords::CrateRoot.name(), path.span.shrink_to_lo().with_ctxt(ctxt)
|
||||
keywords::PathRoot.name(), path.span.shrink_to_lo().with_ctxt(ctxt)
|
||||
)))
|
||||
};
|
||||
|
||||
|
@ -5090,17 +5090,17 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
|||
}
|
||||
|
||||
fn is_self_type(path: &[Segment], namespace: Namespace) -> bool {
|
||||
namespace == TypeNS && path.len() == 1 && path[0].ident.name == keywords::SelfType.name()
|
||||
namespace == TypeNS && path.len() == 1 && path[0].ident.name == keywords::SelfUpper.name()
|
||||
}
|
||||
|
||||
fn is_self_value(path: &[Segment], namespace: Namespace) -> bool {
|
||||
namespace == ValueNS && path.len() == 1 && path[0].ident.name == keywords::SelfValue.name()
|
||||
namespace == ValueNS && path.len() == 1 && path[0].ident.name == keywords::SelfLower.name()
|
||||
}
|
||||
|
||||
fn names_to_string(idents: &[Ident]) -> String {
|
||||
let mut result = String::new();
|
||||
for (i, ident) in idents.iter()
|
||||
.filter(|ident| ident.name != keywords::CrateRoot.name())
|
||||
.filter(|ident| ident.name != keywords::PathRoot.name())
|
||||
.enumerate() {
|
||||
if i > 0 {
|
||||
result.push_str("::");
|
||||
|
|
|
@ -167,7 +167,7 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
|
|||
|
||||
if path.segments[0].ident.name == keywords::DollarCrate.name() {
|
||||
let module = self.0.resolve_crate_root(path.segments[0].ident);
|
||||
path.segments[0].ident.name = keywords::CrateRoot.name();
|
||||
path.segments[0].ident.name = keywords::PathRoot.name();
|
||||
if !module.is_local() {
|
||||
let span = path.segments[0].ident.span;
|
||||
path.segments.insert(1, match module.kind {
|
||||
|
@ -674,7 +674,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
|
|||
_ => Err(Determinacy::Determined),
|
||||
}
|
||||
WhereToResolve::CrateRoot => {
|
||||
let root_ident = Ident::new(keywords::CrateRoot.name(), orig_ident.span);
|
||||
let root_ident = Ident::new(keywords::PathRoot.name(), orig_ident.span);
|
||||
let root_module = self.resolve_crate_root(root_ident);
|
||||
let binding = self.resolve_ident_in_module_ext(
|
||||
ModuleOrUniformRoot::Module(root_module),
|
||||
|
@ -960,7 +960,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
|
|||
break 'ok;
|
||||
}
|
||||
if rust_2015 {
|
||||
let root_ident = Ident::new(keywords::CrateRoot.name(), orig_ident.span);
|
||||
let root_ident = Ident::new(keywords::PathRoot.name(), orig_ident.span);
|
||||
let root_module = self.resolve_crate_root(root_ident);
|
||||
if self.resolve_ident_in_module_ext(ModuleOrUniformRoot::Module(root_module),
|
||||
orig_ident, ns, None, false, path_span)
|
||||
|
|
|
@ -198,7 +198,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
|
|||
.to_name_binding(self.arenas);
|
||||
return Ok(binding);
|
||||
} else if ident.name == keywords::Super.name() ||
|
||||
ident.name == keywords::SelfValue.name() {
|
||||
ident.name == keywords::SelfLower.name() {
|
||||
// FIXME: Implement these with renaming requirements so that e.g.
|
||||
// `use super;` doesn't work, but `use super as name;` does.
|
||||
// Fall through here to get an error from `early_resolve_...`.
|
||||
|
@ -1263,8 +1263,8 @@ fn import_path_to_string(names: &[Ident],
|
|||
subclass: &ImportDirectiveSubclass,
|
||||
span: Span) -> String {
|
||||
let pos = names.iter()
|
||||
.position(|p| span == p.span && p.name != keywords::CrateRoot.name());
|
||||
let global = !names.is_empty() && names[0].name == keywords::CrateRoot.name();
|
||||
.position(|p| span == p.span && p.name != keywords::PathRoot.name());
|
||||
let global = !names.is_empty() && names[0].name == keywords::PathRoot.name();
|
||||
if let Some(pos) = pos {
|
||||
let names = if global { &names[1..pos + 1] } else { &names[..pos + 1] };
|
||||
names_to_string(names)
|
||||
|
|
|
@ -938,7 +938,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty
|
|||
|
||||
opt_self = Some(ty::GenericParamDef {
|
||||
index: 0,
|
||||
name: keywords::SelfType.name().as_interned_str(),
|
||||
name: keywords::SelfUpper.name().as_interned_str(),
|
||||
def_id: tcx.hir.local_def_id(param_id),
|
||||
pure_wrt_drop: false,
|
||||
kind: ty::GenericParamDefKind::Type {
|
||||
|
@ -1007,7 +1007,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty
|
|||
synthetic,
|
||||
..
|
||||
} => {
|
||||
if param.name.ident().name == keywords::SelfType.name() {
|
||||
if param.name.ident().name == keywords::SelfUpper.name() {
|
||||
span_bug!(
|
||||
param.span,
|
||||
"`Self` should not be the name of a regular parameter"
|
||||
|
|
|
@ -1575,7 +1575,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
|
|||
let stripped_typarams = gens.params.iter().filter_map(|param| match param.kind {
|
||||
ty::GenericParamDefKind::Lifetime => None,
|
||||
ty::GenericParamDefKind::Type { .. } => {
|
||||
if param.name == keywords::SelfType.name().as_str() {
|
||||
if param.name == keywords::SelfUpper.name().as_str() {
|
||||
assert_eq!(param.index, 0);
|
||||
return None;
|
||||
}
|
||||
|
@ -3174,7 +3174,7 @@ fn qpath_to_string(p: &hir::QPath) -> String {
|
|||
if i > 0 {
|
||||
s.push_str("::");
|
||||
}
|
||||
if seg.ident.name != keywords::CrateRoot.name() {
|
||||
if seg.ident.name != keywords::PathRoot.name() {
|
||||
s.push_str(&*seg.ident.as_str());
|
||||
}
|
||||
}
|
||||
|
@ -3726,7 +3726,7 @@ fn resolve_type(cx: &DocContext,
|
|||
hir::Float(float_ty) => return Primitive(float_ty.into()),
|
||||
},
|
||||
Def::SelfTy(..) if path.segments.len() == 1 => {
|
||||
return Generic(keywords::SelfType.name().to_string());
|
||||
return Generic(keywords::SelfUpper.name().to_string());
|
||||
}
|
||||
Def::TyParam(..) if path.segments.len() == 1 => {
|
||||
return Generic(format!("{:#}", path));
|
||||
|
|
|
@ -73,7 +73,7 @@ impl fmt::Debug for Lifetime {
|
|||
pub struct Path {
|
||||
pub span: Span,
|
||||
/// The segments in the path: the things separated by `::`.
|
||||
/// Global paths begin with `keywords::CrateRoot`.
|
||||
/// Global paths begin with `keywords::PathRoot`.
|
||||
pub segments: Vec<PathSegment>,
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ 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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ impl PathSegment {
|
|||
PathSegment { ident, id: DUMMY_NODE_ID, args: None }
|
||||
}
|
||||
pub fn crate_root(span: Span) -> Self {
|
||||
PathSegment::from_ident(Ident::new(keywords::CrateRoot.name(), span))
|
||||
PathSegment::from_ident(Ident::new(keywords::PathRoot.name(), span))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1688,7 +1688,7 @@ pub type ExplicitSelf = Spanned<SelfKind>;
|
|||
impl Arg {
|
||||
pub fn to_self(&self) -> Option<ExplicitSelf> {
|
||||
if let PatKind::Ident(BindingMode::ByValue(mutbl), ident, _) = self.pat.node {
|
||||
if ident.name == keywords::SelfValue.name() {
|
||||
if ident.name == keywords::SelfLower.name() {
|
||||
return match self.ty.node {
|
||||
TyKind::ImplicitSelf => Some(respan(self.pat.span, SelfKind::Value(mutbl))),
|
||||
TyKind::Rptr(lt, MutTy { ref ty, mutbl }) if ty.node.is_implicit_self() => {
|
||||
|
@ -1706,7 +1706,7 @@ impl Arg {
|
|||
|
||||
pub fn is_self(&self) -> bool {
|
||||
if let PatKind::Ident(_, ident, _) = self.pat.node {
|
||||
ident.name == keywords::SelfValue.name()
|
||||
ident.name == keywords::SelfLower.name()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
|
|
@ -625,7 +625,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
|||
self.expr_path(self.path_ident(span, id))
|
||||
}
|
||||
fn expr_self(&self, span: Span) -> P<ast::Expr> {
|
||||
self.expr_ident(span, keywords::SelfValue.ident())
|
||||
self.expr_ident(span, keywords::SelfLower.ident())
|
||||
}
|
||||
|
||||
fn expr_binary(&self, sp: Span, op: ast::BinOpKind,
|
||||
|
|
|
@ -204,7 +204,7 @@ fn macro_bang_format(path: &ast::Path) -> ExpnFormat {
|
|||
path_str.push_str("::");
|
||||
}
|
||||
|
||||
if segment.ident.name != keywords::CrateRoot.name() &&
|
||||
if segment.ident.name != keywords::PathRoot.name() &&
|
||||
segment.ident.name != keywords::DollarCrate.name()
|
||||
{
|
||||
path_str.push_str(&segment.ident.as_str())
|
||||
|
|
|
@ -5508,7 +5508,7 @@ impl<'a> Parser<'a> {
|
|||
_ => unreachable!()
|
||||
};
|
||||
let isolated_self = |this: &mut Self, n| {
|
||||
this.look_ahead(n, |t| t.is_keyword(keywords::SelfValue)) &&
|
||||
this.look_ahead(n, |t| t.is_keyword(keywords::SelfLower)) &&
|
||||
this.look_ahead(n + 1, |t| t != &token::ModSep)
|
||||
};
|
||||
|
||||
|
@ -6330,7 +6330,7 @@ impl<'a> Parser<'a> {
|
|||
return Ok(vis)
|
||||
} else if self.look_ahead(2, |t| t == &token::CloseDelim(token::Paren)) &&
|
||||
self.look_ahead(1, |t| t.is_keyword(keywords::Super) ||
|
||||
t.is_keyword(keywords::SelfValue))
|
||||
t.is_keyword(keywords::SelfLower))
|
||||
{
|
||||
// `pub(self)` or `pub(super)`
|
||||
self.bump(); // `(`
|
||||
|
@ -6782,7 +6782,7 @@ impl<'a> Parser<'a> {
|
|||
let error_msg = "crate name using dashes are not valid in `extern crate` statements";
|
||||
let suggestion_msg = "if the original crate name uses dashes you need to use underscores \
|
||||
in the code";
|
||||
let mut ident = if self.token.is_keyword(keywords::SelfValue) {
|
||||
let mut ident = if self.token.is_keyword(keywords::SelfLower) {
|
||||
self.parse_path_segment_ident()
|
||||
} else {
|
||||
self.parse_ident()
|
||||
|
|
|
@ -724,7 +724,7 @@ pub trait PrintState<'a> {
|
|||
if i > 0 {
|
||||
self.writer().word("::")?
|
||||
}
|
||||
if segment.ident.name != keywords::CrateRoot.name() &&
|
||||
if segment.ident.name != keywords::PathRoot.name() &&
|
||||
segment.ident.name != keywords::DollarCrate.name()
|
||||
{
|
||||
self.writer().word(segment.ident.as_str().get())?;
|
||||
|
@ -2463,7 +2463,7 @@ impl<'a> State<'a> {
|
|||
colons_before_params: bool)
|
||||
-> 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)?;
|
||||
if let Some(ref args) = segment.args {
|
||||
|
|
|
@ -112,7 +112,7 @@ pub fn maybe_inject_crates_ref(
|
|||
vis: respan(span.shrink_to_lo(), ast::VisibilityKind::Inherited),
|
||||
node: ast::ItemKind::Use(P(ast::UseTree {
|
||||
prefix: ast::Path {
|
||||
segments: iter::once(keywords::CrateRoot.ident())
|
||||
segments: iter::once(keywords::PathRoot.ident())
|
||||
.chain(
|
||||
[name, "prelude", "v1"].iter().cloned()
|
||||
.map(ast::Ident::from_str)
|
||||
|
|
|
@ -140,7 +140,7 @@ fn cs_clone_shallow(name: &str,
|
|||
let mut stmts = Vec::new();
|
||||
if is_union {
|
||||
// let _: AssertParamIsCopy<Self>;
|
||||
let self_ty = cx.ty_path(cx.path_ident(trait_span, keywords::SelfType.ident()));
|
||||
let self_ty = cx.ty_path(cx.path_ident(trait_span, keywords::SelfUpper.ident()));
|
||||
assert_ty_bounds(cx, &mut stmts, self_ty, trait_span, "AssertParamIsCopy");
|
||||
} else {
|
||||
match *substr.fields {
|
||||
|
|
|
@ -938,7 +938,7 @@ impl<'a> MethodDef<'a> {
|
|||
let args = {
|
||||
let self_args = explicit_self.map(|explicit_self| {
|
||||
ast::Arg::from_self(explicit_self,
|
||||
keywords::SelfValue.ident().with_span_pos(trait_.span))
|
||||
keywords::SelfLower.ident().with_span_pos(trait_.span))
|
||||
});
|
||||
let nonself_args = arg_types.into_iter()
|
||||
.map(|(name, ty)| cx.arg(trait_.span, name, ty));
|
||||
|
|
|
@ -349,7 +349,7 @@ declare_keywords! {
|
|||
// Special reserved identifiers used internally for elided lifetimes,
|
||||
// unnamed method parameters, crate root module, error recovery etc.
|
||||
(0, Invalid, "")
|
||||
(1, CrateRoot, "{{root}}")
|
||||
(1, PathRoot, "{{root}}")
|
||||
(2, DollarCrate, "$crate")
|
||||
(3, Underscore, "_")
|
||||
|
||||
|
@ -378,8 +378,8 @@ declare_keywords! {
|
|||
(25, Pub, "pub")
|
||||
(26, Ref, "ref")
|
||||
(27, Return, "return")
|
||||
(28, SelfValue, "self")
|
||||
(29, SelfType, "Self")
|
||||
(28, SelfLower, "self")
|
||||
(29, SelfUpper, "Self")
|
||||
(30, Static, "static")
|
||||
(31, Struct, "struct")
|
||||
(32, Super, "super")
|
||||
|
@ -462,11 +462,11 @@ impl Ident {
|
|||
/// A keyword or reserved identifier that can be used as a path segment.
|
||||
pub fn is_path_segment_keyword(self) -> bool {
|
||||
self.name == keywords::Super.name() ||
|
||||
self.name == keywords::SelfValue.name() ||
|
||||
self.name == keywords::SelfType.name() ||
|
||||
self.name == keywords::SelfLower.name() ||
|
||||
self.name == keywords::SelfUpper.name() ||
|
||||
self.name == keywords::Extern.name() ||
|
||||
self.name == keywords::Crate.name() ||
|
||||
self.name == keywords::CrateRoot.name() ||
|
||||
self.name == keywords::PathRoot.name() ||
|
||||
self.name == keywords::DollarCrate.name()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue