Repository navigation
A trait impl method that omits its return type is checked against the trait's as a written one is; one report per return mismatch - #3598
Merged
Conversation
… trait's as a written one is; one report per return mismatch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while sizing item 1 of #3061 (part of #3061 and #2519: both want to remove a return type the trait already declares, and that form was broken).
The bug.
impl Size for i64: fn size(): selfunderfn size(self: &Self) -> i64was an internal compiler error (invalid MIR: a&i64assigned to ani64). With the return written, it compiled.Root cause. In
check_fn_decl's body check (src/SemaCheck.with), a method with no written return and a trait contract set its signature from the contract and stopped:check_annotated_body_resultran only on the written branch. So the tail was never checked or adjusted against the declared return (the copy out of a&Selftail, the implicitOk), andcheck_body_resultwas told the function had no declared return, which also skipped the owned-returned-as-view check.The fix. The trait's return is the declared return for the whole body check: it is passed to
check_body_under_returnas one, andcheck_annotated_body_resultruns on the contract branch.Also. A written return that the tail did not meet was reported twice (a bare
return type mismatch, then the one naming both types).check_body_resultnow leaves a declared return's mismatch to the check that names the types and reports only what that check lets by.Tests:
behav_trait_impl_omitted_return_is_the_traits(a&Selftail, an integer literal underf64, a bare value underResultandOption,Self),err_trait_impl_omitted_return_mismatch. Both fail on main.Evidence at 7227f2e: both compilers check the source; release build,
:unit-return-review,:ceremony-census,:self-audit,:native-compile-error-tests,:behavior-testsgreen; battery green;:release-checkssurvey: all targets green. Sema only: no platform leg.