Skip to content

Rollup of 17 pull requests #141644

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

Merged
merged 35 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3cd065d
macro expansion issue
Kivooeo May 2, 2025
7238669
intrinsics: reduce references to LLVM and update notes on where the i…
RalfJung May 24, 2025
ff33414
ScalarInt: support conversion with signed int types and cmp::Ordering
RalfJung May 24, 2025
77e295c
Improve `ambiguous_wide_pointer_comparisons` lint compare diagnostics
Urgau May 25, 2025
b71a127
dist: make sure llvm-project submodule is present
onur-ozkan May 26, 2025
0ea12c3
cfg_version: pull out dedicated syntax test from feature gate test
jieyouxu May 25, 2025
5e31cd3
Support opaque_types_defined_by for SyntheticCoroutineBody
compiler-errors May 26, 2025
1d35ac9
Add missing edition directives for async-await tests
Veykril May 26, 2025
c27aff3
Add test
BoxyUwU May 26, 2025
0497f31
rustc book: fix erratic sentence by making it more simple
tshepang May 26, 2025
19802e8
Remove an unnecessary use of `Box::into_inner`.
nnethercote May 26, 2025
108c16e
bootstrap: translate Windows paths in a way that works for both Cygwi…
jeremyd2019 May 26, 2025
6a8663a
Update mdbook to 0.4.51
ehuss May 26, 2025
c8ed2a7
Remove spastorino from vacations
spastorino May 26, 2025
7fe8263
use custom types to clarify arguments to `emit_ptr_va_arg`
folkertdev May 26, 2025
e0d4cf3
further dedup `WalkItemKind` for `mut_visit` and `visit`
fee1-dead May 27, 2025
3fff727
Use more detailed spans in dyn compat errors within bodies
oli-obk May 26, 2025
89c21f7
Remove out-of-date `noop_*` names.
nnethercote May 19, 2025
77e3594
Rollup merge of #140591 - Kivooeo:new-fix-five, r=davidtwco
compiler-errors May 27, 2025
a0d77f3
Rollup merge of #141536 - Urgau:ambi_wide_ptr-cmp-diag, r=fee1-dead
compiler-errors May 27, 2025
b7854c6
Rollup merge of #141552 - jieyouxu:cfg-version-tests, r=est31
compiler-errors May 27, 2025
f1371a8
Rollup merge of #141556 - jeremyd2019:patch-1, r=jieyouxu
compiler-errors May 27, 2025
7acdffb
Rollup merge of #141563 - nnethercote:rm-noop, r=petrochenkov
compiler-errors May 27, 2025
2c5361a
Rollup merge of #141568 - onur-ozkan:141393-fix, r=Kobzol
compiler-errors May 27, 2025
fbac805
Rollup merge of #141580 - oli-obk:early-dyn-catches-the-incompat, r=c…
compiler-errors May 27, 2025
fb4cc99
Rollup merge of #141582 - RalfJung:cleanup, r=bjorn3
compiler-errors May 27, 2025
9d46af1
Rollup merge of #141584 - compiler-errors:typing-env-synthetic-body, …
compiler-errors May 27, 2025
38d1862
Rollup merge of #141587 - ferrocene:lw-yurotqzwvwlw, r=jieyouxu
compiler-errors May 27, 2025
6344245
Rollup merge of #141594 - BoxyUwU:another_gai_test, r=jieyouxu
compiler-errors May 27, 2025
4b47bd4
Rollup merge of #141596 - tshepang:patch-2, r=Urgau
compiler-errors May 27, 2025
2de2e65
Rollup merge of #141599 - nnethercote:rm-Box-into_inner, r=fmease,che…
compiler-errors May 27, 2025
761dbc7
Rollup merge of #141611 - ehuss:update-mdbook, r=Mark-Simulacrum
compiler-errors May 27, 2025
1aa6a27
Rollup merge of #141616 - spastorino:remove-spastorino-on-vacations, …
compiler-errors May 27, 2025
f0ee1d7
Rollup merge of #141623 - folkertdev:va-arg-explicit-types, r=working…
compiler-errors May 27, 2025
d7e961a
Rollup merge of #141635 - fee1-dead-contrib:push-lmyymwotrspk, r=oli-obk
compiler-errors May 27, 2025
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
Prev Previous commit
Next Next commit
cfg_version: pull out dedicated syntax test from feature gate test
The feature gate test was dual-purposing causing feature gate errors to
distract from syntax exercises.
  • Loading branch information
jieyouxu committed May 26, 2025
commit 0ea12c3c5fd218671ae42a99757a332fba8597cc
152 changes: 152 additions & 0 deletions tests/ui/cfg/cfg-version/syntax.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
//! Check `#[cfg(version(..))]` parsing.

#![feature(cfg_version)]

// Overall grammar
// ===============
//
// `#[cfg(version(..))]` accepts only the `version(VERSION_STRING_LITERAL)` predicate form, where
// only a single string literal is permitted.

#[cfg(version(42))]
//~^ ERROR expected a version literal
fn not_a_string_literal_simple() {}

#[cfg(version(1.20))]
//~^ ERROR expected a version literal
fn not_a_string_literal_semver_like() {}

#[cfg(version(false))]
//~^ ERROR expected a version literal
fn not_a_string_literal_other() {}

#[cfg(version("1.43", "1.44", "1.45"))]
//~^ ERROR expected single version literal
fn multiple_version_literals() {}

// The key-value form `cfg(version = "..")` is not considered a valid `cfg(version(..))` usage, but
// it will only trigger the `unexpected_cfgs` lint and not a hard error.

#[cfg(version = "1.43")]
//~^ WARN unexpected `cfg` condition name: `version`
fn key_value_form() {}

// Additional version string literal constraints
// =============================================
//
// The `VERSION_STRING_LITERAL` ("version literal") has additional constraints on its syntactical
// well-formedness.

// 1. A valid version literal can only constitute of numbers and periods (a "simple" semver version
// string). Non-semver strings or "complex" semver strings (such as build metadata) are not
// considered valid version literals, and will emit a non-lint warning "unknown version literal
// format".

#[cfg(version("1.43.0"))]
fn valid_major_minor_patch() {}

#[cfg(version("0.0.0"))]
fn valid_zero_zero_zero_major_minor_patch() {}

#[cfg(version("foo"))]
//~^ WARN unknown version literal format, assuming it refers to a future version
fn not_numbers_or_periods() {}

#[cfg(version("1.20.0-stable"))]
//~^ WARN unknown version literal format, assuming it refers to a future version
fn complex_semver_with_metadata() {}

// 2. "Shortened" version strings are permitted but *only* for the omission of the patch number.

#[cfg(version("1.0"))]
fn valid_major_minor_1() {}

#[cfg(version("1.43"))]
fn valid_major_minor_2() {}

#[cfg(not(version("1.44")))]
fn valid_major_minor_negated_smoke_test() {}

#[cfg(version("0.0"))]
fn valid_zero_zero_major_minor() {}

#[cfg(version("0.7"))]
fn valid_zero_major_minor() {}

// 3. Major-only, or other non-Semver-like strings are not permitted.

#[cfg(version("1"))]
//~^ WARN unknown version literal format, assuming it refers to a future version
fn invalid_major_only() {}

#[cfg(version("0"))]
//~^ WARN unknown version literal format, assuming it refers to a future version
fn invalid_major_only_zero() {}

#[cfg(version(".7"))]
//~^ WARN unknown version literal format, assuming it refers to a future version
fn invalid_decimal_like() {}

// Misc parsing overflow/underflow edge cases
// ==========================================
//
// Check that we report "unknown version literal format" user-facing warnings and not ICEs.

#[cfg(version("-1"))]
//~^ WARN unknown version literal format, assuming it refers to a future version
fn invalid_major_only_negative() {}

// Implementation detail: we store rustc version as `{ major: u16, minor: u16, patch: u16 }`.

#[cfg(version("65536"))]
//~^ WARN unknown version literal format, assuming it refers to a future version
fn exceed_u16_major() {}

#[cfg(version("1.65536.0"))]
//~^ WARN unknown version literal format, assuming it refers to a future version
fn exceed_u16_minor() {}

#[cfg(version("1.0.65536"))]
//~^ WARN unknown version literal format, assuming it refers to a future version
fn exceed_u16_patch() {}

#[cfg(version("65536.0.65536"))]
//~^ WARN unknown version literal format, assuming it refers to a future version
fn exceed_u16_mixed() {}

// Usage as `cfg!()`
// =================

fn cfg_usage() {
assert!(cfg!(version("1.0")));
assert!(cfg!(version("1.43")));
assert!(cfg!(version("1.43.0")));

assert!(cfg!(version("foo")));
//~^ WARN unknown version literal format, assuming it refers to a future version
assert!(cfg!(version("1.20.0-stable")));
//~^ WARN unknown version literal format, assuming it refers to a future version

assert!(cfg!(version = "1.43"));
//~^ WARN unexpected `cfg` condition name: `version`
}

fn main() {
cfg_usage();

// `cfg(version = "..")` is not a valid `cfg_version` form, but it only triggers
// `unexpected_cfgs` lint, and `cfg(version = "..")` eval to `false`.
key_value_form(); //~ ERROR cannot find function

// Invalid version literal formats within valid `cfg(version(..))` form should also cause
// `cfg(version(..))` eval to `false`.
not_numbers_or_periods(); //~ ERROR cannot find function
complex_semver_with_metadata(); //~ ERROR cannot find function
invalid_major_only(); //~ ERROR cannot find function
invalid_major_only_zero(); //~ ERROR cannot find function
invalid_major_only_negative(); //~ ERROR cannot find function
exceed_u16_major(); //~ ERROR cannot find function
exceed_u16_minor(); //~ ERROR cannot find function
exceed_u16_patch(); //~ ERROR cannot find function
exceed_u16_mixed(); //~ ERROR cannot find function
}
188 changes: 188 additions & 0 deletions tests/ui/cfg/cfg-version/syntax.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
error: expected a version literal
--> $DIR/syntax.rs:11:15
|
LL | #[cfg(version(42))]
| ^^

error: expected a version literal
--> $DIR/syntax.rs:15:15
|
LL | #[cfg(version(1.20))]
| ^^^^

error: expected a version literal
--> $DIR/syntax.rs:19:15
|
LL | #[cfg(version(false))]
| ^^^^^

error: expected single version literal
--> $DIR/syntax.rs:23:7
|
LL | #[cfg(version("1.43", "1.44", "1.45"))]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: unknown version literal format, assuming it refers to a future version
--> $DIR/syntax.rs:51:15
|
LL | #[cfg(version("foo"))]
| ^^^^^

warning: unknown version literal format, assuming it refers to a future version
--> $DIR/syntax.rs:55:15
|
LL | #[cfg(version("1.20.0-stable"))]
| ^^^^^^^^^^^^^^^

warning: unknown version literal format, assuming it refers to a future version
--> $DIR/syntax.rs:78:15
|
LL | #[cfg(version("1"))]
| ^^^

warning: unknown version literal format, assuming it refers to a future version
--> $DIR/syntax.rs:82:15
|
LL | #[cfg(version("0"))]
| ^^^

warning: unknown version literal format, assuming it refers to a future version
--> $DIR/syntax.rs:86:15
|
LL | #[cfg(version(".7"))]
| ^^^^

warning: unknown version literal format, assuming it refers to a future version
--> $DIR/syntax.rs:95:15
|
LL | #[cfg(version("-1"))]
| ^^^^

warning: unknown version literal format, assuming it refers to a future version
--> $DIR/syntax.rs:101:15
|
LL | #[cfg(version("65536"))]
| ^^^^^^^

warning: unknown version literal format, assuming it refers to a future version
--> $DIR/syntax.rs:105:15
|
LL | #[cfg(version("1.65536.0"))]
| ^^^^^^^^^^^

warning: unknown version literal format, assuming it refers to a future version
--> $DIR/syntax.rs:109:15
|
LL | #[cfg(version("1.0.65536"))]
| ^^^^^^^^^^^

warning: unknown version literal format, assuming it refers to a future version
--> $DIR/syntax.rs:113:15
|
LL | #[cfg(version("65536.0.65536"))]
| ^^^^^^^^^^^^^^^

warning: unknown version literal format, assuming it refers to a future version
--> $DIR/syntax.rs:125:26
|
LL | assert!(cfg!(version("foo")));
| ^^^^^

warning: unknown version literal format, assuming it refers to a future version
--> $DIR/syntax.rs:127:26
|
LL | assert!(cfg!(version("1.20.0-stable")));
| ^^^^^^^^^^^^^^^

warning: unexpected `cfg` condition name: `version`
--> $DIR/syntax.rs:30:7
|
LL | #[cfg(version = "1.43")]
| ^^^^^^^^^^^^^^^^
|
= help: to expect this configuration use `--check-cfg=cfg(version, values("1.43"))`
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
= note: `#[warn(unexpected_cfgs)]` on by default
help: there is a similar config predicate: `version("..")`
|
LL - #[cfg(version = "1.43")]
LL + #[cfg(version("1.43"))]
|

warning: unexpected `cfg` condition name: `version`
--> $DIR/syntax.rs:130:18
|
LL | assert!(cfg!(version = "1.43"));
| ^^^^^^^^^^^^^^^^
|
= help: to expect this configuration use `--check-cfg=cfg(version, values("1.43"))`
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
help: there is a similar config predicate: `version("..")`
|
LL - assert!(cfg!(version = "1.43"));
LL + assert!(cfg!(version("1.43")));
|

error[E0425]: cannot find function `key_value_form` in this scope
--> $DIR/syntax.rs:139:5
|
LL | key_value_form();
| ^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function `not_numbers_or_periods` in this scope
--> $DIR/syntax.rs:143:5
|
LL | not_numbers_or_periods();
| ^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function `complex_semver_with_metadata` in this scope
--> $DIR/syntax.rs:144:5
|
LL | complex_semver_with_metadata();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function `invalid_major_only` in this scope
--> $DIR/syntax.rs:145:5
|
LL | invalid_major_only();
| ^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function `invalid_major_only_zero` in this scope
--> $DIR/syntax.rs:146:5
|
LL | invalid_major_only_zero();
| ^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function `invalid_major_only_negative` in this scope
--> $DIR/syntax.rs:147:5
|
LL | invalid_major_only_negative();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function `exceed_u16_major` in this scope
--> $DIR/syntax.rs:148:5
|
LL | exceed_u16_major();
| ^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function `exceed_u16_minor` in this scope
--> $DIR/syntax.rs:149:5
|
LL | exceed_u16_minor();
| ^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function `exceed_u16_patch` in this scope
--> $DIR/syntax.rs:150:5
|
LL | exceed_u16_patch();
| ^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function `exceed_u16_mixed` in this scope
--> $DIR/syntax.rs:151:5
|
LL | exceed_u16_mixed();
| ^^^^^^^^^^^^^^^^ not found in this scope

error: aborting due to 14 previous errors; 14 warnings emitted

For more information about this error, try `rustc --explain E0425`.
49 changes: 6 additions & 43 deletions tests/ui/feature-gates/feature-gate-cfg-version.rs
Original file line number Diff line number Diff line change
@@ -1,49 +1,12 @@
#[cfg(version(42))] //~ ERROR: expected a version literal
//~^ ERROR `cfg(version)` is experimental and subject to change
fn foo() {}
#[cfg(version(1.20))] //~ ERROR: expected a version literal
//~^ ERROR `cfg(version)` is experimental and subject to change
fn foo() -> bool { true }
#[cfg(version("1.44"))]
//~^ ERROR `cfg(version)` is experimental and subject to change
fn foo() -> bool { true }
#[cfg(not(version("1.44")))]
//~^ ERROR `cfg(version)` is experimental and subject to change
fn foo() -> bool { false }
//! Feature gate test for `cfg_version`.
//!
//! Tracking issue: #64796.

#[cfg(version("1.43", "1.44", "1.45"))] //~ ERROR: expected single version literal
//~^ ERROR `cfg(version)` is experimental and subject to change
fn bar() -> bool { false }
#[cfg(version(false))] //~ ERROR: expected a version literal
//~^ ERROR `cfg(version)` is experimental and subject to change
fn bar() -> bool { false }
#[cfg(version("foo"))] //~ WARNING: unknown version literal format
//~^ ERROR `cfg(version)` is experimental and subject to change
fn bar() -> bool { false }
#[cfg(version("999"))] //~ WARNING: unknown version literal format
//~^ ERROR `cfg(version)` is experimental and subject to change
fn bar() -> bool { false }
#[cfg(version("-1"))] //~ WARNING: unknown version literal format
//~^ ERROR `cfg(version)` is experimental and subject to change
fn bar() -> bool { false }
#[cfg(version("65536"))] //~ WARNING: unknown version literal format
//~^ ERROR `cfg(version)` is experimental and subject to change
fn bar() -> bool { false }
#[cfg(version("0"))] //~ WARNING: unknown version literal format
//~^ ERROR `cfg(version)` is experimental and subject to change
fn bar() -> bool { true }
#[cfg(version("1.0"))]
//~^ ERROR `cfg(version)` is experimental and subject to change
fn bar() -> bool { true }
#[cfg(version("1.65536.2"))] //~ WARNING: unknown version literal format
//~^ ERROR `cfg(version)` is experimental and subject to change
fn bar() -> bool { false }
#[cfg(version("1.20.0-stable"))] //~ WARNING: unknown version literal format
#[cfg(version("1.42"))]
//~^ ERROR `cfg(version)` is experimental and subject to change
fn bar() {}

fn main() {
assert!(foo());
assert!(bar());
assert!(cfg!(version("1.42"))); //~ ERROR `cfg(version)` is experimental and subject to change
assert!(cfg!(version("1.42")));
//~^ ERROR `cfg(version)` is experimental and subject to change
}
Loading
Loading