From 3d81af8c55cd422910c4560f6cdc03722f4530c7 Mon Sep 17 00:00:00 2001 From: Kivooeo Date: Sat, 28 Jun 2025 22:57:01 +0500 Subject: moved tests --- .../ui/codegen/maximal-hir-to-mir-coverage-flag.rs | 10 ++++++ .../ui/lint/missing-debug-implementations-lint.rs | 38 ++++++++++++++++++++++ .../lint/missing-debug-implementations-lint.stderr | 20 ++++++++++++ tests/ui/maximal_mir_to_hir_coverage.rs | 10 ------ tests/ui/maybe-bounds.rs | 9 ----- tests/ui/maybe-bounds.stderr | 31 ------------------ tests/ui/method-output-diff-issue-127263.rs | 8 ----- tests/ui/method-output-diff-issue-127263.stderr | 25 -------------- .../fn-pointer-mismatch-diagnostics.rs | 8 +++++ .../fn-pointer-mismatch-diagnostics.stderr | 25 ++++++++++++++ tests/ui/missing_debug_impls.rs | 38 ---------------------- tests/ui/missing_debug_impls.stderr | 20 ------------ tests/ui/mod-subitem-as-enum-variant.rs | 9 ----- tests/ui/mod-subitem-as-enum-variant.stderr | 11 ------- .../maybe-trait-bounds-forbidden-locations.rs | 9 +++++ .../maybe-trait-bounds-forbidden-locations.stderr | 31 ++++++++++++++++++ .../module-type-args-error.rs | 9 +++++ .../module-type-args-error.stderr | 11 +++++++ 18 files changed, 161 insertions(+), 161 deletions(-) create mode 100644 tests/ui/codegen/maximal-hir-to-mir-coverage-flag.rs create mode 100644 tests/ui/lint/missing-debug-implementations-lint.rs create mode 100644 tests/ui/lint/missing-debug-implementations-lint.stderr delete mode 100644 tests/ui/maximal_mir_to_hir_coverage.rs delete mode 100644 tests/ui/maybe-bounds.rs delete mode 100644 tests/ui/maybe-bounds.stderr delete mode 100644 tests/ui/method-output-diff-issue-127263.rs delete mode 100644 tests/ui/method-output-diff-issue-127263.stderr create mode 100644 tests/ui/mismatched_types/fn-pointer-mismatch-diagnostics.rs create mode 100644 tests/ui/mismatched_types/fn-pointer-mismatch-diagnostics.stderr delete mode 100644 tests/ui/missing_debug_impls.rs delete mode 100644 tests/ui/missing_debug_impls.stderr delete mode 100644 tests/ui/mod-subitem-as-enum-variant.rs delete mode 100644 tests/ui/mod-subitem-as-enum-variant.stderr create mode 100644 tests/ui/traits/maybe-trait-bounds-forbidden-locations.rs create mode 100644 tests/ui/traits/maybe-trait-bounds-forbidden-locations.stderr create mode 100644 tests/ui/type-alias-enum-variants/module-type-args-error.rs create mode 100644 tests/ui/type-alias-enum-variants/module-type-args-error.stderr (limited to 'tests') diff --git a/tests/ui/codegen/maximal-hir-to-mir-coverage-flag.rs b/tests/ui/codegen/maximal-hir-to-mir-coverage-flag.rs new file mode 100644 index 00000000000..e57c83d007e --- /dev/null +++ b/tests/ui/codegen/maximal-hir-to-mir-coverage-flag.rs @@ -0,0 +1,10 @@ +//@ compile-flags: -Zmaximal-hir-to-mir-coverage +//@ run-pass + +// Just making sure this flag is accepted and doesn't crash the compiler + +fn main() { + let x = 1; + let y = x + 1; + println!("{y}"); +} diff --git a/tests/ui/lint/missing-debug-implementations-lint.rs b/tests/ui/lint/missing-debug-implementations-lint.rs new file mode 100644 index 00000000000..3abc0706887 --- /dev/null +++ b/tests/ui/lint/missing-debug-implementations-lint.rs @@ -0,0 +1,38 @@ +//@ compile-flags: --crate-type lib +#![deny(missing_debug_implementations)] +#![allow(unused)] + +use std::fmt; + +pub enum A {} //~ ERROR type does not implement `Debug` + +#[derive(Debug)] +pub enum B {} + +pub enum C {} + +impl fmt::Debug for C { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + Ok(()) + } +} + +pub struct Foo; //~ ERROR type does not implement `Debug` + +#[derive(Debug)] +pub struct Bar; + +pub struct Baz; + +impl fmt::Debug for Baz { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + Ok(()) + } +} + +struct PrivateStruct; + +enum PrivateEnum {} + +#[derive(Debug)] +pub struct GenericType(T); diff --git a/tests/ui/lint/missing-debug-implementations-lint.stderr b/tests/ui/lint/missing-debug-implementations-lint.stderr new file mode 100644 index 00000000000..0538f207b44 --- /dev/null +++ b/tests/ui/lint/missing-debug-implementations-lint.stderr @@ -0,0 +1,20 @@ +error: type does not implement `Debug`; consider adding `#[derive(Debug)]` or a manual implementation + --> $DIR/missing_debug_impls.rs:7:1 + | +LL | pub enum A {} + | ^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/missing_debug_impls.rs:2:9 + | +LL | #![deny(missing_debug_implementations)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: type does not implement `Debug`; consider adding `#[derive(Debug)]` or a manual implementation + --> $DIR/missing_debug_impls.rs:20:1 + | +LL | pub struct Foo; + | ^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/maximal_mir_to_hir_coverage.rs b/tests/ui/maximal_mir_to_hir_coverage.rs deleted file mode 100644 index e57c83d007e..00000000000 --- a/tests/ui/maximal_mir_to_hir_coverage.rs +++ /dev/null @@ -1,10 +0,0 @@ -//@ compile-flags: -Zmaximal-hir-to-mir-coverage -//@ run-pass - -// Just making sure this flag is accepted and doesn't crash the compiler - -fn main() { - let x = 1; - let y = x + 1; - println!("{y}"); -} diff --git a/tests/ui/maybe-bounds.rs b/tests/ui/maybe-bounds.rs deleted file mode 100644 index 02ed45c656f..00000000000 --- a/tests/ui/maybe-bounds.rs +++ /dev/null @@ -1,9 +0,0 @@ -trait Tr: ?Sized {} -//~^ ERROR `?Trait` is not permitted in supertraits - -type A1 = dyn Tr + (?Sized); -//~^ ERROR `?Trait` is not permitted in trait object types -type A2 = dyn for<'a> Tr + (?Sized); -//~^ ERROR `?Trait` is not permitted in trait object types - -fn main() {} diff --git a/tests/ui/maybe-bounds.stderr b/tests/ui/maybe-bounds.stderr deleted file mode 100644 index 230d11fd0ae..00000000000 --- a/tests/ui/maybe-bounds.stderr +++ /dev/null @@ -1,31 +0,0 @@ -error[E0658]: `?Trait` is not permitted in supertraits - --> $DIR/maybe-bounds.rs:1:11 - | -LL | trait Tr: ?Sized {} - | ^^^^^^ - | - = note: traits are `?Sized` by default - = help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: `?Trait` is not permitted in trait object types - --> $DIR/maybe-bounds.rs:4:20 - | -LL | type A1 = dyn Tr + (?Sized); - | ^^^^^^^^ - | - = help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: `?Trait` is not permitted in trait object types - --> $DIR/maybe-bounds.rs:6:28 - | -LL | type A2 = dyn for<'a> Tr + (?Sized); - | ^^^^^^^^ - | - = help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/method-output-diff-issue-127263.rs b/tests/ui/method-output-diff-issue-127263.rs deleted file mode 100644 index 85a903e2453..00000000000 --- a/tests/ui/method-output-diff-issue-127263.rs +++ /dev/null @@ -1,8 +0,0 @@ -fn bar() {} -fn foo(x: i32) -> u32 { - 0 -} -fn main() { - let b: fn() -> u32 = bar; //~ ERROR mismatched types [E0308] - let f: fn(i32) = foo; //~ ERROR mismatched types [E0308] -} diff --git a/tests/ui/method-output-diff-issue-127263.stderr b/tests/ui/method-output-diff-issue-127263.stderr deleted file mode 100644 index 35b86114f16..00000000000 --- a/tests/ui/method-output-diff-issue-127263.stderr +++ /dev/null @@ -1,25 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/method-output-diff-issue-127263.rs:6:26 - | -LL | let b: fn() -> u32 = bar; - | ----------- ^^^ expected fn pointer, found fn item - | | - | expected due to this - | - = note: expected fn pointer `fn() -> u32` - found fn item `fn() -> () {bar}` - -error[E0308]: mismatched types - --> $DIR/method-output-diff-issue-127263.rs:7:22 - | -LL | let f: fn(i32) = foo; - | ------- ^^^ expected fn pointer, found fn item - | | - | expected due to this - | - = note: expected fn pointer `fn(_) -> ()` - found fn item `fn(_) -> u32 {foo}` - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/mismatched_types/fn-pointer-mismatch-diagnostics.rs b/tests/ui/mismatched_types/fn-pointer-mismatch-diagnostics.rs new file mode 100644 index 00000000000..85a903e2453 --- /dev/null +++ b/tests/ui/mismatched_types/fn-pointer-mismatch-diagnostics.rs @@ -0,0 +1,8 @@ +fn bar() {} +fn foo(x: i32) -> u32 { + 0 +} +fn main() { + let b: fn() -> u32 = bar; //~ ERROR mismatched types [E0308] + let f: fn(i32) = foo; //~ ERROR mismatched types [E0308] +} diff --git a/tests/ui/mismatched_types/fn-pointer-mismatch-diagnostics.stderr b/tests/ui/mismatched_types/fn-pointer-mismatch-diagnostics.stderr new file mode 100644 index 00000000000..35b86114f16 --- /dev/null +++ b/tests/ui/mismatched_types/fn-pointer-mismatch-diagnostics.stderr @@ -0,0 +1,25 @@ +error[E0308]: mismatched types + --> $DIR/method-output-diff-issue-127263.rs:6:26 + | +LL | let b: fn() -> u32 = bar; + | ----------- ^^^ expected fn pointer, found fn item + | | + | expected due to this + | + = note: expected fn pointer `fn() -> u32` + found fn item `fn() -> () {bar}` + +error[E0308]: mismatched types + --> $DIR/method-output-diff-issue-127263.rs:7:22 + | +LL | let f: fn(i32) = foo; + | ------- ^^^ expected fn pointer, found fn item + | | + | expected due to this + | + = note: expected fn pointer `fn(_) -> ()` + found fn item `fn(_) -> u32 {foo}` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/missing_debug_impls.rs b/tests/ui/missing_debug_impls.rs deleted file mode 100644 index 3abc0706887..00000000000 --- a/tests/ui/missing_debug_impls.rs +++ /dev/null @@ -1,38 +0,0 @@ -//@ compile-flags: --crate-type lib -#![deny(missing_debug_implementations)] -#![allow(unused)] - -use std::fmt; - -pub enum A {} //~ ERROR type does not implement `Debug` - -#[derive(Debug)] -pub enum B {} - -pub enum C {} - -impl fmt::Debug for C { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - Ok(()) - } -} - -pub struct Foo; //~ ERROR type does not implement `Debug` - -#[derive(Debug)] -pub struct Bar; - -pub struct Baz; - -impl fmt::Debug for Baz { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - Ok(()) - } -} - -struct PrivateStruct; - -enum PrivateEnum {} - -#[derive(Debug)] -pub struct GenericType(T); diff --git a/tests/ui/missing_debug_impls.stderr b/tests/ui/missing_debug_impls.stderr deleted file mode 100644 index 0538f207b44..00000000000 --- a/tests/ui/missing_debug_impls.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error: type does not implement `Debug`; consider adding `#[derive(Debug)]` or a manual implementation - --> $DIR/missing_debug_impls.rs:7:1 - | -LL | pub enum A {} - | ^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/missing_debug_impls.rs:2:9 - | -LL | #![deny(missing_debug_implementations)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: type does not implement `Debug`; consider adding `#[derive(Debug)]` or a manual implementation - --> $DIR/missing_debug_impls.rs:20:1 - | -LL | pub struct Foo; - | ^^^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/tests/ui/mod-subitem-as-enum-variant.rs b/tests/ui/mod-subitem-as-enum-variant.rs deleted file mode 100644 index 959024c46f4..00000000000 --- a/tests/ui/mod-subitem-as-enum-variant.rs +++ /dev/null @@ -1,9 +0,0 @@ -mod Mod { - pub struct FakeVariant(pub T); -} - -fn main() { - Mod::FakeVariant::(0); - Mod::::FakeVariant(0); - //~^ ERROR type arguments are not allowed on module `Mod` [E0109] -} diff --git a/tests/ui/mod-subitem-as-enum-variant.stderr b/tests/ui/mod-subitem-as-enum-variant.stderr deleted file mode 100644 index 92d972eba42..00000000000 --- a/tests/ui/mod-subitem-as-enum-variant.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0109]: type arguments are not allowed on module `Mod` - --> $DIR/mod-subitem-as-enum-variant.rs:7:11 - | -LL | Mod::::FakeVariant(0); - | --- ^^^ type argument not allowed - | | - | not allowed on module `Mod` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0109`. diff --git a/tests/ui/traits/maybe-trait-bounds-forbidden-locations.rs b/tests/ui/traits/maybe-trait-bounds-forbidden-locations.rs new file mode 100644 index 00000000000..02ed45c656f --- /dev/null +++ b/tests/ui/traits/maybe-trait-bounds-forbidden-locations.rs @@ -0,0 +1,9 @@ +trait Tr: ?Sized {} +//~^ ERROR `?Trait` is not permitted in supertraits + +type A1 = dyn Tr + (?Sized); +//~^ ERROR `?Trait` is not permitted in trait object types +type A2 = dyn for<'a> Tr + (?Sized); +//~^ ERROR `?Trait` is not permitted in trait object types + +fn main() {} diff --git a/tests/ui/traits/maybe-trait-bounds-forbidden-locations.stderr b/tests/ui/traits/maybe-trait-bounds-forbidden-locations.stderr new file mode 100644 index 00000000000..230d11fd0ae --- /dev/null +++ b/tests/ui/traits/maybe-trait-bounds-forbidden-locations.stderr @@ -0,0 +1,31 @@ +error[E0658]: `?Trait` is not permitted in supertraits + --> $DIR/maybe-bounds.rs:1:11 + | +LL | trait Tr: ?Sized {} + | ^^^^^^ + | + = note: traits are `?Sized` by default + = help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: `?Trait` is not permitted in trait object types + --> $DIR/maybe-bounds.rs:4:20 + | +LL | type A1 = dyn Tr + (?Sized); + | ^^^^^^^^ + | + = help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: `?Trait` is not permitted in trait object types + --> $DIR/maybe-bounds.rs:6:28 + | +LL | type A2 = dyn for<'a> Tr + (?Sized); + | ^^^^^^^^ + | + = help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/type-alias-enum-variants/module-type-args-error.rs b/tests/ui/type-alias-enum-variants/module-type-args-error.rs new file mode 100644 index 00000000000..959024c46f4 --- /dev/null +++ b/tests/ui/type-alias-enum-variants/module-type-args-error.rs @@ -0,0 +1,9 @@ +mod Mod { + pub struct FakeVariant(pub T); +} + +fn main() { + Mod::FakeVariant::(0); + Mod::::FakeVariant(0); + //~^ ERROR type arguments are not allowed on module `Mod` [E0109] +} diff --git a/tests/ui/type-alias-enum-variants/module-type-args-error.stderr b/tests/ui/type-alias-enum-variants/module-type-args-error.stderr new file mode 100644 index 00000000000..92d972eba42 --- /dev/null +++ b/tests/ui/type-alias-enum-variants/module-type-args-error.stderr @@ -0,0 +1,11 @@ +error[E0109]: type arguments are not allowed on module `Mod` + --> $DIR/mod-subitem-as-enum-variant.rs:7:11 + | +LL | Mod::::FakeVariant(0); + | --- ^^^ type argument not allowed + | | + | not allowed on module `Mod` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0109`. -- cgit 1.4.1-3-g733a5 From ed16ae851bdb840ab2e7776e343ef865bfcbb76d Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 28 Jun 2025 20:46:46 +0000 Subject: Do not freshen ReError --- compiler/rustc_infer/src/infer/freshen.rs | 9 +++---- tests/crashes/132882.rs | 13 ---------- tests/ui/traits/eval-caching-error-region.rs | 23 +++++++++++++++++ tests/ui/traits/eval-caching-error-region.stderr | 33 ++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 18 deletions(-) delete mode 100644 tests/crashes/132882.rs create mode 100644 tests/ui/traits/eval-caching-error-region.rs create mode 100644 tests/ui/traits/eval-caching-error-region.stderr (limited to 'tests') diff --git a/compiler/rustc_infer/src/infer/freshen.rs b/compiler/rustc_infer/src/infer/freshen.rs index cae674165f0..ddc0b116806 100644 --- a/compiler/rustc_infer/src/infer/freshen.rs +++ b/compiler/rustc_infer/src/infer/freshen.rs @@ -110,17 +110,16 @@ impl<'a, 'tcx> TypeFolder> for TypeFreshener<'a, 'tcx> { fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { match r.kind() { - ty::ReBound(..) => { - // leave bound regions alone - r - } + // Leave bound regions alone, since they affect selection via the leak check. + ty::ReBound(..) => r, + // Leave error regions alone, since they affect selection b/c of incompleteness. + ty::ReError(_) => r, ty::ReEarlyParam(..) | ty::ReLateParam(_) | ty::ReVar(_) | ty::RePlaceholder(..) | ty::ReStatic - | ty::ReError(_) | ty::ReErased => self.cx().lifetimes.re_erased, } } diff --git a/tests/crashes/132882.rs b/tests/crashes/132882.rs deleted file mode 100644 index 6b5e4dba803..00000000000 --- a/tests/crashes/132882.rs +++ /dev/null @@ -1,13 +0,0 @@ -//@ known-bug: #132882 - -use std::ops::Add; - -pub trait Numoid -where - for &'a Self: Add, -{ -} - -pub fn compute(a: N) -> N { - &a + a -} diff --git a/tests/ui/traits/eval-caching-error-region.rs b/tests/ui/traits/eval-caching-error-region.rs new file mode 100644 index 00000000000..831b5ab80c1 --- /dev/null +++ b/tests/ui/traits/eval-caching-error-region.rs @@ -0,0 +1,23 @@ +// Regression test for #132882. + +use std::ops::Add; + +pub trait Numoid: Sized +where + &'missing Self: Add, + //~^ ERROR use of undeclared lifetime name `'missing` +{ +} + +// Proving `N: Numoid`'s well-formedness causes us to have to prove `&'missing N: Add`. +// Since `'missing` is a region error, that will lead to us consider the predicate to hold, +// since it references errors. Since the freshener turns error regions into fresh regions, +// this means that subsequent lookups of `&'?0 N: Add` will also hit this cache entry +// even if candidate assembly can't assemble anything for `&'?0 N: Add` anyways. This +// led to an ICE. +pub fn compute(a: N) { + let _ = &a + a; + //~^ ERROR cannot add `N` to `&N` +} + +fn main() {} diff --git a/tests/ui/traits/eval-caching-error-region.stderr b/tests/ui/traits/eval-caching-error-region.stderr new file mode 100644 index 00000000000..6365d242d2e --- /dev/null +++ b/tests/ui/traits/eval-caching-error-region.stderr @@ -0,0 +1,33 @@ +error[E0261]: use of undeclared lifetime name `'missing` + --> $DIR/eval-caching-error-region.rs:7:6 + | +LL | &'missing Self: Add, + | ^^^^^^^^ undeclared lifetime + | + = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html +help: consider making the bound lifetime-generic with a new `'missing` lifetime + | +LL | for<'missing> &'missing Self: Add, + | +++++++++++++ +help: consider introducing lifetime `'missing` here + | +LL | pub trait Numoid<'missing>: Sized + | ++++++++++ + +error[E0369]: cannot add `N` to `&N` + --> $DIR/eval-caching-error-region.rs:19:16 + | +LL | let _ = &a + a; + | -- ^ - N + | | + | &N + | +help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement + | +LL | pub fn compute(a: N) where &N: Add { + | ++++++++++++++++ + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0261, E0369. +For more information about an error, try `rustc --explain E0261`. -- cgit 1.4.1-3-g733a5 From 74657a4a1a8b18bed905bd997aa390a90a3b943f Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sat, 28 Jun 2025 18:59:25 -0500 Subject: Move some UI tests to more apropriate directories Prepare for rework done in the rest of [PR143118]. [PR143118]: https://www.github.com/rust-lang/rust/pull/143118 Co-authored-by: Kivooeo --- .../ui-test-missing-annotations-detection.rs | 6 ++++ tests/ui/derives/derive-Debug-enum-variants.rs | 21 ++++++++++++ tests/ui/fmt/debug-single-call.rs | 29 ++++++++++++++++ tests/ui/lexical-scoping.rs | 19 ---------- tests/ui/link-section.rs | 40 ---------------------- tests/ui/linkage-attr/link-section-placement.rs | 40 ++++++++++++++++++++++ tests/ui/log-knows-the-names-of-variants.rs | 21 ------------ tests/ui/logging-only-prints-once.rs | 29 ---------------- tests/ui/loud_ui.rs | 6 ---- tests/ui/max-min-classes.rs | 32 ----------------- tests/ui/resolve/struct-function-same-name.rs | 32 +++++++++++++++++ tests/ui/resolve/type-param-local-var-shadowing.rs | 19 ++++++++++ 12 files changed, 147 insertions(+), 147 deletions(-) create mode 100644 tests/ui/compiletest-self-test/ui-test-missing-annotations-detection.rs create mode 100644 tests/ui/derives/derive-Debug-enum-variants.rs create mode 100644 tests/ui/fmt/debug-single-call.rs delete mode 100644 tests/ui/lexical-scoping.rs delete mode 100644 tests/ui/link-section.rs create mode 100644 tests/ui/linkage-attr/link-section-placement.rs delete mode 100644 tests/ui/log-knows-the-names-of-variants.rs delete mode 100644 tests/ui/logging-only-prints-once.rs delete mode 100644 tests/ui/loud_ui.rs delete mode 100644 tests/ui/max-min-classes.rs create mode 100644 tests/ui/resolve/struct-function-same-name.rs create mode 100644 tests/ui/resolve/type-param-local-var-shadowing.rs (limited to 'tests') diff --git a/tests/ui/compiletest-self-test/ui-test-missing-annotations-detection.rs b/tests/ui/compiletest-self-test/ui-test-missing-annotations-detection.rs new file mode 100644 index 00000000000..2a73e49e172 --- /dev/null +++ b/tests/ui/compiletest-self-test/ui-test-missing-annotations-detection.rs @@ -0,0 +1,6 @@ +//@ should-fail + +// this test ensures that when we forget to use +// any `//~ ERROR` comments whatsoever, that the test doesn't succeed + +fn main() {} diff --git a/tests/ui/derives/derive-Debug-enum-variants.rs b/tests/ui/derives/derive-Debug-enum-variants.rs new file mode 100644 index 00000000000..cb82cb4878a --- /dev/null +++ b/tests/ui/derives/derive-Debug-enum-variants.rs @@ -0,0 +1,21 @@ +//@ run-pass + +#![allow(non_camel_case_types)] +#![allow(dead_code)] +#[derive(Debug)] +enum foo { + a(usize), + b(String), + c, +} + +#[derive(Debug)] +enum bar { + d, e, f +} + +pub fn main() { + assert_eq!("a(22)".to_string(), format!("{:?}", foo::a(22))); + assert_eq!("c".to_string(), format!("{:?}", foo::c)); + assert_eq!("d".to_string(), format!("{:?}", bar::d)); +} diff --git a/tests/ui/fmt/debug-single-call.rs b/tests/ui/fmt/debug-single-call.rs new file mode 100644 index 00000000000..bb8c29694b5 --- /dev/null +++ b/tests/ui/fmt/debug-single-call.rs @@ -0,0 +1,29 @@ +//@ run-pass +//@ needs-threads + +use std::cell::Cell; +use std::fmt; +use std::thread; + +struct Foo(Cell); + +impl fmt::Debug for Foo { + fn fmt(&self, _fmt: &mut fmt::Formatter) -> fmt::Result { + let Foo(ref f) = *self; + assert_eq!(f.get(), 0); + f.set(1); + Ok(()) + } +} + +pub fn main() { + thread::spawn(move || { + let mut f = Foo(Cell::new(0)); + println!("{:?}", f); + let Foo(ref mut f) = f; + assert_eq!(f.get(), 1); + }) + .join() + .ok() + .unwrap(); +} diff --git a/tests/ui/lexical-scoping.rs b/tests/ui/lexical-scoping.rs deleted file mode 100644 index f858369f7ce..00000000000 --- a/tests/ui/lexical-scoping.rs +++ /dev/null @@ -1,19 +0,0 @@ -//@ run-pass -// Tests that items in subscopes can shadow type parameters and local variables (see issue #23880). - -#![allow(unused)] -struct Foo { x: Box } -impl Foo { - fn foo(&self) { - type Bar = i32; - let _: Bar = 42; - } -} - -fn main() { - let f = 1; - { - fn f() {} - f(); - } -} diff --git a/tests/ui/link-section.rs b/tests/ui/link-section.rs deleted file mode 100644 index a8de8c2e1e7..00000000000 --- a/tests/ui/link-section.rs +++ /dev/null @@ -1,40 +0,0 @@ -//@ run-pass - -// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint -#![allow(static_mut_refs)] - -#![allow(non_upper_case_globals)] -#[cfg(not(target_vendor = "apple"))] -#[link_section = ".moretext"] -fn i_live_in_more_text() -> &'static str { - "knock knock" -} - -#[cfg(not(target_vendor = "apple"))] -#[link_section = ".imm"] -static magic: usize = 42; - -#[cfg(not(target_vendor = "apple"))] -#[link_section = ".mut"] -static mut frobulator: usize = 0xdeadbeef; - -#[cfg(target_vendor = "apple")] -#[link_section = "__TEXT,__moretext"] -fn i_live_in_more_text() -> &'static str { - "knock knock" -} - -#[cfg(target_vendor = "apple")] -#[link_section = "__RODATA,__imm"] -static magic: usize = 42; - -#[cfg(target_vendor = "apple")] -#[link_section = "__DATA,__mut"] -static mut frobulator: usize = 0xdeadbeef; - -pub fn main() { - unsafe { - frobulator = 0x12345678; - println!("{} {} {}", i_live_in_more_text(), magic, frobulator); - } -} diff --git a/tests/ui/linkage-attr/link-section-placement.rs b/tests/ui/linkage-attr/link-section-placement.rs new file mode 100644 index 00000000000..a8de8c2e1e7 --- /dev/null +++ b/tests/ui/linkage-attr/link-section-placement.rs @@ -0,0 +1,40 @@ +//@ run-pass + +// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint +#![allow(static_mut_refs)] + +#![allow(non_upper_case_globals)] +#[cfg(not(target_vendor = "apple"))] +#[link_section = ".moretext"] +fn i_live_in_more_text() -> &'static str { + "knock knock" +} + +#[cfg(not(target_vendor = "apple"))] +#[link_section = ".imm"] +static magic: usize = 42; + +#[cfg(not(target_vendor = "apple"))] +#[link_section = ".mut"] +static mut frobulator: usize = 0xdeadbeef; + +#[cfg(target_vendor = "apple")] +#[link_section = "__TEXT,__moretext"] +fn i_live_in_more_text() -> &'static str { + "knock knock" +} + +#[cfg(target_vendor = "apple")] +#[link_section = "__RODATA,__imm"] +static magic: usize = 42; + +#[cfg(target_vendor = "apple")] +#[link_section = "__DATA,__mut"] +static mut frobulator: usize = 0xdeadbeef; + +pub fn main() { + unsafe { + frobulator = 0x12345678; + println!("{} {} {}", i_live_in_more_text(), magic, frobulator); + } +} diff --git a/tests/ui/log-knows-the-names-of-variants.rs b/tests/ui/log-knows-the-names-of-variants.rs deleted file mode 100644 index cb82cb4878a..00000000000 --- a/tests/ui/log-knows-the-names-of-variants.rs +++ /dev/null @@ -1,21 +0,0 @@ -//@ run-pass - -#![allow(non_camel_case_types)] -#![allow(dead_code)] -#[derive(Debug)] -enum foo { - a(usize), - b(String), - c, -} - -#[derive(Debug)] -enum bar { - d, e, f -} - -pub fn main() { - assert_eq!("a(22)".to_string(), format!("{:?}", foo::a(22))); - assert_eq!("c".to_string(), format!("{:?}", foo::c)); - assert_eq!("d".to_string(), format!("{:?}", bar::d)); -} diff --git a/tests/ui/logging-only-prints-once.rs b/tests/ui/logging-only-prints-once.rs deleted file mode 100644 index bb8c29694b5..00000000000 --- a/tests/ui/logging-only-prints-once.rs +++ /dev/null @@ -1,29 +0,0 @@ -//@ run-pass -//@ needs-threads - -use std::cell::Cell; -use std::fmt; -use std::thread; - -struct Foo(Cell); - -impl fmt::Debug for Foo { - fn fmt(&self, _fmt: &mut fmt::Formatter) -> fmt::Result { - let Foo(ref f) = *self; - assert_eq!(f.get(), 0); - f.set(1); - Ok(()) - } -} - -pub fn main() { - thread::spawn(move || { - let mut f = Foo(Cell::new(0)); - println!("{:?}", f); - let Foo(ref mut f) = f; - assert_eq!(f.get(), 1); - }) - .join() - .ok() - .unwrap(); -} diff --git a/tests/ui/loud_ui.rs b/tests/ui/loud_ui.rs deleted file mode 100644 index 2a73e49e172..00000000000 --- a/tests/ui/loud_ui.rs +++ /dev/null @@ -1,6 +0,0 @@ -//@ should-fail - -// this test ensures that when we forget to use -// any `//~ ERROR` comments whatsoever, that the test doesn't succeed - -fn main() {} diff --git a/tests/ui/max-min-classes.rs b/tests/ui/max-min-classes.rs deleted file mode 100644 index 338a3156a9a..00000000000 --- a/tests/ui/max-min-classes.rs +++ /dev/null @@ -1,32 +0,0 @@ -//@ run-pass - -#![allow(non_snake_case)] -trait Product { - fn product(&self) -> isize; -} - -struct Foo { - x: isize, - y: isize, -} - -impl Foo { - pub fn sum(&self) -> isize { - self.x + self.y - } -} - -impl Product for Foo { - fn product(&self) -> isize { - self.x * self.y - } -} - -fn Foo(x: isize, y: isize) -> Foo { - Foo { x: x, y: y } -} - -pub fn main() { - let foo = Foo(3, 20); - println!("{} {}", foo.sum(), foo.product()); -} diff --git a/tests/ui/resolve/struct-function-same-name.rs b/tests/ui/resolve/struct-function-same-name.rs new file mode 100644 index 00000000000..338a3156a9a --- /dev/null +++ b/tests/ui/resolve/struct-function-same-name.rs @@ -0,0 +1,32 @@ +//@ run-pass + +#![allow(non_snake_case)] +trait Product { + fn product(&self) -> isize; +} + +struct Foo { + x: isize, + y: isize, +} + +impl Foo { + pub fn sum(&self) -> isize { + self.x + self.y + } +} + +impl Product for Foo { + fn product(&self) -> isize { + self.x * self.y + } +} + +fn Foo(x: isize, y: isize) -> Foo { + Foo { x: x, y: y } +} + +pub fn main() { + let foo = Foo(3, 20); + println!("{} {}", foo.sum(), foo.product()); +} diff --git a/tests/ui/resolve/type-param-local-var-shadowing.rs b/tests/ui/resolve/type-param-local-var-shadowing.rs new file mode 100644 index 00000000000..f858369f7ce --- /dev/null +++ b/tests/ui/resolve/type-param-local-var-shadowing.rs @@ -0,0 +1,19 @@ +//@ run-pass +// Tests that items in subscopes can shadow type parameters and local variables (see issue #23880). + +#![allow(unused)] +struct Foo { x: Box } +impl Foo { + fn foo(&self) { + type Bar = i32; + let _: Bar = 42; + } +} + +fn main() { + let f = 1; + { + fn f() {} + f(); + } +} -- cgit 1.4.1-3-g733a5 From d0bd27924e69084f11290e7876ee63b69c0d9667 Mon Sep 17 00:00:00 2001 From: Kivooeo Date: Thu, 12 Jun 2025 20:49:48 +0500 Subject: cleaned up some tests --- src/tools/tidy/src/issues.txt | 1 - tests/ui/attributes/inner-attrs-impl-cfg.rs | 36 ++++++++ tests/ui/indexing/indexing-integral-types.rs | 20 +++++ tests/ui/indexing/indexing-integral-types.stderr | 99 ++++++++++++++++++++++ tests/ui/inner-attrs-on-impl.rs | 24 ------ tests/ui/inner-module.rs | 10 --- tests/ui/inner-static-type-parameter.rs | 11 --- tests/ui/inner-static-type-parameter.stderr | 23 ----- tests/ui/integral-indexing.rs | 16 ---- tests/ui/integral-indexing.stderr | 99 ---------------------- tests/ui/integral-variable-unification-error.rs | 8 -- .../ui/integral-variable-unification-error.stderr | 14 --- tests/ui/invalid_dispatch_from_dyn_impls.rs | 55 ------------ tests/ui/invalid_dispatch_from_dyn_impls.stderr | 60 ------------- tests/ui/issue-11881.rs | 91 -------------------- .../ui/mismatched_types/int-float-type-mismatch.rs | 11 +++ .../int-float-type-mismatch.stderr | 14 +++ tests/ui/modules/nested-modules-basic.rs | 19 +++++ tests/ui/statics/static-generic-param-soundness.rs | 20 +++++ .../statics/static-generic-param-soundness.stderr | 23 +++++ tests/ui/traits/dispatch-from-dyn-invalid-impls.rs | 71 ++++++++++++++++ .../traits/dispatch-from-dyn-invalid-impls.stderr | 60 +++++++++++++ tests/ui/traits/encoder-trait-bounds-regression.rs | 98 +++++++++++++++++++++ 23 files changed, 471 insertions(+), 412 deletions(-) create mode 100644 tests/ui/attributes/inner-attrs-impl-cfg.rs create mode 100644 tests/ui/indexing/indexing-integral-types.rs create mode 100644 tests/ui/indexing/indexing-integral-types.stderr delete mode 100644 tests/ui/inner-attrs-on-impl.rs delete mode 100644 tests/ui/inner-module.rs delete mode 100644 tests/ui/inner-static-type-parameter.rs delete mode 100644 tests/ui/inner-static-type-parameter.stderr delete mode 100644 tests/ui/integral-indexing.rs delete mode 100644 tests/ui/integral-indexing.stderr delete mode 100644 tests/ui/integral-variable-unification-error.rs delete mode 100644 tests/ui/integral-variable-unification-error.stderr delete mode 100644 tests/ui/invalid_dispatch_from_dyn_impls.rs delete mode 100644 tests/ui/invalid_dispatch_from_dyn_impls.stderr delete mode 100644 tests/ui/issue-11881.rs create mode 100644 tests/ui/mismatched_types/int-float-type-mismatch.rs create mode 100644 tests/ui/mismatched_types/int-float-type-mismatch.stderr create mode 100644 tests/ui/modules/nested-modules-basic.rs create mode 100644 tests/ui/statics/static-generic-param-soundness.rs create mode 100644 tests/ui/statics/static-generic-param-soundness.stderr create mode 100644 tests/ui/traits/dispatch-from-dyn-invalid-impls.rs create mode 100644 tests/ui/traits/dispatch-from-dyn-invalid-impls.stderr create mode 100644 tests/ui/traits/encoder-trait-bounds-regression.rs (limited to 'tests') diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index b3517b2e9da..38c6da5ba96 100644 --- a/src/tools/tidy/src/issues.txt +++ b/src/tools/tidy/src/issues.txt @@ -1368,7 +1368,6 @@ ui/infinite/issue-41731-infinite-macro-println.rs ui/intrinsics/issue-28575.rs ui/intrinsics/issue-84297-reifying-copy.rs ui/invalid/issue-114435-layout-type-err.rs -ui/issue-11881.rs ui/issue-15924.rs ui/issue-16822.rs ui/issues-71798.rs diff --git a/tests/ui/attributes/inner-attrs-impl-cfg.rs b/tests/ui/attributes/inner-attrs-impl-cfg.rs new file mode 100644 index 00000000000..e7a5cfa9e2f --- /dev/null +++ b/tests/ui/attributes/inner-attrs-impl-cfg.rs @@ -0,0 +1,36 @@ +//! Test inner attributes (#![...]) behavior in impl blocks with cfg conditions. +//! +//! This test verifies that: +//! - Inner attributes can conditionally exclude entire impl blocks +//! - Regular attributes within impl blocks work independently +//! - Attribute parsing doesn't consume too eagerly + +//@ run-pass + +struct Foo; + +impl Foo { + #![cfg(false)] + + fn method(&self) -> bool { + false + } +} + +impl Foo { + #![cfg(not(FALSE))] + + // Check that we don't eat attributes too eagerly. + #[cfg(false)] + fn method(&self) -> bool { + false + } + + fn method(&self) -> bool { + true + } +} + +pub fn main() { + assert!(Foo.method()); +} diff --git a/tests/ui/indexing/indexing-integral-types.rs b/tests/ui/indexing/indexing-integral-types.rs new file mode 100644 index 00000000000..a91696a6fd5 --- /dev/null +++ b/tests/ui/indexing/indexing-integral-types.rs @@ -0,0 +1,20 @@ +//! Test that only usize can be used for indexing arrays and slices. + +pub fn main() { + let v: Vec = vec![0, 1, 2, 3, 4, 5]; + let s: String = "abcdef".to_string(); + + // Valid indexing with usize + v[3_usize]; + v[3]; + v[3u8]; //~ ERROR the type `[isize]` cannot be indexed by `u8` + v[3i8]; //~ ERROR the type `[isize]` cannot be indexed by `i8` + v[3u32]; //~ ERROR the type `[isize]` cannot be indexed by `u32` + v[3i32]; //~ ERROR the type `[isize]` cannot be indexed by `i32` + s.as_bytes()[3_usize]; + s.as_bytes()[3]; + s.as_bytes()[3u8]; //~ ERROR the type `[u8]` cannot be indexed by `u8` + s.as_bytes()[3i8]; //~ ERROR the type `[u8]` cannot be indexed by `i8` + s.as_bytes()[3u32]; //~ ERROR the type `[u8]` cannot be indexed by `u32` + s.as_bytes()[3i32]; //~ ERROR the type `[u8]` cannot be indexed by `i32` +} diff --git a/tests/ui/indexing/indexing-integral-types.stderr b/tests/ui/indexing/indexing-integral-types.stderr new file mode 100644 index 00000000000..b63991ec2c4 --- /dev/null +++ b/tests/ui/indexing/indexing-integral-types.stderr @@ -0,0 +1,99 @@ +error[E0277]: the type `[isize]` cannot be indexed by `u8` + --> $DIR/indexing-integral-types.rs:10:7 + | +LL | v[3u8]; + | ^^^ slice indices are of type `usize` or ranges of `usize` + | + = help: the trait `SliceIndex<[isize]>` is not implemented for `u8` + = help: the following other types implement trait `SliceIndex`: + `usize` implements `SliceIndex` + `usize` implements `SliceIndex<[T]>` + = note: required for `Vec` to implement `Index` + +error[E0277]: the type `[isize]` cannot be indexed by `i8` + --> $DIR/indexing-integral-types.rs:11:7 + | +LL | v[3i8]; + | ^^^ slice indices are of type `usize` or ranges of `usize` + | + = help: the trait `SliceIndex<[isize]>` is not implemented for `i8` + = help: the following other types implement trait `SliceIndex`: + `usize` implements `SliceIndex` + `usize` implements `SliceIndex<[T]>` + = note: required for `Vec` to implement `Index` + +error[E0277]: the type `[isize]` cannot be indexed by `u32` + --> $DIR/indexing-integral-types.rs:12:7 + | +LL | v[3u32]; + | ^^^^ slice indices are of type `usize` or ranges of `usize` + | + = help: the trait `SliceIndex<[isize]>` is not implemented for `u32` + = help: the following other types implement trait `SliceIndex`: + `usize` implements `SliceIndex` + `usize` implements `SliceIndex<[T]>` + = note: required for `Vec` to implement `Index` + +error[E0277]: the type `[isize]` cannot be indexed by `i32` + --> $DIR/indexing-integral-types.rs:13:7 + | +LL | v[3i32]; + | ^^^^ slice indices are of type `usize` or ranges of `usize` + | + = help: the trait `SliceIndex<[isize]>` is not implemented for `i32` + = help: the following other types implement trait `SliceIndex`: + `usize` implements `SliceIndex` + `usize` implements `SliceIndex<[T]>` + = note: required for `Vec` to implement `Index` + +error[E0277]: the type `[u8]` cannot be indexed by `u8` + --> $DIR/indexing-integral-types.rs:16:18 + | +LL | s.as_bytes()[3u8]; + | ^^^ slice indices are of type `usize` or ranges of `usize` + | + = help: the trait `SliceIndex<[u8]>` is not implemented for `u8` + = help: the following other types implement trait `SliceIndex`: + `usize` implements `SliceIndex` + `usize` implements `SliceIndex<[T]>` + = note: required for `[u8]` to implement `Index` + +error[E0277]: the type `[u8]` cannot be indexed by `i8` + --> $DIR/indexing-integral-types.rs:17:18 + | +LL | s.as_bytes()[3i8]; + | ^^^ slice indices are of type `usize` or ranges of `usize` + | + = help: the trait `SliceIndex<[u8]>` is not implemented for `i8` + = help: the following other types implement trait `SliceIndex`: + `usize` implements `SliceIndex` + `usize` implements `SliceIndex<[T]>` + = note: required for `[u8]` to implement `Index` + +error[E0277]: the type `[u8]` cannot be indexed by `u32` + --> $DIR/indexing-integral-types.rs:18:18 + | +LL | s.as_bytes()[3u32]; + | ^^^^ slice indices are of type `usize` or ranges of `usize` + | + = help: the trait `SliceIndex<[u8]>` is not implemented for `u32` + = help: the following other types implement trait `SliceIndex`: + `usize` implements `SliceIndex` + `usize` implements `SliceIndex<[T]>` + = note: required for `[u8]` to implement `Index` + +error[E0277]: the type `[u8]` cannot be indexed by `i32` + --> $DIR/indexing-integral-types.rs:19:18 + | +LL | s.as_bytes()[3i32]; + | ^^^^ slice indices are of type `usize` or ranges of `usize` + | + = help: the trait `SliceIndex<[u8]>` is not implemented for `i32` + = help: the following other types implement trait `SliceIndex`: + `usize` implements `SliceIndex` + `usize` implements `SliceIndex<[T]>` + = note: required for `[u8]` to implement `Index` + +error: aborting due to 8 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/inner-attrs-on-impl.rs b/tests/ui/inner-attrs-on-impl.rs deleted file mode 100644 index 1dce1cdd261..00000000000 --- a/tests/ui/inner-attrs-on-impl.rs +++ /dev/null @@ -1,24 +0,0 @@ -//@ run-pass - -struct Foo; - -impl Foo { - #![cfg(false)] - - fn method(&self) -> bool { false } -} - -impl Foo { - #![cfg(not(FALSE))] - - // check that we don't eat attributes too eagerly. - #[cfg(false)] - fn method(&self) -> bool { false } - - fn method(&self) -> bool { true } -} - - -pub fn main() { - assert!(Foo.method()); -} diff --git a/tests/ui/inner-module.rs b/tests/ui/inner-module.rs deleted file mode 100644 index 111f2cab857..00000000000 --- a/tests/ui/inner-module.rs +++ /dev/null @@ -1,10 +0,0 @@ -//@ run-pass - -mod inner { - pub mod inner2 { - pub fn hello() { println!("hello, modular world"); } - } - pub fn hello() { inner2::hello(); } -} - -pub fn main() { inner::hello(); inner::inner2::hello(); } diff --git a/tests/ui/inner-static-type-parameter.rs b/tests/ui/inner-static-type-parameter.rs deleted file mode 100644 index a1994e7529c..00000000000 --- a/tests/ui/inner-static-type-parameter.rs +++ /dev/null @@ -1,11 +0,0 @@ -// see #9186 - -enum Bar { What } //~ ERROR parameter `T` is never used - -fn foo() { - static a: Bar = Bar::What; -//~^ ERROR can't use generic parameters from outer item -} - -fn main() { -} diff --git a/tests/ui/inner-static-type-parameter.stderr b/tests/ui/inner-static-type-parameter.stderr deleted file mode 100644 index 88d33b44c59..00000000000 --- a/tests/ui/inner-static-type-parameter.stderr +++ /dev/null @@ -1,23 +0,0 @@ -error[E0401]: can't use generic parameters from outer item - --> $DIR/inner-static-type-parameter.rs:6:19 - | -LL | fn foo() { - | - type parameter from outer item -LL | static a: Bar = Bar::What; - | ^ use of generic parameter from outer item - | - = note: a `static` is a separate item from the item that contains it - -error[E0392]: type parameter `T` is never used - --> $DIR/inner-static-type-parameter.rs:3:10 - | -LL | enum Bar { What } - | ^ unused type parameter - | - = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` - = help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead - -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0392, E0401. -For more information about an error, try `rustc --explain E0392`. diff --git a/tests/ui/integral-indexing.rs b/tests/ui/integral-indexing.rs deleted file mode 100644 index e20553af8a2..00000000000 --- a/tests/ui/integral-indexing.rs +++ /dev/null @@ -1,16 +0,0 @@ -pub fn main() { - let v: Vec = vec![0, 1, 2, 3, 4, 5]; - let s: String = "abcdef".to_string(); - v[3_usize]; - v[3]; - v[3u8]; //~ ERROR the type `[isize]` cannot be indexed by `u8` - v[3i8]; //~ ERROR the type `[isize]` cannot be indexed by `i8` - v[3u32]; //~ ERROR the type `[isize]` cannot be indexed by `u32` - v[3i32]; //~ ERROR the type `[isize]` cannot be indexed by `i32` - s.as_bytes()[3_usize]; - s.as_bytes()[3]; - s.as_bytes()[3u8]; //~ ERROR the type `[u8]` cannot be indexed by `u8` - s.as_bytes()[3i8]; //~ ERROR the type `[u8]` cannot be indexed by `i8` - s.as_bytes()[3u32]; //~ ERROR the type `[u8]` cannot be indexed by `u32` - s.as_bytes()[3i32]; //~ ERROR the type `[u8]` cannot be indexed by `i32` -} diff --git a/tests/ui/integral-indexing.stderr b/tests/ui/integral-indexing.stderr deleted file mode 100644 index 26253e078cb..00000000000 --- a/tests/ui/integral-indexing.stderr +++ /dev/null @@ -1,99 +0,0 @@ -error[E0277]: the type `[isize]` cannot be indexed by `u8` - --> $DIR/integral-indexing.rs:6:7 - | -LL | v[3u8]; - | ^^^ slice indices are of type `usize` or ranges of `usize` - | - = help: the trait `SliceIndex<[isize]>` is not implemented for `u8` - = help: the following other types implement trait `SliceIndex`: - `usize` implements `SliceIndex` - `usize` implements `SliceIndex<[T]>` - = note: required for `Vec` to implement `Index` - -error[E0277]: the type `[isize]` cannot be indexed by `i8` - --> $DIR/integral-indexing.rs:7:7 - | -LL | v[3i8]; - | ^^^ slice indices are of type `usize` or ranges of `usize` - | - = help: the trait `SliceIndex<[isize]>` is not implemented for `i8` - = help: the following other types implement trait `SliceIndex`: - `usize` implements `SliceIndex` - `usize` implements `SliceIndex<[T]>` - = note: required for `Vec` to implement `Index` - -error[E0277]: the type `[isize]` cannot be indexed by `u32` - --> $DIR/integral-indexing.rs:8:7 - | -LL | v[3u32]; - | ^^^^ slice indices are of type `usize` or ranges of `usize` - | - = help: the trait `SliceIndex<[isize]>` is not implemented for `u32` - = help: the following other types implement trait `SliceIndex`: - `usize` implements `SliceIndex` - `usize` implements `SliceIndex<[T]>` - = note: required for `Vec` to implement `Index` - -error[E0277]: the type `[isize]` cannot be indexed by `i32` - --> $DIR/integral-indexing.rs:9:7 - | -LL | v[3i32]; - | ^^^^ slice indices are of type `usize` or ranges of `usize` - | - = help: the trait `SliceIndex<[isize]>` is not implemented for `i32` - = help: the following other types implement trait `SliceIndex`: - `usize` implements `SliceIndex` - `usize` implements `SliceIndex<[T]>` - = note: required for `Vec` to implement `Index` - -error[E0277]: the type `[u8]` cannot be indexed by `u8` - --> $DIR/integral-indexing.rs:12:18 - | -LL | s.as_bytes()[3u8]; - | ^^^ slice indices are of type `usize` or ranges of `usize` - | - = help: the trait `SliceIndex<[u8]>` is not implemented for `u8` - = help: the following other types implement trait `SliceIndex`: - `usize` implements `SliceIndex` - `usize` implements `SliceIndex<[T]>` - = note: required for `[u8]` to implement `Index` - -error[E0277]: the type `[u8]` cannot be indexed by `i8` - --> $DIR/integral-indexing.rs:13:18 - | -LL | s.as_bytes()[3i8]; - | ^^^ slice indices are of type `usize` or ranges of `usize` - | - = help: the trait `SliceIndex<[u8]>` is not implemented for `i8` - = help: the following other types implement trait `SliceIndex`: - `usize` implements `SliceIndex` - `usize` implements `SliceIndex<[T]>` - = note: required for `[u8]` to implement `Index` - -error[E0277]: the type `[u8]` cannot be indexed by `u32` - --> $DIR/integral-indexing.rs:14:18 - | -LL | s.as_bytes()[3u32]; - | ^^^^ slice indices are of type `usize` or ranges of `usize` - | - = help: the trait `SliceIndex<[u8]>` is not implemented for `u32` - = help: the following other types implement trait `SliceIndex`: - `usize` implements `SliceIndex` - `usize` implements `SliceIndex<[T]>` - = note: required for `[u8]` to implement `Index` - -error[E0277]: the type `[u8]` cannot be indexed by `i32` - --> $DIR/integral-indexing.rs:15:18 - | -LL | s.as_bytes()[3i32]; - | ^^^^ slice indices are of type `usize` or ranges of `usize` - | - = help: the trait `SliceIndex<[u8]>` is not implemented for `i32` - = help: the following other types implement trait `SliceIndex`: - `usize` implements `SliceIndex` - `usize` implements `SliceIndex<[T]>` - = note: required for `[u8]` to implement `Index` - -error: aborting due to 8 previous errors - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/integral-variable-unification-error.rs b/tests/ui/integral-variable-unification-error.rs deleted file mode 100644 index 8d1621321e8..00000000000 --- a/tests/ui/integral-variable-unification-error.rs +++ /dev/null @@ -1,8 +0,0 @@ -fn main() { - let mut x //~ NOTE expected due to the type of this binding - = - 2; //~ NOTE expected due to this value - x = 5.0; - //~^ ERROR mismatched types - //~| NOTE expected integer, found floating-point number -} diff --git a/tests/ui/integral-variable-unification-error.stderr b/tests/ui/integral-variable-unification-error.stderr deleted file mode 100644 index 1caa6042fd2..00000000000 --- a/tests/ui/integral-variable-unification-error.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/integral-variable-unification-error.rs:5:9 - | -LL | let mut x - | ----- expected due to the type of this binding -LL | = -LL | 2; - | - expected due to this value -LL | x = 5.0; - | ^^^ expected integer, found floating-point number - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/invalid_dispatch_from_dyn_impls.rs b/tests/ui/invalid_dispatch_from_dyn_impls.rs deleted file mode 100644 index b1d4b261bab..00000000000 --- a/tests/ui/invalid_dispatch_from_dyn_impls.rs +++ /dev/null @@ -1,55 +0,0 @@ -#![feature(unsize, dispatch_from_dyn)] - -use std::{ - ops::DispatchFromDyn, - marker::{Unsize, PhantomData}, -}; - -struct WrapperWithExtraField(T, i32); - -impl DispatchFromDyn> for WrapperWithExtraField -//~^ ERROR [E0378] -where - T: DispatchFromDyn, -{} - - -struct MultiplePointers{ - ptr1: *const T, - ptr2: *const T, -} - -impl DispatchFromDyn> for MultiplePointers -//~^ ERROR implementing `DispatchFromDyn` does not allow multiple fields to be coerced -where - T: Unsize, -{} - - -struct NothingToCoerce { - data: PhantomData, -} - -impl DispatchFromDyn> for NothingToCoerce {} -//~^ ERROR implementing `DispatchFromDyn` requires a field to be coerced - -#[repr(C)] -struct HasReprC(Box); - -impl DispatchFromDyn> for HasReprC -//~^ ERROR [E0378] -where - T: Unsize, -{} - -#[repr(align(64))] -struct OverAlignedZst; -struct OverAligned(Box, OverAlignedZst); - -impl DispatchFromDyn> for OverAligned -//~^ ERROR [E0378] - where - T: Unsize, -{} - -fn main() {} diff --git a/tests/ui/invalid_dispatch_from_dyn_impls.stderr b/tests/ui/invalid_dispatch_from_dyn_impls.stderr deleted file mode 100644 index 93ec6bbe089..00000000000 --- a/tests/ui/invalid_dispatch_from_dyn_impls.stderr +++ /dev/null @@ -1,60 +0,0 @@ -error[E0378]: the trait `DispatchFromDyn` may only be implemented for structs containing the field being coerced, ZST fields with 1 byte alignment that don't mention type/const generics, and nothing else - --> $DIR/invalid_dispatch_from_dyn_impls.rs:10:1 - | -LL | / impl DispatchFromDyn> for WrapperWithExtraField -LL | | -LL | | where -LL | | T: DispatchFromDyn, - | |__________________________^ - | - = note: extra field `1` of type `i32` is not allowed - -error[E0375]: implementing `DispatchFromDyn` does not allow multiple fields to be coerced - --> $DIR/invalid_dispatch_from_dyn_impls.rs:22:1 - | -LL | / impl DispatchFromDyn> for MultiplePointers -LL | | -LL | | where -LL | | T: Unsize, - | |_________________^ - | -note: the trait `DispatchFromDyn` may only be implemented when a single field is being coerced - --> $DIR/invalid_dispatch_from_dyn_impls.rs:18:5 - | -LL | ptr1: *const T, - | ^^^^^^^^^^^^^^ -LL | ptr2: *const T, - | ^^^^^^^^^^^^^^ - -error[E0374]: implementing `DispatchFromDyn` requires a field to be coerced - --> $DIR/invalid_dispatch_from_dyn_impls.rs:33:1 - | -LL | impl DispatchFromDyn> for NothingToCoerce {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: expected a single field to be coerced, none found - -error[E0378]: structs implementing `DispatchFromDyn` may not have `#[repr(packed)]` or `#[repr(C)]` - --> $DIR/invalid_dispatch_from_dyn_impls.rs:39:1 - | -LL | / impl DispatchFromDyn> for HasReprC -LL | | -LL | | where -LL | | T: Unsize, - | |_________________^ - -error[E0378]: the trait `DispatchFromDyn` may only be implemented for structs containing the field being coerced, ZST fields with 1 byte alignment that don't mention type/const generics, and nothing else - --> $DIR/invalid_dispatch_from_dyn_impls.rs:49:1 - | -LL | / impl DispatchFromDyn> for OverAligned -LL | | -LL | | where -LL | | T: Unsize, - | |_____________________^ - | - = note: extra field `1` of type `OverAlignedZst` is not allowed - -error: aborting due to 5 previous errors - -Some errors have detailed explanations: E0374, E0375, E0378. -For more information about an error, try `rustc --explain E0374`. diff --git a/tests/ui/issue-11881.rs b/tests/ui/issue-11881.rs deleted file mode 100644 index 1abe0797203..00000000000 --- a/tests/ui/issue-11881.rs +++ /dev/null @@ -1,91 +0,0 @@ -//@ run-pass - -#![allow(unused_must_use)] -#![allow(dead_code)] -#![allow(unused_imports)] - -use std::fmt; -use std::io::prelude::*; -use std::io::Cursor; -use std::slice; -use std::marker::PhantomData; - -trait Encoder { - type Error; -} - -trait Encodable { - fn encode(&self, s: &mut S) -> Result<(), S::Error>; -} - -struct JsonEncoder<'a>(PhantomData<&'a mut ()>); - -impl Encoder for JsonEncoder<'_> { - type Error = (); -} - -struct AsJson<'a, T> { - inner: &'a T, -} - -impl<'a, T: for<'r> Encodable>> fmt::Display for AsJson<'a, T> { - /// Encodes a json value into a string - fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { - Ok(()) - } -} - -fn as_json(t: &T) -> AsJson<'_, T> { - AsJson { inner: t } -} - -struct OpaqueEncoder(Vec); - -impl Encoder for OpaqueEncoder { - type Error = (); -} - - -struct Foo { - baz: bool, -} - -impl Encodable for Foo { - fn encode(&self, _s: &mut S) -> Result<(), S::Error> { - Ok(()) - } -} - -struct Bar { - froboz: usize, -} - -impl Encodable for Bar { - fn encode(&self, _s: &mut S) -> Result<(), S::Error> { - Ok(()) - } -} - -enum WireProtocol { - JSON, - Opaque, - // ... -} - -fn encode_json Encodable>>(val: &T, wr: &mut Cursor>) { - write!(wr, "{}", as_json(val)); -} - -fn encode_opaque>(val: &T, wr: Vec) { - let mut encoder = OpaqueEncoder(wr); - val.encode(&mut encoder); -} - -pub fn main() { - let target = Foo { baz: false }; - let proto = WireProtocol::JSON; - match proto { - WireProtocol::JSON => encode_json(&target, &mut Cursor::new(Vec::new())), - WireProtocol::Opaque => encode_opaque(&target, Vec::new()), - } -} diff --git a/tests/ui/mismatched_types/int-float-type-mismatch.rs b/tests/ui/mismatched_types/int-float-type-mismatch.rs new file mode 100644 index 00000000000..b45d02730d9 --- /dev/null +++ b/tests/ui/mismatched_types/int-float-type-mismatch.rs @@ -0,0 +1,11 @@ +//! Check that a type mismatch error is reported when trying +//! to unify a {float} value assignment to an {integer} variable. + +fn main() { + let mut x //~ NOTE expected due to the type of this binding + = + 2; //~ NOTE expected due to this value + x = 5.0; + //~^ ERROR mismatched types + //~| NOTE expected integer, found floating-point number +} diff --git a/tests/ui/mismatched_types/int-float-type-mismatch.stderr b/tests/ui/mismatched_types/int-float-type-mismatch.stderr new file mode 100644 index 00000000000..43b8609a49d --- /dev/null +++ b/tests/ui/mismatched_types/int-float-type-mismatch.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/int-float-type-mismatch.rs:8:9 + | +LL | let mut x + | ----- expected due to the type of this binding +LL | = +LL | 2; + | - expected due to this value +LL | x = 5.0; + | ^^^ expected integer, found floating-point number + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/modules/nested-modules-basic.rs b/tests/ui/modules/nested-modules-basic.rs new file mode 100644 index 00000000000..12eccec2808 --- /dev/null +++ b/tests/ui/modules/nested-modules-basic.rs @@ -0,0 +1,19 @@ +//! Basic test for nested module functionality and path resolution + +//@ run-pass + +mod inner { + pub mod inner2 { + pub fn hello() { + println!("hello, modular world"); + } + } + pub fn hello() { + inner2::hello(); + } +} + +pub fn main() { + inner::hello(); + inner::inner2::hello(); +} diff --git a/tests/ui/statics/static-generic-param-soundness.rs b/tests/ui/statics/static-generic-param-soundness.rs new file mode 100644 index 00000000000..aabcca514d3 --- /dev/null +++ b/tests/ui/statics/static-generic-param-soundness.rs @@ -0,0 +1,20 @@ +//! Originally, inner statics in generic functions were generated only once, causing the same +//! static to be shared across all generic instantiations. This created a soundness hole where +//! different types could be coerced through thread-local storage in safe code. +//! +//! This test checks that generic parameters from outer scopes cannot be used in inner statics, +//! preventing this soundness issue. +//! +//! See https://github.com/rust-lang/rust/issues/9186 + +enum Bar { + //~^ ERROR parameter `T` is never used + What, +} + +fn foo() { + static a: Bar = Bar::What; + //~^ ERROR can't use generic parameters from outer item +} + +fn main() {} diff --git a/tests/ui/statics/static-generic-param-soundness.stderr b/tests/ui/statics/static-generic-param-soundness.stderr new file mode 100644 index 00000000000..47554c7fcb0 --- /dev/null +++ b/tests/ui/statics/static-generic-param-soundness.stderr @@ -0,0 +1,23 @@ +error[E0401]: can't use generic parameters from outer item + --> $DIR/static-generic-param-soundness.rs:16:19 + | +LL | fn foo() { + | - type parameter from outer item +LL | static a: Bar = Bar::What; + | ^ use of generic parameter from outer item + | + = note: a `static` is a separate item from the item that contains it + +error[E0392]: type parameter `T` is never used + --> $DIR/static-generic-param-soundness.rs:10:10 + | +LL | enum Bar { + | ^ unused type parameter + | + = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0392, E0401. +For more information about an error, try `rustc --explain E0392`. diff --git a/tests/ui/traits/dispatch-from-dyn-invalid-impls.rs b/tests/ui/traits/dispatch-from-dyn-invalid-impls.rs new file mode 100644 index 00000000000..f5f66ca69cf --- /dev/null +++ b/tests/ui/traits/dispatch-from-dyn-invalid-impls.rs @@ -0,0 +1,71 @@ +//! Test various invalid implementations of DispatchFromDyn trait. +//! +//! DispatchFromDyn is a special trait used by the compiler for dyn-compatible dynamic dispatch. +//! This checks that the compiler correctly rejects invalid implementations: +//! - Structs with extra non-coercible fields +//! - Structs with multiple pointer fields +//! - Structs with no coercible fields +//! - Structs with repr(C) or other incompatible representations +//! - Structs with over-aligned fields + +#![feature(unsize, dispatch_from_dyn)] + +use std::marker::{PhantomData, Unsize}; +use std::ops::DispatchFromDyn; + +// Extra field prevents DispatchFromDyn +struct WrapperWithExtraField(T, i32); + +impl DispatchFromDyn> for WrapperWithExtraField +//~^ ERROR [E0378] +where + T: DispatchFromDyn +{ +} + +// Multiple pointer fields create ambiguous coercion +struct MultiplePointers { + ptr1: *const T, + ptr2: *const T, +} + +impl DispatchFromDyn> for MultiplePointers +//~^ ERROR implementing `DispatchFromDyn` does not allow multiple fields to be coerced +where + T: Unsize +{ +} + +// No coercible fields (only PhantomData) +struct NothingToCoerce { + data: PhantomData, +} + +impl DispatchFromDyn> for NothingToCoerce {} +//~^ ERROR implementing `DispatchFromDyn` requires a field to be coerced + +// repr(C) is incompatible with DispatchFromDyn +#[repr(C)] +struct HasReprC(Box); + +impl DispatchFromDyn> for HasReprC +//~^ ERROR [E0378] +where + T: Unsize +{ +} + +// Over-aligned fields are incompatible +#[repr(align(64))] +struct OverAlignedZst; + +struct OverAligned(Box, OverAlignedZst); + +impl DispatchFromDyn> for OverAligned +//~^ ERROR [E0378] +where + T: Unsize +{ +} + +fn main() {} diff --git a/tests/ui/traits/dispatch-from-dyn-invalid-impls.stderr b/tests/ui/traits/dispatch-from-dyn-invalid-impls.stderr new file mode 100644 index 00000000000..676da0ce81f --- /dev/null +++ b/tests/ui/traits/dispatch-from-dyn-invalid-impls.stderr @@ -0,0 +1,60 @@ +error[E0378]: the trait `DispatchFromDyn` may only be implemented for structs containing the field being coerced, ZST fields with 1 byte alignment that don't mention type/const generics, and nothing else + --> $DIR/dispatch-from-dyn-invalid-impls.rs:19:1 + | +LL | / impl DispatchFromDyn> for WrapperWithExtraField +LL | | +LL | | where +LL | | T: DispatchFromDyn + | |_________________________^ + | + = note: extra field `1` of type `i32` is not allowed + +error[E0375]: implementing `DispatchFromDyn` does not allow multiple fields to be coerced + --> $DIR/dispatch-from-dyn-invalid-impls.rs:32:1 + | +LL | / impl DispatchFromDyn> for MultiplePointers +LL | | +LL | | where +LL | | T: Unsize + | |________________^ + | +note: the trait `DispatchFromDyn` may only be implemented when a single field is being coerced + --> $DIR/dispatch-from-dyn-invalid-impls.rs:28:5 + | +LL | ptr1: *const T, + | ^^^^^^^^^^^^^^ +LL | ptr2: *const T, + | ^^^^^^^^^^^^^^ + +error[E0374]: implementing `DispatchFromDyn` requires a field to be coerced + --> $DIR/dispatch-from-dyn-invalid-impls.rs:44:1 + | +LL | impl DispatchFromDyn> for NothingToCoerce {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: expected a single field to be coerced, none found + +error[E0378]: structs implementing `DispatchFromDyn` may not have `#[repr(packed)]` or `#[repr(C)]` + --> $DIR/dispatch-from-dyn-invalid-impls.rs:51:1 + | +LL | / impl DispatchFromDyn> for HasReprC +LL | | +LL | | where +LL | | T: Unsize + | |________________^ + +error[E0378]: the trait `DispatchFromDyn` may only be implemented for structs containing the field being coerced, ZST fields with 1 byte alignment that don't mention type/const generics, and nothing else + --> $DIR/dispatch-from-dyn-invalid-impls.rs:64:1 + | +LL | / impl DispatchFromDyn> for OverAligned +LL | | +LL | | where +LL | | T: Unsize + | |________________^ + | + = note: extra field `1` of type `OverAlignedZst` is not allowed + +error: aborting due to 5 previous errors + +Some errors have detailed explanations: E0374, E0375, E0378. +For more information about an error, try `rustc --explain E0374`. diff --git a/tests/ui/traits/encoder-trait-bounds-regression.rs b/tests/ui/traits/encoder-trait-bounds-regression.rs new file mode 100644 index 00000000000..292b921cdf7 --- /dev/null +++ b/tests/ui/traits/encoder-trait-bounds-regression.rs @@ -0,0 +1,98 @@ +//! Regression test for issue #11881 +//! +//! Originally, the compiler would ICE when trying to parameterize on certain encoder types +//! due to issues with higher-ranked trait bounds and lifetime inference. This test checks +//! that various encoder patterns work correctly: +//! - Generic encoders with associated error types +//! - Higher-ranked trait bounds (for<'r> Encodable>) +//! - Multiple encoder implementations for the same type +//! - Polymorphic encoding functions + +//@ run-pass + +#![allow(unused_must_use)] +#![allow(dead_code)] +#![allow(unused_imports)] + +use std::io::Cursor; +use std::io::prelude::*; +use std::marker::PhantomData; +use std::{fmt, slice}; + +trait Encoder { + type Error; +} + +trait Encodable { + fn encode(&self, s: &mut S) -> Result<(), S::Error>; +} + +struct JsonEncoder<'a>(PhantomData<&'a mut ()>); + +impl Encoder for JsonEncoder<'_> { + type Error = (); +} + +struct AsJson<'a, T> { + inner: &'a T, +} + +impl<'a, T: for<'r> Encodable>> fmt::Display for AsJson<'a, T> { + /// Encodes a json value into a string + fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { + Ok(()) + } +} + +fn as_json(t: &T) -> AsJson<'_, T> { + AsJson { inner: t } +} + +struct OpaqueEncoder(Vec); + +impl Encoder for OpaqueEncoder { + type Error = (); +} + +struct Foo { + baz: bool, +} + +impl Encodable for Foo { + fn encode(&self, _s: &mut S) -> Result<(), S::Error> { + Ok(()) + } +} + +struct Bar { + froboz: usize, +} + +impl Encodable for Bar { + fn encode(&self, _s: &mut S) -> Result<(), S::Error> { + Ok(()) + } +} + +enum WireProtocol { + JSON, + Opaque, +} + +fn encode_json Encodable>>(val: &T, wr: &mut Cursor>) { + write!(wr, "{}", as_json(val)); +} + +fn encode_opaque>(val: &T, wr: Vec) { + let mut encoder = OpaqueEncoder(wr); + val.encode(&mut encoder); +} + +pub fn main() { + let target = Foo { baz: false }; + let proto = WireProtocol::JSON; + match proto { + WireProtocol::JSON => encode_json(&target, &mut Cursor::new(Vec::new())), + WireProtocol::Opaque => encode_opaque(&target, Vec::new()), + } +} -- cgit 1.4.1-3-g733a5 From a38c78c4616d6032af37739fad903e842a52e290 Mon Sep 17 00:00:00 2001 From: Kivooeo Date: Sun, 29 Jun 2025 17:39:08 +0500 Subject: moved tests --- tests/ui/auxiliary/msvc-data-only-lib.rs | 5 ---- tests/ui/codegen/mono-respects-abi-alignment.rs | 35 ++++++++++++++++++++++ tests/ui/codegen/msvc-opt-level-z-no-corruption.rs | 31 +++++++++++++++++++ .../auxiliary/msvc-static-data-import-lib.rs | 5 ++++ tests/ui/linkage-attr/msvc-static-data-import.rs | 8 +++++ tests/ui/monomorphize-abi-alignment.rs | 35 ---------------------- tests/ui/msvc-data-only.rs | 8 ----- tests/ui/msvc-opt-minsize.rs | 31 ------------------- tests/ui/multibyte.rs | 7 ----- tests/ui/multiline-comment.rs | 6 ---- tests/ui/parser/multiline-comments-basic.rs | 6 ++++ tests/ui/parser/unicode-multibyte-chars-no-ice.rs | 7 +++++ 12 files changed, 92 insertions(+), 92 deletions(-) delete mode 100644 tests/ui/auxiliary/msvc-data-only-lib.rs create mode 100644 tests/ui/codegen/mono-respects-abi-alignment.rs create mode 100644 tests/ui/codegen/msvc-opt-level-z-no-corruption.rs create mode 100644 tests/ui/linkage-attr/auxiliary/msvc-static-data-import-lib.rs create mode 100644 tests/ui/linkage-attr/msvc-static-data-import.rs delete mode 100644 tests/ui/monomorphize-abi-alignment.rs delete mode 100644 tests/ui/msvc-data-only.rs delete mode 100644 tests/ui/msvc-opt-minsize.rs delete mode 100644 tests/ui/multibyte.rs delete mode 100644 tests/ui/multiline-comment.rs create mode 100644 tests/ui/parser/multiline-comments-basic.rs create mode 100644 tests/ui/parser/unicode-multibyte-chars-no-ice.rs (limited to 'tests') diff --git a/tests/ui/auxiliary/msvc-data-only-lib.rs b/tests/ui/auxiliary/msvc-data-only-lib.rs deleted file mode 100644 index b8a8f905e8b..00000000000 --- a/tests/ui/auxiliary/msvc-data-only-lib.rs +++ /dev/null @@ -1,5 +0,0 @@ -//@ no-prefer-dynamic - -#![crate_type = "rlib"] - -pub static FOO: i32 = 42; diff --git a/tests/ui/codegen/mono-respects-abi-alignment.rs b/tests/ui/codegen/mono-respects-abi-alignment.rs new file mode 100644 index 00000000000..62df1aca357 --- /dev/null +++ b/tests/ui/codegen/mono-respects-abi-alignment.rs @@ -0,0 +1,35 @@ +//@ run-pass + +#![allow(non_upper_case_globals)] +#![allow(dead_code)] +/*! + * On x86_64-linux-gnu and possibly other platforms, structs get 8-byte "preferred" alignment, + * but their "ABI" alignment (i.e., what actually matters for data layout) is the largest alignment + * of any field. (Also, `u64` has 8-byte ABI alignment; this is not always true). + * + * On such platforms, if monomorphize uses the "preferred" alignment, then it will unify + * `A` and `B`, even though `S` and `S` have the field `t` at different offsets, + * and apply the wrong instance of the method `unwrap`. + */ + +#[derive(Copy, Clone)] +struct S { i:u8, t:T } + +impl S { + fn unwrap(self) -> T { + self.t + } +} + +#[derive(Copy, Clone, PartialEq, Debug)] +struct A((u32, u32)); + +#[derive(Copy, Clone, PartialEq, Debug)] +struct B(u64); + +pub fn main() { + static Ca: S = S { i: 0, t: A((13, 104)) }; + static Cb: S = S { i: 0, t: B(31337) }; + assert_eq!(Ca.unwrap(), A((13, 104))); + assert_eq!(Cb.unwrap(), B(31337)); +} diff --git a/tests/ui/codegen/msvc-opt-level-z-no-corruption.rs b/tests/ui/codegen/msvc-opt-level-z-no-corruption.rs new file mode 100644 index 00000000000..c1be168a05d --- /dev/null +++ b/tests/ui/codegen/msvc-opt-level-z-no-corruption.rs @@ -0,0 +1,31 @@ +// A previously outdated version of LLVM caused compilation failures on Windows +// specifically with optimization level `z`. After the update to a more recent LLVM +// version, this test checks that compilation and execution both succeed. +// See https://github.com/rust-lang/rust/issues/45034 + +//@ ignore-cross-compile +// Reason: the compiled binary is executed +//@ only-windows +// Reason: the observed bug only occurs on Windows +//@ run-pass +//@ compile-flags: -C opt-level=z + +#![feature(test)] +extern crate test; + +fn foo(x: i32, y: i32) -> i64 { + (x + y) as i64 +} + +#[inline(never)] +fn bar() { + let _f = Box::new(0); + // This call used to trigger an LLVM bug in opt-level z where the base + // pointer gets corrupted, see issue #45034 + let y: fn(i32, i32) -> i64 = test::black_box(foo); + test::black_box(y(1, 2)); +} + +fn main() { + bar(); +} diff --git a/tests/ui/linkage-attr/auxiliary/msvc-static-data-import-lib.rs b/tests/ui/linkage-attr/auxiliary/msvc-static-data-import-lib.rs new file mode 100644 index 00000000000..b8a8f905e8b --- /dev/null +++ b/tests/ui/linkage-attr/auxiliary/msvc-static-data-import-lib.rs @@ -0,0 +1,5 @@ +//@ no-prefer-dynamic + +#![crate_type = "rlib"] + +pub static FOO: i32 = 42; diff --git a/tests/ui/linkage-attr/msvc-static-data-import.rs b/tests/ui/linkage-attr/msvc-static-data-import.rs new file mode 100644 index 00000000000..15d799085fe --- /dev/null +++ b/tests/ui/linkage-attr/msvc-static-data-import.rs @@ -0,0 +1,8 @@ +//@ run-pass +//@ aux-build:msvc-data-only-lib.rs + +extern crate msvc_data_only_lib; + +fn main() { + println!("The answer is {} !", msvc_data_only_lib::FOO); +} diff --git a/tests/ui/monomorphize-abi-alignment.rs b/tests/ui/monomorphize-abi-alignment.rs deleted file mode 100644 index 62df1aca357..00000000000 --- a/tests/ui/monomorphize-abi-alignment.rs +++ /dev/null @@ -1,35 +0,0 @@ -//@ run-pass - -#![allow(non_upper_case_globals)] -#![allow(dead_code)] -/*! - * On x86_64-linux-gnu and possibly other platforms, structs get 8-byte "preferred" alignment, - * but their "ABI" alignment (i.e., what actually matters for data layout) is the largest alignment - * of any field. (Also, `u64` has 8-byte ABI alignment; this is not always true). - * - * On such platforms, if monomorphize uses the "preferred" alignment, then it will unify - * `A` and `B`, even though `S` and `S` have the field `t` at different offsets, - * and apply the wrong instance of the method `unwrap`. - */ - -#[derive(Copy, Clone)] -struct S { i:u8, t:T } - -impl S { - fn unwrap(self) -> T { - self.t - } -} - -#[derive(Copy, Clone, PartialEq, Debug)] -struct A((u32, u32)); - -#[derive(Copy, Clone, PartialEq, Debug)] -struct B(u64); - -pub fn main() { - static Ca: S = S { i: 0, t: A((13, 104)) }; - static Cb: S = S { i: 0, t: B(31337) }; - assert_eq!(Ca.unwrap(), A((13, 104))); - assert_eq!(Cb.unwrap(), B(31337)); -} diff --git a/tests/ui/msvc-data-only.rs b/tests/ui/msvc-data-only.rs deleted file mode 100644 index 15d799085fe..00000000000 --- a/tests/ui/msvc-data-only.rs +++ /dev/null @@ -1,8 +0,0 @@ -//@ run-pass -//@ aux-build:msvc-data-only-lib.rs - -extern crate msvc_data_only_lib; - -fn main() { - println!("The answer is {} !", msvc_data_only_lib::FOO); -} diff --git a/tests/ui/msvc-opt-minsize.rs b/tests/ui/msvc-opt-minsize.rs deleted file mode 100644 index c1be168a05d..00000000000 --- a/tests/ui/msvc-opt-minsize.rs +++ /dev/null @@ -1,31 +0,0 @@ -// A previously outdated version of LLVM caused compilation failures on Windows -// specifically with optimization level `z`. After the update to a more recent LLVM -// version, this test checks that compilation and execution both succeed. -// See https://github.com/rust-lang/rust/issues/45034 - -//@ ignore-cross-compile -// Reason: the compiled binary is executed -//@ only-windows -// Reason: the observed bug only occurs on Windows -//@ run-pass -//@ compile-flags: -C opt-level=z - -#![feature(test)] -extern crate test; - -fn foo(x: i32, y: i32) -> i64 { - (x + y) as i64 -} - -#[inline(never)] -fn bar() { - let _f = Box::new(0); - // This call used to trigger an LLVM bug in opt-level z where the base - // pointer gets corrupted, see issue #45034 - let y: fn(i32, i32) -> i64 = test::black_box(foo); - test::black_box(y(1, 2)); -} - -fn main() { - bar(); -} diff --git a/tests/ui/multibyte.rs b/tests/ui/multibyte.rs deleted file mode 100644 index d585a791fb9..00000000000 --- a/tests/ui/multibyte.rs +++ /dev/null @@ -1,7 +0,0 @@ -//@ run-pass -// - -// Test that multibyte characters don't crash the compiler -pub fn main() { - println!("마이너스 사인이 없으면"); -} diff --git a/tests/ui/multiline-comment.rs b/tests/ui/multiline-comment.rs deleted file mode 100644 index 98174882032..00000000000 --- a/tests/ui/multiline-comment.rs +++ /dev/null @@ -1,6 +0,0 @@ -//@ run-pass - -/* - * This is a multi-line oldcomment. - */ -pub fn main() { } diff --git a/tests/ui/parser/multiline-comments-basic.rs b/tests/ui/parser/multiline-comments-basic.rs new file mode 100644 index 00000000000..98174882032 --- /dev/null +++ b/tests/ui/parser/multiline-comments-basic.rs @@ -0,0 +1,6 @@ +//@ run-pass + +/* + * This is a multi-line oldcomment. + */ +pub fn main() { } diff --git a/tests/ui/parser/unicode-multibyte-chars-no-ice.rs b/tests/ui/parser/unicode-multibyte-chars-no-ice.rs new file mode 100644 index 00000000000..d585a791fb9 --- /dev/null +++ b/tests/ui/parser/unicode-multibyte-chars-no-ice.rs @@ -0,0 +1,7 @@ +//@ run-pass +// + +// Test that multibyte characters don't crash the compiler +pub fn main() { + println!("마이너스 사인이 없으면"); +} -- cgit 1.4.1-3-g733a5 From 54cec0cf5a1f03e295f483d047a0feae203e715b Mon Sep 17 00:00:00 2001 From: Anne Stijns Date: Sun, 29 Jun 2025 15:37:54 +0200 Subject: Port #[link_section] to the new attribute parsing infrastructure --- .../rustc_attr_data_structures/src/attributes.rs | 3 +++ .../src/encode_cross_crate.rs | 1 + compiler/rustc_attr_parsing/messages.ftl | 2 ++ .../src/attributes/link_attrs.rs | 31 +++++++++++++++++++++- compiler/rustc_attr_parsing/src/context.rs | 3 ++- .../rustc_attr_parsing/src/session_diagnostics.rs | 7 +++++ compiler/rustc_codegen_ssa/src/codegen_attrs.rs | 13 +++------ compiler/rustc_passes/src/check_attr.rs | 10 ++++--- src/librustdoc/clean/types.rs | 5 +++- tests/rustdoc-json/attrs/link_section_2021.rs | 6 +++++ tests/rustdoc-json/attrs/link_section_2024.rs | 9 +++++++ .../issue-43106-gating-of-builtin-attrs.stderr | 16 +++++------ tests/ui/lint/unused/unused-attr-duplicate.rs | 6 +++++ tests/ui/lint/unused/unused-attr-duplicate.stderr | 15 ++++++++++- 14 files changed, 101 insertions(+), 26 deletions(-) create mode 100644 tests/rustdoc-json/attrs/link_section_2021.rs create mode 100644 tests/rustdoc-json/attrs/link_section_2024.rs (limited to 'tests') diff --git a/compiler/rustc_attr_data_structures/src/attributes.rs b/compiler/rustc_attr_data_structures/src/attributes.rs index 5eb1931152d..85a4f1c6765 100644 --- a/compiler/rustc_attr_data_structures/src/attributes.rs +++ b/compiler/rustc_attr_data_structures/src/attributes.rs @@ -256,6 +256,9 @@ pub enum AttributeKind { /// Represents `#[link_name]`. LinkName { name: Symbol, span: Span }, + /// Represents [`#[link_section]`](https://doc.rust-lang.org/reference/abi.html#the-link_section-attribute) + LinkSection { name: Symbol, span: Span }, + /// Represents `#[loop_match]`. LoopMatch(Span), diff --git a/compiler/rustc_attr_data_structures/src/encode_cross_crate.rs b/compiler/rustc_attr_data_structures/src/encode_cross_crate.rs index 0d6ee77c718..3c55f62cc80 100644 --- a/compiler/rustc_attr_data_structures/src/encode_cross_crate.rs +++ b/compiler/rustc_attr_data_structures/src/encode_cross_crate.rs @@ -24,6 +24,7 @@ impl AttributeKind { DocComment { .. } => Yes, ExportName { .. } => Yes, Inline(..) => No, + LinkSection { .. } => No, MacroTransparency(..) => Yes, Repr(..) => No, Stability { .. } => Yes, diff --git a/compiler/rustc_attr_parsing/messages.ftl b/compiler/rustc_attr_parsing/messages.ftl index 39652335f55..9ad46a83f50 100644 --- a/compiler/rustc_attr_parsing/messages.ftl +++ b/compiler/rustc_attr_parsing/messages.ftl @@ -99,6 +99,8 @@ attr_parsing_non_ident_feature = attr_parsing_null_on_export = `export_name` may not contain null characters +attr_parsing_null_on_link_section = `link_section` may not contain null characters + attr_parsing_repr_ident = meta item in `repr` must be an identifier diff --git a/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs index 740222178ed..e298053ab76 100644 --- a/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs @@ -1,11 +1,12 @@ use rustc_attr_data_structures::AttributeKind; -use rustc_attr_data_structures::AttributeKind::LinkName; +use rustc_attr_data_structures::AttributeKind::{LinkName, LinkSection}; use rustc_feature::{AttributeTemplate, template}; use rustc_span::{Symbol, sym}; use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser}; use crate::context::{AcceptContext, Stage}; use crate::parser::ArgParser; +use crate::session_diagnostics::NullOnLinkSection; pub(crate) struct LinkNameParser; @@ -28,3 +29,31 @@ impl SingleAttributeParser for LinkNameParser { Some(LinkName { name, span: cx.attr_span }) } } + +pub(crate) struct LinkSectionParser; + +impl SingleAttributeParser for LinkSectionParser { + const PATH: &[Symbol] = &[sym::link_section]; + const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst; + const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError; + const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name"); + + fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option { + let Some(nv) = args.name_value() else { + cx.expected_name_value(cx.attr_span, None); + return None; + }; + let Some(name) = nv.value_as_str() else { + cx.expected_string_literal(nv.value_span, Some(nv.value_as_lit())); + return None; + }; + if name.as_str().contains('\0') { + // `#[link_section = ...]` will be converted to a null-terminated string, + // so it may not contain any null characters. + cx.emit_err(NullOnLinkSection { span: cx.attr_span }); + return None; + } + + Some(LinkSection { name, span: cx.attr_span }) + } +} diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index 1ac41b9c7e8..eee6d860550 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -22,7 +22,7 @@ use crate::attributes::codegen_attrs::{ use crate::attributes::confusables::ConfusablesParser; use crate::attributes::deprecation::DeprecationParser; use crate::attributes::inline::{InlineParser, RustcForceInlineParser}; -use crate::attributes::link_attrs::LinkNameParser; +use crate::attributes::link_attrs::{LinkNameParser, LinkSectionParser}; use crate::attributes::lint_helpers::{AsPtrParser, PubTransparentParser}; use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser}; use crate::attributes::must_use::MustUseParser; @@ -123,6 +123,7 @@ attribute_parsers!( Single, Single, Single, + Single, Single, Single, Single, diff --git a/compiler/rustc_attr_parsing/src/session_diagnostics.rs b/compiler/rustc_attr_parsing/src/session_diagnostics.rs index 7cfce579979..53aafaa714f 100644 --- a/compiler/rustc_attr_parsing/src/session_diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/session_diagnostics.rs @@ -452,6 +452,13 @@ pub(crate) struct NullOnExport { pub span: Span, } +#[derive(Diagnostic)] +#[diag(attr_parsing_null_on_link_section, code = E0648)] +pub(crate) struct NullOnLinkSection { + #[primary_span] + pub span: Span, +} + #[derive(Diagnostic)] #[diag(attr_parsing_stability_outside_std, code = E0734)] pub(crate) struct StabilityOutsideStd { diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index 7680f8e1074..a87c26f43f9 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -124,6 +124,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { AttributeKind::Naked(_) => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NAKED, AttributeKind::Align { align, .. } => codegen_fn_attrs.alignment = Some(*align), AttributeKind::LinkName { name, .. } => codegen_fn_attrs.link_name = Some(*name), + AttributeKind::LinkSection { name, .. } => { + codegen_fn_attrs.link_section = Some(*name) + } AttributeKind::NoMangle(attr_span) => { if tcx.opt_item_name(did.to_def_id()).is_some() { codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE; @@ -253,16 +256,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { } } } - sym::link_section => { - if let Some(val) = attr.value_str() { - if val.as_str().bytes().any(|b| b == 0) { - let msg = format!("illegal null byte in link_section value: `{val}`"); - tcx.dcx().span_err(attr.span(), msg); - } else { - codegen_fn_attrs.link_section = Some(val); - } - } - } sym::link_ordinal => { link_ordinal_span = Some(attr.span()); if let ordinal @ Some(_) = check_link_ordinal(tcx, attr) { diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index ae486a58062..34c76bd3f27 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -177,6 +177,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> { Attribute::Parsed(AttributeKind::Align { align, span: repr_span }) => { self.check_align(span, target, *align, *repr_span) } + Attribute::Parsed(AttributeKind::LinkSection { span: attr_span, .. }) => { + self.check_link_section(hir_id, *attr_span, span, target) + } Attribute::Parsed(AttributeKind::Naked(attr_span)) => { self.check_naked(hir_id, *attr_span, span, target) } @@ -286,7 +289,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { [sym::ffi_const, ..] => self.check_ffi_const(attr.span(), target), [sym::link_ordinal, ..] => self.check_link_ordinal(attr, span, target), [sym::link, ..] => self.check_link(hir_id, attr, span, target), - [sym::link_section, ..] => self.check_link_section(hir_id, attr, span, target), [sym::macro_use, ..] | [sym::macro_escape, ..] => { self.check_macro_use(hir_id, attr, target) } @@ -1831,7 +1833,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } /// Checks if `#[link_section]` is applied to a function or static. - fn check_link_section(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) { + fn check_link_section(&self, hir_id: HirId, attr_span: Span, span: Span, target: Target) { match target { Target::Static | Target::Fn | Target::Method(..) => {} // FIXME(#80564): We permit struct fields, match arms and macro defs to have an @@ -1839,7 +1841,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { // erroneously allowed it and some crates used it accidentally, to be compatible // with crates depending on them, we can't throw an error here. Target::Field | Target::Arm | Target::MacroDef => { - self.inline_attr_str_error_with_macro_def(hir_id, attr.span(), "link_section"); + self.inline_attr_str_error_with_macro_def(hir_id, attr_span, "link_section"); } _ => { // FIXME: #[link_section] was previously allowed on non-functions/statics and some @@ -1847,7 +1849,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { self.tcx.emit_node_span_lint( UNUSED_ATTRIBUTES, hir_id, - attr.span(), + attr_span, errors::LinkSection { span }, ); } diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 3cac55493f0..600c564d714 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -753,9 +753,12 @@ impl Item { .other_attrs .iter() .filter_map(|attr| { + if let hir::Attribute::Parsed(AttributeKind::LinkSection { name, .. }) = attr { + Some(format!("#[link_section = \"{name}\"]")) + } // NoMangle is special cased, as it appears in HTML output, and we want to show it in source form, not HIR printing. // It is also used by cargo-semver-checks. - if let hir::Attribute::Parsed(AttributeKind::NoMangle(..)) = attr { + else if let hir::Attribute::Parsed(AttributeKind::NoMangle(..)) = attr { Some("#[no_mangle]".to_string()) } else if let hir::Attribute::Parsed(AttributeKind::ExportName { name, .. }) = attr { diff --git a/tests/rustdoc-json/attrs/link_section_2021.rs b/tests/rustdoc-json/attrs/link_section_2021.rs new file mode 100644 index 00000000000..a1312f4210b --- /dev/null +++ b/tests/rustdoc-json/attrs/link_section_2021.rs @@ -0,0 +1,6 @@ +//@ edition: 2021 +#![no_std] + +//@ is "$.index[?(@.name=='example')].attrs" '["#[link_section = \".text\"]"]' +#[link_section = ".text"] +pub extern "C" fn example() {} diff --git a/tests/rustdoc-json/attrs/link_section_2024.rs b/tests/rustdoc-json/attrs/link_section_2024.rs new file mode 100644 index 00000000000..edb028451a8 --- /dev/null +++ b/tests/rustdoc-json/attrs/link_section_2024.rs @@ -0,0 +1,9 @@ +//@ edition: 2024 +#![no_std] + +// Since the 2024 edition the link_section attribute must use the unsafe qualification. +// However, the unsafe qualification is not shown by rustdoc. + +//@ is "$.index[?(@.name=='example')].attrs" '["#[link_section = \".text\"]"]' +#[unsafe(link_section = ".text")] +pub extern "C" fn example() {} diff --git a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr index 1243ed5d8f4..02b9e2f06ee 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr +++ b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr @@ -387,14 +387,6 @@ LL | #![link()] | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! -warning: attribute should be applied to a function or static - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:69:1 - | -LL | #![link_section = "1800"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ not a function or static - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - warning: attribute should be applied to a function definition --> $DIR/issue-43106-gating-of-builtin-attrs.rs:62:1 | @@ -411,6 +403,14 @@ LL | #![link_name = "1900"] | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! +warning: attribute should be applied to a function or static + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:69:1 + | +LL | #![link_section = "1800"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ not a function or static + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + warning: `#[must_use]` has no effect when applied to a module --> $DIR/issue-43106-gating-of-builtin-attrs.rs:72:1 | diff --git a/tests/ui/lint/unused/unused-attr-duplicate.rs b/tests/ui/lint/unused/unused-attr-duplicate.rs index 407af40654e..bf94a42f6e0 100644 --- a/tests/ui/lint/unused/unused-attr-duplicate.rs +++ b/tests/ui/lint/unused/unused-attr-duplicate.rs @@ -102,4 +102,10 @@ pub fn no_mangle_test() {} #[used] //~ ERROR unused attribute static FOO: u32 = 0; +#[link_section = ".text"] +//~^ ERROR unused attribute +//~| WARN this was previously accepted +#[link_section = ".bss"] +pub extern "C" fn example() {} + fn main() {} diff --git a/tests/ui/lint/unused/unused-attr-duplicate.stderr b/tests/ui/lint/unused/unused-attr-duplicate.stderr index e8452465efc..feae8528cf7 100644 --- a/tests/ui/lint/unused/unused-attr-duplicate.stderr +++ b/tests/ui/lint/unused/unused-attr-duplicate.stderr @@ -289,5 +289,18 @@ note: attribute also specified here LL | #[used] | ^^^^^^^ -error: aborting due to 23 previous errors +error: unused attribute + --> $DIR/unused-attr-duplicate.rs:105:1 + | +LL | #[link_section = ".text"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/unused-attr-duplicate.rs:108:1 + | +LL | #[link_section = ".bss"] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +error: aborting due to 24 previous errors -- cgit 1.4.1-3-g733a5 From 20d69c6c2643a0be8c2ea6a78bfda59aba73433e Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sun, 29 Jun 2025 22:19:14 +0800 Subject: Re-disable `tests/run-make/short-ice` on Windows MSVC again --- tests/run-make/short-ice/rmake.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/run-make/short-ice/rmake.rs b/tests/run-make/short-ice/rmake.rs index 483def62fc7..dbe0f692aef 100644 --- a/tests/run-make/short-ice/rmake.rs +++ b/tests/run-make/short-ice/rmake.rs @@ -5,9 +5,12 @@ // See https://github.com/rust-lang/rust/issues/107910 //@ needs-target-std -//@ ignore-i686-pc-windows-msvc -// Reason: the assert_eq! on line 37 fails, almost seems like it missing debug info? -// Haven't been able to reproduce locally, but it happens on CI. +//@ ignore-windows-msvc +// +// - FIXME(#143198): On `i686-pc-windows-msvc`: the assert_eq! on line 37 fails, almost seems like +// it missing debug info? Haven't been able to reproduce locally, but it happens on CI. +// - FIXME(#143198): On `x86_64-pc-windows-msvc`: full backtrace sometimes do not contain matching +// count of short backtrace markers (e.g. 5x end marker, but 3x start marker). use run_make_support::rustc; -- cgit 1.4.1-3-g733a5 From 580bc128441236345a5f3d5022af5a60091451ac Mon Sep 17 00:00:00 2001 From: Kivooeo Date: Fri, 27 Jun 2025 20:45:19 +0500 Subject: cleaned up some tests --- .../ui-test-missing-annotations-detection.rs | 9 ++++--- tests/ui/derives/derive-Debug-enum-variants.rs | 31 ++++++++++++++-------- tests/ui/fmt/debug-single-call.rs | 7 +++-- tests/ui/linkage-attr/link-section-placement.rs | 3 ++- tests/ui/log-err-phi.rs | 7 ----- tests/ui/resolve/struct-function-same-name.rs | 4 ++- tests/ui/resolve/type-param-local-var-shadowing.rs | 9 +++++-- 7 files changed, 43 insertions(+), 27 deletions(-) delete mode 100644 tests/ui/log-err-phi.rs (limited to 'tests') diff --git a/tests/ui/compiletest-self-test/ui-test-missing-annotations-detection.rs b/tests/ui/compiletest-self-test/ui-test-missing-annotations-detection.rs index 2a73e49e172..3a110bdad35 100644 --- a/tests/ui/compiletest-self-test/ui-test-missing-annotations-detection.rs +++ b/tests/ui/compiletest-self-test/ui-test-missing-annotations-detection.rs @@ -1,6 +1,9 @@ -//@ should-fail +//! Regression test checks UI tests without error annotations are detected as failing. +//! +//! This tests that when we forget to use any `//~ ERROR` comments whatsoever, +//! the test doesn't succeed +//! Originally created in https://github.com/rust-lang/rust/pull/56244 -// this test ensures that when we forget to use -// any `//~ ERROR` comments whatsoever, that the test doesn't succeed +//@ should-fail fn main() {} diff --git a/tests/ui/derives/derive-Debug-enum-variants.rs b/tests/ui/derives/derive-Debug-enum-variants.rs index cb82cb4878a..26f527f7664 100644 --- a/tests/ui/derives/derive-Debug-enum-variants.rs +++ b/tests/ui/derives/derive-Debug-enum-variants.rs @@ -1,21 +1,30 @@ +//! Test that `#[derive(Debug)]` for enums correctly formats variant names. + //@ run-pass -#![allow(non_camel_case_types)] -#![allow(dead_code)] #[derive(Debug)] -enum foo { - a(usize), - b(String), - c, +enum Foo { + A(usize), + C, } #[derive(Debug)] -enum bar { - d, e, f +enum Bar { + D, } pub fn main() { - assert_eq!("a(22)".to_string(), format!("{:?}", foo::a(22))); - assert_eq!("c".to_string(), format!("{:?}", foo::c)); - assert_eq!("d".to_string(), format!("{:?}", bar::d)); + // Test variant with data + let foo_a = Foo::A(22); + assert_eq!("A(22)".to_string(), format!("{:?}", foo_a)); + + if let Foo::A(value) = foo_a { + println!("Value: {}", value); // This needs to remove #[allow(dead_code)] + } + + // Test unit variant + assert_eq!("C".to_string(), format!("{:?}", Foo::C)); + + // Test unit variant from different enum + assert_eq!("D".to_string(), format!("{:?}", Bar::D)); } diff --git a/tests/ui/fmt/debug-single-call.rs b/tests/ui/fmt/debug-single-call.rs index bb8c29694b5..b59a766c71a 100644 --- a/tests/ui/fmt/debug-single-call.rs +++ b/tests/ui/fmt/debug-single-call.rs @@ -1,9 +1,12 @@ +//! Test that Debug::fmt is called exactly once during formatting. +//! +//! This is a regression test for PR https://github.com/rust-lang/rust/pull/10715 + //@ run-pass //@ needs-threads use std::cell::Cell; -use std::fmt; -use std::thread; +use std::{fmt, thread}; struct Foo(Cell); diff --git a/tests/ui/linkage-attr/link-section-placement.rs b/tests/ui/linkage-attr/link-section-placement.rs index a8de8c2e1e7..6a143bfedb4 100644 --- a/tests/ui/linkage-attr/link-section-placement.rs +++ b/tests/ui/linkage-attr/link-section-placement.rs @@ -1,8 +1,9 @@ +//! Test placement of functions and statics in custom link sections + //@ run-pass // FIXME(static_mut_refs): Do not allow `static_mut_refs` lint #![allow(static_mut_refs)] - #![allow(non_upper_case_globals)] #[cfg(not(target_vendor = "apple"))] #[link_section = ".moretext"] diff --git a/tests/ui/log-err-phi.rs b/tests/ui/log-err-phi.rs deleted file mode 100644 index 1bb97758782..00000000000 --- a/tests/ui/log-err-phi.rs +++ /dev/null @@ -1,7 +0,0 @@ -//@ run-pass - -pub fn main() { - if false { - println!("{}", "foobar"); - } -} diff --git a/tests/ui/resolve/struct-function-same-name.rs b/tests/ui/resolve/struct-function-same-name.rs index 338a3156a9a..bb2837d7ca6 100644 --- a/tests/ui/resolve/struct-function-same-name.rs +++ b/tests/ui/resolve/struct-function-same-name.rs @@ -1,3 +1,5 @@ +//! Test that a struct and function can have the same name +//! //@ run-pass #![allow(non_snake_case)] @@ -23,7 +25,7 @@ impl Product for Foo { } fn Foo(x: isize, y: isize) -> Foo { - Foo { x: x, y: y } + Foo { x, y } } pub fn main() { diff --git a/tests/ui/resolve/type-param-local-var-shadowing.rs b/tests/ui/resolve/type-param-local-var-shadowing.rs index f858369f7ce..e08379e2acf 100644 --- a/tests/ui/resolve/type-param-local-var-shadowing.rs +++ b/tests/ui/resolve/type-param-local-var-shadowing.rs @@ -1,8 +1,13 @@ +//! Test that items in subscopes correctly shadow type parameters and local variables +//! +//! Regression test for https://github.com/rust-lang/rust/issues/23880 + //@ run-pass -// Tests that items in subscopes can shadow type parameters and local variables (see issue #23880). #![allow(unused)] -struct Foo { x: Box } +struct Foo { + x: Box, +} impl Foo { fn foo(&self) { type Bar = i32; -- cgit 1.4.1-3-g733a5 From 1e3a2b2d4aa0ae75f9331c950b7346b1a017d4d9 Mon Sep 17 00:00:00 2001 From: Kivooeo Date: Sun, 29 Jun 2025 17:43:51 +0500 Subject: cleaned up some tests --- tests/ui/codegen/mono-respects-abi-alignment.rs | 40 ++++++++++++---------- tests/ui/codegen/msvc-opt-level-z-no-corruption.rs | 20 +++++++---- tests/ui/linkage-attr/msvc-static-data-import.rs | 16 +++++++-- tests/ui/parser/multiline-comments-basic.rs | 8 +++-- tests/ui/parser/unicode-multibyte-chars-no-ice.rs | 6 ++-- 5 files changed, 57 insertions(+), 33 deletions(-) (limited to 'tests') diff --git a/tests/ui/codegen/mono-respects-abi-alignment.rs b/tests/ui/codegen/mono-respects-abi-alignment.rs index 62df1aca357..045d82b761f 100644 --- a/tests/ui/codegen/mono-respects-abi-alignment.rs +++ b/tests/ui/codegen/mono-respects-abi-alignment.rs @@ -1,19 +1,20 @@ -//@ run-pass +//! Test that monomorphization correctly distinguishes types with different ABI alignment. +//! +//! On x86_64-linux-gnu and similar platforms, structs get 8-byte "preferred" +//! alignment, but their "ABI" alignment (what actually matters for data layout) +//! is the largest alignment of any field. If monomorphization incorrectly uses +//! "preferred" alignment instead of "ABI" alignment, it might unify types `A` +//! and `B` even though `S` and `S` have field `t` at different offsets, +//! leading to incorrect method dispatch for `unwrap()`. -#![allow(non_upper_case_globals)] -#![allow(dead_code)] -/*! - * On x86_64-linux-gnu and possibly other platforms, structs get 8-byte "preferred" alignment, - * but their "ABI" alignment (i.e., what actually matters for data layout) is the largest alignment - * of any field. (Also, `u64` has 8-byte ABI alignment; this is not always true). - * - * On such platforms, if monomorphize uses the "preferred" alignment, then it will unify - * `A` and `B`, even though `S` and `S` have the field `t` at different offsets, - * and apply the wrong instance of the method `unwrap`. - */ +//@ run-pass #[derive(Copy, Clone)] -struct S { i:u8, t:T } +struct S { + #[allow(dead_code)] + i: u8, + t: T, +} impl S { fn unwrap(self) -> T { @@ -22,14 +23,15 @@ impl S { } #[derive(Copy, Clone, PartialEq, Debug)] -struct A((u32, u32)); +struct A((u32, u32)); // Different ABI alignment than B #[derive(Copy, Clone, PartialEq, Debug)] -struct B(u64); +struct B(u64); // Different ABI alignment than A pub fn main() { - static Ca: S = S { i: 0, t: A((13, 104)) }; - static Cb: S = S { i: 0, t: B(31337) }; - assert_eq!(Ca.unwrap(), A((13, 104))); - assert_eq!(Cb.unwrap(), B(31337)); + static CA: S = S { i: 0, t: A((13, 104)) }; + static CB: S = S { i: 0, t: B(31337) }; + + assert_eq!(CA.unwrap(), A((13, 104))); + assert_eq!(CB.unwrap(), B(31337)); } diff --git a/tests/ui/codegen/msvc-opt-level-z-no-corruption.rs b/tests/ui/codegen/msvc-opt-level-z-no-corruption.rs index c1be168a05d..ba97acec822 100644 --- a/tests/ui/codegen/msvc-opt-level-z-no-corruption.rs +++ b/tests/ui/codegen/msvc-opt-level-z-no-corruption.rs @@ -1,12 +1,18 @@ -// A previously outdated version of LLVM caused compilation failures on Windows -// specifically with optimization level `z`. After the update to a more recent LLVM -// version, this test checks that compilation and execution both succeed. -// See https://github.com/rust-lang/rust/issues/45034 +//! Test that opt-level=z produces correct code on Windows MSVC targets. +//! +//! A previously outdated version of LLVM caused compilation failures and +//! generated invalid code on Windows specifically with optimization level `z`. +//! The bug manifested as corrupted base pointers due to incorrect register +//! usage in the generated assembly (e.g., `popl %esi` corrupting local variables). +//! After updating to a more recent LLVM version, this test ensures that +//! compilation and execution both succeed with opt-level=z. +//! +//! Regression test for . //@ ignore-cross-compile // Reason: the compiled binary is executed //@ only-windows -// Reason: the observed bug only occurs on Windows +// Reason: the observed bug only occurred on Windows MSVC targets //@ run-pass //@ compile-flags: -C opt-level=z @@ -20,8 +26,8 @@ fn foo(x: i32, y: i32) -> i64 { #[inline(never)] fn bar() { let _f = Box::new(0); - // This call used to trigger an LLVM bug in opt-level z where the base - // pointer gets corrupted, see issue #45034 + // This call used to trigger an LLVM bug in opt-level=z where the base + // pointer gets corrupted due to incorrect register allocation let y: fn(i32, i32) -> i64 = test::black_box(foo); test::black_box(y(1, 2)); } diff --git a/tests/ui/linkage-attr/msvc-static-data-import.rs b/tests/ui/linkage-attr/msvc-static-data-import.rs index 15d799085fe..e53eb404ef6 100644 --- a/tests/ui/linkage-attr/msvc-static-data-import.rs +++ b/tests/ui/linkage-attr/msvc-static-data-import.rs @@ -1,8 +1,18 @@ +//! Test that static data from external crates can be imported on MSVC targets. +//! +//! On Windows MSVC targets, static data from external rlibs must be imported +//! through `__imp_` stubs to ensure proper linking. Without this, +//! the linker would fail with "unresolved external symbol" errors when trying +//! to reference static data from another crate. +//! +//! Regression test for . +//! Fixed in . + //@ run-pass -//@ aux-build:msvc-data-only-lib.rs +//@ aux-build:msvc-static-data-import-lib.rs -extern crate msvc_data_only_lib; +extern crate msvc_static_data_import_lib; fn main() { - println!("The answer is {} !", msvc_data_only_lib::FOO); + println!("The answer is {}!", msvc_static_data_import_lib::FOO); } diff --git a/tests/ui/parser/multiline-comments-basic.rs b/tests/ui/parser/multiline-comments-basic.rs index 98174882032..1aa2a531f5c 100644 --- a/tests/ui/parser/multiline-comments-basic.rs +++ b/tests/ui/parser/multiline-comments-basic.rs @@ -1,6 +1,10 @@ +//! Test that basic multiline comments are parsed correctly. +//! +//! Feature implementation test for . + //@ run-pass /* - * This is a multi-line oldcomment. + * This is a multi-line comment. */ -pub fn main() { } +pub fn main() {} diff --git a/tests/ui/parser/unicode-multibyte-chars-no-ice.rs b/tests/ui/parser/unicode-multibyte-chars-no-ice.rs index d585a791fb9..b1bb0c66ae2 100644 --- a/tests/ui/parser/unicode-multibyte-chars-no-ice.rs +++ b/tests/ui/parser/unicode-multibyte-chars-no-ice.rs @@ -1,7 +1,9 @@ +//! Test that multibyte Unicode characters don't crash the compiler. +//! +//! Regression test for . + //@ run-pass -// -// Test that multibyte characters don't crash the compiler pub fn main() { println!("마이너스 사인이 없으면"); } -- cgit 1.4.1-3-g733a5 From c240566561b1b819e102618dcf9347b1745f3c92 Mon Sep 17 00:00:00 2001 From: Kivooeo Date: Sat, 28 Jun 2025 22:59:17 +0500 Subject: cleaned up some tests --- tests/ui/codegen/maximal-hir-to-mir-coverage-flag.rs | 12 +++++++----- tests/ui/lint/missing-debug-implementations-lint.rs | 8 +++++--- tests/ui/lint/missing-debug-implementations-lint.stderr | 6 +++--- tests/ui/mismatched_types/fn-pointer-mismatch-diagnostics.rs | 8 ++++++++ .../mismatched_types/fn-pointer-mismatch-diagnostics.stderr | 4 ++-- tests/ui/traits/maybe-trait-bounds-forbidden-locations.rs | 9 +++++++++ .../ui/traits/maybe-trait-bounds-forbidden-locations.stderr | 6 +++--- tests/ui/type-alias-enum-variants/module-type-args-error.rs | 7 +++++++ .../type-alias-enum-variants/module-type-args-error.stderr | 2 +- 9 files changed, 45 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/ui/codegen/maximal-hir-to-mir-coverage-flag.rs b/tests/ui/codegen/maximal-hir-to-mir-coverage-flag.rs index e57c83d007e..64c31beba28 100644 --- a/tests/ui/codegen/maximal-hir-to-mir-coverage-flag.rs +++ b/tests/ui/codegen/maximal-hir-to-mir-coverage-flag.rs @@ -1,10 +1,12 @@ +//! Test that -Z maximal-hir-to-mir-coverage flag is accepted. +//! +//! Original PR: https://github.com/rust-lang/rust/pull/105286 + //@ compile-flags: -Zmaximal-hir-to-mir-coverage //@ run-pass -// Just making sure this flag is accepted and doesn't crash the compiler - fn main() { - let x = 1; - let y = x + 1; - println!("{y}"); + let x = 1; + let y = x + 1; + println!("{y}"); } diff --git a/tests/ui/lint/missing-debug-implementations-lint.rs b/tests/ui/lint/missing-debug-implementations-lint.rs index 3abc0706887..8a93f052f9c 100644 --- a/tests/ui/lint/missing-debug-implementations-lint.rs +++ b/tests/ui/lint/missing-debug-implementations-lint.rs @@ -1,3 +1,7 @@ +//! Test the `missing_debug_implementations` lint that warns about public types without Debug. +//! +//! See https://github.com/rust-lang/rust/issues/20855 + //@ compile-flags: --crate-type lib #![deny(missing_debug_implementations)] #![allow(unused)] @@ -10,7 +14,6 @@ pub enum A {} //~ ERROR type does not implement `Debug` pub enum B {} pub enum C {} - impl fmt::Debug for C { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { Ok(()) @@ -23,15 +26,14 @@ pub struct Foo; //~ ERROR type does not implement `Debug` pub struct Bar; pub struct Baz; - impl fmt::Debug for Baz { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { Ok(()) } } +// Private types should not trigger the lint struct PrivateStruct; - enum PrivateEnum {} #[derive(Debug)] diff --git a/tests/ui/lint/missing-debug-implementations-lint.stderr b/tests/ui/lint/missing-debug-implementations-lint.stderr index 0538f207b44..288ab981034 100644 --- a/tests/ui/lint/missing-debug-implementations-lint.stderr +++ b/tests/ui/lint/missing-debug-implementations-lint.stderr @@ -1,17 +1,17 @@ error: type does not implement `Debug`; consider adding `#[derive(Debug)]` or a manual implementation - --> $DIR/missing_debug_impls.rs:7:1 + --> $DIR/missing-debug-implementations-lint.rs:11:1 | LL | pub enum A {} | ^^^^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/missing_debug_impls.rs:2:9 + --> $DIR/missing-debug-implementations-lint.rs:6:9 | LL | #![deny(missing_debug_implementations)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: type does not implement `Debug`; consider adding `#[derive(Debug)]` or a manual implementation - --> $DIR/missing_debug_impls.rs:20:1 + --> $DIR/missing-debug-implementations-lint.rs:23:1 | LL | pub struct Foo; | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/mismatched_types/fn-pointer-mismatch-diagnostics.rs b/tests/ui/mismatched_types/fn-pointer-mismatch-diagnostics.rs index 85a903e2453..e28ca3e55b5 100644 --- a/tests/ui/mismatched_types/fn-pointer-mismatch-diagnostics.rs +++ b/tests/ui/mismatched_types/fn-pointer-mismatch-diagnostics.rs @@ -1,7 +1,15 @@ +//! This test checks that when there's a type mismatch between a function item and +//! a function pointer, the error message focuses on the actual type difference +//! (return types, argument types) rather than the confusing "pointer vs item" distinction. +//! +//! See https://github.com/rust-lang/rust/issues/127263 + fn bar() {} + fn foo(x: i32) -> u32 { 0 } + fn main() { let b: fn() -> u32 = bar; //~ ERROR mismatched types [E0308] let f: fn(i32) = foo; //~ ERROR mismatched types [E0308] diff --git a/tests/ui/mismatched_types/fn-pointer-mismatch-diagnostics.stderr b/tests/ui/mismatched_types/fn-pointer-mismatch-diagnostics.stderr index 35b86114f16..8d63f2ea2d3 100644 --- a/tests/ui/mismatched_types/fn-pointer-mismatch-diagnostics.stderr +++ b/tests/ui/mismatched_types/fn-pointer-mismatch-diagnostics.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/method-output-diff-issue-127263.rs:6:26 + --> $DIR/fn-pointer-mismatch-diagnostics.rs:14:26 | LL | let b: fn() -> u32 = bar; | ----------- ^^^ expected fn pointer, found fn item @@ -10,7 +10,7 @@ LL | let b: fn() -> u32 = bar; found fn item `fn() -> () {bar}` error[E0308]: mismatched types - --> $DIR/method-output-diff-issue-127263.rs:7:22 + --> $DIR/fn-pointer-mismatch-diagnostics.rs:15:22 | LL | let f: fn(i32) = foo; | ------- ^^^ expected fn pointer, found fn item diff --git a/tests/ui/traits/maybe-trait-bounds-forbidden-locations.rs b/tests/ui/traits/maybe-trait-bounds-forbidden-locations.rs index 02ed45c656f..04963c98765 100644 --- a/tests/ui/traits/maybe-trait-bounds-forbidden-locations.rs +++ b/tests/ui/traits/maybe-trait-bounds-forbidden-locations.rs @@ -1,3 +1,12 @@ +//! Test that ?Trait bounds are forbidden in supertraits and trait object types. +//! +//! While `?Sized` and other maybe bounds are allowed in type parameter bounds and where clauses, +//! they are explicitly forbidden in certain syntactic positions: +//! - As supertraits in trait definitions +//! - In trait object type expressions +//! +//! See https://github.com/rust-lang/rust/issues/20503 + trait Tr: ?Sized {} //~^ ERROR `?Trait` is not permitted in supertraits diff --git a/tests/ui/traits/maybe-trait-bounds-forbidden-locations.stderr b/tests/ui/traits/maybe-trait-bounds-forbidden-locations.stderr index 230d11fd0ae..bd0baa580bd 100644 --- a/tests/ui/traits/maybe-trait-bounds-forbidden-locations.stderr +++ b/tests/ui/traits/maybe-trait-bounds-forbidden-locations.stderr @@ -1,5 +1,5 @@ error[E0658]: `?Trait` is not permitted in supertraits - --> $DIR/maybe-bounds.rs:1:11 + --> $DIR/maybe-trait-bounds-forbidden-locations.rs:10:11 | LL | trait Tr: ?Sized {} | ^^^^^^ @@ -9,7 +9,7 @@ LL | trait Tr: ?Sized {} = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: `?Trait` is not permitted in trait object types - --> $DIR/maybe-bounds.rs:4:20 + --> $DIR/maybe-trait-bounds-forbidden-locations.rs:13:20 | LL | type A1 = dyn Tr + (?Sized); | ^^^^^^^^ @@ -18,7 +18,7 @@ LL | type A1 = dyn Tr + (?Sized); = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: `?Trait` is not permitted in trait object types - --> $DIR/maybe-bounds.rs:6:28 + --> $DIR/maybe-trait-bounds-forbidden-locations.rs:15:28 | LL | type A2 = dyn for<'a> Tr + (?Sized); | ^^^^^^^^ diff --git a/tests/ui/type-alias-enum-variants/module-type-args-error.rs b/tests/ui/type-alias-enum-variants/module-type-args-error.rs index 959024c46f4..9f7dae4f4f5 100644 --- a/tests/ui/type-alias-enum-variants/module-type-args-error.rs +++ b/tests/ui/type-alias-enum-variants/module-type-args-error.rs @@ -1,9 +1,16 @@ +//! Test that type arguments are properly rejected on modules. +//! +//! Related PR: https://github.com/rust-lang/rust/pull/56225 (RFC 2338 implementation) + mod Mod { pub struct FakeVariant(pub T); } fn main() { + // This should work fine - normal generic struct constructor Mod::FakeVariant::(0); + + // This should error - type arguments not allowed on modules Mod::::FakeVariant(0); //~^ ERROR type arguments are not allowed on module `Mod` [E0109] } diff --git a/tests/ui/type-alias-enum-variants/module-type-args-error.stderr b/tests/ui/type-alias-enum-variants/module-type-args-error.stderr index 92d972eba42..4c59d19eaa7 100644 --- a/tests/ui/type-alias-enum-variants/module-type-args-error.stderr +++ b/tests/ui/type-alias-enum-variants/module-type-args-error.stderr @@ -1,5 +1,5 @@ error[E0109]: type arguments are not allowed on module `Mod` - --> $DIR/mod-subitem-as-enum-variant.rs:7:11 + --> $DIR/module-type-args-error.rs:14:11 | LL | Mod::::FakeVariant(0); | --- ^^^ type argument not allowed -- cgit 1.4.1-3-g733a5