Skip to content

The standard library writes no explicit receiver outside a trait body, and an attribute above an impl-block method is the method's (part of #727) - #3586

Merged
ehartford merged 4 commits into
mainfrom
explicit-receivers
Nov 24, 2026
Merged

ehartford merged 4 commits into
mainfrom
explicit-receivers

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Part of #727, which stays open: the last step there, refusing an explicit self, changes what compiles and waits for a go.

1. The sweep. 205 top-level dotted instance methods in lib/std (pub fn BuildCtx.fs(self: &Self) -> &ToolFs) move into impl blocks in the keyword form (pub fn fs() -> &ToolFs, mut fn, move fn), and 17 trait-impl methods take it too (tools/migrate_receivers.with). std.build held 150 of them. The generated Deref impl of a facade resource is written the same way. What is left in the tree is trait declarations (the carve-out), and source text inside fixtures and templates.

2. A compiler bug the sweep found. Parser.parse_impl_block read the attributes above a method and dropped them: @[suspends], @[must_use], @[tailrec], @[inline], @[noinline], @[no_alloc]. On main, this is accepted:

impl Gate:
    @[suspends]
    fn pass() -> i32: self.n
…
    no_suspend:
        print(g.pass())

std.sync only worked because its suspending methods were dotted. The attributes now reach the method, and a function attribute written above the impl line itself is refused instead of dropped.

3. Return types. Moving a method changes its signature text, so the -> Unit review looked at each. A typed probe showed which are needed: a body ending in an assignment returns the assigned value (D43), so those keep -> Unit. Six that end in a Unit call lose it; nine signatures are recorded in docs/unit-return-reviews.tsv with the reason.

Tests. err_727_suspends_on_impl_method (fails on main), err_727_function_attribute_above_impl_block, err_727_once_call_in_no_suspend (nothing checked that Once.call_once still declared it may suspend; the first battery only caught the same slip on Barrier.wait).

Evidence at 2c21606. :behavior-tests, :runtime-tests, :native-compile-error-tests, :validate-all-tests, :deep-debug-tool-tests (audit:receiver-surface), pre-checks green; battery green (the first one was red on err_barrier_wait_in_no_suspend: an attribute my first script pass left above an impl header); linux-aarch64 container leg green (:build, :behavior-tests, :runtime-tests, :native-compile-error-tests); :release-checks survey: all targets green.

Eric Hartford added 4 commits November 24, 2026 02:09
…: 205 dotted methods move into impl blocks and 17 trait-impl methods take the keyword form (part of #727)
…@[must_use], @[tailrec], @[inline], @[noinline] and @[no_alloc] were read and dropped there (found by #727's move of std.sync into impl blocks)
…, and a function attribute above an impl block is refused instead of dropped (part of #727)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant