Skip to content

rustlantis: validate projection chains when constructing places #1160

Closed

Description

@uurl

Problem

mir::syntax::Place currently accepts projection chains without validating them when they are constructed.

Both Place::from_projected and Place::project can therefore create a Place containing an invalid sequence of ProjectionElems. Invalid projections can remain unchecked until Place::ty()
calls TyId::projected_ty(), which may panic while interpreting the chain.

This delays detection of malformed MIR state and makes the source of the invalid projection harder to identify.

Proposed change

Validate each projection as it is appended to a Place.

Projection validation should cover:

  • dereferencing only pointer/reference types
  • tuple field bounds
  • struct field bounds
  • array projection source types and constant-index bounds
  • enum downcast variant and field bounds
  • consistency between the type stored in DowncastField and the actual field type

The projection type semantics should remain centralized rather than duplicating the ProjectionElem matching logic between construction and later type lookup.

Expected behavior

After this change, invalid projection chains should fail at the point where the Place is constructed or extended, rather than later during Place::ty().

Existing valid projection paths generated by Rustlantis should continue to behave unchanged.

Activity

  1. added
    bugSomething isn't working
    fuzzerFuzzing infrastructure (rustlantis, difftest)
    enhancementNew feature or request
    questionFurther information is requested
    and removed
    bugSomething isn't working
    on Aug 24, 2026
  2. nihalpasham commented on Aug 24, 2026

    @nihalpasham
    Collaborator

    This needs a narrower, evidence-backed problem statement before we schedule it.

    • Place::from_projected and Place::project are unchecked, but we have not found a production caller that creates an invalid chain. Please provide a minimal generated seed or caller that fails today.
    • Validation must use the authoritative LocalDecls; a caller-supplied base type is not enough. Index must also reject a missing or non-usize local.
    • Add a fail-before/pass-after regression through the real generator path, plus a valid-chain control.

    Without a reachable failure, please frame this as defensive hardening and explain its concrete maintenance value. This follows the current acceptance criteria.

  3. nihalpasham commented on Sep 18, 2026

    @nihalpasham
    Collaborator

    I reviewed #1263 as defensive hardening. Place construction now checks projections against the authoritative local declarations, including rejecting an i32 index local where usize is required.

    The valid-chain controls and seed comparisons pass. This catches malformed generator state before it can be mistaken for a backend failure; I am not claiming a reachable old seed failure. The PR depends on #1262's generator build fix; hosted CI passes on both reviewed heads.

    This covers the agreed defensive scope and closes this issue once merged.

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

    enhancementNew feature or requestfuzzerFuzzing infrastructure (rustlantis, difftest)questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions