diff options
Diffstat (limited to 'tests')
168 files changed, 2790 insertions, 1286 deletions
diff --git a/tests/codegen/align-fn.rs b/tests/codegen/align-fn.rs index 267da060240..90073ff3081 100644 --- a/tests/codegen/align-fn.rs +++ b/tests/codegen/align-fn.rs @@ -1,10 +1,10 @@ -//@ compile-flags: -C no-prepopulate-passes -Z mir-opt-level=0 +//@ compile-flags: -C no-prepopulate-passes -Z mir-opt-level=0 -Clink-dead-code #![crate_type = "lib"] #![feature(fn_align)] // CHECK: align 16 -#[no_mangle] +#[unsafe(no_mangle)] #[align(16)] pub fn fn_align() {} @@ -12,12 +12,12 @@ pub struct A; impl A { // CHECK: align 16 - #[no_mangle] + #[unsafe(no_mangle)] #[align(16)] pub fn method_align(self) {} // CHECK: align 16 - #[no_mangle] + #[unsafe(no_mangle)] #[align(16)] pub fn associated_fn() {} } @@ -25,46 +25,94 @@ impl A { trait T: Sized { fn trait_fn() {} - // CHECK: align 32 - #[align(32)] fn trait_method(self) {} + + #[align(8)] + fn trait_method_inherit_low(self); + + #[align(32)] + fn trait_method_inherit_high(self); + + #[align(32)] + fn trait_method_inherit_default(self) {} + + #[align(4)] + #[align(128)] + #[align(8)] + fn inherit_highest(self) {} } impl T for A { - // CHECK: align 16 - #[no_mangle] + // CHECK-LABEL: trait_fn + // CHECK-SAME: align 16 + #[unsafe(no_mangle)] #[align(16)] fn trait_fn() {} - // CHECK: align 16 - #[no_mangle] + // CHECK-LABEL: trait_method + // CHECK-SAME: align 16 + #[unsafe(no_mangle)] #[align(16)] fn trait_method(self) {} -} -impl T for () {} + // The prototype's align is ignored because the align here is higher. + // CHECK-LABEL: trait_method_inherit_low + // CHECK-SAME: align 16 + #[unsafe(no_mangle)] + #[align(16)] + fn trait_method_inherit_low(self) {} + + // The prototype's align is used because it is higher. + // CHECK-LABEL: trait_method_inherit_high + // CHECK-SAME: align 32 + #[unsafe(no_mangle)] + #[align(16)] + fn trait_method_inherit_high(self) {} + + // The prototype's align inherited. + // CHECK-LABEL: trait_method_inherit_default + // CHECK-SAME: align 32 + #[unsafe(no_mangle)] + fn trait_method_inherit_default(self) {} + + // The prototype's highest align inherited. + // CHECK-LABEL: inherit_highest + // CHECK-SAME: align 128 + #[unsafe(no_mangle)] + #[align(32)] + #[align(64)] + fn inherit_highest(self) {} +} -pub fn foo() { - ().trait_method(); +trait HasDefaultImpl: Sized { + // CHECK-LABEL: inherit_from_default_method + // CHECK-LABEL: inherit_from_default_method + // CHECK-SAME: align 32 + #[align(32)] + fn inherit_from_default_method(self) {} } +pub struct InstantiateDefaultMethods; + +impl HasDefaultImpl for InstantiateDefaultMethods {} + // CHECK-LABEL: align_specified_twice_1 // CHECK-SAME: align 64 -#[no_mangle] +#[unsafe(no_mangle)] #[align(32)] #[align(64)] pub fn align_specified_twice_1() {} // CHECK-LABEL: align_specified_twice_2 // CHECK-SAME: align 128 -#[no_mangle] +#[unsafe(no_mangle)] #[align(128)] #[align(32)] pub fn align_specified_twice_2() {} // CHECK-LABEL: align_specified_twice_3 // CHECK-SAME: align 256 -#[no_mangle] +#[unsafe(no_mangle)] #[align(32)] #[align(256)] pub fn align_specified_twice_3() {} 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<N: Numoid> &'a Self: Add<Self>, -{ -} - -pub fn compute<N: Numoid>(a: N) -> N { - &a + a -} 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; 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/rustdoc-ui/invalid_infered_static_and_const.stderr b/tests/rustdoc-ui/invalid_infered_static_and_const.stderr index 401020224d6..3e116826c49 100644 --- a/tests/rustdoc-ui/invalid_infered_static_and_const.stderr +++ b/tests/rustdoc-ui/invalid_infered_static_and_const.stderr @@ -1,10 +1,10 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants --> $DIR/invalid_infered_static_and_const.rs:1:24 | LL | const FOO: dyn Fn() -> _ = ""; | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for statics --> $DIR/invalid_infered_static_and_const.rs:2:25 | LL | static BOO: dyn Fn() -> _ = ""; diff --git a/tests/ui-fulldeps/stable-mir/check_allocation.rs b/tests/ui-fulldeps/stable-mir/check_allocation.rs index 692c24f0544..64194e72888 100644 --- a/tests/ui-fulldeps/stable-mir/check_allocation.rs +++ b/tests/ui-fulldeps/stable-mir/check_allocation.rs @@ -19,12 +19,6 @@ extern crate rustc_driver; extern crate rustc_interface; extern crate stable_mir; -use stable_mir::crate_def::CrateDef; -use stable_mir::mir::alloc::GlobalAlloc; -use stable_mir::mir::mono::{Instance, InstanceKind, StaticDef}; -use stable_mir::mir::{Body, TerminatorKind}; -use stable_mir::ty::{Allocation, ConstantKind, RigidTy, TyKind}; -use stable_mir::{CrateItem, CrateItems, ItemKind}; use std::ascii::Char; use std::assert_matches::assert_matches; use std::cmp::{max, min}; @@ -33,6 +27,13 @@ use std::ffi::CStr; use std::io::Write; use std::ops::ControlFlow; +use stable_mir::crate_def::CrateDef; +use stable_mir::mir::Body; +use stable_mir::mir::alloc::GlobalAlloc; +use stable_mir::mir::mono::{Instance, StaticDef}; +use stable_mir::ty::{Allocation, ConstantKind}; +use stable_mir::{CrateItem, CrateItems, ItemKind}; + const CRATE_NAME: &str = "input"; /// This function uses the Stable MIR APIs to get information about the test crate. @@ -44,7 +45,6 @@ fn test_stable_mir() -> ControlFlow<()> { check_len(*get_item(&items, (ItemKind::Static, "LEN")).unwrap()); check_cstr(*get_item(&items, (ItemKind::Static, "C_STR")).unwrap()); check_other_consts(*get_item(&items, (ItemKind::Fn, "other_consts")).unwrap()); - check_type_id(*get_item(&items, (ItemKind::Fn, "check_type_id")).unwrap()); ControlFlow::Continue(()) } @@ -107,7 +107,9 @@ fn check_other_consts(item: CrateItem) { // Instance body will force constant evaluation. let body = Instance::try_from(item).unwrap().body().unwrap(); let assigns = collect_consts(&body); - assert_eq!(assigns.len(), 8); + assert_eq!(assigns.len(), 10); + let mut char_id = None; + let mut bool_id = None; for (name, alloc) in assigns { match name.as_str() { "_max_u128" => { @@ -149,35 +151,21 @@ fn check_other_consts(item: CrateItem) { assert_eq!(max(first, second) as u32, u32::MAX); assert_eq!(min(first, second), 10); } + "_bool_id" => { + bool_id = Some(alloc); + } + "_char_id" => { + char_id = Some(alloc); + } _ => { unreachable!("{name} -- {alloc:?}") } } } -} - -/// Check that we can retrieve the type id of char and bool, and that they have different values. -fn check_type_id(item: CrateItem) { - let body = Instance::try_from(item).unwrap().body().unwrap(); - let mut ids: Vec<u128> = vec![]; - for term in body.blocks.iter().map(|bb| &bb.terminator) { - match &term.kind { - TerminatorKind::Call { func, destination, .. } => { - let TyKind::RigidTy(ty) = func.ty(body.locals()).unwrap().kind() else { - unreachable!() - }; - let RigidTy::FnDef(def, args) = ty else { unreachable!() }; - let instance = Instance::resolve(def, &args).unwrap(); - assert_eq!(instance.kind, InstanceKind::Intrinsic); - let dest_ty = destination.ty(body.locals()).unwrap(); - let alloc = instance.try_const_eval(dest_ty).unwrap(); - ids.push(alloc.read_uint().unwrap()); - } - _ => { /* Do nothing */ } - } - } - assert_eq!(ids.len(), 2); - assert_ne!(ids[0], ids[1]); + let bool_id = bool_id.unwrap(); + let char_id = char_id.unwrap(); + // FIXME(stable_mir): add `read_ptr` to `Allocation` + assert_ne!(bool_id, char_id); } /// Collects all the constant assignments. @@ -235,6 +223,7 @@ fn generate_input(path: &str) -> std::io::Result<()> { file, r#" #![feature(core_intrinsics)] + #![expect(internal_features)] use std::intrinsics::type_id; static LEN: usize = 2; @@ -254,11 +243,8 @@ fn generate_input(path: &str) -> std::io::Result<()> { let _ptr = &BAR; let _null_ptr: *const u8 = NULL; let _tuple = TUPLE; - }} - - fn check_type_id() {{ - let _char_id = type_id::<char>(); - let _bool_id = type_id::<bool>(); + let _char_id = const {{ type_id::<char>() }}; + let _bool_id = const {{ type_id::<bool>() }}; }} pub fn main() {{ diff --git a/tests/ui/empty-allocation-non-null.rs b/tests/ui/allocator/empty-alloc-nonnull-guarantee.rs index 45035a42a5f..f4081306c77 100644 --- a/tests/ui/empty-allocation-non-null.rs +++ b/tests/ui/allocator/empty-alloc-nonnull-guarantee.rs @@ -1,3 +1,7 @@ +//! Check that the default global Rust allocator produces non-null Box allocations for ZSTs. +//! +//! See https://github.com/rust-lang/rust/issues/11998 + //@ run-pass pub fn main() { diff --git a/tests/ui/associated-types/unconstrained-lifetime-assoc-type.rs b/tests/ui/associated-types/unconstrained-lifetime-assoc-type.rs new file mode 100644 index 00000000000..2c4af7da921 --- /dev/null +++ b/tests/ui/associated-types/unconstrained-lifetime-assoc-type.rs @@ -0,0 +1,21 @@ +//! Regression test for issue #22077 +//! lifetime parameters must be constrained in associated type definitions + +trait Fun { + type Output; + fn call<'x>(&'x self) -> Self::Output; +} + +struct Holder { + x: String, +} + +impl<'a> Fun for Holder { + //~^ ERROR E0207 + type Output = &'a str; + fn call<'b>(&'b self) -> &'b str { + &self.x[..] + } +} + +fn main() {} diff --git a/tests/ui/impl-unused-rps-in-assoc-type.stderr b/tests/ui/associated-types/unconstrained-lifetime-assoc-type.stderr index ef61fa4be48..15d0820c895 100644 --- a/tests/ui/impl-unused-rps-in-assoc-type.stderr +++ b/tests/ui/associated-types/unconstrained-lifetime-assoc-type.stderr @@ -1,5 +1,5 @@ error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates - --> $DIR/impl-unused-rps-in-assoc-type.rs:11:6 + --> $DIR/unconstrained-lifetime-assoc-type.rs:13:6 | LL | impl<'a> Fun for Holder { | ^^ unconstrained lifetime parameter diff --git a/tests/ui/inline-disallow-on-variant.rs b/tests/ui/attributes/inline-attribute-enum-variant-error.rs index d92a4e8cc8d..305b285d2a4 100644 --- a/tests/ui/inline-disallow-on-variant.rs +++ b/tests/ui/attributes/inline-attribute-enum-variant-error.rs @@ -1,3 +1,5 @@ +//! Test that #[inline] attribute cannot be applied to enum variants + enum Foo { #[inline] //~^ ERROR attribute should be applied diff --git a/tests/ui/inline-disallow-on-variant.stderr b/tests/ui/attributes/inline-attribute-enum-variant-error.stderr index 255f6bc6a19..a4564d8f722 100644 --- a/tests/ui/inline-disallow-on-variant.stderr +++ b/tests/ui/attributes/inline-attribute-enum-variant-error.stderr @@ -1,5 +1,5 @@ error[E0518]: attribute should be applied to function or closure - --> $DIR/inline-disallow-on-variant.rs:2:5 + --> $DIR/inline-attribute-enum-variant-error.rs:4:5 | LL | #[inline] | ^^^^^^^^^ diff --git a/tests/ui/attributes/inline-main.rs b/tests/ui/attributes/inline-main.rs new file mode 100644 index 00000000000..7181ee19b67 --- /dev/null +++ b/tests/ui/attributes/inline-main.rs @@ -0,0 +1,6 @@ +//! Test that #[inline(always)] can be applied to main function + +//@ run-pass + +#[inline(always)] +fn main() {} 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/attributes/malformed-attrs.rs b/tests/ui/attributes/malformed-attrs.rs new file mode 100644 index 00000000000..64c0d223f83 --- /dev/null +++ b/tests/ui/attributes/malformed-attrs.rs @@ -0,0 +1,221 @@ +// This file contains a bunch of malformed attributes. +// We enable a bunch of features to not get feature-gate errs in this test. +#![feature(rustc_attrs)] +#![feature(rustc_allow_const_fn_unstable)] +#![feature(allow_internal_unstable)] +#![feature(fn_align)] +#![feature(optimize_attribute)] +#![feature(dropck_eyepatch)] +#![feature(export_stable)] +#![allow(incomplete_features)] +#![feature(min_generic_const_args)] +#![feature(ffi_const, ffi_pure)] +#![feature(coverage_attribute)] +#![feature(no_sanitize)] +#![feature(marker_trait_attr)] +#![feature(thread_local)] +#![feature(must_not_suspend)] +#![feature(coroutines)] +#![feature(linkage)] +#![feature(cfi_encoding, extern_types)] +#![feature(patchable_function_entry)] +#![feature(omit_gdb_pretty_printer_section)] +#![feature(fundamental)] + + +#![omit_gdb_pretty_printer_section = 1] +//~^ ERROR malformed `omit_gdb_pretty_printer_section` attribute input + +#![windows_subsystem] +//~^ ERROR malformed + +#[unsafe(export_name)] +//~^ ERROR malformed +#[rustc_allow_const_fn_unstable] +//~^ ERROR `rustc_allow_const_fn_unstable` expects a list of feature names +#[allow_internal_unstable] +//~^ ERROR `allow_internal_unstable` expects a list of feature names +#[rustc_confusables] +//~^ ERROR malformed +#[deprecated = 5] +//~^ ERROR malformed +#[doc] +//~^ ERROR valid forms for the attribute are +//~| WARN this was previously accepted by the compiler +#[rustc_macro_transparency] +//~^ ERROR malformed +#[repr] +//~^ ERROR malformed +#[rustc_as_ptr = 5] +//~^ ERROR malformed +#[inline = 5] +//~^ ERROR valid forms for the attribute are +//~| WARN this was previously accepted by the compiler +#[align] +//~^ ERROR malformed +#[optimize] +//~^ ERROR malformed +#[cold = 1] +//~^ ERROR malformed +#[must_use()] +//~^ ERROR valid forms for the attribute are +#[no_mangle = 1] +//~^ ERROR malformed +#[unsafe(naked())] +//~^ ERROR malformed +#[track_caller()] +//~^ ERROR malformed +#[export_name()] +//~^ ERROR malformed +#[used()] +//~^ ERROR malformed +#[crate_name] +//~^ ERROR malformed +#[doc] +//~^ ERROR valid forms for the attribute are +//~| WARN this was previously accepted by the compiler +#[target_feature] +//~^ ERROR malformed +#[export_stable = 1] +//~^ ERROR malformed +#[link] +//~^ ERROR attribute must be of the form +//~| WARN this was previously accepted by the compiler +#[link_name] +//~^ ERROR malformed +#[link_section] +//~^ ERROR malformed +#[coverage] +//~^ ERROR malformed `coverage` attribute input +#[no_sanitize] +//~^ ERROR malformed +#[ignore()] +//~^ ERROR valid forms for the attribute are +//~| WARN this was previously accepted by the compiler +#[no_implicit_prelude = 23] +//~^ ERROR malformed +#[proc_macro = 18] +//~^ ERROR malformed +//~| ERROR the `#[proc_macro]` attribute is only usable with crates of the `proc-macro` crate type +#[cfg] +//~^ ERROR is not followed by parentheses +#[cfg_attr] +//~^ ERROR malformed +#[instruction_set] +//~^ ERROR malformed +#[patchable_function_entry] +//~^ ERROR malformed +fn test() { + #[coroutine = 63] || {} + //~^ ERROR malformed `coroutine` attribute input + //~| ERROR mismatched types [E0308] +} + +#[proc_macro_attribute = 19] +//~^ ERROR malformed +//~| ERROR the `#[proc_macro_attribute]` attribute is only usable with crates of the `proc-macro` crate type +#[must_use = 1] +//~^ ERROR malformed +fn test2() { } + +#[proc_macro_derive] +//~^ ERROR malformed `proc_macro_derive` attribute +//~| ERROR the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type +pub fn test3() {} + +#[rustc_layout_scalar_valid_range_start] +//~^ ERROR malformed +#[rustc_layout_scalar_valid_range_end] +//~^ ERROR malformed +#[must_not_suspend()] +//~^ ERROR malformed +#[cfi_encoding] +//~^ ERROR malformed +struct Test; + +#[diagnostic::on_unimplemented] +//~^ WARN missing options for `on_unimplemented` attribute +#[diagnostic::on_unimplemented = 1] +//~^ WARN malformed +trait Hey { + #[type_const = 1] + //~^ ERROR malformed + const HEY: usize = 5; +} + +struct Empty; +#[diagnostic::do_not_recommend()] +//~^ WARN does not expect any arguments +impl Hey for Empty { + +} + +#[marker = 3] +//~^ ERROR malformed +#[fundamental()] +//~^ ERROR malformed +trait EmptyTrait { + +} + + +extern "C" { + #[unsafe(ffi_pure = 1)] + //~^ ERROR malformed + #[link_ordinal] + //~^ ERROR malformed + pub fn baz(); + + #[unsafe(ffi_const = 1)] + //~^ ERROR malformed + #[linkage] + //~^ ERROR malformed + pub fn bar(); +} + +#[allow] +//~^ ERROR malformed +#[expect] +//~^ ERROR malformed +#[warn] +//~^ ERROR malformed +#[deny] +//~^ ERROR malformed +#[forbid] +//~^ ERROR malformed +#[debugger_visualizer] +//~^ ERROR invalid argument +//~| ERROR malformed `debugger_visualizer` attribute input +#[automatically_derived = 18] +//~^ ERROR malformed +mod yooo { + +} + +#[non_exhaustive = 1] +//~^ ERROR malformed +enum Slenum { + +} + +#[thread_local()] +//~^ ERROR malformed +static mut TLS: u8 = 42; + +#[no_link()] +//~^ ERROR malformed +#[macro_use = 1] +//~^ ERROR malformed +extern crate wloop; +//~^ ERROR can't find crate for `wloop` [E0463] + +#[macro_export = 18] +//~^ ERROR malformed `macro_export` attribute input +#[allow_internal_unsafe = 1] +//~^ ERROR malformed +//~| ERROR allow_internal_unsafe side-steps the unsafe_code lint +macro_rules! slump { + () => {} +} + +fn main() {} diff --git a/tests/ui/attributes/malformed-attrs.stderr b/tests/ui/attributes/malformed-attrs.stderr new file mode 100644 index 00000000000..bf063e8f6e5 --- /dev/null +++ b/tests/ui/attributes/malformed-attrs.stderr @@ -0,0 +1,596 @@ +error: `cfg` is not followed by parentheses + --> $DIR/malformed-attrs.rs:100:1 + | +LL | #[cfg] + | ^^^^^^ help: expected syntax is: `cfg(/* predicate */)` + +error: malformed `cfg_attr` attribute input + --> $DIR/malformed-attrs.rs:102:1 + | +LL | #[cfg_attr] + | ^^^^^^^^^^^ + | + = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute> +help: missing condition and attribute + | +LL | #[cfg_attr(condition, attribute, other_attribute, ...)] + | ++++++++++++++++++++++++++++++++++++++++++++ + +error[E0463]: can't find crate for `wloop` + --> $DIR/malformed-attrs.rs:209:1 + | +LL | extern crate wloop; + | ^^^^^^^^^^^^^^^^^^^ can't find crate + +error: malformed `omit_gdb_pretty_printer_section` attribute input + --> $DIR/malformed-attrs.rs:26:1 + | +LL | #![omit_gdb_pretty_printer_section = 1] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#![omit_gdb_pretty_printer_section]` + +error: malformed `windows_subsystem` attribute input + --> $DIR/malformed-attrs.rs:29:1 + | +LL | #![windows_subsystem] + | ^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#![windows_subsystem = "windows|console"]` + +error: malformed `crate_name` attribute input + --> $DIR/malformed-attrs.rs:72:1 + | +LL | #[crate_name] + | ^^^^^^^^^^^^^ help: must be of the form: `#[crate_name = "name"]` + +error: malformed `target_feature` attribute input + --> $DIR/malformed-attrs.rs:77:1 + | +LL | #[target_feature] + | ^^^^^^^^^^^^^^^^^ help: must be of the form: `#[target_feature(enable = "name")]` + +error: malformed `export_stable` attribute input + --> $DIR/malformed-attrs.rs:79:1 + | +LL | #[export_stable = 1] + | ^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[export_stable]` + +error: malformed `coverage` attribute input + --> $DIR/malformed-attrs.rs:88:1 + | +LL | #[coverage] + | ^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | +++++ +LL | #[coverage(on)] + | ++++ + +error: malformed `no_sanitize` attribute input + --> $DIR/malformed-attrs.rs:90:1 + | +LL | #[no_sanitize] + | ^^^^^^^^^^^^^^ help: must be of the form: `#[no_sanitize(address, kcfi, memory, thread)]` + +error: malformed `no_implicit_prelude` attribute input + --> $DIR/malformed-attrs.rs:95:1 + | +LL | #[no_implicit_prelude = 23] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[no_implicit_prelude]` + +error: malformed `proc_macro` attribute input + --> $DIR/malformed-attrs.rs:97:1 + | +LL | #[proc_macro = 18] + | ^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[proc_macro]` + +error: malformed `instruction_set` attribute input + --> $DIR/malformed-attrs.rs:104:1 + | +LL | #[instruction_set] + | ^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[instruction_set(set)]` + +error: malformed `patchable_function_entry` attribute input + --> $DIR/malformed-attrs.rs:106:1 + | +LL | #[patchable_function_entry] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[patchable_function_entry(prefix_nops = m, entry_nops = n)]` + +error: malformed `coroutine` attribute input + --> $DIR/malformed-attrs.rs:109:5 + | +LL | #[coroutine = 63] || {} + | ^^^^^^^^^^^^^^^^^ help: must be of the form: `#[coroutine]` + +error: malformed `proc_macro_attribute` attribute input + --> $DIR/malformed-attrs.rs:114:1 + | +LL | #[proc_macro_attribute = 19] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[proc_macro_attribute]` + +error: malformed `proc_macro_derive` attribute input + --> $DIR/malformed-attrs.rs:121:1 + | +LL | #[proc_macro_derive] + | ^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` + +error: malformed `must_not_suspend` attribute input + --> $DIR/malformed-attrs.rs:130:1 + | +LL | #[must_not_suspend()] + | ^^^^^^^^^^^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL - #[must_not_suspend()] +LL + #[must_not_suspend = "reason"] + | +LL - #[must_not_suspend()] +LL + #[must_not_suspend] + | + +error: malformed `cfi_encoding` attribute input + --> $DIR/malformed-attrs.rs:132:1 + | +LL | #[cfi_encoding] + | ^^^^^^^^^^^^^^^ help: must be of the form: `#[cfi_encoding = "encoding"]` + +error: malformed `type_const` attribute input + --> $DIR/malformed-attrs.rs:141:5 + | +LL | #[type_const = 1] + | ^^^^^^^^^^^^^^^^^ help: must be of the form: `#[type_const]` + +error: malformed `marker` attribute input + --> $DIR/malformed-attrs.rs:153:1 + | +LL | #[marker = 3] + | ^^^^^^^^^^^^^ help: must be of the form: `#[marker]` + +error: malformed `fundamental` attribute input + --> $DIR/malformed-attrs.rs:155:1 + | +LL | #[fundamental()] + | ^^^^^^^^^^^^^^^^ help: must be of the form: `#[fundamental]` + +error: malformed `ffi_pure` attribute input + --> $DIR/malformed-attrs.rs:163:5 + | +LL | #[unsafe(ffi_pure = 1)] + | ^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[ffi_pure]` + +error: malformed `link_ordinal` attribute input + --> $DIR/malformed-attrs.rs:165:5 + | +LL | #[link_ordinal] + | ^^^^^^^^^^^^^^^ help: must be of the form: `#[link_ordinal(ordinal)]` + +error: malformed `ffi_const` attribute input + --> $DIR/malformed-attrs.rs:169:5 + | +LL | #[unsafe(ffi_const = 1)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[ffi_const]` + +error: malformed `linkage` attribute input + --> $DIR/malformed-attrs.rs:171:5 + | +LL | #[linkage] + | ^^^^^^^^^^ help: must be of the form: `#[linkage = "external|internal|..."]` + +error: malformed `allow` attribute input + --> $DIR/malformed-attrs.rs:176:1 + | +LL | #[allow] + | ^^^^^^^^ help: must be of the form: `#[allow(lint1, lint2, ..., /*opt*/ reason = "...")]` + +error: malformed `expect` attribute input + --> $DIR/malformed-attrs.rs:178:1 + | +LL | #[expect] + | ^^^^^^^^^ help: must be of the form: `#[expect(lint1, lint2, ..., /*opt*/ reason = "...")]` + +error: malformed `warn` attribute input + --> $DIR/malformed-attrs.rs:180:1 + | +LL | #[warn] + | ^^^^^^^ help: must be of the form: `#[warn(lint1, lint2, ..., /*opt*/ reason = "...")]` + +error: malformed `deny` attribute input + --> $DIR/malformed-attrs.rs:182:1 + | +LL | #[deny] + | ^^^^^^^ help: must be of the form: `#[deny(lint1, lint2, ..., /*opt*/ reason = "...")]` + +error: malformed `forbid` attribute input + --> $DIR/malformed-attrs.rs:184:1 + | +LL | #[forbid] + | ^^^^^^^^^ help: must be of the form: `#[forbid(lint1, lint2, ..., /*opt*/ reason = "...")]` + +error: malformed `debugger_visualizer` attribute input + --> $DIR/malformed-attrs.rs:186:1 + | +LL | #[debugger_visualizer] + | ^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[debugger_visualizer(natvis_file = "...", gdb_script_file = "...")]` + +error: malformed `automatically_derived` attribute input + --> $DIR/malformed-attrs.rs:189:1 + | +LL | #[automatically_derived = 18] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[automatically_derived]` + +error: malformed `non_exhaustive` attribute input + --> $DIR/malformed-attrs.rs:195:1 + | +LL | #[non_exhaustive = 1] + | ^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[non_exhaustive]` + +error: malformed `thread_local` attribute input + --> $DIR/malformed-attrs.rs:201:1 + | +LL | #[thread_local()] + | ^^^^^^^^^^^^^^^^^ help: must be of the form: `#[thread_local]` + +error: malformed `no_link` attribute input + --> $DIR/malformed-attrs.rs:205:1 + | +LL | #[no_link()] + | ^^^^^^^^^^^^ help: must be of the form: `#[no_link]` + +error: malformed `macro_use` attribute input + --> $DIR/malformed-attrs.rs:207:1 + | +LL | #[macro_use = 1] + | ^^^^^^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL - #[macro_use = 1] +LL + #[macro_use(name1, name2, ...)] + | +LL - #[macro_use = 1] +LL + #[macro_use] + | + +error: malformed `macro_export` attribute input + --> $DIR/malformed-attrs.rs:212:1 + | +LL | #[macro_export = 18] + | ^^^^^^^^^^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL - #[macro_export = 18] +LL + #[macro_export(local_inner_macros)] + | +LL - #[macro_export = 18] +LL + #[macro_export] + | + +error: malformed `allow_internal_unsafe` attribute input + --> $DIR/malformed-attrs.rs:214:1 + | +LL | #[allow_internal_unsafe = 1] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[allow_internal_unsafe]` + +error: the `#[proc_macro]` attribute is only usable with crates of the `proc-macro` crate type + --> $DIR/malformed-attrs.rs:97:1 + | +LL | #[proc_macro = 18] + | ^^^^^^^^^^^^^^^^^^ + +error: the `#[proc_macro_attribute]` attribute is only usable with crates of the `proc-macro` crate type + --> $DIR/malformed-attrs.rs:114:1 + | +LL | #[proc_macro_attribute = 19] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type + --> $DIR/malformed-attrs.rs:121:1 + | +LL | #[proc_macro_derive] + | ^^^^^^^^^^^^^^^^^^^^ + +error[E0658]: allow_internal_unsafe side-steps the unsafe_code lint + --> $DIR/malformed-attrs.rs:214:1 + | +LL | #[allow_internal_unsafe = 1] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(allow_internal_unsafe)]` 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: valid forms for the attribute are `#[doc(hidden|inline|...)]` and `#[doc = "string"]` + --> $DIR/malformed-attrs.rs:42:1 + | +LL | #[doc] + | ^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: `#[deny(ill_formed_attribute_input)]` on by default + +error: valid forms for the attribute are `#[doc(hidden|inline|...)]` and `#[doc = "string"]` + --> $DIR/malformed-attrs.rs:74:1 + | +LL | #[doc] + | ^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571> + +error: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...", /*opt*/ import_name_type = "decorated|noprefix|undecorated")]` + --> $DIR/malformed-attrs.rs:81:1 + | +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! + = note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571> + +error: valid forms for the attribute are `#[ignore]` and `#[ignore = "reason"]` + --> $DIR/malformed-attrs.rs:92:1 + | +LL | #[ignore()] + | ^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571> + +error: invalid argument + --> $DIR/malformed-attrs.rs:186:1 + | +LL | #[debugger_visualizer] + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = note: expected: `natvis_file = "..."` + = note: OR + = note: expected: `gdb_script_file = "..."` + +error[E0539]: malformed `export_name` attribute input + --> $DIR/malformed-attrs.rs:32:1 + | +LL | #[unsafe(export_name)] + | ^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[export_name = "name"]` + +error: `rustc_allow_const_fn_unstable` expects a list of feature names + --> $DIR/malformed-attrs.rs:34:1 + | +LL | #[rustc_allow_const_fn_unstable] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: `allow_internal_unstable` expects a list of feature names + --> $DIR/malformed-attrs.rs:36:1 + | +LL | #[allow_internal_unstable] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0539]: malformed `rustc_confusables` attribute input + --> $DIR/malformed-attrs.rs:38:1 + | +LL | #[rustc_confusables] + | ^^^^^^^^^^^^^^^^^^^^ + | | + | expected this to be a list + | help: must be of the form: `#[rustc_confusables("name1", "name2", ...)]` + +error[E0539]: malformed `deprecated` attribute input + --> $DIR/malformed-attrs.rs:40:1 + | +LL | #[deprecated = 5] + | ^^^^^^^^^^^^^^^-^ + | | + | expected a string literal here + | +help: try changing it to one of the following valid forms of the attribute + | +LL - #[deprecated = 5] +LL + #[deprecated = "reason"] + | +LL - #[deprecated = 5] +LL + #[deprecated(/*opt*/ since = "version", /*opt*/ note = "reason")] + | +LL - #[deprecated = 5] +LL + #[deprecated] + | + +error[E0539]: malformed `rustc_macro_transparency` attribute input + --> $DIR/malformed-attrs.rs:45:1 + | +LL | #[rustc_macro_transparency] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_macro_transparency = "transparent|semitransparent|opaque"]` + +error[E0539]: malformed `repr` attribute input + --> $DIR/malformed-attrs.rs:47:1 + | +LL | #[repr] + | ^^^^^^^ + | | + | expected this to be a list + | help: must be of the form: `#[repr(C | Rust | align(...) | packed(...) | <integer type> | transparent)]` + +error[E0565]: malformed `rustc_as_ptr` attribute input + --> $DIR/malformed-attrs.rs:49:1 + | +LL | #[rustc_as_ptr = 5] + | ^^^^^^^^^^^^^^^---^ + | | | + | | didn't expect any arguments here + | help: must be of the form: `#[rustc_as_ptr]` + +error[E0539]: malformed `align` attribute input + --> $DIR/malformed-attrs.rs:54:1 + | +LL | #[align] + | ^^^^^^^^ + | | + | expected this to be a list + | help: must be of the form: `#[align(<alignment in bytes>)]` + +error[E0539]: malformed `optimize` attribute input + --> $DIR/malformed-attrs.rs:56:1 + | +LL | #[optimize] + | ^^^^^^^^^^^ + | | + | expected this to be a list + | help: must be of the form: `#[optimize(size|speed|none)]` + +error[E0565]: malformed `cold` attribute input + --> $DIR/malformed-attrs.rs:58:1 + | +LL | #[cold = 1] + | ^^^^^^^---^ + | | | + | | didn't expect any arguments here + | help: must be of the form: `#[cold]` + +error: valid forms for the attribute are `#[must_use = "reason"]` and `#[must_use]` + --> $DIR/malformed-attrs.rs:60:1 + | +LL | #[must_use()] + | ^^^^^^^^^^^^^ + +error[E0565]: malformed `no_mangle` attribute input + --> $DIR/malformed-attrs.rs:62:1 + | +LL | #[no_mangle = 1] + | ^^^^^^^^^^^^---^ + | | | + | | didn't expect any arguments here + | help: must be of the form: `#[no_mangle]` + +error[E0565]: malformed `naked` attribute input + --> $DIR/malformed-attrs.rs:64:1 + | +LL | #[unsafe(naked())] + | ^^^^^^^^^^^^^^--^^ + | | | + | | didn't expect any arguments here + | help: must be of the form: `#[naked]` + +error[E0565]: malformed `track_caller` attribute input + --> $DIR/malformed-attrs.rs:66:1 + | +LL | #[track_caller()] + | ^^^^^^^^^^^^^^--^ + | | | + | | didn't expect any arguments here + | help: must be of the form: `#[track_caller]` + +error[E0539]: malformed `export_name` attribute input + --> $DIR/malformed-attrs.rs:68:1 + | +LL | #[export_name()] + | ^^^^^^^^^^^^^^^^ help: must be of the form: `#[export_name = "name"]` + +error[E0805]: malformed `used` attribute input + --> $DIR/malformed-attrs.rs:70:1 + | +LL | #[used()] + | ^^^^^^--^ + | | + | expected a single argument here + | +help: try changing it to one of the following valid forms of the attribute + | +LL | #[used(compiler|linker)] + | +++++++++++++++ +LL - #[used()] +LL + #[used] + | + +error[E0539]: malformed `link_name` attribute input + --> $DIR/malformed-attrs.rs:84:1 + | +LL | #[link_name] + | ^^^^^^^^^^^^ help: must be of the form: `#[link_name = "name"]` + +error[E0539]: malformed `link_section` attribute input + --> $DIR/malformed-attrs.rs:86:1 + | +LL | #[link_section] + | ^^^^^^^^^^^^^^^ help: must be of the form: `#[link_section = "name"]` + +error[E0539]: malformed `must_use` attribute input + --> $DIR/malformed-attrs.rs:117:1 + | +LL | #[must_use = 1] + | ^^^^^^^^^^^^^-^ + | | + | expected a string literal here + | +help: try changing it to one of the following valid forms of the attribute + | +LL - #[must_use = 1] +LL + #[must_use = "reason"] + | +LL - #[must_use = 1] +LL + #[must_use] + | + +error[E0539]: malformed `rustc_layout_scalar_valid_range_start` attribute input + --> $DIR/malformed-attrs.rs:126:1 + | +LL | #[rustc_layout_scalar_valid_range_start] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | expected this to be a list + | help: must be of the form: `#[rustc_layout_scalar_valid_range_start(start)]` + +error[E0539]: malformed `rustc_layout_scalar_valid_range_end` attribute input + --> $DIR/malformed-attrs.rs:128:1 + | +LL | #[rustc_layout_scalar_valid_range_end] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | expected this to be a list + | help: must be of the form: `#[rustc_layout_scalar_valid_range_end(end)]` + +warning: `#[diagnostic::do_not_recommend]` does not expect any arguments + --> $DIR/malformed-attrs.rs:147:1 + | +LL | #[diagnostic::do_not_recommend()] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default + +warning: missing options for `on_unimplemented` attribute + --> $DIR/malformed-attrs.rs:136:1 + | +LL | #[diagnostic::on_unimplemented] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: at least one of the `message`, `note` and `label` options are expected + +warning: malformed `on_unimplemented` attribute + --> $DIR/malformed-attrs.rs:138:1 + | +LL | #[diagnostic::on_unimplemented = 1] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid option found here + | + = help: only `message`, `note` and `label` are allowed as options + +error: valid forms for the attribute are `#[inline(always|never)]` and `#[inline]` + --> $DIR/malformed-attrs.rs:51:1 + | +LL | #[inline = 5] + | ^^^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571> + +error[E0308]: mismatched types + --> $DIR/malformed-attrs.rs:109:23 + | +LL | fn test() { + | - help: a return type might be missing here: `-> _` +LL | #[coroutine = 63] || {} + | ^^^^^ expected `()`, found coroutine + | + = note: expected unit type `()` + found coroutine `{coroutine@$DIR/malformed-attrs.rs:109:23: 109:25}` + +error: aborting due to 72 previous errors; 3 warnings emitted + +Some errors have detailed explanations: E0308, E0463, E0539, E0565, E0658, E0805. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/closures/missing-body.rs b/tests/ui/closures/missing-body.rs new file mode 100644 index 00000000000..461c2be3ccd --- /dev/null +++ b/tests/ui/closures/missing-body.rs @@ -0,0 +1,7 @@ +// Checks that the compiler complains about the missing closure body and does not +// crash. +// This is a regression test for <https://github.com/rust-lang/rust/issues/143128>. + +fn main() { |b: [str; _]| {}; } +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for closures +//~| ERROR the size for values of type `str` cannot be known at compilation time diff --git a/tests/ui/closures/missing-body.stderr b/tests/ui/closures/missing-body.stderr new file mode 100644 index 00000000000..33580fc2fbd --- /dev/null +++ b/tests/ui/closures/missing-body.stderr @@ -0,0 +1,19 @@ +error[E0121]: the placeholder `_` is not allowed within types on item signatures for closures + --> $DIR/missing-body.rs:5:23 + | +LL | fn main() { |b: [str; _]| {}; } + | ^ not allowed in type signatures + +error[E0277]: the size for values of type `str` cannot be known at compilation time + --> $DIR/missing-body.rs:5:17 + | +LL | fn main() { |b: [str; _]| {}; } + | ^^^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `str` + = note: slice and array elements must have `Sized` type + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0121, E0277. +For more information about an error, try `rustc --explain E0121`. 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..64c31beba28 --- /dev/null +++ b/tests/ui/codegen/maximal-hir-to-mir-coverage-flag.rs @@ -0,0 +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 + +fn main() { + let x = 1; + let y = x + 1; + println!("{y}"); +} 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..045d82b761f --- /dev/null +++ b/tests/ui/codegen/mono-respects-abi-alignment.rs @@ -0,0 +1,37 @@ +//! 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<A>` and `S<B>` have field `t` at different offsets, +//! leading to incorrect method dispatch for `unwrap()`. + +//@ run-pass + +#[derive(Copy, Clone)] +struct S<T> { + #[allow(dead_code)] + i: u8, + t: T, +} + +impl<T> S<T> { + fn unwrap(self) -> T { + self.t + } +} + +#[derive(Copy, Clone, PartialEq, Debug)] +struct A((u32, u32)); // Different ABI alignment than B + +#[derive(Copy, Clone, PartialEq, Debug)] +struct B(u64); // Different ABI alignment than A + +pub fn main() { + static CA: S<A> = S { i: 0, t: A((13, 104)) }; + static CB: S<B> = 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..ba97acec822 --- /dev/null +++ b/tests/ui/codegen/msvc-opt-level-z-no-corruption.rs @@ -0,0 +1,37 @@ +//! 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 <https://github.com/rust-lang/rust/issues/45034>. + +//@ ignore-cross-compile +// Reason: the compiled binary is executed +//@ only-windows +// Reason: the observed bug only occurred on Windows MSVC targets +//@ 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 due to incorrect register allocation + let y: fn(i32, i32) -> i64 = test::black_box(foo); + test::black_box(y(1, 2)); +} + +fn main() { + bar(); +} 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..3a110bdad35 --- /dev/null +++ b/tests/ui/compiletest-self-test/ui-test-missing-annotations-detection.rs @@ -0,0 +1,9 @@ +//! 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 + +//@ should-fail + +fn main() {} diff --git a/tests/ui/consts/const-fn-type-name.rs b/tests/ui/consts/const-fn-type-name.rs index 5403c26b979..733ab79b7cd 100644 --- a/tests/ui/consts/const-fn-type-name.rs +++ b/tests/ui/consts/const-fn-type-name.rs @@ -5,7 +5,7 @@ #![allow(dead_code)] const fn type_name_wrapper<T>(_: &T) -> &'static str { - core::intrinsics::type_name::<T>() + const { core::intrinsics::type_name::<T>() } } struct Struct<TA, TB, TC> { 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..26f527f7664 --- /dev/null +++ b/tests/ui/derives/derive-Debug-enum-variants.rs @@ -0,0 +1,30 @@ +//! Test that `#[derive(Debug)]` for enums correctly formats variant names. + +//@ run-pass + +#[derive(Debug)] +enum Foo { + A(usize), + C, +} + +#[derive(Debug)] +enum Bar { + D, +} + +pub fn main() { + // 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/did_you_mean/bad-assoc-ty.edition2015.stderr b/tests/ui/did_you_mean/bad-assoc-ty.edition2015.stderr index fe1ce5ad18b..ed6e5c3e0c0 100644 --- a/tests/ui/did_you_mean/bad-assoc-ty.edition2015.stderr +++ b/tests/ui/did_you_mean/bad-assoc-ty.edition2015.stderr @@ -302,7 +302,7 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures LL | trait P<F> where F: Fn() -> _ { | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions --> $DIR/bad-assoc-ty.rs:88:38 | LL | fn foo<F>(_: F) where F: Fn() -> _ {} diff --git a/tests/ui/did_you_mean/bad-assoc-ty.edition2021.stderr b/tests/ui/did_you_mean/bad-assoc-ty.edition2021.stderr index 2cf7a150aa2..2ee8ab2760a 100644 --- a/tests/ui/did_you_mean/bad-assoc-ty.edition2021.stderr +++ b/tests/ui/did_you_mean/bad-assoc-ty.edition2021.stderr @@ -284,7 +284,7 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures LL | trait P<F> where F: Fn() -> _ { | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions --> $DIR/bad-assoc-ty.rs:88:38 | LL | fn foo<F>(_: F) where F: Fn() -> _ {} diff --git a/tests/ui/did_you_mean/bad-assoc-ty.rs b/tests/ui/did_you_mean/bad-assoc-ty.rs index 9abda4fd962..39f0a84855a 100644 --- a/tests/ui/did_you_mean/bad-assoc-ty.rs +++ b/tests/ui/did_you_mean/bad-assoc-ty.rs @@ -86,7 +86,7 @@ trait P<F> where F: Fn() -> _ { trait Q { fn foo<F>(_: F) where F: Fn() -> _ {} - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated functions } fn main() {} diff --git a/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.fixed b/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.fixed index db18cf2ad96..0096d3eaea4 100644 --- a/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.fixed +++ b/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.fixed @@ -7,7 +7,7 @@ trait Foo<T>: Sized { impl Foo<usize> for () { fn bar(i: i32, t: usize, s: &()) -> (usize, i32) { - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated functions //~| ERROR type annotations needed (1, 2) } diff --git a/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.rs b/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.rs index 1217a96112d..9ebc565b8fd 100644 --- a/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.rs +++ b/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.rs @@ -7,7 +7,7 @@ trait Foo<T>: Sized { impl Foo<usize> for () { fn bar(i: _, t: _, s: _) -> _ { - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated functions //~| ERROR type annotations needed (1, 2) } diff --git a/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.stderr b/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.stderr index 6c24a5899ea..3c11ad0cf29 100644 --- a/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.stderr +++ b/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.stderr @@ -1,4 +1,4 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions --> $DIR/replace-impl-infer-ty-from-trait.rs:9:15 | LL | fn bar(i: _, t: _, s: _) -> _ { diff --git a/tests/ui/diverging-fn-tail-35849.rs b/tests/ui/diverging-fn-tail-35849.rs deleted file mode 100644 index f21ce2973e9..00000000000 --- a/tests/ui/diverging-fn-tail-35849.rs +++ /dev/null @@ -1,8 +0,0 @@ -fn assert_sizeof() -> ! { - unsafe { - ::std::mem::transmute::<f64, [u8; 8]>(panic!()) - //~^ ERROR mismatched types - } -} - -fn main() { } diff --git a/tests/ui/early-ret-binop-add.rs b/tests/ui/early-ret-binop-add.rs deleted file mode 100644 index 3fec66f35fb..00000000000 --- a/tests/ui/early-ret-binop-add.rs +++ /dev/null @@ -1,10 +0,0 @@ -//@ run-pass - -#![allow(dead_code)] -#![allow(unreachable_code)] - -use std::ops::Add; - -fn wsucc<T:Add<Output=T> + Copy>(n: T) -> T { n + { return n } } - -pub fn main() { } diff --git a/tests/ui/elide-errors-on-mismatched-tuple.rs b/tests/ui/elide-errors-on-mismatched-tuple.rs deleted file mode 100644 index 7d87b0a7756..00000000000 --- a/tests/ui/elide-errors-on-mismatched-tuple.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Hide irrelevant E0277 errors (#50333) - -trait T {} - -struct A; -impl T for A {} -impl A { - fn new() -> Self { - Self {} - } -} - -fn main() { - let (a, b, c) = (A::new(), A::new()); // This tuple is 2 elements, should be three - //~^ ERROR mismatched types - let ts: Vec<&dyn T> = vec![&a, &b, &c]; - // There is no E0277 error above, as `a`, `b` and `c` are `TyErr` -} diff --git a/tests/ui/elided-test.rs b/tests/ui/elided-test.rs deleted file mode 100644 index 2bedc25e17b..00000000000 --- a/tests/ui/elided-test.rs +++ /dev/null @@ -1,5 +0,0 @@ -// Since we're not compiling a test runner this function should be elided -// and the build will fail because main doesn't exist -#[test] -fn main() { -} //~ ERROR `main` function not found in crate `elided_test` diff --git a/tests/ui/elided-test.stderr b/tests/ui/elided-test.stderr deleted file mode 100644 index 7aebe5d8264..00000000000 --- a/tests/ui/elided-test.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0601]: `main` function not found in crate `elided_test` - --> $DIR/elided-test.rs:5:2 - | -LL | } - | ^ consider adding a `main` function to `$DIR/elided-test.rs` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0601`. diff --git a/tests/ui/else-if.rs b/tests/ui/else-if.rs deleted file mode 100644 index 2161b28c58c..00000000000 --- a/tests/ui/else-if.rs +++ /dev/null @@ -1,20 +0,0 @@ -//@ run-pass - -pub fn main() { - if 1 == 2 { - assert!((false)); - } else if 2 == 3 { - assert!((false)); - } else if 3 == 4 { assert!((false)); } else { assert!((true)); } - if 1 == 2 { assert!((false)); } else if 2 == 2 { assert!((true)); } - if 1 == 2 { - assert!((false)); - } else if 2 == 2 { - if 1 == 1 { - assert!((true)); - } else { if 2 == 1 { assert!((false)); } else { assert!((false)); } } - } - if 1 == 2 { - assert!((false)); - } else { if 1 == 2 { assert!((false)); } else { assert!((true)); } } -} diff --git a/tests/ui/expr/early-return-in-binop.rs b/tests/ui/expr/early-return-in-binop.rs new file mode 100644 index 00000000000..389d25210f7 --- /dev/null +++ b/tests/ui/expr/early-return-in-binop.rs @@ -0,0 +1,19 @@ +//! Test early return within binary operation expressions + +//@ run-pass + +#![allow(dead_code)] +#![allow(unreachable_code)] + +use std::ops::Add; + +/// Function that performs addition with an early return in the right operand +fn add_with_early_return<T: Add<Output = T> + Copy>(n: T) -> T { + n + { return n } +} + +pub fn main() { + // Test with different numeric types to ensure generic behavior works + let _result1 = add_with_early_return(42i32); + let _result2 = add_with_early_return(3.14f64); +} diff --git a/tests/ui/extern/issue-47725.rs b/tests/ui/extern/issue-47725.rs index 012673b9159..60d0cd62347 100644 --- a/tests/ui/extern/issue-47725.rs +++ b/tests/ui/extern/issue-47725.rs @@ -17,7 +17,6 @@ extern "C" { #[link_name] //~^ ERROR malformed `link_name` attribute input //~| HELP must be of the form -//~| NOTE expected this to be of the form `link_name = "..." extern "C" { fn bar() -> u32; } diff --git a/tests/ui/extern/issue-47725.stderr b/tests/ui/extern/issue-47725.stderr index 53d6b4927f8..4fd02a1778b 100644 --- a/tests/ui/extern/issue-47725.stderr +++ b/tests/ui/extern/issue-47725.stderr @@ -2,10 +2,7 @@ error[E0539]: malformed `link_name` attribute input --> $DIR/issue-47725.rs:17:1 | LL | #[link_name] - | ^^^^^^^^^^^^ - | | - | expected this to be of the form `link_name = "..."` - | help: must be of the form: `#[link_name = "name"]` + | ^^^^^^^^^^^^ help: must be of the form: `#[link_name = "name"]` warning: attribute should be applied to a foreign function or static --> $DIR/issue-47725.rs:3:1 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/logging-only-prints-once.rs b/tests/ui/fmt/debug-single-call.rs index bb8c29694b5..b59a766c71a 100644 --- a/tests/ui/logging-only-prints-once.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<isize>); diff --git a/tests/ui/fn/error-recovery-mismatch.stderr b/tests/ui/fn/error-recovery-mismatch.stderr index c046302cb91..10dab3052be 100644 --- a/tests/ui/fn/error-recovery-mismatch.stderr +++ b/tests/ui/fn/error-recovery-mismatch.stderr @@ -29,7 +29,7 @@ LL | fn fold<T>(&self, _: T, &self._) {} = note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686> = note: `#[warn(anonymous_parameters)]` on by default -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/error-recovery-mismatch.rs:11:35 | LL | fn fold<T>(&self, _: T, &self._) {} diff --git a/tests/ui/generics/unconstrained-type-params-inherent-impl.rs b/tests/ui/generics/unconstrained-type-params-inherent-impl.rs new file mode 100644 index 00000000000..c971de0d1f2 --- /dev/null +++ b/tests/ui/generics/unconstrained-type-params-inherent-impl.rs @@ -0,0 +1,32 @@ +//! Test for unconstrained type parameters in inherent implementations + +struct MyType; + +struct MyType1<T>(T); + +trait Bar { + type Out; +} + +impl<T> MyType { + //~^ ERROR the type parameter `T` is not constrained + // T is completely unused - this should fail +} + +impl<T> MyType1<T> { + // OK: T is used in the self type `MyType1<T>` +} + +impl<T, U> MyType1<T> { + //~^ ERROR the type parameter `U` is not constrained + // T is used in self type, but U is unconstrained - this should fail +} + +impl<T, U> MyType1<T> +where + T: Bar<Out = U>, +{ + // OK: T is used in self type, U is constrained through the where clause +} + +fn main() {} diff --git a/tests/ui/impl-unused-tps-inherent.stderr b/tests/ui/generics/unconstrained-type-params-inherent-impl.stderr index 43f63cf968c..19b02ad396c 100644 --- a/tests/ui/impl-unused-tps-inherent.stderr +++ b/tests/ui/generics/unconstrained-type-params-inherent-impl.stderr @@ -1,14 +1,14 @@ error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates - --> $DIR/impl-unused-tps-inherent.rs:9:6 + --> $DIR/unconstrained-type-params-inherent-impl.rs:11:6 | LL | impl<T> MyType { | ^ unconstrained type parameter error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates - --> $DIR/impl-unused-tps-inherent.rs:17:8 + --> $DIR/unconstrained-type-params-inherent-impl.rs:20:9 | -LL | impl<T,U> MyType1<T> { - | ^ unconstrained type parameter +LL | impl<T, U> MyType1<T> { + | ^ unconstrained type parameter error: aborting due to 2 previous errors diff --git a/tests/ui/impl-unused-rps-in-assoc-type.rs b/tests/ui/impl-unused-rps-in-assoc-type.rs deleted file mode 100644 index ea41997a698..00000000000 --- a/tests/ui/impl-unused-rps-in-assoc-type.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Test that lifetime parameters must be constrained if they appear in -// an associated type def'n. Issue #22077. - -trait Fun { - type Output; - fn call<'x>(&'x self) -> Self::Output; -} - -struct Holder { x: String } - -impl<'a> Fun for Holder { //~ ERROR E0207 - type Output = &'a str; - fn call<'b>(&'b self) -> &'b str { - &self.x[..] - } -} - -fn main() { } diff --git a/tests/ui/impl-unused-tps-inherent.rs b/tests/ui/impl-unused-tps-inherent.rs deleted file mode 100644 index 83a228e551a..00000000000 --- a/tests/ui/impl-unused-tps-inherent.rs +++ /dev/null @@ -1,25 +0,0 @@ -struct MyType; - -struct MyType1<T>(T); - -trait Bar { - type Out; -} - -impl<T> MyType { - //~^ ERROR the type parameter `T` is not constrained -} - -impl<T> MyType1<T> { - // OK, T is used in `Foo<T>`. -} - -impl<T,U> MyType1<T> { - //~^ ERROR the type parameter `U` is not constrained -} - -impl<T,U> MyType1<T> where T: Bar<Out=U> { - // OK, T is used in `Foo<T>`. -} - -fn main() { } diff --git a/tests/ui/implicit-method-bind.rs b/tests/ui/implicit-method-bind.rs deleted file mode 100644 index 5e27516a89a..00000000000 --- a/tests/ui/implicit-method-bind.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - let _f = 10i32.abs; //~ ERROR attempted to take value of method -} diff --git a/tests/ui/implicit-method-bind.stderr b/tests/ui/implicit-method-bind.stderr deleted file mode 100644 index e9357113f36..00000000000 --- a/tests/ui/implicit-method-bind.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0615]: attempted to take value of method `abs` on type `i32` - --> $DIR/implicit-method-bind.rs:2:20 - | -LL | let _f = 10i32.abs; - | ^^^ method, not a field - | -help: use parentheses to call the method - | -LL | let _f = 10i32.abs(); - | ++ - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0615`. diff --git a/tests/ui/double-type-import.rs b/tests/ui/imports/duplicate-use-bindings.rs index 6b1eb65d5ae..8cec23ea732 100644 --- a/tests/ui/double-type-import.rs +++ b/tests/ui/imports/duplicate-use-bindings.rs @@ -1,3 +1,5 @@ +//! Test that duplicate use bindings in same namespace produce error + mod foo { pub use self::bar::X; use self::bar::X; diff --git a/tests/ui/double-type-import.stderr b/tests/ui/imports/duplicate-use-bindings.stderr index 8a8fe05ec19..1d4f1fc82db 100644 --- a/tests/ui/double-type-import.stderr +++ b/tests/ui/imports/duplicate-use-bindings.stderr @@ -1,5 +1,5 @@ error[E0252]: the name `X` is defined multiple times - --> $DIR/double-type-import.rs:3:9 + --> $DIR/duplicate-use-bindings.rs:5:9 | LL | pub use self::bar::X; | ------------ previous import of the type `X` here diff --git a/tests/ui/integral-indexing.rs b/tests/ui/indexing/indexing-integral-types.rs index e20553af8a2..a91696a6fd5 100644 --- a/tests/ui/integral-indexing.rs +++ b/tests/ui/indexing/indexing-integral-types.rs @@ -1,16 +1,20 @@ +//! Test that only usize can be used for indexing arrays and slices. + pub fn main() { let v: Vec<isize> = 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[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()[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/indexing/indexing-integral-types.stderr index 26253e078cb..b63991ec2c4 100644 --- a/tests/ui/integral-indexing.stderr +++ b/tests/ui/indexing/indexing-integral-types.stderr @@ -1,5 +1,5 @@ error[E0277]: the type `[isize]` cannot be indexed by `u8` - --> $DIR/integral-indexing.rs:6:7 + --> $DIR/indexing-integral-types.rs:10:7 | LL | v[3u8]; | ^^^ slice indices are of type `usize` or ranges of `usize` @@ -11,7 +11,7 @@ LL | v[3u8]; = note: required for `Vec<isize>` to implement `Index<u8>` error[E0277]: the type `[isize]` cannot be indexed by `i8` - --> $DIR/integral-indexing.rs:7:7 + --> $DIR/indexing-integral-types.rs:11:7 | LL | v[3i8]; | ^^^ slice indices are of type `usize` or ranges of `usize` @@ -23,7 +23,7 @@ LL | v[3i8]; = note: required for `Vec<isize>` to implement `Index<i8>` error[E0277]: the type `[isize]` cannot be indexed by `u32` - --> $DIR/integral-indexing.rs:8:7 + --> $DIR/indexing-integral-types.rs:12:7 | LL | v[3u32]; | ^^^^ slice indices are of type `usize` or ranges of `usize` @@ -35,7 +35,7 @@ LL | v[3u32]; = note: required for `Vec<isize>` to implement `Index<u32>` error[E0277]: the type `[isize]` cannot be indexed by `i32` - --> $DIR/integral-indexing.rs:9:7 + --> $DIR/indexing-integral-types.rs:13:7 | LL | v[3i32]; | ^^^^ slice indices are of type `usize` or ranges of `usize` @@ -47,7 +47,7 @@ LL | v[3i32]; = note: required for `Vec<isize>` to implement `Index<i32>` error[E0277]: the type `[u8]` cannot be indexed by `u8` - --> $DIR/integral-indexing.rs:12:18 + --> $DIR/indexing-integral-types.rs:16:18 | LL | s.as_bytes()[3u8]; | ^^^ slice indices are of type `usize` or ranges of `usize` @@ -59,7 +59,7 @@ LL | s.as_bytes()[3u8]; = note: required for `[u8]` to implement `Index<u8>` error[E0277]: the type `[u8]` cannot be indexed by `i8` - --> $DIR/integral-indexing.rs:13:18 + --> $DIR/indexing-integral-types.rs:17:18 | LL | s.as_bytes()[3i8]; | ^^^ slice indices are of type `usize` or ranges of `usize` @@ -71,7 +71,7 @@ LL | s.as_bytes()[3i8]; = note: required for `[u8]` to implement `Index<i8>` error[E0277]: the type `[u8]` cannot be indexed by `u32` - --> $DIR/integral-indexing.rs:14:18 + --> $DIR/indexing-integral-types.rs:18:18 | LL | s.as_bytes()[3u32]; | ^^^^ slice indices are of type `usize` or ranges of `usize` @@ -83,7 +83,7 @@ LL | s.as_bytes()[3u32]; = note: required for `[u8]` to implement `Index<u32>` error[E0277]: the type `[u8]` cannot be indexed by `i32` - --> $DIR/integral-indexing.rs:15:18 + --> $DIR/indexing-integral-types.rs:19:18 | LL | s.as_bytes()[3i32]; | ^^^^ slice indices are of type `usize` or ranges of `usize` diff --git a/tests/ui/inlined-main.rs b/tests/ui/inlined-main.rs deleted file mode 100644 index 731ac0dddca..00000000000 --- a/tests/ui/inlined-main.rs +++ /dev/null @@ -1,4 +0,0 @@ -//@ run-pass - -#[inline(always)] -fn main() {} 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<T> { What } //~ ERROR parameter `T` is never used - -fn foo<T>() { - static a: Bar<T> = Bar::What; -//~^ ERROR can't use generic parameters from outer item -} - -fn main() { -} diff --git a/tests/ui/invalid/invalid_rustc_layout_scalar_valid_range.stderr b/tests/ui/invalid/invalid_rustc_layout_scalar_valid_range.stderr index 7879e7358c0..8b9ad78db37 100644 --- a/tests/ui/invalid/invalid_rustc_layout_scalar_valid_range.stderr +++ b/tests/ui/invalid/invalid_rustc_layout_scalar_valid_range.stderr @@ -1,20 +1,38 @@ -error: expected exactly one integer literal argument +error[E0539]: malformed `rustc_layout_scalar_valid_range_start` attribute input --> $DIR/invalid_rustc_layout_scalar_valid_range.rs:3:1 | LL | #[rustc_layout_scalar_valid_range_start(u32::MAX)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------^^ + | | | + | | expected an integer literal here + | help: must be of the form: `#[rustc_layout_scalar_valid_range_start(start)]` -error: expected exactly one integer literal argument +error[E0805]: malformed `rustc_layout_scalar_valid_range_end` attribute input --> $DIR/invalid_rustc_layout_scalar_valid_range.rs:6:1 | LL | #[rustc_layout_scalar_valid_range_end(1, 2)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------^ + | | | + | | expected a single argument here + | help: must be of the form: `#[rustc_layout_scalar_valid_range_end(end)]` -error: expected exactly one integer literal argument +error[E0539]: malformed `rustc_layout_scalar_valid_range_end` attribute input --> $DIR/invalid_rustc_layout_scalar_valid_range.rs:9:1 | LL | #[rustc_layout_scalar_valid_range_end(a = "a")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------^^ + | | | + | | expected an integer literal here + | help: must be of the form: `#[rustc_layout_scalar_valid_range_end(end)]` + +error[E0539]: malformed `rustc_layout_scalar_valid_range_start` attribute input + --> $DIR/invalid_rustc_layout_scalar_valid_range.rs:18:1 + | +LL | #[rustc_layout_scalar_valid_range_start(rustc_layout_scalar_valid_range_start)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------------------------------^^ + | | | + | | expected an integer literal here + | help: must be of the form: `#[rustc_layout_scalar_valid_range_start(start)]` error: attribute should be applied to a struct --> $DIR/invalid_rustc_layout_scalar_valid_range.rs:12:1 @@ -27,11 +45,7 @@ LL | | Y = 14, LL | | } | |_- not a struct -error: expected exactly one integer literal argument - --> $DIR/invalid_rustc_layout_scalar_valid_range.rs:18:1 - | -LL | #[rustc_layout_scalar_valid_range_start(rustc_layout_scalar_valid_range_start)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - error: aborting due to 5 previous errors +Some errors have detailed explanations: E0539, E0805. +For more information about an error, try `rustc --explain E0539`. diff --git a/tests/ui/auxiliary/msvc-data-only-lib.rs b/tests/ui/linkage-attr/auxiliary/msvc-static-data-import-lib.rs index b8a8f905e8b..b8a8f905e8b 100644 --- a/tests/ui/auxiliary/msvc-data-only-lib.rs +++ b/tests/ui/linkage-attr/auxiliary/msvc-static-data-import-lib.rs diff --git a/tests/ui/link-section.rs b/tests/ui/linkage-attr/link-section-placement.rs index a8de8c2e1e7..6a143bfedb4 100644 --- a/tests/ui/link-section.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/linkage-attr/msvc-static-data-import.rs b/tests/ui/linkage-attr/msvc-static-data-import.rs new file mode 100644 index 00000000000..e53eb404ef6 --- /dev/null +++ b/tests/ui/linkage-attr/msvc-static-data-import.rs @@ -0,0 +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_<symbol>` 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 <https://github.com/rust-lang/rust/issues/26591>. +//! Fixed in <https://github.com/rust-lang/rust/pull/28646>. + +//@ run-pass +//@ aux-build:msvc-static-data-import-lib.rs + +extern crate msvc_static_data_import_lib; + +fn main() { + println!("The answer is {}!", msvc_static_data_import_lib::FOO); +} diff --git a/tests/ui/missing_debug_impls.rs b/tests/ui/lint/missing-debug-implementations-lint.rs index 3abc0706887..8a93f052f9c 100644 --- a/tests/ui/missing_debug_impls.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/missing_debug_impls.stderr b/tests/ui/lint/missing-debug-implementations-lint.stderr index 0538f207b44..288ab981034 100644 --- a/tests/ui/missing_debug_impls.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/lint/unused/must-use-macros.fixed b/tests/ui/lint/unused/must-use-macros.fixed new file mode 100644 index 00000000000..609d0c6392b --- /dev/null +++ b/tests/ui/lint/unused/must-use-macros.fixed @@ -0,0 +1,60 @@ +// Makes sure the suggestions of the `unused_must_use` lint are not inside +// +// See <https://github.com/rust-lang/rust/issues/143025> + +//@ check-pass +//@ run-rustfix + +#![expect(unused_macros)] +#![warn(unused_must_use)] + +fn main() { + { + macro_rules! cmp { + ($a:tt, $b:tt) => { + $a == $b + }; + } + + // FIXME(Urgau): For some unknown reason the spans we get are not + // recorded to be from any expansions, preventing us from either + // suggesting in front of the macro or not at all. + // cmp!(1, 1); + } + + { + macro_rules! cmp { + ($a:ident, $b:ident) => { + $a == $b + }; //~^ WARN unused comparison that must be used + } + + let a = 1; + let b = 1; + let _ = cmp!(a, b); + //~^ SUGGESTION let _ + } + + { + macro_rules! cmp { + ($a:expr, $b:expr) => { + $a == $b + }; //~^ WARN unused comparison that must be used + } + + let _ = cmp!(1, 1); + //~^ SUGGESTION let _ + } + + { + macro_rules! cmp { + ($a:tt, $b:tt) => { + $a.eq(&$b) + }; + } + + let _ = cmp!(1, 1); + //~^ WARN unused return value + //~| SUGGESTION let _ + } +} diff --git a/tests/ui/lint/unused/must-use-macros.rs b/tests/ui/lint/unused/must-use-macros.rs new file mode 100644 index 00000000000..63e246ed374 --- /dev/null +++ b/tests/ui/lint/unused/must-use-macros.rs @@ -0,0 +1,60 @@ +// Makes sure the suggestions of the `unused_must_use` lint are not inside +// +// See <https://github.com/rust-lang/rust/issues/143025> + +//@ check-pass +//@ run-rustfix + +#![expect(unused_macros)] +#![warn(unused_must_use)] + +fn main() { + { + macro_rules! cmp { + ($a:tt, $b:tt) => { + $a == $b + }; + } + + // FIXME(Urgau): For some unknown reason the spans we get are not + // recorded to be from any expansions, preventing us from either + // suggesting in front of the macro or not at all. + // cmp!(1, 1); + } + + { + macro_rules! cmp { + ($a:ident, $b:ident) => { + $a == $b + }; //~^ WARN unused comparison that must be used + } + + let a = 1; + let b = 1; + cmp!(a, b); + //~^ SUGGESTION let _ + } + + { + macro_rules! cmp { + ($a:expr, $b:expr) => { + $a == $b + }; //~^ WARN unused comparison that must be used + } + + cmp!(1, 1); + //~^ SUGGESTION let _ + } + + { + macro_rules! cmp { + ($a:tt, $b:tt) => { + $a.eq(&$b) + }; + } + + cmp!(1, 1); + //~^ WARN unused return value + //~| SUGGESTION let _ + } +} diff --git a/tests/ui/lint/unused/must-use-macros.stderr b/tests/ui/lint/unused/must-use-macros.stderr new file mode 100644 index 00000000000..2ad174e10b5 --- /dev/null +++ b/tests/ui/lint/unused/must-use-macros.stderr @@ -0,0 +1,48 @@ +warning: unused comparison that must be used + --> $DIR/must-use-macros.rs:28:17 + | +LL | $a == $b + | ^^^^^^^^ the comparison produces a value +... +LL | cmp!(a, b); + | ---------- in this macro invocation + | +note: the lint level is defined here + --> $DIR/must-use-macros.rs:9:9 + | +LL | #![warn(unused_must_use)] + | ^^^^^^^^^^^^^^^ + = note: this warning originates in the macro `cmp` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = cmp!(a, b); + | +++++++ + +warning: unused comparison that must be used + --> $DIR/must-use-macros.rs:41:17 + | +LL | $a == $b + | ^^^^^^^^ the comparison produces a value +... +LL | cmp!(1, 1); + | ---------- in this macro invocation + | + = note: this warning originates in the macro `cmp` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = cmp!(1, 1); + | +++++++ + +warning: unused return value of `std::cmp::PartialEq::eq` that must be used + --> $DIR/must-use-macros.rs:56:9 + | +LL | cmp!(1, 1); + | ^^^^^^^^^^ + | +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = cmp!(1, 1); + | +++++++ + +warning: 3 warnings emitted + 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 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/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/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/macros/macro-metavar-expr-concat/allowed-operations.rs b/tests/ui/macros/metavar-expressions/concat-allowed-operations.rs index 695a752fe17..695a752fe17 100644 --- a/tests/ui/macros/macro-metavar-expr-concat/allowed-operations.rs +++ b/tests/ui/macros/metavar-expressions/concat-allowed-operations.rs diff --git a/tests/ui/macros/macro-metavar-expr-concat/hygiene.rs b/tests/ui/macros/metavar-expressions/concat-hygiene.rs index 24b0e36498a..24b0e36498a 100644 --- a/tests/ui/macros/macro-metavar-expr-concat/hygiene.rs +++ b/tests/ui/macros/metavar-expressions/concat-hygiene.rs diff --git a/tests/ui/macros/macro-metavar-expr-concat/hygiene.stderr b/tests/ui/macros/metavar-expressions/concat-hygiene.stderr index ef2326dce85..f3150d385ee 100644 --- a/tests/ui/macros/macro-metavar-expr-concat/hygiene.stderr +++ b/tests/ui/macros/metavar-expressions/concat-hygiene.stderr @@ -1,5 +1,5 @@ error[E0425]: cannot find value `abcdef` in this scope - --> $DIR/hygiene.rs:5:10 + --> $DIR/concat-hygiene.rs:5:10 | LL | ${concat($lhs, $rhs)} | ^^^^^^^^^^^^^^^^^^^^ not found in this scope diff --git a/tests/ui/macros/macro-metavar-expr-concat/raw-identifiers.rs b/tests/ui/macros/metavar-expressions/concat-raw-identifiers.rs index b1cb2141cc4..b1cb2141cc4 100644 --- a/tests/ui/macros/macro-metavar-expr-concat/raw-identifiers.rs +++ b/tests/ui/macros/metavar-expressions/concat-raw-identifiers.rs diff --git a/tests/ui/macros/macro-metavar-expr-concat/raw-identifiers.stderr b/tests/ui/macros/metavar-expressions/concat-raw-identifiers.stderr index 4e11e20acc5..7abab6a5103 100644 --- a/tests/ui/macros/macro-metavar-expr-concat/raw-identifiers.stderr +++ b/tests/ui/macros/metavar-expressions/concat-raw-identifiers.stderr @@ -1,47 +1,47 @@ error: expected identifier or string literal - --> $DIR/raw-identifiers.rs:28:22 + --> $DIR/concat-raw-identifiers.rs:28:22 | LL | let ${concat(r#abc, abc)}: () = (); | ^^^^^ error: expected identifier or string literal - --> $DIR/raw-identifiers.rs:32:27 + --> $DIR/concat-raw-identifiers.rs:32:27 | LL | let ${concat(abc, r#abc)}: () = (); | ^^^^^ error: expected identifier or string literal - --> $DIR/raw-identifiers.rs:35:22 + --> $DIR/concat-raw-identifiers.rs:35:22 | LL | let ${concat(r#abc, r#abc)}: () = (); | ^^^^^ error: `${concat(..)}` currently does not support raw identifiers - --> $DIR/raw-identifiers.rs:5:28 + --> $DIR/concat-raw-identifiers.rs:5:28 | LL | let ${concat(abc, $rhs)}: () = (); | ^^^ error: `${concat(..)}` currently does not support raw identifiers - --> $DIR/raw-identifiers.rs:12:23 + --> $DIR/concat-raw-identifiers.rs:12:23 | LL | let ${concat($lhs, abc)}: () = (); | ^^^ error: `${concat(..)}` currently does not support raw identifiers - --> $DIR/raw-identifiers.rs:19:23 + --> $DIR/concat-raw-identifiers.rs:19:23 | LL | let ${concat($lhs, $rhs)}: () = (); | ^^^ error: `${concat(..)}` currently does not support raw identifiers - --> $DIR/raw-identifiers.rs:19:29 + --> $DIR/concat-raw-identifiers.rs:19:29 | LL | let ${concat($lhs, $rhs)}: () = (); | ^^^ error: `${concat(..)}` currently does not support raw identifiers - --> $DIR/raw-identifiers.rs:19:23 + --> $DIR/concat-raw-identifiers.rs:19:23 | LL | let ${concat($lhs, $rhs)}: () = (); | ^^^ @@ -49,31 +49,31 @@ LL | let ${concat($lhs, $rhs)}: () = (); = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: `${concat(..)}` currently does not support raw identifiers - --> $DIR/raw-identifiers.rs:42:28 + --> $DIR/concat-raw-identifiers.rs:42:28 | LL | let ${concat(abc, $rhs)}: () = (); | ^^^ error: `${concat(..)}` currently does not support raw identifiers - --> $DIR/raw-identifiers.rs:49:23 + --> $DIR/concat-raw-identifiers.rs:49:23 | LL | let ${concat($lhs, abc)}: () = (); | ^^^ error: `${concat(..)}` currently does not support raw identifiers - --> $DIR/raw-identifiers.rs:56:23 + --> $DIR/concat-raw-identifiers.rs:56:23 | LL | let ${concat($lhs, $rhs)}: () = (); | ^^^ error: `${concat(..)}` currently does not support raw identifiers - --> $DIR/raw-identifiers.rs:56:29 + --> $DIR/concat-raw-identifiers.rs:56:29 | LL | let ${concat($lhs, $rhs)}: () = (); | ^^^ error: `${concat(..)}` currently does not support raw identifiers - --> $DIR/raw-identifiers.rs:56:23 + --> $DIR/concat-raw-identifiers.rs:56:23 | LL | let ${concat($lhs, $rhs)}: () = (); | ^^^ @@ -81,7 +81,7 @@ LL | let ${concat($lhs, $rhs)}: () = (); = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: expected pattern, found `$` - --> $DIR/raw-identifiers.rs:28:13 + --> $DIR/concat-raw-identifiers.rs:28:13 | LL | let ${concat(r#abc, abc)}: () = (); | ^ expected pattern diff --git a/tests/ui/macros/macro-metavar-expr-concat/repetitions.rs b/tests/ui/macros/metavar-expressions/concat-repetitions.rs index 52a7d5cd8a7..52a7d5cd8a7 100644 --- a/tests/ui/macros/macro-metavar-expr-concat/repetitions.rs +++ b/tests/ui/macros/metavar-expressions/concat-repetitions.rs diff --git a/tests/ui/macros/macro-metavar-expr-concat/repetitions.stderr b/tests/ui/macros/metavar-expressions/concat-repetitions.stderr index c3006c4be5d..18b0a90c1c8 100644 --- a/tests/ui/macros/macro-metavar-expr-concat/repetitions.stderr +++ b/tests/ui/macros/metavar-expressions/concat-repetitions.stderr @@ -1,17 +1,17 @@ error: invalid syntax - --> $DIR/repetitions.rs:14:20 + --> $DIR/concat-repetitions.rs:14:20 | LL | const ${concat($a, Z)}: i32 = 3; | ^^^^^^^^^^^^^^^ error: invalid syntax - --> $DIR/repetitions.rs:22:17 + --> $DIR/concat-repetitions.rs:22:17 | LL | read::<${concat($t, $en)}>() | ^^^^^^^^^^^^^^^^^ error: invalid syntax - --> $DIR/repetitions.rs:22:17 + --> $DIR/concat-repetitions.rs:22:17 | LL | read::<${concat($t, $en)}>() | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/macros/metavar-expressions/concat-trace-errors.rs b/tests/ui/macros/metavar-expressions/concat-trace-errors.rs new file mode 100644 index 00000000000..45407f5e86d --- /dev/null +++ b/tests/ui/macros/metavar-expressions/concat-trace-errors.rs @@ -0,0 +1,33 @@ +// Our diagnostics should be able to point to a specific input that caused an invalid +// identifier. + +#![feature(macro_metavar_expr_concat)] + +// See what we can do without expanding anything +macro_rules! pre_expansion { + ($a:ident) => { + ${concat("hi", " bye ")}; + ${concat("hi", "-", "bye")}; + ${concat($a, "-")}; + } +} + +macro_rules! post_expansion { + ($a:literal) => { + const _: () = ${concat("hi", $a, "bye")}; + //~^ ERROR is not generating a valid identifier + } +} + +post_expansion!("!"); + +macro_rules! post_expansion_many { + ($a:ident, $b:ident, $c:ident, $d:literal, $e:ident) => { + const _: () = ${concat($a, $b, $c, $d, $e)}; + //~^ ERROR is not generating a valid identifier + } +} + +post_expansion_many!(a, b, c, ".d", e); + +fn main() {} diff --git a/tests/ui/macros/metavar-expressions/concat-trace-errors.stderr b/tests/ui/macros/metavar-expressions/concat-trace-errors.stderr new file mode 100644 index 00000000000..dac8b58a15c --- /dev/null +++ b/tests/ui/macros/metavar-expressions/concat-trace-errors.stderr @@ -0,0 +1,24 @@ +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-trace-errors.rs:17:24 + | +LL | const _: () = ${concat("hi", $a, "bye")}; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | post_expansion!("!"); + | -------------------- in this macro invocation + | + = note: this error originates in the macro `post_expansion` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-trace-errors.rs:26:24 + | +LL | const _: () = ${concat($a, $b, $c, $d, $e)}; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | post_expansion_many!(a, b, c, ".d", e); + | -------------------------------------- in this macro invocation + | + = note: this error originates in the macro `post_expansion_many` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 2 previous errors + diff --git a/tests/ui/macros/macro-metavar-expr-concat/unicode-expansion.rs b/tests/ui/macros/metavar-expressions/concat-unicode-expansion.rs index 4eeb2384deb..4eeb2384deb 100644 --- a/tests/ui/macros/macro-metavar-expr-concat/unicode-expansion.rs +++ b/tests/ui/macros/metavar-expressions/concat-unicode-expansion.rs diff --git a/tests/ui/macros/macro-metavar-expr-concat/syntax-errors.rs b/tests/ui/macros/metavar-expressions/concat-usage-errors.rs index 7673bd3200f..7d8756de9e2 100644 --- a/tests/ui/macros/macro-metavar-expr-concat/syntax-errors.rs +++ b/tests/ui/macros/metavar-expressions/concat-usage-errors.rs @@ -1,6 +1,8 @@ +//@ edition: 2021 + #![feature(macro_metavar_expr_concat)] -macro_rules! wrong_concat_declarations { +macro_rules! syntax_errors { ($ex:expr) => { ${concat()} //~^ ERROR expected identifier @@ -90,11 +92,31 @@ macro_rules! unsupported_literals { //~| ERROR expected pattern let ${concat(_a, 1)}: () = (); //~^ ERROR expected identifier or string literal + let ${concat(_a, 1.5)}: () = (); + //~^ ERROR expected identifier or string literal + let ${concat(_a, c"hi")}: () = (); + //~^ ERROR expected identifier or string literal + let ${concat(_a, b"hi")}: () = (); + //~^ ERROR expected identifier or string literal + let ${concat(_a, b'b')}: () = (); + //~^ ERROR expected identifier or string literal + let ${concat(_a, b'b')}: () = (); + //~^ ERROR expected identifier or string literal let ${concat($ident, 'b')}: () = (); //~^ ERROR expected identifier or string literal let ${concat($ident, 1)}: () = (); //~^ ERROR expected identifier or string literal + let ${concat($ident, 1.5)}: () = (); + //~^ ERROR expected identifier or string literal + let ${concat($ident, c"hi")}: () = (); + //~^ ERROR expected identifier or string literal + let ${concat($ident, b"hi")}: () = (); + //~^ ERROR expected identifier or string literal + let ${concat($ident, b'b')}: () = (); + //~^ ERROR expected identifier or string literal + let ${concat($ident, b'b')}: () = (); + //~^ ERROR expected identifier or string literal }}; } @@ -132,7 +154,7 @@ macro_rules! bad_tt_literal { } fn main() { - wrong_concat_declarations!(1); + syntax_errors!(1); dollar_sign_without_referenced_ident!(VAR); diff --git a/tests/ui/macros/macro-metavar-expr-concat/syntax-errors.stderr b/tests/ui/macros/metavar-expressions/concat-usage-errors.stderr index 2de6d2b3ce3..8be3e792ec3 100644 --- a/tests/ui/macros/macro-metavar-expr-concat/syntax-errors.stderr +++ b/tests/ui/macros/metavar-expressions/concat-usage-errors.stderr @@ -1,71 +1,131 @@ error: expected identifier or string literal - --> $DIR/syntax-errors.rs:5:10 + --> $DIR/concat-usage-errors.rs:7:10 | LL | ${concat()} | ^^^^^^^^^^ error: `concat` must have at least two elements - --> $DIR/syntax-errors.rs:8:11 + --> $DIR/concat-usage-errors.rs:10:11 | LL | ${concat(aaaa)} | ^^^^^^ error: expected identifier or string literal - --> $DIR/syntax-errors.rs:11:10 + --> $DIR/concat-usage-errors.rs:13:10 | LL | ${concat(aaaa,)} | ^^^^^^^^^^^^^^^ error: expected comma - --> $DIR/syntax-errors.rs:16:10 + --> $DIR/concat-usage-errors.rs:18:10 | LL | ${concat(aaaa aaaa)} | ^^^^^^^^^^^^^^^^^^^ error: `concat` must have at least two elements - --> $DIR/syntax-errors.rs:19:11 + --> $DIR/concat-usage-errors.rs:21:11 | LL | ${concat($ex)} | ^^^^^^ error: expected comma - --> $DIR/syntax-errors.rs:25:10 + --> $DIR/concat-usage-errors.rs:27:10 | LL | ${concat($ex, aaaa 123)} | ^^^^^^^^^^^^^^^^^^^^^^^ error: expected identifier or string literal - --> $DIR/syntax-errors.rs:28:10 + --> $DIR/concat-usage-errors.rs:30:10 | LL | ${concat($ex, aaaa,)} | ^^^^^^^^^^^^^^^^^^^^ error: expected identifier or string literal - --> $DIR/syntax-errors.rs:88:26 + --> $DIR/concat-usage-errors.rs:90:26 | LL | let ${concat(_a, 'b')}: () = (); | ^^^ error: expected identifier or string literal - --> $DIR/syntax-errors.rs:91:26 + --> $DIR/concat-usage-errors.rs:93:26 | LL | let ${concat(_a, 1)}: () = (); | ^ error: expected identifier or string literal - --> $DIR/syntax-errors.rs:94:30 + --> $DIR/concat-usage-errors.rs:95:26 + | +LL | let ${concat(_a, 1.5)}: () = (); + | ^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:97:26 + | +LL | let ${concat(_a, c"hi")}: () = (); + | ^^^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:99:26 + | +LL | let ${concat(_a, b"hi")}: () = (); + | ^^^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:101:26 + | +LL | let ${concat(_a, b'b')}: () = (); + | ^^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:103:26 + | +LL | let ${concat(_a, b'b')}: () = (); + | ^^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:106:30 | LL | let ${concat($ident, 'b')}: () = (); | ^^^ error: expected identifier or string literal - --> $DIR/syntax-errors.rs:96:30 + --> $DIR/concat-usage-errors.rs:108:30 | LL | let ${concat($ident, 1)}: () = (); | ^ +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:110:30 + | +LL | let ${concat($ident, 1.5)}: () = (); + | ^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:112:30 + | +LL | let ${concat($ident, c"hi")}: () = (); + | ^^^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:114:30 + | +LL | let ${concat($ident, b"hi")}: () = (); + | ^^^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:116:30 + | +LL | let ${concat($ident, b'b')}: () = (); + | ^^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:118:30 + | +LL | let ${concat($ident, b'b')}: () = (); + | ^^^^ + error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/syntax-errors.rs:22:19 + --> $DIR/concat-usage-errors.rs:24:19 | LL | ${concat($ex, aaaa)} | ^^ @@ -73,13 +133,13 @@ LL | ${concat($ex, aaaa)} = note: currently only string literals are supported error: variable `foo` is not recognized in meta-variable expression - --> $DIR/syntax-errors.rs:35:30 + --> $DIR/concat-usage-errors.rs:37:30 | LL | const ${concat(FOO, $foo)}: i32 = 2; | ^^^ error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:42:14 + --> $DIR/concat-usage-errors.rs:44:14 | LL | let ${concat("1", $ident)}: () = (); | ^^^^^^^^^^^^^^^^^^^^^ @@ -90,7 +150,7 @@ LL | starting_number!(_abc); = note: this error originates in the macro `starting_number` (in Nightly builds, run with -Z macro-backtrace for more info) error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:55:14 + --> $DIR/concat-usage-errors.rs:57:14 | LL | let ${concat("\u{00BD}", $ident)}: () = (); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -101,7 +161,7 @@ LL | starting_invalid_unicode!(_abc); = note: this error originates in the macro `starting_invalid_unicode` (in Nightly builds, run with -Z macro-backtrace for more info) error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:74:14 + --> $DIR/concat-usage-errors.rs:76:14 | LL | let ${concat($ident, "\u{00BD}")}: () = (); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +172,7 @@ LL | ending_invalid_unicode!(_abc); = note: this error originates in the macro `ending_invalid_unicode` (in Nightly builds, run with -Z macro-backtrace for more info) error: expected pattern, found `$` - --> $DIR/syntax-errors.rs:88:13 + --> $DIR/concat-usage-errors.rs:90:13 | LL | let ${concat(_a, 'b')}: () = (); | ^ expected pattern @@ -123,7 +183,7 @@ LL | unsupported_literals!(_abc); = note: this error originates in the macro `unsupported_literals` (in Nightly builds, run with -Z macro-backtrace for more info) error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:81:14 + --> $DIR/concat-usage-errors.rs:83:14 | LL | let ${concat("", "")}: () = (); | ^^^^^^^^^^^^^^^^ @@ -134,7 +194,7 @@ LL | empty!(); = note: this error originates in the macro `empty` (in Nightly builds, run with -Z macro-backtrace for more info) error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:103:16 + --> $DIR/concat-usage-errors.rs:125:16 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +205,7 @@ LL | bad_literal_string!("\u{00BD}"); = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:103:16 + --> $DIR/concat-usage-errors.rs:125:16 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -156,7 +216,7 @@ LL | bad_literal_string!("\x41"); = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:103:16 + --> $DIR/concat-usage-errors.rs:125:16 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -167,7 +227,7 @@ LL | bad_literal_string!("🤷"); = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:103:16 + --> $DIR/concat-usage-errors.rs:125:16 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -178,7 +238,7 @@ LL | bad_literal_string!("d[-_-]b"); = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:103:16 + --> $DIR/concat-usage-errors.rs:125:16 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -189,7 +249,7 @@ LL | bad_literal_string!("-1"); = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:103:16 + --> $DIR/concat-usage-errors.rs:125:16 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -200,7 +260,7 @@ LL | bad_literal_string!("1.0"); = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:103:16 + --> $DIR/concat-usage-errors.rs:125:16 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -211,7 +271,7 @@ LL | bad_literal_string!("'1'"); = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/syntax-errors.rs:116:31 + --> $DIR/concat-usage-errors.rs:138:31 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^ @@ -219,7 +279,7 @@ LL | const ${concat(_foo, $literal)}: () = (); = note: currently only string literals are supported error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/syntax-errors.rs:116:31 + --> $DIR/concat-usage-errors.rs:138:31 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^ @@ -228,7 +288,7 @@ LL | const ${concat(_foo, $literal)}: () = (); = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/syntax-errors.rs:116:31 + --> $DIR/concat-usage-errors.rs:138:31 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^ @@ -237,7 +297,7 @@ LL | const ${concat(_foo, $literal)}: () = (); = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/syntax-errors.rs:116:31 + --> $DIR/concat-usage-errors.rs:138:31 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^ @@ -246,7 +306,7 @@ LL | const ${concat(_foo, $literal)}: () = (); = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/syntax-errors.rs:116:31 + --> $DIR/concat-usage-errors.rs:138:31 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^ @@ -255,7 +315,7 @@ LL | const ${concat(_foo, $literal)}: () = (); = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/syntax-errors.rs:127:31 + --> $DIR/concat-usage-errors.rs:149:31 | LL | const ${concat(_foo, $tt)}: () = (); | ^^ @@ -263,7 +323,7 @@ LL | const ${concat(_foo, $tt)}: () = (); = note: currently only string literals are supported error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/syntax-errors.rs:127:31 + --> $DIR/concat-usage-errors.rs:149:31 | LL | const ${concat(_foo, $tt)}: () = (); | ^^ @@ -272,7 +332,7 @@ LL | const ${concat(_foo, $tt)}: () = (); = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/syntax-errors.rs:127:31 + --> $DIR/concat-usage-errors.rs:149:31 | LL | const ${concat(_foo, $tt)}: () = (); | ^^ @@ -280,5 +340,5 @@ LL | const ${concat(_foo, $tt)}: () = (); = note: currently only string literals are supported = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: aborting due to 33 previous errors +error: aborting due to 43 previous errors diff --git a/tests/ui/macros/rfc-3086-metavar-expr/count-and-length-are-distinct.rs b/tests/ui/macros/metavar-expressions/count-and-length-are-distinct.rs index 8ca453273cd..8ca453273cd 100644 --- a/tests/ui/macros/rfc-3086-metavar-expr/count-and-length-are-distinct.rs +++ b/tests/ui/macros/metavar-expressions/count-and-length-are-distinct.rs diff --git a/tests/ui/macros/rfc-3086-metavar-expr/issue-111904.rs b/tests/ui/macros/metavar-expressions/count-empty-index-arg.rs index 3000bfed6a8..69880ee7fa9 100644 --- a/tests/ui/macros/rfc-3086-metavar-expr/issue-111904.rs +++ b/tests/ui/macros/metavar-expressions/count-empty-index-arg.rs @@ -1,3 +1,6 @@ +// Issue: https://github.com/rust-lang/rust/issues/111904 +// Ensure that a trailing `,` is not interpreted as a `0`. + #![feature(macro_metavar_expr)] macro_rules! foo { @@ -10,5 +13,4 @@ fn test() { foo!(a, a; b, b); } -fn main() { -} +fn main() {} diff --git a/tests/ui/macros/rfc-3086-metavar-expr/issue-111904.stderr b/tests/ui/macros/metavar-expressions/count-empty-index-arg.stderr index fd53c1686cf..e1f9d020b7f 100644 --- a/tests/ui/macros/rfc-3086-metavar-expr/issue-111904.stderr +++ b/tests/ui/macros/metavar-expressions/count-empty-index-arg.stderr @@ -1,11 +1,11 @@ error: `count` followed by a comma must have an associated index indicating its depth - --> $DIR/issue-111904.rs:4:37 + --> $DIR/count-empty-index-arg.rs:7:37 | LL | ( $( $($t:ident),* );* ) => { ${count($t,)} } | ^^^^^ error: expected expression, found `$` - --> $DIR/issue-111904.rs:4:35 + --> $DIR/count-empty-index-arg.rs:7:35 | LL | ( $( $($t:ident),* );* ) => { ${count($t,)} } | ^ expected expression diff --git a/tests/ui/macros/rfc-3086-metavar-expr/dollar-dollar-has-correct-behavior.rs b/tests/ui/macros/metavar-expressions/dollar-dollar-has-correct-behavior.rs index 9b8e3216a68..9b8e3216a68 100644 --- a/tests/ui/macros/rfc-3086-metavar-expr/dollar-dollar-has-correct-behavior.rs +++ b/tests/ui/macros/metavar-expressions/dollar-dollar-has-correct-behavior.rs diff --git a/tests/ui/macros/rfc-3086-metavar-expr/feature-gate-macro_metavar_expr.rs b/tests/ui/macros/metavar-expressions/feature-gate-macro_metavar_expr.rs index 51445221c57..51445221c57 100644 --- a/tests/ui/macros/rfc-3086-metavar-expr/feature-gate-macro_metavar_expr.rs +++ b/tests/ui/macros/metavar-expressions/feature-gate-macro_metavar_expr.rs diff --git a/tests/ui/macros/rfc-3086-metavar-expr/macro-expansion.rs b/tests/ui/macros/metavar-expressions/macro-expansion.rs index 1d34275874b..1d34275874b 100644 --- a/tests/ui/macros/rfc-3086-metavar-expr/macro-expansion.rs +++ b/tests/ui/macros/metavar-expressions/macro-expansion.rs diff --git a/tests/ui/macros/rfc-3086-metavar-expr/out-of-bounds-arguments.rs b/tests/ui/macros/metavar-expressions/out-of-bounds-arguments.rs index 0caa3ea89e4..0caa3ea89e4 100644 --- a/tests/ui/macros/rfc-3086-metavar-expr/out-of-bounds-arguments.rs +++ b/tests/ui/macros/metavar-expressions/out-of-bounds-arguments.rs diff --git a/tests/ui/macros/rfc-3086-metavar-expr/out-of-bounds-arguments.stderr b/tests/ui/macros/metavar-expressions/out-of-bounds-arguments.stderr index 0b441cad083..0b441cad083 100644 --- a/tests/ui/macros/rfc-3086-metavar-expr/out-of-bounds-arguments.stderr +++ b/tests/ui/macros/metavar-expressions/out-of-bounds-arguments.stderr diff --git a/tests/ui/macros/rfc-3086-metavar-expr/required-feature.rs b/tests/ui/macros/metavar-expressions/required-feature.rs index 77c165e3855..77c165e3855 100644 --- a/tests/ui/macros/rfc-3086-metavar-expr/required-feature.rs +++ b/tests/ui/macros/metavar-expressions/required-feature.rs diff --git a/tests/ui/macros/rfc-3086-metavar-expr/required-feature.stderr b/tests/ui/macros/metavar-expressions/required-feature.stderr index f28f822a058..f28f822a058 100644 --- a/tests/ui/macros/rfc-3086-metavar-expr/required-feature.stderr +++ b/tests/ui/macros/metavar-expressions/required-feature.stderr diff --git a/tests/ui/macros/metavar-expressions/syntax-errors.rs b/tests/ui/macros/metavar-expressions/syntax-errors.rs new file mode 100644 index 00000000000..8fc76a74baa --- /dev/null +++ b/tests/ui/macros/metavar-expressions/syntax-errors.rs @@ -0,0 +1,117 @@ +// General syntax errors that apply to all matavariable expressions +// +// We don't invoke the macros here to ensure code gets rejected at the definition rather than +// only when expanded. + +#![feature(macro_metavar_expr)] + +macro_rules! dollar_dollar_in_the_lhs { + ( $$ $a:ident ) => { + //~^ ERROR unexpected token: $ + }; +} + +macro_rules! metavar_in_the_lhs { + ( ${ len() } ) => { + //~^ ERROR unexpected token: { + //~| ERROR expected one of: `*`, `+`, or `?` + }; +} + +macro_rules! metavar_token_without_ident { + ( $( $i:ident ),* ) => { ${ ignore() } }; + //~^ ERROR meta-variable expressions must be referenced using a dollar sign +} + +macro_rules! metavar_with_literal_suffix { + ( $( $i:ident ),* ) => { ${ index(1u32) } }; + //~^ ERROR only unsuffixes integer literals are supported in meta-variable expressions +} + +macro_rules! mve_without_parens { + ( $( $i:ident ),* ) => { ${ count } }; + //~^ ERROR meta-variable expression parameter must be wrapped in parentheses +} + +#[rustfmt::skip] +macro_rules! empty_expression { + () => { ${} }; + //~^ ERROR expected identifier or string literal +} + +#[rustfmt::skip] +macro_rules! open_brackets_with_lit { + () => { ${ "hi" } }; + //~^ ERROR expected identifier + } + +macro_rules! mve_wrong_delim { + ( $( $i:ident ),* ) => { ${ count{i} } }; + //~^ ERROR meta-variable expression parameter must be wrapped in parentheses +} + +macro_rules! invalid_metavar { + () => { ${ignore($123)} } + //~^ ERROR expected identifier, found `123` +} + +#[rustfmt::skip] +macro_rules! open_brackets_with_group { + ( $( $i:ident ),* ) => { ${ {} } }; + //~^ ERROR expected identifier +} + +macro_rules! extra_garbage_after_metavar { + ( $( $i:ident ),* ) => { + ${count() a b c} + //~^ ERROR unexpected token: a + ${count($i a b c)} + //~^ ERROR unexpected token: a + ${count($i, 1 a b c)} + //~^ ERROR unexpected token: a + ${count($i) a b c} + //~^ ERROR unexpected token: a + + ${ignore($i) a b c} + //~^ ERROR unexpected token: a + ${ignore($i a b c)} + //~^ ERROR unexpected token: a + + ${index() a b c} + //~^ ERROR unexpected token: a + ${index(1 a b c)} + //~^ ERROR unexpected token: a + + ${index() a b c} + //~^ ERROR unexpected token: a + ${index(1 a b c)} + //~^ ERROR unexpected token: a + }; +} + +const IDX: usize = 1; +macro_rules! metavar_depth_is_not_literal { + ( $( $i:ident ),* ) => { ${ index(IDX) } }; + //~^ ERROR meta-variable expression depth must be a literal +} + +macro_rules! unknown_count_ident { + ( $( $i:ident )* ) => { + ${count(foo)} + //~^ ERROR meta-variable expressions must be referenced using a dollar sign + }; +} + +macro_rules! unknown_ignore_ident { + ( $( $i:ident )* ) => { + ${ignore(bar)} + //~^ ERROR meta-variable expressions must be referenced using a dollar sign + }; +} + +macro_rules! unknown_metavar { + ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; + //~^ ERROR unrecognized meta-variable expression +} + +fn main() {} diff --git a/tests/ui/macros/metavar-expressions/syntax-errors.stderr b/tests/ui/macros/metavar-expressions/syntax-errors.stderr new file mode 100644 index 00000000000..20d2358facc --- /dev/null +++ b/tests/ui/macros/metavar-expressions/syntax-errors.stderr @@ -0,0 +1,224 @@ +error: unexpected token: $ + --> $DIR/syntax-errors.rs:9:8 + | +LL | ( $$ $a:ident ) => { + | ^ + +note: `$$` and meta-variable expressions are not allowed inside macro parameter definitions + --> $DIR/syntax-errors.rs:9:8 + | +LL | ( $$ $a:ident ) => { + | ^ + +error: unexpected token: { + --> $DIR/syntax-errors.rs:15:8 + | +LL | ( ${ len() } ) => { + | ^^^^^^^^^ + +note: `$$` and meta-variable expressions are not allowed inside macro parameter definitions + --> $DIR/syntax-errors.rs:15:8 + | +LL | ( ${ len() } ) => { + | ^^^^^^^^^ + +error: expected one of: `*`, `+`, or `?` + --> $DIR/syntax-errors.rs:15:8 + | +LL | ( ${ len() } ) => { + | ^^^^^^^^^ + +error: meta-variables within meta-variable expressions must be referenced using a dollar sign + --> $DIR/syntax-errors.rs:22:33 + | +LL | ( $( $i:ident ),* ) => { ${ ignore() } }; + | ^^^^^^ + +error: only unsuffixes integer literals are supported in meta-variable expressions + --> $DIR/syntax-errors.rs:27:33 + | +LL | ( $( $i:ident ),* ) => { ${ index(1u32) } }; + | ^^^^^ + +error: meta-variable expression parameter must be wrapped in parentheses + --> $DIR/syntax-errors.rs:32:33 + | +LL | ( $( $i:ident ),* ) => { ${ count } }; + | ^^^^^ + +error: meta-variable expression parameter must be wrapped in parentheses + --> $DIR/syntax-errors.rs:49:33 + | +LL | ( $( $i:ident ),* ) => { ${ count{i} } }; + | ^^^^^ + +error: expected identifier, found `123` + --> $DIR/syntax-errors.rs:54:23 + | +LL | () => { ${ignore($123)} } + | ^^^ help: try removing `123` + +error: unexpected token: a + --> $DIR/syntax-errors.rs:66:19 + | +LL | ${count() a b c} + | ^ + | +note: meta-variable expression must not have trailing tokens + --> $DIR/syntax-errors.rs:66:19 + | +LL | ${count() a b c} + | ^ + +error: unexpected token: a + --> $DIR/syntax-errors.rs:68:20 + | +LL | ${count($i a b c)} + | ^ + | +note: meta-variable expression must not have trailing tokens + --> $DIR/syntax-errors.rs:68:20 + | +LL | ${count($i a b c)} + | ^ + +error: unexpected token: a + --> $DIR/syntax-errors.rs:70:23 + | +LL | ${count($i, 1 a b c)} + | ^ + | +note: meta-variable expression must not have trailing tokens + --> $DIR/syntax-errors.rs:70:23 + | +LL | ${count($i, 1 a b c)} + | ^ + +error: unexpected token: a + --> $DIR/syntax-errors.rs:72:21 + | +LL | ${count($i) a b c} + | ^ + | +note: meta-variable expression must not have trailing tokens + --> $DIR/syntax-errors.rs:72:21 + | +LL | ${count($i) a b c} + | ^ + +error: unexpected token: a + --> $DIR/syntax-errors.rs:75:22 + | +LL | ${ignore($i) a b c} + | ^ + | +note: meta-variable expression must not have trailing tokens + --> $DIR/syntax-errors.rs:75:22 + | +LL | ${ignore($i) a b c} + | ^ + +error: unexpected token: a + --> $DIR/syntax-errors.rs:77:21 + | +LL | ${ignore($i a b c)} + | ^ + | +note: meta-variable expression must not have trailing tokens + --> $DIR/syntax-errors.rs:77:21 + | +LL | ${ignore($i a b c)} + | ^ + +error: unexpected token: a + --> $DIR/syntax-errors.rs:80:19 + | +LL | ${index() a b c} + | ^ + | +note: meta-variable expression must not have trailing tokens + --> $DIR/syntax-errors.rs:80:19 + | +LL | ${index() a b c} + | ^ + +error: unexpected token: a + --> $DIR/syntax-errors.rs:82:19 + | +LL | ${index(1 a b c)} + | ^ + | +note: meta-variable expression must not have trailing tokens + --> $DIR/syntax-errors.rs:82:19 + | +LL | ${index(1 a b c)} + | ^ + +error: unexpected token: a + --> $DIR/syntax-errors.rs:85:19 + | +LL | ${index() a b c} + | ^ + | +note: meta-variable expression must not have trailing tokens + --> $DIR/syntax-errors.rs:85:19 + | +LL | ${index() a b c} + | ^ + +error: unexpected token: a + --> $DIR/syntax-errors.rs:87:19 + | +LL | ${index(1 a b c)} + | ^ + | +note: meta-variable expression must not have trailing tokens + --> $DIR/syntax-errors.rs:87:19 + | +LL | ${index(1 a b c)} + | ^ + +error: meta-variable expression depth must be a literal + --> $DIR/syntax-errors.rs:94:33 + | +LL | ( $( $i:ident ),* ) => { ${ index(IDX) } }; + | ^^^^^ + +error: meta-variables within meta-variable expressions must be referenced using a dollar sign + --> $DIR/syntax-errors.rs:100:11 + | +LL | ${count(foo)} + | ^^^^^ + +error: meta-variables within meta-variable expressions must be referenced using a dollar sign + --> $DIR/syntax-errors.rs:107:11 + | +LL | ${ignore(bar)} + | ^^^^^^ + +error: unrecognized meta-variable expression + --> $DIR/syntax-errors.rs:113:33 + | +LL | ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; + | ^^^^^^^^^^^^^^ help: supported expressions are count, ignore, index and len + +error: expected identifier or string literal + --> $DIR/syntax-errors.rs:38:14 + | +LL | () => { ${} }; + | ^^ + +error: expected identifier, found `"hi"` + --> $DIR/syntax-errors.rs:44:17 + | +LL | () => { ${ "hi" } }; + | ^^^^ help: try removing `"hi"` + +error: expected identifier or string literal + --> $DIR/syntax-errors.rs:60:33 + | +LL | ( $( $i:ident ),* ) => { ${ {} } }; + | ^^ + +error: aborting due to 25 previous errors + diff --git a/tests/ui/macros/metavar-expressions/usage-errors.rs b/tests/ui/macros/metavar-expressions/usage-errors.rs new file mode 100644 index 00000000000..feff02e2ce4 --- /dev/null +++ b/tests/ui/macros/metavar-expressions/usage-errors.rs @@ -0,0 +1,55 @@ +// Errors for the `count` and `length` metavariable expressions + +#![feature(macro_metavar_expr)] + +// `curly` = Right hand side curly brackets +// `no_rhs_dollar` = No dollar sign at the right hand side meta variable "function" +// `round` = Left hand side round brackets + +macro_rules! curly__no_rhs_dollar__round { + ( $( $i:ident ),* ) => { ${ count($i) } }; +} +const _: u32 = curly__no_rhs_dollar__round!(a, b, c); + +macro_rules! curly__no_rhs_dollar__no_round { + ( $i:ident ) => { ${ count($i) } }; + //~^ ERROR `count` can not be placed inside the innermost repetition +} +curly__no_rhs_dollar__no_round!(a); + +macro_rules! curly__rhs_dollar__no_round { + ( $i:ident ) => { ${ count($i) } }; + //~^ ERROR `count` can not be placed inside the innermost repetition +} +curly__rhs_dollar__no_round !(a); + +#[rustfmt::skip] // autoformatters can break a few of the error traces +macro_rules! no_curly__no_rhs_dollar__round { + ( $( $i:ident ),* ) => { count(i) }; + //~^ ERROR missing `fn` or `struct` for function or struct definition +} +no_curly__no_rhs_dollar__round !(a, b, c); + +#[rustfmt::skip] // autoformatters can break a few of the error traces +macro_rules! no_curly__no_rhs_dollar__no_round { + ( $i:ident ) => { count(i) }; + //~^ ERROR missing `fn` or `struct` for function or struct definition +} +no_curly__no_rhs_dollar__no_round !(a); + +#[rustfmt::skip] // autoformatters can break a few of the error traces +macro_rules! no_curly__rhs_dollar__round { + ( $( $i:ident ),* ) => { count($i) }; + //~^ ERROR variable `i` is still repeating at this depth +} +no_curly__rhs_dollar__round! (a); + +#[rustfmt::skip] // autoformatters can break a few of the error traces +macro_rules! no_curly__rhs_dollar__no_round { + ( $i:ident ) => { count($i) }; + //~^ ERROR cannot find function `count` in this scope +} +const _: u32 = no_curly__rhs_dollar__no_round! (a); +//~^ ERROR cannot find value `a` in this scope + +fn main() {} diff --git a/tests/ui/macros/metavar-expressions/usage-errors.stderr b/tests/ui/macros/metavar-expressions/usage-errors.stderr new file mode 100644 index 00000000000..f66f522e23b --- /dev/null +++ b/tests/ui/macros/metavar-expressions/usage-errors.stderr @@ -0,0 +1,71 @@ +error: `count` can not be placed inside the innermost repetition + --> $DIR/usage-errors.rs:15:24 + | +LL | ( $i:ident ) => { ${ count($i) } }; + | ^^^^^^^^^^^^^ + +error: `count` can not be placed inside the innermost repetition + --> $DIR/usage-errors.rs:21:24 + | +LL | ( $i:ident ) => { ${ count($i) } }; + | ^^^^^^^^^^^^^ + +error: missing `fn` or `struct` for function or struct definition + --> $DIR/usage-errors.rs:28:30 + | +LL | ( $( $i:ident ),* ) => { count(i) }; + | ^^^^^ +... +LL | no_curly__no_rhs_dollar__round !(a, b, c); + | ----------------------------------------- in this macro invocation + | + = note: this error originates in the macro `no_curly__no_rhs_dollar__round` (in Nightly builds, run with -Z macro-backtrace for more info) +help: if you meant to call a macro, try + | +LL | ( $( $i:ident ),* ) => { count!(i) }; + | + + +error: missing `fn` or `struct` for function or struct definition + --> $DIR/usage-errors.rs:35:23 + | +LL | ( $i:ident ) => { count(i) }; + | ^^^^^ +... +LL | no_curly__no_rhs_dollar__no_round !(a); + | -------------------------------------- in this macro invocation + | + = note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info) +help: if you meant to call a macro, try + | +LL | ( $i:ident ) => { count!(i) }; + | + + +error: variable `i` is still repeating at this depth + --> $DIR/usage-errors.rs:42:36 + | +LL | ( $( $i:ident ),* ) => { count($i) }; + | ^^ + +error[E0425]: cannot find value `a` in this scope + --> $DIR/usage-errors.rs:52:49 + | +LL | ( $i:ident ) => { count($i) }; + | -- due to this macro variable +... +LL | const _: u32 = no_curly__rhs_dollar__no_round! (a); + | ^ not found in this scope + +error[E0425]: cannot find function `count` in this scope + --> $DIR/usage-errors.rs:49:23 + | +LL | ( $i:ident ) => { count($i) }; + | ^^^^^ not found in this scope +... +LL | const _: u32 = no_curly__rhs_dollar__no_round! (a); + | ----------------------------------- in this macro invocation + | + = note: this error originates in the macro `no_curly__rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 7 previous errors + +For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/macros/must-use-in-macro-55516.stderr b/tests/ui/macros/must-use-in-macro-55516.stderr index 7bf4aaab51c..b93d40d7e5a 100644 --- a/tests/ui/macros/must-use-in-macro-55516.stderr +++ b/tests/ui/macros/must-use-in-macro-55516.stderr @@ -7,7 +7,10 @@ LL | write!(&mut example, "{}", 42); = note: this `Result` may be an `Err` variant, which should be handled = note: `-W unused-must-use` implied by `-W unused` = help: to override `-W unused` add `#[allow(unused_must_use)]` - = note: this warning originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = write!(&mut example, "{}", 42); + | +++++++ warning: 1 warning emitted diff --git a/tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.rs b/tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.rs deleted file mode 100644 index 78cede92526..00000000000 --- a/tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.rs +++ /dev/null @@ -1,164 +0,0 @@ -#![feature(macro_metavar_expr)] - -// `curly` = Right hand side curly brackets -// `no_rhs_dollar` = No dollar sign at the right hand side meta variable "function" -// `round` = Left hand side round brackets - -macro_rules! curly__no_rhs_dollar__round { - ( $( $i:ident ),* ) => { ${ count($i) } }; -} - -macro_rules! curly__no_rhs_dollar__no_round { - ( $i:ident ) => { ${ count($i) } }; - //~^ ERROR `count` can not be placed inside the innermost repetition -} - -macro_rules! curly__rhs_dollar__no_round { - ( $i:ident ) => { ${ count($i) } }; - //~^ ERROR `count` can not be placed inside the innermost repetition -} - -#[rustfmt::skip] // autoformatters can break a few of the error traces -macro_rules! no_curly__no_rhs_dollar__round { - ( $( $i:ident ),* ) => { count(i) }; - //~^ ERROR cannot find function `count` in this scope - //~| ERROR cannot find value `i` in this scope -} - -#[rustfmt::skip] // autoformatters can break a few of the error traces -macro_rules! no_curly__no_rhs_dollar__no_round { - ( $i:ident ) => { count(i) }; - //~^ ERROR cannot find function `count` in this scope - //~| ERROR cannot find value `i` in this scope -} - -#[rustfmt::skip] // autoformatters can break a few of the error traces -macro_rules! no_curly__rhs_dollar__round { - ( $( $i:ident ),* ) => { count($i) }; - //~^ ERROR variable `i` is still repeating at this depth -} - -#[rustfmt::skip] // autoformatters can break a few of the error traces -macro_rules! no_curly__rhs_dollar__no_round { - ( $i:ident ) => { count($i) }; - //~^ ERROR cannot find function `count` in this scope -} - -// Other scenarios - -macro_rules! dollar_dollar_in_the_lhs { - ( $$ $a:ident ) => { - //~^ ERROR unexpected token: $ - }; -} - -macro_rules! extra_garbage_after_metavar { - ( $( $i:ident ),* ) => { - ${count() a b c} - //~^ ERROR unexpected token: a - //~| ERROR expected expression, found `$` - ${count($i a b c)} - //~^ ERROR unexpected token: a - ${count($i, 1 a b c)} - //~^ ERROR unexpected token: a - ${count($i) a b c} - //~^ ERROR unexpected token: a - - ${ignore($i) a b c} - //~^ ERROR unexpected token: a - ${ignore($i a b c)} - //~^ ERROR unexpected token: a - - ${index() a b c} - //~^ ERROR unexpected token: a - ${index(1 a b c)} - //~^ ERROR unexpected token: a - - ${index() a b c} - //~^ ERROR unexpected token: a - ${index(1 a b c)} - //~^ ERROR unexpected token: a - }; -} - -const IDX: usize = 1; -macro_rules! metavar_depth_is_not_literal { - ( $( $i:ident ),* ) => { ${ index(IDX) } }; - //~^ ERROR meta-variable expression depth must be a literal - //~| ERROR expected expression, found `$` -} - -macro_rules! metavar_in_the_lhs { - ( ${ len() } ) => { - //~^ ERROR unexpected token: { - //~| ERROR expected one of: `*`, `+`, or `?` - }; -} - -macro_rules! metavar_token_without_ident { - ( $( $i:ident ),* ) => { ${ ignore() } }; - //~^ ERROR meta-variable expressions must be referenced using a dollar sign - //~| ERROR expected expression -} - -macro_rules! metavar_with_literal_suffix { - ( $( $i:ident ),* ) => { ${ index(1u32) } }; - //~^ ERROR only unsuffixes integer literals are supported in meta-variable expressions - //~| ERROR expected expression, found `$` -} - -macro_rules! metavar_without_parens { - ( $( $i:ident ),* ) => { ${ count{i} } }; - //~^ ERROR meta-variable expression parameter must be wrapped in parentheses - //~| ERROR expected expression, found `$` -} - -#[rustfmt::skip] -macro_rules! open_brackets_without_tokens { - ( $( $i:ident ),* ) => { ${ {} } }; - //~^ ERROR expected expression, found `$` - //~| ERROR expected identifier -} - -macro_rules! unknown_count_ident { - ( $( $i:ident )* ) => { - ${count(foo)} - //~^ ERROR meta-variable expressions must be referenced using a dollar sign - //~| ERROR expected expression - }; -} - -macro_rules! unknown_ignore_ident { - ( $( $i:ident )* ) => { - ${ignore(bar)} - //~^ ERROR meta-variable expressions must be referenced using a dollar sign - //~| ERROR expected expression - }; -} - -macro_rules! unknown_metavar { - ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; - //~^ ERROR unrecognized meta-variable expression - //~| ERROR expected expression -} - -fn main() { - curly__no_rhs_dollar__round!(a, b, c); - curly__no_rhs_dollar__no_round!(a); - curly__rhs_dollar__no_round!(a); - no_curly__no_rhs_dollar__round!(a, b, c); - no_curly__no_rhs_dollar__no_round!(a); - no_curly__rhs_dollar__round!(a, b, c); - no_curly__rhs_dollar__no_round!(a); - //~^ ERROR cannot find value `a` in this scope - - extra_garbage_after_metavar!(a); - metavar_depth_is_not_literal!(a); - metavar_token_without_ident!(a); - metavar_with_literal_suffix!(a); - metavar_without_parens!(a); - open_brackets_without_tokens!(a); - unknown_count_ident!(a); - unknown_ignore_ident!(a); - unknown_metavar!(a); -} diff --git a/tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr b/tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr deleted file mode 100644 index d9646760cea..00000000000 --- a/tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr +++ /dev/null @@ -1,382 +0,0 @@ -error: unexpected token: $ - --> $DIR/syntax-errors.rs:50:8 - | -LL | ( $$ $a:ident ) => { - | ^ - -note: `$$` and meta-variable expressions are not allowed inside macro parameter definitions - --> $DIR/syntax-errors.rs:50:8 - | -LL | ( $$ $a:ident ) => { - | ^ - -error: unexpected token: a - --> $DIR/syntax-errors.rs:57:19 - | -LL | ${count() a b c} - | ^ - | -note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:57:19 - | -LL | ${count() a b c} - | ^ - -error: unexpected token: a - --> $DIR/syntax-errors.rs:60:20 - | -LL | ${count($i a b c)} - | ^ - | -note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:60:20 - | -LL | ${count($i a b c)} - | ^ - -error: unexpected token: a - --> $DIR/syntax-errors.rs:62:23 - | -LL | ${count($i, 1 a b c)} - | ^ - | -note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:62:23 - | -LL | ${count($i, 1 a b c)} - | ^ - -error: unexpected token: a - --> $DIR/syntax-errors.rs:64:21 - | -LL | ${count($i) a b c} - | ^ - | -note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:64:21 - | -LL | ${count($i) a b c} - | ^ - -error: unexpected token: a - --> $DIR/syntax-errors.rs:67:22 - | -LL | ${ignore($i) a b c} - | ^ - | -note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:67:22 - | -LL | ${ignore($i) a b c} - | ^ - -error: unexpected token: a - --> $DIR/syntax-errors.rs:69:21 - | -LL | ${ignore($i a b c)} - | ^ - | -note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:69:21 - | -LL | ${ignore($i a b c)} - | ^ - -error: unexpected token: a - --> $DIR/syntax-errors.rs:72:19 - | -LL | ${index() a b c} - | ^ - | -note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:72:19 - | -LL | ${index() a b c} - | ^ - -error: unexpected token: a - --> $DIR/syntax-errors.rs:74:19 - | -LL | ${index(1 a b c)} - | ^ - | -note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:74:19 - | -LL | ${index(1 a b c)} - | ^ - -error: unexpected token: a - --> $DIR/syntax-errors.rs:77:19 - | -LL | ${index() a b c} - | ^ - | -note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:77:19 - | -LL | ${index() a b c} - | ^ - -error: unexpected token: a - --> $DIR/syntax-errors.rs:79:19 - | -LL | ${index(1 a b c)} - | ^ - | -note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:79:19 - | -LL | ${index(1 a b c)} - | ^ - -error: meta-variable expression depth must be a literal - --> $DIR/syntax-errors.rs:86:33 - | -LL | ( $( $i:ident ),* ) => { ${ index(IDX) } }; - | ^^^^^ - -error: unexpected token: { - --> $DIR/syntax-errors.rs:92:8 - | -LL | ( ${ len() } ) => { - | ^^^^^^^^^ - -note: `$$` and meta-variable expressions are not allowed inside macro parameter definitions - --> $DIR/syntax-errors.rs:92:8 - | -LL | ( ${ len() } ) => { - | ^^^^^^^^^ - -error: expected one of: `*`, `+`, or `?` - --> $DIR/syntax-errors.rs:92:8 - | -LL | ( ${ len() } ) => { - | ^^^^^^^^^ - -error: meta-variables within meta-variable expressions must be referenced using a dollar sign - --> $DIR/syntax-errors.rs:99:33 - | -LL | ( $( $i:ident ),* ) => { ${ ignore() } }; - | ^^^^^^ - -error: only unsuffixes integer literals are supported in meta-variable expressions - --> $DIR/syntax-errors.rs:105:33 - | -LL | ( $( $i:ident ),* ) => { ${ index(1u32) } }; - | ^^^^^ - -error: meta-variable expression parameter must be wrapped in parentheses - --> $DIR/syntax-errors.rs:111:33 - | -LL | ( $( $i:ident ),* ) => { ${ count{i} } }; - | ^^^^^ - -error: meta-variables within meta-variable expressions must be referenced using a dollar sign - --> $DIR/syntax-errors.rs:125:11 - | -LL | ${count(foo)} - | ^^^^^ - -error: meta-variables within meta-variable expressions must be referenced using a dollar sign - --> $DIR/syntax-errors.rs:133:11 - | -LL | ${ignore(bar)} - | ^^^^^^ - -error: unrecognized meta-variable expression - --> $DIR/syntax-errors.rs:140:33 - | -LL | ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; - | ^^^^^^^^^^^^^^ help: supported expressions are count, ignore, index and len - -error: expected identifier or string literal - --> $DIR/syntax-errors.rs:118:33 - | -LL | ( $( $i:ident ),* ) => { ${ {} } }; - | ^^ - -error: `count` can not be placed inside the innermost repetition - --> $DIR/syntax-errors.rs:12:24 - | -LL | ( $i:ident ) => { ${ count($i) } }; - | ^^^^^^^^^^^^^ - -error: `count` can not be placed inside the innermost repetition - --> $DIR/syntax-errors.rs:17:24 - | -LL | ( $i:ident ) => { ${ count($i) } }; - | ^^^^^^^^^^^^^ - -error: variable `i` is still repeating at this depth - --> $DIR/syntax-errors.rs:37:36 - | -LL | ( $( $i:ident ),* ) => { count($i) }; - | ^^ - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:57:9 - | -LL | ${count() a b c} - | ^ expected expression -... -LL | extra_garbage_after_metavar!(a); - | ------------------------------- in this macro invocation - | - = note: this error originates in the macro `extra_garbage_after_metavar` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:86:30 - | -LL | ( $( $i:ident ),* ) => { ${ index(IDX) } }; - | ^ expected expression -... -LL | metavar_depth_is_not_literal!(a); - | -------------------------------- in this macro invocation - | - = note: this error originates in the macro `metavar_depth_is_not_literal` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:99:30 - | -LL | ( $( $i:ident ),* ) => { ${ ignore() } }; - | ^ expected expression -... -LL | metavar_token_without_ident!(a); - | ------------------------------- in this macro invocation - | - = note: this error originates in the macro `metavar_token_without_ident` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:105:30 - | -LL | ( $( $i:ident ),* ) => { ${ index(1u32) } }; - | ^ expected expression -... -LL | metavar_with_literal_suffix!(a); - | ------------------------------- in this macro invocation - | - = note: this error originates in the macro `metavar_with_literal_suffix` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:111:30 - | -LL | ( $( $i:ident ),* ) => { ${ count{i} } }; - | ^ expected expression -... -LL | metavar_without_parens!(a); - | -------------------------- in this macro invocation - | - = note: this error originates in the macro `metavar_without_parens` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:118:30 - | -LL | ( $( $i:ident ),* ) => { ${ {} } }; - | ^ expected expression -... -LL | open_brackets_without_tokens!(a); - | -------------------------------- in this macro invocation - | - = note: this error originates in the macro `open_brackets_without_tokens` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:125:9 - | -LL | ${count(foo)} - | ^ expected expression -... -LL | unknown_count_ident!(a); - | ----------------------- in this macro invocation - | - = note: this error originates in the macro `unknown_count_ident` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:133:9 - | -LL | ${ignore(bar)} - | ^ expected expression -... -LL | unknown_ignore_ident!(a); - | ------------------------ in this macro invocation - | - = note: this error originates in the macro `unknown_ignore_ident` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:140:30 - | -LL | ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; - | ^ expected expression -... -LL | unknown_metavar!(a); - | ------------------- in this macro invocation - | - = note: this error originates in the macro `unknown_metavar` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0425]: cannot find value `i` in this scope - --> $DIR/syntax-errors.rs:23:36 - | -LL | ( $( $i:ident ),* ) => { count(i) }; - | ^ not found in this scope -... -LL | no_curly__no_rhs_dollar__round!(a, b, c); - | ---------------------------------------- in this macro invocation - | - = note: this error originates in the macro `no_curly__no_rhs_dollar__round` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0425]: cannot find value `i` in this scope - --> $DIR/syntax-errors.rs:30:29 - | -LL | ( $i:ident ) => { count(i) }; - | ^ not found in this scope -... -LL | no_curly__no_rhs_dollar__no_round!(a); - | ------------------------------------- in this macro invocation - | - = note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0425]: cannot find value `a` in this scope - --> $DIR/syntax-errors.rs:152:37 - | -LL | ( $i:ident ) => { count($i) }; - | -- due to this macro variable -... -LL | no_curly__rhs_dollar__no_round!(a); - | ^ not found in this scope - -error[E0425]: cannot find function `count` in this scope - --> $DIR/syntax-errors.rs:23:30 - | -LL | ( $( $i:ident ),* ) => { count(i) }; - | ^^^^^ not found in this scope -... -LL | no_curly__no_rhs_dollar__round!(a, b, c); - | ---------------------------------------- in this macro invocation - | - = note: this error originates in the macro `no_curly__no_rhs_dollar__round` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0425]: cannot find function `count` in this scope - --> $DIR/syntax-errors.rs:30:23 - | -LL | ( $i:ident ) => { count(i) }; - | ^^^^^ not found in this scope -... -LL | no_curly__no_rhs_dollar__no_round!(a); - | ------------------------------------- in this macro invocation - | - = note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0425]: cannot find function `count` in this scope - --> $DIR/syntax-errors.rs:43:23 - | -LL | ( $i:ident ) => { count($i) }; - | ^^^^^ not found in this scope -... -LL | no_curly__rhs_dollar__no_round!(a); - | ---------------------------------- in this macro invocation - | - = note: this error originates in the macro `no_curly__rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 39 previous errors - -For more information about this error, try `rustc --explain E0425`. 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/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/methods/method-missing-call.rs b/tests/ui/methods/method-missing-call.rs deleted file mode 100644 index 7ce1e9a4f1b..00000000000 --- a/tests/ui/methods/method-missing-call.rs +++ /dev/null @@ -1,30 +0,0 @@ -// Tests to make sure that parens are needed for method calls without arguments. -// outputs text to make sure either an anonymous function is provided or -// open-close '()' parens are given - - -struct Point { - x: isize, - y: isize -} -impl Point { - fn new() -> Point { - Point{x:0, y:0} - } - fn get_x(&self) -> isize { - self.x - } -} - -fn main() { - let point: Point = Point::new(); - let px: isize = point - .get_x;//~ ERROR attempted to take value of method `get_x` on type `Point` - - // Ensure the span is useful - let ys = &[1,2,3,4,5,6,7]; - let a = ys.iter() - .map(|x| x) - .filter(|&&x| x == 1) - .filter_map; //~ ERROR attempted to take value of method `filter_map` on type -} diff --git a/tests/ui/methods/method-missing-call.stderr b/tests/ui/methods/method-missing-call.stderr deleted file mode 100644 index bc508461b69..00000000000 --- a/tests/ui/methods/method-missing-call.stderr +++ /dev/null @@ -1,25 +0,0 @@ -error[E0615]: attempted to take value of method `get_x` on type `Point` - --> $DIR/method-missing-call.rs:22:26 - | -LL | .get_x; - | ^^^^^ method, not a field - | -help: use parentheses to call the method - | -LL | .get_x(); - | ++ - -error[E0615]: attempted to take value of method `filter_map` on type `Filter<Map<std::slice::Iter<'_, {integer}>, {closure@$DIR/method-missing-call.rs:27:20: 27:23}>, {closure@$DIR/method-missing-call.rs:28:23: 28:28}>` - --> $DIR/method-missing-call.rs:29:16 - | -LL | .filter_map; - | ^^^^^^^^^^ method, not a field - | -help: use parentheses to call the method - | -LL | .filter_map(_); - | +++ - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0615`. diff --git a/tests/ui/methods/method-value-without-call.rs b/tests/ui/methods/method-value-without-call.rs new file mode 100644 index 00000000000..43bee4864b4 --- /dev/null +++ b/tests/ui/methods/method-value-without-call.rs @@ -0,0 +1,33 @@ +//! Test taking a method value without parentheses + +struct Point { + x: isize, + y: isize, +} + +impl Point { + fn new() -> Point { + Point { x: 0, y: 0 } + } + + fn get_x(&self) -> isize { + self.x + } +} + +fn main() { + // Test with primitive type method + let _f = 10i32.abs; //~ ERROR attempted to take value of method + + // Test with custom type method + let point: Point = Point::new(); + let px: isize = point.get_x; //~ ERROR attempted to take value of method `get_x` on type `Point` + + // Test with method chains - ensure the span is useful + let ys = &[1, 2, 3, 4, 5, 6, 7]; + let a = ys + .iter() + .map(|x| x) + .filter(|&&x| x == 1) + .filter_map; //~ ERROR attempted to take value of method `filter_map` on type +} diff --git a/tests/ui/methods/method-value-without-call.stderr b/tests/ui/methods/method-value-without-call.stderr new file mode 100644 index 00000000000..0c3870e2868 --- /dev/null +++ b/tests/ui/methods/method-value-without-call.stderr @@ -0,0 +1,36 @@ +error[E0615]: attempted to take value of method `abs` on type `i32` + --> $DIR/method-value-without-call.rs:20:20 + | +LL | let _f = 10i32.abs; + | ^^^ method, not a field + | +help: use parentheses to call the method + | +LL | let _f = 10i32.abs(); + | ++ + +error[E0615]: attempted to take value of method `get_x` on type `Point` + --> $DIR/method-value-without-call.rs:24:27 + | +LL | let px: isize = point.get_x; + | ^^^^^ method, not a field + | +help: use parentheses to call the method + | +LL | let px: isize = point.get_x(); + | ++ + +error[E0615]: attempted to take value of method `filter_map` on type `Filter<Map<std::slice::Iter<'_, {integer}>, {closure@$DIR/method-value-without-call.rs:30:14: 30:17}>, {closure@$DIR/method-value-without-call.rs:31:17: 31:22}>` + --> $DIR/method-value-without-call.rs:32:10 + | +LL | .filter_map; + | ^^^^^^^^^^ method, not a field + | +help: use parentheses to call the method + | +LL | .filter_map(_); + | +++ + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0615`. diff --git a/tests/ui/mismatched_types/elide-on-tuple-mismatch.rs b/tests/ui/mismatched_types/elide-on-tuple-mismatch.rs new file mode 100644 index 00000000000..c36d041d296 --- /dev/null +++ b/tests/ui/mismatched_types/elide-on-tuple-mismatch.rs @@ -0,0 +1,25 @@ +//! Regression test for issue #50333: elide irrelevant E0277 errors on tuple mismatch + +// Hide irrelevant E0277 errors (#50333) + +trait T {} + +struct A; + +impl T for A {} + +impl A { + fn new() -> Self { + Self {} + } +} + +fn main() { + // This creates a tuple type mismatch: 2-element tuple destructured into 3 variables + let (a, b, c) = (A::new(), A::new()); + //~^ ERROR mismatched types + + // This line should NOT produce an E0277 error about `Sized` trait bounds, + // because `a`, `b`, and `c` are `TyErr` due to the mismatch above + let _ts: Vec<&dyn T> = vec![&a, &b, &c]; +} diff --git a/tests/ui/elide-errors-on-mismatched-tuple.stderr b/tests/ui/mismatched_types/elide-on-tuple-mismatch.stderr index f852a223b42..7de45eb40ca 100644 --- a/tests/ui/elide-errors-on-mismatched-tuple.stderr +++ b/tests/ui/mismatched_types/elide-on-tuple-mismatch.stderr @@ -1,7 +1,7 @@ error[E0308]: mismatched types - --> $DIR/elide-errors-on-mismatched-tuple.rs:14:9 + --> $DIR/elide-on-tuple-mismatch.rs:19:9 | -LL | let (a, b, c) = (A::new(), A::new()); // This tuple is 2 elements, should be three +LL | let (a, b, c) = (A::new(), A::new()); | ^^^^^^^^^ -------------------- this expression has type `(A, A)` | | | expected a tuple with 2 elements, found one with 3 elements 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..e28ca3e55b5 --- /dev/null +++ b/tests/ui/mismatched_types/fn-pointer-mismatch-diagnostics.rs @@ -0,0 +1,16 @@ +//! 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/method-output-diff-issue-127263.stderr b/tests/ui/mismatched_types/fn-pointer-mismatch-diagnostics.stderr index 35b86114f16..8d63f2ea2d3 100644 --- a/tests/ui/method-output-diff-issue-127263.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/integral-variable-unification-error.rs b/tests/ui/mismatched_types/int-float-type-mismatch.rs index 8d1621321e8..b45d02730d9 100644 --- a/tests/ui/integral-variable-unification-error.rs +++ b/tests/ui/mismatched_types/int-float-type-mismatch.rs @@ -1,3 +1,6 @@ +//! 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 = diff --git a/tests/ui/integral-variable-unification-error.stderr b/tests/ui/mismatched_types/int-float-type-mismatch.stderr index 1caa6042fd2..43b8609a49d 100644 --- a/tests/ui/integral-variable-unification-error.stderr +++ b/tests/ui/mismatched_types/int-float-type-mismatch.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/integral-variable-unification-error.rs:5:9 + --> $DIR/int-float-type-mismatch.rs:8:9 | LL | let mut x | ----- expected due to the type of this binding 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<T>(pub T); -} - -fn main() { - Mod::FakeVariant::<i32>(0); - Mod::<i32>::FakeVariant(0); - //~^ ERROR type arguments are not allowed on module `Mod` [E0109] -} 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/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<A>` and `S<B>` have the field `t` at different offsets, - * and apply the wrong instance of the method `unwrap`. - */ - -#[derive(Copy, Clone)] -struct S<T> { i:u8, t:T } - -impl<T> S<T> { - 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<A> = S { i: 0, t: A((13, 104)) }; - static Cb: S<B> = 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/bad-lit-suffixes.rs b/tests/ui/parser/bad-lit-suffixes.rs index 4e8edf4d46e..0a01bb84f01 100644 --- a/tests/ui/parser/bad-lit-suffixes.rs +++ b/tests/ui/parser/bad-lit-suffixes.rs @@ -33,6 +33,7 @@ fn f() {} #[must_use = "string"suffix] //~^ ERROR suffixes on string literals are invalid +//~| ERROR malformed `must_use` attribute input fn g() {} #[link(name = "string"suffix)] @@ -41,4 +42,5 @@ extern "C" {} #[rustc_layout_scalar_valid_range_start(0suffix)] //~^ ERROR invalid suffix `suffix` for number literal +//~| ERROR malformed `rustc_layout_scalar_valid_range_start` attribute input struct S; diff --git a/tests/ui/parser/bad-lit-suffixes.stderr b/tests/ui/parser/bad-lit-suffixes.stderr index 416143e496a..7876d75c5a4 100644 --- a/tests/ui/parser/bad-lit-suffixes.stderr +++ b/tests/ui/parser/bad-lit-suffixes.stderr @@ -23,13 +23,13 @@ LL | #[must_use = "string"suffix] | ^^^^^^^^^^^^^^ invalid suffix `suffix` error: suffixes on string literals are invalid - --> $DIR/bad-lit-suffixes.rs:38:15 + --> $DIR/bad-lit-suffixes.rs:39:15 | LL | #[link(name = "string"suffix)] | ^^^^^^^^^^^^^^ invalid suffix `suffix` error: invalid suffix `suffix` for number literal - --> $DIR/bad-lit-suffixes.rs:42:41 + --> $DIR/bad-lit-suffixes.rs:43:41 | LL | #[rustc_layout_scalar_valid_range_start(0suffix)] | ^^^^^^^ invalid suffix `suffix` @@ -150,5 +150,33 @@ LL | 1.0e10suffix; | = help: valid suffixes are `f32` and `f64` -error: aborting due to 20 previous errors; 2 warnings emitted +error[E0539]: malformed `must_use` attribute input + --> $DIR/bad-lit-suffixes.rs:34:1 + | +LL | #[must_use = "string"suffix] + | ^^^^^^^^^^^^^--------------^ + | | + | expected a string literal here + | +help: try changing it to one of the following valid forms of the attribute + | +LL - #[must_use = "string"suffix] +LL + #[must_use = "reason"] + | +LL - #[must_use = "string"suffix] +LL + #[must_use] + | + +error[E0805]: malformed `rustc_layout_scalar_valid_range_start` attribute input + --> $DIR/bad-lit-suffixes.rs:43:1 + | +LL | #[rustc_layout_scalar_valid_range_start(0suffix)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------^ + | | | + | | expected a single argument here + | help: must be of the form: `#[rustc_layout_scalar_valid_range_start(start)]` + +error: aborting due to 22 previous errors; 2 warnings emitted +Some errors have detailed explanations: E0539, E0805. +For more information about an error, try `rustc --explain E0539`. diff --git a/tests/ui/parser/multiline-comments-basic.rs b/tests/ui/parser/multiline-comments-basic.rs new file mode 100644 index 00000000000..1aa2a531f5c --- /dev/null +++ b/tests/ui/parser/multiline-comments-basic.rs @@ -0,0 +1,10 @@ +//! Test that basic multiline comments are parsed correctly. +//! +//! Feature implementation test for <https://github.com/rust-lang/rust/issues/66>. + +//@ run-pass + +/* + * This is a multi-line comment. + */ +pub fn main() {} diff --git a/tests/ui/double-ref.rs b/tests/ui/parser/reference-whitespace-parsing.rs index eecf68ff209..7109c5911ae 100644 --- a/tests/ui/double-ref.rs +++ b/tests/ui/parser/reference-whitespace-parsing.rs @@ -1,3 +1,5 @@ +//! Test parsing of multiple references with various whitespace arrangements + //@ run-pass #![allow(dead_code)] 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..b1bb0c66ae2 --- /dev/null +++ b/tests/ui/parser/unicode-multibyte-chars-no-ice.rs @@ -0,0 +1,9 @@ +//! Test that multibyte Unicode characters don't crash the compiler. +//! +//! Regression test for <https://github.com/rust-lang/rust/issues/4780>. + +//@ run-pass + +pub fn main() { + println!("마이너스 사인이 없으면"); +} diff --git a/tests/ui/resolve/resolve-conflict-extern-crate-vs-extern-crate.stderr b/tests/ui/resolve/resolve-conflict-extern-crate-vs-extern-crate.stderr index a9b45a18af3..f53e9e3b478 100644 --- a/tests/ui/resolve/resolve-conflict-extern-crate-vs-extern-crate.stderr +++ b/tests/ui/resolve/resolve-conflict-extern-crate-vs-extern-crate.stderr @@ -2,6 +2,7 @@ error[E0259]: the name `std` is defined multiple times | = note: `std` must be defined only once in the type namespace of this module help: you can use `as` to change the binding name of the import + --> $DIR/resolve-conflict-extern-crate-vs-extern-crate.rs:1:17 | LL | extern crate std as other_std; | ++++++++++++ diff --git a/tests/ui/max-min-classes.rs b/tests/ui/resolve/struct-function-same-name.rs index 338a3156a9a..bb2837d7ca6 100644 --- a/tests/ui/max-min-classes.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/lexical-scoping.rs b/tests/ui/resolve/type-param-local-var-shadowing.rs index f858369f7ce..e08379e2acf 100644 --- a/tests/ui/lexical-scoping.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> { x: Box<X> } +struct Foo<X> { + x: Box<X>, +} impl<Bar> Foo<Bar> { fn foo(&self) { type Bar = i32; diff --git a/tests/ui/self/self-infer.rs b/tests/ui/self/self-infer.rs index 9839b8880e9..d6f6d8bfa06 100644 --- a/tests/ui/self/self-infer.rs +++ b/tests/ui/self/self-infer.rs @@ -1,8 +1,8 @@ struct S; impl S { - fn f(self: _) {} //~ERROR the placeholder `_` is not allowed within types on item signatures for functions - fn g(self: &_) {} //~ERROR the placeholder `_` is not allowed within types on item signatures for functions + fn f(self: _) {} //~ERROR the placeholder `_` is not allowed within types on item signatures for methods + fn g(self: &_) {} //~ERROR the placeholder `_` is not allowed within types on item signatures for methods } fn main() {} diff --git a/tests/ui/self/self-infer.stderr b/tests/ui/self/self-infer.stderr index f9db559390f..13d803d9559 100644 --- a/tests/ui/self/self-infer.stderr +++ b/tests/ui/self/self-infer.stderr @@ -1,10 +1,10 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/self-infer.rs:4:16 | LL | fn f(self: _) {} | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/self-infer.rs:5:17 | LL | fn g(self: &_) {} diff --git a/tests/ui/simd/intrinsic/float-math-pass.rs b/tests/ui/simd/intrinsic/float-math-pass.rs index 4c28568a739..01fed8537d0 100644 --- a/tests/ui/simd/intrinsic/float-math-pass.rs +++ b/tests/ui/simd/intrinsic/float-math-pass.rs @@ -85,6 +85,9 @@ fn main() { let r = simd_round(h); assert_eq!(x, r); + let r = simd_round_ties_even(h); + assert_eq!(z, r); + let r = simd_trunc(h); assert_eq!(z, r); } diff --git a/tests/ui/simd/intrinsic/generic-arithmetic-2.rs b/tests/ui/simd/intrinsic/generic-arithmetic-2.rs index fdf06b7882e..caec607d6fe 100644 --- a/tests/ui/simd/intrinsic/generic-arithmetic-2.rs +++ b/tests/ui/simd/intrinsic/generic-arithmetic-2.rs @@ -43,6 +43,10 @@ fn main() { simd_shl(y, y); simd_shr(x, x); simd_shr(y, y); + simd_funnel_shl(x, x, x); + simd_funnel_shl(y, y, y); + simd_funnel_shr(x, x, x); + simd_funnel_shr(y, y, y); simd_and(x, x); simd_and(y, y); simd_or(x, x); @@ -73,6 +77,10 @@ fn main() { //~^ ERROR expected SIMD input type, found non-SIMD `i32` simd_shr(0, 0); //~^ ERROR expected SIMD input type, found non-SIMD `i32` + simd_funnel_shl(0, 0, 0); + //~^ ERROR expected SIMD input type, found non-SIMD `i32` + simd_funnel_shr(0, 0, 0); + //~^ ERROR expected SIMD input type, found non-SIMD `i32` simd_and(0, 0); //~^ ERROR expected SIMD input type, found non-SIMD `i32` simd_or(0, 0); @@ -95,6 +103,10 @@ fn main() { //~^ ERROR unsupported operation on `f32x4` with element `f32` simd_shr(z, z); //~^ ERROR unsupported operation on `f32x4` with element `f32` + simd_funnel_shl(z, z, z); + //~^ ERROR unsupported operation on `f32x4` with element `f32` + simd_funnel_shr(z, z, z); + //~^ ERROR unsupported operation on `f32x4` with element `f32` simd_and(z, z); //~^ ERROR unsupported operation on `f32x4` with element `f32` simd_or(z, z); diff --git a/tests/ui/simd/intrinsic/generic-arithmetic-2.stderr b/tests/ui/simd/intrinsic/generic-arithmetic-2.stderr index 76db6d5328f..a27a8d721fb 100644 --- a/tests/ui/simd/intrinsic/generic-arithmetic-2.stderr +++ b/tests/ui/simd/intrinsic/generic-arithmetic-2.stderr @@ -1,147 +1,171 @@ error[E0511]: invalid monomorphization of `simd_add` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-arithmetic-2.rs:64:9 + --> $DIR/generic-arithmetic-2.rs:68:9 | LL | simd_add(0, 0); | ^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_sub` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-arithmetic-2.rs:66:9 + --> $DIR/generic-arithmetic-2.rs:70:9 | LL | simd_sub(0, 0); | ^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_mul` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-arithmetic-2.rs:68:9 + --> $DIR/generic-arithmetic-2.rs:72:9 | LL | simd_mul(0, 0); | ^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_div` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-arithmetic-2.rs:70:9 + --> $DIR/generic-arithmetic-2.rs:74:9 | LL | simd_div(0, 0); | ^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shl` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-arithmetic-2.rs:72:9 + --> $DIR/generic-arithmetic-2.rs:76:9 | LL | simd_shl(0, 0); | ^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shr` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-arithmetic-2.rs:74:9 + --> $DIR/generic-arithmetic-2.rs:78:9 | LL | simd_shr(0, 0); | ^^^^^^^^^^^^^^ +error[E0511]: invalid monomorphization of `simd_funnel_shl` intrinsic: expected SIMD input type, found non-SIMD `i32` + --> $DIR/generic-arithmetic-2.rs:80:9 + | +LL | simd_funnel_shl(0, 0, 0); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0511]: invalid monomorphization of `simd_funnel_shr` intrinsic: expected SIMD input type, found non-SIMD `i32` + --> $DIR/generic-arithmetic-2.rs:82:9 + | +LL | simd_funnel_shr(0, 0, 0); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + error[E0511]: invalid monomorphization of `simd_and` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-arithmetic-2.rs:76:9 + --> $DIR/generic-arithmetic-2.rs:84:9 | LL | simd_and(0, 0); | ^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_or` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-arithmetic-2.rs:78:9 + --> $DIR/generic-arithmetic-2.rs:86:9 | LL | simd_or(0, 0); | ^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_xor` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-arithmetic-2.rs:80:9 + --> $DIR/generic-arithmetic-2.rs:88:9 | LL | simd_xor(0, 0); | ^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_neg` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-arithmetic-2.rs:83:9 + --> $DIR/generic-arithmetic-2.rs:91:9 | LL | simd_neg(0); | ^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_bswap` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-arithmetic-2.rs:85:9 + --> $DIR/generic-arithmetic-2.rs:93:9 | LL | simd_bswap(0); | ^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_bitreverse` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-arithmetic-2.rs:87:9 + --> $DIR/generic-arithmetic-2.rs:95:9 | LL | simd_bitreverse(0); | ^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_ctlz` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-arithmetic-2.rs:89:9 + --> $DIR/generic-arithmetic-2.rs:97:9 | LL | simd_ctlz(0); | ^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_cttz` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-arithmetic-2.rs:91:9 + --> $DIR/generic-arithmetic-2.rs:99:9 | LL | simd_cttz(0); | ^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shl` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:94:9 + --> $DIR/generic-arithmetic-2.rs:102:9 | LL | simd_shl(z, z); | ^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shr` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:96:9 + --> $DIR/generic-arithmetic-2.rs:104:9 | LL | simd_shr(z, z); | ^^^^^^^^^^^^^^ +error[E0511]: invalid monomorphization of `simd_funnel_shl` intrinsic: unsupported operation on `f32x4` with element `f32` + --> $DIR/generic-arithmetic-2.rs:106:9 + | +LL | simd_funnel_shl(z, z, z); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0511]: invalid monomorphization of `simd_funnel_shr` intrinsic: unsupported operation on `f32x4` with element `f32` + --> $DIR/generic-arithmetic-2.rs:108:9 + | +LL | simd_funnel_shr(z, z, z); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + error[E0511]: invalid monomorphization of `simd_and` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:98:9 + --> $DIR/generic-arithmetic-2.rs:110:9 | LL | simd_and(z, z); | ^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_or` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:100:9 + --> $DIR/generic-arithmetic-2.rs:112:9 | LL | simd_or(z, z); | ^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_xor` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:102:9 + --> $DIR/generic-arithmetic-2.rs:114:9 | LL | simd_xor(z, z); | ^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_bswap` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:104:9 + --> $DIR/generic-arithmetic-2.rs:116:9 | LL | simd_bswap(z); | ^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_bitreverse` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:106:9 + --> $DIR/generic-arithmetic-2.rs:118:9 | LL | simd_bitreverse(z); | ^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_ctlz` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:108:9 + --> $DIR/generic-arithmetic-2.rs:120:9 | LL | simd_ctlz(z); | ^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_ctpop` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:110:9 + --> $DIR/generic-arithmetic-2.rs:122:9 | LL | simd_ctpop(z); | ^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_cttz` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:112:9 + --> $DIR/generic-arithmetic-2.rs:124:9 | LL | simd_cttz(z); | ^^^^^^^^^^^^ -error: aborting due to 24 previous errors +error: aborting due to 28 previous errors For more information about this error, try `rustc --explain E0511`. diff --git a/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs b/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs index 3f0325d690b..4c97fb2141d 100644 --- a/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs +++ b/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs @@ -83,6 +83,80 @@ fn main() { all_eq!(simd_shr(simd_shl(y1, y2), y2), y1); all_eq!(simd_shr(simd_shl(y2, y1), y1), y2); + all_eq!( + simd_funnel_shl(x1, x2, x1), + i32x4([ + (1 << 1) | (2 >> 31), + (2 << 2) | (3 >> 30), + (3 << 3) | (4 >> 29), + (4 << 4) | (5 >> 28) + ]) + ); + all_eq!( + simd_funnel_shl(x2, x1, x1), + i32x4([ + (2 << 1) | (1 >> 31), + (3 << 2) | (2 >> 30), + (4 << 3) | (3 >> 29), + (5 << 4) | (4 >> 28) + ]) + ); + all_eq!( + simd_funnel_shl(y1, y2, y1), + U32::<4>([ + (1 << 1) | (2 >> 31), + (2 << 2) | (3 >> 30), + (3 << 3) | (4 >> 29), + (4 << 4) | (5 >> 28) + ]) + ); + all_eq!( + simd_funnel_shl(y2, y1, y1), + U32::<4>([ + (2 << 1) | (1 >> 31), + (3 << 2) | (2 >> 30), + (4 << 3) | (3 >> 29), + (5 << 4) | (4 >> 28) + ]) + ); + + all_eq!( + simd_funnel_shr(x1, x2, x1), + i32x4([ + (1 << 31) | (2 >> 1), + (2 << 30) | (3 >> 2), + (3 << 29) | (4 >> 3), + (4 << 28) | (5 >> 4) + ]) + ); + all_eq!( + simd_funnel_shr(x2, x1, x1), + i32x4([ + (2 << 31) | (1 >> 1), + (3 << 30) | (2 >> 2), + (4 << 29) | (3 >> 3), + (5 << 28) | (4 >> 4) + ]) + ); + all_eq!( + simd_funnel_shr(y1, y2, y1), + U32::<4>([ + (1 << 31) | (2 >> 1), + (2 << 30) | (3 >> 2), + (3 << 29) | (4 >> 3), + (4 << 28) | (5 >> 4) + ]) + ); + all_eq!( + simd_funnel_shr(y2, y1, y1), + U32::<4>([ + (2 << 31) | (1 >> 1), + (3 << 30) | (2 >> 2), + (4 << 29) | (3 >> 3), + (5 << 28) | (4 >> 4) + ]) + ); + // ensure we get logical vs. arithmetic shifts correct let (a, b, c, d) = (-12, -123, -1234, -12345); all_eq!(simd_shr(i32x4([a, b, c, d]), x1), i32x4([a >> 1, b >> 2, c >> 3, d >> 4])); 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<T> { + //~^ ERROR parameter `T` is never used + What, +} + +fn foo<T>() { + static a: Bar<T> = 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/statics/static-generic-param-soundness.stderr index 88d33b44c59..47554c7fcb0 100644 --- a/tests/ui/inner-static-type-parameter.stderr +++ b/tests/ui/statics/static-generic-param-soundness.stderr @@ -1,5 +1,5 @@ error[E0401]: can't use generic parameters from outer item - --> $DIR/inner-static-type-parameter.rs:6:19 + --> $DIR/static-generic-param-soundness.rs:16:19 | LL | fn foo<T>() { | - type parameter from outer item @@ -9,9 +9,9 @@ LL | static a: Bar<T> = Bar::What; = 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 + --> $DIR/static-generic-param-soundness.rs:10:10 | -LL | enum Bar<T> { What } +LL | enum Bar<T> { | ^ unused type parameter | = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` diff --git a/tests/ui/stats/macro-stats.rs b/tests/ui/stats/macro-stats.rs index ee265d682fd..d986904ddd6 100644 --- a/tests/ui/stats/macro-stats.rs +++ b/tests/ui/stats/macro-stats.rs @@ -49,12 +49,17 @@ fn opt(x: Option<u32>) { } } -macro_rules! this_is_a_really_really_long_macro_name { +macro_rules! long_name_that_fits_on_a_single_line { + () => {} +} +long_name_that_fits_on_a_single_line!(); + +macro_rules! long_name_that_doesnt_fit_on_one_line { ($t:ty) => { fn f(_: $t) {} } } -this_is_a_really_really_long_macro_name!(u32!()); // AstFragmentKind::{Items,Ty} +long_name_that_doesnt_fit_on_one_line!(u32!()); // AstFragmentKind::{Items,Ty} macro_rules! trait_tys { () => { diff --git a/tests/ui/stats/macro-stats.stderr b/tests/ui/stats/macro-stats.stderr index 00c6b55c6a2..8d0fdb8958a 100644 --- a/tests/ui/stats/macro-stats.stderr +++ b/tests/ui/stats/macro-stats.stderr @@ -15,12 +15,13 @@ macro-stats #[derive(Copy)] 1 2 2.0 macro-stats p! 1 3 3.0 32 32.0 macro-stats trait_impl_tys! 1 2 2.0 28 28.0 macro-stats foreign_item! 1 1 1.0 21 21.0 -macro-stats this_is_a_really_really_long_macro_name! +macro-stats long_name_that_doesnt_fit_on_one_line! macro-stats 1 1 1.0 18 18.0 macro-stats impl_const! 1 1 1.0 17 17.0 macro-stats trait_tys! 1 2 2.0 15 15.0 macro-stats n99! 2 2 1.0 4 2.0 macro-stats none! 1 1 1.0 4 4.0 macro-stats u32! 1 1 1.0 3 3.0 +macro-stats long_name_that_fits_on_a_single_line! 1 1 1.0 0 0.0 macro-stats #[test] 1 1 1.0 0 0.0 macro-stats =================================================================================== diff --git a/tests/ui/suggestions/bad-infer-in-trait-impl.rs b/tests/ui/suggestions/bad-infer-in-trait-impl.rs index f38b168037b..db6fc9319e1 100644 --- a/tests/ui/suggestions/bad-infer-in-trait-impl.rs +++ b/tests/ui/suggestions/bad-infer-in-trait-impl.rs @@ -4,7 +4,7 @@ trait Foo { impl Foo for () { fn bar(s: _) {} - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated functions //~| ERROR has 1 parameter but the declaration in trait `Foo::bar` has 0 } diff --git a/tests/ui/suggestions/bad-infer-in-trait-impl.stderr b/tests/ui/suggestions/bad-infer-in-trait-impl.stderr index 8b7d67ac041..5aa46545943 100644 --- a/tests/ui/suggestions/bad-infer-in-trait-impl.stderr +++ b/tests/ui/suggestions/bad-infer-in-trait-impl.stderr @@ -1,4 +1,4 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions --> $DIR/bad-infer-in-trait-impl.rs:6:15 | LL | fn bar(s: _) {} diff --git a/tests/ui/test-attrs/test-function-elided-no-main.rs b/tests/ui/test-attrs/test-function-elided-no-main.rs new file mode 100644 index 00000000000..97654581567 --- /dev/null +++ b/tests/ui/test-attrs/test-function-elided-no-main.rs @@ -0,0 +1,8 @@ +//! Test that #[test] functions are elided when not running tests, causing missing main error + +#[test] +fn main() { + // This function would normally serve as main, but since it's marked with #[test], + // it gets elided when not running tests +} +//~^ ERROR `main` function not found in crate `test_function_elided_no_main` diff --git a/tests/ui/test-attrs/test-function-elided-no-main.stderr b/tests/ui/test-attrs/test-function-elided-no-main.stderr new file mode 100644 index 00000000000..0bae690be2b --- /dev/null +++ b/tests/ui/test-attrs/test-function-elided-no-main.stderr @@ -0,0 +1,9 @@ +error[E0601]: `main` function not found in crate `test_function_elided_no_main` + --> $DIR/test-function-elided-no-main.rs:7:2 + | +LL | } + | ^ consider adding a `main` function to `$DIR/test-function-elided-no-main.rs` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0601`. diff --git a/tests/ui/traits/const-traits/ice-119717-constant-lifetime.stderr b/tests/ui/traits/const-traits/ice-119717-constant-lifetime.stderr index c6e0c699520..a165ef12060 100644 --- a/tests/ui/traits/const-traits/ice-119717-constant-lifetime.stderr +++ b/tests/ui/traits/const-traits/ice-119717-constant-lifetime.stderr @@ -16,7 +16,7 @@ LL | impl<T> const FromResidual for T { = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions --> $DIR/ice-119717-constant-lifetime.rs:9:31 | LL | fn from_residual(t: T) -> _ { diff --git a/tests/ui/impl-unused-tps.rs b/tests/ui/traits/constrained-type-params-trait-impl.rs index a5836db3c8e..301bbdb2ccb 100644 --- a/tests/ui/impl-unused-tps.rs +++ b/tests/ui/traits/constrained-type-params-trait-impl.rs @@ -1,3 +1,11 @@ +//! Comprehensive test for type parameter constraints in trait implementations +//! +//! This tests various scenarios of type parameter usage in trait implementations: +//! - Properly constrained parameters through trait bounds +//! - Unconstrained parameters that should cause compilation errors +//! - Complex constraint scenarios with `where` clauses and associated types +//! - Conflicting implementations detection + trait Foo<A> { fn get(&self, A: &A) {} } @@ -7,34 +15,34 @@ trait Bar { } impl<T> Foo<T> for [isize; 0] { - // OK, T is used in `Foo<T>`. + // OK: T is used in the trait bound `Foo<T>` } impl<T, U> Foo<T> for [isize; 1] { //~^ ERROR the type parameter `U` is not constrained + // T is constrained by `Foo<T>`, but U is completely unused } impl<T, U> Foo<T> for [isize; 2] where T: Bar<Out = U>, { - // OK, `U` is now constrained by the output type parameter. + // OK: T is constrained by `Foo<T>`, U is constrained by the where clause } impl<T: Bar<Out = U>, U> Foo<T> for [isize; 3] { - // OK, same as above but written differently. + // OK: Same as above but using bound syntax instead of where clause } impl<T, U> Foo<T> for U { //~^ ERROR conflicting implementations of trait `Foo<_>` for type `[isize; 0]` + // This conflicts with the first impl when U = [isize; 0] } impl<T, U> Bar for T { //~^ ERROR the type parameter `U` is not constrained - type Out = U; - - // Using `U` in an associated type within the impl is not good enough! + // Using U only in associated type definition is insufficient for constraint } impl<T, U> Bar for T @@ -43,7 +51,7 @@ where { //~^^^^ ERROR the type parameter `U` is not constrained by the impl trait, self type, or predicates //~| ERROR conflicting implementations of trait `Bar` - // This crafty self-referential attempt is still no good. + // Self-referential constraint doesn't properly constrain U } impl<T, U, V> Foo<T> for T @@ -53,9 +61,7 @@ where //~^^^^ ERROR the type parameter `U` is not constrained //~| ERROR the type parameter `V` is not constrained //~| ERROR conflicting implementations of trait `Foo<[isize; 0]>` for type `[isize; 0]` - - // Here, `V` is bound by an output type parameter, but the inputs - // are not themselves constrained. + // V is bound through output type, but U and V are not properly constrained as inputs } impl<T, U, V> Foo<(T, U)> for T @@ -63,7 +69,7 @@ where (T, U): Bar<Out = V>, { //~^^^^ ERROR conflicting implementations of trait `Foo<([isize; 0], _)>` for type `[isize; 0]` - // As above, but both T and U ARE constrained. + // Both T and U are constrained through `Foo<(T, U)>`, but creates conflicting impl } fn main() {} diff --git a/tests/ui/impl-unused-tps.stderr b/tests/ui/traits/constrained-type-params-trait-impl.stderr index eff5ffff9b6..2175129a8df 100644 --- a/tests/ui/impl-unused-tps.stderr +++ b/tests/ui/traits/constrained-type-params-trait-impl.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `Foo<_>` for type `[isize; 0]` - --> $DIR/impl-unused-tps.rs:28:1 + --> $DIR/constrained-type-params-trait-impl.rs:37:1 | LL | impl<T> Foo<T> for [isize; 0] { | ----------------------------- first implementation here @@ -8,7 +8,7 @@ LL | impl<T, U> Foo<T> for U { | ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `[isize; 0]` error[E0119]: conflicting implementations of trait `Foo<[isize; 0]>` for type `[isize; 0]` - --> $DIR/impl-unused-tps.rs:49:1 + --> $DIR/constrained-type-params-trait-impl.rs:57:1 | LL | impl<T> Foo<T> for [isize; 0] { | ----------------------------- first implementation here @@ -19,7 +19,7 @@ LL | | (T, U): Bar<Out = V>, | |_________________________^ conflicting implementation for `[isize; 0]` error[E0119]: conflicting implementations of trait `Foo<([isize; 0], _)>` for type `[isize; 0]` - --> $DIR/impl-unused-tps.rs:61:1 + --> $DIR/constrained-type-params-trait-impl.rs:67:1 | LL | impl<T> Foo<T> for [isize; 0] { | ----------------------------- first implementation here @@ -30,37 +30,37 @@ LL | | (T, U): Bar<Out = V>, | |_________________________^ conflicting implementation for `[isize; 0]` error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates - --> $DIR/impl-unused-tps.rs:13:9 + --> $DIR/constrained-type-params-trait-impl.rs:21:9 | LL | impl<T, U> Foo<T> for [isize; 1] { | ^ unconstrained type parameter error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates - --> $DIR/impl-unused-tps.rs:32:9 + --> $DIR/constrained-type-params-trait-impl.rs:42:9 | LL | impl<T, U> Bar for T { | ^ unconstrained type parameter error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates - --> $DIR/impl-unused-tps.rs:40:9 + --> $DIR/constrained-type-params-trait-impl.rs:48:9 | LL | impl<T, U> Bar for T | ^ unconstrained type parameter error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates - --> $DIR/impl-unused-tps.rs:49:9 + --> $DIR/constrained-type-params-trait-impl.rs:57:9 | LL | impl<T, U, V> Foo<T> for T | ^ unconstrained type parameter error[E0207]: the type parameter `V` is not constrained by the impl trait, self type, or predicates - --> $DIR/impl-unused-tps.rs:49:12 + --> $DIR/constrained-type-params-trait-impl.rs:57:12 | LL | impl<T, U, V> Foo<T> for T | ^ unconstrained type parameter error[E0119]: conflicting implementations of trait `Bar` - --> $DIR/impl-unused-tps.rs:40:1 + --> $DIR/constrained-type-params-trait-impl.rs:48:1 | LL | impl<T, U> Bar for T { | -------------------- first implementation here diff --git a/tests/ui/invalid_dispatch_from_dyn_impls.rs b/tests/ui/traits/dispatch-from-dyn-invalid-impls.rs index b1d4b261bab..f5f66ca69cf 100644 --- a/tests/ui/invalid_dispatch_from_dyn_impls.rs +++ b/tests/ui/traits/dispatch-from-dyn-invalid-impls.rs @@ -1,20 +1,30 @@ +//! 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::{ - ops::DispatchFromDyn, - marker::{Unsize, PhantomData}, -}; +use std::marker::{PhantomData, Unsize}; +use std::ops::DispatchFromDyn; +// Extra field prevents DispatchFromDyn struct WrapperWithExtraField<T>(T, i32); impl<T, U> DispatchFromDyn<WrapperWithExtraField<U>> for WrapperWithExtraField<T> //~^ ERROR [E0378] where - T: DispatchFromDyn<U>, -{} - + T: DispatchFromDyn<U> +{ +} -struct MultiplePointers<T: ?Sized>{ +// Multiple pointer fields create ambiguous coercion +struct MultiplePointers<T: ?Sized> { ptr1: *const T, ptr2: *const T, } @@ -22,10 +32,11 @@ struct MultiplePointers<T: ?Sized>{ impl<T: ?Sized, U: ?Sized> DispatchFromDyn<MultiplePointers<U>> for MultiplePointers<T> //~^ ERROR implementing `DispatchFromDyn` does not allow multiple fields to be coerced where - T: Unsize<U>, -{} - + T: Unsize<U> +{ +} +// No coercible fields (only PhantomData) struct NothingToCoerce<T: ?Sized> { data: PhantomData<T>, } @@ -33,23 +44,28 @@ struct NothingToCoerce<T: ?Sized> { impl<T: ?Sized, U: ?Sized> DispatchFromDyn<NothingToCoerce<T>> for NothingToCoerce<U> {} //~^ ERROR implementing `DispatchFromDyn` requires a field to be coerced +// repr(C) is incompatible with DispatchFromDyn #[repr(C)] struct HasReprC<T: ?Sized>(Box<T>); impl<T: ?Sized, U: ?Sized> DispatchFromDyn<HasReprC<U>> for HasReprC<T> //~^ ERROR [E0378] where - T: Unsize<U>, -{} + T: Unsize<U> +{ +} +// Over-aligned fields are incompatible #[repr(align(64))] struct OverAlignedZst; + struct OverAligned<T: ?Sized>(Box<T>, OverAlignedZst); impl<T: ?Sized, U: ?Sized> DispatchFromDyn<OverAligned<U>> for OverAligned<T> //~^ ERROR [E0378] - where - T: Unsize<U>, -{} +where + T: Unsize<U> +{ +} fn main() {} diff --git a/tests/ui/invalid_dispatch_from_dyn_impls.stderr b/tests/ui/traits/dispatch-from-dyn-invalid-impls.stderr index 93ec6bbe089..676da0ce81f 100644 --- a/tests/ui/invalid_dispatch_from_dyn_impls.stderr +++ b/tests/ui/traits/dispatch-from-dyn-invalid-impls.stderr @@ -1,25 +1,25 @@ 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 + --> $DIR/dispatch-from-dyn-invalid-impls.rs:19:1 | LL | / impl<T, U> DispatchFromDyn<WrapperWithExtraField<U>> for WrapperWithExtraField<T> LL | | LL | | where -LL | | T: DispatchFromDyn<U>, - | |__________________________^ +LL | | T: DispatchFromDyn<U> + | |_________________________^ | = 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 + --> $DIR/dispatch-from-dyn-invalid-impls.rs:32:1 | LL | / impl<T: ?Sized, U: ?Sized> DispatchFromDyn<MultiplePointers<U>> for MultiplePointers<T> LL | | LL | | where -LL | | T: Unsize<U>, - | |_________________^ +LL | | T: Unsize<U> + | |________________^ | note: the trait `DispatchFromDyn` may only be implemented when a single field is being coerced - --> $DIR/invalid_dispatch_from_dyn_impls.rs:18:5 + --> $DIR/dispatch-from-dyn-invalid-impls.rs:28:5 | LL | ptr1: *const T, | ^^^^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL | ptr2: *const T, | ^^^^^^^^^^^^^^ error[E0374]: implementing `DispatchFromDyn` requires a field to be coerced - --> $DIR/invalid_dispatch_from_dyn_impls.rs:33:1 + --> $DIR/dispatch-from-dyn-invalid-impls.rs:44:1 | LL | impl<T: ?Sized, U: ?Sized> DispatchFromDyn<NothingToCoerce<T>> for NothingToCoerce<U> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -35,22 +35,22 @@ LL | impl<T: ?Sized, U: ?Sized> DispatchFromDyn<NothingToCoerce<T>> for NothingT = 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 + --> $DIR/dispatch-from-dyn-invalid-impls.rs:51:1 | LL | / impl<T: ?Sized, U: ?Sized> DispatchFromDyn<HasReprC<U>> for HasReprC<T> LL | | LL | | where -LL | | T: Unsize<U>, - | |_________________^ +LL | | T: Unsize<U> + | |________________^ 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 + --> $DIR/dispatch-from-dyn-invalid-impls.rs:64:1 | LL | / impl<T: ?Sized, U: ?Sized> DispatchFromDyn<OverAligned<U>> for OverAligned<T> LL | | -LL | | where -LL | | T: Unsize<U>, - | |_____________________^ +LL | | where +LL | | T: Unsize<U> + | |________________^ | = note: extra field `1` of type `OverAlignedZst` is not allowed diff --git a/tests/ui/issue-11881.rs b/tests/ui/traits/encoder-trait-bounds-regression.rs index 1abe0797203..292b921cdf7 100644 --- a/tests/ui/issue-11881.rs +++ b/tests/ui/traits/encoder-trait-bounds-regression.rs @@ -1,14 +1,23 @@ +//! 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<JsonEncoder<'r>>) +//! - Multiple encoder implementations for the same type +//! - Polymorphic encoding functions + //@ 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::io::prelude::*; use std::marker::PhantomData; +use std::{fmt, slice}; trait Encoder { type Error; @@ -45,7 +54,6 @@ impl Encoder for OpaqueEncoder { type Error = (); } - struct Foo { baz: bool, } @@ -69,7 +77,6 @@ impl<S: Encoder> Encodable<S> for Bar { enum WireProtocol { JSON, Opaque, - // ... } fn encode_json<T: for<'a> Encodable<JsonEncoder<'a>>>(val: &T, wr: &mut Cursor<Vec<u8>>) { 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<Self>, + //~^ ERROR use of undeclared lifetime name `'missing` +{ +} + +// Proving `N: Numoid`'s well-formedness causes us to have to prove `&'missing N: Add<N>`. +// 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<N>` will also hit this cache entry +// even if candidate assembly can't assemble anything for `&'?0 N: Add<?1>` anyways. This +// led to an ICE. +pub fn compute<N: Numoid>(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<Self>, + | ^^^^^^^^ 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<Self>, + | +++++++++++++ +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<N: Numoid>(a: N) where &N: Add<N> { + | ++++++++++++++++ + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0261, E0369. +For more information about an error, try `rustc --explain E0261`. 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..04963c98765 --- /dev/null +++ b/tests/ui/traits/maybe-trait-bounds-forbidden-locations.rs @@ -0,0 +1,18 @@ +//! 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 + +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/traits/maybe-trait-bounds-forbidden-locations.stderr index 230d11fd0ae..bd0baa580bd 100644 --- a/tests/ui/maybe-bounds.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/traits/method-argument-mismatch-variance-ice-119867.stderr b/tests/ui/traits/method-argument-mismatch-variance-ice-119867.stderr index d535c39639f..6472ac7363b 100644 --- a/tests/ui/traits/method-argument-mismatch-variance-ice-119867.stderr +++ b/tests/ui/traits/method-argument-mismatch-variance-ice-119867.stderr @@ -1,4 +1,4 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions --> $DIR/method-argument-mismatch-variance-ice-119867.rs:8:23 | LL | fn deserialize(s: _) {} diff --git a/tests/ui/transmute/diverging-fn-transmute.rs b/tests/ui/transmute/diverging-fn-transmute.rs new file mode 100644 index 00000000000..aca82037a0c --- /dev/null +++ b/tests/ui/transmute/diverging-fn-transmute.rs @@ -0,0 +1,10 @@ +//! Regression test for issue #35849: transmute with panic in diverging function + +fn assert_sizeof() -> ! { + unsafe { + ::std::mem::transmute::<f64, [u8; 8]>(panic!()) + //~^ ERROR mismatched types + } +} + +fn main() {} diff --git a/tests/ui/diverging-fn-tail-35849.stderr b/tests/ui/transmute/diverging-fn-transmute.stderr index 614f9b9cb5d..b9aeae7ed62 100644 --- a/tests/ui/diverging-fn-tail-35849.stderr +++ b/tests/ui/transmute/diverging-fn-transmute.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/diverging-fn-tail-35849.rs:3:9 + --> $DIR/diverging-fn-transmute.rs:5:9 | LL | fn assert_sizeof() -> ! { | - expected `!` because of return type 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..9f7dae4f4f5 --- /dev/null +++ b/tests/ui/type-alias-enum-variants/module-type-args-error.rs @@ -0,0 +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<T>(pub T); +} + +fn main() { + // This should work fine - normal generic struct constructor + Mod::FakeVariant::<i32>(0); + + // This should error - type arguments not allowed on modules + Mod::<i32>::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/type-alias-enum-variants/module-type-args-error.stderr index 92d972eba42..4c59d19eaa7 100644 --- a/tests/ui/mod-subitem-as-enum-variant.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::<i32>::FakeVariant(0); | --- ^^^ type argument not allowed diff --git a/tests/ui/typeck/issue-74086.rs b/tests/ui/typeck/issue-74086.rs index 1993cc7db35..c00ba81f551 100644 --- a/tests/ui/typeck/issue-74086.rs +++ b/tests/ui/typeck/issue-74086.rs @@ -1,4 +1,4 @@ fn main() { static BUG: fn(_) -> u8 = |_| 8; - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for static items + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for statics } diff --git a/tests/ui/typeck/issue-74086.stderr b/tests/ui/typeck/issue-74086.stderr index 25f454ac0c3..02c48201918 100644 --- a/tests/ui/typeck/issue-74086.stderr +++ b/tests/ui/typeck/issue-74086.stderr @@ -1,4 +1,4 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for statics --> $DIR/issue-74086.rs:2:20 | LL | static BUG: fn(_) -> u8 = |_| 8; diff --git a/tests/ui/typeck/issue-75889.stderr b/tests/ui/typeck/issue-75889.stderr index 1438f481ec7..c76f7c60b2e 100644 --- a/tests/ui/typeck/issue-75889.stderr +++ b/tests/ui/typeck/issue-75889.stderr @@ -1,10 +1,10 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants --> $DIR/issue-75889.rs:3:24 | LL | const FOO: dyn Fn() -> _ = ""; | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for statics --> $DIR/issue-75889.rs:4:25 | LL | static BOO: dyn Fn() -> _ = ""; diff --git a/tests/ui/typeck/issue-81885.rs b/tests/ui/typeck/issue-81885.rs index d73c77b8f3a..d675231d898 100644 --- a/tests/ui/typeck/issue-81885.rs +++ b/tests/ui/typeck/issue-81885.rs @@ -1,7 +1,7 @@ const TEST4: fn() -> _ = 42; -//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constant items +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants fn main() { const TEST5: fn() -> _ = 42; - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constant items + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants } diff --git a/tests/ui/typeck/issue-81885.stderr b/tests/ui/typeck/issue-81885.stderr index 25a6bb632ef..414fe548883 100644 --- a/tests/ui/typeck/issue-81885.stderr +++ b/tests/ui/typeck/issue-81885.stderr @@ -1,10 +1,10 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants --> $DIR/issue-81885.rs:1:22 | LL | const TEST4: fn() -> _ = 42; | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants --> $DIR/issue-81885.rs:5:26 | LL | const TEST5: fn() -> _ = 42; diff --git a/tests/ui/typeck/issue-83621-placeholder-static-in-extern.stderr b/tests/ui/typeck/issue-83621-placeholder-static-in-extern.stderr index a4cb53025e3..c4a5c0dea6e 100644 --- a/tests/ui/typeck/issue-83621-placeholder-static-in-extern.stderr +++ b/tests/ui/typeck/issue-83621-placeholder-static-in-extern.stderr @@ -1,4 +1,4 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables +error[E0121]: the placeholder `_` is not allowed within types on item signatures for statics --> $DIR/issue-83621-placeholder-static-in-extern.rs:4:15 | LL | static x: _; diff --git a/tests/ui/typeck/issue-88643.rs b/tests/ui/typeck/issue-88643.rs index 4435cba0207..e562f3e55ac 100644 --- a/tests/ui/typeck/issue-88643.rs +++ b/tests/ui/typeck/issue-88643.rs @@ -8,12 +8,12 @@ use std::collections::HashMap; pub trait T {} static CALLBACKS: HashMap<*const dyn T, dyn FnMut(&mut _) + 'static> = HashMap::new(); -//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for static items [E0121] +//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for statics [E0121] static CALLBACKS2: Vec<dyn Fn(& _)> = Vec::new(); -//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for static items [E0121] +//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for statics [E0121] static CALLBACKS3: Option<dyn Fn(& _)> = None; -//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for static items [E0121] +//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for statics [E0121] fn main() {} diff --git a/tests/ui/typeck/issue-88643.stderr b/tests/ui/typeck/issue-88643.stderr index d5d596b6f42..ad11c3ea8e0 100644 --- a/tests/ui/typeck/issue-88643.stderr +++ b/tests/ui/typeck/issue-88643.stderr @@ -1,16 +1,16 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for statics --> $DIR/issue-88643.rs:10:56 | LL | static CALLBACKS: HashMap<*const dyn T, dyn FnMut(&mut _) + 'static> = HashMap::new(); | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for statics --> $DIR/issue-88643.rs:13:33 | LL | static CALLBACKS2: Vec<dyn Fn(& _)> = Vec::new(); | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for statics --> $DIR/issue-88643.rs:16:36 | LL | static CALLBACKS3: Option<dyn Fn(& _)> = None; diff --git a/tests/ui/typeck/typeck_type_placeholder_item.rs b/tests/ui/typeck/typeck_type_placeholder_item.rs index dc790361919..48547c019d6 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item.rs +++ b/tests/ui/typeck/typeck_type_placeholder_item.rs @@ -41,7 +41,7 @@ impl Test9 { //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types fn test10(&self, _x : _) { } - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods } fn test11(x: &usize) -> &_ { @@ -56,10 +56,10 @@ unsafe fn test12(x: *const usize) -> *const *const _ { impl Clone for Test9 { fn clone(&self) -> _ { Test9 } - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods fn clone_from(&mut self, other: _) { *self = Test9; } - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods } struct Test10 { @@ -108,15 +108,15 @@ pub fn main() { //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types fn fn_test10(&self, _x : _) { } - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods } impl Clone for FnTest9 { fn clone(&self) -> _ { FnTest9 } - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods fn clone_from(&mut self, other: _) { *self = FnTest9; } - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods } struct FnTest10 { @@ -140,19 +140,19 @@ pub fn main() { trait T { fn method_test1(&self, x: _); - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods fn method_test2(&self, x: _) -> _; - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions - //~| ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods + //~| ERROR the placeholder `_` is not allowed within types on item signatures for methods fn method_test3(&self) -> _; - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods fn assoc_fn_test1(x: _); - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated functions fn assoc_fn_test2(x: _) -> _; - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions - //~| ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated functions + //~| ERROR the placeholder `_` is not allowed within types on item signatures for associated functions fn assoc_fn_test3() -> _; - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated functions } struct BadStruct<_>(_); diff --git a/tests/ui/typeck/typeck_type_placeholder_item.stderr b/tests/ui/typeck/typeck_type_placeholder_item.stderr index 53476f6c807..87750ee6dc1 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_item.stderr @@ -203,7 +203,7 @@ LL | unsafe fn test12(x: *const usize) -> *const *const _ { | | not allowed in type signatures | help: replace with the correct return type: `*const *const usize` -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:58:24 | LL | fn clone(&self) -> _ { Test9 } @@ -215,7 +215,7 @@ LL - fn clone(&self) -> _ { Test9 } LL + fn clone(&self) -> Test9 { Test9 } | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:61:37 | LL | fn clone_from(&mut self, other: _) { *self = Test9; } @@ -332,7 +332,7 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures LL | fn fn_test8(_f: fn() -> _) { } | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:115:28 | LL | fn clone(&self) -> _ { FnTest9 } @@ -344,7 +344,7 @@ LL - fn clone(&self) -> _ { FnTest9 } LL + fn clone(&self) -> FnTest9 { FnTest9 } | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:118:41 | LL | fn clone_from(&mut self, other: _) { *self = FnTest9; } @@ -389,49 +389,49 @@ LL | fn fn_test13(x: _) -> (i32, _) { (x, x) } | | not allowed in type signatures | help: replace with the correct return type: `(i32, i32)` -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:142:31 | LL | fn method_test1(&self, x: _); | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:144:31 | LL | fn method_test2(&self, x: _) -> _; | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:144:37 | LL | fn method_test2(&self, x: _) -> _; | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:147:31 | LL | fn method_test3(&self) -> _; | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions --> $DIR/typeck_type_placeholder_item.rs:149:26 | LL | fn assoc_fn_test1(x: _); | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions --> $DIR/typeck_type_placeholder_item.rs:151:26 | LL | fn assoc_fn_test2(x: _) -> _; | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions --> $DIR/typeck_type_placeholder_item.rs:151:32 | LL | fn assoc_fn_test2(x: _) -> _; | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions --> $DIR/typeck_type_placeholder_item.rs:154:28 | LL | fn assoc_fn_test3() -> _; @@ -575,7 +575,7 @@ LL | fn test9(&self) -> _ { () } | not allowed in type signatures | help: replace with the correct return type: `()` -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:43:27 | LL | fn test10(&self, _x : _) { } @@ -590,7 +590,7 @@ LL | fn fn_test9(&self) -> _ { () } | not allowed in type signatures | help: replace with the correct return type: `()` -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:110:34 | LL | fn fn_test10(&self, _x : _) { } diff --git a/tests/ui/typeck/typeck_type_placeholder_item_help.rs b/tests/ui/typeck/typeck_type_placeholder_item_help.rs index ab433aaaf16..758b94f9854 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item_help.rs +++ b/tests/ui/typeck/typeck_type_placeholder_item_help.rs @@ -11,7 +11,7 @@ const TEST3: _ = Some(42); //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants const TEST4: fn() -> _ = 42; -//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constant items +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants trait Test5 { const TEST5: _ = 42; diff --git a/tests/ui/typeck/typeck_type_placeholder_item_help.stderr b/tests/ui/typeck/typeck_type_placeholder_item_help.stderr index 5066e2eaa52..2fce00e7a8e 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item_help.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_item_help.stderr @@ -31,7 +31,7 @@ LL - const TEST3: _ = Some(42); LL + const TEST3: Option<i32> = Some(42); | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants --> $DIR/typeck_type_placeholder_item_help.rs:13:22 | LL | const TEST4: fn() -> _ = 42; |
