Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
438 changes: 272 additions & 166 deletions compiler/rustc_lint/src/levels.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Make sure that the copied `#[expect]` attr in the derived code does not trigger an unfulfilled
// expectation as it's linked to the original one which is fulfilled.
// Make sure that sharing the `#[expect]` attr with the derived code does not trigger an
// unfulfilled expectation there when the expectation is fulfilled at the original item.
//
// See <https://github.com/rust-lang/rust/issues/150553#issuecomment-3780810363> for rational.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// FIXME: Bring back duplication of the `#[expect]` attribute when deriving.
//
// Make sure we produce the unfulfilled expectation lint if neither the struct or the
// derived code fulfilled it.
// Make sure we produce the unfulfilled expectation lint exactly once if neither the
// struct nor the derived code fulfilled it: one written attribute is one expectation,
// no matter how many impls are derived from the item.

//@ check-pass

#[expect(unexpected_cfgs)]
//~^ WARN this lint expectation is unfulfilled
//FIXME ~^^ WARN this lint expectation is unfulfilled
#[derive(Debug)]
pub struct MyStruct {
pub t_ref: i64,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: this lint expectation is unfulfilled
--> $DIR/derive-expect-issue-150553-3.rs:8:10
--> $DIR/derive-expect-issue-150553-3.rs:7:10
|
LL | #[expect(unexpected_cfgs)]
| ^^^^^^^^^^^^^^^
Expand Down
25 changes: 25 additions & 0 deletions tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553-5.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// An `#[expect]` on an item is shared with the impls derived from it, but not with
// hand-written impls for the same type: lints there must still fire.

#![deny(redundant_lifetimes)]

#[derive(Clone)]
#[expect(redundant_lifetimes)]
pub struct W<'a>
where
'a: 'static,
{
pub r: &'a u8,
}

impl<'a> W<'a>
//~^ ERROR unnecessary lifetime parameter `'a`
where
'a: 'static,
{
pub fn get(&self) -> &'a u8 {
self.r
}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error: unnecessary lifetime parameter `'a`
--> $DIR/derive-expect-issue-150553.rs:16:23
--> $DIR/derive-expect-issue-150553-5.rs:15:6
|
LL | pub struct RefWrapper<'a, T>
| ^^
LL | impl<'a> W<'a>
| ^^
|
= note: you can use the `'static` lifetime directly, in place of `'a`
note: the lint level is defined here
--> $DIR/derive-expect-issue-150553.rs:10:9
--> $DIR/derive-expect-issue-150553-5.rs:4:9
|
LL | #![deny(redundant_lifetimes)]
| ^^^^^^^^^^^^^^^^^^^
Expand Down
44 changes: 44 additions & 0 deletions tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553-6.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// The `#[expect]` sharing with derived code must survive `#[cfg]`/`#[cfg_attr]`
// processing of the derive input: the attribute-id duplication this caused is why
// #152289 (copying the attribute to the derived impl) was reverted in #153055.
// One written attribute is one expectation, fulfilled by the item or its derived
// code, and reported exactly once when genuinely unfulfilled.

//@ check-pass

#![deny(redundant_lifetimes)]

use std::fmt::Debug;

#[derive(Debug)]
#[expect(redundant_lifetimes)]
pub struct CfgField<'a, T: Debug>
where
'a: 'static,
{
pub t_ref: &'a T,
#[cfg(false)]
pub gone: u8,
}

#[derive(Debug)]
#[cfg_attr(all(), expect(redundant_lifetimes))]
pub struct CfgAttrExpect<'a, T: Debug>
where
'a: 'static,
{
pub t_ref: &'a T,
#[cfg(false)]
pub gone: u8,
}

#[derive(Debug)]
#[expect(unexpected_cfgs)]
//~^ WARN this lint expectation is unfulfilled
pub struct Unfulfilled {
pub x: i64,
#[cfg(false)]
pub gone: u8,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
warning: this lint expectation is unfulfilled
--> $DIR/derive-expect-issue-150553-6.rs:36:10
|
LL | #[expect(unexpected_cfgs)]
| ^^^^^^^^^^^^^^^
|
= note: `#[warn(unfulfilled_lint_expectations)]` on by default

warning: 1 warning emitted

57 changes: 57 additions & 0 deletions tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553-7.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// The `#[expect]` sharing with derive-generated code also applies when the
// derive itself is expanded from a macros 2.0 macro: the derive expansion is
// the innermost one, so the expansion-kind gate recognizes the impl no matter
// what macro produced the derived item. A genuinely unfulfilled expectation
// is still reported exactly once.

//@ check-pass

#![feature(decl_macro)]
#![deny(redundant_lifetimes)]

use std::fmt::Debug;

macro fulfilled() {
#[derive(Debug)]
#[expect(redundant_lifetimes)]
pub struct RefWrapper<'a, T>
where
'a: 'static,
T: Debug,
{
pub t_ref: &'a T,
}
}

fulfilled!();

macro passthrough($i:item) {
$i
}

passthrough! {
#[derive(Debug)]
#[expect(redundant_lifetimes)]
pub struct RefWrapperPassthrough<'a, T>
where
'a: 'static,
T: Debug,
{
pub t_ref: &'a T,
}
}

macro unfulfilled() {
#[derive(Debug)]
#[expect(unexpected_cfgs)]
//~^ WARN this lint expectation is unfulfilled
pub struct Unfulfilled {
pub x: i64,
#[cfg(false)]
pub gone: u8,
}
}

unfulfilled!();

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
warning: this lint expectation is unfulfilled
--> $DIR/derive-expect-issue-150553-7.rs:46:14
|
LL | #[expect(unexpected_cfgs)]
| ^^^^^^^^^^^^^^^
...
LL | unfulfilled!();
| -------------- in this macro invocation
|
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
= note: this warning originates in the macro `unfulfilled` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: 1 warning emitted

Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// FIXME: Bring back duplication of the `#[expect]` attribute when deriving.
//
// Make sure we properly copy the `#[expect]` attr to the derived code and that no
// unfulfilled expectations are trigerred.
// Make sure the `#[expect]` attr on an item is shared with the code derived from it:
// the lint is suppressed there and fulfills the expectation.
//
// See <https://github.com/rust-lang/rust/issues/150553> for rational.

//@ check-fail
//@ check-pass

#![deny(redundant_lifetimes)]

Expand All @@ -14,7 +12,6 @@ use std::fmt::Debug;
#[derive(Debug)]
#[expect(redundant_lifetimes)]
pub struct RefWrapper<'a, T>
//~^ ERROR redundant_lifetimes
where
'a: 'static,
T: Debug,
Expand Down
Loading