diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 15bb782452e..dfaefb39ba0 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -95,7 +95,11 @@ impl LateLintPass for NewWithoutDefault { return; } - if let FnKind::Method(name, _, _, _) = kind { + if let FnKind::Method(name, ref sig, _, _) = kind { + if sig.constness == hir::Constness::Const { + // can't be implemented by default + return; + } if decl.inputs.is_empty() && name.as_str() == "new" && cx.access_levels.is_reachable(id) { let self_ty = cx.tcx.lookup_item_type(cx.tcx.map.local_def_id( diff --git a/tests/compile-fail/new_without_default.rs b/tests/compile-fail/new_without_default.rs index 042fab840c1..e3a8024dde1 100644 --- a/tests/compile-fail/new_without_default.rs +++ b/tests/compile-fail/new_without_default.rs @@ -1,4 +1,4 @@ -#![feature(plugin)] +#![feature(plugin, const_fn)] #![plugin(clippy)] #![allow(dead_code)] @@ -70,4 +70,9 @@ impl Private { fn new() -> Private { unimplemented!() } // We don't lint private items } +struct Const; + +impl Const { + pub const fn new() -> Const { Const } // const fns can't be implemented via Default +} fn main() {}