Skip to content

Comprehensive niche checks for Rust #262

@nikomatsakis

Description

@nikomatsakis
Contributor
Metadata
Point of contact @1c3t3a
Team(s) compiler, opsem
Goal document 2025h2/comprehensive-niche-checks

Summary

Add runtime checks to rustc that check for valid niche values. This is an
extension of a previous project goal
that added null pointer and enum checks and generally works towards checking for
Undefined behavior at runtime (in debug builds / behind compiler flags).

The check should fire for invalid values that are already created by inserting
a check at load-time / on function entry.

Tasks and status

  • Discussion and moral support (compiler, opsem Team)
    Implementation (@1c3t3a, @jakos-sec)
    MCP decision (compiler Team)
    Dedicated reviewer (compiler, opsem Team)

Note: we have updated the body to match the 2025h2 goal. Your original text is preserved below.

Metadata
Point of contact @1c3t3a
Team(s) compiler, lang, opsem
Goal document 2025h1/null-enum-discriminant-debug-checks

Summary

Add runtime checks to rustc that check for null pointers on pointer access and
invalid enum discriminants. Similar to integer overflow and pointer alignment
checks, this will only be enabled in debug builds.

Tasks and status

  • Discussion and moral support (lang, opsem Team)
    Implementation (@1c3t3a, @vabr-g)
    Standard reviews (compiler, opsem Team)

Activity

added this to the 2025h1 milestone on Feb 18, 2025
nikomatsakis

nikomatsakis commented on Feb 18, 2025

@nikomatsakis
ContributorAuthor

This issue is intended for status updates only.

For general questions or comments, please contact the owner(s) directly.

1c3t3a

1c3t3a commented on Feb 19, 2025

@1c3t3a
Member

Status update: The null-checks landed in rust#134424. Next up are the enum discriminant checks.

moved this to Project goals in Lang team featureson Feb 21, 2025
moved this to Project goal in Lang team featureson Mar 4, 2025
1c3t3a

1c3t3a commented on May 22, 2025

@1c3t3a
Member

Upps, giving another status update here:

Key developments: Landed an extension of the alignment check to include (mutable) borrows in rust#137940. Working on the enums check (no draft PR yet). Hope to open a PR by mid next week.

Blockers: None so far.

Help wanted: Happy to join forces on general checks and for advice what other UB would be great to check!! :)

1c3t3a

1c3t3a commented on Jul 25, 2025

@1c3t3a
Member

Key developments: Landed the enum discriminant check and enabled it for transmutes to enums for now (this is not so powerful), currently extending it to union reads and pointer reads.

Blockers: question of how to insert a check if we already observe UB (e.g. the enum is only represented by an i1 in LLVM IR). This is to be addressed by the next project goal: https://rust-lang.github.io/rust-project-goals/2025h2/comprehensive-niche-checks.html.

changed the title [-]Null and enum-discriminant runtime checks in debug builds[/-] [+]Comprehensive niche checks for Rust[/+] on Sep 16, 2025
nikomatsakis

nikomatsakis commented on Sep 16, 2025

@nikomatsakis
ContributorAuthor

This is a continuing project goal, and the updates below this comment will be for the new period 2025h2

nikomatsakis

nikomatsakis commented on Sep 16, 2025

@nikomatsakis
ContributorAuthor

This is a continuing project goal, and the updates below this comment will be for the new period 2025h2

nikomatsakis

nikomatsakis commented on Sep 16, 2025

@nikomatsakis
ContributorAuthor

This is a continuing project goal, and the updates below this comment will be for the new period 2025h2

nikomatsakis

nikomatsakis commented on Sep 16, 2025

@nikomatsakis
ContributorAuthor

This is a continuing project goal, and the updates below this comment will be for the new period 2025h2

nikomatsakis

nikomatsakis commented on Sep 16, 2025

@nikomatsakis
ContributorAuthor

This is a continuing project goal, and the updates below this comment will be for the new period 2025h2

nikomatsakis

nikomatsakis commented on Sep 16, 2025

@nikomatsakis
ContributorAuthor

This is a continuing project goal, and the updates below this comment will be for the new period 2025h2

nikomatsakis

nikomatsakis commented on Sep 16, 2025

@nikomatsakis
ContributorAuthor

This is a continuing project goal, and the updates below this comment will be for the new period 2025h2

modified the milestones: 2025h1, 2025h2 on Sep 16, 2025
nikomatsakis

nikomatsakis commented on Sep 16, 2025

@nikomatsakis
ContributorAuthor

This is a continuing project goal, and the updates below this comment will be for the new period 2025h2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Project goal

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @nikomatsakis@1c3t3a

      Issue actions

        Comprehensive niche checks for Rust · Issue #262 · rust-lang/rust-project-goals