Re:Mistakes with Rust smart pointers: when Deref goes wrong
by ninepoints on Monday July 10, 2023 @03:31AM
(#36663147)
What does this comment mean? Function parameters used or not are part of the function signature, so obviously would participate in any form of argument dependent lookup.
[ Parent
| on HN ]
Re:Mistakes with Rust smart pointers: when Deref goes wrong
by codeflo on Monday July 10, 2023 @03:51AM
(#36663273)
I mean, you can do as small a change as adding a const somewhere, and cause an (almost) independent file somewhere else in your codebase to hit the wrong overload.
Re:Mistakes with Rust smart pointers: when Deref goes wrong
by foldr on Monday July 10, 2023 @04:08AM
(#36663384)
Perhaps a case where after removing the unused parameter and updating all the call sites, none of the calls resolve to the original function anymore.
Re:Mistakes with Rust smart pointers: when Deref goes wrong
by ninepoints on Monday July 10, 2023 @05:30AM
(#36663939)
And we would expect this behavior why?
Re:Mistakes with Rust smart pointers: when Deref goes wrong
by quietbritishjim on Monday July 10, 2023 @05:39AM
(#36663988)
If you start with
void foo(std::string x, int y);
void foo(const char* x);
Then calls too foo("bar", 0) would resolve to the first overload: the second isn't a match at all, but the first is a match with an implicit conversion from const char* to std::string. But if you removed the second parameter, including arguments at all call sites, then foo("bar") would match the second better because it doesn't involve any conversions, so it would be selected instead of the first.
Re:Mistakes with Rust smart pointers: when Deref goes wrong
by quietbritishjim on Monday July 10, 2023 @05:36AM
(#36663970)
Perhaps the argument had a default value so call sites didn't need to mention it. Although I can't think of removing an argument with a default value would change its priority in the overload set. But I definitely don't know all the rules so I can believe that it could!
Re:Mistakes with Rust smart pointers: when Deref goes wrong
by IshKebab on Monday July 10, 2023 @05:55PM
(#36673491)
There was an argument that was not used by the function implementation. I removed it from the signature entirely - at the definition and the call sites.
Boom. No longer compiles.
Yes I understand the complex and surprising rules that cause this to happen. That doesn't make them any less complex and surprising.
Re:Mistakes with Rust smart pointers: when Deref goes wrong
by qsdf38100 on Monday July 10, 2023 @08:08PM
(#36674843)
"not used by the function implementation" doesn't mean "not passed in by callers".
The callers won't find a matching signature once there is 1 less parameter. I don't see what is confusing about it.
You probably misunderstood that warning as "No callers pass this parameter", which btw would only make sense for a parameter with a default value.
Re:Mistakes with Rust smart pointers: when Deref goes wrong
by IshKebab on Wednesday July 12, 2023 @03:20PM
(#36700274)
I removed the parameter from the definition and call sites.
I went from
void foo(A a, B b) {
// Only use a
}
...
foo(x, y);
To this void foo(A a) {
// Only use a
}
...
foo(x);
And it stopped compiling. There were no other functions called `foo` so it is nothing to do with overloading.I'll give you the answer if you want or we can leave it a mystery so you can experience how confusing that behaviour is...
Re:Mistakes with Rust smart pointers: when Deref goes wrong
by quietbritishjim on Thursday July 13, 2023 @07:39PM
(#36717569)
All I can think of is Koenig lookup [1]: B and foo were defined in a namespace, and the calls to foo were not in that namespace and didn't explicitly qualify foo but still found it.
[1] https://en.m.wikipedia.org/wiki/Argument-dependent_name_look...
Re:Mistakes with Rust smart pointers: when Deref goes wrong
by qsdf38100 on Thursday July 13, 2023 @07:58PM
(#36717712)
Yes I’d like to know the answer.
Re:Mistakes with Rust smart pointers: when Deref goes wrong
by ninepoints on Saturday July 15, 2023 @03:58AM
(#36734602)
Sigh. This is entirely expected behavior, and in fact, is _necessary_ behavior. If changing signatures in that way continued to allow code to "compile" with reckless abandon, so many things would break. I think before complaining, you need to understand how general symbol resolution, name mangling, and argument dependent lookup work. And if you're too impatient to learn, you're not actually in a position to criticize.