-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Overly verbose diagnostic when calling .as_ref() on type not implementing AsRef #89806
Comments
This regressed between 1.52.0 and 1.53.0. Bisection gives:
|
Seems similar to #84769 (though this probably isn't a duplicate since that issue doesn't appear to have regressed). |
We need to filter traits with blacket impls on all of these types, I guess. We can also get away with a check for "oh, we're suggesting all of these? it's likely wrong" and silence them that way (with a length check or something similarly simple). |
@rustbot claim |
Hi @estebank |
These suggestions show up here as well struct S;
impl std::convert::TryInto<i32> for S {
type Error = ();
fn try_into(self) -> Result<i32, Self::Error> {
Err(())
}
}
mod out_of_scope {
pub trait TryInto {
fn try_into(self) -> Result<i32, ()>;
}
impl TryInto for super::S {
fn try_into(self) -> Result<i32, ()> {
Err(())
}
}
}
fn err(a: S) -> i32 {
a.try_into().unwrap()
} Yielding an output of
Here they would not fix the actual issue, and introduce a new one if incorporated. That being said, this is probably not a big deal since I can't reproduce this in more realistic scenarios where someone is not defining their own |
@yuvaldolev the code is being suggested here: For the case in the comment above, we might want to delay emitting a suggestion until we've confirmed that importing a trait wouldn't be enough to fix the problem. For the original report... we might want to check whether the trait we've found doesn't have a blanket impl, because those would otherwise always suggest the wrapper types, and would be always wrong. We try to do that with a deny list for specific traits, which we can extend to include |
@estebank Thanks! |
…agnostic, r=estebank Skipping verbose diagnostic suggestions when calling .as_ref() on type not implementing AsRef Addresses rust-lang#89806 Skipping suggestions when calling `.as_ref()` for types that do not implement the `AsRef` trait. r? `@estebank`
Shouldn't this be closed now that the relevant PR is merged? |
Following code seems to lead to overly long diagnostics: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20main()%20%7B%0A%20%20%20%200u8.as_ref()%0A%7D
The current output is:
Note that this happens not just with 0u8 but with most types not implementing AsRef as far as I can see.
The text was updated successfully, but these errors were encountered: