Skip to content

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

Closed

Description

@ehartford

Summary

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
  |                    ^^^^

Same bodies with other spellings

receiver result
fn Owned.set(mut self, v: i32) ICE
fn Owned.set(mut self: Self, v: i32) ✅ prints 3
impl Owned: mut fn set(v: i32) ✅ prints 3
impl Owned: mut fn set(mut self, v: i32) ✅ prints 3 (the #897 fix)
fn Owned.ok(mut self) reading self.ptr == null "null requires pointer type context"
fn Owned.ok(mut self: Self) same body ✅ prints false

Expected

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

  1. added
    bug
    on Nov 9, 2026
  2. added 2 commits that reference this issue on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions