Don't see {{}}
as placeholder in panic_fmt lint.
This commit is contained in:
parent
dd262e3856
commit
9615d27ab7
@ -47,19 +47,18 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
|
|||||||
fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tcx hir::Expr<'tcx>) {
|
fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tcx hir::Expr<'tcx>) {
|
||||||
if let hir::ExprKind::Lit(lit) = &arg.kind {
|
if let hir::ExprKind::Lit(lit) = &arg.kind {
|
||||||
if let ast::LitKind::Str(sym, _) = lit.node {
|
if let ast::LitKind::Str(sym, _) = lit.node {
|
||||||
let s = sym.as_str();
|
|
||||||
let open = s.find('{');
|
|
||||||
let close = s[open.unwrap_or(0)..].find('}');
|
|
||||||
let looks_like_placeholder = match (open, close) {
|
|
||||||
(Some(_), Some(_)) => true,
|
|
||||||
(Some(_), None) | (None, Some(_)) => false,
|
|
||||||
(None, None) => return, // OK, no braces.
|
|
||||||
};
|
|
||||||
let expn = f.span.ctxt().outer_expn_data();
|
let expn = f.span.ctxt().outer_expn_data();
|
||||||
if let Some(id) = expn.macro_def_id {
|
if let Some(id) = expn.macro_def_id {
|
||||||
if cx.tcx.is_diagnostic_item(sym::std_panic_macro, id)
|
if cx.tcx.is_diagnostic_item(sym::std_panic_macro, id)
|
||||||
|| cx.tcx.is_diagnostic_item(sym::core_panic_macro, id)
|
|| cx.tcx.is_diagnostic_item(sym::core_panic_macro, id)
|
||||||
{
|
{
|
||||||
|
let s = sym.as_str();
|
||||||
|
if !s.contains(&['{', '}'][..]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let s = s.replace("{{", "").replace("}}", "");
|
||||||
|
let looks_like_placeholder =
|
||||||
|
s.find('{').map_or(false, |i| s[i + 1..].contains('}'));
|
||||||
let expn = {
|
let expn = {
|
||||||
// Unwrap another level of macro expansion if this
|
// Unwrap another level of macro expansion if this
|
||||||
// panic!() was expanded from assert!().
|
// panic!() was expanded from assert!().
|
||||||
|
Loading…
Reference in New Issue
Block a user