{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/comments/144116789","pull_request_review_id":68729338,"id":144116789,"diff_hunk":"@@ -955,6 +952,55 @@ pub fn const_scalar_checked_binop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,\n     }\n }\n \n+unsafe fn const_cast_from_float(operand: &Const, signed: bool, int_ty: Type) -> ValueRef {\n+    let llval = operand.llval;\n+    // Note: this breaks if addresses can be turned into integers (is that possible?)","path":"src/librustc_trans/mir/constant.rs","position":38,"original_position":38,"commit_id":"dd2563060a4a555953e6c878b99f512c799a7c83","original_commit_id":"dd2563060a4a555953e6c878b99f512c799a7c83","user":{"login":"est31","id":8872119,"avatar_url":"https://avatars2.githubusercontent.com/u/8872119?v=4","gravatar_id":"","url":"https://api.github.com/users/est31","html_url":"https://github.com/est31","followers_url":"https://api.github.com/users/est31/followers","following_url":"https://api.github.com/users/est31/following{/other_user}","gists_url":"https://api.github.com/users/est31/gists{/gist_id}","starred_url":"https://api.github.com/users/est31/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/est31/subscriptions","organizations_url":"https://api.github.com/users/est31/orgs","repos_url":"https://api.github.com/users/est31/repos","events_url":"https://api.github.com/users/est31/events{/privacy}","received_events_url":"https://api.github.com/users/est31/received_events","type":"User","site_admin":false},"body":"This is valid rust code, isn't it?\r\n\r\n```\r\nprintln!(\"{}\", {let w: * const u32 = {let v = 0u32; &v}; w} as usize);\r\n```","created_at":"2017-10-11T19:48:10Z","updated_at":"2017-10-11T19:48:10Z","html_url":"https://github.com/rust-lang/rust/pull/45205#discussion_r144116789","pull_request_url":"https://api.github.com/repos/rust-lang/rust/pulls/45205","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/comments/144116789"},"html":{"href":"https://github.com/rust-lang/rust/pull/45205#discussion_r144116789"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/45205"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/45205","id":146000298,"html_url":"https://github.com/rust-lang/rust/pull/45205","diff_url":"https://github.com/rust-lang/rust/pull/45205.diff","patch_url":"https://github.com/rust-lang/rust/pull/45205.patch","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/45205","number":45205,"state":"open","locked":false,"title":"Saturating casts between integers and floats","user":{"login":"rkruppe","id":2311707,"avatar_url":"https://avatars2.githubusercontent.com/u/2311707?v=4","gravatar_id":"","url":"https://api.github.com/users/rkruppe","html_url":"https://github.com/rkruppe","followers_url":"https://api.github.com/users/rkruppe/followers","following_url":"https://api.github.com/users/rkruppe/following{/other_user}","gists_url":"https://api.github.com/users/rkruppe/gists{/gist_id}","starred_url":"https://api.github.com/users/rkruppe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkruppe/subscriptions","organizations_url":"https://api.github.com/users/rkruppe/orgs","repos_url":"https://api.github.com/users/rkruppe/repos","events_url":"https://api.github.com/users/rkruppe/events{/privacy}","received_events_url":"https://api.github.com/users/rkruppe/received_events","type":"User","site_admin":false},"body":"Introduces a new flag, `-Z saturating-float-casts`, which makes code generation for int->float and float->int casts safe (`undef`-free), implementing [the saturating semantics laid out by](https://github.com/rust-lang/rust/issues/10184#issuecomment-299229143) @jorendorff for float->int casts and overflowing to infinity for `u128::MAX` -> `f32`. Constant evaluation in trans also behaves the same way &ndash; even without the -Z flag, because it doesn't affect run time or type checking.\r\nThe HIR constant evaluator is unaffected because it currently works correctly for u128->f32 and returns an error for problematic float->casts. That error is conservatively correct and we should be careful to not accept more code in constant expressions.\r\n\r\nMany thanks to @eddyb, whose APFloat port simplified many parts of this patch, and made HIR constant evaluation recognize dangerous float casts as mentioned above.\r\nAlso thanks to @ActuallyaDeviloper whose branchless implementation served as inspiration for this implementation.\r\n\r\ncc #10184 #41799\r\nfixes #45134","created_at":"2017-10-11T16:30:19Z","updated_at":"2017-10-11T19:48:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f5095265790255c9bef56f9aedd4a6e6750fae6a","assignee":{"login":"eddyb","id":77424,"avatar_url":"https://avatars2.githubusercontent.com/u/77424?v=4","gravatar_id":"","url":"https://api.github.com/users/eddyb","html_url":"https://github.com/eddyb","followers_url":"https://api.github.com/users/eddyb/followers","following_url":"https://api.github.com/users/eddyb/following{/other_user}","gists_url":"https://api.github.com/users/eddyb/gists{/gist_id}","starred_url":"https://api.github.com/users/eddyb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eddyb/subscriptions","organizations_url":"https://api.github.com/users/eddyb/orgs","repos_url":"https://api.github.com/users/eddyb/repos","events_url":"https://api.github.com/users/eddyb/events{/privacy}","received_events_url":"https://api.github.com/users/eddyb/received_events","type":"User","site_admin":false},"assignees":[{"login":"eddyb","id":77424,"avatar_url":"https://avatars2.githubusercontent.com/u/77424?v=4","gravatar_id":"","url":"https://api.github.com/users/eddyb","html_url":"https://github.com/eddyb","followers_url":"https://api.github.com/users/eddyb/followers","following_url":"https://api.github.com/users/eddyb/following{/other_user}","gists_url":"https://api.github.com/users/eddyb/gists{/gist_id}","starred_url":"https://api.github.com/users/eddyb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eddyb/subscriptions","organizations_url":"https://api.github.com/users/eddyb/orgs","repos_url":"https://api.github.com/users/eddyb/repos","events_url":"https://api.github.com/users/eddyb/events{/privacy}","received_events_url":"https://api.github.com/users/eddyb/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang/rust/pulls/45205/commits","review_comments_url":"https://api.github.com/repos/rust-lang/rust/pulls/45205/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/45205/comments","statuses_url":"https://api.github.com/repos/rust-lang/rust/statuses/dd2563060a4a555953e6c878b99f512c799a7c83","head":{"label":"rkruppe:saturating-casts","ref":"saturating-casts","sha":"dd2563060a4a555953e6c878b99f512c799a7c83","user":{"login":"rkruppe","id":2311707,"avatar_url":"https://avatars2.githubusercontent.com/u/2311707?v=4","gravatar_id":"","url":"https://api.github.com/users/rkruppe","html_url":"https://github.com/rkruppe","followers_url":"https://api.github.com/users/rkruppe/followers","following_url":"https://api.github.com/users/rkruppe/following{/other_user}","gists_url":"https://api.github.com/users/rkruppe/gists{/gist_id}","starred_url":"https://api.github.com/users/rkruppe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkruppe/subscriptions","organizations_url":"https://api.github.com/users/rkruppe/orgs","repos_url":"https://api.github.com/users/rkruppe/repos","events_url":"https://api.github.com/users/rkruppe/events{/privacy}","received_events_url":"https://api.github.com/users/rkruppe/received_events","type":"User","site_admin":false},"repo":{"id":33378811,"name":"rust","full_name":"rkruppe/rust","owner":{"login":"rkruppe","id":2311707,"avatar_url":"https://avatars2.githubusercontent.com/u/2311707?v=4","gravatar_id":"","url":"https://api.github.com/users/rkruppe","html_url":"https://github.com/rkruppe","followers_url":"https://api.github.com/users/rkruppe/followers","following_url":"https://api.github.com/users/rkruppe/following{/other_user}","gists_url":"https://api.github.com/users/rkruppe/gists{/gist_id}","starred_url":"https://api.github.com/users/rkruppe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkruppe/subscriptions","organizations_url":"https://api.github.com/users/rkruppe/orgs","repos_url":"https://api.github.com/users/rkruppe/repos","events_url":"https://api.github.com/users/rkruppe/events{/privacy}","received_events_url":"https://api.github.com/users/rkruppe/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rkruppe/rust","description":"a safe, concurrent, practical language","fork":true,"url":"https://api.github.com/repos/rkruppe/rust","forks_url":"https://api.github.com/repos/rkruppe/rust/forks","keys_url":"https://api.github.com/repos/rkruppe/rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rkruppe/rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rkruppe/rust/teams","hooks_url":"https://api.github.com/repos/rkruppe/rust/hooks","issue_events_url":"https://api.github.com/repos/rkruppe/rust/issues/events{/number}","events_url":"https://api.github.com/repos/rkruppe/rust/events","assignees_url":"https://api.github.com/repos/rkruppe/rust/assignees{/user}","branches_url":"https://api.github.com/repos/rkruppe/rust/branches{/branch}","tags_url":"https://api.github.com/repos/rkruppe/rust/tags","blobs_url":"https://api.github.com/repos/rkruppe/rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rkruppe/rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rkruppe/rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/rkruppe/rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rkruppe/rust/statuses/{sha}","languages_url":"https://api.github.com/repos/rkruppe/rust/languages","stargazers_url":"https://api.github.com/repos/rkruppe/rust/stargazers","contributors_url":"https://api.github.com/repos/rkruppe/rust/contributors","subscribers_url":"https://api.github.com/repos/rkruppe/rust/subscribers","subscription_url":"https://api.github.com/repos/rkruppe/rust/subscription","commits_url":"https://api.github.com/repos/rkruppe/rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/rkruppe/rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/rkruppe/rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/rkruppe/rust/issues/comments{/number}","contents_url":"https://api.github.com/repos/rkruppe/rust/contents/{+path}","compare_url":"https://api.github.com/repos/rkruppe/rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rkruppe/rust/merges","archive_url":"https://api.github.com/repos/rkruppe/rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rkruppe/rust/downloads","issues_url":"https://api.github.com/repos/rkruppe/rust/issues{/number}","pulls_url":"https://api.github.com/repos/rkruppe/rust/pulls{/number}","milestones_url":"https://api.github.com/repos/rkruppe/rust/milestones{/number}","notifications_url":"https://api.github.com/repos/rkruppe/rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rkruppe/rust/labels{/name}","releases_url":"https://api.github.com/repos/rkruppe/rust/releases{/id}","deployments_url":"https://api.github.com/repos/rkruppe/rust/deployments","created_at":"2015-04-03T19:20:10Z","updated_at":"2016-01-26T21:20:25Z","pushed_at":"2017-10-11T18:33:21Z","git_url":"git://github.com/rkruppe/rust.git","ssh_url":"git@github.com:rkruppe/rust.git","clone_url":"https://github.com/rkruppe/rust.git","svn_url":"https://github.com/rkruppe/rust","homepage":"http://www.rust-lang.org","size":324823,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_projects":true,"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":"c0d40a1908723a7bbf0d2f745570162de250f188","user":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars1.githubusercontent.com/u/5430905?v=4","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://avatars1.githubusercontent.com/u/5430905?v=4","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":"2017-10-11T19:42:16Z","pushed_at":"2017-10-11T19:46:18Z","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":328612,"stargazers_count":23810,"watchers_count":23810,"language":"Rust","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4397,"mirror_url":null,"open_issues_count":2971,"forks":4397,"open_issues":2971,"watchers":23810,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/45205"},"html":{"href":"https://github.com/rust-lang/rust/pull/45205"},"issue":{"href":"https://api.github.com/repos/rust-lang/rust/issues/45205"},"comments":{"href":"https://api.github.com/repos/rust-lang/rust/issues/45205/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/45205/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/45205/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/rust/statuses/dd2563060a4a555953e6c878b99f512c799a7c83"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"est31"}}