Implement DerefImm and DerefMut #7141#12491
Conversation
|
But then there's Oh, and how could #12402 happen while I can't seem to call a method on the right trait (if it's not in EDIT: I didn't realize it at first, but |
|
Is this ready for review? |
|
Ended up fixing #12402 and removing |
|
/me will review |
|
@eddyb please put a description into the issue at some point, since bors will not pick up its title when it merges. |
|
This looks excellent. You're missing a few tests. Here is a patch to apply: https://gist.github.com/nikomatsakis/9348385 r+ once the new tests are applied and nit corrected (and rebased, of course ;) |
|
Actually, the one other thing I'd like to see: Some new run-pass tests that: (1) do not depend on (2) are targeted at checking that the correct method (deref vs deref_mut) is invoked in the correct times. I'm envisioning a type which either modifies a |
|
Regarding the existing overloaded operator test, arguably it should be moved to |
|
Updated my patch with some fns for the compile-fail tests. |
Add the `Deref` and `DerefMut` traits and implement overloading explicit dereferences.
Enables the dereference overloads introduced by #12491 to be applied wherever automatic dereferences would be used (field accesses, method calls and indexing).
fix span calculation for non-ascii in `needless_return` Fixes rust-lang#12491 Probably fixes rust-lang#12328 as well, but that one has no reproducer, so 🤷 The bug was that the lint used `rfind()` for finding the byte index of the start of the previous non-whitespace character: ``` // abc\n return; ^ ``` ... then subtracting one to get the byte index of the actual whitespace (the `\n` here). (Subtracting instead of adding because it treats this as the length from the `return` token to the `\n`) That's correct for ascii, like here, and will get us to the `\n`, however for non ascii, the `c` could be multiple bytes wide, which would put us in the middle of a codepoint if we simply subtract 1 and is what caused the ICE. There's probably a lot of ways we could fix this. This PR changes it to iterate backwards using bytes instead of characters, so that when `rposition()` finally finds a non-whitespace byte, we *know* that we've skipped exactly 1 byte. This was *probably*(?) what the code was intending to do changelog: Fix ICE in [`needless_return`] when previous line end in a non-ascii character
Add the
DerefandDerefMuttraits and implement overloading explicit dereferences.