Skip to content

Commit a48c735

Browse files
authored
Rollup merge of #108801 - fee1-dead-contrib:c-str, r=compiler-errors
Implement RFC 3348, `c"foo"` literals RFC: rust-lang/rfcs#3348 Tracking issue: #105723
2 parents 8518391 + f7595e0 commit a48c735

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

clippy_lints/src/matches/match_same_arms.rs

+1
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ impl<'a> NormalizedPat<'a> {
284284
LitKind::Str(sym, _) => Self::LitStr(sym),
285285
LitKind::ByteStr(ref bytes, _) => Self::LitBytes(bytes),
286286
LitKind::Byte(val) => Self::LitInt(val.into()),
287+
LitKind::CStr(ref bytes, _) => Self::LitBytes(bytes),
287288
LitKind::Char(val) => Self::LitInt(val.into()),
288289
LitKind::Int(val, _) => Self::LitInt(val),
289290
LitKind::Bool(val) => Self::LitBool(val),

clippy_lints/src/strlen_on_c_strings.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::snippet_with_context;
3-
use clippy_utils::ty::is_type_diagnostic_item;
3+
use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item};
44
use clippy_utils::visitors::is_expr_unsafe;
55
use clippy_utils::{get_parent_node, match_libc_symbol};
66
use if_chain::if_chain;
77
use rustc_errors::Applicability;
8-
use rustc_hir::{Block, BlockCheckMode, Expr, ExprKind, Node, UnsafeSource};
8+
use rustc_hir::{Block, BlockCheckMode, Expr, ExprKind, LangItem, Node, UnsafeSource};
99
use rustc_lint::{LateContext, LateLintPass};
1010
use rustc_session::{declare_lint_pass, declare_tool_lint};
1111
use rustc_span::symbol::sym;
@@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for StrlenOnCStrings {
6767
let val_name = snippet_with_context(cx, self_arg.span, ctxt, "..", &mut app).0;
6868
let method_name = if is_type_diagnostic_item(cx, ty, sym::cstring_type) {
6969
"as_bytes"
70-
} else if is_type_diagnostic_item(cx, ty, sym::CStr) {
70+
} else if is_type_lang_item(cx, ty, LangItem::CStr) {
7171
"to_bytes"
7272
} else {
7373
return;

clippy_lints/src/utils/author.rs

+5
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
304304
kind!("ByteStr(ref {vec})");
305305
chain!(self, "let [{:?}] = **{vec}", vec.value);
306306
},
307+
LitKind::CStr(ref vec, _) => {
308+
bind!(self, vec);
309+
kind!("CStr(ref {vec})");
310+
chain!(self, "let [{:?}] = **{vec}", vec.value);
311+
}
307312
LitKind::Str(s, _) => {
308313
bind!(self, s);
309314
kind!("Str({s}, _)");

clippy_utils/src/consts.rs

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ pub fn lit_to_mir_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
211211
LitKind::Str(ref is, _) => Constant::Str(is.to_string()),
212212
LitKind::Byte(b) => Constant::Int(u128::from(b)),
213213
LitKind::ByteStr(ref s, _) => Constant::Binary(Lrc::clone(s)),
214+
LitKind::CStr(ref s, _) => Constant::Binary(Lrc::clone(s)),
214215
LitKind::Char(c) => Constant::Char(c),
215216
LitKind::Int(n, _) => Constant::Int(n),
216217
LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty {

0 commit comments

Comments
 (0)