{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/21203","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/21203/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/21203/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/21203/events","html_url":"https://github.com/rust-lang/rust/issues/21203","id":54478475,"number":21203,"title":"Allow where clause predicates that contain no type parameters","user":{"login":"erickt","id":84711,"avatar_url":"https://avatars.githubusercontent.com/u/84711?v=3","gravatar_id":"","url":"https://api.github.com/users/erickt","html_url":"https://github.com/erickt","followers_url":"https://api.github.com/users/erickt/followers","following_url":"https://api.github.com/users/erickt/following{/other_user}","gists_url":"https://api.github.com/users/erickt/gists{/gist_id}","starred_url":"https://api.github.com/users/erickt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erickt/subscriptions","organizations_url":"https://api.github.com/users/erickt/orgs","repos_url":"https://api.github.com/users/erickt/repos","events_url":"https://api.github.com/users/erickt/events{/privacy}","received_events_url":"https://api.github.com/users/erickt/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-typesystem","name":"A-typesystem","color":"d7e102"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-01-15T17:26:53Z","updated_at":"2015-02-07T10:49:26Z","closed_at":null,"body":"Where clauses right now require predicates to contain type parameters, as in:\r\n\r\n```rust\r\ntrait Foo {\r\n    fn foo(&self);\r\n}\r\n\r\nstruct Bar<T> {\r\n    x: T,\r\n}\r\n\r\nimpl<T> Foo for Bar<T> where T: Foo {\r\n    fn foo(&self) {\r\n        self.x.foo()\r\n    }\r\n}\r\n```\r\n\r\nBut we cannot add constraints on non-generic types:\r\n\r\n```rust\r\nstruct Baz { x: i32 }\r\n\r\nimpl Foo for Baz where i32: Foo {\r\n    fn foo(&self) {\r\n        self.x.foo()\r\n    }\r\n}\r\n```\r\n\r\nWill error out with:\r\n\r\n```\r\ntest.rs:15:1: 19:2 error: cannot bound type `i32`, where clause bounds may only be attached to types involving type parameters\r\ntest.rs:15 impl Foo for Baz where i32: Foo {\r\ntest.rs:16     fn foo(&self) {\r\ntest.rs:17         self.x.foo()\r\ntest.rs:18     }\r\ntest.rs:19 }\r\n```\r\n\r\nIn hand written code this usually won't come up, but this would be really helpful for a code generator like `macro_rules!` or `#[derive]`, especially when dealing with associated types. Currently the only way to know if a type is generic or not is to manually walk it and see if any of the type paths start with the same name as a type parameter. If so, add that type to the predicate list. Instead, it would be much simpler if we could just add all the types listed in a field or enum to the predicate list and let the type checker report an error if one of those types doesn't implement the trait.\r\n\r\ncc @nikomatsakis, @jroesch"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/73359337","html_url":"https://github.com/rust-lang/rust/issues/21203#issuecomment-73359337","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/21203","id":73359337,"user":{"login":"jroesch","id":696509,"avatar_url":"https://avatars.githubusercontent.com/u/696509?v=3","gravatar_id":"","url":"https://api.github.com/users/jroesch","html_url":"https://github.com/jroesch","followers_url":"https://api.github.com/users/jroesch/followers","following_url":"https://api.github.com/users/jroesch/following{/other_user}","gists_url":"https://api.github.com/users/jroesch/gists{/gist_id}","starred_url":"https://api.github.com/users/jroesch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jroesch/subscriptions","organizations_url":"https://api.github.com/users/jroesch/orgs","repos_url":"https://api.github.com/users/jroesch/repos","events_url":"https://api.github.com/users/jroesch/events{/privacy}","received_events_url":"https://api.github.com/users/jroesch/received_events","type":"User","site_admin":false},"created_at":"2015-02-07T10:49:26Z","updated_at":"2015-02-07T10:49:26Z","body":"I lost track of this, did anyone remove the check that ensures bound types include a type parameter? I remember we had talked about shuffling around some error reporting as well, but its been too many days since I've thought about this."}}