Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mu001999
Copy link
Contributor

@mu001999 mu001999 commented Sep 24, 2025

Fixes #146968

Emit error CfgPredicateIdentifier if the word is path-segment keyword.

Detailed change description - #146978 (comment).

r? petrochenkov

@rustbot
Copy link
Collaborator

rustbot commented Sep 24, 2025

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 24, 2025
@petrochenkov
Copy link
Contributor

Could you

  • add similar test cases for some non path-segment keyword, like struct
  • add test cases for --cfg on command line and make sure that they behave identically to cfg! and #[cfg].

After that we should be able to run crater on this.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 26, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 26, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@mu001999 mu001999 force-pushed the fix/path-kw-as-cfg-pred branch from 505d13f to b2be57d Compare September 27, 2025 03:24
@rustbot

This comment has been minimized.

@mu001999
Copy link
Contributor Author

add test cases for --cfg on command line and make sure that they behave identically to cfg! and #[cfg]

--cfg will emit same error but will be suppressed because parse_cfg is called with ParseSess::with_fatal_emitter

@mu001999
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 27, 2025
@petrochenkov
Copy link
Contributor

add test cases for --cfg on command line and make sure that they behave identically to cfg! and #[cfg]

--cfg will emit same error but will be suppressed because parse_cfg is called with ParseSess::with_fatal_emitter

with_fatal_emitter doesn't suppress errors, it makes them fatal.
--cfg parsing has its own error reporting logic in fn parse_cfg in compiler\rustc_interface\src\interface.rs, and the new errors are not emitted there.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 30, 2025
@mu001999
Copy link
Contributor Author

with_fatal_emitter doesn't suppress errors, it makes them fatal.

@petrochenkov I found with_fatal_emitter create dcx with FatalOnlyEmitter, see

pub fn with_fatal_emitter(locale_resources: Vec<&'static str>, fatal_note: String) -> Self {
let translator = Translator::with_fallback_bundle(locale_resources, false);
let sm = Arc::new(SourceMap::new(FilePathMapping::empty()));
let fatal_emitter =
Box::new(HumanEmitter::new(stderr_destination(ColorConfig::Auto), translator));
let dcx = DiagCtxt::new(Box::new(FatalOnlyEmitter {
fatal_emitter,
fatal_note: Some(fatal_note),
}))
.disable_warnings();
ParseSess::with_dcx(dcx, sm)
}

and the comment of FatalOnlyEmitter and the impl of FatalOnlyEmitter::emit_diagnostic show only errors with diag.level == Level::Fatal can be emitted, see

/// An emitter that does nothing when emitting a non-fatal diagnostic.
/// Fatal diagnostics are forwarded to `fatal_emitter` to avoid silent
/// failures of rustc, as witnessed e.g. in issue #89358.
pub struct FatalOnlyEmitter {
pub fatal_emitter: Box<dyn Emitter + DynSend>,
pub fatal_note: Option<String>,
}
impl Emitter for FatalOnlyEmitter {
fn source_map(&self) -> Option<&SourceMap> {
None
}
fn emit_diagnostic(&mut self, mut diag: DiagInner, registry: &Registry) {
if diag.level == Level::Fatal {
if let Some(fatal_note) = &self.fatal_note {
diag.sub(Level::Note, fatal_note.clone(), MultiSpan::new());
}
self.fatal_emitter.emit_diagnostic(diag, registry);
}
}
fn translator(&self) -> &Translator {
self.fatal_emitter.translator()
}
}

@mu001999
Copy link
Contributor Author

mu001999 commented Sep 30, 2025

I have debug the logic in fn parse_cfg, and the err.emit is called in fact, but it is suppressed by the FatalOnlyEmitter.

@petrochenkov
Copy link
Contributor

petrochenkov commented Sep 30, 2025

Ah, ok, "fatal emitter" means "fatal-only emitter".

In any case, the behavior is not correct.
I guess the assumption when using the fatal emitter was that we always reach the "expected key or key="value"" error at the bottom anyway, but that's not actually the case.
If we get to return (ident.name, meta_item.value_str()), then all the non-fatal errors are lost, which is incorrect.

@mu001999 mu001999 marked this pull request as draft October 9, 2025 06:02
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the fix/path-kw-as-cfg-pred branch from 956aa91 to 97cd2c7 Compare October 9, 2025 11:16
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the fix/path-kw-as-cfg-pred branch from 97cd2c7 to a7d6090 Compare October 9, 2025 11:54
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the fix/path-kw-as-cfg-pred branch from a7d6090 to c8bc460 Compare October 9, 2025 15:31
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the fix/path-kw-as-cfg-pred branch from cc53ca4 to 9c2ed4c Compare October 9, 2025 18:10
bors added a commit that referenced this pull request Nov 13, 2025
…etrochenkov

Emit error when using path-segment keyword as cfg pred

Fixes #146968

Emit error `CfgPredicateIdentifier` if the word is path-segment keyword.

Detailed change description - #146978 (comment).

r? petrochenkov
@bors
Copy link
Collaborator

bors commented Nov 13, 2025

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 13, 2025
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-mingw-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[882/3793] Building CXX object lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/GCOVProfiling.cpp.obj
[883/3793] Building CXX object lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/MemProfInstrumentation.cpp.obj
[884/3793] Building CXX object lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/MemorySanitizer.cpp.obj
[885/3793] Building CXX object lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/InstrProfiling.cpp.obj
FAILED: lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/InstrProfiling.cpp.obj 
sccache D:\a\rust\rust\mingw64\bin\g++.exe -DEXPERIMENTAL_KEY_INSTRUCTIONS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_FILE_OFFSET_BITS=64 -D_GLIBCXX_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -ID:/a/rust/rust/build/x86_64-pc-windows-gnu/llvm/build/lib/Transforms/Instrumentation -ID:/a/rust/rust/src/llvm-project/llvm/lib/Transforms/Instrumentation -ID:/a/rust/rust/build/x86_64-pc-windows-gnu/llvm/build/include -ID:/a/rust/rust/src/llvm-project/llvm/include -ffunction-sections -fdata-sections -m64 -Wa,-mbig-obj -Werror=date-time -w -ffunction-sections -fdata-sections  -O2 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/InstrProfiling.cpp.obj -MF lib\Transforms\Instrumentation\CMakeFiles\LLVMInstrumentation.dir\InstrProfiling.cpp.obj.d -o lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/InstrProfiling.cpp.obj -c D:/a/rust/rust/src/llvm-project/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
sccache: error: An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full. (os error 10055)
[886/3793] Building CXX object lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/MemProfUse.cpp.obj
[887/3793] Building CXX object lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/NumericalStabilitySanitizer.cpp.obj
[888/3793] Building CXX object lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/IndirectCallPromotion.cpp.obj
ninja: build stopped: subcommand failed.

---
             at .\src\bootstrap\src\core\build_steps\compile.rs:2043:69
   8: bootstrap::core::builder::Builder::ensure
             at .\src\bootstrap\src\core\builder\mod.rs:1605:36
   9: bootstrap::core::builder::Builder::compiler
             at .\src\bootstrap\src\core\builder\mod.rs:1175:14
  10: <bootstrap::core::build_steps::test::Ui as bootstrap::core::builder::Step>::make_run
             at .\src\bootstrap\src\core\build_steps\test.rs:1443:49
  11: bootstrap::core::builder::StepDescription::maybe_run
             at .\src\bootstrap\src\core\builder\mod.rs:465:13
  12: bootstrap::core::builder::cli_paths::match_paths_to_steps_and_run
             at .\src\bootstrap\src\core\builder\cli_paths.rs:140:22
  13: bootstrap::core::builder::Builder::run_step_descriptions
             at .\src\bootstrap\src\core\builder\mod.rs:1148:9
  14: bootstrap::core::builder::Builder::execute_cli
---
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
 finished in 206.315 seconds
##[endgroup]
Build completed unsuccessfully in 0:03:48
make: *** [Makefile:123: ci-mingw-x] Error 1
  local time: Thu Nov 13 13:46:09 CUT 2025
  network time: Thu, 13 Nov 2025 13:46:09 GMT
##[error]Process completed with exit code 2.
##[group]Run echo "disk usage:"
echo "disk usage:"

@mu001999

This comment was marked as outdated.

@petrochenkov
Copy link
Contributor

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 13, 2025
@ehuss
Copy link
Contributor

ehuss commented Nov 13, 2025

Filed #148910

Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 13, 2025
…g-pred, r=petrochenkov

Emit error when using path-segment keyword as cfg pred

Fixes rust-lang#146968

Emit error `CfgPredicateIdentifier` if the word is path-segment keyword.

Detailed change description - rust-lang#146978 (comment).

r? petrochenkov
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 13, 2025
…g-pred, r=petrochenkov

Emit error when using path-segment keyword as cfg pred

Fixes rust-lang#146968

Emit error `CfgPredicateIdentifier` if the word is path-segment keyword.

Detailed change description - rust-lang#146978 (comment).

r? petrochenkov
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 13, 2025
…g-pred, r=petrochenkov

Emit error when using path-segment keyword as cfg pred

Fixes rust-lang#146968

Emit error `CfgPredicateIdentifier` if the word is path-segment keyword.

Detailed change description - rust-lang#146978 (comment).

r? petrochenkov
bors added a commit that referenced this pull request Nov 14, 2025
Rollup of 14 pull requests

Successful merges:

 - #146978 (Emit error when using path-segment keyword as cfg pred)
 - #148543 (Correctly link to associated trait items in reexports)
 - #148808 (Some resolve cleanups)
 - #148812 (coverage: Associate hole spans with expansion tree nodes )
 - #148826 (CStr docs: Fix CStr vs &CStr confusion)
 - #148850 (Implement `Read::read_array`)
 - #148867 (Refactor `Box::take`)
 - #148870 (Remove unused LLVMModuleRef argument)
 - #148878 (error when ABI does not support guaranteed tail calls)
 - #148901 (Disable rustdoc-test-builder test partially for SGX target.)
 - #148902 (add missing s390x target feature to std detect test)
 - #148904 (waffle: stop watching codegen ssa)
 - #148906 (Expose fmt::Arguments::from_str as unstable.)
 - #148907 (add assembly test for infinite recursion with `become`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Nov 14, 2025
…etrochenkov

Emit error when using path-segment keyword as cfg pred

Fixes #146968

Emit error `CfgPredicateIdentifier` if the word is path-segment keyword.

Detailed change description - #146978 (comment).

r? petrochenkov
@bors
Copy link
Collaborator

bors commented Nov 14, 2025

⌛ Testing commit 5d70446 with merge 3d503f1...

@Zalathar
Copy link
Member

Possibly failed in rollup: #148927 (comment)

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 14, 2025
@Zalathar
Copy link
Member

@bors try jobs=x86_64-gnu-aux

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Nov 14, 2025
…try>

Emit error when using path-segment keyword as cfg pred

try-job: x86_64-gnu-aux
@Zalathar
Copy link
Member

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 14, 2025
@mu001999
Copy link
Contributor Author

mu001999 commented Nov 14, 2025

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-aux failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@rust-bors
Copy link

rust-bors bot commented Nov 14, 2025

💔 Test for 097ec3c failed: CI. Failed jobs:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. F-explicit_tail_calls `#![feature(explicit_tail_calls)]` finished-final-comment-period The final comment period is finished for this PR / Issue. relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team to-announce Announce this issue on triage meeting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cfg!($crate), cfg!(crate), cfg!(self), cfg!(Self), and cfg!(super) should not be accepted