Skip to content

Commit 28ead17

Browse files
authoredAug 23, 2022
Rollup merge of #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

+6-4
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

+2-2
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

‎src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl<'a> NormalizedPat<'a> {
290290
LitKind::Char(val) => Self::LitInt(val.into()),
291291
LitKind::Int(val, _) => Self::LitInt(val),
292292
LitKind::Bool(val) => Self::LitBool(val),
293-
LitKind::Float(..) | LitKind::Err(_) => Self::Wild,
293+
LitKind::Float(..) | LitKind::Err => Self::Wild,
294294
},
295295
_ => Self::Wild,
296296
},

‎src/tools/clippy/clippy_lints/src/utils/author.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
276276
match lit.value.node {
277277
LitKind::Bool(val) => kind!("Bool({val:?})"),
278278
LitKind::Char(c) => kind!("Char({c:?})"),
279-
LitKind::Err(val) => kind!("Err({val})"),
279+
LitKind::Err => kind!("Err"),
280280
LitKind::Byte(b) => kind!("Byte({b})"),
281281
LitKind::Int(i, suffix) => {
282282
let int_ty = match suffix {

‎src/tools/clippy/clippy_utils/src/consts.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub enum Constant {
4545
/// A reference
4646
Ref(Box<Constant>),
4747
/// A literal with syntax error.
48-
Err(Symbol),
48+
Err,
4949
}
5050

5151
impl PartialEq for Constant {
@@ -118,9 +118,7 @@ impl Hash for Constant {
118118
Self::Ref(ref r) => {
119119
r.hash(state);
120120
},
121-
Self::Err(ref s) => {
122-
s.hash(state);
123-
},
121+
Self::Err => {},
124122
}
125123
}
126124
}
@@ -194,7 +192,7 @@ pub fn lit_to_mir_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
194192
_ => bug!(),
195193
},
196194
LitKind::Bool(b) => Constant::Bool(b),
197-
LitKind::Err(s) => Constant::Err(s),
195+
LitKind::Err => Constant::Err,
198196
}
199197
}
200198

0 commit comments

Comments
 (0)