-
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
Type bounds are ignored in trait and impl function definitions #24011
Comments
In this commit, I managed to reuse the existing infrastructure to check the bounds of impl function items. I do not really have an in depth understanding of the well formedness checks, but if this approach is reasonable I am pretty sure it is possible to avoid most of the duplicated code. But I could not get this approach to work for trait items, because it relies on |
AFAICT, there is no unsoundness exposed by these examples, since any attempt to create instances of the types one needs to pass (to invoke the functions that are unchecked here) will fail ... right? I agree there is a bug here; I just want to double-check the above, in terms of how to triage it. |
Yes I think it should not be unsound, as it should be impossible to create
structs that do not satisfy their type constraint. Also calling a function
that was defined in a bound will raise an error.
The only problem with this is that rustc does not check the well-formedness
of impl and trait function items and this leads to pretty confusing error
messages.
|
I've noticed this sort of thing before. I can look into it. Probably worth trying to do before 1.0. |
triage: P-high (1.0) |
This is related to #19182. |
A similar issue with default type parameters that compiles successfully: trait Bar {}
struct Foo<T = usize>(T) where T: Bar;
|
Fixed by #27641. |
It seems that
rustc
does not check if the type paramater satisfy the declared type bounds in trait and impl function definitions, but only for bare functions.Rustc
fails on the following code with the following, rather confusing, error message:type &mut std::collections::hash::set::HashSet<[u8]> does not implement any method in scope named insert
But I think that
rustc
should fail at an earlier stage, because[u8]
does not implementcore::marker::Sized
.The following code is a more general example and does not depend on any library.
The text was updated successfully, but these errors were encountered: