Skip to content
Permalink
Browse files

Rename `Lit.node` to `Lit.kind`

  • Loading branch information...
varkor committed Sep 26, 2019
1 parent ce6aabb commit 17726f6b52b68279384cfb13209f015ab491c1c0
@@ -54,7 +54,7 @@ impl LoweringContext<'_> {
let ohs = P(self.lower_expr(ohs));
hir::ExprKind::Unary(op, ohs)
}
ExprKind::Lit(ref l) => hir::ExprKind::Lit(respan(l.span, l.node.clone())),
ExprKind::Lit(ref l) => hir::ExprKind::Lit(respan(l.span, l.kind.clone())),
ExprKind::Cast(ref expr, ref ty) => {
let expr = P(self.lower_expr(expr));
hir::ExprKind::Cast(expr, self.lower_ty(ty, ImplTraitContext::disallowed()))
@@ -142,7 +142,7 @@ impl_stable_hash_for!(enum ::syntax::ast::LitIntType {
});

impl_stable_hash_for!(struct ::syntax::ast::Lit {
node,
kind,
token,
span
});
@@ -226,7 +226,7 @@ impl<'a> LintLevelsBuilder<'a> {
metas = &metas[0..metas.len()-1];
// FIXME (#55112): issue unused-attributes lint if we thereby
// don't have any lint names (`#[level(reason = "foo")]`)
if let ast::LitKind::Str(rationale, _) = name_value.node {
if let ast::LitKind::Str(rationale, _) = name_value.kind {
if !self.sess.features_untracked().lint_reasons {
feature_gate::emit_feature_err(
&self.sess.parse_sess,
@@ -1883,7 +1883,7 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String
MetaItemKind::List(..) => {
error!(r#"expected `key` or `key="value"`"#);
}
MetaItemKind::NameValue(lit) if !lit.node.is_str() => {
MetaItemKind::NameValue(lit) if !lit.kind.is_str() => {
error!("argument value must be a string");
}
MetaItemKind::NameValue(..) | MetaItemKind::Word => {
@@ -1150,7 +1150,7 @@ impl<'tcx> TyCtxt<'tcx> {
None => return Bound::Unbounded,
};
for meta in attr.meta_item_list().expect("rustc_layout_scalar_valid_range takes args") {
match meta.literal().expect("attribute takes lit").node {
match meta.literal().expect("attribute takes lit").kind {
ast::LitKind::Int(a, _) => return Bound::Included(a),
_ => span_bug!(attr.span, "rustc_layout_scalar_valid_range expects int arg"),
}
@@ -77,7 +77,7 @@ impl EarlyLintPass for WhileTrue {
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
if let ast::ExprKind::While(cond, ..) = &e.kind {
if let ast::ExprKind::Lit(ref lit) = pierce_parens(cond).kind {
if let ast::LitKind::Bool(true) = lit.node {
if let ast::LitKind::Bool(true) = lit.kind {
if !lit.span.from_expansion() {
let msg = "denote infinite loops with `loop { ... }`";
let condition_span = cx.sess.source_map().def_span(e.span);
@@ -258,7 +258,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
.and_then(|attr| attr.meta())
.and_then(|meta| {
meta.name_value_literal().and_then(|lit| {
if let ast::LitKind::Str(name, ..) = lit.node {
if let ast::LitKind::Str(name, ..) = lit.kind {
// Discard the double quotes surrounding the literal.
let sp = cx.sess().source_map().span_to_snippet(lit.span)
.ok()
@@ -1768,7 +1768,7 @@ fn args_required_const(tcx: TyCtxt<'_>, def_id: DefId) -> Option<FxHashSet<usize
let attr = attrs.iter().find(|a| a.check_name(sym::rustc_args_required_const))?;
let mut ret = FxHashSet::default();
for meta in attr.meta_item_list()? {
match meta.literal()?.node {
match meta.literal()?.kind {
LitKind::Int(a, _) => { ret.insert(a as usize); }
_ => return None,
}
@@ -70,7 +70,7 @@ impl Cfg {
};
match cfg.node {
MetaItemKind::Word => Ok(Cfg::Cfg(name, None)),
MetaItemKind::NameValue(ref lit) => match lit.node {
MetaItemKind::NameValue(ref lit) => match lit.kind {
LitKind::Str(value, _) => Ok(Cfg::Cfg(name, Some(value))),
_ => Err(InvalidCfgError {
// FIXME: if the main #[cfg] syntax decided to support non-string literals,
@@ -1361,7 +1361,7 @@ pub struct Lit {
/// The "semantic" representation of the literal lowered from the original tokens.
/// Strings are unescaped, hexadecimal forms are eliminated, etc.
/// FIXME: Remove this and only create the semantic representation during lowering to HIR.
pub node: LitKind,
pub kind: LitKind,
pub span: Span,
}

@@ -36,7 +36,7 @@ impl AttributeTemplate {
match meta_item_kind {
ast::MetaItemKind::Word => self.word,
ast::MetaItemKind::List(..) => self.list.is_some(),
ast::MetaItemKind::NameValue(lit) if lit.node.is_str() => self.name_value_str.is_some(),
ast::MetaItemKind::NameValue(lit) if lit.kind.is_str() => self.name_value_str.is_some(),
ast::MetaItemKind::NameValue(..) => false,
}
}
@@ -538,13 +538,13 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat
MetaItemKind::List(..) => {
error(cfg.span, "unexpected parentheses after `cfg` predicate key")
}
MetaItemKind::NameValue(lit) if !lit.node.is_str() => {
MetaItemKind::NameValue(lit) if !lit.kind.is_str() => {
handle_errors(
sess,
lit.span,
AttrError::UnsupportedLiteral(
"literal in `cfg` predicate value must be a string",
lit.node.is_bytestr()
lit.kind.is_bytestr()
),
);
true
@@ -668,7 +668,7 @@ fn find_deprecation_generic<'a, I>(sess: &ParseSess,
AttrError::UnsupportedLiteral(
"literal in `deprecated` \
value must be a string",
lit.node.is_bytestr()
lit.kind.is_bytestr()
),
);
} else {
@@ -811,14 +811,14 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec<ReprAttr> {
let mut literal_error = None;
if name == sym::align {
recognised = true;
match parse_alignment(&value.node) {
match parse_alignment(&value.kind) {
Ok(literal) => acc.push(ReprAlign(literal)),
Err(message) => literal_error = Some(message)
};
}
else if name == sym::packed {
recognised = true;
match parse_alignment(&value.node) {
match parse_alignment(&value.kind) {
Ok(literal) => acc.push(ReprPacked(literal)),
Err(message) => literal_error = Some(message)
};
@@ -834,7 +834,7 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec<ReprAttr> {
recognised = true;
let mut err = struct_span_err!(diagnostic, item.span(), E0693,
"incorrect `repr(align)` attribute format");
match value.node {
match value.kind {
ast::LitKind::Int(int, ast::LitIntType::Unsuffixed) => {
err.span_suggestion(
item.span(),
@@ -219,7 +219,7 @@ impl MetaItem {
pub fn value_str(&self) -> Option<Symbol> {
match self.node {
MetaItemKind::NameValue(ref v) => {
match v.node {
match v.kind {
LitKind::Str(ref s, _) => Some(*s),
_ => None,
}
@@ -1099,7 +1099,7 @@ pub fn expr_to_spanned_string<'a>(
let expr = cx.expander().fully_expand_fragment(AstFragment::Expr(expr)).make_expr();

Err(match expr.kind {
ast::ExprKind::Lit(ref l) => match l.node {
ast::ExprKind::Lit(ref l) => match l.kind {
ast::LitKind::Str(s, style) => return Ok((s, style, expr.span)),
ast::LitKind::Err(_) => None,
_ => Some(cx.struct_span_err(l.span, err_msg))
@@ -1504,7 +1504,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
// Check if the user erroneously used `doc(include(...))` syntax.
let literal = it.meta_item_list().and_then(|list| {
if list.len() == 1 {
list[0].literal().map(|literal| &literal.node)
list[0].literal().map(|literal| &literal.kind)
} else {
None
}
@@ -249,7 +249,7 @@ impl<'a> Parser<'a> {
let lit = self.parse_lit()?;
debug!("checking if {:?} is unusuffixed", lit);

if !lit.node.is_unsuffixed() {
if !lit.kind.is_unsuffixed() {
let msg = "suffixed literals are not allowed in attributes";
self.diagnostic().struct_span_err(lit.span, msg)
.help("instead of using a suffixed literal \
@@ -255,7 +255,7 @@ impl LitKind {
impl Lit {
/// Converts literal token into an AST literal.
fn from_lit_token(token: token::Lit, span: Span) -> Result<Lit, LitError> {
Ok(Lit { token, node: LitKind::from_lit_token(token)?, span })
Ok(Lit { token, kind: LitKind::from_lit_token(token)?, span })
}

/// Converts arbitrary token into an AST literal.
@@ -282,8 +282,8 @@ impl Lit {
/// Attempts to recover an AST literal from semantic literal.
/// This function is used when the original token doesn't exist (e.g. the literal is created
/// by an AST-based macro) or unavailable (e.g. from HIR pretty-printing).
pub fn from_lit_kind(node: LitKind, span: Span) -> Lit {
Lit { token: node.to_lit_token(), node, span }
pub fn from_lit_kind(kind: LitKind, span: Span) -> Lit {
Lit { token: kind.to_lit_token(), kind, span }
}

/// Losslessly convert an AST literal into a token stream.
@@ -19,7 +19,7 @@ pub fn expand_concat(
let mut has_errors = false;
for e in es {
match e.kind {
ast::ExprKind::Lit(ref lit) => match lit.node {
ast::ExprKind::Lit(ref lit) => match lit.kind {
ast::LitKind::Str(ref s, _)
| ast::LitKind::Float(ref s, _)
| ast::LitKind::FloatUnsuffixed(ref s) => {

0 comments on commit 17726f6

Please sign in to comment.
You can’t perform that action at this time.