{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/comments/49860303","id":49860303,"diff_hunk":"@@ -353,26 +353,35 @@ If you really want global mutable state, try using `static mut` or a global\n \"##,\n \n E0018: r##\"\n-The value of static and const variables must be known at compile time. You\n-can't cast a pointer as an integer because we can't know what value the\n-address will take.\n-\n-However, pointers to other constants' addresses are allowed in constants,\n-example:\n+The value of static and constant integers must be known at compile time. You\n+can't cast a pointer to an integer because the address of a pointer can\n+vary.\n \n+For example, if you write:\n ```\n-const X: u32 = 50;\n-const Y: *const u32 = &X;\n+static MY_STATIC: u32 = 42;\n+static MY_STATIC_ADDR: usize = &MY_STATIC as *const _ as usize;\n+static WHAT: usize = (MY_STATIC_ADDR^17) + MY_STATIC_ADDR;\n ```\n \n-Therefore, casting one of these non-constant pointers to an integer results\n-in a non-constant integer which lead to this error. Example:\n+Then MY_STATIC_ADDR would contain the address of MY_STATIC. However,\n+that address can change when the program is linked, as well as change\n+between different executions due to ASLR, and many linkers would\n+not be able to calculate the value of WHAT.\n+\n+On the other hand, static and constant pointers can point either to\n+a known numeric address or to the address of a symbol.\n \n ```\n-const X: u32 = 1;\n-const Y: usize = &X as *const u32 as usize;\n-println!(\"{}\", Y);\n+static MY_STATIC_ADDR: &'static u32 = &MY_STATIC;\n+// ..and also\n+static MY_STATIC_ADDR2: *const u32 = &MY_STATIC;\n+\n+const CONST_ADDR: *const u8 = 0x5f3759df as *const u8;\n ```\n+\n+This does not pose a problem by itself because they can't be\n+accessed directly.","path":"src/librustc/diagnostics.rs","position":45,"original_position":45,"commit_id":"e59de788b320c0e2e7058c9accb4cc0c1a5676a5","original_commit_id":"e59de788b320c0e2e7058c9accb4cc0c1a5676a5","user":{"login":"oli-obk","id":332036,"avatar_url":"https://avatars.githubusercontent.com/u/332036?v=3","gravatar_id":"","url":"https://api.github.com/users/oli-obk","html_url":"https://github.com/oli-obk","followers_url":"https://api.github.com/users/oli-obk/followers","following_url":"https://api.github.com/users/oli-obk/following{/other_user}","gists_url":"https://api.github.com/users/oli-obk/gists{/gist_id}","starred_url":"https://api.github.com/users/oli-obk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oli-obk/subscriptions","organizations_url":"https://api.github.com/users/oli-obk/orgs","repos_url":"https://api.github.com/users/oli-obk/repos","events_url":"https://api.github.com/users/oli-obk/events{/privacy}","received_events_url":"https://api.github.com/users/oli-obk/received_events","type":"User","site_admin":false},"body":"because the address is never inspected nor is the pointer ever dereferenced","created_at":"2016-01-15T14:48:44Z","updated_at":"2016-01-15T14:48:44Z","html_url":"https://github.com/rust-lang/rust/pull/30932#discussion_r49860303","pull_request_url":"https://api.github.com/repos/rust-lang/rust/pulls/30932","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/comments/49860303"},"html":{"href":"https://github.com/rust-lang/rust/pull/30932#discussion_r49860303"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/30932"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/30932","id":56164828,"html_url":"https://github.com/rust-lang/rust/pull/30932","diff_url":"https://github.com/rust-lang/rust/pull/30932.diff","patch_url":"https://github.com/rust-lang/rust/pull/30932.patch","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/30932","number":30932,"state":"open","locked":false,"title":"Improve the error explanations for check_const","user":{"login":"arielb1","id":1830974,"avatar_url":"https://avatars.githubusercontent.com/u/1830974?v=3","gravatar_id":"","url":"https://api.github.com/users/arielb1","html_url":"https://github.com/arielb1","followers_url":"https://api.github.com/users/arielb1/followers","following_url":"https://api.github.com/users/arielb1/following{/other_user}","gists_url":"https://api.github.com/users/arielb1/gists{/gist_id}","starred_url":"https://api.github.com/users/arielb1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arielb1/subscriptions","organizations_url":"https://api.github.com/users/arielb1/orgs","repos_url":"https://api.github.com/users/arielb1/repos","events_url":"https://api.github.com/users/arielb1/events{/privacy}","received_events_url":"https://api.github.com/users/arielb1/received_events","type":"User","site_admin":false},"body":"Fixes #30705\r\n\r\nr? @nagisa ","created_at":"2016-01-15T12:43:05Z","updated_at":"2016-01-15T14:48:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c59b2bff8222e27adb50aeae6b66b42b146d37c5","assignee":{"login":"nagisa","id":679122,"avatar_url":"https://avatars.githubusercontent.com/u/679122?v=3","gravatar_id":"","url":"https://api.github.com/users/nagisa","html_url":"https://github.com/nagisa","followers_url":"https://api.github.com/users/nagisa/followers","following_url":"https://api.github.com/users/nagisa/following{/other_user}","gists_url":"https://api.github.com/users/nagisa/gists{/gist_id}","starred_url":"https://api.github.com/users/nagisa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nagisa/subscriptions","organizations_url":"https://api.github.com/users/nagisa/orgs","repos_url":"https://api.github.com/users/nagisa/repos","events_url":"https://api.github.com/users/nagisa/events{/privacy}","received_events_url":"https://api.github.com/users/nagisa/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang/rust/pulls/30932/commits","review_comments_url":"https://api.github.com/repos/rust-lang/rust/pulls/30932/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/30932/comments","statuses_url":"https://api.github.com/repos/rust-lang/rust/statuses/e59de788b320c0e2e7058c9accb4cc0c1a5676a5","head":{"label":"arielb1:raw-const-errors","ref":"raw-const-errors","sha":"e59de788b320c0e2e7058c9accb4cc0c1a5676a5","user":{"login":"arielb1","id":1830974,"avatar_url":"https://avatars.githubusercontent.com/u/1830974?v=3","gravatar_id":"","url":"https://api.github.com/users/arielb1","html_url":"https://github.com/arielb1","followers_url":"https://api.github.com/users/arielb1/followers","following_url":"https://api.github.com/users/arielb1/following{/other_user}","gists_url":"https://api.github.com/users/arielb1/gists{/gist_id}","starred_url":"https://api.github.com/users/arielb1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arielb1/subscriptions","organizations_url":"https://api.github.com/users/arielb1/orgs","repos_url":"https://api.github.com/users/arielb1/repos","events_url":"https://api.github.com/users/arielb1/events{/privacy}","received_events_url":"https://api.github.com/users/arielb1/received_events","type":"User","site_admin":false},"repo":{"id":20256861,"name":"rust","full_name":"arielb1/rust","owner":{"login":"arielb1","id":1830974,"avatar_url":"https://avatars.githubusercontent.com/u/1830974?v=3","gravatar_id":"","url":"https://api.github.com/users/arielb1","html_url":"https://github.com/arielb1","followers_url":"https://api.github.com/users/arielb1/followers","following_url":"https://api.github.com/users/arielb1/following{/other_user}","gists_url":"https://api.github.com/users/arielb1/gists{/gist_id}","starred_url":"https://api.github.com/users/arielb1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arielb1/subscriptions","organizations_url":"https://api.github.com/users/arielb1/orgs","repos_url":"https://api.github.com/users/arielb1/repos","events_url":"https://api.github.com/users/arielb1/events{/privacy}","received_events_url":"https://api.github.com/users/arielb1/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/arielb1/rust","description":"a safe, concurrent, practical language","fork":true,"url":"https://api.github.com/repos/arielb1/rust","forks_url":"https://api.github.com/repos/arielb1/rust/forks","keys_url":"https://api.github.com/repos/arielb1/rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/arielb1/rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/arielb1/rust/teams","hooks_url":"https://api.github.com/repos/arielb1/rust/hooks","issue_events_url":"https://api.github.com/repos/arielb1/rust/issues/events{/number}","events_url":"https://api.github.com/repos/arielb1/rust/events","assignees_url":"https://api.github.com/repos/arielb1/rust/assignees{/user}","branches_url":"https://api.github.com/repos/arielb1/rust/branches{/branch}","tags_url":"https://api.github.com/repos/arielb1/rust/tags","blobs_url":"https://api.github.com/repos/arielb1/rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/arielb1/rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/arielb1/rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/arielb1/rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/arielb1/rust/statuses/{sha}","languages_url":"https://api.github.com/repos/arielb1/rust/languages","stargazers_url":"https://api.github.com/repos/arielb1/rust/stargazers","contributors_url":"https://api.github.com/repos/arielb1/rust/contributors","subscribers_url":"https://api.github.com/repos/arielb1/rust/subscribers","subscription_url":"https://api.github.com/repos/arielb1/rust/subscription","commits_url":"https://api.github.com/repos/arielb1/rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/arielb1/rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/arielb1/rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/arielb1/rust/issues/comments{/number}","contents_url":"https://api.github.com/repos/arielb1/rust/contents/{+path}","compare_url":"https://api.github.com/repos/arielb1/rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/arielb1/rust/merges","archive_url":"https://api.github.com/repos/arielb1/rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/arielb1/rust/downloads","issues_url":"https://api.github.com/repos/arielb1/rust/issues{/number}","pulls_url":"https://api.github.com/repos/arielb1/rust/pulls{/number}","milestones_url":"https://api.github.com/repos/arielb1/rust/milestones{/number}","notifications_url":"https://api.github.com/repos/arielb1/rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/arielb1/rust/labels{/name}","releases_url":"https://api.github.com/repos/arielb1/rust/releases{/id}","created_at":"2014-05-28T12:39:09Z","updated_at":"2015-05-07T16:35:59Z","pushed_at":"2016-01-15T12:42:49Z","git_url":"git://github.com/arielb1/rust.git","ssh_url":"git@github.com:arielb1/rust.git","clone_url":"https://github.com/arielb1/rust.git","svn_url":"https://github.com/arielb1/rust","homepage":"http://www.rust-lang.org","size":280280,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"a70a60a02bca4c1fb75a0eb0ecf80acb73972f66","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}","created_at":"2010-06-16T20:39:03Z","updated_at":"2016-01-15T14:11:31Z","pushed_at":"2016-01-15T14:32:44Z","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":"http://www.rust-lang.org","size":466081,"stargazers_count":14917,"watchers_count":14917,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2911,"mirror_url":null,"open_issues_count":2327,"forks":2911,"open_issues":2327,"watchers":14917,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/30932"},"html":{"href":"https://github.com/rust-lang/rust/pull/30932"},"issue":{"href":"https://api.github.com/repos/rust-lang/rust/issues/30932"},"comments":{"href":"https://api.github.com/repos/rust-lang/rust/issues/30932/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/30932/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/30932/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/rust/statuses/e59de788b320c0e2e7058c9accb4cc0c1a5676a5"}}}}