Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duplicate note on platform_intrinsics feature gate #116293

Closed
matthiaskrgr opened this issue Sep 30, 2023 · 11 comments · Fixed by #116628
Closed

duplicate note on platform_intrinsics feature gate #116293

matthiaskrgr opened this issue Sep 30, 2023 · 11 comments · Fixed by #116628
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Sep 30, 2023

I tried this code:

#![feature(platform_intrinsics)]

pub fn main() {}

note the duplicate = note: using it is strongly discouraged

warning: the feature `platform_intrinsics` is internal to the compiler or standard library
 --> 688E28C68796BD785ADEA37D96B0DC202A82E2B0FF1F2A33B2A9C36992515DA4.rs:1:12
  |
1 | #![feature(platform_intrinsics)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: using it is strongly discouraged
  = note: using it is strongly discouraged
  = note: `#[warn(internal_features)]` on by default

warning: 1 warning emitted
rustc 1.74.0-nightly (8ce4540bd 2023-09-29)
binary: rustc
commit-hash: 8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72
commit-date: 2023-09-29
host: x86_64-unknown-linux-gnu
release: 1.74.0-nightly
LLVM version: 17.0.2
@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. labels Sep 30, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 30, 2023
@workingjubilee
Copy link
Member

feature, not a bug: we want people to be very strongly discouraged, so we say it twice.

@Noratrieb
Copy link
Member

the more repetions, the more discouraged. lang_items should go up to 10.

@matthiaskrgr
Copy link
Member Author

Maybe we should print it in an infinite loop, just to be on the save side? 😇

@workingjubilee
Copy link
Member

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 1, 2023
@meysam81
Copy link
Contributor

meysam81 commented Oct 2, 2023

This is happening on rustc 1.75.0-nightly (e0d7ed1f4 2023-10-01) as well.

@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 2, 2023
@gurry
Copy link
Contributor

gurry commented Oct 11, 2023

@rustbot claim

The source of the problem is the decorator for BuiltinInternalFeatures which is adding two children to the Diagnostic instead of one. I'm trying to dig further and decipher the marco-generated decorator code here:

let implementation = builder.each_variant(&mut structure, |mut builder, variant| {
let preamble = builder.preamble(variant);
let body = builder.body(variant);
let diag = &builder.parent.diag;
let formatting_init = &builder.formatting_init;
quote! {
#preamble
#formatting_init
#body
#diag
}
});

I also noticed that the behaviour seems to differ across gates. E.g. building this:

#![feature(custom_mir)]
#![feature(platform_intrinsics)]

pub fn main() {}

emits one note for custom_mir and two notes for platform_intrinsics:

warning: the feature `custom_mir` is internal to the compiler or standard library
 --> ../test.rs:1:12
  |
1 | #![feature(custom_mir)]
  |            ^^^^^^^^^^
  |
  = note: using it is strongly discouraged
  = note: `#[warn(internal_features)]` on by default

warning: the feature `platform_intrinsics` is internal to the compiler or standard library
 --> ../test.rs:2:12
  |
2 | #![feature(platform_intrinsics)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: using it is strongly discouraged
  = note: using it is strongly discouraged

warning: 2 warnings emitted

Not sure what's different about these gates.

I'm new to this area, so if you can provide any pointers based on the above, please do.

@gurry
Copy link
Contributor

gurry commented Oct 11, 2023

This program tests all the internal gates:

#![feature(allocator_internals)]
#![feature(allow_internal_unsafe)]
#![feature(allow_internal_unstable)]
#![feature(compiler_builtins)]
#![feature(custom_mir)]
#![feature(intrinsics)]
#![feature(lang_items)]
#![feature(omit_gdb_pretty_printer_section)]
#![feature(prelude_import)]
#![feature(profiler_runtime)]
#![feature(rustc_attrs)]
#![feature(staged_api)]
#![feature(test_2018_feature)]
#![feature(test_unstable_lint)]
#![feature(unsafe_pin_internals)]
#![feature(link_llvm_intrinsics)]
#![feature(needs_panic_runtime)]
#![feature(panic_runtime)]
#![feature(platform_intrinsics)]
#![feature(rustc_allow_const_fn_unstable)]
#![feature(rustdoc_internals)]

pub fn main() {}

It produces the following output:

warning: the feature `allocator_internals` is internal to the compiler or standard library
 --> ../test.rs:1:12
  |
1 | #![feature(allocator_internals)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: using it is strongly discouraged
  = note: `#[warn(internal_features)]` on by default

warning: the feature `allow_internal_unsafe` is internal to the compiler or standard library
 --> ../test.rs:2:12
  |
2 | #![feature(allow_internal_unsafe)]
  |            ^^^^^^^^^^^^^^^^^^^^^
  |
  = note: using it is strongly discouraged

warning: the feature `allow_internal_unstable` is internal to the compiler or standard library
 --> ../test.rs:3:12
  |
3 | #![feature(allow_internal_unstable)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: using it is strongly discouraged

warning: the feature `compiler_builtins` is internal to the compiler or standard library
 --> ../test.rs:4:12
  |
4 | #![feature(compiler_builtins)]
  |            ^^^^^^^^^^^^^^^^^
  |
  = note: using it is strongly discouraged

warning: the feature `custom_mir` is internal to the compiler or standard library
 --> ../test.rs:5:12
  |
5 | #![feature(custom_mir)]
  |            ^^^^^^^^^^
  |
  = note: using it is strongly discouraged

warning: the feature `intrinsics` is internal to the compiler or standard library
 --> ../test.rs:6:12
  |
6 | #![feature(intrinsics)]
  |            ^^^^^^^^^^
  |
  = note: using it is strongly discouraged

warning: the feature `lang_items` is internal to the compiler or standard library
 --> ../test.rs:7:12
  |
7 | #![feature(lang_items)]
  |            ^^^^^^^^^^
  |
  = note: using it is strongly discouraged

warning: the feature `omit_gdb_pretty_printer_section` is internal to the compiler or standard library
 --> ../test.rs:8:12
  |
8 | #![feature(omit_gdb_pretty_printer_section)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: using it is strongly discouraged

warning: the feature `prelude_import` is internal to the compiler or standard library
 --> ../test.rs:9:12
  |
9 | #![feature(prelude_import)]
  |            ^^^^^^^^^^^^^^
  |
  = note: using it is strongly discouraged

warning: the feature `profiler_runtime` is internal to the compiler or standard library
  --> ../test.rs:10:12
   |
10 | #![feature(profiler_runtime)]
   |            ^^^^^^^^^^^^^^^^
   |
   = note: using it is strongly discouraged

warning: the feature `rustc_attrs` is internal to the compiler or standard library
  --> ../test.rs:11:12
   |
11 | #![feature(rustc_attrs)]
   |            ^^^^^^^^^^^
   |
   = note: using it is strongly discouraged

warning: the feature `staged_api` is internal to the compiler or standard library
  --> ../test.rs:12:12
   |
12 | #![feature(staged_api)]
   |            ^^^^^^^^^^
   |
   = note: using it is strongly discouraged

warning: the feature `test_2018_feature` is internal to the compiler or standard library
  --> ../test.rs:13:12
   |
13 | #![feature(test_2018_feature)]
   |            ^^^^^^^^^^^^^^^^^
   |
   = note: using it is strongly discouraged

warning: the feature `test_unstable_lint` is internal to the compiler or standard library
  --> ../test.rs:14:12
   |
14 | #![feature(test_unstable_lint)]
   |            ^^^^^^^^^^^^^^^^^^
   |
   = note: using it is strongly discouraged

warning: the feature `unsafe_pin_internals` is internal to the compiler or standard library
  --> ../test.rs:15:12
   |
15 | #![feature(unsafe_pin_internals)]
   |            ^^^^^^^^^^^^^^^^^^^^
   |
   = note: using it is strongly discouraged

warning: the feature `link_llvm_intrinsics` is internal to the compiler or standard library
  --> ../test.rs:16:12
   |
16 | #![feature(link_llvm_intrinsics)]
   |            ^^^^^^^^^^^^^^^^^^^^
   |
   = note: using it is strongly discouraged
   = note: using it is strongly discouraged

warning: the feature `needs_panic_runtime` is internal to the compiler or standard library
  --> ../test.rs:17:12
   |
17 | #![feature(needs_panic_runtime)]
   |            ^^^^^^^^^^^^^^^^^^^
   |
   = note: using it is strongly discouraged
   = note: using it is strongly discouraged

warning: the feature `panic_runtime` is internal to the compiler or standard library
  --> ../test.rs:18:12
   |
18 | #![feature(panic_runtime)]
   |            ^^^^^^^^^^^^^
   |
   = note: using it is strongly discouraged
   = note: using it is strongly discouraged

warning: the feature `platform_intrinsics` is internal to the compiler or standard library
  --> ../test.rs:19:12
   |
19 | #![feature(platform_intrinsics)]
   |            ^^^^^^^^^^^^^^^^^^^
   |
   = note: using it is strongly discouraged
   = note: using it is strongly discouraged

warning: the feature `rustc_allow_const_fn_unstable` is internal to the compiler or standard library
  --> ../test.rs:20:12
   |
20 | #![feature(rustc_allow_const_fn_unstable)]
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: using it is strongly discouraged
   = note: using it is strongly discouraged

warning: the feature `rustdoc_internals` is internal to the compiler or standard library
  --> ../test.rs:21:12
   |
21 | #![feature(rustdoc_internals)]
   |            ^^^^^^^^^^^^^^^^^
   |
   = note: using it is strongly discouraged
   = note: using it is strongly discouraged

error: module has missing stability attribute
  --> ../test.rs:1:1
   |
1  | / #![feature(allocator_internals)]
2  | | #![feature(allow_internal_unsafe)]
3  | | #![feature(allow_internal_unstable)]
4  | | #![feature(compiler_builtins)]
...  |
22 | |
23 | | pub fn main() {}
   | |________________^

error: function has missing stability attribute
  --> ../test.rs:23:1
   |
23 | pub fn main() {}
   | ^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors; 21 warnings emitted

Of the 21 internal gates, only the last 6 result in duplicate notes.

@matthiaskrgr
Copy link
Member Author

These should be more, there's a file somewhere that defines all the features but I can't check it right now on mobile

@Noratrieb
Copy link
Member

I think that should be all of them. This is super weird indeed, no idea

@gurry
Copy link
Contributor

gurry commented Oct 11, 2023

Thanks @matthiaskrgr & @Nilstrieb.

I found what's different about gates with duplicate notes: they all have an associated issue.

Here's the full list grepped from compiler/rustc_feature/src/active.rs:

(internal, allocator_internals, "1.20.0", None, None),
(internal, allow_internal_unsafe, "1.0.0", None, None),
(internal, allow_internal_unstable, "1.0.0", None, None),
(internal, compiler_builtins, "1.13.0", None, None),
(internal, custom_mir, "1.65.0", None, None),
(internal, intrinsics, "1.0.0", None, None),
(internal, lang_items, "1.0.0", None, None),
(internal, omit_gdb_pretty_printer_section, "1.5.0", None, None),
(internal, prelude_import, "1.2.0", None, None),
(internal, profiler_runtime, "1.18.0", None, None),
(internal, rustc_attrs, "1.0.0", None, None),
(internal, staged_api, "1.0.0", None, None),
(internal, test_2018_feature, "1.31.0", None, Some(Edition::Edition2018)),
(internal, test_unstable_lint, "1.60.0", None, None),
(internal, unsafe_pin_internals, "1.60.0", None, None),
(internal, link_llvm_intrinsics, "1.0.0", Some(29602), None),
(internal, needs_panic_runtime, "1.10.0", Some(32837), None),
(internal, panic_runtime, "1.10.0", Some(32837), None),
(internal, platform_intrinsics, "1.4.0", Some(27731), None),
(internal, rustc_allow_const_fn_unstable, "1.49.0", Some(69399), None),
(internal, rustdoc_internals, "1.58.0", Some(90418), None),

Notice that the second last field in the last 6 lines is Some unlike the rest where it is None. Apparently having an associated issue causes this problem.

@gurry
Copy link
Contributor

gurry commented Oct 11, 2023

The root cause is the note being passed on this line:

BuiltinInternalFeatures { name, note },

Its value is Some(...) for gates that have an associated issue and None for others. Since BuiltinInternalFeatures already has a #[note] attribute:


this results in duplicates.

The solution is to always pass None for internal gates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants