Skip to content

Commit

Permalink
Unrolled build for rust-lang#131771
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#131771 - Urgau:cfg-target-131759, r=jieyouxu

Handle gracefully true/false in `cfg(target(..))` compact

This PR handles gracefully `true`/`false` in `cfg(target(..))` compact instead of ICE.

r? `@nnethercote`
Fixes rust-lang#131759
  • Loading branch information
rust-timer authored Oct 16, 2024
2 parents d829780 + 5eb8636 commit fbbc0df
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
8 changes: 7 additions & 1 deletion compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,13 @@ pub fn eval_condition(
}

mis.iter().fold(true, |res, mi| {
let mut mi = mi.meta_item().unwrap().clone();
let Some(mut mi) = mi.meta_item().cloned() else {
dcx.emit_err(session_diagnostics::CfgPredicateIdentifier {
span: mi.span(),
});
return false;
};

if let [seg, ..] = &mut mi.path.segments[..] {
seg.ident.name = Symbol::intern(&format!("target_{}", seg.ident.name));
}
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/cfg/cfg-target-compact-errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ fn two() {}
//~^ ERROR invalid predicate `target_pointer`
fn three() {}

#[cfg(target(true))]
//~^ ERROR `cfg` predicate key must be an identifier
fn four() {}

fn main() {}
8 changes: 7 additions & 1 deletion tests/ui/cfg/cfg-target-compact-errors.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ error[E0537]: invalid predicate `target_pointer`
LL | #[cfg(target(os = "linux", pointer(width = "64")))]
| ^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 3 previous errors
error: `cfg` predicate key must be an identifier
--> $DIR/cfg-target-compact-errors.rs:17:14
|
LL | #[cfg(target(true))]
| ^^^^

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0537, E0565.
For more information about an error, try `rustc --explain E0537`.

0 comments on commit fbbc0df

Please sign in to comment.