Skip to content

Some errors only show up with cargo build not cargo check #70923

Closed
@oli-obk

Description

@oli-obk
Contributor

This is partially due to the fact that our analysis query

fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
does not invoke the optimized_mir query on all items in the current crate, and also because we don't run monomorphization when building bin crates.

  • run optimized_mir query in analysis
    • this may cause slowdowns for cargo check because we'd be doing optimizations now
    • All const propagation lints are emitted in optimized_mir, but we may add more in the future.
  • run monomorphization where possible.
    • Not sure how useful this is, it will only give us additional lints in very specific situations. (e.g. when we subtract something form an associated constant, we may get an overflow error depending on the value of the constant).
    • This will also be significantly more expensive than just running optimized_mir

cc @Centril

Activity

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Apr 8, 2020
RalfJung

RalfJung commented on Apr 8, 2020

@RalfJung
Member

Or maybe it is a bad idea to emit lints during optimization, and we should move the lints from const-prop to elsewhere?

added
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
and removed
C-bugCategory: This is a bug.
on Apr 8, 2020
ehuss

ehuss commented on Apr 8, 2020

@ehuss
Contributor

This gets reported occasionally, like #49292 and #61330.

oli-obk

oli-obk commented on Apr 8, 2020

@oli-obk
ContributorAuthor

the reason the lints are part of const prop is to ensure we don't do the work twice, once for linting and once for the const prop optimization. I'm not sure how we could do that differently.

Also I was envisioning adding more lints to the optimization pipeline instead of the other way around.

RalfJung

RalfJung commented on Apr 30, 2020

@RalfJung
Member

Do we have a concrete example / test case demonstrating this?

mati865

mati865 commented on Apr 30, 2020

@mati865
RalfJung

RalfJung commented on Apr 30, 2020

@RalfJung
Member

@ehuss has an example of this: it passes with cargo check, but fails cargo build, latest nightly rustc 1.45.0-nightly (fa51f810e 2020-04-29).

fn main() {
    let a: u8 = 42;
    let b = ((a | 0x0F) - 1) >> 31 > 0;
    println!("{}", b);
}

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

8 remaining items

Loading
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

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.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

        Participants

        @ehuss@RalfJung@oli-obk@mati865@jonas-schievink

        Issue actions

          Some errors only show up with `cargo build` not `cargo check` · Issue #70923 · rust-lang/rust