{"action":"created","comment":{"url":"https://api.github.com/repos/Manishearth/rust-clippy/pulls/comments/63614063","id":63614063,"diff_hunk":"@@ -66,19 +97,53 @@ impl LateLintPass for NewWithoutDefault {\n \n         if let FnKind::Method(name, _, _, _) = kind {\n             if decl.inputs.is_empty() && name.as_str() == \"new\" {\n-                let self_ty = cx.tcx.lookup_item_type(cx.tcx.map.local_def_id(cx.tcx.map.get_parent(id))).ty;\n-\n+                let self_ty = cx.tcx.lookup_item_type(cx.tcx.map.local_def_id(\n+                    cx.tcx.map.get_parent(id))).ty;\n                 if_let_chain!{[\n                     self_ty.walk_shallow().next().is_none(), // implements_trait does not work with generics\n                     let Some(ret_ty) = return_ty(cx, id),\n                     same_tys(cx, self_ty, ret_ty, id),\n                     let Some(default_trait_id) = get_trait_def_id(cx, &paths::DEFAULT_TRAIT),\n                     !implements_trait(cx, self_ty, default_trait_id, Vec::new())\n                 ], {\n-                    span_lint(cx, NEW_WITHOUT_DEFAULT, span,\n-                              &format!(\"you should consider adding a `Default` implementation for `{}`\", self_ty));\n+                    if can_derive_default(self_ty, cx, default_trait_id) {\n+                        span_lint(cx,\n+                                  NEW_WITHOUT_DEFAULT_DERIVE, span,\n+                                  &format!(\"you should consider deriving a \\\n+                                           `Default` implementation for `{}`\",\n+                                           self_ty)).\n+                                  span_suggestion(span,\n+                                                  \"try this\",\n+                                                  \"#[derive(Default)]\".into());\n+                    } else {\n+                        span_lint(cx,\n+                                  NEW_WITHOUT_DEFAULT, span,\n+                                  &format!(\"you should consider adding a \\\n+                                           `Default` implementation for `{}`\",\n+                                           self_ty)).\n+                                  span_suggestion(span,\n+                                                  \"try this\",\n+                             format!(\"impl Default for {} {{ fn default() -> \\\n+                                    Self {{ {}::new() }} }}\", self_ty, self_ty));\n+                    }\n                 }}\n             }\n         }\n     }\n }\n+\n+fn can_derive_default<'t, 'c>(ty: ty::Ty<'t>, cx: &LateContext<'c, 't>, default_trait_id: DefId) -> bool {\n+    match ty.sty {\n+        ty::TyEnum(ref adt_def, ref substs) |","path":"src/new_without_default.rs","position":131,"original_position":131,"commit_id":"ec953a74321711626c5228e73506d1fa9cd1e7be","original_commit_id":"ec953a74321711626c5228e73506d1fa9cd1e7be","user":{"login":"llogiq","id":4200835,"avatar_url":"https://avatars.githubusercontent.com/u/4200835?v=3","gravatar_id":"","url":"https://api.github.com/users/llogiq","html_url":"https://github.com/llogiq","followers_url":"https://api.github.com/users/llogiq/followers","following_url":"https://api.github.com/users/llogiq/following{/other_user}","gists_url":"https://api.github.com/users/llogiq/gists{/gist_id}","starred_url":"https://api.github.com/users/llogiq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/llogiq/subscriptions","organizations_url":"https://api.github.com/users/llogiq/orgs","repos_url":"https://api.github.com/users/llogiq/repos","events_url":"https://api.github.com/users/llogiq/events{/privacy}","received_events_url":"https://api.github.com/users/llogiq/received_events","type":"User","site_admin":false},"body":"Right. Gimme a sec.","created_at":"2016-05-17T22:15:42Z","updated_at":"2016-05-17T22:15:42Z","html_url":"https://github.com/Manishearth/rust-clippy/pull/938#discussion_r63614063","pull_request_url":"https://api.github.com/repos/Manishearth/rust-clippy/pulls/938","_links":{"self":{"href":"https://api.github.com/repos/Manishearth/rust-clippy/pulls/comments/63614063"},"html":{"href":"https://github.com/Manishearth/rust-clippy/pull/938#discussion_r63614063"},"pull_request":{"href":"https://api.github.com/repos/Manishearth/rust-clippy/pulls/938"}}},"pull_request":{"url":"https://api.github.com/repos/Manishearth/rust-clippy/pulls/938","id":70307174,"html_url":"https://github.com/Manishearth/rust-clippy/pull/938","diff_url":"https://github.com/Manishearth/rust-clippy/pull/938.diff","patch_url":"https://github.com/Manishearth/rust-clippy/pull/938.patch","issue_url":"https://api.github.com/repos/Manishearth/rust-clippy/issues/938","number":938,"state":"open","locked":false,"title":"Split `new_without_default` and `new_without_default_derive`.","user":{"login":"llogiq","id":4200835,"avatar_url":"https://avatars.githubusercontent.com/u/4200835?v=3","gravatar_id":"","url":"https://api.github.com/users/llogiq","html_url":"https://github.com/llogiq","followers_url":"https://api.github.com/users/llogiq/followers","following_url":"https://api.github.com/users/llogiq/following{/other_user}","gists_url":"https://api.github.com/users/llogiq/gists{/gist_id}","starred_url":"https://api.github.com/users/llogiq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/llogiq/subscriptions","organizations_url":"https://api.github.com/users/llogiq/orgs","repos_url":"https://api.github.com/users/llogiq/repos","events_url":"https://api.github.com/users/llogiq/events{/privacy}","received_events_url":"https://api.github.com/users/llogiq/received_events","type":"User","site_admin":false},"body":"This is still very slow, because we do a trait lookup for each field.\r\nPerhaps storing the visited types in a set to reuse types would improve\r\nperformance somewhat. Also we may want to pre-decide some known types\r\n(e.g. `Vec<T>`, `Option<T>`).\r\n\r\nr? @Manishearth ","created_at":"2016-05-17T06:48:20Z","updated_at":"2016-05-17T22:15:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2dcbec328147cf633cf6885b2f1461b8667400a4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Manishearth/rust-clippy/pulls/938/commits","review_comments_url":"https://api.github.com/repos/Manishearth/rust-clippy/pulls/938/comments","review_comment_url":"https://api.github.com/repos/Manishearth/rust-clippy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Manishearth/rust-clippy/issues/938/comments","statuses_url":"https://api.github.com/repos/Manishearth/rust-clippy/statuses/ec953a74321711626c5228e73506d1fa9cd1e7be","head":{"label":"Manishearth:fix-876","ref":"fix-876","sha":"ec953a74321711626c5228e73506d1fa9cd1e7be","user":{"login":"Manishearth","id":1617736,"avatar_url":"https://avatars.githubusercontent.com/u/1617736?v=3","gravatar_id":"","url":"https://api.github.com/users/Manishearth","html_url":"https://github.com/Manishearth","followers_url":"https://api.github.com/users/Manishearth/followers","following_url":"https://api.github.com/users/Manishearth/following{/other_user}","gists_url":"https://api.github.com/users/Manishearth/gists{/gist_id}","starred_url":"https://api.github.com/users/Manishearth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Manishearth/subscriptions","organizations_url":"https://api.github.com/users/Manishearth/orgs","repos_url":"https://api.github.com/users/Manishearth/repos","events_url":"https://api.github.com/users/Manishearth/events{/privacy}","received_events_url":"https://api.github.com/users/Manishearth/received_events","type":"User","site_admin":false},"repo":{"id":26850443,"name":"rust-clippy","full_name":"Manishearth/rust-clippy","owner":{"login":"Manishearth","id":1617736,"avatar_url":"https://avatars.githubusercontent.com/u/1617736?v=3","gravatar_id":"","url":"https://api.github.com/users/Manishearth","html_url":"https://github.com/Manishearth","followers_url":"https://api.github.com/users/Manishearth/followers","following_url":"https://api.github.com/users/Manishearth/following{/other_user}","gists_url":"https://api.github.com/users/Manishearth/gists{/gist_id}","starred_url":"https://api.github.com/users/Manishearth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Manishearth/subscriptions","organizations_url":"https://api.github.com/users/Manishearth/orgs","repos_url":"https://api.github.com/users/Manishearth/repos","events_url":"https://api.github.com/users/Manishearth/events{/privacy}","received_events_url":"https://api.github.com/users/Manishearth/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Manishearth/rust-clippy","description":"A bunch of lints to catch common mistakes and improve your Rust code","fork":false,"url":"https://api.github.com/repos/Manishearth/rust-clippy","forks_url":"https://api.github.com/repos/Manishearth/rust-clippy/forks","keys_url":"https://api.github.com/repos/Manishearth/rust-clippy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Manishearth/rust-clippy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Manishearth/rust-clippy/teams","hooks_url":"https://api.github.com/repos/Manishearth/rust-clippy/hooks","issue_events_url":"https://api.github.com/repos/Manishearth/rust-clippy/issues/events{/number}","events_url":"https://api.github.com/repos/Manishearth/rust-clippy/events","assignees_url":"https://api.github.com/repos/Manishearth/rust-clippy/assignees{/user}","branches_url":"https://api.github.com/repos/Manishearth/rust-clippy/branches{/branch}","tags_url":"https://api.github.com/repos/Manishearth/rust-clippy/tags","blobs_url":"https://api.github.com/repos/Manishearth/rust-clippy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Manishearth/rust-clippy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Manishearth/rust-clippy/git/refs{/sha}","trees_url":"https://api.github.com/repos/Manishearth/rust-clippy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Manishearth/rust-clippy/statuses/{sha}","languages_url":"https://api.github.com/repos/Manishearth/rust-clippy/languages","stargazers_url":"https://api.github.com/repos/Manishearth/rust-clippy/stargazers","contributors_url":"https://api.github.com/repos/Manishearth/rust-clippy/contributors","subscribers_url":"https://api.github.com/repos/Manishearth/rust-clippy/subscribers","subscription_url":"https://api.github.com/repos/Manishearth/rust-clippy/subscription","commits_url":"https://api.github.com/repos/Manishearth/rust-clippy/commits{/sha}","git_commits_url":"https://api.github.com/repos/Manishearth/rust-clippy/git/commits{/sha}","comments_url":"https://api.github.com/repos/Manishearth/rust-clippy/comments{/number}","issue_comment_url":"https://api.github.com/repos/Manishearth/rust-clippy/issues/comments{/number}","contents_url":"https://api.github.com/repos/Manishearth/rust-clippy/contents/{+path}","compare_url":"https://api.github.com/repos/Manishearth/rust-clippy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Manishearth/rust-clippy/merges","archive_url":"https://api.github.com/repos/Manishearth/rust-clippy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Manishearth/rust-clippy/downloads","issues_url":"https://api.github.com/repos/Manishearth/rust-clippy/issues{/number}","pulls_url":"https://api.github.com/repos/Manishearth/rust-clippy/pulls{/number}","milestones_url":"https://api.github.com/repos/Manishearth/rust-clippy/milestones{/number}","notifications_url":"https://api.github.com/repos/Manishearth/rust-clippy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Manishearth/rust-clippy/labels{/name}","releases_url":"https://api.github.com/repos/Manishearth/rust-clippy/releases{/id}","deployments_url":"https://api.github.com/repos/Manishearth/rust-clippy/deployments","created_at":"2014-11-19T07:49:21Z","updated_at":"2016-05-17T13:37:56Z","pushed_at":"2016-05-17T21:39:54Z","git_url":"git://github.com/Manishearth/rust-clippy.git","ssh_url":"git@github.com:Manishearth/rust-clippy.git","clone_url":"https://github.com/Manishearth/rust-clippy.git","svn_url":"https://github.com/Manishearth/rust-clippy","homepage":"","size":2441,"stargazers_count":659,"watchers_count":659,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":73,"mirror_url":null,"open_issues_count":194,"forks":73,"open_issues":194,"watchers":659,"default_branch":"master"}},"base":{"label":"Manishearth:master","ref":"master","sha":"4c4b1af03c61ca7b37e228f8193a82cbd6b803b1","user":{"login":"Manishearth","id":1617736,"avatar_url":"https://avatars.githubusercontent.com/u/1617736?v=3","gravatar_id":"","url":"https://api.github.com/users/Manishearth","html_url":"https://github.com/Manishearth","followers_url":"https://api.github.com/users/Manishearth/followers","following_url":"https://api.github.com/users/Manishearth/following{/other_user}","gists_url":"https://api.github.com/users/Manishearth/gists{/gist_id}","starred_url":"https://api.github.com/users/Manishearth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Manishearth/subscriptions","organizations_url":"https://api.github.com/users/Manishearth/orgs","repos_url":"https://api.github.com/users/Manishearth/repos","events_url":"https://api.github.com/users/Manishearth/events{/privacy}","received_events_url":"https://api.github.com/users/Manishearth/received_events","type":"User","site_admin":false},"repo":{"id":26850443,"name":"rust-clippy","full_name":"Manishearth/rust-clippy","owner":{"login":"Manishearth","id":1617736,"avatar_url":"https://avatars.githubusercontent.com/u/1617736?v=3","gravatar_id":"","url":"https://api.github.com/users/Manishearth","html_url":"https://github.com/Manishearth","followers_url":"https://api.github.com/users/Manishearth/followers","following_url":"https://api.github.com/users/Manishearth/following{/other_user}","gists_url":"https://api.github.com/users/Manishearth/gists{/gist_id}","starred_url":"https://api.github.com/users/Manishearth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Manishearth/subscriptions","organizations_url":"https://api.github.com/users/Manishearth/orgs","repos_url":"https://api.github.com/users/Manishearth/repos","events_url":"https://api.github.com/users/Manishearth/events{/privacy}","received_events_url":"https://api.github.com/users/Manishearth/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Manishearth/rust-clippy","description":"A bunch of lints to catch common mistakes and improve your Rust code","fork":false,"url":"https://api.github.com/repos/Manishearth/rust-clippy","forks_url":"https://api.github.com/repos/Manishearth/rust-clippy/forks","keys_url":"https://api.github.com/repos/Manishearth/rust-clippy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Manishearth/rust-clippy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Manishearth/rust-clippy/teams","hooks_url":"https://api.github.com/repos/Manishearth/rust-clippy/hooks","issue_events_url":"https://api.github.com/repos/Manishearth/rust-clippy/issues/events{/number}","events_url":"https://api.github.com/repos/Manishearth/rust-clippy/events","assignees_url":"https://api.github.com/repos/Manishearth/rust-clippy/assignees{/user}","branches_url":"https://api.github.com/repos/Manishearth/rust-clippy/branches{/branch}","tags_url":"https://api.github.com/repos/Manishearth/rust-clippy/tags","blobs_url":"https://api.github.com/repos/Manishearth/rust-clippy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Manishearth/rust-clippy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Manishearth/rust-clippy/git/refs{/sha}","trees_url":"https://api.github.com/repos/Manishearth/rust-clippy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Manishearth/rust-clippy/statuses/{sha}","languages_url":"https://api.github.com/repos/Manishearth/rust-clippy/languages","stargazers_url":"https://api.github.com/repos/Manishearth/rust-clippy/stargazers","contributors_url":"https://api.github.com/repos/Manishearth/rust-clippy/contributors","subscribers_url":"https://api.github.com/repos/Manishearth/rust-clippy/subscribers","subscription_url":"https://api.github.com/repos/Manishearth/rust-clippy/subscription","commits_url":"https://api.github.com/repos/Manishearth/rust-clippy/commits{/sha}","git_commits_url":"https://api.github.com/repos/Manishearth/rust-clippy/git/commits{/sha}","comments_url":"https://api.github.com/repos/Manishearth/rust-clippy/comments{/number}","issue_comment_url":"https://api.github.com/repos/Manishearth/rust-clippy/issues/comments{/number}","contents_url":"https://api.github.com/repos/Manishearth/rust-clippy/contents/{+path}","compare_url":"https://api.github.com/repos/Manishearth/rust-clippy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Manishearth/rust-clippy/merges","archive_url":"https://api.github.com/repos/Manishearth/rust-clippy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Manishearth/rust-clippy/downloads","issues_url":"https://api.github.com/repos/Manishearth/rust-clippy/issues{/number}","pulls_url":"https://api.github.com/repos/Manishearth/rust-clippy/pulls{/number}","milestones_url":"https://api.github.com/repos/Manishearth/rust-clippy/milestones{/number}","notifications_url":"https://api.github.com/repos/Manishearth/rust-clippy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Manishearth/rust-clippy/labels{/name}","releases_url":"https://api.github.com/repos/Manishearth/rust-clippy/releases{/id}","deployments_url":"https://api.github.com/repos/Manishearth/rust-clippy/deployments","created_at":"2014-11-19T07:49:21Z","updated_at":"2016-05-17T13:37:56Z","pushed_at":"2016-05-17T21:39:54Z","git_url":"git://github.com/Manishearth/rust-clippy.git","ssh_url":"git@github.com:Manishearth/rust-clippy.git","clone_url":"https://github.com/Manishearth/rust-clippy.git","svn_url":"https://github.com/Manishearth/rust-clippy","homepage":"","size":2441,"stargazers_count":659,"watchers_count":659,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":73,"mirror_url":null,"open_issues_count":194,"forks":73,"open_issues":194,"watchers":659,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Manishearth/rust-clippy/pulls/938"},"html":{"href":"https://github.com/Manishearth/rust-clippy/pull/938"},"issue":{"href":"https://api.github.com/repos/Manishearth/rust-clippy/issues/938"},"comments":{"href":"https://api.github.com/repos/Manishearth/rust-clippy/issues/938/comments"},"review_comments":{"href":"https://api.github.com/repos/Manishearth/rust-clippy/pulls/938/comments"},"review_comment":{"href":"https://api.github.com/repos/Manishearth/rust-clippy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Manishearth/rust-clippy/pulls/938/commits"},"statuses":{"href":"https://api.github.com/repos/Manishearth/rust-clippy/statuses/ec953a74321711626c5228e73506d1fa9cd1e7be"}}}}