Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 28ead17

Browse files
authored
Rollup merge of rust-lang#100909 - nnethercote:minor-ast-LitKind-improvement, r=petrochenkov
Minor `ast::LitKind` improvements r? `@petrochenkov`
2 parents 12c1ac0 + 6087dc2 commit 28ead17

File tree

13 files changed

+21
-21
lines changed

13 files changed

+21
-21
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,8 @@ pub enum LitFloatType {
17511751
/// E.g., `"foo"`, `42`, `12.34`, or `bool`.
17521752
#[derive(Clone, Encodable, Decodable, Debug, Hash, Eq, PartialEq, HashStable_Generic)]
17531753
pub enum LitKind {
1754-
/// A string literal (`"foo"`).
1754+
/// A string literal (`"foo"`). The symbol is unescaped, and so may differ
1755+
/// from the original token's symbol.
17551756
Str(Symbol, StrStyle),
17561757
/// A byte string (`b"foo"`).
17571758
ByteStr(Lrc<[u8]>),
@@ -1761,12 +1762,13 @@ pub enum LitKind {
17611762
Char(char),
17621763
/// An integer literal (`1`).
17631764
Int(u128, LitIntType),
1764-
/// A float literal (`1f64` or `1E10f64`).
1765+
/// A float literal (`1f64` or `1E10f64`). Stored as a symbol rather than
1766+
/// `f64` so that `LitKind` can impl `Eq` and `Hash`.
17651767
Float(Symbol, LitFloatType),
17661768
/// A boolean literal.
17671769
Bool(bool),
17681770
/// Placeholder for a literal that wasn't well-formed in some way.
1769-
Err(Symbol),
1771+
Err,
17701772
}
17711773

17721774
impl LitKind {
@@ -1805,7 +1807,7 @@ impl LitKind {
18051807
| LitKind::Int(_, LitIntType::Unsuffixed)
18061808
| LitKind::Float(_, LitFloatType::Unsuffixed)
18071809
| LitKind::Bool(..)
1808-
| LitKind::Err(..) => false,
1810+
| LitKind::Err => false,
18091811
}
18101812
}
18111813
}

compiler/rustc_ast/src/util/literal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl LitKind {
146146

147147
LitKind::ByteStr(bytes.into())
148148
}
149-
token::Err => LitKind::Err(symbol),
149+
token::Err => LitKind::Err,
150150
})
151151
}
152152

@@ -199,7 +199,7 @@ impl LitKind {
199199
let symbol = if value { kw::True } else { kw::False };
200200
(token::Bool, symbol, None)
201201
}
202-
LitKind::Err(symbol) => (token::Err, symbol, None),
202+
LitKind::Err => unreachable!(),
203203
};
204204

205205
token::Lit::new(kind, symbol, suffix)

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
928928
} else {
929929
Lit {
930930
token_lit: token::Lit::new(token::LitKind::Err, kw::Empty, None),
931-
kind: LitKind::Err(kw::Empty),
931+
kind: LitKind::Err,
932932
span: DUMMY_SP,
933933
}
934934
};

compiler/rustc_builtin_macros/src/concat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn expand_concat(
3939
ast::LitKind::Byte(..) | ast::LitKind::ByteStr(..) => {
4040
cx.span_err(e.span, "cannot concatenate a byte string literal");
4141
}
42-
ast::LitKind::Err(_) => {
42+
ast::LitKind::Err => {
4343
has_errors = true;
4444
}
4545
},

compiler/rustc_builtin_macros/src/concat_bytes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn invalid_type_err(cx: &mut base::ExtCtxt<'_>, expr: &P<rustc_ast::Expr>, is_ne
4242
ast::LitKind::Bool(_) => {
4343
cx.span_err(expr.span, "cannot concatenate boolean literals");
4444
}
45-
ast::LitKind::Err(_) => {}
45+
ast::LitKind::Err => {}
4646
ast::LitKind::Int(_, _) if !is_nested => {
4747
let mut err = cx.struct_span_err(expr.span, "cannot concatenate numeric literals");
4848
if let Ok(snippet) = cx.sess.source_map().span_to_snippet(expr.span) {

compiler/rustc_expand/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ pub fn expr_to_spanned_string<'a>(
12271227
);
12281228
Some((err, true))
12291229
}
1230-
ast::LitKind::Err(_) => None,
1230+
ast::LitKind::Err => None,
12311231
_ => Some((cx.struct_span_err(l.span, err_msg), false)),
12321232
},
12331233
ast::ExprKind::Err => None,

compiler/rustc_mir_build/src/build/expr/as_constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pub(crate) fn lit_to_mir_constant<'tcx>(
144144
}
145145
(ast::LitKind::Bool(b), ty::Bool) => ConstValue::Scalar(Scalar::from_bool(*b)),
146146
(ast::LitKind::Char(c), ty::Char) => ConstValue::Scalar(Scalar::from_char(*c)),
147-
(ast::LitKind::Err(_), _) => return Err(LitToConstError::Reported),
147+
(ast::LitKind::Err, _) => return Err(LitToConstError::Reported),
148148
_ => return Err(LitToConstError::TypeError),
149149
};
150150

compiler/rustc_mir_build/src/thir/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub(crate) fn lit_to_const<'tcx>(
4444
}
4545
(ast::LitKind::Bool(b), ty::Bool) => ty::ValTree::from_scalar_int((*b).into()),
4646
(ast::LitKind::Char(c), ty::Char) => ty::ValTree::from_scalar_int((*c).into()),
47-
(ast::LitKind::Err(_), _) => return Err(LitToConstError::Reported),
47+
(ast::LitKind::Err, _) => return Err(LitToConstError::Reported),
4848
_ => return Err(LitToConstError::TypeError),
4949
};
5050

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ impl<'a> Parser<'a> {
13831383
match self.parse_str_lit() {
13841384
Ok(str_lit) => Some(str_lit),
13851385
Err(Some(lit)) => match lit.kind {
1386-
ast::LitKind::Err(_) => None,
1386+
ast::LitKind::Err => None,
13871387
_ => {
13881388
self.struct_span_err(lit.span, "non-string ABI literal")
13891389
.span_suggestion(

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11361136
opt_ty.unwrap_or_else(|| self.next_float_var())
11371137
}
11381138
ast::LitKind::Bool(_) => tcx.types.bool,
1139-
ast::LitKind::Err(_) => tcx.ty_error(),
1139+
ast::LitKind::Err => tcx.ty_error(),
11401140
}
11411141
}
11421142

0 commit comments

Comments
 (0)