Skip to content

incremental compilation flags #[rustc_on_unimplemented] as an unused attribute #59523

Closed
@pnkfelix

Description

@pnkfelix

Spawned off of #58633

The following code will compile successfully the first time you build it with -C incremental=dir, then will fail the second time (again with -C incremental=dir).

Code:

// This is a case where we should not see the lint, but we are seeing
// it if incremental compilation is enabled.

#![feature(on_unimplemented)]
#![deny(unused_attributes)]

#[rustc_on_unimplemented = "invalid"]
trait Index<Idx: ?Sized> {
    type Output: ?Sized;
    fn index(&self, index: Idx) -> &Self::Output;
}

#[rustc_on_unimplemented = "a usize is required to index into a slice"]
impl Index<usize> for [i32] {
    type Output = i32;
    fn index(&self, index: usize) -> &i32 {
        &self[index]
    }
}

fn main() {
    Index::<usize>::index(&[1, 2, 3] as &[i32], 2);
}

Demonstration:

% rustc +nightly -C incremental=dir on-impl-works.rs
% rustc +nightly -C incremental=dir on-impl-works.rs
error: unused attribute
 --> on-impl-works.rs:7:1
  |
7 | #[rustc_on_unimplemented = "invalid"]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: lint level defined here
 --> on-impl-works.rs:5:9
  |
5 | #![deny(unused_attributes)]
  |         ^^^^^^^^^^^^^^^^^

error: unused attribute
  --> on-impl-works.rs:13:1
   |
13 | #[rustc_on_unimplemented = "a usize is required to index into a slice"]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

This may seem like a low priority item since it is using #![feature(on_unimplemented)]; but we use that feature in libcore itself, so this problem is causing issues for people who want to use incremental compilation when making their locally bootstrapped build, which defaults to -D warnings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-incr-compArea: Incremental compilationA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.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