Auto merge of #3700 - phansch:would_you_like_some_help_with_this_const_fn, r=oli-obk

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
This commit is contained in:
bors
2019-01-28 14:30:18 +00:00
7 changed files with 72 additions and 36 deletions

View File

@@ -82,6 +82,10 @@ pub fn in_constant(cx: &LateContext<'_, '_>, id: NodeId) -> bool {
node: ItemKind::Static(..),
..
}) => true,
Node::Item(&Item {
node: ItemKind::Fn(_, header, ..),
..
}) => header.constness == Constness::Const,
_ => false,
}
}