Skip to content

Commit a1885cd

Browse files
committed
Restore the old behavior of the rustdoc keyword check + Fix rebase
1 parent c389a39 commit a1885cd

File tree

13 files changed

+44
-41
lines changed

13 files changed

+44
-41
lines changed

src/librustc/ty/print/pretty.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::ty::{self, DefIdTree, ParamConst, Ty, TyCtxt, TypeFoldable};
88
use crate::ty::subst::{Kind, Subst, UnpackedKind};
99
use crate::mir::interpret::ConstValue;
1010
use rustc_target::spec::abi::Abi;
11-
use syntax::symbol::{keywords, InternedString};
11+
use syntax::symbol::{kw, InternedString};
1212

1313
use std::cell::Cell;
1414
use std::fmt::{self, Write as _};
@@ -1140,16 +1140,16 @@ impl<F: fmt::Write> PrettyPrinter<'gcx, 'tcx> for FmtPrinter<'_, 'gcx, 'tcx, F>
11401140

11411141
match *region {
11421142
ty::ReEarlyBound(ref data) => {
1143-
data.name.as_symbol() != keywords::Invalid.name() &&
1144-
data.name.as_symbol() != keywords::UnderscoreLifetime.name()
1143+
data.name.as_symbol() != kw::Invalid &&
1144+
data.name.as_symbol() != kw::UnderscoreLifetime
11451145
}
11461146

11471147
ty::ReLateBound(_, br) |
11481148
ty::ReFree(ty::FreeRegion { bound_region: br, .. }) |
11491149
ty::RePlaceholder(ty::Placeholder { name: br, .. }) => {
11501150
if let ty::BrNamed(_, name) = br {
1151-
if name.as_symbol() != keywords::Invalid.name() &&
1152-
name.as_symbol() != keywords::UnderscoreLifetime.name() {
1151+
if name.as_symbol() != kw::Invalid &&
1152+
name.as_symbol() != kw::UnderscoreLifetime {
11531153
return true;
11541154
}
11551155
}
@@ -1205,7 +1205,7 @@ impl<F: fmt::Write> FmtPrinter<'_, '_, '_, F> {
12051205
// `explain_region()` or `note_and_explain_region()`.
12061206
match *region {
12071207
ty::ReEarlyBound(ref data) => {
1208-
if data.name.as_symbol() != keywords::Invalid.name() {
1208+
if data.name.as_symbol() != kw::Invalid {
12091209
p!(write("{}", data.name));
12101210
return Ok(self);
12111211
}
@@ -1214,8 +1214,8 @@ impl<F: fmt::Write> FmtPrinter<'_, '_, '_, F> {
12141214
ty::ReFree(ty::FreeRegion { bound_region: br, .. }) |
12151215
ty::RePlaceholder(ty::Placeholder { name: br, .. }) => {
12161216
if let ty::BrNamed(_, name) = br {
1217-
if name.as_symbol() != keywords::Invalid.name() &&
1218-
name.as_symbol() != keywords::UnderscoreLifetime.name() {
1217+
if name.as_symbol() != kw::Invalid &&
1218+
name.as_symbol() != kw::UnderscoreLifetime {
12191219
p!(write("{}", name));
12201220
return Ok(self);
12211221
}

src/librustc_allocator/expand.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use syntax::{
1919
mut_visit::{self, MutVisitor},
2020
parse::ParseSess,
2121
ptr::P,
22-
symbol::{keywords, Symbol, sym}
22+
symbol::{kw, sym, Symbol}
2323
};
2424
use syntax_pos::Span;
2525

@@ -116,8 +116,7 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> {
116116

117117
// We will generate a new submodule. To `use` the static from that module, we need to get
118118
// the `super::...` path.
119-
let super_path =
120-
f.cx.path(f.span, vec![Ident::with_empty_ctxt(keywords::Super.name()), f.global]);
119+
let super_path = f.cx.path(f.span, vec![Ident::with_empty_ctxt(kw::Super), f.global]);
121120

122121
// Generate the items in the submodule
123122
let mut items = vec![

src/librustc_plugin/load.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::mem;
1111
use std::path::PathBuf;
1212
use syntax::ast;
1313
use syntax::span_err;
14-
use syntax::symbol::{Symbol, keywords, sym};
14+
use syntax::symbol::{Symbol, kw, sym};
1515
use syntax_pos::{Span, DUMMY_SP};
1616

1717
/// Pointer to a registrar function.
@@ -58,7 +58,7 @@ pub fn load_plugins(sess: &Session,
5858
for plugin in plugins {
5959
// plugins must have a name and can't be key = value
6060
let name = plugin.name_or_empty();
61-
if name != keywords::Invalid.name() && !plugin.is_value_str() {
61+
if name != kw::Invalid && !plugin.is_value_str() {
6262
let args = plugin.meta_item_list().map(ToOwned::to_owned);
6363
loader.load_plugin(plugin.span(), name, args.unwrap_or_default());
6464
} else {

src/librustc_resolve/resolve_imports.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
707707
has_errors = true;
708708

709709
if let SingleImport { source, ref source_bindings, .. } = import.subclass {
710-
if source.name == keywords::SelfLower.name() {
710+
if source.name == kw::SelfLower {
711711
// Silence `unresolved import` error if E0429 is already emitted
712712
if let Err(Determined) = source_bindings.value_ns.get() {
713713
continue;

src/librustdoc/html/highlight.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use syntax::source_map::{SourceMap, FilePathMapping};
1515
use syntax::parse::lexer::{self, TokenAndSpan};
1616
use syntax::parse::token;
1717
use syntax::parse;
18+
use syntax::symbol::{kw, sym};
1819
use syntax_pos::{Span, FileName};
1920

2021
/// Highlights `src`, returning the HTML output.
@@ -325,16 +326,15 @@ impl<'a> Classifier<'a> {
325326

326327
// Keywords are also included in the identifier set.
327328
token::Ident(ident, is_raw) => {
328-
match &*ident.as_str() {
329-
"ref" | "mut" if !is_raw => Class::RefKeyWord,
329+
match ident.name {
330+
kw::Ref | kw::Mut if !is_raw => Class::RefKeyWord,
330331

331-
"self" | "Self" => Class::Self_,
332-
"false" | "true" if !is_raw => Class::Bool,
332+
kw::SelfLower | kw::SelfUpper => Class::Self_,
333+
kw::False | kw::True if !is_raw => Class::Bool,
333334

334-
"Option" | "Result" => Class::PreludeTy,
335-
"Some" | "None" | "Ok" | "Err" => Class::PreludeVal,
335+
sym::Option | sym::Result => Class::PreludeTy,
336+
sym::Some | sym::None | sym::Ok | sym::Err => Class::PreludeVal,
336337

337-
"$crate" => Class::KeyWord,
338338
_ if tas.tok.is_reserved_ident() => Class::KeyWord,
339339

340340
_ => {

src/librustdoc/html/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
4444
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\
4545
<meta name=\"generator\" content=\"rustdoc\">\
4646
<meta name=\"description\" content=\"{description}\">\
47-
<meta name=\"keywords\" content=\"{kw}\">\
47+
<meta name=\"keywords\" content=\"{keywords}\">\
4848
<title>{title}</title>\
4949
<link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}normalize{suffix}.css\">\
5050
<link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}rustdoc{suffix}.css\" \

src/libsyntax/attr/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::parse::parser::Parser;
2222
use crate::parse::{self, ParseSess, PResult};
2323
use crate::parse::token::{self, Token};
2424
use crate::ptr::P;
25-
use crate::symbol::{kw, sym, Symbol};
25+
use crate::symbol::{sym, Symbol};
2626
use crate::ThinVec;
2727
use crate::tokenstream::{TokenStream, TokenTree, DelimSpan};
2828
use crate::GLOBALS;
@@ -206,7 +206,7 @@ impl MetaItem {
206206
}
207207
}
208208
pub fn name_or_empty(&self) -> Symbol {
209-
self.ident().unwrap_or(Ident.invalid()).name
209+
self.ident().unwrap_or(Ident::invalid()).name
210210
}
211211

212212
// #[attribute(name = "value")]

src/libsyntax/ext/tt/macro_rules.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::parse::{Directory, ParseSess};
1313
use crate::parse::parser::Parser;
1414
use crate::parse::token::{self, NtTT};
1515
use crate::parse::token::Token::*;
16-
use crate::symbol::{Symbol, keywords, sym};
16+
use crate::symbol::{Symbol, kw, sym};
1717
use crate::tokenstream::{DelimSpan, TokenStream, TokenTree};
1818

1919
use errors::FatalError;
@@ -1046,8 +1046,8 @@ fn is_in_follow(tok: &quoted::TokenTree, frag: &str) -> IsInFollow {
10461046
match *tok {
10471047
TokenTree::Token(_, ref tok) => match *tok {
10481048
FatArrow | Comma | Eq | BinOp(token::Or) => IsInFollow::Yes,
1049-
Ident(i, false) if i.name == keywords::If.name() ||
1050-
i.name == keywords::In.name() => IsInFollow::Yes,
1049+
Ident(i, false) if i.name == kw::If ||
1050+
i.name == kw::In => IsInFollow::Yes,
10511051
_ => IsInFollow::No(tokens),
10521052
},
10531053
_ => IsInFollow::No(tokens),
@@ -1064,8 +1064,8 @@ fn is_in_follow(tok: &quoted::TokenTree, frag: &str) -> IsInFollow {
10641064
OpenDelim(token::DelimToken::Bracket) |
10651065
Comma | FatArrow | Colon | Eq | Gt | BinOp(token::Shr) | Semi |
10661066
BinOp(token::Or) => IsInFollow::Yes,
1067-
Ident(i, false) if i.name == keywords::As.name() ||
1068-
i.name == keywords::Where.name() => IsInFollow::Yes,
1067+
Ident(i, false) if i.name == kw::As ||
1068+
i.name == kw::Where => IsInFollow::Yes,
10691069
_ => IsInFollow::No(tokens),
10701070
},
10711071
TokenTree::MetaVarDecl(_, _, frag) if frag.name == sym::block =>
@@ -1092,7 +1092,7 @@ fn is_in_follow(tok: &quoted::TokenTree, frag: &str) -> IsInFollow {
10921092
match *tok {
10931093
TokenTree::Token(_, ref tok) => match *tok {
10941094
Comma => IsInFollow::Yes,
1095-
Ident(i, is_raw) if is_raw || i.name != keywords::Priv.name() =>
1095+
Ident(i, is_raw) if is_raw || i.name != kw::Priv =>
10961096
IsInFollow::Yes,
10971097
ref tok => if tok.can_begin_type() {
10981098
IsInFollow::Yes

src/libsyntax/feature_gate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::source_map::Spanned;
2222
use crate::edition::{ALL_EDITIONS, Edition};
2323
use crate::visit::{self, FnKind, Visitor};
2424
use crate::parse::{token, ParseSess};
25-
use crate::symbol::{Symbol, keywords, sym};
25+
use crate::symbol::{Symbol, kw, sym};
2626
use crate::tokenstream::TokenTree;
2727

2828
use errors::{DiagnosticBuilder, Handler};
@@ -1948,7 +1948,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
19481948
fn visit_item(&mut self, i: &'a ast::Item) {
19491949
match i.node {
19501950
ast::ItemKind::Const(_,_) => {
1951-
if i.ident.name == keywords::Underscore.name() {
1951+
if i.ident.name == kw::Underscore {
19521952
gate_feature_post!(&self, underscore_const_names, i.span,
19531953
"naming constants with `_` is unstable");
19541954
}

src/libsyntax/parse/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::parse::PResult;
66
use crate::parse::Parser;
77
use crate::print::pprust;
88
use crate::ptr::P;
9-
use crate::symbol::keywords;
9+
use crate::symbol::kw;
1010
use crate::ThinVec;
1111
use errors::{Applicability, DiagnosticBuilder};
1212
use syntax_pos::Span;
@@ -405,7 +405,7 @@ impl<'a> Parser<'a> {
405405

406406
/// Recover from `pub` keyword in places where it seems _reasonable_ but isn't valid.
407407
crate fn eat_bad_pub(&mut self) {
408-
if self.token.is_keyword(keywords::Pub) {
408+
if self.token.is_keyword(kw::Pub) {
409409
match self.parse_visibility(false) {
410410
Ok(vis) => {
411411
self.diagnostic()

src/libsyntax/parse/literal.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ impl LitKind {
4343

4444
Some(match lit {
4545
token::Bool(i) => {
46-
assert!(i == keywords::True.name() || i == keywords::False.name());
47-
LitKind::Bool(i == keywords::True.name())
46+
assert!(i == kw::True || i == kw::False);
47+
LitKind::Bool(i == kw::True)
4848
}
4949
token::Byte(i) => {
5050
match unescape_byte(&i.as_str()) {
@@ -156,8 +156,8 @@ impl LitKind {
156156
}
157157
LitKind::FloatUnsuffixed(symbol) => (token::Lit::Float(symbol), None),
158158
LitKind::Bool(value) => {
159-
let kw = if value { keywords::True } else { keywords::False };
160-
(token::Lit::Bool(kw.name()), None)
159+
let kw = if value { kw::True } else { kw::False };
160+
(token::Lit::Bool(kw), None)
161161
}
162162
LitKind::Err(val) => (token::Lit::Err(val), None),
163163
}
@@ -175,8 +175,7 @@ impl Lit {
175175
diag: Option<(Span, &Handler)>,
176176
) -> Option<Lit> {
177177
let (token, suffix) = match *token {
178-
token::Ident(ident, false) if ident.name == keywords::True.name() ||
179-
ident.name == keywords::False.name() =>
178+
token::Ident(ident, false) if ident.name == kw::True || ident.name == kw::False =>
180179
(token::Bool(ident.name), None),
181180
token::Literal(token, suffix) =>
182181
(token, suffix),

src/libsyntax/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ fn mk_reexport_mod(cx: &mut TestCtxt<'_>,
215215
tests: Vec<Ident>,
216216
tested_submods: Vec<(Ident, Ident)>)
217217
-> (P<ast::Item>, Ident) {
218-
let super_ = Ident::with_empty_ctxt(keywords::Super.name());
218+
let super_ = Ident::with_empty_ctxt(kw::Super);
219219

220220
let items = tests.into_iter().map(|r| {
221221
cx.ext_cx.item_use_simple(DUMMY_SP, dummy_spanned(ast::VisibilityKind::Public),

src/libsyntax_pos/symbol.rs

+5
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,11 @@ impl Symbol {
951951
fn is_unused_keyword_2018(self) -> bool {
952952
self >= kw::Async && self <= kw::Try
953953
}
954+
955+
/// Used for sanity checking rustdoc keyword sections.
956+
pub fn is_doc_keyword(self) -> bool {
957+
self <= kw::Union
958+
}
954959
}
955960

956961
impl Ident {

0 commit comments

Comments
 (0)