-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
E0122 says bounds aren't enforced, but they actually are? #40640
Comments
Future compatibility warnings are made explicitly un"turn-off"able exactly because people "turn-off" them and then when stable version making it a hard error releases, complain on rust-lang/rust that their code was broken without any prior warning. |
How hard is it to enforce trait bounds in type aliases? |
I've run into similar issue recently. What's weird is that compiler actually does enforce trait bounds in type aliases, at least in this case. If you try to compile the example, you'll see that compiler contradicts itself. I can't imagine a universe in which it isn't a bug. |
In my case I want to use a trait's associated types, so the type bound is unavoidable:
For this use the message is pure noise. And as @Kixunil mentioned: it looks like the bound is enforced:
fails to compile with:
Playground: https://play.rust-lang.org/?gist=85d34e30da9c6ba78893fd885ab05547 |
Shockingly, you're allowed to make a type alias using associated types without declaring the bounds: type Foo<I> = Box<<I as Iterator>::Item>; |
Oh, interesting! I hadn't considered that variation. |
I think the message is referring to the fact that you can do something like this without raising an error:
You do get an error if |
@durka Interesting. Seems like the best way to turn off that message is to remove the bound and put it into doc comment. |
Any plans for actually enforcing these bounds soon?
In most cases, objects which don't satisfy those bounds cannot be created (due to other bounds). I don't think this is significant enough to put Rust's stability guarantees at risk. So please make these warnings suppress-able, if this is at low priority for being implemented. |
Triage: as far as I know, these warnings are not silence-able today. |
Checking the linked playground, and just off memory, I believe this error message has been removed? Is there anything left to do here? |
Looks like it is still there if you don't attempt to use the alias: https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=c12b07f4ca88e40071ccfdbe2167e347
It seems to me the compiler is not enforcing the bounds in the alias. Rather, it's enforcing implicit bounds that come from using a fully qualified associated type in the right side of the alias, as I noted above. That is, if you remove the Circling back around to @steveklabnik's comment, the warnings are now silenceable with With compiler-colored glasses, the only issue is that we don't enforce bounds declared in type aliases (why though?), but it's definitely a confusing diagnostic situation in all of these cases. |
For multistr I've included trait bounds in type aliases so that it's clear in the documentation what should be passed to the generics for these aliases, e.g. SliceArray5.
But because I've generated several of these aliases E0122 floods my error output and I don't see any way of turning it off:
(× 17)
It'd be really nice if I could silence this error somehow, because while it's good to have the error by default, it's making debugging my code very hard when I have to scroll past a wall of these errors.
The text was updated successfully, but these errors were encountered: