You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bare 'mut self' on a dotted method (fn T.m(mut self, …)): field write is an ICE (invalid MIR), field read loses its type — #897 sibling #3112
A bare mut self receiver (no : Self) on a dotted top-level method, fn T.m(mut self, …), passes the front end and then:
writing a field through it is an ICE in the MIR validator;
reading a raw-pointer field through it loses the field's type (self.ptr == null → "null requires pointer type context").
This is the sibling of #897. That fix (d8cd406, #2718) covers the impl T: mut fn m(mut self) form, which now works. The dotted form still doesn't.
with v0.16.0.8 (~/.local/bin/with, repo HEAD 4c215ba, which contains d8cd406), darwin-aarch64.
Repro 1: ICE on field write
type Owned { n: i32 }
fn Owned.set(mut self, v: i32):
self.n = v
fn main:
var o = Owned { n: 0 }
o.set(3)
print(f"{o.n}")
error: internal compiler error: invalid MIR before codegen (a bug in the With compiler, not in this program): use rvalue type is incompatible with assign destination (dest ty=14 kind=4, src ty=3 kind=1) in `Owned.set`
--> ice_int.w:4:5
4 | self.n = v
| ^
The same happens for a raw-pointer field (type Owned { ptr: *mut u8 } … self.ptr = p: src ty=123 kind=13), with or without a Drop impl.
Repro 2: field type lost on read
type Owned { ptr: *mut u8 }
fn Owned.ok(mut self) -> bool:
if self.ptr == null: return false
true
fn main:
var o = Owned { ptr: null }
print(f"{o.ok()}")
error: null requires pointer type context
--> null_untyped.w:4:20
4 | if self.ptr == null: return false
| ^^^^
As #897 put it: either the bare spelling is legal and behaves exactly like mut self: Self, or it is a parse/sema error at the receiver. It should never reach the MIR validator.
Found while writing a libcurl wrapper (fn HeaderList.append(mut self, line: &str) assigning self.ptr), see #3111.
Activity
#3112: a written `self` with no type on a function outside a type is …
#3112: a written `self` with no type on a function outside a type is …