{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/32842","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/32842/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/32842/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/32842/events","html_url":"https://github.com/rust-lang/rust/issues/32842","id":147048540,"number":32842,"title":"Constant evaluation failure reports an error on each use-site","user":{"login":"retep998","id":666308,"avatar_url":"https://avatars.githubusercontent.com/u/666308?v=3","gravatar_id":"","url":"https://api.github.com/users/retep998","html_url":"https://github.com/retep998","followers_url":"https://api.github.com/users/retep998/followers","following_url":"https://api.github.com/users/retep998/following{/other_user}","gists_url":"https://api.github.com/users/retep998/gists{/gist_id}","starred_url":"https://api.github.com/users/retep998/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/retep998/subscriptions","organizations_url":"https://api.github.com/users/retep998/orgs","repos_url":"https://api.github.com/users/retep998/repos","events_url":"https://api.github.com/users/retep998/events{/privacy}","received_events_url":"https://api.github.com/users/retep998/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-diagnostics","name":"A-diagnostics","color":"d7e102"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2016-04-08T21:50:31Z","updated_at":"2016-04-13T07:51:14Z","closed_at":null,"body":"In the past few days `winapi` was hit with a deluge of this warning (266 of them to be precise): `warning: constant evaluation error: attempted to subtract with overflow. This will become a HARD ERROR in the future, #[warn(const_err)] on by default`\r\n\r\nI can't say I'm too thrilled as `winapi` makes use of this pattern quite a bit in defining constants: `pub const LVN_DELETEALLITEMS: ::UINT = LVN_FIRST - 4;`\r\n\r\nThe workaround is kinda ugly: `pub const LVN_DELETEALLITEMS: ::UINT = (LVN_FIRST as ::INT - 4) as ::UINT;`"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/209288768","html_url":"https://github.com/rust-lang/rust/issues/32842#issuecomment-209288768","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/32842","id":209288768,"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},"created_at":"2016-04-13T07:51:14Z","updated_at":"2016-04-13T07:51:14Z","body":"No. We currently report const eval errors in a few locations, with differing criticality:\r\n\r\n1. the const_err lint is triggered in the `check_const` pass on all constants and statics\r\n2. the const_err lint is triggered in the `check_const` pass on division by zero for all expressions that can be constant evaluated\r\n3. during trans, if a const eval error occurs outside a constant's expression, a warning is triggered and normal trans is used\r\n4. during trans, if a const eval error occurs in a constant's expression, an error is triggered and compilation is aborted at some point.\r\n\r\nThe code shown by @arielb1 triggers 2 and 4 on stable and 1, 2 and 4 on nightly (and has been doing so since [rfc1229](https://github.com/rust-lang/rfcs/blob/master/text/1229-compile-time-asserts.md)).\r\n\r\nWe can probably eliminate 2 from triggering inside constants\r\n\r\nSince 1 is just a lint, it doesn't stop compilation and so the expression is still compiled. Trans will need to report an error, because otherwise we'd end up miscompiling the constant. We could make sure that it only shows up once, by caching translated constants (and thus translating every constant only once). With the lint enabled we'd still report the const eval error twice though, once in the lint, and once at the first use site.\r\n\r\nTurning the lint into a hard error will eliminate all of these duplicates, because compilation can never get that far. This would also greatly simplify trans/consts, because we can simply `bug!` out wherever we reported errors before."}}