]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #3700 - phansch:would_you_like_some_help_with_this_const_fn, r=oli-obk
authorbors <bors@rust-lang.org>
Mon, 28 Jan 2019 14:30:18 +0000 (14:30 +0000)
committerbors <bors@rust-lang.org>
Mon, 28 Jan 2019 14:30:18 +0000 (14:30 +0000)
Prevent incorrect cast_lossless suggestion in const_fn

`::from` is not a const fn, so applying the suggestion of
`cast_lossless` would fail to compile. The fix is to skip the lint if
the cast is found inside a const fn.

Fixes #3656

1  2 
clippy_lints/src/utils/mod.rs

index af9b1599649dc21d49d906c3efb4fc3d48b86b9a,9df0896068ad631d9a590394bba17e5d6d2668bd..2b2b3e8b2f6a58b807aff8b7aaccb493f7925d3a
@@@ -82,6 -82,10 +82,10 @@@ pub fn in_constant(cx: &LateContext<'_
              node: ItemKind::Static(..),
              ..
          }) => true,
+         Node::Item(&Item {
+             node: ItemKind::Fn(_, header, ..),
+             ..
+         }) => header.constness == Constness::Const,
          _ => false,
      }
  }
@@@ -693,7 -697,7 +697,7 @@@ pub fn span_lint_and_sugg<'a, 'tcx: 'a
      applicability: Applicability,
  ) {
      span_lint_and_then(cx, lint, sp, msg, |db| {
 -        db.span_suggestion_with_applicability(sp, help, sugg, applicability);
 +        db.span_suggestion(sp, help, sugg, applicability);
      });
  }