1
Fork 0

Restore the old behavior of the rustdoc keyword check + Fix rebase

This commit is contained in:
Vadim Petrochenkov 2019-05-13 22:46:20 +03:00
parent c389a39c97
commit a1885cdba3
13 changed files with 44 additions and 41 deletions

View file

@ -8,7 +8,7 @@ use crate::ty::{self, DefIdTree, ParamConst, Ty, TyCtxt, TypeFoldable};
use crate::ty::subst::{Kind, Subst, UnpackedKind}; use crate::ty::subst::{Kind, Subst, UnpackedKind};
use crate::mir::interpret::ConstValue; use crate::mir::interpret::ConstValue;
use rustc_target::spec::abi::Abi; use rustc_target::spec::abi::Abi;
use syntax::symbol::{keywords, InternedString}; use syntax::symbol::{kw, InternedString};
use std::cell::Cell; use std::cell::Cell;
use std::fmt::{self, Write as _}; use std::fmt::{self, Write as _};
@ -1140,16 +1140,16 @@ impl<F: fmt::Write> PrettyPrinter<'gcx, 'tcx> for FmtPrinter<'_, 'gcx, 'tcx, F>
match *region { match *region {
ty::ReEarlyBound(ref data) => { ty::ReEarlyBound(ref data) => {
data.name.as_symbol() != keywords::Invalid.name() && data.name.as_symbol() != kw::Invalid &&
data.name.as_symbol() != keywords::UnderscoreLifetime.name() data.name.as_symbol() != kw::UnderscoreLifetime
} }
ty::ReLateBound(_, br) | ty::ReLateBound(_, br) |
ty::ReFree(ty::FreeRegion { bound_region: br, .. }) | ty::ReFree(ty::FreeRegion { bound_region: br, .. }) |
ty::RePlaceholder(ty::Placeholder { name: br, .. }) => { ty::RePlaceholder(ty::Placeholder { name: br, .. }) => {
if let ty::BrNamed(_, name) = br { if let ty::BrNamed(_, name) = br {
if name.as_symbol() != keywords::Invalid.name() && if name.as_symbol() != kw::Invalid &&
name.as_symbol() != keywords::UnderscoreLifetime.name() { name.as_symbol() != kw::UnderscoreLifetime {
return true; return true;
} }
} }
@ -1205,7 +1205,7 @@ impl<F: fmt::Write> FmtPrinter<'_, '_, '_, F> {
// `explain_region()` or `note_and_explain_region()`. // `explain_region()` or `note_and_explain_region()`.
match *region { match *region {
ty::ReEarlyBound(ref data) => { ty::ReEarlyBound(ref data) => {
if data.name.as_symbol() != keywords::Invalid.name() { if data.name.as_symbol() != kw::Invalid {
p!(write("{}", data.name)); p!(write("{}", data.name));
return Ok(self); return Ok(self);
} }
@ -1214,8 +1214,8 @@ impl<F: fmt::Write> FmtPrinter<'_, '_, '_, F> {
ty::ReFree(ty::FreeRegion { bound_region: br, .. }) | ty::ReFree(ty::FreeRegion { bound_region: br, .. }) |
ty::RePlaceholder(ty::Placeholder { name: br, .. }) => { ty::RePlaceholder(ty::Placeholder { name: br, .. }) => {
if let ty::BrNamed(_, name) = br { if let ty::BrNamed(_, name) = br {
if name.as_symbol() != keywords::Invalid.name() && if name.as_symbol() != kw::Invalid &&
name.as_symbol() != keywords::UnderscoreLifetime.name() { name.as_symbol() != kw::UnderscoreLifetime {
p!(write("{}", name)); p!(write("{}", name));
return Ok(self); return Ok(self);
} }

View file

@ -19,7 +19,7 @@ use syntax::{
mut_visit::{self, MutVisitor}, mut_visit::{self, MutVisitor},
parse::ParseSess, parse::ParseSess,
ptr::P, ptr::P,
symbol::{keywords, Symbol, sym} symbol::{kw, sym, Symbol}
}; };
use syntax_pos::Span; use syntax_pos::Span;
@ -116,8 +116,7 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> {
// We will generate a new submodule. To `use` the static from that module, we need to get // We will generate a new submodule. To `use` the static from that module, we need to get
// the `super::...` path. // the `super::...` path.
let super_path = let super_path = f.cx.path(f.span, vec![Ident::with_empty_ctxt(kw::Super), f.global]);
f.cx.path(f.span, vec![Ident::with_empty_ctxt(keywords::Super.name()), f.global]);
// Generate the items in the submodule // Generate the items in the submodule
let mut items = vec![ let mut items = vec![

View file

@ -11,7 +11,7 @@ use std::mem;
use std::path::PathBuf; use std::path::PathBuf;
use syntax::ast; use syntax::ast;
use syntax::span_err; use syntax::span_err;
use syntax::symbol::{Symbol, keywords, sym}; use syntax::symbol::{Symbol, kw, sym};
use syntax_pos::{Span, DUMMY_SP}; use syntax_pos::{Span, DUMMY_SP};
/// Pointer to a registrar function. /// Pointer to a registrar function.
@ -58,7 +58,7 @@ pub fn load_plugins(sess: &Session,
for plugin in plugins { for plugin in plugins {
// plugins must have a name and can't be key = value // plugins must have a name and can't be key = value
let name = plugin.name_or_empty(); let name = plugin.name_or_empty();
if name != keywords::Invalid.name() && !plugin.is_value_str() { if name != kw::Invalid && !plugin.is_value_str() {
let args = plugin.meta_item_list().map(ToOwned::to_owned); let args = plugin.meta_item_list().map(ToOwned::to_owned);
loader.load_plugin(plugin.span(), name, args.unwrap_or_default()); loader.load_plugin(plugin.span(), name, args.unwrap_or_default());
} else { } else {

View file

@ -707,7 +707,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
has_errors = true; has_errors = true;
if let SingleImport { source, ref source_bindings, .. } = import.subclass { if let SingleImport { source, ref source_bindings, .. } = import.subclass {
if source.name == keywords::SelfLower.name() { if source.name == kw::SelfLower {
// Silence `unresolved import` error if E0429 is already emitted // Silence `unresolved import` error if E0429 is already emitted
if let Err(Determined) = source_bindings.value_ns.get() { if let Err(Determined) = source_bindings.value_ns.get() {
continue; continue;

View file

@ -15,6 +15,7 @@ use syntax::source_map::{SourceMap, FilePathMapping};
use syntax::parse::lexer::{self, TokenAndSpan}; use syntax::parse::lexer::{self, TokenAndSpan};
use syntax::parse::token; use syntax::parse::token;
use syntax::parse; use syntax::parse;
use syntax::symbol::{kw, sym};
use syntax_pos::{Span, FileName}; use syntax_pos::{Span, FileName};
/// Highlights `src`, returning the HTML output. /// Highlights `src`, returning the HTML output.
@ -325,16 +326,15 @@ impl<'a> Classifier<'a> {
// Keywords are also included in the identifier set. // Keywords are also included in the identifier set.
token::Ident(ident, is_raw) => { token::Ident(ident, is_raw) => {
match &*ident.as_str() { match ident.name {
"ref" | "mut" if !is_raw => Class::RefKeyWord, kw::Ref | kw::Mut if !is_raw => Class::RefKeyWord,
"self" | "Self" => Class::Self_, kw::SelfLower | kw::SelfUpper => Class::Self_,
"false" | "true" if !is_raw => Class::Bool, kw::False | kw::True if !is_raw => Class::Bool,
"Option" | "Result" => Class::PreludeTy, sym::Option | sym::Result => Class::PreludeTy,
"Some" | "None" | "Ok" | "Err" => Class::PreludeVal, sym::Some | sym::None | sym::Ok | sym::Err => Class::PreludeVal,
"$crate" => Class::KeyWord,
_ if tas.tok.is_reserved_ident() => Class::KeyWord, _ if tas.tok.is_reserved_ident() => Class::KeyWord,
_ => { _ => {

View file

@ -44,7 +44,7 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\ <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\
<meta name=\"generator\" content=\"rustdoc\">\ <meta name=\"generator\" content=\"rustdoc\">\
<meta name=\"description\" content=\"{description}\">\ <meta name=\"description\" content=\"{description}\">\
<meta name=\"keywords\" content=\"{kw}\">\ <meta name=\"keywords\" content=\"{keywords}\">\
<title>{title}</title>\ <title>{title}</title>\
<link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}normalize{suffix}.css\">\ <link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}normalize{suffix}.css\">\
<link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}rustdoc{suffix}.css\" \ <link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}rustdoc{suffix}.css\" \

View file

@ -22,7 +22,7 @@ use crate::parse::parser::Parser;
use crate::parse::{self, ParseSess, PResult}; use crate::parse::{self, ParseSess, PResult};
use crate::parse::token::{self, Token}; use crate::parse::token::{self, Token};
use crate::ptr::P; use crate::ptr::P;
use crate::symbol::{kw, sym, Symbol}; use crate::symbol::{sym, Symbol};
use crate::ThinVec; use crate::ThinVec;
use crate::tokenstream::{TokenStream, TokenTree, DelimSpan}; use crate::tokenstream::{TokenStream, TokenTree, DelimSpan};
use crate::GLOBALS; use crate::GLOBALS;
@ -206,7 +206,7 @@ impl MetaItem {
} }
} }
pub fn name_or_empty(&self) -> Symbol { pub fn name_or_empty(&self) -> Symbol {
self.ident().unwrap_or(Ident.invalid()).name self.ident().unwrap_or(Ident::invalid()).name
} }
// #[attribute(name = "value")] // #[attribute(name = "value")]

View file

@ -13,7 +13,7 @@ use crate::parse::{Directory, ParseSess};
use crate::parse::parser::Parser; use crate::parse::parser::Parser;
use crate::parse::token::{self, NtTT}; use crate::parse::token::{self, NtTT};
use crate::parse::token::Token::*; use crate::parse::token::Token::*;
use crate::symbol::{Symbol, keywords, sym}; use crate::symbol::{Symbol, kw, sym};
use crate::tokenstream::{DelimSpan, TokenStream, TokenTree}; use crate::tokenstream::{DelimSpan, TokenStream, TokenTree};
use errors::FatalError; use errors::FatalError;
@ -1046,8 +1046,8 @@ fn is_in_follow(tok: &quoted::TokenTree, frag: &str) -> IsInFollow {
match *tok { match *tok {
TokenTree::Token(_, ref tok) => match *tok { TokenTree::Token(_, ref tok) => match *tok {
FatArrow | Comma | Eq | BinOp(token::Or) => IsInFollow::Yes, FatArrow | Comma | Eq | BinOp(token::Or) => IsInFollow::Yes,
Ident(i, false) if i.name == keywords::If.name() || Ident(i, false) if i.name == kw::If ||
i.name == keywords::In.name() => IsInFollow::Yes, i.name == kw::In => IsInFollow::Yes,
_ => IsInFollow::No(tokens), _ => IsInFollow::No(tokens),
}, },
_ => IsInFollow::No(tokens), _ => IsInFollow::No(tokens),
@ -1064,8 +1064,8 @@ fn is_in_follow(tok: &quoted::TokenTree, frag: &str) -> IsInFollow {
OpenDelim(token::DelimToken::Bracket) | OpenDelim(token::DelimToken::Bracket) |
Comma | FatArrow | Colon | Eq | Gt | BinOp(token::Shr) | Semi | Comma | FatArrow | Colon | Eq | Gt | BinOp(token::Shr) | Semi |
BinOp(token::Or) => IsInFollow::Yes, BinOp(token::Or) => IsInFollow::Yes,
Ident(i, false) if i.name == keywords::As.name() || Ident(i, false) if i.name == kw::As ||
i.name == keywords::Where.name() => IsInFollow::Yes, i.name == kw::Where => IsInFollow::Yes,
_ => IsInFollow::No(tokens), _ => IsInFollow::No(tokens),
}, },
TokenTree::MetaVarDecl(_, _, frag) if frag.name == sym::block => TokenTree::MetaVarDecl(_, _, frag) if frag.name == sym::block =>
@ -1092,7 +1092,7 @@ fn is_in_follow(tok: &quoted::TokenTree, frag: &str) -> IsInFollow {
match *tok { match *tok {
TokenTree::Token(_, ref tok) => match *tok { TokenTree::Token(_, ref tok) => match *tok {
Comma => IsInFollow::Yes, Comma => IsInFollow::Yes,
Ident(i, is_raw) if is_raw || i.name != keywords::Priv.name() => Ident(i, is_raw) if is_raw || i.name != kw::Priv =>
IsInFollow::Yes, IsInFollow::Yes,
ref tok => if tok.can_begin_type() { ref tok => if tok.can_begin_type() {
IsInFollow::Yes IsInFollow::Yes

View file

@ -22,7 +22,7 @@ use crate::source_map::Spanned;
use crate::edition::{ALL_EDITIONS, Edition}; use crate::edition::{ALL_EDITIONS, Edition};
use crate::visit::{self, FnKind, Visitor}; use crate::visit::{self, FnKind, Visitor};
use crate::parse::{token, ParseSess}; use crate::parse::{token, ParseSess};
use crate::symbol::{Symbol, keywords, sym}; use crate::symbol::{Symbol, kw, sym};
use crate::tokenstream::TokenTree; use crate::tokenstream::TokenTree;
use errors::{DiagnosticBuilder, Handler}; use errors::{DiagnosticBuilder, Handler};
@ -1948,7 +1948,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
fn visit_item(&mut self, i: &'a ast::Item) { fn visit_item(&mut self, i: &'a ast::Item) {
match i.node { match i.node {
ast::ItemKind::Const(_,_) => { ast::ItemKind::Const(_,_) => {
if i.ident.name == keywords::Underscore.name() { if i.ident.name == kw::Underscore {
gate_feature_post!(&self, underscore_const_names, i.span, gate_feature_post!(&self, underscore_const_names, i.span,
"naming constants with `_` is unstable"); "naming constants with `_` is unstable");
} }

View file

@ -6,7 +6,7 @@ use crate::parse::PResult;
use crate::parse::Parser; use crate::parse::Parser;
use crate::print::pprust; use crate::print::pprust;
use crate::ptr::P; use crate::ptr::P;
use crate::symbol::keywords; use crate::symbol::kw;
use crate::ThinVec; use crate::ThinVec;
use errors::{Applicability, DiagnosticBuilder}; use errors::{Applicability, DiagnosticBuilder};
use syntax_pos::Span; use syntax_pos::Span;
@ -405,7 +405,7 @@ impl<'a> Parser<'a> {
/// Recover from `pub` keyword in places where it seems _reasonable_ but isn't valid. /// Recover from `pub` keyword in places where it seems _reasonable_ but isn't valid.
crate fn eat_bad_pub(&mut self) { crate fn eat_bad_pub(&mut self) {
if self.token.is_keyword(keywords::Pub) { if self.token.is_keyword(kw::Pub) {
match self.parse_visibility(false) { match self.parse_visibility(false) {
Ok(vis) => { Ok(vis) => {
self.diagnostic() self.diagnostic()

View file

@ -43,8 +43,8 @@ impl LitKind {
Some(match lit { Some(match lit {
token::Bool(i) => { token::Bool(i) => {
assert!(i == keywords::True.name() || i == keywords::False.name()); assert!(i == kw::True || i == kw::False);
LitKind::Bool(i == keywords::True.name()) LitKind::Bool(i == kw::True)
} }
token::Byte(i) => { token::Byte(i) => {
match unescape_byte(&i.as_str()) { match unescape_byte(&i.as_str()) {
@ -156,8 +156,8 @@ impl LitKind {
} }
LitKind::FloatUnsuffixed(symbol) => (token::Lit::Float(symbol), None), LitKind::FloatUnsuffixed(symbol) => (token::Lit::Float(symbol), None),
LitKind::Bool(value) => { LitKind::Bool(value) => {
let kw = if value { keywords::True } else { keywords::False }; let kw = if value { kw::True } else { kw::False };
(token::Lit::Bool(kw.name()), None) (token::Lit::Bool(kw), None)
} }
LitKind::Err(val) => (token::Lit::Err(val), None), LitKind::Err(val) => (token::Lit::Err(val), None),
} }
@ -175,8 +175,7 @@ impl Lit {
diag: Option<(Span, &Handler)>, diag: Option<(Span, &Handler)>,
) -> Option<Lit> { ) -> Option<Lit> {
let (token, suffix) = match *token { let (token, suffix) = match *token {
token::Ident(ident, false) if ident.name == keywords::True.name() || token::Ident(ident, false) if ident.name == kw::True || ident.name == kw::False =>
ident.name == keywords::False.name() =>
(token::Bool(ident.name), None), (token::Bool(ident.name), None),
token::Literal(token, suffix) => token::Literal(token, suffix) =>
(token, suffix), (token, suffix),

View file

@ -215,7 +215,7 @@ fn mk_reexport_mod(cx: &mut TestCtxt<'_>,
tests: Vec<Ident>, tests: Vec<Ident>,
tested_submods: Vec<(Ident, Ident)>) tested_submods: Vec<(Ident, Ident)>)
-> (P<ast::Item>, Ident) { -> (P<ast::Item>, Ident) {
let super_ = Ident::with_empty_ctxt(keywords::Super.name()); let super_ = Ident::with_empty_ctxt(kw::Super);
let items = tests.into_iter().map(|r| { let items = tests.into_iter().map(|r| {
cx.ext_cx.item_use_simple(DUMMY_SP, dummy_spanned(ast::VisibilityKind::Public), cx.ext_cx.item_use_simple(DUMMY_SP, dummy_spanned(ast::VisibilityKind::Public),

View file

@ -951,6 +951,11 @@ impl Symbol {
fn is_unused_keyword_2018(self) -> bool { fn is_unused_keyword_2018(self) -> bool {
self >= kw::Async && self <= kw::Try self >= kw::Async && self <= kw::Try
} }
/// Used for sanity checking rustdoc keyword sections.
pub fn is_doc_keyword(self) -> bool {
self <= kw::Union
}
} }
impl Ident { impl Ident {