{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/comments/74855348","id":74855348,"diff_hunk":"@@ -381,19 +384,85 @@ impl EmitterWriter {\n         max\n     }\n \n-    fn get_max_line_num(&mut self, db: &DiagnosticBuilder) -> usize {\n+    fn get_max_line_num(&mut self, span: &MultiSpan, children: &Vec<SubDiagnostic>) -> usize {\n         let mut max = 0;\n \n-        let primary = self.get_multispan_max_line_num(&db.span);\n+        let primary = self.get_multispan_max_line_num(span);\n         max = if primary > max { primary } else { max };\n \n-        for sub in &db.children {\n+        for sub in children {\n             let sub_result = self.get_multispan_max_line_num(&sub.span);\n             max = if sub_result > max { primary } else { max };\n         }\n         max\n     }\n \n+    fn fix_multispan_in_std_macros(&mut self, span: &mut MultiSpan) -> bool {\n+        let mut spans_updated = false;\n+\n+        if let Some(ref cm) = self.cm {\n+            let mut before_after: Vec<(Span, Span)> = vec![];\n+            let mut new_labels: Vec<(Span, String)> = vec![];\n+\n+            // First, find all the spans in <std macros> and point instead at their use site\n+            for sp in span.primary_spans() {\n+                if cm.span_to_filename(sp.clone()) == \"<std macros>\" {\n+                    let v = cm.macro_backtrace(sp.clone());\n+                    if let Some(use_site) = v.last() {\n+                        before_after.push((sp.clone(), use_site.call_site.clone()));\n+                    };\n+                }\n+                for trace in cm.macro_backtrace(sp.clone()).iter().rev() {\n+                    // Only show macro locations that are local\n+                    // and display them like a span_note\n+                    if let Some(def_site) = trace.def_site_span {\n+                        // Check to make sure we're not in a <std macros>\n+                        if cm.span_to_filename(def_site) != \"<std macros>\" {\n+                            new_labels.push((trace.call_site,\n+                                             \"in this macro invocation\".to_string()));\n+                            break;\n+                        }\n+                    }\n+                }\n+            }\n+            for (label_span, label_text) in new_labels {\n+                span.push_span_label(label_span, label_text);\n+            }\n+            for sp_label in span.span_labels() {\n+                if cm.span_to_filename(sp_label.span.clone()) == \"<std macros>\" {\n+                    let v = cm.macro_backtrace(sp_label.span.clone());\n+                    if let Some(use_site) = v.last() {\n+                        before_after.push((sp_label.span.clone(), use_site.call_site.clone()));\n+                    };\n+                }\n+            }\n+            // After we have them, make sure we replace these 'bad' def sites with their use sites\n+            for (before, after) in before_after {\n+                span.replace(before, after);\n+                spans_updated = true;\n+            }\n+        }\n+\n+        spans_updated\n+    }\n+\n+    fn fix_multispans_in_std_macros(&mut self,\n+                                    span: &mut MultiSpan,\n+                                    children: &mut Vec<SubDiagnostic>) {\n+        let mut spans_updated = self.fix_multispan_in_std_macros(span);\n+        for i in 0..children.len() {","path":"src/librustc_errors/emitter.rs","position":94,"original_position":94,"commit_id":"5dc8710c76692c15c00c678c65ce64cbe7c9c390","original_commit_id":"5dc8710c76692c15c00c678c65ce64cbe7c9c390","user":{"login":"Mark-Simulacrum","id":5047365,"avatar_url":"https://avatars.githubusercontent.com/u/5047365?v=3","gravatar_id":"","url":"https://api.github.com/users/Mark-Simulacrum","html_url":"https://github.com/Mark-Simulacrum","followers_url":"https://api.github.com/users/Mark-Simulacrum/followers","following_url":"https://api.github.com/users/Mark-Simulacrum/following{/other_user}","gists_url":"https://api.github.com/users/Mark-Simulacrum/gists{/gist_id}","starred_url":"https://api.github.com/users/Mark-Simulacrum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mark-Simulacrum/subscriptions","organizations_url":"https://api.github.com/users/Mark-Simulacrum/orgs","repos_url":"https://api.github.com/users/Mark-Simulacrum/repos","events_url":"https://api.github.com/users/Mark-Simulacrum/events{/privacy}","received_events_url":"https://api.github.com/users/Mark-Simulacrum/received_events","type":"User","site_admin":false},"body":"Why can't this be `for child in &mut children`?","created_at":"2016-08-15T23:40:32Z","updated_at":"2016-08-15T23:40:32Z","html_url":"https://github.com/rust-lang/rust/pull/35702#discussion_r74855348","pull_request_url":"https://api.github.com/repos/rust-lang/rust/pulls/35702","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/comments/74855348"},"html":{"href":"https://github.com/rust-lang/rust/pull/35702#discussion_r74855348"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/35702"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/35702","id":81392008,"html_url":"https://github.com/rust-lang/rust/pull/35702","diff_url":"https://github.com/rust-lang/rust/pull/35702.diff","patch_url":"https://github.com/rust-lang/rust/pull/35702.patch","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/35702","number":35702,"state":"open","locked":false,"title":"Replace macro backtraces with labeled local uses","user":{"login":"jonathandturner","id":547158,"avatar_url":"https://avatars.githubusercontent.com/u/547158?v=3","gravatar_id":"","url":"https://api.github.com/users/jonathandturner","html_url":"https://github.com/jonathandturner","followers_url":"https://api.github.com/users/jonathandturner/followers","following_url":"https://api.github.com/users/jonathandturner/following{/other_user}","gists_url":"https://api.github.com/users/jonathandturner/gists{/gist_id}","starred_url":"https://api.github.com/users/jonathandturner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonathandturner/subscriptions","organizations_url":"https://api.github.com/users/jonathandturner/orgs","repos_url":"https://api.github.com/users/jonathandturner/repos","events_url":"https://api.github.com/users/jonathandturner/events{/privacy}","received_events_url":"https://api.github.com/users/jonathandturner/received_events","type":"User","site_admin":false},"body":"This PR (which builds on https://github.com/rust-lang/rust/pull/35688) follows from the conversations on how best to [handle the macro backtraces](https://internals.rust-lang.org/t/improving-macro-errors/3809).  The feeling there was that there were two different \"groups\" of users.\r\n\r\nThe first group, the macro users, rarely (and likely never) want to see the macro backtrace.  This is often more confusing to users as it will be talking about code they didn't write.\r\n\r\nThe second group, the macro writers, are trying to debug a macro.  They'll want to see something of the backtrace so that they can see where it's going wrong and what the steps were to get there.\r\n\r\nFor the first group, it seems clear that we don't want to show *any* macro backtrace.  For the second group, we want to show enough to help the macro writer.\r\n\r\nThis PR uses a heuristic.  It will only show any backtrace steps if they are in the same crate that is being compiled.  This keeps errors in foreign crates from showing to users that didn't need them.\r\n\r\nAdditionally, in asking around I repeated heard that the middle steps of the backtrace are rarely, if ever, used in practice.  This PR takes and applies this knowledge.  Now, instead of a full backtrace, the user is given the error underline inside of a local macro as well as the use site as a secondary label.  This effectively means seeing the root of the error and the top of the backtrace, eliding the middle steps.\r\n\r\nRather than being the \"perfect solution\", this PR opts to take an incremental step towards a better experience.  Likely it would help to have additional macro debugging tools, as they could be much more verbose than we'd likely want to use in the error messages themselves.\r\n\r\nSome examples follow.\r\n\r\n**Example 1**\r\n\r\nBefore:\r\n\r\n<img width=\"1275\" alt=\"screen shot 2016-08-15 at 4 13 18 pm\" src=\"https://cloud.githubusercontent.com/assets/547158/17682828/3948cea2-6303-11e6-93b4-b567e9d62848.png\">\r\n\r\nAfter:\r\n\r\n<img width=\"596\" alt=\"screen shot 2016-08-15 at 4 13 03 pm\" src=\"https://cloud.githubusercontent.com/assets/547158/17682832/3d670d8c-6303-11e6-9bdc-f30a30bf11ac.png\">\r\n\r\n**Example 2**\r\n\r\nBefore:\r\n\r\n<img width=\"918\" alt=\"screen shot 2016-08-15 at 4 14 35 pm\" src=\"https://cloud.githubusercontent.com/assets/547158/17682870/722225de-6303-11e6-9175-336a3f7ce308.png\">\r\n\r\nAfter:\r\n\r\n<img width=\"483\" alt=\"screen shot 2016-08-15 at 4 15 01 pm\" src=\"https://cloud.githubusercontent.com/assets/547158/17682872/7582cf6c-6303-11e6-9235-f67960f6bd4c.png\">\r\n\r\n\r\n","created_at":"2016-08-15T23:19:31Z","updated_at":"2016-08-15T23:40:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"74de3b555b5281b7a6b5072ebee981077341b685","assignee":{"login":"nikomatsakis","id":155238,"avatar_url":"https://avatars.githubusercontent.com/u/155238?v=3","gravatar_id":"","url":"https://api.github.com/users/nikomatsakis","html_url":"https://github.com/nikomatsakis","followers_url":"https://api.github.com/users/nikomatsakis/followers","following_url":"https://api.github.com/users/nikomatsakis/following{/other_user}","gists_url":"https://api.github.com/users/nikomatsakis/gists{/gist_id}","starred_url":"https://api.github.com/users/nikomatsakis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikomatsakis/subscriptions","organizations_url":"https://api.github.com/users/nikomatsakis/orgs","repos_url":"https://api.github.com/users/nikomatsakis/repos","events_url":"https://api.github.com/users/nikomatsakis/events{/privacy}","received_events_url":"https://api.github.com/users/nikomatsakis/received_events","type":"User","site_admin":false},"assignees":[{"login":"nikomatsakis","id":155238,"avatar_url":"https://avatars.githubusercontent.com/u/155238?v=3","gravatar_id":"","url":"https://api.github.com/users/nikomatsakis","html_url":"https://github.com/nikomatsakis","followers_url":"https://api.github.com/users/nikomatsakis/followers","following_url":"https://api.github.com/users/nikomatsakis/following{/other_user}","gists_url":"https://api.github.com/users/nikomatsakis/gists{/gist_id}","starred_url":"https://api.github.com/users/nikomatsakis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikomatsakis/subscriptions","organizations_url":"https://api.github.com/users/nikomatsakis/orgs","repos_url":"https://api.github.com/users/nikomatsakis/repos","events_url":"https://api.github.com/users/nikomatsakis/events{/privacy}","received_events_url":"https://api.github.com/users/nikomatsakis/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang/rust/pulls/35702/commits","review_comments_url":"https://api.github.com/repos/rust-lang/rust/pulls/35702/comments","review_comment_url":"https://api.github.com/repos/rust-lang/rust/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/35702/comments","statuses_url":"https://api.github.com/repos/rust-lang/rust/statuses/5dc8710c76692c15c00c678c65ce64cbe7c9c390","head":{"label":"jonathandturner:add_backtrace_labels","ref":"add_backtrace_labels","sha":"5dc8710c76692c15c00c678c65ce64cbe7c9c390","user":{"login":"jonathandturner","id":547158,"avatar_url":"https://avatars.githubusercontent.com/u/547158?v=3","gravatar_id":"","url":"https://api.github.com/users/jonathandturner","html_url":"https://github.com/jonathandturner","followers_url":"https://api.github.com/users/jonathandturner/followers","following_url":"https://api.github.com/users/jonathandturner/following{/other_user}","gists_url":"https://api.github.com/users/jonathandturner/gists{/gist_id}","starred_url":"https://api.github.com/users/jonathandturner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonathandturner/subscriptions","organizations_url":"https://api.github.com/users/jonathandturner/orgs","repos_url":"https://api.github.com/users/jonathandturner/repos","events_url":"https://api.github.com/users/jonathandturner/events{/privacy}","received_events_url":"https://api.github.com/users/jonathandturner/received_events","type":"User","site_admin":false},"repo":{"id":46572587,"name":"rust","full_name":"jonathandturner/rust","owner":{"login":"jonathandturner","id":547158,"avatar_url":"https://avatars.githubusercontent.com/u/547158?v=3","gravatar_id":"","url":"https://api.github.com/users/jonathandturner","html_url":"https://github.com/jonathandturner","followers_url":"https://api.github.com/users/jonathandturner/followers","following_url":"https://api.github.com/users/jonathandturner/following{/other_user}","gists_url":"https://api.github.com/users/jonathandturner/gists{/gist_id}","starred_url":"https://api.github.com/users/jonathandturner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonathandturner/subscriptions","organizations_url":"https://api.github.com/users/jonathandturner/orgs","repos_url":"https://api.github.com/users/jonathandturner/repos","events_url":"https://api.github.com/users/jonathandturner/events{/privacy}","received_events_url":"https://api.github.com/users/jonathandturner/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jonathandturner/rust","description":"A safe, concurrent, practical language.","fork":true,"url":"https://api.github.com/repos/jonathandturner/rust","forks_url":"https://api.github.com/repos/jonathandturner/rust/forks","keys_url":"https://api.github.com/repos/jonathandturner/rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jonathandturner/rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jonathandturner/rust/teams","hooks_url":"https://api.github.com/repos/jonathandturner/rust/hooks","issue_events_url":"https://api.github.com/repos/jonathandturner/rust/issues/events{/number}","events_url":"https://api.github.com/repos/jonathandturner/rust/events","assignees_url":"https://api.github.com/repos/jonathandturner/rust/assignees{/user}","branches_url":"https://api.github.com/repos/jonathandturner/rust/branches{/branch}","tags_url":"https://api.github.com/repos/jonathandturner/rust/tags","blobs_url":"https://api.github.com/repos/jonathandturner/rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jonathandturner/rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jonathandturner/rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/jonathandturner/rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jonathandturner/rust/statuses/{sha}","languages_url":"https://api.github.com/repos/jonathandturner/rust/languages","stargazers_url":"https://api.github.com/repos/jonathandturner/rust/stargazers","contributors_url":"https://api.github.com/repos/jonathandturner/rust/contributors","subscribers_url":"https://api.github.com/repos/jonathandturner/rust/subscribers","subscription_url":"https://api.github.com/repos/jonathandturner/rust/subscription","commits_url":"https://api.github.com/repos/jonathandturner/rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/jonathandturner/rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/jonathandturner/rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/jonathandturner/rust/issues/comments{/number}","contents_url":"https://api.github.com/repos/jonathandturner/rust/contents/{+path}","compare_url":"https://api.github.com/repos/jonathandturner/rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jonathandturner/rust/merges","archive_url":"https://api.github.com/repos/jonathandturner/rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jonathandturner/rust/downloads","issues_url":"https://api.github.com/repos/jonathandturner/rust/issues{/number}","pulls_url":"https://api.github.com/repos/jonathandturner/rust/pulls{/number}","milestones_url":"https://api.github.com/repos/jonathandturner/rust/milestones{/number}","notifications_url":"https://api.github.com/repos/jonathandturner/rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jonathandturner/rust/labels{/name}","releases_url":"https://api.github.com/repos/jonathandturner/rust/releases{/id}","deployments_url":"https://api.github.com/repos/jonathandturner/rust/deployments","created_at":"2015-11-20T16:12:05Z","updated_at":"2015-11-20T16:12:57Z","pushed_at":"2016-08-15T23:08:41Z","git_url":"git://github.com/jonathandturner/rust.git","ssh_url":"git@github.com:jonathandturner/rust.git","clone_url":"https://github.com/jonathandturner/rust.git","svn_url":"https://github.com/jonathandturner/rust","homepage":"http://www.rust-lang.org","size":295863,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rust-lang:master","ref":"master","sha":"197be89f367d1240d5f9cd9c4efd77812775354e","user":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"repo":{"id":724712,"name":"rust","full_name":"rust-lang/rust","owner":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rust-lang/rust","description":"A safe, concurrent, practical language.","fork":false,"url":"https://api.github.com/repos/rust-lang/rust","forks_url":"https://api.github.com/repos/rust-lang/rust/forks","keys_url":"https://api.github.com/repos/rust-lang/rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-lang/rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-lang/rust/teams","hooks_url":"https://api.github.com/repos/rust-lang/rust/hooks","issue_events_url":"https://api.github.com/repos/rust-lang/rust/issues/events{/number}","events_url":"https://api.github.com/repos/rust-lang/rust/events","assignees_url":"https://api.github.com/repos/rust-lang/rust/assignees{/user}","branches_url":"https://api.github.com/repos/rust-lang/rust/branches{/branch}","tags_url":"https://api.github.com/repos/rust-lang/rust/tags","blobs_url":"https://api.github.com/repos/rust-lang/rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-lang/rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-lang/rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-lang/rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-lang/rust/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-lang/rust/languages","stargazers_url":"https://api.github.com/repos/rust-lang/rust/stargazers","contributors_url":"https://api.github.com/repos/rust-lang/rust/contributors","subscribers_url":"https://api.github.com/repos/rust-lang/rust/subscribers","subscription_url":"https://api.github.com/repos/rust-lang/rust/subscription","commits_url":"https://api.github.com/repos/rust-lang/rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-lang/rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-lang/rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-lang/rust/issues/comments{/number}","contents_url":"https://api.github.com/repos/rust-lang/rust/contents/{+path}","compare_url":"https://api.github.com/repos/rust-lang/rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-lang/rust/merges","archive_url":"https://api.github.com/repos/rust-lang/rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-lang/rust/downloads","issues_url":"https://api.github.com/repos/rust-lang/rust/issues{/number}","pulls_url":"https://api.github.com/repos/rust-lang/rust/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-lang/rust/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-lang/rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-lang/rust/labels{/name}","releases_url":"https://api.github.com/repos/rust-lang/rust/releases{/id}","deployments_url":"https://api.github.com/repos/rust-lang/rust/deployments","created_at":"2010-06-16T20:39:03Z","updated_at":"2016-08-15T21:14:31Z","pushed_at":"2016-08-15T23:24:59Z","git_url":"git://github.com/rust-lang/rust.git","ssh_url":"git@github.com:rust-lang/rust.git","clone_url":"https://github.com/rust-lang/rust.git","svn_url":"https://github.com/rust-lang/rust","homepage":"https://www.rust-lang.org","size":506566,"stargazers_count":17945,"watchers_count":17945,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3461,"mirror_url":null,"open_issues_count":2730,"forks":3461,"open_issues":2730,"watchers":17945,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/35702"},"html":{"href":"https://github.com/rust-lang/rust/pull/35702"},"issue":{"href":"https://api.github.com/repos/rust-lang/rust/issues/35702"},"comments":{"href":"https://api.github.com/repos/rust-lang/rust/issues/35702/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/35702/comments"},"review_comment":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/35702/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/rust/statuses/5dc8710c76692c15c00c678c65ce64cbe7c9c390"}}}}
{"actor":{"display_login":"Mark-Simulacrum"}}