Skip to content

Commit fced230

Browse files
Rollup merge of #152289 - Urgau:expect-in-derive-150553, r=jdonszelmann
Also duplicate `#[expect]` attribute in `#[derive]`-ed code This PR updates our derive logic to also duplicate any `#[expect]` attribute in the `#[derive]`-ed code, as we already do for all the other lint attribute (`#[allow]`, `#[warn]`, `#[deny]`, ...). The original and duplicated attribute share the same attribute id, which due to the way [`check_expectations`](https://github.com/rust-lang/rust/blob/56aaf58ec02b6ac974e8364269fbb33a8a806e28/compiler/rustc_lint/src/expect.rs#L28-L46) is implemented makes the expectation fulfilled if the lint is either trigger in the original code or the derived code. This was discussed by T-lang in #150553 (comment). cc @rust-lang/lang-ops (in case you want to do an FCP) Fixes #150553
2 parents 6e7f929 + 2407f47 commit fced230

5 files changed

Lines changed: 69 additions & 0 deletions

File tree

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ impl<'a> TraitDef<'a> {
540540
.filter(|a| {
541541
a.has_any_name(&[
542542
sym::allow,
543+
sym::expect,
543544
sym::warn,
544545
sym::deny,
545546
sym::forbid,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Make sure that the copied `#[expect]` attr in the derived code does not trigger an unfulfilled
2+
// expectation as it's linked to the original one which is fulfilled.
3+
//
4+
// See <https://github.com/rust-lang/rust/issues/150553#issuecomment-3780810363> for rational.
5+
6+
//@ check-pass
7+
8+
#[expect(non_camel_case_types)]
9+
#[derive(Debug)]
10+
pub struct SCREAMING_CASE {
11+
pub t_ref: i64,
12+
}
13+
14+
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Make sure we produce the unfulfilled expectation lint if neither the struct or the
2+
// derived code fulfilled it.
3+
4+
//@ check-pass
5+
6+
#[expect(unexpected_cfgs)]
7+
//~^ WARN this lint expectation is unfulfilled
8+
//~^^ WARN this lint expectation is unfulfilled
9+
#[derive(Debug)]
10+
pub struct MyStruct {
11+
pub t_ref: i64,
12+
}
13+
14+
fn main() {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
warning: this lint expectation is unfulfilled
2+
--> $DIR/derive-expect-issue-150553-3.rs:6:10
3+
|
4+
LL | #[expect(unexpected_cfgs)]
5+
| ^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
8+
9+
warning: this lint expectation is unfulfilled
10+
--> $DIR/derive-expect-issue-150553-3.rs:6:10
11+
|
12+
LL | #[expect(unexpected_cfgs)]
13+
| ^^^^^^^^^^^^^^^
14+
|
15+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
16+
17+
warning: 2 warnings emitted
18+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Make sure we properly copy the `#[expect]` attr to the derived code and that no
2+
// unfulfilled expectations are trigerred.
3+
//
4+
// See <https://github.com/rust-lang/rust/issues/150553> for rational.
5+
6+
//@ check-pass
7+
8+
#![deny(redundant_lifetimes)]
9+
10+
use std::fmt::Debug;
11+
12+
#[derive(Debug)]
13+
#[expect(redundant_lifetimes)]
14+
pub struct RefWrapper<'a, T>
15+
where
16+
'a: 'static,
17+
T: Debug,
18+
{
19+
pub t_ref: &'a T,
20+
}
21+
22+
fn main() {}

0 commit comments

Comments
 (0)