Skip to content

D111: an unannotated let of a str field, and a str global read, still need .clone() (seven sites the #2942 sweep could not remove) #3026

Closed

Description

@ehartford

Found by the #2942 sweep (branch ceremony-sweeps): removing .clone() at the census's 483 str-clone sites leaves seven the compiler refuses, all one gap.

Field and local-record fields. let source_path = self.source_path (compiler/Compilation.w:1125), let saved_module_path = self.current_module_path (SemaCheck.w:29540), let record_name = record.name (ComptimeEval.w:6428): an unannotated let of a str field binds a view of the place (field_let_binds_as_view; MIR alias-binds it), so a later self.…(…) mutation is refused ("cannot mutate self while source_path is a live view into it") and consuming record afterwards is refused ("view record_name may outlive its origin"). The diagnostic's own help is let source_path: str = …, which is the str-view-copy-annotation ceremony the census counts, and D179's comment on type_takes_value_on_binding says the unannotated binding takes the str — but that rule runs only when the expression is a &str, not a str place.

Globals. g_migrate_shared_defs_prefix as a tail value (CiMigrate.w:395), g_ci_bail_location / g_ci_bail_message (CImport.w:18486, 18492), build_cache_compiler_fingerprint (BuildGraphCache.w:276): "cannot move out of global …: clone it (.clone()) instead" (reject_move_out_of_global, keyed on type_needs_drop). A str read out of a global is a count increment, never a move.

D111: a str is a value; passing a str always copies; code using str never sees "use of moved value" and never needs .clone(). So: an unannotated let of a str place (field, element, global) takes the str (a str_clone_ref copy in MIR, the annotated form's path), and a global str read in value position copies. Fixtures: let s = self.name; self.name = "x"; print(s) prints the old name; fn f() -> str: g_name compiles. Then the seven sites drop their .clone() and the census pattern str-view-copy-annotation can sweep.

Activity

  1. added 6 commits that reference this issue on Nov 3, 2026
  2. added 3 commits that reference this issue on Nov 3, 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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions