Skip to content

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

Closed

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.

Activity

  1. pnkfelix commented on Mar 29, 2019

    @pnkfelix
    ContributorAuthor

    Probably the easiest short-term answer is just do something analogous to 81a6437 but for on_unimplemented.

  2. added
    A-incr-comp
    on Mar 29, 2019
  3. pnkfelix commented on Mar 29, 2019

    @pnkfelix
    ContributorAuthor

    For the long term, I am vaguely worried that this may be an instance of a class of bugs with the interaction between lints and incremental compilation that we should be tracking.

    For example, see also #52387

  4. added
    A-lints
    T-compiler
    on Mar 29, 2019
  5. added 2 commits that reference this issue on Mar 29, 2019
    4ce217b
    11e1b3e
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

    A-incr-compA-lintsT-compiler

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions