rust-lang/rust · error
immutable unnamed local
Error message
immutable unnamed local
What it means
mutability_errors.rs:91: while reporting a mutability error on a local, for a local that is not the direct access place, the diagnostic does self.local_name(local).expect("immutable unnamed local"). The invariant: a local reachable here has a user-visible name. Compiler-generated temporaries or unnamed locals are not expected on this path.
Source
Thrown at compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs:91
access_place={:?}, span={:?}, the_place_err={:?}, error_access={:?}, location={:?},\
)",
access_place, span, the_place_err, error_access, location,
);
let mut err;
let item_msg;
let reason;
let mut opt_source = None;
let access_place_desc = self.describe_any_place(access_place.as_ref());
debug!("report_mutability_error: access_place_desc={:?}", access_place_desc);
match the_place_err {
PlaceRef { local, projection: [] } => {
item_msg = access_place_desc;
if access_place.as_local().is_some() {
reason = ", as it is not declared as mutable".to_string();
} else {
let name = self.local_name(local).expect("immutable unnamed local");
reason = format!(", as `{name}` is not declared as mutable");
}
}
PlaceRef {
local,
projection: [proj_base @ .., ProjectionElem::Field(upvar_index, _)],
} => {
debug_assert!(is_closure_like(
Place::ty_from(local, proj_base, self.body, self.infcx.tcx).ty
));
let imm_borrow_derefed = self.upvars[upvar_index.index()]
.place
.deref_tys()
.any(|ty| matches!(ty.kind(), ty::Ref(.., hir::Mutability::Not)));
// If the place is immutable then:View on GitHub (pinned to 7088e4b63a)
Solutions
- File a rustc ICE with the minimized code that produces the mutability error.
- Rewrite the expression so the offending place is a named binding (bind the temporary to a let).
- Bisect across nightlies with cargo bisect-rustc.
- Try stable vs nightly to confirm a regression.
Defensive patterns
Strategy: fallback
Prevention
- Treat as a borrowck diagnostic ICE; report with the minimized code that produces the mutability error.
- Bind compiler-generated temporaries to a named `let` to give the place a user-visible name.
- Bisect with cargo bisect-rustc and compare stable vs nightly.
- Pin to a known-good toolchain until fixed.
When it happens
Trigger: Borrowck builds a mutability diagnostic for an unnamed/compiler-generated local that reaches the non-access-place branch, where local_name() returns None.
Common situations: An ICE inside borrowck's diagnostic emitter, typically a regression when reporting `cannot assign`-style errors for synthetic temporaries; not triggered by ordinary source.
Related errors
- return depth from strip_n_refs should be smaller than the in
- coroutine lowered from async fn should be in fn
- coroutine lowered from gen fn should be in fn
- alt layout should always work
- alt layout should have a niche like the regular one
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/04f8780ff1443e8b.
Report an issue: GitHub.