mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-18 03:25:55 +00:00
Merge pull request #778 from mcarton/fix-new_without_default
Fix `new_without_default` with lts and generics
This commit is contained in:
commit
6ce7737d47
@ -51,6 +51,7 @@ impl LateLintPass for NewWithoutDefault {
|
||||
let self_ty = cx.tcx.lookup_item_type(cx.tcx.map.local_def_id(cx.tcx.map.get_parent(id))).ty;
|
||||
|
||||
if_let_chain!{[
|
||||
self_ty.walk_shallow().next().is_none(), // implements_trait does not work with generics
|
||||
let Some(ret_ty) = return_ty(cx.tcx.node_id_to_type(id)),
|
||||
same_tys(cx, self_ty, ret_ty),
|
||||
let Some(default_trait_id) = get_trait_def_id(cx, &DEFAULT_TRAIT_PATH),
|
||||
|
@ -270,6 +270,7 @@ pub fn implements_trait<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: ty::Ty<'tcx>,
|
||||
-> bool {
|
||||
cx.tcx.populate_implementations_for_trait_if_necessary(trait_id);
|
||||
|
||||
let ty = cx.tcx.erase_regions(&ty);
|
||||
let infcx = infer::new_infer_ctxt(cx.tcx, &cx.tcx.tables, None, ProjectionMode::Any);
|
||||
let obligation = traits::predicate_for_trait_def(cx.tcx,
|
||||
traits::ObligationCause::dummy(),
|
||||
|
@ -32,13 +32,36 @@ impl Params {
|
||||
fn new(_: u32) -> Self { Params }
|
||||
}
|
||||
|
||||
struct Generics<'a, T> {
|
||||
foo: &'a bool,
|
||||
struct GenericsOk<T> {
|
||||
bar: T,
|
||||
}
|
||||
|
||||
impl<'c, V> Generics<'c, V> {
|
||||
fn new<'b>() -> Generics<'b, V> { unimplemented!() } //~ERROR: you should consider adding a `Default` implementation for
|
||||
impl<U> Default for GenericsOk<U> {
|
||||
fn default() -> Self { unimplemented!(); }
|
||||
}
|
||||
|
||||
impl<'c, V> GenericsOk<V> {
|
||||
fn new() -> GenericsOk<V> { unimplemented!() }
|
||||
}
|
||||
|
||||
struct LtOk<'a> {
|
||||
foo: &'a bool,
|
||||
}
|
||||
|
||||
impl<'b> Default for LtOk<'b> {
|
||||
fn default() -> Self { unimplemented!(); }
|
||||
}
|
||||
|
||||
impl<'c> LtOk<'c> {
|
||||
fn new() -> LtOk<'c> { unimplemented!() }
|
||||
}
|
||||
|
||||
struct LtKo<'a> {
|
||||
foo: &'a bool,
|
||||
}
|
||||
|
||||
impl<'c> LtKo<'c> {
|
||||
fn new() -> LtKo<'c> { unimplemented!() } //~ERROR: you should consider adding a `Default` implementation for
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
Loading…
Reference in New Issue
Block a user