Skip to content

Const eval incorrectly computes that mutable param is zero #64970

Closed
@rinon

Description

@rinon

The following code results in a const eval divide by zero error, when it cannot actually error at runtime:

pub fn foo(mut n: i32) {
  if n < 0i32 { n = 0i32 }
  if n > 0i32 {
    dbg!((1i32) / n);
  }
}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=ee4964acbb7fe290cfdaa573fddf5195

Metadata

Metadata

Assignees

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions