diff --git a/compiler/rustc_ast/src/util/literal.rs b/compiler/rustc_ast/src/util/literal.rs index b5d8fc821ae0e..2b264a6843837 100644 --- a/compiler/rustc_ast/src/util/literal.rs +++ b/compiler/rustc_ast/src/util/literal.rs @@ -1,6 +1,5 @@ //! Code related to parsing literals. -use std::fmt::Write as _; use std::{ascii, fmt, str}; use rustc_literal_escaper::{ @@ -38,19 +37,8 @@ pub fn escape_string_symbol(symbol: Symbol) -> Symbol { let mut escaped = String::with_capacity(s.len() + 1); escaped.push_str(prefix); - // Don't use escape_default() here, because using it is slower than escaping manually. - for c in suffix.chars() { - match c { - '\t' => escaped.push_str("\\t"), - '\r' => escaped.push_str("\\r"), - '\n' => escaped.push_str("\\n"), - '\\' => escaped.push_str("\\\\"), - '\'' => escaped.push_str("\\'"), - '\"' => escaped.push_str("\\\""), - '\x20'..='\x7e' => escaped.push(c), - c => write!(escaped, "\\u{{{:x}}}", c as u32).unwrap(), - } - } + escaped.extend(suffix.escape_default()); + Symbol::intern(&escaped) } diff --git a/compiler/rustc_attr_parsing/src/diagnostics.rs b/compiler/rustc_attr_parsing/src/diagnostics.rs index 848ab845dc7f6..b5bfbc9e3dc3b 100644 --- a/compiler/rustc_attr_parsing/src/diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/diagnostics.rs @@ -1389,6 +1389,8 @@ pub(crate) struct InvalidTarget { pub attr_span: Span, pub name: AttrPath, pub target: &'static str, + #[context] + pub target_span: Span, pub applied: DiagArgValue, pub only: &'static str, pub attribute_args: String, diff --git a/compiler/rustc_attr_parsing/src/target_checking.rs b/compiler/rustc_attr_parsing/src/target_checking.rs index 5fc0b248110f7..7eb3e8e1f319a 100644 --- a/compiler/rustc_attr_parsing/src/target_checking.rs +++ b/compiler/rustc_attr_parsing/src/target_checking.rs @@ -131,23 +131,31 @@ impl<'sess> AttributeParser<'sess> { let (applied, only) = allowed_targets_applied(allowed_targets, cx.target, cx.features); let is_diagnostic_attr = cx.attr_path.segments[0] == sym::diagnostic; + let span = if attribute_args.is_empty() { + // Example: for the attribute `#[inline]`, name+attribute_args gives "inline", + // and the path span covers `inline` which is just what we want. + cx.attr_path.span + } else { + // Example 1: for the attribute `#[repr(C)]`, name+attribute_args gives + // "repr(C)", and the inner span covers `repr(C)` which is just what we want. + // + // Example 2: for the attribute `#[repr(C, packed)]`, name+attribute_args gives + // "repr(C)", and the inner span covers `repr(C, packed)` which doesn't match + // exactly but is as close as we can get. + cx.inner_span + }; + let target_span = if span.eq_ctxt(cx.target_span) && cx.target != Target::Crate { + cx.target_span.shrink_to_lo() + } else { + span + }; + let diag = InvalidTarget { - span: if attribute_args.is_empty() { - // Example: for the attribute `#[inline]`, name+attribute_args gives "inline", - // and the path span covers `inline` which is just what we want. - cx.attr_path.span - } else { - // Example 1: for the attribute `#[repr(C)]`, name+attribute_args gives - // "repr(C)", and the inner span covers `repr(C)` which is just what we want. - // - // Example 2: for the attribute `#[repr(C, packed)]`, name+attribute_args gives - // "repr(C)", and the inner span covers `repr(C, packed)` which doesn't match - // exactly but is as close as we can get. - cx.inner_span - }, + span, attr_span: cx.attr_span, name: cx.attr_path.clone(), target: cx.target.plural_name(), + target_span, only: if only { "only " } else { "" }, applied: DiagArgValue::StrListSepByAnd(applied.into_iter().map(Cow::Owned).collect()), attribute_args: attribute_args.to_string(), diff --git a/compiler/rustc_codegen_gcc/.github/workflows/ci.yml b/compiler/rustc_codegen_gcc/.github/workflows/ci.yml index 0687bc1150907..66362e27ce4da 100644 --- a/compiler/rustc_codegen_gcc/.github/workflows/ci.yml +++ b/compiler/rustc_codegen_gcc/.github/workflows/ci.yml @@ -116,8 +116,6 @@ jobs: - name: Set env run: | echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV - # /tmp is a small tmpfs, and rustdoc keeps every compiled doctest there until the run ends. - echo "TMPDIR=$RUNNER_TEMP" >> $GITHUB_ENV #- name: Cache rust repository ## We only clone the rust repository for rustc tests diff --git a/compiler/rustc_codegen_gcc/.github/workflows/rustup.yml b/compiler/rustc_codegen_gcc/.github/workflows/rustup.yml index 57d7a39de049a..0309ccbad5481 100644 --- a/compiler/rustc_codegen_gcc/.github/workflows/rustup.yml +++ b/compiler/rustc_codegen_gcc/.github/workflows/rustup.yml @@ -77,8 +77,6 @@ jobs: - name: Set env run: | echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV - # /tmp is a small tmpfs, and rustdoc keeps every compiled doctest there until the run ends. - echo "TMPDIR=$RUNNER_TEMP" >> $GITHUB_ENV - name: Prepare if: ${{ matrix.run_cargo_tests }} diff --git a/compiler/rustc_codegen_gcc/Cargo.lock b/compiler/rustc_codegen_gcc/Cargo.lock index d94ce6575ac0e..aec0ef270bf73 100644 --- a/compiler/rustc_codegen_gcc/Cargo.lock +++ b/compiler/rustc_codegen_gcc/Cargo.lock @@ -56,18 +56,18 @@ dependencies = [ [[package]] name = "gccjit" -version = "7.2.0" +version = "7.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27cd340f3c265988de3379689cbbd103c25b1f8a3d0cc73f91a49083e899d3e1" +checksum = "ea1820165dfb376a3bbfe8b69628d9e5a851c423e0480a666f71f560e2d0a924" dependencies = [ "gccjit_sys", ] [[package]] name = "gccjit_sys" -version = "4.2.0" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da2d9d74572f004908f17ec1bd0af071e5db63a12c3335c9651a6125593951c6" +checksum = "a6091291fc118448b91df5b662d20564020198fee46d8445a6aa0c25b6b435be" dependencies = [ "libc", ] diff --git a/compiler/rustc_codegen_gcc/Cargo.toml b/compiler/rustc_codegen_gcc/Cargo.toml index 95c4c991297fa..3e279961bfbe0 100644 --- a/compiler/rustc_codegen_gcc/Cargo.toml +++ b/compiler/rustc_codegen_gcc/Cargo.toml @@ -20,7 +20,7 @@ default = ["master"] [dependencies] object = { version = "0.39.0", default-features = false, features = ["std", "read"] } tempfile = "3.20" -gccjit = { version = "7.2.0", features = ["dlopen"] } +gccjit = { version = "7.3.0", features = ["dlopen"] } #gccjit = { git = "https://github.com/rust-lang/gccjit.rs", branch = "error-dlopen", features = ["dlopen"] } # Local copy. diff --git a/compiler/rustc_codegen_gcc/build_system/src/build.rs b/compiler/rustc_codegen_gcc/build_system/src/build.rs index ac076836579ac..cc87c660520d8 100644 --- a/compiler/rustc_codegen_gcc/build_system/src/build.rs +++ b/compiler/rustc_codegen_gcc/build_system/src/build.rs @@ -6,7 +6,8 @@ use std::path::{Path, PathBuf}; use crate::config::{Channel, ConfigInfo}; use crate::utils::{ - create_dir, get_sysroot_dir, run_command, run_command_with_output_and_env, walk_dir, + create_dir, get_sysroot_dir, run_command, run_command_with_output_and_env, rustc_version_info, + walk_dir, }; #[derive(Default)] @@ -137,17 +138,16 @@ pub fn build_sysroot(env: &HashMap, config: &ConfigInfo) -> Resu // Builds libs let mut rustflags = env.get("RUSTFLAGS").cloned().unwrap_or_default(); - // Record the sysroot sources under the path the `rust-src` component uses, which is where - // rustc looks for them to turn a sysroot span into `/rustc/$hash`. Without this, ui tests - // print the build path where they expect `$SRC_DIR`. - let sysroot_source_dir = lib_path.join("rustlib/src/rust/library"); + // Remap both source spans and embedded panic locations to the standard virtual path. + let sysroot_source_dir = start_dir.join("sysroot_src"); + let rustc_commit = rustc_version_info(env.get("RUSTC").map(String::as_str))? + .commit_hash + .ok_or_else(|| "Couldn't retrieve rustc commit hash".to_string())?; + // Cargo passes workspace-relative filenames, including those used by panic locations. + // Also: the `==` is intentional! The first `=` is "FROM" and the second `=` is for "TO". + rustflags.push_str(&format!(" --remap-path-prefix==/rustc/{rustc_commit}/library")); rustflags.push_str(&format!( - " --remap-path-prefix={library_dir}={sysroot_source_dir}", - library_dir = std::path::absolute(&library_dir) - .map_err(|error| format!( - "Failed to get the absolute path of the sysroot sources: {error:?}" - ))? - .display(), + " --remap-path-prefix={sysroot_source_dir}=/rustc/{rustc_commit}", sysroot_source_dir = std::path::absolute(&sysroot_source_dir) .map_err(|error| format!( "Failed to get the absolute path of the sysroot sources: {error:?}" diff --git a/compiler/rustc_codegen_gcc/doc/subtree.md b/compiler/rustc_codegen_gcc/doc/subtree.md index fcac399e46542..dbdc09499e30d 100644 --- a/compiler/rustc_codegen_gcc/doc/subtree.md +++ b/compiler/rustc_codegen_gcc/doc/subtree.md @@ -1,54 +1,13 @@ -# git subtree sync +# Subtree sync procedure -`rustc_codegen_gcc` is a subtree of the rust compiler. As such, it needs to be -synced from time to time to ensure changes that happened on their side are also -included on our side. +`rustc_codegen_gcc` is using [Josh] to perform subtree synces with the `rust-lang/rust` repository. -### How to install a forked git-subtree +[Josh]: https://josh-project.dev/docs/intro.html -Using git-subtree with `rustc` requires a patched git to make it work. -The PR that is needed is [here](https://github.com/gitgitgadget/git/pull/493). -Use the following instructions to install it: +The procedure for performing subtree synchronizations is documented [here][rdg-josh]. -```bash -git clone git@github.com:tqc/git.git -cd git -git checkout tqc/subtree -make -make install -cd contrib/subtree -make -cp git-subtree ~/bin -``` +[rdg-josh]: https://rustc-dev-guide.rust-lang.org/external-repos.html#synchronizing-a-josh-subtree -### Syncing with rust compiler +## Pushing changes to `rust-lang/rust` -Do a sync with this command: - -```bash -PATH="$HOME/bin:$PATH" ~/bin/git-subtree push -P compiler/rustc_codegen_gcc/ ../rustc_codegen_gcc/ sync_branch_name -cd ../rustc_codegen_gcc -git checkout master -git pull -git checkout sync_branch_name -git merge master -``` - -To send the changes to the rust repo: - -```bash -cd ../rust -git pull origin master -git checkout -b subtree-update_cg_gcc_YYYY-MM-DD -PATH="$HOME/bin:$PATH" ~/bin/git-subtree pull --prefix=compiler/rustc_codegen_gcc/ https://github.com/rust-lang/rustc_codegen_gcc.git master -# Don't forget to update the `gcc` submodule to the same version as the -# one in `rustc_codegen_gcc/libgccjit.version`. -git push - -# Immediately merge the merge commit into cg_gcc to prevent merge conflicts when syncing from rust-lang/rust later. -PATH="$HOME/bin:$PATH" ~/bin/git-subtree push -P compiler/rustc_codegen_gcc/ ../rustc_codegen_gcc/ sync_branch_name -``` - -FIXME: write a script that does the above. - -https://rust-lang.zulipchat.com/#narrow/stream/301329-t-devtools/topic/subtree.20madness/near/258877725 +If the used GCC commit (recorded in `libgccjit.version`) changed in `rustc_codegen_gcc`, then you will have to update the `gcc` submodule in the `rust-lang/rust` repository in the push sync PR. The CI in `rust-lang/rust` should ensure that these two commit references match. You can simply update the `gcc` submodule commit and push it to your push sync PR once it has been created. diff --git a/compiler/rustc_codegen_gcc/libgccjit.version b/compiler/rustc_codegen_gcc/libgccjit.version index 0bcc711e4696b..0c6f40148d1e5 100644 --- a/compiler/rustc_codegen_gcc/libgccjit.version +++ b/compiler/rustc_codegen_gcc/libgccjit.version @@ -1 +1 @@ -37ea7cd851f04ee6a313c5067c9fde9328f876aa +e1c6e07b095d091177376a163da44039475e05e3 diff --git a/compiler/rustc_codegen_gcc/rust-toolchain.toml b/compiler/rustc_codegen_gcc/rust-toolchain.toml index 7d0a982195aa0..5750754596ba2 100644 --- a/compiler/rustc_codegen_gcc/rust-toolchain.toml +++ b/compiler/rustc_codegen_gcc/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2026-10-19" +channel = "nightly-2026-10-24" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] diff --git a/compiler/rustc_codegen_gcc/src/attributes.rs b/compiler/rustc_codegen_gcc/src/attributes.rs index b6b0352d2516c..925c600aee936 100644 --- a/compiler/rustc_codegen_gcc/src/attributes.rs +++ b/compiler/rustc_codegen_gcc/src/attributes.rs @@ -20,7 +20,7 @@ use crate::base; use crate::context::CodegenCx; #[cfg(feature = "master")] use crate::gcc_util::to_gcc_aarch64_extension; -use crate::gcc_util::to_gcc_features; +use crate::gcc_util::{to_gcc_features, to_gcc_target_attribute_feature}; /// Checks if the function `instance` is recursively inline. /// Returns `false` if a functions is guaranteed to be non-recursive, and `true` if it *might* be recursive. @@ -192,20 +192,7 @@ pub fn from_fn_attrs<'gcc, 'tcx>( } let target_features = function_features .iter() - .filter_map(|feature| { - // FIXME(antoyo): support soft-float. - if feature.contains("soft-float") { - return None; - } - - if feature.starts_with('-') { - Some(format!("no{}", feature)) - } else if let Some(stripped) = feature.strip_prefix('+') { - Some(stripped.to_string()) - } else { - Some(feature.to_string()) - } - }) + .filter_map(|feature| to_gcc_target_attribute_feature(feature)) .collect::>() .join(","); if !target_features.is_empty() { diff --git a/compiler/rustc_codegen_gcc/src/common.rs b/compiler/rustc_codegen_gcc/src/common.rs index 21d92c6cc2936..895bc629d63ce 100644 --- a/compiler/rustc_codegen_gcc/src/common.rs +++ b/compiler/rustc_codegen_gcc/src/common.rs @@ -28,12 +28,14 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { self.const_uint(self.type_u16(), i as u64) } - fn global_string(&self, string: &str) -> LValue<'gcc> { - // FIXME(antoyo): handle non-null-terminated strings. - let string = self.context.new_string_literal(string); + fn global_const_string(&self, string: &str) -> LValue<'gcc> { + // The bytes of a Rust string are not NUL-terminated and can contain NULs. + let string = bytes_in_context(self, string.as_bytes()); let sym = self.generate_local_symbol_name("str"); let global = self.declare_private_global(&sym, self.val_ty(string)); global.global_set_initializer_rvalue(string); + #[cfg(feature = "master")] + global.global_set_readonly(); global // FIXME(antoyo): set linkage. } @@ -126,18 +128,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { } } -/// The element type and element count of the array used to represent a run of `len` constant bytes. -/// -/// Larger integers are used where possible: this reduces the number of rvalues, which is a -/// significant memory saving on constant-heavy crates. -fn byte_run_shape<'gcc>(cx: &CodegenCx<'gcc, '_>, len: usize) -> (Type<'gcc>, u64) { - match len % 8 { - 0 => (cx.context.new_type::(), len as u64 / 8), - 4 => (cx.context.new_type::(), len as u64 / 4), - _ => (cx.context.new_type::(), len as u64), - } -} - /// The type [`bytes_in_context`] gives a run of `len` constant bytes. /// /// Exposed separately so that the type of a constant allocation can be computed before any of its @@ -147,65 +137,30 @@ fn byte_run_shape<'gcc>(cx: &CodegenCx<'gcc, '_>, len: usize) -> (Type<'gcc>, u6 /// Two equal-but-distinct array types would key [`CodegenCx::type_struct`] differently and so /// produce two distinct anonymous structs, and libgccjit compares struct types by identity. pub fn bytes_type_in_context<'gcc>(cx: &CodegenCx<'gcc, '_>, len: usize) -> Type<'gcc> { - let (element_type, count) = byte_run_shape(cx, len); - if let Some(&typ) = cx.byte_array_types.borrow().get(&(element_type, count)) { + if let Some(&typ) = cx.byte_array_types.borrow().get(&len) { return typ; } - let typ = new_array_type(cx.context, None, element_type, count); - cx.byte_array_types.borrow_mut().insert((element_type, count), typ); + let typ = new_array_type(cx.context, None, cx.type_u8(), len as u64); + cx.byte_array_types.borrow_mut().insert(len, typ); typ } -// FIXME(FractalFir): Consider using `global_set_initializer` instead. Before this is done, we need to confirm that -// `global_set_initializer` is more memory efficient than the current solution. -// `global_set_initializer` calls `global_set_initializer_rvalue` under the hood - does it generate an array of rvalues, -// or is it using a more efficient representation? pub fn bytes_in_context<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, bytes: &[u8]) -> RValue<'gcc> { let typ = bytes_type_in_context(cx, bytes.len()); - let (element_type, _) = byte_run_shape(cx, bytes.len()); - let context = &cx.context; - // Since we are representing arbitrary byte runs as integers, we need to follow the target - // endianness. - let endian = cx.sess().target.options.endian; - let elements: Vec<_> = match bytes.len() % 8 { - 0 => { - let (arrays, remainder) = bytes.as_chunks::<8>(); - debug_assert!(remainder.is_empty()); - arrays - .iter() - .map(|&arr| { - context.new_rvalue_from_long( - element_type, - match endian { - rustc_abi::Endian::Little => u64::from_le_bytes(arr) as i64, - rustc_abi::Endian::Big => u64::from_be_bytes(arr) as i64, - }, - ) - }) - .collect() - } - 4 => { - let (arrays, remainder) = bytes.as_chunks::<4>(); - debug_assert!(remainder.is_empty()); - arrays - .iter() - .map(|&arr| { - context.new_rvalue_from_int( - element_type, - match endian { - rustc_abi::Endian::Little => u32::from_le_bytes(arr) as i32, - rustc_abi::Endian::Big => u32::from_be_bytes(arr) as i32, - }, - ) - }) - .collect() - } - _ => bytes + // Raw bytes take far less RAM in libgccjit than one rvalue per array element. + #[cfg(feature = "master")] + { + cx.context.new_array_from_bytes(None, typ, bytes) + } + #[cfg(not(feature = "master"))] + { + let byte_type = cx.type_u8(); + let elements: Vec<_> = bytes .iter() - .map(|&byte| context.new_rvalue_from_int(element_type, byte as i32)) - .collect(), - }; - context.new_array_constructor(None, typ, &elements) + .map(|&byte| cx.context.new_rvalue_from_int(byte_type, byte as i32)) + .collect(); + cx.context.new_array_constructor(None, typ, &elements) + } } pub fn type_is_pointer(typ: Type<'_>) -> bool { @@ -292,7 +247,7 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> { fn const_str(&self, s: &str) -> (RValue<'gcc>, RValue<'gcc>) { let mut const_str_cache = self.const_str_cache.borrow_mut(); let str_global = const_str_cache.get(s).copied().unwrap_or_else(|| { - let g = self.global_string(s); + let g = self.global_const_string(s); const_str_cache.insert(s.to_owned(), g); g }); diff --git a/compiler/rustc_codegen_gcc/src/consts.rs b/compiler/rustc_codegen_gcc/src/consts.rs index 902f8ba52faaa..6cf765a9b80b7 100644 --- a/compiler/rustc_codegen_gcc/src/consts.rs +++ b/compiler/rustc_codegen_gcc/src/consts.rs @@ -64,14 +64,18 @@ impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> { let cv = const_alloc_to_gcc(self, alloc); let align = alloc.inner().align; - if let Some(variable) = self.const_globals.borrow().get(&cv) { - if let Some(global_variable) = self.global_lvalues.borrow().get(variable) { - let alignment = align.bits() as i32; - if alignment > global_variable.get_alignment() { - global_variable.set_alignment(alignment); - } + if let Some(&mut (variable, ref mut global_align)) = + self.const_globals.borrow_mut().get_mut(&cv) + { + // `set_alignment` replaces the alignment, which is on the global's type and thus not + // reported by `get_alignment`: only raise it, or a smaller use would lower it. + if align > *global_align + && let Some(global_variable) = self.global_lvalues.borrow().get(&variable) + { + global_variable.set_alignment(align.bytes() as i32); + *global_align = align; } - return *variable; + return variable; } let global_value = self.static_addr_of_mut(cv, align, kind); #[cfg(feature = "master")] @@ -80,7 +84,7 @@ impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> { .get(&global_value) .expect("`static_addr_of_mut` did not add the global to `self.global_lvalues`") .global_set_readonly(); - self.const_globals.borrow_mut().insert(cv, global_value); + self.const_globals.borrow_mut().insert(cv, (global_value, align)); global_value } @@ -359,18 +363,30 @@ fn alloc_fields(cx: &CodegenCx<'_, '_>, alloc: &interpret::Allocation) -> Vec next_offset { - fields.push(AllocField::Bytes { range: next_offset..offset }); + push_byte_runs(&mut fields, next_offset..offset); } fields.push(AllocField::Pointer { offset, prov }); next_offset = offset + pointer_size; } if alloc.len() >= next_offset { - fields.push(AllocField::Bytes { range: next_offset..alloc.len() }); + push_byte_runs(&mut fields, next_offset..alloc.len()); } fields } +/// `gcc_jit_context_new_array_from_bytes` rejects runs of `i32::MAX` bytes or more. +const MAX_BYTE_RUN_LEN: usize = i32::MAX as usize - 1; + +fn push_byte_runs(fields: &mut Vec, range: Range) { + let mut start = range.start; + while range.end - start > MAX_BYTE_RUN_LEN { + fields.push(AllocField::Bytes { range: start..start + MAX_BYTE_RUN_LEN }); + start += MAX_BYTE_RUN_LEN; + } + fields.push(AllocField::Bytes { range: start..range.end }); +} + /// The type [`const_alloc_to_gcc`] gives `alloc`, computed without building any rvalue. /// /// This lets `predefine_static` declare a static's global with the type its initializer will have, diff --git a/compiler/rustc_codegen_gcc/src/context.rs b/compiler/rustc_codegen_gcc/src/context.rs index b57e0fb2cd23a..39a98ede628f2 100644 --- a/compiler/rustc_codegen_gcc/src/context.rs +++ b/compiler/rustc_codegen_gcc/src/context.rs @@ -97,11 +97,11 @@ pub struct CodegenCx<'gcc, 'tcx> { /// Cache of the anonymous struct types. pub struct_types: RefCell, Type<'gcc>>>, - /// Cache of the array types used for runs of constant bytes, keyed by element type and count. + /// Cache of the array types used for runs of constant bytes, keyed by length. /// /// libgccjit mints a fresh type on every `new_array_type`, and struct types are keyed on their /// field types, so without this two equal byte runs would yield two distinct anonymous structs. - pub byte_array_types: RefCell, u64), Type<'gcc>>>, + pub byte_array_types: RefCell>>, /// Cache of the return types of the pairs returned in two registers, keyed by the types of the /// two scalars. @@ -126,8 +126,8 @@ pub struct CodegenCx<'gcc, 'tcx> { /// Local holding the return value of the defined functions returning it in memory. pub functions_with_indirect_return: RefCell, LValue<'gcc>>>, - /// Cache of emitted const globals (value -> global) - pub const_globals: RefCell, RValue<'gcc>>>, + /// Cache of emitted const globals (value -> global and its alignment) + pub const_globals: RefCell, (RValue<'gcc>, Align)>>, /// Map from the address of a global variable (rvalue) to the global variable itself (lvalue). /// FIXME(antoyo): remove when the rustc API is fixed. diff --git a/compiler/rustc_codegen_gcc/src/gcc_util.rs b/compiler/rustc_codegen_gcc/src/gcc_util.rs index 5ecc971830f20..b0442cdfb11cc 100644 --- a/compiler/rustc_codegen_gcc/src/gcc_util.rs +++ b/compiler/rustc_codegen_gcc/src/gcc_util.rs @@ -20,7 +20,10 @@ fn gcc_features_by_flags(sess: &EarlySession, features: &mut Vec) { /// The list of GCC features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`, /// `--target` and similar). -pub(crate) fn global_gcc_features(sess: &EarlySession) -> Vec { +/// +/// If `for_cfg` is `true`, only the features implied by `--target` are included, to configure the +/// target info that populates [`rustc_codegen_ssa::TargetConfig`]. +pub(crate) fn global_gcc_features(sess: &EarlySession, for_cfg: bool) -> Vec { // Features that come earlier are overridden by conflicting features later in the string. // Typically we'll want more explicit settings to override the implicit ones, so: // @@ -57,6 +60,12 @@ pub(crate) fn global_gcc_features(sess: &EarlySession) -> Vec { // Features implied by an implicit or explicit `--target`. target_features::target_spec_to_backend_features(sess, &mut extend_backend_features); + // `internal_target_features` applies -Ctarget-features itself, and GCC has no options for the + // features implied by other flags (e.g. retpoline), which would break the target info. + if for_cfg { + return features; + } + // -Ctarget-features target_features::flag_to_backend_features(sess, extend_backend_features); @@ -267,25 +276,7 @@ pub fn new_context<'gcc>(sess: &Session) -> Context<'gcc> { context.add_command_line_option("-mavx"); } - if sess.target.arch == Arch::AArch64 { - // Unlike LLVM, GCC enables outline atomics by default, but their libgcc helpers are - // missing on targets without this feature, like the Linux kernel. Only AArch64 has it. - let outline_atomics = sess - .global_backend_features - .iter() - .rev() - .find_map(|feature| match feature.as_str() { - "outline-atomics" | "+outline-atomics" => Some(true), - "-outline-atomics" => Some(false), - _ => None, - }) - .unwrap_or(false); - context.add_command_line_option(if outline_atomics { - "-moutline-atomics" - } else { - "-mno-outline-atomics" - }); - } + add_feature_options(&context, &sess.target.arch, &sess.global_backend_features); for arg in &sess.opts.cg.llvm_args { context.add_command_line_option(arg); @@ -387,6 +378,80 @@ pub fn new_context<'gcc>(sess: &Session) -> Context<'gcc> { context } +/// Add the options for the global `features` that are not applied with function attributes. +fn add_feature_options(context: &Context<'_>, arch: &Arch, features: &[String]) { + if *arch == Arch::AArch64 { + // Unlike LLVM, GCC enables outline atomics by default, but their libgcc helpers are + // missing on targets without this feature, like the Linux kernel. Only AArch64 has it. + let outline_atomics = + feature_setting(features, "outline-atomics") == FeatureSetting::Enabled; + context.add_command_line_option(if outline_atomics { + "-moutline-atomics" + } else { + "-mno-outline-atomics" + }); + + // Rust's `neon` covers both FP and SIMD, so without it (e.g. on softfloat targets like the + // Linux kernel) GCC must not touch those registers at all. + if feature_setting(features, "neon") == FeatureSetting::Disabled { + context.add_command_line_option("-mgeneral-regs-only"); + } + } +} + +/// Configure the target info `context` with the global `features`, like codegen does. +#[cfg(feature = "master")] +pub fn add_target_info_feature_options(context: &Context<'_>, arch: &Arch, features: &[String]) { + add_feature_options(context, arch, features); + // Codegen applies these as function attributes, which the target info does not see. Of the + // arches using these attributes, libgccjit only has target info for x86, not PowerPC. + if matches!(arch, Arch::X86 | Arch::X86_64) { + for feature in + features.iter().filter_map(|feature| to_gcc_target_attribute_feature(feature)) + { + context.add_command_line_option(format!("-m{}", feature)); + } + } +} + +/// The spelling of a global `feature` in a GCC `target` attribute, e.g. `no-sse` for `-sse`. +pub fn to_gcc_target_attribute_feature(feature: &str) -> Option { + // FIXME(antoyo): support soft-float. + if feature.contains("soft-float") { + return None; + } + + if feature.starts_with('-') { + Some(format!("no{}", feature)) + } else if let Some(stripped) = feature.strip_prefix('+') { + Some(stripped.to_string()) + } else { + Some(feature.to_string()) + } +} + +#[derive(Clone, Copy, PartialEq, Eq)] +enum FeatureSetting { + Enabled, + Disabled, + /// No global feature mentions it. + Unspecified, +} + +/// The last setting of `feature` in `features`. +fn feature_setting(features: &[String], feature: &str) -> FeatureSetting { + features + .iter() + .rev() + .find_map(|global_feature| match global_feature.strip_prefix('-') { + Some(disabled) if disabled == feature => Some(FeatureSetting::Disabled), + Some(_) => None, + None => (global_feature.strip_prefix('+').unwrap_or(global_feature) == feature) + .then_some(FeatureSetting::Enabled), + }) + .unwrap_or(FeatureSetting::Unspecified) +} + pub fn add_pic_option<'gcc>(context: &Context<'gcc>, relocation_model: RelocModel) { match relocation_model { rustc_target::spec::RelocModel::Static => { diff --git a/compiler/rustc_codegen_gcc/src/lib.rs b/compiler/rustc_codegen_gcc/src/lib.rs index 414bff06866a8..17034d0c195e7 100644 --- a/compiler/rustc_codegen_gcc/src/lib.rs +++ b/compiler/rustc_codegen_gcc/src/lib.rs @@ -240,7 +240,7 @@ impl CodegenBackend for GccCodegenBackend { panic!("Could not load libgccjit.so. Attempted paths: {:#?}", paths); } } - let global_backend_features = gcc_util::global_gcc_features(sess); + let global_backend_features = gcc_util::global_gcc_features(sess, false); #[cfg(feature = "master")] { @@ -253,6 +253,11 @@ impl CodegenBackend for GccCodegenBackend { if target_cpu != "generic" { context.add_command_line_option(format!("-march={}", target_cpu)); } + gcc_util::add_target_info_feature_options( + &context, + &sess.target.arch, + &gcc_util::global_gcc_features(sess, true), + ); // libgccjit always passes -fPIC, which some targets reject (e.g. MIPS without -mabicalls). gcc_util::add_pic_option(&context, sess.relocation_model()); diff --git a/compiler/rustc_codegen_gcc/tests/asm/const_global_alignment.rs b/compiler/rustc_codegen_gcc/tests/asm/const_global_alignment.rs new file mode 100644 index 0000000000000..e4dfd4bb26dd0 --- /dev/null +++ b/compiler/rustc_codegen_gcc/tests/asm/const_global_alignment.rs @@ -0,0 +1,44 @@ +//@ assembly-output: emit-asm +//@ only-x86_64-unknown-linux-gnu + +#![crate_type = "lib"] + +// Constants with identical bytes share one global, which needs the largest alignment among +// their uses: lowering it to a later, smaller one or reading it as bits fails these checks. + +// CHECK: "A_WIDE": +// CHECK-NEXT: .quad "[[WIDE_THEN_BYTES:global\.[0-9]+]]" +#[no_mangle] +pub static A_WIDE: &[u128; 4] = &[0x09090909_09090909_09090909_09090909; 4]; + +// CHECK: "B_BYTES": +// CHECK-NEXT: .quad "[[WIDE_THEN_BYTES]]" +#[no_mangle] +pub static B_BYTES: &[u8; 64] = &[9; 64]; + +// CHECK: "C_BYTES": +// CHECK-NEXT: .quad "[[BYTES_THEN_WIDE:global\.[0-9]+]]" +#[no_mangle] +pub static C_BYTES: &[u8; 64] = &[8; 64]; + +// CHECK: "D_WIDE": +// CHECK-NEXT: .quad "[[BYTES_THEN_WIDE]]" +#[no_mangle] +pub static D_WIDE: &[u128; 4] = &[0x08080808_08080808_08080808_08080808; 4]; + +// CHECK: "E_BYTES": +// CHECK-NEXT: .quad "[[BYTES_THEN_HALVES:global\.[0-9]+]]" +#[no_mangle] +pub static E_BYTES: &[u8; 4] = &[3; 4]; + +// CHECK: "F_HALVES": +// CHECK-NEXT: .quad "[[BYTES_THEN_HALVES]]" +#[no_mangle] +pub static F_HALVES: &[u16; 2] = &[0x0303; 2]; + +// CHECK: .section .rodata.[[WIDE_THEN_BYTES]],"a" +// CHECK-NEXT: .align {{16|32|64}}{{$}} +// CHECK: .section .rodata.[[BYTES_THEN_WIDE]],"a" +// CHECK-NEXT: .align 16{{$}} +// CHECK: .section .rodata.[[BYTES_THEN_HALVES]],"a" +// CHECK-NEXT: .align 2{{$}} diff --git a/compiler/rustc_codegen_gcc/tests/asm/const_str.rs b/compiler/rustc_codegen_gcc/tests/asm/const_str.rs new file mode 100644 index 0000000000000..65969a713c996 --- /dev/null +++ b/compiler/rustc_codegen_gcc/tests/asm/const_str.rs @@ -0,0 +1,24 @@ +//@ assembly-output: emit-asm +//@ only-x86_64-unknown-linux-gnu +//@ compile-flags: -Copt-level=2 + +#![crate_type = "lib"] +#![allow(invalid_value)] + +// The panic messages of the `assert_zero_valid` and `assert_inhabited` intrinsics are built with +// `const_str`, which passes the address of its global as the string data. The global must +// therefore hold the bytes themselves (not a pointer to a string literal), without a trailing +// NUL so that its size matches the length passed along, and it must be read-only. + +// CHECK-LABEL: "zeroed_ref": +// CHECK: mov esi, 57 +// CHECK: lea rdi, "[[REF_STR:str\.[0-9]+]]"[rip] +#[unsafe(no_mangle)] +pub fn zeroed_ref() -> &'static u8 { + unsafe { std::mem::zeroed() } +} + +// CHECK: .section .rodata.[[REF_STR]],"a" +// CHECK: .size "[[REF_STR]]", 57 +// CHECK-NEXT: "[[REF_STR]]": +// CHECK-NEXT: .ascii "attempted to zero-initialize type `&u8`, which is invalid" diff --git a/compiler/rustc_codegen_gcc/tests/compile/large_byte_constant.rs b/compiler/rustc_codegen_gcc/tests/compile/large_byte_constant.rs index b26387ecacdb6..2ca3f4c2fec36 100644 --- a/compiler/rustc_codegen_gcc/tests/compile/large_byte_constant.rs +++ b/compiler/rustc_codegen_gcc/tests/compile/large_byte_constant.rs @@ -1,8 +1,8 @@ -//@ memory-limit: 2G +//@ memory-limit: 1G // Compiler: -// An 8 MiB constant must compile within 2 GiB of address space. A backend that builds one rvalue -// per byte of a constant needs more than 6 GiB for it and runs out of memory. +// An 8 MiB constant must compile within 1 GiB of address space. A backend that builds one rvalue +// per 8 bytes of a constant needs about 1.4 GiB for it and runs out of memory. #![crate_type = "lib"] diff --git a/compiler/rustc_codegen_gcc/tests/failing-ui-tests.txt b/compiler/rustc_codegen_gcc/tests/failing-ui-tests.txt index a18eaf272fd07..e35d9916247f1 100644 --- a/compiler/rustc_codegen_gcc/tests/failing-ui-tests.txt +++ b/compiler/rustc_codegen_gcc/tests/failing-ui-tests.txt @@ -1,6 +1,5 @@ tests/ui/asm/may_unwind.rs tests/ui/asm/x86_64/may_unwind.rs -tests/ui/intrinsics/panic-uninitialized-zeroed.rs tests/ui/simd/issue-17170.rs tests/ui/simd/issue-39720.rs tests/ui/process/println-with-broken-pipe.rs @@ -12,7 +11,6 @@ tests/ui/process/nofile-limit.rs tests/ui/attributes/fn-align-dyn.rs tests/ui/linkage-attr/raw-dylib/elf/glibc-x86_64.rs tests/ui/statics/const_generics.rs -tests/ui/thir-print/offset_of.rs tests/ui/asm/x86_64/global_asm_escape.rs tests/ui/lto/all-crates.rs tests/ui/explicit-tail-calls/tailcc-no-signature-restriction.rs @@ -20,7 +18,6 @@ tests/ui/explicit-tail-calls/become-indirect-return.rs tests/ui/explicit-tail-calls/indirect.rs tests/ui/abi/rust-tail-cc.rs tests/ui/abi/rust-preserve-none-cc.rs -tests/ui/extern/extern-types-field-offset.rs tests/ui/scalable-vectors/debuginfo-does-not-spill.rs tests/ui/scalable-vectors/debuginfo-no-opt-llvm-ice.rs tests/ui/scalable-vectors/transmute.rs diff --git a/compiler/rustc_codegen_llvm/src/back/llvm_backend.rs b/compiler/rustc_codegen_llvm/src/back/llvm_backend.rs index 385b785233a75..c2fd8a79407f0 100644 --- a/compiler/rustc_codegen_llvm/src/back/llvm_backend.rs +++ b/compiler/rustc_codegen_llvm/src/back/llvm_backend.rs @@ -2,12 +2,12 @@ //! and related traits for the LLVM codegen backend. use std::any::Any; +use std::cell::OnceCell; use std::ffi::CStr; use std::marker::PhantomData; use std::mem::ManuallyDrop; use std::path::PathBuf; use std::ptr; -use std::sync::OnceLock; use rustc_ast::expand::allocator::AllocatorMethod; use rustc_codegen_ssa::back::lto::ThinModule; @@ -451,13 +451,15 @@ pub struct ModuleLlvm { /// Saved ThinLTO buffer for embedding in the object file. /// - /// This is currently a `OnceLock` to avoid aliasing problems when writing to it + /// This is currently a `OnceCell` to avoid aliasing problems when writing to it /// from code that also wants to pass around a shared ref to `ModuleCodegen`. - pub(crate) thin_lto_buffer: OnceLock>, + pub(crate) thin_lto_buffer: OnceCell>, } +// An LLVM context can only be used by one thread at a time. But we can move the entire context and +// all objects inside it to another thread (needed for parallel codegen). This is sound because +// `ModuleLlvm` owns the context and only allows borrowing LLVM objects tied to the context. unsafe impl Send for ModuleLlvm {} -unsafe impl Sync for ModuleLlvm {} /// Shared helper to call [`llvm::LLVMContextCreate`] and then configure /// [`llvm::LLVMContextSetDiscardValueNames`]. @@ -478,7 +480,7 @@ impl ModuleLlvm { llmod_raw, llcx_raw, tm: ManuallyDrop::new(create_target_machine(tcx, mod_name)), - thin_lto_buffer: OnceLock::new(), + thin_lto_buffer: OnceCell::new(), } } } @@ -491,7 +493,7 @@ impl ModuleLlvm { llmod_raw, llcx_raw, tm: ManuallyDrop::new(create_informational_target_machine(tcx.sess)), - thin_lto_buffer: OnceLock::new(), + thin_lto_buffer: OnceCell::new(), } } } @@ -512,7 +514,7 @@ impl ModuleLlvm { llmod_raw, llcx_raw, tm: ManuallyDrop::new(tm), - thin_lto_buffer: OnceLock::new(), + thin_lto_buffer: OnceCell::new(), } } } diff --git a/compiler/rustc_codegen_ssa/src/traits/write.rs b/compiler/rustc_codegen_ssa/src/traits/write.rs index 4c0df97a41985..36bc0a68d882e 100644 --- a/compiler/rustc_codegen_ssa/src/traits/write.rs +++ b/compiler/rustc_codegen_ssa/src/traits/write.rs @@ -14,7 +14,7 @@ use crate::back::write::{ use crate::{CompiledModule, ModuleCodegen}; pub trait WriteBackendMethods: Clone + 'static { - type Module: Send + Sync; + type Module: Send; type TargetMachine; type ModuleBuffer: ModuleBufferMethods; type ThinData: Send + Sync; diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 068ec3424d91d..973c0bd04e55f 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -962,13 +962,15 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { }; if a_def.did() == b_def.did() { // Reborrow is applicable here - self.unify_and( + let coerce = self.unify_and( a, b, [], Adjust::GenericReborrow(ty::Mutability::Mut), ForceLeakCheck::No, - ) + )?; + self.taint_if_reborrow_impls_are_invalid(ty::Mutability::Mut); + Ok(coerce) } else { // FIXME: CoerceShared check goes here, error for now Err(TypeError::Mismatch) @@ -1003,6 +1005,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { ocx.register_obligation(obligation); let errs = ocx.evaluate_obligations_error_on_ambiguity(); if errs.no_errors() { + self.taint_if_reborrow_impls_are_invalid(ty::Mutability::Not); Ok(InferOk { value: ( vec![Adjustment { @@ -1018,6 +1021,24 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { } } + /// Borrowck and const eval lower a generic reborrow by walking the fields of the source and + /// target types, trusting that coherence has validated the `Reborrow` and `CoerceShared` impls + /// that permit it. If coherence rejected any of those impls, that walk can hit shapes it does + /// not expect, so we taint the body to keep it away from them. + fn taint_if_reborrow_impls_are_invalid(&self, mutability: ty::Mutability) { + let lang_items = self.tcx.lang_items(); + let trait_def_ids = match mutability { + ty::Mutability::Mut => [lang_items.reborrow(), None], + // A shared reborrow also reborrows any fields of the source that implement `Reborrow`. + ty::Mutability::Not => [lang_items.coerce_shared(), lang_items.reborrow()], + }; + for trait_def_id in trait_def_ids.into_iter().flatten() { + if let Err(guar) = self.tcx.ensure_result().coherent_trait(trait_def_id) { + self.set_tainted_by_errors(guar); + } + } + } + fn coerce_from_fn_pointer( &self, a: Ty<'tcx>, diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 5ad0aae9a916a..d4ddc46b43a56 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -3894,8 +3894,6 @@ impl<'a> Parser<'a> { let attrs = self.parse_outer_attributes()?; self.recover_vcs_conflict_marker(); self.collect_tokens(None, attrs, ForceCollect::No, |this, attrs| { - let lo = this.token.span; - // Check if a colon exists one ahead. This means we're parsing a fieldname. let is_shorthand = !this.look_ahead(1, |t| t == &token::Colon || t == &token::Eq); // Proactively check whether parsing the field will be incorrect. @@ -3914,22 +3912,25 @@ impl<'a> Parser<'a> { token: pprust::token_to_string(&this.look_ahead(1, |t| *t)), })); } - let (ident, expr) = if is_shorthand { + let (ident, expr, span) = if is_shorthand { // Mimic `x: x` for the `x` field shorthand. let ident = this.parse_ident_common(false)?; let path = ast::Path::from_ident(ident); - (ident, this.mk_expr(ident.span, ExprKind::Path(None, path))) + (ident, this.mk_expr(ident.span, ExprKind::Path(None, path)), ident.span) } else { let ident = this.parse_field_name()?; + let span = ident.span.to(this.token.span); this.error_on_eq_field_init(ident); this.bump(); // `:` - (ident, this.parse_expr()?) + let expr = this.parse_expr()?; + let span = span.to(expr.span); + (ident, expr, span) }; Ok(( ast::ExprField { ident, - span: lo.to(expr.span), + span, expr, is_shorthand, attrs, diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 94b3c6ee01455..51f5bc189281b 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -1480,8 +1480,8 @@ impl VecDeque { // SAFETY: // * Any slice passed to `drop_in_place` is valid; the second case has - // `len <= front.len()` and returning on `len > self.len()` ensures - // `begin <= back.len()` in the first case + // `len <= front.len()` and returning on `len >= self.len()` ensures + // `begin < back.len()` in the first case // * The head of the VecDeque is moved before calling `drop_in_place`, // so no value is dropped twice if `drop_in_place` panics unsafe { diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 6c2d5d68d787c..aefe43aa13ef2 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -92,6 +92,7 @@ #![feature(allocator_ext)] #![feature(array_into_iter_constructors)] #![feature(ascii_char)] +#![feature(ascii_char_variants)] #![feature(async_fn_traits)] #![feature(async_iterator)] #![feature(borrowed_buf_init)] @@ -156,6 +157,7 @@ #![feature(pattern)] #![feature(pin_coerce_unsized_trait)] #![feature(ptr_alignment_type)] +#![feature(ptr_cast_array)] #![feature(ptr_metadata)] #![feature(random)] #![feature(raw_os_error_ty)] diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index bb8301e53d34f..9961c71dc062e 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -42,11 +42,15 @@ #![stable(feature = "rust1", since = "1.0.0")] +#[cfg(not(no_global_oom_handling))] +use core::ascii; use core::error::Error; use core::iter::FusedIterator; #[cfg(not(no_global_oom_handling))] use core::iter::from_fn; #[cfg(not(no_global_oom_handling))] +use core::mem::MaybeUninit; +#[cfg(not(no_global_oom_handling))] use core::num::Saturating; #[cfg(not(no_global_oom_handling))] use core::ops::Add; @@ -1488,8 +1492,8 @@ impl String { /// Shortens this `String` to the specified length. /// - /// If `new_len` is greater than or equal to the string's current length, this has no - /// effect. + /// If `new_len` is greater than or equal to the string's current length, + /// this has no effect. /// /// Note that this method has no effect on the allocated capacity /// of the string @@ -1511,10 +1515,11 @@ impl String { #[stable(feature = "rust1", since = "1.0.0")] #[track_caller] pub fn truncate(&mut self, new_len: usize) { - if new_len <= self.len() { - assert!(self.is_char_boundary(new_len)); - self.vec.truncate(new_len) + if new_len >= self.len() { + return; } + assert!(self.is_char_boundary(new_len)); + self.vec.truncate(new_len) } /// Removes the last character from the string buffer and returns it. @@ -2448,12 +2453,35 @@ impl Clone for String { #[stable(feature = "rust1", since = "1.0.0")] impl FromIterator for String { fn from_iter>(iter: I) -> String { - let mut buf = String::new(); - buf.extend(iter); + FromCharIterSpec::to_string_spec(iter.into_iter()) + } +} + +#[cfg(not(no_global_oom_handling))] +trait FromCharIterSpec: Iterator { + fn to_string_spec(self) -> String; +} + +#[cfg(not(no_global_oom_handling))] +impl FromCharIterSpec for T +where + T: Iterator, +{ + default fn to_string_spec(self) -> String { + let mut buf = String::with_capacity(self.size_hint().0); + buf.extend(self); buf } } +#[cfg(not(no_global_oom_handling))] +impl FromCharIterSpec for core::str::EscapeDefault<'_> { + fn to_string_spec(self) -> String { + // go through the ToString specialization + self.to_string() + } +} + #[cfg(not(no_global_oom_handling))] #[stable(feature = "string_from_iter_by_ref", since = "1.17.0")] impl<'a> FromIterator<&'a char> for String { @@ -2549,10 +2577,7 @@ impl<'a> FromIterator<&'a core::ascii::Char> for String { #[stable(feature = "rust1", since = "1.0.0")] impl Extend for String { fn extend>(&mut self, iter: I) { - let iterator = iter.into_iter(); - let (lower_bound, _) = iterator.size_hint(); - self.reserve(lower_bound); - iterator.for_each(move |c| self.push(c)); + SpecExtendChars::spec_extend_into(iter, self); } #[inline] @@ -2566,6 +2591,28 @@ impl Extend for String { } } +#[cfg(not(no_global_oom_handling))] +trait SpecExtendChars { + fn spec_extend_into(self, s: &mut String); +} + +#[cfg(not(no_global_oom_handling))] +impl> SpecExtendChars for T { + default fn spec_extend_into(self, target: &mut String) { + let iterator = self.into_iter(); + let (lower_bound, _) = iterator.size_hint(); + target.reserve(lower_bound); + iterator.for_each(move |c| target.push(c)); + } +} + +#[cfg(not(no_global_oom_handling))] +impl SpecExtendChars for core::str::EscapeDefault<'_> { + fn spec_extend_into(self, target: &mut String) { + target.extend_from_escape_default(self); + } +} + #[cfg(not(no_global_oom_handling))] #[stable(feature = "extend_ref", since = "1.2.0")] impl<'a> Extend<&'a char> for String { @@ -3160,6 +3207,126 @@ impl SpecToString for fmt::Arguments<'_> { } } +#[cfg(not(no_global_oom_handling))] +impl SpecToString for core::str::EscapeDefault<'_> { + fn spec_to_string(&self) -> String { + let mut s = String::new(); + s.extend_from_escape_default(self.clone()); + s + } +} + +#[cfg(not(no_global_oom_handling))] +impl String { + #[inline] + fn extend_from_escape_default(&mut self, escaper: core::str::EscapeDefault<'_>) { + let (front, middle, tail) = escaper.into_parts(); + let lengths = front.as_ref().map_or_default(|f| f.size_hint().0) + + middle.as_ref().map_or_default(|m| m.size_hint().0) + + tail.as_ref().map_or_default(|t| t.size_hint().0); + self.reserve(lengths); + + if let Some(front) = front { + self.extend(front); + } + if let Some(middle) = middle { + /// Ensures a spare capacity of N bytes and then passes that as MaybeUninit + /// slice to a closure that returns the bytes written, then + /// updates the length. + /// + /// # Safety: + /// + /// The caller must initialize the number of bytes returned by the closure. + #[inline] + unsafe fn with_spare( + bytes: &mut Vec, + then: impl FnOnce(&mut [MaybeUninit; N]) -> usize, + ) { + const { + assert!(core::mem::size_of::() == 1); + } + bytes.reserve(N); + let old_len = bytes.len(); + // SAFETY: We reserved enough space for the requested number of bytes. + unsafe { + let spare: &mut [MaybeUninit; N] = bytes + .spare_capacity_mut() + .as_mut_ptr() + .cast::() + .cast_uninit() + .cast_array::() + .as_mut_unchecked(); + let written = then(spare); + bytes.set_len(old_len + written); + } + } + + for c in middle { + match c { + '\'' | '\"' | '\\' => { + self.push('\\'); + self.push(c); + } + '\x20'..='\x7e' => self.push(c), + '\t' => { + self.push('\\'); + self.push('t'); + } + '\r' => { + self.push('\\'); + self.push('r'); + } + '\n' => { + self.push('\\'); + self.push('n'); + } + c => { + // SAFETY: We only let the function write ascii chars, so it remains valid utf8. + // and it returns the number of bytes written, so so with_spare ensures the rest for us. + unsafe { + with_spare::<10, ascii::Char>(self.as_mut_vec(), |spare| { + escape_unicode_into(spare, c) + }); + } + } + } + } + } + + if let Some(tail) = tail { + self.extend(tail); + } + } +} + +#[cfg(not(no_global_oom_handling))] +#[inline] +// adapted from core::escape::escape_unicode, but it's left-aligned instead of right-aligned. +fn escape_unicode_into(output: &mut [MaybeUninit; 10], c: char) -> usize { + const HEX_DIGITS: [ascii::Char; 16] = *b"0123456789abcdef".as_ascii().unwrap(); + + let c = c as u32; + // OR-ing `1` ensures that for `c == 0` the code computes that + // one digit should be printed. + let prefix_skip = (c | 1).leading_zeros() as usize / 4 - 2; + + // Always write all digits, but for shorter representations the unused + // digits get overwritten by later writes. + output[3usize.saturating_sub(prefix_skip)].write(HEX_DIGITS[((c >> 20) & 15) as usize]); + output[4usize.saturating_sub(prefix_skip)].write(HEX_DIGITS[((c >> 16) & 15) as usize]); + output[5usize.saturating_sub(prefix_skip)].write(HEX_DIGITS[((c >> 12) & 15) as usize]); + output[6usize.saturating_sub(prefix_skip)].write(HEX_DIGITS[((c >> 8) & 15) as usize]); + output[7usize.saturating_sub(prefix_skip)].write(HEX_DIGITS[((c >> 4) & 15) as usize]); + output[8usize.saturating_sub(prefix_skip)].write(HEX_DIGITS[(c & 15) as usize]); + + output[0].write(ascii::Char::ReverseSolidus); + output[1].write(ascii::Char::SmallU); + output[2].write(ascii::Char::LeftCurlyBracket); + output[9 - prefix_skip].write(ascii::Char::RightCurlyBracket); + + 10 - prefix_skip +} + #[stable(feature = "rust1", since = "1.0.0")] impl AsRef for String { #[inline] diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index d51eb95e9eeec..03702b19f92c7 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1701,8 +1701,8 @@ impl Vec { /// assert_eq!(vec, [1, 2]); /// ``` /// - /// No truncation occurs when `len` is greater than the vector's current - /// length: + /// No truncation occurs when `len` is greater than or equal to the + /// vector's current length: /// /// ``` /// let mut vec = vec![1, 2, 3]; @@ -1728,16 +1728,13 @@ impl Vec { // This is safe because: // - // * the slice passed to `drop_in_place` is valid; the `len > self.len` + // * the slice passed to `drop_in_place` is valid; the `len >= self.len` // case avoids creating an invalid slice, and // * the `len` of the vector is shrunk before calling `drop_in_place`, // such that no value will be dropped twice in case `drop_in_place` // were to panic once (if it panics twice, the program aborts). unsafe { - // Note: It's intentional that this is `>` and not `>=`. - // Changing it to `>=` has negative performance - // implications in some cases. See #78884 for more. - if len > self.len { + if len >= self.len { return; } let remaining_len = self.len - len; @@ -3163,7 +3160,8 @@ impl Vec { /// calling the closure `f`. The return values from `f` will end up /// in the `Vec` in the order they have been generated. /// - /// If `new_len` is less than `len`, the `Vec` is simply truncated. + /// If `new_len` is less than or equal to `len`, the `Vec` is simply + /// truncated. /// /// This method uses a closure to create new values on every push. If /// you'd rather [`Clone`] a given value, use [`Vec::resize`]. If you @@ -3517,7 +3515,8 @@ impl Vec { /// /// If `new_len` is greater than `len`, the `Vec` is extended by the /// difference, with each additional slot filled with `value`. - /// If `new_len` is less than `len`, the `Vec` is simply truncated. + /// If `new_len` is less than or equal to `len`, the `Vec` is simply + /// truncated. /// /// This method requires `T` to implement [`Clone`], /// in order to be able to clone the passed value. diff --git a/library/alloc/src/wtf8/mod.rs b/library/alloc/src/wtf8/mod.rs index 232fbba622b35..2296806d0cd42 100644 --- a/library/alloc/src/wtf8/mod.rs +++ b/library/alloc/src/wtf8/mod.rs @@ -354,18 +354,19 @@ impl Wtf8Buf { /// Shortens a string to the specified length. /// - /// If `new_len` is greater than the string's current length, this has no - /// effect. + /// If `new_len` is greater than or equal to the string's current length, + /// this has no effect. /// /// # Panics /// /// Panics if `new_len` does not lie on a code point boundary. #[inline] pub fn truncate(&mut self, new_len: usize) { - if new_len <= self.len() { - assert!(self.is_code_point_boundary(new_len)); - self.bytes.truncate(new_len) + if new_len >= self.len() { + return; } + assert!(self.is_code_point_boundary(new_len)); + self.bytes.truncate(new_len) } /// Consumes the WTF-8 string and tries to convert it to a vec of bytes. diff --git a/library/alloctests/benches/str.rs b/library/alloctests/benches/str.rs index 98c7c5413caef..68bdfbed8c8b5 100644 --- a/library/alloctests/benches/str.rs +++ b/library/alloctests/benches/str.rs @@ -1,5 +1,9 @@ use test::{Bencher, black_box}; +#[allow(unused)] // this is a symlink to core benches, we don't use everything here +#[path = "../../coretests/benches/str/corpora.rs"] +pub(super) mod corpora; + #[bench] fn char_iterator(b: &mut Bencher) { let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb"; diff --git a/library/alloctests/benches/string.rs b/library/alloctests/benches/string.rs index 0bbec12e4fdc6..75caf722d723d 100644 --- a/library/alloctests/benches/string.rs +++ b/library/alloctests/benches/string.rs @@ -159,3 +159,15 @@ fn bench_insert_str_long(b: &mut Bencher) { x }) } + +#[bench] +fn bench_from_escape_default_ascii(b: &mut Bencher) { + let s = super::str::corpora::en::LARGE; + b.iter(|| black_box(s).escape_default().to_string()) +} + +#[bench] +fn bench_from_escape_default_multibyte(b: &mut Bencher) { + let s = super::str::corpora::emoji::LARGE; + b.iter(|| black_box(s).escape_default().to_string()) +} diff --git a/library/alloctests/tests/string.rs b/library/alloctests/tests/string.rs index 08eb1855a4824..9c632b4e3a2f9 100644 --- a/library/alloctests/tests/string.rs +++ b/library/alloctests/tests/string.rs @@ -956,3 +956,14 @@ fn test_str_concat() { let s: String = format!("{a}{b}"); assert_eq!(s.as_bytes()[9], 'd' as u8); } + +// alloc has a specialization for EscapeDefault's ToString impl, which isn't covered by core tests. +#[test] +fn test_from_escaped_str() { + assert_eq!("abcABC012".escape_default().to_string(), "abcABC012"); + assert_eq!("\t\n\"".escape_default().to_string(), r#"\t\n\""#); + assert_eq!("\u{10FFFF}".escape_default().to_string(), "\\u{10ffff}"); + assert_eq!("\u{0}".escape_default().to_string(), "\\u{0}"); + assert_eq!("\u{1}".escape_default().to_string(), "\\u{1}"); + assert_eq!("\u{100}".escape_default().to_string(), "\\u{100}"); +} diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index ede69cb01c77a..96981a75d98f2 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -638,9 +638,8 @@ macro_rules! int_impl { /// /// # Safety /// - /// This results in undefined behavior when - #[doc = concat!("`self + rhs > ", stringify!($SelfT), "::MAX` or `self + rhs < ", stringify!($SelfT), "::MIN`,")] - /// i.e. when [`checked_add`] would return `None`. + /// This results in undefined behavior when overflow occurs, i.e. when + /// [`checked_add`] would return `None`. /// /// [`unwrap_unchecked`]: option/enum.Option.html#method.unwrap_unchecked #[doc = concat!("[`checked_add`]: ", stringify!($SelfT), "::checked_add")] @@ -778,9 +777,8 @@ macro_rules! int_impl { /// /// # Safety /// - /// This results in undefined behavior when - #[doc = concat!("`self - rhs > ", stringify!($SelfT), "::MAX` or `self - rhs < ", stringify!($SelfT), "::MIN`,")] - /// i.e. when [`checked_sub`] would return `None`. + /// This results in undefined behavior when overflow occurs, i.e. when + /// [`checked_sub`] would return `None`. /// /// [`unwrap_unchecked`]: option/enum.Option.html#method.unwrap_unchecked #[doc = concat!("[`checked_sub`]: ", stringify!($SelfT), "::checked_sub")] @@ -918,9 +916,8 @@ macro_rules! int_impl { /// /// # Safety /// - /// This results in undefined behavior when - #[doc = concat!("`self * rhs > ", stringify!($SelfT), "::MAX` or `self * rhs < ", stringify!($SelfT), "::MIN`,")] - /// i.e. when [`checked_mul`] would return `None`. + /// This results in undefined behavior when overflow occurs, i.e. when + /// [`checked_mul`] would return `None`. /// /// [`unwrap_unchecked`]: option/enum.Option.html#method.unwrap_unchecked #[doc = concat!("[`checked_mul`]: ", stringify!($SelfT), "::checked_mul")] diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index c97e6f4c45395..d0cc0e3b31da7 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -1274,17 +1274,8 @@ macro_rules! nonzero_integer { /// /// # Safety /// - /// This results in undefined behavior when - #[doc = sign_dependent_expr!{ - $signedness ? - if signed { - concat!("`self * rhs > ", stringify!($Int), "::MAX`, ", - "or `self * rhs < ", stringify!($Int), "::MIN`.") - } - if unsigned { - concat!("`self * rhs > ", stringify!($Int), "::MAX`.") - } - }] + /// This results in undefined behavior when overflow occurs, i.e. + /// when [`checked_mul`] would return `None`. /// /// # Examples /// @@ -1302,6 +1293,8 @@ macro_rules! nonzero_integer { /// # Some(()) /// # } /// ``` + /// + /// [`checked_mul`]: Self::checked_mul #[unstable(feature = "nonzero_ops", issue = "84186")] #[must_use = "this returns the result of the operation, \ without modifying the original"] @@ -1506,10 +1499,12 @@ macro_rules! nonzero_integer { #[inline] const fn from_ascii_bytes_radix_impl(src: &[u8], radix: u32) -> Result { + // FIXME(const-hack): This should use `?` again, once it's `const` let n = match <$Int>::from_ascii_bytes_radix_impl(src, radix) { Ok(n) => n, Err(err) => return Err(err), }; + // FIXME(const-hack): This should use `Option::ok_or` again, once it's `const` if let Some(n) = Self::new(n) { Ok(n) } else { @@ -1871,8 +1866,8 @@ macro_rules! nonzero_integer_signedness_dependent_methods { /// /// # Safety /// - /// This results in undefined behavior when - #[doc = concat!("`self + rhs > ", stringify!($Int), "::MAX`.")] + /// This results in undefined behavior when overflow occurs, i.e. when + /// [`checked_add`] would return `None`. /// /// # Examples /// @@ -1890,6 +1885,8 @@ macro_rules! nonzero_integer_signedness_dependent_methods { /// # Some(()) /// # } /// ``` + /// + /// [`checked_add`]: Self::checked_add #[unstable(feature = "nonzero_ops", issue = "84186")] #[must_use = "this returns the result of the operation, \ without modifying the original"] diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 69352e9f3ed97..84107ec3f1883 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -1009,9 +1009,8 @@ macro_rules! uint_impl { /// /// # Safety /// - /// This results in undefined behavior when - #[doc = concat!("`self + rhs > ", stringify!($SelfT), "::MAX`,")] - /// i.e. when [`checked_add`] would return `None`. + /// This results in undefined behavior when overflow occurs, i.e. when + /// [`checked_add`] would return `None`. /// /// [`unwrap_unchecked`]: option/enum.Option.html#method.unwrap_unchecked #[doc = concat!("[`checked_add`]: ", stringify!($SelfT), "::checked_add")] @@ -1188,9 +1187,8 @@ macro_rules! uint_impl { /// /// # Safety /// - /// This results in undefined behavior when - #[doc = concat!("`self - rhs < ", stringify!($SelfT), "::MIN`,")] - /// i.e. when [`checked_sub`] would return `None`. + /// This results in undefined behavior when overflow occurs, i.e. when + /// [`checked_sub`] would return `None`. /// /// [`unwrap_unchecked`]: option/enum.Option.html#method.unwrap_unchecked #[doc = concat!("[`checked_sub`]: ", stringify!($SelfT), "::checked_sub")] @@ -1397,9 +1395,8 @@ macro_rules! uint_impl { /// /// # Safety /// - /// This results in undefined behavior when - #[doc = concat!("`self * rhs > ", stringify!($SelfT), "::MAX`,")] - /// i.e. when [`checked_mul`] would return `None`. + /// This results in undefined behavior when overflow occurs, i.e. when + /// [`checked_mul`] would return `None`. /// /// [`unwrap_unchecked`]: option/enum.Option.html#method.unwrap_unchecked #[doc = concat!("[`checked_mul`]: ", stringify!($SelfT), "::checked_mul")] diff --git a/library/core/src/str/iter.rs b/library/core/src/str/iter.rs index 60b9e81aaeff9..657d894d38878 100644 --- a/library/core/src/str/iter.rs +++ b/library/core/src/str/iter.rs @@ -1589,6 +1589,18 @@ pub struct EscapeDefault<'a> { pub(super) inner: FlatMap, char_mod::EscapeDefault, CharEscapeDefault>, } +impl<'a> EscapeDefault<'a> { + /// Disassembles the iterator into its internal state. + /// Used by alloc for an optimized to_string impl. + #[unstable(feature = "std_internals", issue = "none")] + pub fn into_parts( + self, + ) -> (Option>, Option>, Option>) + { + self.inner.into_parts() + } +} + /// The return type of [`str::escape_unicode`]. #[stable(feature = "str_escape", since = "1.34.0")] #[derive(Clone, Debug)] diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index 770cc5f834a11..7a4a7049533ce 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -569,8 +569,8 @@ impl OsString { /// Truncate the `OsString` to the specified length. /// - /// If `new_len` is greater than the string's current length, this has no - /// effect. + /// If `new_len` is greater than or equal to the string's current length, + /// this has no effect. /// /// # Panics /// @@ -579,11 +579,12 @@ impl OsString { #[inline] #[unstable(feature = "os_string_truncate", issue = "133262")] pub fn truncate(&mut self, len: usize) { - if len <= self.len() { - self.as_os_str().inner.check_public_boundary(len); - // SAFETY: The length was just checked to be at a valid boundary. - unsafe { self.inner.truncate_unchecked(len) }; + if len >= self.len() { + return; } + self.as_os_str().inner.check_public_boundary(len); + // SAFETY: The length was just checked to be at a valid boundary. + unsafe { self.inner.truncate_unchecked(len) }; } /// Provides plumbing to `Vec::extend_from_slice` without giving full diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs index 6c6f9b552c926..dd6336748db2c 100644 --- a/library/std/src/os/fd/owned.rs +++ b/library/std/src/os/fd/owned.rs @@ -90,6 +90,31 @@ impl BorrowedFd<'_> { pub const unsafe fn borrow_raw(fd: RawFd) -> Self { Self { fd: ValidRawFd::new(fd).expect("fd != -1"), _phantom: PhantomData } } + + /// Converts a `BorrowedFd` into a reference to a file-like type. + /// + #[cfg_attr(all(unix, not(miri)), doc = "```")] + #[cfg_attr( + // FIXME: https://github.com/rust-lang/miri/issues/5453 + any(not(unix), miri), + doc = "```ignore (needs unix; miri doesn't support metadata on stdio)" + )] + /// # #![feature(fd_view)] + /// # use std::fs::File; + /// # use std::io; + /// # use std::os::fd::AsFd; + /// let meta = io::stdout().as_fd().to_view::().metadata().unwrap(); + /// if meta.is_file() { + /// println!("stdout is a regular file"); + /// } + /// ``` + #[unstable(feature = "fd_view", issue = "160402")] + pub fn to_view(&self) -> &T + where + Self: AsRef, + { + self.as_ref() + } } impl OwnedFd { @@ -435,6 +460,58 @@ impl From for crate::net::UdpSocket { } } +/// Implements `AsRef<$t>` conversions from `BorrowedFd` to the specified types. +/// +/// # Safety +/// +/// It must be sound to transmute `&BorrowedFd` to `&$t`. +/// +/// This typically implies that: +/// +/// - $t must be a wrapper with `BorrowedFd`, `OwnedFd` or `RawFd` being the single non-ZST-field. +/// Nominally it also requires repr(transparent), but std can cheat because we can stay in +/// sync with rustc's layout implementation details. +/// - `&$t` must not have any methods that would allow closing the file descriptor. +/// - `&$t` impls must tolerate instances being created from any kind of file-descriptor without +/// going through some dedicated constructor function, akin to `From` being a noop +/// conversion. +pub(crate) macro unsafe_impl_fd_asrefs { + ($($t:ty),*$(,)?) => {$( + #[unstable(feature = "fd_view", issue = "160402")] + #[unstable_feature_bound(fd_view)] + impl AsRef<$t> for BorrowedFd<'_> { + #[inline] + fn as_ref(&self) -> &$t { + use core::mem; + + // These are neither necessary nor sufficient, but generally + // a type that implements them is more likely to have the required behavior. + fn type_check + Into + AsFd>() {} + + // sanity check in case layouts change + const { + assert!(mem::size_of::() == mem::size_of::<$t>()); + assert!(mem::size_of::() == mem::size_of::>()); + } + type_check::<$t>(); + // SAFETY: See macro-level requirements. + unsafe { mem::transmute::<&BorrowedFd<'_>, &$t>(self) } + } + } + )*} +} + +#[cfg(not(target_os = "trusty"))] +unsafe_impl_fd_asrefs!( + crate::fs::File, + crate::net::TcpStream, + crate::net::TcpListener, + crate::net::UdpSocket, +); + +#[cfg(unix)] +unsafe_impl_fd_asrefs!(io::PipeWriter, io::PipeReader); + #[stable(feature = "asfd_ptrs", since = "1.64.0")] /// This impl allows implementing traits that require `AsFd` on Arc. /// ``` diff --git a/library/std/src/os/unix/fs.rs b/library/std/src/os/unix/fs.rs index fcafe1c29797f..6edb464b949d5 100644 --- a/library/std/src/os/unix/fs.rs +++ b/library/std/src/os/unix/fs.rs @@ -220,7 +220,7 @@ pub trait FileExt { let prev_written = buf.written(); match self.read_buf_at(buf.reborrow(), offset) { Ok(()) => {} - Err(e) if e.is_interrupted() => {} + Err(e) if e.is_interrupted() => continue, Err(e) => return Err(e), } let n = buf.written() - prev_written; diff --git a/library/std/src/os/unix/fs/tests.rs b/library/std/src/os/unix/fs/tests.rs index 1840bb38c17c8..52e0fe940a81f 100644 --- a/library/std/src/os/unix/fs/tests.rs +++ b/library/std/src/os/unix/fs/tests.rs @@ -56,6 +56,33 @@ fn write_vectored_at() { assert_eq!(&content, expected); } +#[test] +fn read_buf_exact_at_interrupted() { + struct InterruptOnce(crate::cell::Cell); + + impl FileExt for InterruptOnce { + fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result { + if self.0.replace(false) { + return Err(io::ErrorKind::Interrupted.into()); + } + let data = &b"pread is working!"[offset as usize..]; + let n = buf.len().min(data.len()); + buf[..n].copy_from_slice(&data[..n]); + Ok(n) + } + + fn write_at(&self, _buf: &[u8], _offset: u64) -> io::Result { + unimplemented!() + } + } + + let file = InterruptOnce(crate::cell::Cell::new(true)); + let mut buf = [0; 10]; + let mut buf = io::BorrowedBuf::from(buf.as_mut_slice()); + file.read_buf_exact_at(buf.unfilled(), 6).unwrap(); + assert_eq!(buf.filled(), b"is working"); +} + #[test] fn test_mkfifo() { let tmp_dir = crate::test_helpers::tmpdir(); diff --git a/library/std/src/os/unix/net/datagram.rs b/library/std/src/os/unix/net/datagram.rs index 548dca3592063..309f80f7923b2 100644 --- a/library/std/src/os/unix/net/datagram.rs +++ b/library/std/src/os/unix/net/datagram.rs @@ -20,7 +20,9 @@ use super::{SocketAncillary, recv_vectored_with_ancillary_from, send_vectored_wi #[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))] use crate::io::{IoSlice, IoSliceMut}; use crate::net::Shutdown; -use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; +use crate::os::unix::io::{ + AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd, unsafe_impl_fd_asrefs, +}; use crate::path::Path; use crate::sys::net::Socket; use crate::sys::{AsInner, FromInner, IntoInner, cvt}; @@ -1015,6 +1017,11 @@ impl AsFd for UnixDatagram { } } +// SAFETY: It's a tower of 1-field wrappers around OwnedFd. +// No methods to close the socket, no methods with safety preconditions, +// other than the fd being valid. +unsafe_impl_fd_asrefs!(UnixDatagram); + #[stable(feature = "io_safety", since = "1.63.0")] impl From for OwnedFd { /// Takes ownership of a [`UnixDatagram`]'s socket file descriptor. diff --git a/library/std/src/os/unix/net/listener.rs b/library/std/src/os/unix/net/listener.rs index 2e47a4b23a1cb..713ad2944a8cb 100644 --- a/library/std/src/os/unix/net/listener.rs +++ b/library/std/src/os/unix/net/listener.rs @@ -1,5 +1,7 @@ use super::{SocketAddr, UnixStream, sockaddr_un}; -use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; +use crate::os::unix::io::{ + AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd, unsafe_impl_fd_asrefs, +}; use crate::path::Path; use crate::sys::net::Socket; use crate::sys::{AsInner, FromInner, IntoInner, cvt}; @@ -355,6 +357,11 @@ impl From for UnixListener { } } +// SAFETY: It's a tower of 1-field wrappers around OwnedFd. +// No methods to close the socket, no methods with safety preconditions, +// other than the fd being valid. +unsafe_impl_fd_asrefs!(UnixListener); + #[stable(feature = "io_safety", since = "1.63.0")] impl From for OwnedFd { /// Takes ownership of a [`UnixListener`]'s socket file descriptor. diff --git a/library/std/src/os/unix/net/stream.rs b/library/std/src/os/unix/net/stream.rs index dba49d0406bf1..00c3e75592ee2 100644 --- a/library/std/src/os/unix/net/stream.rs +++ b/library/std/src/os/unix/net/stream.rs @@ -40,7 +40,9 @@ use super::{UCred, peer_cred}; use crate::fmt; use crate::io::{self, IoSlice, IoSliceMut}; use crate::net::Shutdown; -use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; +use crate::os::unix::io::{ + AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd, unsafe_impl_fd_asrefs, +}; use crate::path::Path; use crate::sys::net::Socket; use crate::sys::{AsInner, FromInner, cvt}; @@ -745,6 +747,11 @@ impl AsFd for UnixStream { } } +// SAFETY: It's a tower of 1-field wrappers around OwnedFd. +// No methods to close the socket, no methods with safety preconditions, +// other than the fd being valid. +unsafe_impl_fd_asrefs!(UnixStream); + #[stable(feature = "io_safety", since = "1.63.0")] impl From for OwnedFd { /// Takes ownership of a [`UnixStream`]'s socket file descriptor. diff --git a/library/std/src/os/windows/io/handle.rs b/library/std/src/os/windows/io/handle.rs index 01bd36155b110..ec20baf2bf2ce 100644 --- a/library/std/src/os/windows/io/handle.rs +++ b/library/std/src/os/windows/io/handle.rs @@ -151,6 +151,27 @@ impl BorrowedHandle<'_> { pub const unsafe fn borrow_raw(handle: RawHandle) -> Self { Self { handle, _phantom: PhantomData } } + + /// Converts a `BorrowedHandle` into a reference to a file-like type. + /// + #[cfg_attr(windows, doc = "```no_run")] + #[cfg_attr(not(windows), doc = "```ignore (needs windows)")] + /// # #![feature(fd_view)] + /// # use std::fs::File; + /// # use std::io; + /// # use std::os::windows::io::AsHandle; + /// let meta = io::stdout().as_handle().to_view::().metadata().unwrap(); + /// if meta.is_file() { + /// println!("stdout is a regular file"); + /// } + /// ``` + #[unstable(feature = "fd_view", issue = "160402")] + pub fn to_view(&self) -> &T + where + Self: AsRef, + { + self.as_ref() + } } #[stable(feature = "io_safety", since = "1.63.0")] @@ -680,6 +701,49 @@ impl AsHandle for io::PipeWriter { } } +/// Implements `AsRef<$t>` conversions from `BorrowedHandle` to the specified types. +/// +/// # Safety +/// +/// It must be sound to transmute `&BorrowedHandle` to `&$t`. +/// +/// This typically implies that: +/// +/// - $t must be a wrapper with `BorrowedHandle`, `OwnedHandle` or `RawHandle` being the single non-ZST-field. +/// Nominally it also requires repr(transparent), but std can cheat because we can stay in +/// sync with rustc's layout implementation details. +/// - `&$t` must not have any methods that would allow closing the file descriptor. +/// - `&$t` impls must tolerate instances being created from any kind of file-descriptor without +/// going through some dedicated constructor function, akin to `From` being a noop +/// conversion. +pub(crate) macro unsafe_impl_handle_asrefs { + ($($t:ty),*$(,)?) => {$( + #[unstable(feature = "fd_view", issue = "160402")] + #[unstable_feature_bound(fd_view)] + impl AsRef<$t> for BorrowedHandle<'_> { + #[inline] + fn as_ref(&self) -> &$t { + use core::mem; + + // These are neither necessary nor sufficient, but generally + // a type that implements them is more likely to have the required behavior. + fn type_check + Into + AsHandle>() {} + + // sanity check in case layouts change + const { + assert!(mem::size_of::() == mem::size_of::<$t>()); + assert!(mem::size_of::() == mem::size_of::>()); + } + type_check::<$t>(); + // SAFETY: See macro-level requirements. + unsafe { mem::transmute::<&BorrowedHandle<'_>, &$t>(self) } + } + } + )*} +} + +unsafe_impl_handle_asrefs!(crate::fs::File, io::PipeWriter, io::PipeReader,); + #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl From for OwnedHandle { fn from(pipe: io::PipeWriter) -> Self { diff --git a/library/std/src/sys/fs/windows.rs b/library/std/src/sys/fs/windows.rs index 0585ea5348c78..77311d233fc74 100644 --- a/library/std/src/sys/fs/windows.rs +++ b/library/std/src/sys/fs/windows.rs @@ -717,7 +717,7 @@ impl File { fn readlink(&self) -> io::Result { let mut space = Align8([MaybeUninit::::uninit(); c::MAXIMUM_REPARSE_DATA_BUFFER_SIZE as usize]); - let (_bytes, buf) = self.reparse_point(&mut space)?; + let (bytes, buf) = self.reparse_point(&mut space)?; unsafe { let (path_buffer, subst_off, subst_len, relative) = match (*buf).ReparseTag { c::IO_REPARSE_TAG_SYMLINK => { @@ -747,6 +747,17 @@ impl File { )); } }; + // Check that the reparse point offsets and length stay within the data that + // was actually returned, before the slice is built from them. This keeps + // malformed filesystem data from causing an out-of-bounds access. + let path_offset = path_buffer.addr() - buf.addr(); + let end = path_offset + (subst_off as usize * 2) + (subst_len as usize * 2); + if end > bytes as usize { + return Err(io::const_error!( + io::ErrorKind::Uncategorized, + "Invalid reparse point data", + )); + } let subst_ptr = path_buffer.add(subst_off.into()); let subst = slice::from_raw_parts_mut(subst_ptr, subst_len as usize); // Absolute paths start with an NT internal namespace prefix `\??\` diff --git a/library/std/src/sys/process/unix/unix.rs b/library/std/src/sys/process/unix/unix.rs index aa47fcb3360c1..ab02c05ea49a9 100644 --- a/library/std/src/sys/process/unix/unix.rs +++ b/library/std/src/sys/process/unix/unix.rs @@ -1077,12 +1077,6 @@ impl Process { #[derive(PartialEq, Eq, Clone, Copy, Default)] pub struct ExitStatus(c_int); -impl fmt::Debug for ExitStatus { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_tuple("unix_wait_status").field(&self.0).finish() - } -} - impl ExitStatus { pub fn new(status: c_int) -> ExitStatus { ExitStatus(status) @@ -1156,56 +1150,56 @@ impl From for ExitStatus { /// If a signal is unrecognized, it returns the empty string, so that /// you just get the number like "0". If it is recognized, you'll get /// something like "9 (SIGKILL)". -fn signal_string(signal: i32) -> &'static str { - match signal { - libc::SIGHUP => " (SIGHUP)", - libc::SIGINT => " (SIGINT)", - libc::SIGQUIT => " (SIGQUIT)", - libc::SIGILL => " (SIGILL)", - libc::SIGTRAP => " (SIGTRAP)", - libc::SIGABRT => " (SIGABRT)", +fn signal_string(signal: i32) -> Option<&'static str> { + let name = match signal { + libc::SIGHUP => "SIGHUP", + libc::SIGINT => "SIGINT", + libc::SIGQUIT => "SIGQUIT", + libc::SIGILL => "SIGILL", + libc::SIGTRAP => "SIGTRAP", + libc::SIGABRT => "SIGABRT", #[cfg(not(target_os = "l4re"))] - libc::SIGBUS => " (SIGBUS)", - libc::SIGFPE => " (SIGFPE)", - libc::SIGKILL => " (SIGKILL)", + libc::SIGBUS => "SIGBUS", + libc::SIGFPE => "SIGFPE", + libc::SIGKILL => "SIGKILL", #[cfg(not(target_os = "l4re"))] - libc::SIGUSR1 => " (SIGUSR1)", - libc::SIGSEGV => " (SIGSEGV)", + libc::SIGUSR1 => "SIGUSR1", + libc::SIGSEGV => "SIGSEGV", #[cfg(not(target_os = "l4re"))] - libc::SIGUSR2 => " (SIGUSR2)", - libc::SIGPIPE => " (SIGPIPE)", - libc::SIGALRM => " (SIGALRM)", - libc::SIGTERM => " (SIGTERM)", + libc::SIGUSR2 => "SIGUSR2", + libc::SIGPIPE => "SIGPIPE", + libc::SIGALRM => "SIGALRM", + libc::SIGTERM => "SIGTERM", #[cfg(not(target_os = "l4re"))] - libc::SIGCHLD => " (SIGCHLD)", + libc::SIGCHLD => "SIGCHLD", #[cfg(not(target_os = "l4re"))] - libc::SIGCONT => " (SIGCONT)", + libc::SIGCONT => "SIGCONT", #[cfg(not(target_os = "l4re"))] - libc::SIGSTOP => " (SIGSTOP)", + libc::SIGSTOP => "SIGSTOP", #[cfg(not(target_os = "l4re"))] - libc::SIGTSTP => " (SIGTSTP)", + libc::SIGTSTP => "SIGTSTP", #[cfg(not(target_os = "l4re"))] - libc::SIGTTIN => " (SIGTTIN)", + libc::SIGTTIN => "SIGTTIN", #[cfg(not(target_os = "l4re"))] - libc::SIGTTOU => " (SIGTTOU)", + libc::SIGTTOU => "SIGTTOU", #[cfg(not(target_os = "l4re"))] - libc::SIGURG => " (SIGURG)", + libc::SIGURG => "SIGURG", #[cfg(not(target_os = "l4re"))] - libc::SIGXCPU => " (SIGXCPU)", + libc::SIGXCPU => "SIGXCPU", #[cfg(not(any(target_os = "l4re", target_os = "rtems")))] - libc::SIGXFSZ => " (SIGXFSZ)", + libc::SIGXFSZ => "SIGXFSZ", #[cfg(not(any(target_os = "l4re", target_os = "rtems")))] - libc::SIGVTALRM => " (SIGVTALRM)", + libc::SIGVTALRM => "SIGVTALRM", #[cfg(not(target_os = "l4re"))] - libc::SIGPROF => " (SIGPROF)", + libc::SIGPROF => "SIGPROF", #[cfg(not(any(target_os = "l4re", target_os = "rtems")))] - libc::SIGWINCH => " (SIGWINCH)", + libc::SIGWINCH => "SIGWINCH", #[cfg(not(any(target_os = "haiku", target_os = "l4re")))] - libc::SIGIO => " (SIGIO)", + libc::SIGIO => "SIGIO", #[cfg(target_os = "haiku")] - libc::SIGPOLL => " (SIGPOLL)", + libc::SIGPOLL => "SIGPOLL", #[cfg(not(target_os = "l4re"))] - libc::SIGSYS => " (SIGSYS)", + libc::SIGSYS => "SIGSYS", // For information on Linux signals, run `man 7 signal` #[cfg(all( target_os = "linux", @@ -1216,14 +1210,14 @@ fn signal_string(signal: i32) -> &'static str { target_arch = "aarch64" ) ))] - libc::SIGSTKFLT => " (SIGSTKFLT)", + libc::SIGSTKFLT => "SIGSTKFLT", #[cfg(any( target_os = "linux", target_os = "nto", target_os = "qnx", target_os = "cygwin" ))] - libc::SIGPWR => " (SIGPWR)", + libc::SIGPWR => "SIGPWR", #[cfg(any( target_os = "freebsd", target_os = "netbsd", @@ -1234,7 +1228,7 @@ fn signal_string(signal: i32) -> &'static str { target_vendor = "apple", target_os = "cygwin", ))] - libc::SIGEMT => " (SIGEMT)", + libc::SIGEMT => "SIGEMT", #[cfg(any( target_os = "freebsd", target_os = "netbsd", @@ -1242,36 +1236,47 @@ fn signal_string(signal: i32) -> &'static str { target_os = "dragonfly", target_vendor = "apple", ))] - libc::SIGINFO => " (SIGINFO)", + libc::SIGINFO => "SIGINFO", #[cfg(target_os = "hurd")] - libc::SIGLOST => " (SIGLOST)", + libc::SIGLOST => "SIGLOST", #[cfg(target_os = "freebsd")] - libc::SIGTHR => " (SIGTHR)", + libc::SIGTHR => "SIGTHR", #[cfg(target_os = "freebsd")] - libc::SIGLIBRT => " (SIGLIBRT)", - _ => "", + libc::SIGLIBRT => "SIGLIBRT", + _ => return None, + }; + Some(name) +} + +impl fmt::Debug for ExitStatus { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "unix_wait_status({}, \"{self}\")", self.0) } } impl fmt::Display for ExitStatus { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if let Some(code) = self.code() { - write!(f, "exit status: {code}") + write!(f, "exit status: {code}")?; } else if let Some(signal) = self.signal() { - let signal_string = signal_string(signal); + write!(f, "signal: {signal}")?; + if let Some(name) = signal_string(signal) { + write!(f, " ({name})")?; + } if self.core_dumped() { - write!(f, "signal: {signal}{signal_string} (core dumped)") - } else { - write!(f, "signal: {signal}{signal_string}") + write!(f, " (core dumped)")?; } } else if let Some(signal) = self.stopped_signal() { - let signal_string = signal_string(signal); - write!(f, "stopped (not terminated) by signal: {signal}{signal_string}") + write!(f, "stopped (not terminated) by signal: {signal}")?; + if let Some(name) = signal_string(signal) { + write!(f, " ({name})")?; + } } else if self.continued() { - write!(f, "continued (WIFCONTINUED)") + write!(f, "continued (WIFCONTINUED)")?; } else { - write!(f, "unrecognised wait status: {} {:#x}", self.0, self.0) + write!(f, "unrecognised wait status: {} {:#x}", self.0, self.0)?; } + Ok(()) } } diff --git a/library/std/src/sys/process/unix/unix/tests.rs b/library/std/src/sys/process/unix/unix/tests.rs index 9a029f16a3a20..e360b61851b2e 100644 --- a/library/std/src/sys/process/unix/unix/tests.rs +++ b/library/std/src/sys/process/unix/unix/tests.rs @@ -6,13 +6,21 @@ use crate::process::Command; // safety etc., are tested in tests/ui/process/process-panic-after-fork.rs #[test] -fn exitstatus_display_tests() { +fn exitstatus_debug_display_tests() { // In practice this is the same on every Unix. - // If some weird platform turns out to be different, and this test fails, use #[cfg]. + // If some weird platform turns out to be different, and this test fails, use `cfg!`. use crate::os::unix::process::ExitStatusExt; use crate::process::ExitStatus; - let t = |v, s| assert_eq!(s, format!("{}", ::from_raw(v))); + let t = |v, disp| { + let status = ::from_raw(v); + assert_eq!(disp, format!("{status}"), "from value: {v:#x}"); + assert_eq!( + format!("ExitStatus(unix_wait_status({v}, {disp:?}))"), + format!("{status:?}"), + "from value: {v:#x}" + ); + }; t(0x0000f, "signal: 15 (SIGTERM)"); t(0x0008b, "signal: 11 (SIGSEGV) (core dumped)"); @@ -24,19 +32,13 @@ fn exitstatus_display_tests() { // The purpose of this test is to test our string formatting, not our understanding of the wait // status magic numbers. So restrict these to Linux. if cfg!(target_os = "linux") { - #[cfg(any(target_arch = "mips", target_arch = "mips64"))] - t(0x0137f, "stopped (not terminated) by signal: 19 (SIGPWR)"); - - #[cfg(any(target_arch = "sparc", target_arch = "sparc64"))] - t(0x0137f, "stopped (not terminated) by signal: 19 (SIGCONT)"); - - #[cfg(not(any( - target_arch = "mips", - target_arch = "mips64", - target_arch = "sparc", - target_arch = "sparc64" - )))] - t(0x0137f, "stopped (not terminated) by signal: 19 (SIGSTOP)"); + if cfg!(any(target_arch = "mips", target_arch = "mips64")) { + t(0x0137f, "stopped (not terminated) by signal: 19 (SIGPWR)"); + } else if cfg!(any(target_arch = "sparc", target_arch = "sparc64")) { + t(0x0137f, "stopped (not terminated) by signal: 19 (SIGCONT)"); + } else { + t(0x0137f, "stopped (not terminated) by signal: 19 (SIGSTOP)"); + } t(0x0ffff, "continued (WIFCONTINUED)"); } diff --git a/library/std/tests/sync/rwlock.rs b/library/std/tests/sync/rwlock.rs index 311866dab4733..9715411a9a692 100644 --- a/library/std/tests/sync/rwlock.rs +++ b/library/std/tests/sync/rwlock.rs @@ -905,35 +905,36 @@ fn test_rwlock_max_readers() { let mut read_lock_ctr: u32 = 0; let rwlock: RwLock = RwLock::new(0); - const MAX_READERS: u32 = - cfg_select! { - miri => 100, - any( - all(target_os = "windows", not(target_vendor = "win7")), - target_os = "linux", - target_os = "android", - target_os = "freebsd", - target_os = "openbsd", - target_os = "dragonfly", - target_os = "fuchsia", - all(target_family = "wasm", target_feature = "atomics"), - target_os = "hermit", - target_os = "motor", - ) => (1 << 30) - 2, - any( - target_family = "unix", - all(target_os = "windows", target_vendor = "win7", target_pointer_width = "64"), - all(target_vendor = "fortanix", target_env = "sgx"), - target_os = "xous", - target_os = "teeos", - ) => u32::MAX, - // Otherwise a form of deadlock is observed. - all(target_os = "windows", target_vendor = "win7", target_pointer_width = "32") => { - (1 << 28) - 1 + const MAX_READERS: u32 = cfg_select! { + miri => 100, + any( + all(target_os = "windows", not(target_vendor = "win7")), + target_os = "linux", + target_os = "android", + target_os = "freebsd", + target_os = "openbsd", + target_os = "dragonfly", + target_os = "fuchsia", + all(target_family = "wasm", target_feature = "atomics"), + target_os = "hermit", + target_os = "motor", + ) => (1 << 30) - 2, + any( + target_family = "unix", + all(target_os = "windows", target_vendor = "win7"), + all(target_vendor = "fortanix", target_env = "sgx"), + target_os = "xous", + target_os = "teeos", + ) => { + if usize::BITS - 4 > u32::BITS { + u32::MAX + } else { + (usize::MAX >> 4) as u32 } - target_os = "solid_asp3" => (1 << 30), - _ => u32::MAX, - }; + } + target_os = "solid_asp3" => (1 << 30), + _ => u32::MAX, + }; while read_lock_ctr < MAX_READERS { let lock = rwlock.read(); diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index f329f61c100c8..563c38f52fb7a 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -4155,9 +4155,6 @@ impl CommandLineStep for Bootstrap { let build_compiler = builder.compiler(0, host); let record_failed_tests = builder.ensure(SetupFailedTestsFile); - // Some tests require cargo submodule to be present. - builder.sess.require_submodule("src/tools/cargo", None); - let mut cargo = tool::prepare_tool_cargo( builder, build_compiler, diff --git a/src/bootstrap/src/core/builder/cargo.rs b/src/bootstrap/src/core/builder/cargo.rs index 98cfd58198a6c..27de3ec60b96b 100644 --- a/src/bootstrap/src/core/builder/cargo.rs +++ b/src/bootstrap/src/core/builder/cargo.rs @@ -1026,7 +1026,19 @@ impl Builder<'_> { // // Only clear out the directory if we're running Cargo on std; otherwise, we // should let Cargo take care of things for us (via depdep info) - if !self.config.dry_run() && mode == Mode::Std { + // + // When --keep-stage[-std] is passed, two things can happen: + // - Either this function is not invoked on `std` at all, because the corresponding Std step + // checks the flag and doesn't invoke Cargo for std at all. + // - This function is invoked, in which case it will (most likely) do a no-op stdlib + // rebuild. + // + // In the second situation, we must ensure that we will not clear the standard library + // output directory, otherwise --keep-stage[-std] will of course break. + // Note that the compiler stage corresponds to the standard library stage. + let keep_previously_built_std = self.config.keep_stage.contains(&compiler.stage) + || self.config.keep_stage_std.contains(&compiler.stage); + if !self.config.dry_run() && mode == Mode::Std && !keep_previously_built_std { build_stamp::clear_if_dirty(self, &out_dir, &self.rustc(compiler)); } diff --git a/src/ci/docker/host-x86_64/test-pr-check-1/reuse-requirements.txt b/src/ci/docker/host-x86_64/test-pr-check-1/reuse-requirements.txt index 8784e18864b23..231e06ba0a00c 100644 --- a/src/ci/docker/host-x86_64/test-pr-check-1/reuse-requirements.txt +++ b/src/ci/docker/host-x86_64/test-pr-check-1/reuse-requirements.txt @@ -24,9 +24,9 @@ chardet==5.2.0 \ # via # binaryornot # python-debian -jinja2==3.1.4 \ - --hash=sha256:4a3aee7acbbe7303aede8e9648d13b8bf88a429282aa6122a993f0ac800cb369 \ - --hash=sha256:bc5dd2abb727a5319567b7a813e6a2e7318c39f4f487cfe6c89c6f9c7d25197d +Jinja2==3.1.6 \ + --hash=sha256:0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d \ + --hash=sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67 # via reuse license-expression==30.3.0 \ --hash=sha256:1295406f736b4f395ff069aec1cebfad53c0fcb3cf57df0f5ec58fc7b905aea5 \ diff --git a/src/gcc b/src/gcc index 37ea7cd851f04..e1c6e07b095d0 160000 --- a/src/gcc +++ b/src/gcc @@ -1 +1 @@ -Subproject commit 37ea7cd851f04ee6a313c5067c9fde9328f876aa +Subproject commit e1c6e07b095d091177376a163da44039475e05e3 diff --git a/src/librustdoc/passes/strip_priv_imports.rs b/src/librustdoc/passes/strip_priv_imports.rs index 9a432c3bad343..7c68f0091342f 100644 --- a/src/librustdoc/passes/strip_priv_imports.rs +++ b/src/librustdoc/passes/strip_priv_imports.rs @@ -12,6 +12,11 @@ pub(super) fn strip_priv_imports(krate: clean::Crate, cx: &mut DocContext<'_>) - } let is_json_output = cx.is_json_output(); - ImportStripper { tcx: cx.tcx, is_json_output, document_hidden: cx.document_hidden() } - .fold_crate(krate) + ImportStripper { + tcx: cx.tcx, + is_json_output, + document_hidden: cx.document_hidden(), + document_private: cx.document_private(), + } + .fold_crate(krate) } diff --git a/src/librustdoc/passes/strip_private.rs b/src/librustdoc/passes/strip_private.rs index 54c8e9daedd17..e99e488ea227c 100644 --- a/src/librustdoc/passes/strip_private.rs +++ b/src/librustdoc/passes/strip_private.rs @@ -25,9 +25,13 @@ pub(super) fn strip_private(mut krate: clean::Crate, cx: &mut DocContext<'_>) -> is_json_output, tcx: cx.tcx, }; - krate = - ImportStripper { tcx: cx.tcx, is_json_output, document_hidden: cx.document_hidden() } - .fold_crate(stripper.fold_crate(krate)); + krate = ImportStripper { + tcx: cx.tcx, + is_json_output, + document_hidden: cx.document_hidden(), + document_private: cx.document_private(), + } + .fold_crate(stripper.fold_crate(krate)); } // strip all impls referencing private items diff --git a/src/librustdoc/passes/stripper.rs b/src/librustdoc/passes/stripper.rs index 4c6d62917ab24..45bfb519cf4f5 100644 --- a/src/librustdoc/passes/stripper.rs +++ b/src/librustdoc/passes/stripper.rs @@ -268,6 +268,7 @@ pub(crate) struct ImportStripper<'tcx> { pub(crate) tcx: TyCtxt<'tcx>, pub(crate) is_json_output: bool, pub(crate) document_hidden: bool, + pub(crate) document_private: bool, } impl ImportStripper<'_> { @@ -290,6 +291,7 @@ impl DocFolder for ImportStripper<'_> { debug!("ImportStripper: stripping {:?}", i.name); None } + clean::ImportItem(imp) if self.document_private => Some(self.fold_item_recur(i)), // clean::ImportItem(_) if !self.document_hidden && i.is_doc_hidden() => None, clean::ExternCrateItem { .. } | clean::ImportItem(..) if i.visibility(self.tcx) != Some(Visibility::Public) => diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index df55626ffb05d..33b0334e3fd5d 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -490,7 +490,15 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { let tcx = self.cx.tcx; let def_id = item.owner_id.to_def_id(); - let is_pub = tcx.visibility(def_id).is_public(); + // Explanations: if the item is public, nothing more to check. If not, then we check if + // we're documenting private item. If we are, then we want all items, except if it's a + // `use`. In this case, we want to check if it's a reexport. + let is_pub = tcx.visibility(def_id).is_public() + || (self.cx.document_private() + && (!matches!(item.kind, hir::ItemKind::Use(..)) + || def_id.as_local().is_some_and(|def_id| { + tcx.visibility(def_id).is_accessible_from(CRATE_DEF_ID, tcx) + }))); if is_pub { self.store_path(item.owner_id.to_def_id()); @@ -592,7 +600,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { // If there was a private module in the current path then don't bother inlining // anything as it will probably be stripped anyway. - if is_pub && self.inside_public_path { + if is_pub && (self.inside_public_path || self.cx.document_private()) { let please_inline = if let Some(res_did) = res.opt_def_id() && matches!(tcx.def_kind(res_did), DefKind::Macro(MacroKinds::BANG)) { diff --git a/src/tools/clippy/tests/ui/redundant_field_names.fixed b/src/tools/clippy/tests/ui/redundant_field_names.fixed index 0416735e18080..fb7af3a99c5b4 100644 --- a/src/tools/clippy/tests/ui/redundant_field_names.fixed +++ b/src/tools/clippy/tests/ui/redundant_field_names.fixed @@ -106,3 +106,10 @@ fn msrv_1_17() { let _ = RangeFrom { start }; //~^ redundant_field_names } + +fn issue_17525() { + let v = 1; + external! { + let _ = S { $v: $v }; + } +} diff --git a/src/tools/clippy/tests/ui/redundant_field_names.rs b/src/tools/clippy/tests/ui/redundant_field_names.rs index 4aa14fec4086c..4a4a07a77eaf6 100644 --- a/src/tools/clippy/tests/ui/redundant_field_names.rs +++ b/src/tools/clippy/tests/ui/redundant_field_names.rs @@ -106,3 +106,10 @@ fn msrv_1_17() { let _ = RangeFrom { start: start }; //~^ redundant_field_names } + +fn issue_17525() { + let v = 1; + external! { + let _ = S { $v: $v }; + } +} diff --git a/tests/rustdoc-html/inline_local/document-private-reexports.rs b/tests/rustdoc-html/inline_local/document-private-reexports.rs new file mode 100644 index 0000000000000..c0953e7678716 --- /dev/null +++ b/tests/rustdoc-html/inline_local/document-private-reexports.rs @@ -0,0 +1,52 @@ +// Test ensures that when we use the `--document-private-items` option, reexports +// work the same as for "public" items. +// Regression test for . + +//@ compile-flags: --document-private-items + +#![crate_name = "foo"] + +//@ has 'foo/index.html' +// The four reexports, the `not_hidden` and `foofoo` (private) modules. +//@ count - '//*[@class="item-table"]/dt' 6 +//@ has - '//*[@class="item-table"]/dt/a[@href="not_hidden/index.html"]' 'not_hidden' +//@ has - '//*[@class="item-table"]/dt/a[@href="struct.Top.html"]' 'Top' +//@ has - '//*[@class="item-table"]/dt/a[@href="struct.NotHidden.html"]' 'NotHidden' +//@ has - '//*[@class="item-table"]/dt/a[@href="struct.Hidden2.html"]' 'Hidden2' +//@ has - '//*[@class="item-table"]/dt/a[@href="struct.X.html"]' 'X' +//@ has - '//*[@class="item-table"]/dt/a[@href="foofoo/index.html"]' 'foofoo' + +#[doc(hidden)] +pub(crate) struct TopHidden; + +#[doc(inline)] +pub(crate) use TopHidden as Top; + +#[doc(hidden)] +mod hidden { + pub(crate) struct NotHidden; +} + +pub(crate) use self::hidden::NotHidden; +// Even though there is no `pub` of any kind, we display it because we're at the +// crate root. +use self::hidden::NotHidden as X; + +mod not_hidden { + #[doc(hidden)] + pub(crate) struct Hidden; +} + +#[doc(inline)] +pub(crate) use self::not_hidden::Hidden as Hidden2; + +//@ has 'foo/foofoo/index.html' +//@ count - '//*[@class="item-table"]/dt' 1 +//@ has - '//*[@class="item-table"]/dt/a[@href="struct.Something.html"]' 'Something' +mod foofoo { + // Since there is no `pub` of any kind, we don't display it, even if there is `doc(inline)`. + #[doc(inline)] + use crate::not_hidden::Hidden; + #[doc(inline)] + pub(crate) use crate::not_hidden::Hidden as Something; +} diff --git a/tests/rustdoc-html/inline_local/glob-private-document-private-items.rs b/tests/rustdoc-html/inline_local/glob-private-document-private-items.rs index 4ad36da843f80..a85ed41fa5ddf 100644 --- a/tests/rustdoc-html/inline_local/glob-private-document-private-items.rs +++ b/tests/rustdoc-html/inline_local/glob-private-document-private-items.rs @@ -17,25 +17,25 @@ pub use mod1::*; //@ has foo/index.html //@ hasraw - "mod1" //@ hasraw - "Mod1Public" -//@ !hasraw - "Mod1Private" -//@ !hasraw - "mod2" +//@ hasraw - "Mod1Private" +//@ hasraw - "mod2" //@ hasraw - "Mod2Public" -//@ !hasraw - "Mod2Private" +//@ hasraw - "Mod2Private" //@ has foo/struct.Mod1Public.html -//@ !has foo/struct.Mod1Private.html +//@ has foo/struct.Mod1Private.html //@ has foo/struct.Mod2Public.html -//@ !has foo/struct.Mod2Private.html +//@ has foo/struct.Mod2Private.html //@ has foo/mod1/index.html //@ hasraw - "mod2" //@ hasraw - "Mod1Public" //@ hasraw - "Mod1Private" -//@ !hasraw - "Mod2Public" -//@ !hasraw - "Mod2Private" +//@ hasraw - "Mod2Public" +//@ hasraw - "Mod2Private" //@ has foo/mod1/struct.Mod1Public.html //@ has foo/mod1/struct.Mod1Private.html -//@ !has foo/mod1/struct.Mod2Public.html -//@ !has foo/mod1/struct.Mod2Private.html +//@ has foo/mod1/struct.Mod2Public.html +//@ has foo/mod1/struct.Mod2Private.html //@ has foo/mod1/mod2/index.html //@ hasraw - "Mod2Public" @@ -43,6 +43,6 @@ pub use mod1::*; //@ has foo/mod1/mod2/struct.Mod2Public.html //@ has foo/mod1/mod2/struct.Mod2Private.html -//@ !has foo/mod2/index.html -//@ !has foo/mod2/struct.Mod2Public.html -//@ !has foo/mod2/struct.Mod2Private.html +//@ has foo/mod2/index.html +//@ has foo/mod2/struct.Mod2Public.html +//@ has foo/mod2/struct.Mod2Private.html diff --git a/tests/ui/abi/debug.generic.stderr b/tests/ui/abi/debug.generic.stderr index 6f2b69f80ae45..ba924d8401818 100644 --- a/tests/ui/abi/debug.generic.stderr +++ b/tests/ui/abi/debug.generic.stderr @@ -3,6 +3,7 @@ error: the `rustc_abi` attribute cannot be used on constants | LL | #[rustc_abi(debug)] | ^^^^^^^^^ +LL | const C: () = (); | = help: the `rustc_abi` attribute can be applied to functions and type aliases @@ -11,6 +12,7 @@ error: the `rustc_abi` attribute cannot be used on associated consts | LL | #[rustc_abi(debug)] | ^^^^^^^^^ +LL | const C: () = (); | = help: the `rustc_abi` attribute can be applied to functions and type aliases diff --git a/tests/ui/abi/debug.loongarch64.stderr b/tests/ui/abi/debug.loongarch64.stderr index 2159753e15fcd..88152aeb4f99d 100644 --- a/tests/ui/abi/debug.loongarch64.stderr +++ b/tests/ui/abi/debug.loongarch64.stderr @@ -3,6 +3,7 @@ error: the `rustc_abi` attribute cannot be used on constants | LL | #[rustc_abi(debug)] | ^^^^^^^^^ +LL | const C: () = (); | = help: the `rustc_abi` attribute can be applied to functions and type aliases @@ -11,6 +12,7 @@ error: the `rustc_abi` attribute cannot be used on associated consts | LL | #[rustc_abi(debug)] | ^^^^^^^^^ +LL | const C: () = (); | = help: the `rustc_abi` attribute can be applied to functions and type aliases diff --git a/tests/ui/abi/debug.riscv64.stderr b/tests/ui/abi/debug.riscv64.stderr index 2159753e15fcd..88152aeb4f99d 100644 --- a/tests/ui/abi/debug.riscv64.stderr +++ b/tests/ui/abi/debug.riscv64.stderr @@ -3,6 +3,7 @@ error: the `rustc_abi` attribute cannot be used on constants | LL | #[rustc_abi(debug)] | ^^^^^^^^^ +LL | const C: () = (); | = help: the `rustc_abi` attribute can be applied to functions and type aliases @@ -11,6 +12,7 @@ error: the `rustc_abi` attribute cannot be used on associated consts | LL | #[rustc_abi(debug)] | ^^^^^^^^^ +LL | const C: () = (); | = help: the `rustc_abi` attribute can be applied to functions and type aliases diff --git a/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr b/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr index dc4f03429ab45..2d33d7d23ba43 100644 --- a/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr +++ b/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr @@ -3,6 +3,8 @@ error: the `repr(simd)` attribute cannot be used on enums | LL | #[repr(simd)] | ^^^^^^^^^^ +... +LL | enum Es {} | = help: the `repr(simd)` attribute can only be applied to structs diff --git a/tests/ui/asm/naked-functions/invalid-attr.stderr b/tests/ui/asm/naked-functions/invalid-attr.stderr index aa1d2fd07d38f..b9c0c78ea8ea1 100644 --- a/tests/ui/asm/naked-functions/invalid-attr.stderr +++ b/tests/ui/asm/naked-functions/invalid-attr.stderr @@ -17,6 +17,7 @@ error: the `naked` attribute cannot be used on foreign functions | LL | #[unsafe(naked)] | ^^^^^ +LL | fn f(); | = help: the `naked` attribute can only be applied to functions with a body @@ -25,6 +26,8 @@ error: the `naked` attribute cannot be used on structs | LL | #[unsafe(naked)] | ^^^^^ +LL | #[repr(C)] +LL | struct S { | = help: the `naked` attribute can only be applied to functions @@ -33,6 +36,7 @@ error: the `naked` attribute cannot be used on struct fields | LL | #[unsafe(naked)] | ^^^^^ +LL | a: u32, | = help: the `naked` attribute can only be applied to functions @@ -41,6 +45,7 @@ error: the `naked` attribute cannot be used on required trait methods | LL | #[unsafe(naked)] | ^^^^^ +LL | extern "C" fn invoke(&self); | = help: the `naked` attribute can only be applied to functions with a body @@ -49,6 +54,7 @@ error: the `naked` attribute cannot be used on closures | LL | #[unsafe(naked)] | ^^^^^ +LL | || {}; | = help: the `naked` attribute can be applied to functions and methods diff --git a/tests/ui/asm/naked-functions/invalid-repr-attr.stderr b/tests/ui/asm/naked-functions/invalid-repr-attr.stderr index 5b9482e3297c5..755dee7bc6b88 100644 --- a/tests/ui/asm/naked-functions/invalid-repr-attr.stderr +++ b/tests/ui/asm/naked-functions/invalid-repr-attr.stderr @@ -3,6 +3,8 @@ error: the `repr(C)` attribute cannot be used on functions | LL | #[repr(C)] | ^^^^^^^ +... +LL | extern "C" fn example1() { | = help: the `repr(C)` attribute can only be applied to data types @@ -11,6 +13,8 @@ error: the `repr(transparent)` attribute cannot be used on functions | LL | #[repr(transparent)] | ^^^^^^^^^^^^^^^^^ +... +LL | extern "C" fn example2() { | = help: the `repr(transparent)` attribute can only be applied to data types @@ -19,6 +23,8 @@ error: the `repr(C)` attribute cannot be used on functions | LL | #[repr(C)] | ^^^^^^^ +... +LL | extern "C" fn example3() { | = help: the `repr(C)` attribute can only be applied to data types @@ -27,6 +33,8 @@ error: the `repr(C)` attribute cannot be used on functions | LL | #[repr(C, packed)] | ^^^^^^^^^^^^^^^ +... +LL | extern "C" fn example4() { | = help: the `repr(C)` attribute can only be applied to data types @@ -35,6 +43,8 @@ error: the `repr(packed)` attribute cannot be used on functions | LL | #[repr(C, packed)] | ^^^^^^^^^^^^^^^ +... +LL | extern "C" fn example4() { | = help: the `repr(packed)` attribute can only be applied to data types @@ -43,6 +53,8 @@ error: the `repr(u8)` attribute cannot be used on functions | LL | #[repr(u8)] | ^^^^^^^^ +... +LL | extern "C" fn example5() { | = help: the `repr(u8)` attribute can only be applied to enums diff --git a/tests/ui/attributes/align-on-fields-143987.stderr b/tests/ui/attributes/align-on-fields-143987.stderr index 86a4042c7f338..62e1cd3738c7b 100644 --- a/tests/ui/attributes/align-on-fields-143987.stderr +++ b/tests/ui/attributes/align-on-fields-143987.stderr @@ -15,6 +15,7 @@ error: the `rustc_align` attribute cannot be used on struct fields | LL | #[rustc_align(8)] | ^^^^^^^^^^^ +LL | x: usize, | = help: the `rustc_align` attribute can only be applied to functions @@ -23,6 +24,7 @@ error: the `rustc_align` attribute cannot be used on struct fields | LL | #[rustc_align(8)] | ^^^^^^^^^^^ +LL | x: usize8, | = help: the `rustc_align` attribute can only be applied to functions @@ -31,6 +33,7 @@ error: the `rustc_align` attribute cannot be used on struct fields | LL | #[rustc_align(32)] | ^^^^^^^^^^^ +LL | u32 | = help: the `rustc_align` attribute can only be applied to functions diff --git a/tests/ui/attributes/attr-on-mac-call.stderr b/tests/ui/attributes/attr-on-mac-call.stderr index b1b4112e27e2b..3f10e5720e9ee 100644 --- a/tests/ui/attributes/attr-on-mac-call.stderr +++ b/tests/ui/attributes/attr-on-mac-call.stderr @@ -3,6 +3,8 @@ error: the `sanitize` attribute cannot be used on macro calls | LL | #[sanitize(address = "off")] | ^^^^^^^^ +LL | +LL | unreachable!(); | = help: the `sanitize` attribute can be applied to crates, functions, impl blocks, modules, and statics = note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute @@ -22,6 +24,8 @@ error: the `repr(simd)` attribute cannot be used on macro calls | LL | #[repr(simd)] | ^^^^^^^^^^ +... +LL | unreachable!(); | = help: the `repr(simd)` attribute can only be applied to structs = note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute @@ -76,6 +80,8 @@ warning: the `export_name` attribute cannot be used on macro calls | LL | #[export_name = "x"] | ^^^^^^^^^^^ +... +LL | unreachable!(); | = help: the `export_name` attribute can be applied to functions and statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -91,6 +97,8 @@ warning: the `naked` attribute cannot be used on macro calls | LL | #[unsafe(naked)] | ^^^^^ +... +LL | unreachable!(); | = help: the `naked` attribute can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -101,6 +109,8 @@ warning: the `track_caller` attribute cannot be used on macro calls | LL | #[track_caller] | ^^^^^^^^^^^^ +... +LL | unreachable!(); | = help: the `track_caller` attribute can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -111,6 +121,8 @@ warning: the `used` attribute cannot be used on macro calls | LL | #[used] | ^^^^ +... +LL | unreachable!(); | = help: the `used` attribute can only be applied to statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -121,6 +133,8 @@ warning: the `target_feature` attribute cannot be used on macro calls | LL | #[target_feature(enable = "x")] | ^^^^^^^^^^^^^^ +... +LL | unreachable!(); | = help: the `target_feature` attribute can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -131,6 +145,8 @@ warning: the `deprecated` attribute cannot be used on macro calls | LL | #[deprecated] | ^^^^^^^^^^ +... +LL | unreachable!(); | = help: the `deprecated` attribute can be applied to associated consts, associated types, constants, crates, data types, enum variants, foreign statics, functions, inherent impl blocks, macro defs, modules, statics, struct fields, traits, type aliases, and use statements = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -141,6 +157,8 @@ warning: the `inline` attribute cannot be used on macro calls | LL | #[inline] | ^^^^^^ +... +LL | unreachable!(); | = help: the `inline` attribute can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -151,6 +169,8 @@ warning: the `link_name` attribute cannot be used on macro calls | LL | #[link_name = "x"] | ^^^^^^^^^ +... +LL | unreachable!(); | = help: the `link_name` attribute can be applied to foreign functions and foreign statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -161,6 +181,8 @@ warning: the `link_section` attribute cannot be used on macro calls | LL | #[link_section = "__TEXT,__text"] | ^^^^^^^^^^^^ +... +LL | unreachable!(); | = help: the `link_section` attribute can be applied to functions and statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -171,6 +193,8 @@ warning: the `link_ordinal` attribute cannot be used on macro calls | LL | #[link_ordinal(42)] | ^^^^^^^^^^^^ +... +LL | unreachable!(); | = help: the `link_ordinal` attribute can be applied to foreign functions and foreign statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -181,6 +205,8 @@ warning: the `non_exhaustive` attribute cannot be used on macro calls | LL | #[non_exhaustive] | ^^^^^^^^^^^^^^ +... +LL | unreachable!(); | = help: the `non_exhaustive` attribute can be applied to data types and enum variants = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -191,6 +217,8 @@ warning: the `proc_macro` attribute cannot be used on macro calls | LL | #[proc_macro] | ^^^^^^^^^^ +... +LL | unreachable!(); | = help: the `proc_macro` attribute can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -201,6 +229,8 @@ warning: the `cold` attribute cannot be used on macro calls | LL | #[cold] | ^^^^ +... +LL | unreachable!(); | = help: the `cold` attribute can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -211,6 +241,8 @@ warning: the `no_mangle` attribute cannot be used on macro calls | LL | #[no_mangle] | ^^^^^^^^^ +... +LL | unreachable!(); | = help: the `no_mangle` attribute can be applied to functions and statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -221,6 +253,8 @@ warning: the `deprecated` attribute cannot be used on macro calls | LL | #[deprecated] | ^^^^^^^^^^ +... +LL | unreachable!(); | = help: the `deprecated` attribute can be applied to associated consts, associated types, constants, crates, data types, enum variants, foreign statics, functions, inherent impl blocks, macro defs, modules, statics, struct fields, traits, type aliases, and use statements = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -231,6 +265,8 @@ warning: the `automatically_derived` attribute cannot be used on macro calls | LL | #[automatically_derived] | ^^^^^^^^^^^^^^^^^^^^^ +... +LL | unreachable!(); | = help: the `automatically_derived` attribute can only be applied to trait impl blocks = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -241,6 +277,8 @@ warning: the `macro_use` attribute cannot be used on macro calls | LL | #[macro_use] | ^^^^^^^^^ +... +LL | unreachable!(); | = help: the `macro_use` attribute can be applied to extern crates and modules = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -251,6 +289,8 @@ warning: the `must_use` attribute cannot be used on macro calls | LL | #[must_use] | ^^^^^^^^ +... +LL | unreachable!(); | = help: the `must_use` attribute can be applied to data types, functions, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -261,6 +301,8 @@ warning: the `no_implicit_prelude` attribute cannot be used on macro calls | LL | #[no_implicit_prelude] | ^^^^^^^^^^^^^^^^^^^ +... +LL | unreachable!(); | = help: the `no_implicit_prelude` attribute can be applied to crates and modules = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -271,6 +313,8 @@ warning: the `path` attribute cannot be used on macro calls | LL | #[path = ""] | ^^^^ +... +LL | unreachable!(); | = help: the `path` attribute can only be applied to modules = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -281,6 +325,8 @@ warning: the `ignore` attribute cannot be used on macro calls | LL | #[ignore] | ^^^^^^ +... +LL | unreachable!(); | = help: the `ignore` attribute can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -291,6 +337,8 @@ warning: the `should_panic` attribute cannot be used on macro calls | LL | #[should_panic] | ^^^^^^^^^^^^ +... +LL | unreachable!(); | = help: the `should_panic` attribute can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -301,6 +349,8 @@ warning: the `link_name` attribute cannot be used on macro calls | LL | #[link_name = "x"] | ^^^^^^^^^ +... +LL | unreachable!(); | = help: the `link_name` attribute can be applied to foreign functions and foreign statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -311,6 +361,8 @@ warning: the `repr()` attribute cannot be used on macro calls | LL | #[repr()] | ^^^^^^ +... +LL | unreachable!(); | = help: the `repr()` attribute can only be applied to data types = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -329,6 +381,8 @@ warning: the `repr(u8)` attribute cannot be used on macro calls | LL | #[repr(u8)] | ^^^^^^^^ +... +LL | unreachable!(); | = help: the `repr(u8)` attribute can only be applied to enums = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -339,6 +393,8 @@ warning: the `repr(align(...))` attribute cannot be used on macro calls | LL | #[repr(align(8))] | ^^^^^^^^^^^^^^ +... +LL | unreachable!(); | = help: the `repr(align(...))` attribute can only be applied to data types = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -349,6 +405,8 @@ warning: the `repr(packed)` attribute cannot be used on macro calls | LL | #[repr(packed)] | ^^^^^^^^^^^^ +... +LL | unreachable!(); | = help: the `repr(packed)` attribute can only be applied to data types = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -359,6 +417,8 @@ warning: the `repr(C)` attribute cannot be used on macro calls | LL | #[repr(C)] | ^^^^^^^ +... +LL | unreachable!(); | = help: the `repr(C)` attribute can only be applied to data types = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -369,6 +429,8 @@ warning: the `repr(Rust)` attribute cannot be used on macro calls | LL | #[repr(Rust)] | ^^^^^^^^^^ +... +LL | unreachable!(); | = help: the `repr(Rust)` attribute can only be applied to data types = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/attributes/attribute-on-wrong-item-inline-repr.stderr b/tests/ui/attributes/attribute-on-wrong-item-inline-repr.stderr index 3cfccf438614e..f3326cb7769b9 100644 --- a/tests/ui/attributes/attribute-on-wrong-item-inline-repr.stderr +++ b/tests/ui/attributes/attribute-on-wrong-item-inline-repr.stderr @@ -3,6 +3,7 @@ error: the `inline` attribute cannot be used on statements | LL | #[inline] | ^^^^^^ +LL | let _a = 4; | = help: the `inline` attribute can only be applied to functions @@ -32,6 +33,7 @@ error: the `inline` attribute cannot be used on statements | LL | #[inline(XYZ)] | ^^^^^^ +LL | let _b = 4; | = help: the `inline` attribute can only be applied to functions @@ -89,6 +91,7 @@ error: the `inline` attribute cannot be used on expressions | LL | #[inline(ABC)] | ^^^^^^ +LL | foo(); | = help: the `inline` attribute can only be applied to functions diff --git a/tests/ui/attributes/codegen_attr_on_required_trait_method.stderr b/tests/ui/attributes/codegen_attr_on_required_trait_method.stderr index 729231956337d..3ed0d6847bb82 100644 --- a/tests/ui/attributes/codegen_attr_on_required_trait_method.stderr +++ b/tests/ui/attributes/codegen_attr_on_required_trait_method.stderr @@ -3,6 +3,8 @@ error: the `linkage` attribute cannot be used on required trait methods | LL | #[linkage = "weak"] | ^^^^^^^ +LL | +LL | fn method3(&self); | = help: the `linkage` attribute can be applied to foreign functions, foreign statics, functions with a body, and statics @@ -11,6 +13,8 @@ error: the `cold` attribute cannot be used on required trait methods | LL | #[cold] | ^^^^ +... +LL | fn method1(&self); | = help: the `cold` attribute can be applied to foreign functions and functions with a body = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -25,6 +29,8 @@ error: the `link_section` attribute cannot be used on required trait methods | LL | #[link_section = "__TEXT,__text"] | ^^^^^^^^^^^^ +... +LL | fn method2(&self); | = help: the `link_section` attribute can be applied to functions with a body and statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/attributes/cold-attribute-application-54044.stderr b/tests/ui/attributes/cold-attribute-application-54044.stderr index f73fd19425781..b9066eb1055a7 100644 --- a/tests/ui/attributes/cold-attribute-application-54044.stderr +++ b/tests/ui/attributes/cold-attribute-application-54044.stderr @@ -3,6 +3,8 @@ error: the `cold` attribute cannot be used on structs | LL | #[cold] | ^^^^ +... +LL | struct Foo; | = help: the `cold` attribute can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -17,6 +19,8 @@ error: the `cold` attribute cannot be used on expressions | LL | #[cold] | ^^^^ +... +LL | 5; | = help: the `cold` attribute can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/attributes/collapse-debuginfo-invalid.stderr b/tests/ui/attributes/collapse-debuginfo-invalid.stderr index e0b176f4ff141..c67a1b75d7632 100644 --- a/tests/ui/attributes/collapse-debuginfo-invalid.stderr +++ b/tests/ui/attributes/collapse-debuginfo-invalid.stderr @@ -3,6 +3,8 @@ error: the `collapse_debuginfo` attribute cannot be used on extern crates | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | extern crate std; | = help: the `collapse_debuginfo` attribute can only be applied to macro defs @@ -11,6 +13,8 @@ error: the `collapse_debuginfo` attribute cannot be used on use statements | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | use std::collections::HashMap; | = help: the `collapse_debuginfo` attribute can only be applied to macro defs @@ -19,6 +23,8 @@ error: the `collapse_debuginfo` attribute cannot be used on statics | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | static FOO: u32 = 3; | = help: the `collapse_debuginfo` attribute can only be applied to macro defs @@ -27,6 +33,8 @@ error: the `collapse_debuginfo` attribute cannot be used on constants | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | const BAR: u32 = 3; | = help: the `collapse_debuginfo` attribute can only be applied to macro defs @@ -35,6 +43,8 @@ error: the `collapse_debuginfo` attribute cannot be used on functions | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | fn foo() { | = help: the `collapse_debuginfo` attribute can only be applied to macro defs @@ -51,6 +61,8 @@ error: the `collapse_debuginfo` attribute cannot be used on statements | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | let _ = 3; | = help: the `collapse_debuginfo` attribute can only be applied to macro defs @@ -67,6 +79,8 @@ error: the `collapse_debuginfo` attribute cannot be used on match arms | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | _ => (), | = help: the `collapse_debuginfo` attribute can only be applied to macro defs @@ -75,6 +89,8 @@ error: the `collapse_debuginfo` attribute cannot be used on modules | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | mod bar { | = help: the `collapse_debuginfo` attribute can only be applied to macro defs @@ -83,6 +99,8 @@ error: the `collapse_debuginfo` attribute cannot be used on type aliases | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | type Map = HashMap; | = help: the `collapse_debuginfo` attribute can only be applied to macro defs @@ -91,6 +109,8 @@ error: the `collapse_debuginfo` attribute cannot be used on enums | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | enum Foo { | = help: the `collapse_debuginfo` attribute can only be applied to macro defs @@ -99,6 +119,8 @@ error: the `collapse_debuginfo` attribute cannot be used on enum variants | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | Variant, | = help: the `collapse_debuginfo` attribute can only be applied to macro defs @@ -107,6 +129,8 @@ error: the `collapse_debuginfo` attribute cannot be used on structs | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | struct Bar { | = help: the `collapse_debuginfo` attribute can only be applied to macro defs @@ -115,6 +139,8 @@ error: the `collapse_debuginfo` attribute cannot be used on struct fields | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | field: u32, | = help: the `collapse_debuginfo` attribute can only be applied to macro defs @@ -123,6 +149,8 @@ error: the `collapse_debuginfo` attribute cannot be used on unions | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | union Qux { | = help: the `collapse_debuginfo` attribute can only be applied to macro defs @@ -131,6 +159,8 @@ error: the `collapse_debuginfo` attribute cannot be used on traits | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | trait Foobar { | = help: the `collapse_debuginfo` attribute can only be applied to macro defs @@ -139,6 +169,8 @@ error: the `collapse_debuginfo` attribute cannot be used on associated types | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | type Bar; | = help: the `collapse_debuginfo` attribute can only be applied to macro defs @@ -147,6 +179,8 @@ error: the `collapse_debuginfo` attribute cannot be used on type aliases | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | type AFoobar = impl Foobar; | = help: the `collapse_debuginfo` attribute can only be applied to macro defs @@ -155,6 +189,8 @@ error: the `collapse_debuginfo` attribute cannot be used on inherent impl blocks | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | impl Bar { | = help: the `collapse_debuginfo` attribute can only be applied to macro defs @@ -163,6 +199,8 @@ error: the `collapse_debuginfo` attribute cannot be used on associated consts | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | const FOO: u32 = 3; | = help: the `collapse_debuginfo` attribute can only be applied to macro defs @@ -171,6 +209,8 @@ error: the `collapse_debuginfo` attribute cannot be used on inherent methods | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | fn bar(&self) {} | = help: the `collapse_debuginfo` attribute can only be applied to macro defs diff --git a/tests/ui/attributes/const-stability-on-macro.stderr b/tests/ui/attributes/const-stability-on-macro.stderr index 798fce7b0c7a6..b8834c828dcf9 100644 --- a/tests/ui/attributes/const-stability-on-macro.stderr +++ b/tests/ui/attributes/const-stability-on-macro.stderr @@ -3,6 +3,8 @@ error: the `rustc_const_stable` attribute cannot be used on macro defs | LL | #[rustc_const_stable(feature = "foo", since = "3.3.3")] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | macro_rules! foo { | = help: the `rustc_const_stable` attribute can be applied to associated consts, constants, crates, functions, impl blocks, statics, traits, and use statements @@ -11,6 +13,8 @@ error: the `rustc_const_unstable` attribute cannot be used on macro defs | LL | #[rustc_const_unstable(feature = "bar", issue = "none")] | ^^^^^^^^^^^^^^^^^^^^ +LL | +LL | macro_rules! bar { | = help: the `rustc_const_unstable` attribute can be applied to associated consts, constants, crates, functions, impl blocks, statics, traits, and use statements diff --git a/tests/ui/attributes/empty-repr.stderr b/tests/ui/attributes/empty-repr.stderr index 332c065f55ace..c03804fd0a80a 100644 --- a/tests/ui/attributes/empty-repr.stderr +++ b/tests/ui/attributes/empty-repr.stderr @@ -3,6 +3,8 @@ error: the `repr()` attribute cannot be used on where predicates | LL | #[repr()] | ^^^^^^ +... +LL | (): Sized { | = help: the `repr()` attribute can only be applied to data types diff --git a/tests/ui/attributes/export/exportable.binary.stderr b/tests/ui/attributes/export/exportable.binary.stderr index 001be57c9e668..ac82e8b3d7350 100644 --- a/tests/ui/attributes/export/exportable.binary.stderr +++ b/tests/ui/attributes/export/exportable.binary.stderr @@ -3,6 +3,8 @@ error: the `export_stable` attribute cannot be used on traits | LL | #[export_stable] | ^^^^^^^^^^^^^ +LL | +LL | pub trait Trait {} | = help: the `export_stable` attribute can be applied to associated types, data types, functions, inherent impl blocks, modules, type aliases, and use statements @@ -11,6 +13,8 @@ error: the `export_stable` attribute cannot be used on constants | LL | #[export_stable] | ^^^^^^^^^^^^^ +LL | +LL | pub const C: i32 = 0; | = help: the `export_stable` attribute can be applied to associated types, data types, functions, inherent impl blocks, modules, type aliases, and use statements diff --git a/tests/ui/attributes/export/exportable.sdylib.stderr b/tests/ui/attributes/export/exportable.sdylib.stderr index cbcda3da3782c..ef911f0ddcefc 100644 --- a/tests/ui/attributes/export/exportable.sdylib.stderr +++ b/tests/ui/attributes/export/exportable.sdylib.stderr @@ -3,6 +3,8 @@ error: the `export_stable` attribute cannot be used on traits | LL | #[export_stable] | ^^^^^^^^^^^^^ +LL | +LL | pub trait Trait {} | = help: the `export_stable` attribute can be applied to associated types, data types, functions, inherent impl blocks, modules, type aliases, and use statements @@ -11,6 +13,8 @@ error: the `export_stable` attribute cannot be used on constants | LL | #[export_stable] | ^^^^^^^^^^^^^ +LL | +LL | pub const C: i32 = 0; | = help: the `export_stable` attribute can be applied to associated types, data types, functions, inherent impl blocks, modules, type aliases, and use statements diff --git a/tests/ui/attributes/inline-attribute-enum-variant-error.stderr b/tests/ui/attributes/inline-attribute-enum-variant-error.stderr index cdbdee11171d5..9064b5cf514cf 100644 --- a/tests/ui/attributes/inline-attribute-enum-variant-error.stderr +++ b/tests/ui/attributes/inline-attribute-enum-variant-error.stderr @@ -3,6 +3,8 @@ error: the `inline` attribute cannot be used on enum variants | LL | #[inline] | ^^^^^^ +LL | +LL | Variant, | = help: the `inline` attribute can only be applied to functions diff --git a/tests/ui/attributes/inline/attr-usage-inline.stderr b/tests/ui/attributes/inline/attr-usage-inline.stderr index 86eede74eeb99..1725de213e631 100644 --- a/tests/ui/attributes/inline/attr-usage-inline.stderr +++ b/tests/ui/attributes/inline/attr-usage-inline.stderr @@ -3,6 +3,7 @@ error: the `inline` attribute cannot be used on structs | LL | #[inline] | ^^^^^^ +LL | struct S; | = help: the `inline` attribute can only be applied to functions @@ -17,6 +18,8 @@ warning: the `inline` attribute cannot be used on struct fields | LL | #[inline] | ^^^^^^ +... +LL | i: u8, | = help: the `inline` attribute can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -27,6 +30,8 @@ warning: the `inline` attribute cannot be used on macro defs | LL | #[inline] | ^^^^^^ +... +LL | macro_rules! m_e { | = help: the `inline` attribute can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -36,6 +41,8 @@ warning: the `inline` attribute cannot be used on macro defs | LL | #[inline] | ^^^^^^ +... +LL | macro_rules! m { | = help: the `inline` attribute can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/attributes/instrument_fn.stderr b/tests/ui/attributes/instrument_fn.stderr index c6d0887fcd9fa..1b4acad3c616d 100644 --- a/tests/ui/attributes/instrument_fn.stderr +++ b/tests/ui/attributes/instrument_fn.stderr @@ -31,6 +31,7 @@ error: the `instrument_fn` attribute cannot be used on structs | LL | #[instrument_fn = "on"] | ^^^^^^^^^^^^^ +LL | struct F; | = help: the `instrument_fn` attribute can only be applied to functions @@ -39,6 +40,7 @@ error: the `instrument_fn` attribute cannot be used on modules | LL | #[instrument_fn = "on"] | ^^^^^^^^^^^^^ +LL | mod module {} | = help: the `instrument_fn` attribute can only be applied to functions @@ -47,6 +49,7 @@ error: the `instrument_fn` attribute cannot be used on inherent impl blocks | LL | #[instrument_fn = "on"] | ^^^^^^^^^^^^^ +LL | impl F { | = help: the `instrument_fn` attribute can only be applied to functions @@ -55,6 +58,8 @@ error: the `instrument_fn` attribute cannot be used on expressions | LL | #[instrument_fn = "off"] | ^^^^^^^^^^^^^ +LL | +LL | x * 2 | = help: the `instrument_fn` attribute can only be applied to functions @@ -63,6 +68,7 @@ error: the `instrument_fn` attribute cannot be used on traits | LL | #[instrument_fn = "off"] | ^^^^^^^^^^^^^ +LL | trait Foo { | = help: the `instrument_fn` attribute can only be applied to functions @@ -71,6 +77,7 @@ error: the `instrument_fn` attribute cannot be used on required trait methods | LL | #[instrument_fn = "off"] | ^^^^^^^^^^^^^ +LL | fn bar(); | = help: the `instrument_fn` attribute can only be applied to functions with a body @@ -118,6 +125,7 @@ error: the `instrument_fn` attribute cannot be used on closures | LL | let _x = #[instrument_fn = "on"] | ^^^^^^^^^^^^^ +LL | || {}; | = help: the `instrument_fn` attribute can be applied to functions and methods diff --git a/tests/ui/attributes/invalid-debugger-visualizer-target.stderr b/tests/ui/attributes/invalid-debugger-visualizer-target.stderr index 7fca9819908bd..231381a1c902a 100644 --- a/tests/ui/attributes/invalid-debugger-visualizer-target.stderr +++ b/tests/ui/attributes/invalid-debugger-visualizer-target.stderr @@ -3,6 +3,8 @@ error: the `debugger_visualizer` attribute cannot be used on functions | LL | #[debugger_visualizer(natvis_file = "./foo.natvis.xml")] | ^^^^^^^^^^^^^^^^^^^ +LL | +LL | fn main() {} | = help: the `debugger_visualizer` attribute can be applied to crates and modules diff --git a/tests/ui/attributes/invalid-repr.stderr b/tests/ui/attributes/invalid-repr.stderr index ef442f1c1f65f..53ddff27e5fe8 100644 --- a/tests/ui/attributes/invalid-repr.stderr +++ b/tests/ui/attributes/invalid-repr.stderr @@ -3,6 +3,8 @@ error: the `repr(align(...))` attribute cannot be used on type aliases | LL | #[repr(align(16))] | ^^^^^^^^^^^^^^^ +LL | +LL | pub type Foo = i32; | = help: the `repr(align(...))` attribute can only be applied to data types diff --git a/tests/ui/attributes/issue-105594-invalid-attr-validation.stderr b/tests/ui/attributes/issue-105594-invalid-attr-validation.stderr index 2e6e7537bd625..9fabdd7e94b9b 100644 --- a/tests/ui/attributes/issue-105594-invalid-attr-validation.stderr +++ b/tests/ui/attributes/issue-105594-invalid-attr-validation.stderr @@ -3,6 +3,7 @@ error: the `track_caller` attribute cannot be used on statics | LL | #[track_caller] | ^^^^^^^^^^^^ +LL | static _A: () = panic!(); | = help: the `track_caller` attribute can only be applied to functions diff --git a/tests/ui/attributes/link-name-on-static.stderr b/tests/ui/attributes/link-name-on-static.stderr index 2d768acd51bfb..ea63fc5fc89b7 100644 --- a/tests/ui/attributes/link-name-on-static.stderr +++ b/tests/ui/attributes/link-name-on-static.stderr @@ -11,6 +11,8 @@ warning: the `link_name` attribute cannot be used on statics | LL | #[link_name = "VALUE"] | ^^^^^^^^^ +... +LL | static VALUE_DEFINITION: u8 = 0; | = help: the `link_name` attribute can be applied to foreign functions and foreign statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -26,6 +28,8 @@ warning: the `link_name` attribute cannot be used on statics | LL | #[unsafe(link_name = "UNSAFE_VALUE")] | ^^^^^^^^^ +... +LL | static UNSAFE_VALUE_DEFINITION: u8 = 0; | = help: the `link_name` attribute can be applied to foreign functions and foreign statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/attributes/linkage.stderr b/tests/ui/attributes/linkage.stderr index 11a5e7fdfde83..92609e274474a 100644 --- a/tests/ui/attributes/linkage.stderr +++ b/tests/ui/attributes/linkage.stderr @@ -3,6 +3,7 @@ error: the `linkage` attribute cannot be used on type aliases | LL | #[linkage = "weak"] | ^^^^^^^ +LL | type InvalidTy = (); | = help: the `linkage` attribute can be applied to foreign statics, functions, and statics @@ -11,6 +12,7 @@ error: the `linkage` attribute cannot be used on modules | LL | #[linkage = "weak"] | ^^^^^^^ +LL | mod invalid_module {} | = help: the `linkage` attribute can be applied to foreign statics, functions, and statics @@ -19,6 +21,7 @@ error: the `linkage` attribute cannot be used on structs | LL | #[linkage = "weak"] | ^^^^^^^ +LL | struct F; | = help: the `linkage` attribute can be applied to foreign statics, functions, and statics @@ -27,6 +30,7 @@ error: the `linkage` attribute cannot be used on inherent impl blocks | LL | #[linkage = "weak"] | ^^^^^^^ +LL | impl F { | = help: the `linkage` attribute can be applied to foreign statics, functions, and statics @@ -35,6 +39,7 @@ error: the `linkage` attribute cannot be used on expressions | LL | #[linkage = "weak"] | ^^^^^^^ +LL | { | = help: the `linkage` attribute can be applied to foreign statics, functions, and statics @@ -43,6 +48,7 @@ error: the `linkage` attribute cannot be used on closures | LL | let _ = #[linkage = "weak"] | ^^^^^^^ +LL | (|| 1); | = help: the `linkage` attribute can be applied to foreign functions, foreign statics, functions, methods, and statics diff --git a/tests/ui/attributes/malformed-attrs.stderr b/tests/ui/attributes/malformed-attrs.stderr index e2c56722b1311..4eddd0e7bf85a 100644 --- a/tests/ui/attributes/malformed-attrs.stderr +++ b/tests/ui/attributes/malformed-attrs.stderr @@ -99,6 +99,8 @@ error: the `rustc_confusables` attribute cannot be used on functions | LL | #[rustc_confusables] | ^^^^^^^^^^^^^^^^^ +... +LL | fn test() { | = help: the `rustc_confusables` attribute can only be applied to inherent methods @@ -130,6 +132,8 @@ error: the `rustc_macro_transparency` attribute cannot be used on functions | LL | #[rustc_macro_transparency] | ^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | fn test() { | = help: the `rustc_macro_transparency` attribute can only be applied to macro defs @@ -330,6 +334,8 @@ error: the `used` attribute cannot be used on functions | LL | #[used()] | ^^^^ +... +LL | fn test() { | = help: the `used` attribute can only be applied to statics @@ -901,6 +907,8 @@ warning: the `link` attribute cannot be used on functions | LL | #[link] | ^^^^ +... +LL | fn test() { | = help: the `link` attribute can only be applied to foreign modules = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -910,6 +918,8 @@ warning: the `link_name` attribute cannot be used on functions | LL | #[link_name] | ^^^^^^^^^ +... +LL | fn test() { | = help: the `link_name` attribute can be applied to foreign functions and foreign statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -928,6 +938,8 @@ warning: the `no_implicit_prelude` attribute cannot be used on functions | LL | #[no_implicit_prelude = 23] | ^^^^^^^^^^^^^^^^^^^ +... +LL | fn test() { | = help: the `no_implicit_prelude` attribute can be applied to crates and modules = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -960,6 +972,8 @@ warning: the `automatically_derived` attribute cannot be used on modules | LL | #[automatically_derived = 18] | ^^^^^^^^^^^^^^^^^^^^^ +... +LL | mod yooo { | = help: the `automatically_derived` attribute can only be applied to trait impl blocks = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/attributes/malformed-fn-align.stderr b/tests/ui/attributes/malformed-fn-align.stderr index 48d6676f5a7e4..4a13695323df3 100644 --- a/tests/ui/attributes/malformed-fn-align.stderr +++ b/tests/ui/attributes/malformed-fn-align.stderr @@ -54,6 +54,7 @@ error: the `repr(align(...))` attribute cannot be used on functions | LL | #[repr(align(16))] | ^^^^^^^^^^^^^^^ +LL | fn f4() {} | = help: the `repr(align(...))` attribute can only be applied to data types = help: use `#[rustc_align(...)]` instead @@ -101,6 +102,7 @@ error: the `rustc_align` attribute cannot be used on structs | LL | #[rustc_align(16)] | ^^^^^^^^^^^ +LL | struct S1; | = help: the `rustc_align` attribute can only be applied to functions @@ -109,6 +111,7 @@ error: the `rustc_align` attribute cannot be used on constants | LL | #[rustc_align(32)] | ^^^^^^^^^^^ +LL | const FOO: i32 = 42; | = help: the `rustc_align` attribute can only be applied to functions @@ -117,6 +120,7 @@ error: the `rustc_align` attribute cannot be used on modules | LL | #[rustc_align(32)] | ^^^^^^^^^^^ +LL | mod test {} | = help: the `rustc_align` attribute can only be applied to functions @@ -125,6 +129,7 @@ error: the `rustc_align` attribute cannot be used on use statements | LL | #[rustc_align(32)] | ^^^^^^^^^^^ +LL | use ::std::iter; | = help: the `rustc_align` attribute can only be applied to functions diff --git a/tests/ui/attributes/malformed-static-align.stderr b/tests/ui/attributes/malformed-static-align.stderr index 6363cbcd31882..bdc44692635f5 100644 --- a/tests/ui/attributes/malformed-static-align.stderr +++ b/tests/ui/attributes/malformed-static-align.stderr @@ -29,6 +29,7 @@ error: the `repr(align(...))` attribute cannot be used on statics | LL | #[repr(align(16))] | ^^^^^^^^^^^^^^^ +LL | static S4: () = (); | = help: the `repr(align(...))` attribute can only be applied to data types = help: use `#[rustc_align_static(...)]` instead @@ -38,6 +39,7 @@ error: the `rustc_align_static` attribute cannot be used on structs | LL | #[rustc_align_static(16)] | ^^^^^^^^^^^^^^^^^^ +LL | struct Struct1; | = help: the `rustc_align_static` attribute can be applied to foreign statics and statics diff --git a/tests/ui/attributes/may_dangle.stderr b/tests/ui/attributes/may_dangle.stderr index 5f560003a2238..fc6f91334d310 100644 --- a/tests/ui/attributes/may_dangle.stderr +++ b/tests/ui/attributes/may_dangle.stderr @@ -11,6 +11,7 @@ error: the `may_dangle` attribute cannot be used on structs | LL | #[may_dangle] | ^^^^^^^^^^ +LL | struct Dangling; | = help: the `may_dangle` attribute can be applied to lifetime parameters and type parameters @@ -19,6 +20,7 @@ error: the `may_dangle` attribute cannot be used on trait impl blocks | LL | #[may_dangle] | ^^^^^^^^^^ +LL | impl NotDrop for () { | = help: the `may_dangle` attribute can be applied to lifetime parameters and type parameters @@ -27,6 +29,7 @@ error: the `may_dangle` attribute cannot be used on functions | LL | #[may_dangle] | ^^^^^^^^^^ +LL | fn main() { | = help: the `may_dangle` attribute can be applied to lifetime parameters and type parameters @@ -35,6 +38,7 @@ error: the `may_dangle` attribute cannot be used on statements | LL | #[may_dangle] | ^^^^^^^^^^ +LL | let () = (); | = help: the `may_dangle` attribute can be applied to lifetime parameters and type parameters diff --git a/tests/ui/attributes/multiple-invalid.stderr b/tests/ui/attributes/multiple-invalid.stderr index 4c5fa82727489..9668586b6486c 100644 --- a/tests/ui/attributes/multiple-invalid.stderr +++ b/tests/ui/attributes/multiple-invalid.stderr @@ -3,6 +3,8 @@ error: the `inline` attribute cannot be used on constants | LL | #[inline] | ^^^^^^ +... +LL | const FOO: u8 = 0; | = help: the `inline` attribute can only be applied to functions @@ -11,6 +13,8 @@ error: the `target_feature` attribute cannot be used on constants | LL | #[target_feature(enable = "sse2")] | ^^^^^^^^^^^^^^ +LL | +LL | const FOO: u8 = 0; | = help: the `target_feature` attribute can only be applied to functions diff --git a/tests/ui/attributes/optimize.stderr b/tests/ui/attributes/optimize.stderr index 5c9ab33a6e590..d35b43b86c1bb 100644 --- a/tests/ui/attributes/optimize.stderr +++ b/tests/ui/attributes/optimize.stderr @@ -3,6 +3,7 @@ error: the `optimize` attribute cannot be used on structs | LL | #[optimize(speed)] | ^^^^^^^^ +LL | struct F; | = help: the `optimize` attribute can only be applied to functions @@ -11,6 +12,7 @@ error: the `optimize` attribute cannot be used on expressions | LL | #[optimize(speed)] | ^^^^^^^^ +LL | { | = help: the `optimize` attribute can only be applied to functions @@ -19,6 +21,7 @@ error: the `optimize` attribute cannot be used on modules | LL | #[optimize(speed)] | ^^^^^^^^ +LL | mod valid_module {} | = help: the `optimize` attribute can only be applied to functions @@ -27,6 +30,7 @@ error: the `optimize` attribute cannot be used on inherent impl blocks | LL | #[optimize(speed)] | ^^^^^^^^ +LL | impl F {} | = help: the `optimize` attribute can only be applied to functions @@ -35,6 +39,7 @@ error: the `optimize` attribute cannot be used on required trait methods | LL | #[optimize(speed)] | ^^^^^^^^ +LL | fn invalid(); | = help: the `optimize` attribute can only be applied to functions with a body diff --git a/tests/ui/attributes/pass-indirectly.stderr b/tests/ui/attributes/pass-indirectly.stderr index 9b84bc3091cc3..cba60586dc4e9 100644 --- a/tests/ui/attributes/pass-indirectly.stderr +++ b/tests/ui/attributes/pass-indirectly.stderr @@ -3,6 +3,8 @@ error: the `rustc_pass_indirectly_in_non_rustic_abis` attribute cannot be used o | LL | #[rustc_pass_indirectly_in_non_rustic_abis] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | fn not_a_struct() {} | = help: the `rustc_pass_indirectly_in_non_rustic_abis` attribute can only be applied to structs diff --git a/tests/ui/attributes/positions/link-section.stderr b/tests/ui/attributes/positions/link-section.stderr index 56aa525e72387..6d1e81932b857 100644 --- a/tests/ui/attributes/positions/link-section.stderr +++ b/tests/ui/attributes/positions/link-section.stderr @@ -3,6 +3,8 @@ warning: the `link_section` attribute cannot be used on foreign statics | LL | #[unsafe(link_section = "__DATA,__buffer")] | ^^^^^^^^^^^^ +LL | +LL | pub static mut a: [u8; 1024]; | = help: the `link_section` attribute can be applied to functions and statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/attributes/positions/used.stderr b/tests/ui/attributes/positions/used.stderr index dceba0253c1d3..5487572b6b515 100644 --- a/tests/ui/attributes/positions/used.stderr +++ b/tests/ui/attributes/positions/used.stderr @@ -3,6 +3,7 @@ error: the `used` attribute cannot be used on functions | LL | #[used] | ^^^^ +LL | fn foo() {} | = help: the `used` attribute can only be applied to statics @@ -11,6 +12,7 @@ error: the `used` attribute cannot be used on structs | LL | #[used] | ^^^^ +LL | struct Foo {} | = help: the `used` attribute can only be applied to statics @@ -19,6 +21,7 @@ error: the `used` attribute cannot be used on traits | LL | #[used] | ^^^^ +LL | trait Bar {} | = help: the `used` attribute can only be applied to statics @@ -27,6 +30,7 @@ error: the `used` attribute cannot be used on trait impl blocks | LL | #[used] | ^^^^ +LL | impl Bar for Foo {} | = help: the `used` attribute can only be applied to statics @@ -35,6 +39,7 @@ error: the `used` attribute cannot be used on foreign statics | LL | #[used] | ^^^^ +LL | static BAR: i32; | = help: the `used` attribute can only be applied to statics diff --git a/tests/ui/attributes/repr-align-in-trait-issue-132391.stderr b/tests/ui/attributes/repr-align-in-trait-issue-132391.stderr index 5f7e923b390b1..3f39b318dc620 100644 --- a/tests/ui/attributes/repr-align-in-trait-issue-132391.stderr +++ b/tests/ui/attributes/repr-align-in-trait-issue-132391.stderr @@ -3,6 +3,8 @@ error: the `repr(align(...))` attribute cannot be used on required trait methods | LL | #[repr(align)] | ^^^^^^^^^^^ +... +LL | fn myfun(); | = help: the `repr(align(...))` attribute can only be applied to data types diff --git a/tests/ui/attributes/rustc_confusables.stderr b/tests/ui/attributes/rustc_confusables.stderr index cbf59cd8c1cd1..468c61e4a4146 100644 --- a/tests/ui/attributes/rustc_confusables.stderr +++ b/tests/ui/attributes/rustc_confusables.stderr @@ -34,6 +34,8 @@ error: the `rustc_confusables` attribute cannot be used on functions | LL | #[rustc_confusables("blah")] | ^^^^^^^^^^^^^^^^^ +... +LL | fn not_inherent_impl_method() {} | = help: the `rustc_confusables` attribute can only be applied to inherent methods diff --git a/tests/ui/attributes/rustc_skip_during_method_dispatch.stderr b/tests/ui/attributes/rustc_skip_during_method_dispatch.stderr index 3f59d24865c81..b77a054327133 100644 --- a/tests/ui/attributes/rustc_skip_during_method_dispatch.stderr +++ b/tests/ui/attributes/rustc_skip_during_method_dispatch.stderr @@ -96,6 +96,8 @@ error: the `rustc_skip_during_method_dispatch` attribute cannot be used on trait | LL | #[rustc_skip_during_method_dispatch(array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | impl OK for () {} | = help: the `rustc_skip_during_method_dispatch` attribute can only be applied to traits diff --git a/tests/ui/coercion/fudge-inference/closure-input-in-fn-ptr-arg-162109.rs b/tests/ui/coercion/fudge-inference/closure-input-in-fn-ptr-arg-162109.rs new file mode 100644 index 0000000000000..3a7faeb4ac4e0 --- /dev/null +++ b/tests/ui/coercion/fudge-inference/closure-input-in-fn-ptr-arg-162109.rs @@ -0,0 +1,18 @@ +//@ revisions: current next +//@ ignore-compare-mode-next-solver (explicit revisions) +//@[next] compile-flags: -Znext-solver +//@ check-pass + +// A regression test for https://github.com/rust-lang/rust/issues/162109. + +struct Foo(I, fn(I) -> O); + +impl Foo { + fn new(_: I, _: fn(I) -> O) -> Self { + loop {} + } +} + +fn main() { + let _: Foo<_, u8> = Foo::new(&1u8, |input| *input); +} diff --git a/tests/ui/comptime/comptime_closure.stderr b/tests/ui/comptime/comptime_closure.stderr index 71445e033ff1e..8ea1ae3f982c1 100644 --- a/tests/ui/comptime/comptime_closure.stderr +++ b/tests/ui/comptime/comptime_closure.stderr @@ -3,6 +3,8 @@ error: the `rustc_comptime` attribute cannot be used on closures | LL | let f = #[rustc_comptime] | ^^^^^^^^^^^^^^ +LL | +LL | || (); | = help: the `rustc_comptime` attribute can be applied to functions, inherent impl blocks, and inherent methods diff --git a/tests/ui/comptime/comptime_impl.stderr b/tests/ui/comptime/comptime_impl.stderr index 4c55736c0bb63..dbc1e5191267f 100644 --- a/tests/ui/comptime/comptime_impl.stderr +++ b/tests/ui/comptime/comptime_impl.stderr @@ -3,6 +3,8 @@ error: the `rustc_comptime` attribute cannot be used on trait impl blocks | LL | #[rustc_comptime] | ^^^^^^^^^^^^^^ +LL | +LL | impl Foo for Bar { | = help: the `rustc_comptime` attribute can be applied to functions and inherent impl blocks diff --git a/tests/ui/comptime/comptime_trait.stderr b/tests/ui/comptime/comptime_trait.stderr index 71fa410608405..e043d3866aa8b 100644 --- a/tests/ui/comptime/comptime_trait.stderr +++ b/tests/ui/comptime/comptime_trait.stderr @@ -3,6 +3,8 @@ error: the `rustc_comptime` attribute cannot be used on traits | LL | #[rustc_comptime] | ^^^^^^^^^^^^^^ +LL | +LL | trait Trait { | = help: the `rustc_comptime` attribute can be applied to functions and inherent impl blocks @@ -11,6 +13,8 @@ error: the `rustc_comptime` attribute cannot be used on trait impl blocks | LL | #[rustc_comptime] | ^^^^^^^^^^^^^^ +LL | +LL | impl Trait for u32 { | = help: the `rustc_comptime` attribute can be applied to functions and inherent impl blocks @@ -19,6 +23,8 @@ error: the `rustc_comptime` attribute cannot be used on trait aliases | LL | #[rustc_comptime] | ^^^^^^^^^^^^^^ +LL | +LL | trait TraitAlias = const Trait; | = help: the `rustc_comptime` attribute can be applied to functions and inherent impl blocks diff --git a/tests/ui/comptime/trait_comptime.stderr b/tests/ui/comptime/trait_comptime.stderr index 2411ebe70759b..92e5c480e2622 100644 --- a/tests/ui/comptime/trait_comptime.stderr +++ b/tests/ui/comptime/trait_comptime.stderr @@ -3,6 +3,8 @@ error: the `rustc_comptime` attribute cannot be used on required trait methods | LL | #[rustc_comptime] | ^^^^^^^^^^^^^^ +LL | +LL | fn foo(); | = help: the `rustc_comptime` attribute can be applied to functions with a body and inherent impl blocks @@ -11,6 +13,8 @@ error: the `rustc_comptime` attribute cannot be used on provided trait methods | LL | #[rustc_comptime] | ^^^^^^^^^^^^^^ +LL | +LL | fn bar() {} | = help: the `rustc_comptime` attribute can be applied to functions, inherent impl blocks, and inherent methods @@ -19,6 +23,8 @@ error: the `rustc_comptime` attribute cannot be used on trait methods in impl bl | LL | #[rustc_comptime] | ^^^^^^^^^^^^^^ +LL | +LL | fn foo() {} | = help: the `rustc_comptime` attribute can be applied to functions, inherent impl blocks, and inherent methods diff --git a/tests/ui/conditional-compilation/cfg-attr-parsed-span-issue-154801.stderr b/tests/ui/conditional-compilation/cfg-attr-parsed-span-issue-154801.stderr index 70e9698950e1a..132afcc6ef02f 100644 --- a/tests/ui/conditional-compilation/cfg-attr-parsed-span-issue-154801.stderr +++ b/tests/ui/conditional-compilation/cfg-attr-parsed-span-issue-154801.stderr @@ -16,6 +16,7 @@ error: the `inline` attribute cannot be used on expressions | LL | #[inline] | ^^^^^^ +LL | _x | = help: the `inline` attribute can only be applied to functions diff --git a/tests/ui/conditional-compilation/cfg_attr-attr-syntax-validation.stderr b/tests/ui/conditional-compilation/cfg_attr-attr-syntax-validation.stderr index 048affd1c4191..fe8e7c31a9494 100644 --- a/tests/ui/conditional-compilation/cfg_attr-attr-syntax-validation.stderr +++ b/tests/ui/conditional-compilation/cfg_attr-attr-syntax-validation.stderr @@ -193,6 +193,8 @@ warning: the `link_section` attribute cannot be used on structs | LL | #[cfg_attr(true, link_section)] | ^^^^^^^^^^^^ +... +LL | struct S13; | = help: the `link_section` attribute can be applied to functions and statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/const-generics/invalid-rustc_legacy_const_generics-arguments.stderr b/tests/ui/const-generics/invalid-rustc_legacy_const_generics-arguments.stderr index 4b5a14017f62f..b3a9ce3501a5a 100644 --- a/tests/ui/const-generics/invalid-rustc_legacy_const_generics-arguments.stderr +++ b/tests/ui/const-generics/invalid-rustc_legacy_const_generics-arguments.stderr @@ -65,6 +65,7 @@ error: the `rustc_legacy_const_generics` attribute cannot be used on structs | LL | #[rustc_legacy_const_generics(0)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | struct S; | = help: the `rustc_legacy_const_generics` attribute can only be applied to functions @@ -95,6 +96,7 @@ error: the `rustc_legacy_const_generics` attribute cannot be used on foreign fun | LL | #[rustc_legacy_const_generics(1)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | fn foo7(); | = help: the `rustc_legacy_const_generics` attribute can only be applied to functions @@ -111,6 +113,7 @@ error: the `rustc_legacy_const_generics` attribute cannot be used on inherent me | LL | #[rustc_legacy_const_generics(0)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | fn foo9() {} | = help: the `rustc_legacy_const_generics` attribute can only be applied to functions diff --git a/tests/ui/coroutine/invalid_attr_usage.stderr b/tests/ui/coroutine/invalid_attr_usage.stderr index 7c0d8e98eb2aa..07b9513d51bdb 100644 --- a/tests/ui/coroutine/invalid_attr_usage.stderr +++ b/tests/ui/coroutine/invalid_attr_usage.stderr @@ -3,6 +3,8 @@ error: the `coroutine` attribute cannot be used on structs | LL | #[coroutine] | ^^^^^^^^^ +LL | +LL | struct Foo; | = help: the `coroutine` attribute can only be applied to closures @@ -11,6 +13,8 @@ error: the `coroutine` attribute cannot be used on functions | LL | #[coroutine] | ^^^^^^^^^ +LL | +LL | fn main() {} | = help: the `coroutine` attribute can only be applied to closures diff --git a/tests/ui/coverage-attr/allowed-positions.stderr b/tests/ui/coverage-attr/allowed-positions.stderr index 3e585d26e3e40..544d253cd9a59 100644 --- a/tests/ui/coverage-attr/allowed-positions.stderr +++ b/tests/ui/coverage-attr/allowed-positions.stderr @@ -13,6 +13,7 @@ error: the `coverage` attribute cannot be used on type aliases | LL | #[coverage(off)] | ^^^^^^^^ +LL | type MyTypeAlias = (); | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -21,6 +22,7 @@ error: the `coverage` attribute cannot be used on traits | LL | #[coverage(off)] | ^^^^^^^^ +LL | trait MyTrait { | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -29,6 +31,7 @@ error: the `coverage` attribute cannot be used on associated consts | LL | #[coverage(off)] | ^^^^^^^^ +LL | const TRAIT_ASSOC_CONST: u32; | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -37,6 +40,7 @@ error: the `coverage` attribute cannot be used on associated types | LL | #[coverage(off)] | ^^^^^^^^ +LL | type TraitAssocType; | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -45,6 +49,7 @@ error: the `coverage` attribute cannot be used on required trait methods | LL | #[coverage(off)] | ^^^^^^^^ +LL | fn trait_method(&self); | = help: the `coverage` attribute can be applied to crates, functions with a body, impl blocks, and modules @@ -53,6 +58,7 @@ error: the `coverage` attribute cannot be used on required trait methods | LL | #[coverage(off)] | ^^^^^^^^ +LL | fn trait_assoc_fn(); | = help: the `coverage` attribute can be applied to crates, functions with a body, impl blocks, and modules @@ -61,6 +67,7 @@ error: the `coverage` attribute cannot be used on associated types | LL | #[coverage(off)] | ^^^^^^^^ +LL | type TraitAssocType = Self; | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -69,6 +76,7 @@ error: the `coverage` attribute cannot be used on associated types | LL | #[coverage(off)] | ^^^^^^^^ +LL | type T = impl Copy; | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -77,6 +85,7 @@ error: the `coverage` attribute cannot be used on structs | LL | #[coverage(off)] | ^^^^^^^^ +LL | struct MyStruct { | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -85,6 +94,7 @@ error: the `coverage` attribute cannot be used on struct fields | LL | #[coverage(off)] | ^^^^^^^^ +LL | field: u32, | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -93,6 +103,7 @@ error: the `coverage` attribute cannot be used on foreign statics | LL | #[coverage(off)] | ^^^^^^^^ +LL | static X: u32; | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -101,6 +112,7 @@ error: the `coverage` attribute cannot be used on foreign types | LL | #[coverage(off)] | ^^^^^^^^ +LL | type T; | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -109,6 +121,7 @@ error: the `coverage` attribute cannot be used on foreign functions | LL | #[coverage(off)] | ^^^^^^^^ +LL | fn foreign_fn(); | = help: the `coverage` attribute can be applied to crates, functions with a body, impl blocks, and modules @@ -117,6 +130,7 @@ error: the `coverage` attribute cannot be used on statements | LL | #[coverage(off)] | ^^^^^^^^ +LL | let _ = (); | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -125,6 +139,7 @@ error: the `coverage` attribute cannot be used on statements | LL | #[coverage(off)] | ^^^^^^^^ +LL | let _let_closure = || (); | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -133,6 +148,7 @@ error: the `coverage` attribute cannot be used on match arms | LL | #[coverage(off)] | ^^^^^^^^ +LL | () => (), | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -141,6 +157,7 @@ error: the `coverage` attribute cannot be used on expressions | LL | #[coverage(off)] | ^^^^^^^^ +LL | return (); | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules diff --git a/tests/ui/coverage-attr/name-value.stderr b/tests/ui/coverage-attr/name-value.stderr index e5cdcf83e0a48..9b5b161eb6853 100644 --- a/tests/ui/coverage-attr/name-value.stderr +++ b/tests/ui/coverage-attr/name-value.stderr @@ -54,6 +54,8 @@ error: the `coverage` attribute cannot be used on structs | LL | #[coverage = "off"] | ^^^^^^^^ +... +LL | struct MyStruct; | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -96,6 +98,8 @@ error: the `coverage` attribute cannot be used on associated consts | LL | #[coverage = "off"] | ^^^^^^^^ +... +LL | const X: u32 = 7; | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -121,6 +125,8 @@ error: the `coverage` attribute cannot be used on traits | LL | #[coverage = "off"] | ^^^^^^^^ +... +LL | trait MyTrait { | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -146,6 +152,8 @@ error: the `coverage` attribute cannot be used on associated consts | LL | #[coverage = "off"] | ^^^^^^^^ +... +LL | const X: u32; | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -171,6 +179,8 @@ error: the `coverage` attribute cannot be used on associated types | LL | #[coverage = "off"] | ^^^^^^^^ +... +LL | type T; | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -213,6 +223,8 @@ error: the `coverage` attribute cannot be used on associated consts | LL | #[coverage = "off"] | ^^^^^^^^ +... +LL | const X: u32 = 8; | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -238,6 +250,8 @@ error: the `coverage` attribute cannot be used on associated types | LL | #[coverage = "off"] | ^^^^^^^^ +... +LL | type T = (); | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules diff --git a/tests/ui/coverage-attr/word-only.stderr b/tests/ui/coverage-attr/word-only.stderr index fdf8506ae30a0..aaeb76e50f98d 100644 --- a/tests/ui/coverage-attr/word-only.stderr +++ b/tests/ui/coverage-attr/word-only.stderr @@ -42,6 +42,8 @@ error: the `coverage` attribute cannot be used on structs | LL | #[coverage] | ^^^^^^^^ +... +LL | struct MyStruct; | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -76,6 +78,8 @@ error: the `coverage` attribute cannot be used on associated consts | LL | #[coverage] | ^^^^^^^^ +... +LL | const X: u32 = 7; | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -97,6 +101,8 @@ error: the `coverage` attribute cannot be used on traits | LL | #[coverage] | ^^^^^^^^ +... +LL | trait MyTrait { | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -118,6 +124,8 @@ error: the `coverage` attribute cannot be used on associated consts | LL | #[coverage] | ^^^^^^^^ +... +LL | const X: u32; | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -139,6 +147,8 @@ error: the `coverage` attribute cannot be used on associated types | LL | #[coverage] | ^^^^^^^^ +... +LL | type T; | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -173,6 +183,8 @@ error: the `coverage` attribute cannot be used on associated consts | LL | #[coverage] | ^^^^^^^^ +... +LL | const X: u32 = 8; | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules @@ -194,6 +206,8 @@ error: the `coverage` attribute cannot be used on associated types | LL | #[coverage] | ^^^^^^^^ +... +LL | type T = (); | = help: the `coverage` attribute can be applied to crates, functions, impl blocks, and modules diff --git a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155127.stderr b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155127.stderr index 571a0f7198df9..1b3924f00d6af 100644 --- a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155127.stderr +++ b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155127.stderr @@ -3,6 +3,8 @@ error: the `deprecated` attribute cannot be used on delegations | LL | #[deprecated] | ^^^^^^^^^^ +LL | +LL | reuse foo; | = help: the `deprecated` attribute can be applied to associated consts, associated types, constants, crates, data types, enum variants, foreign statics, functions, inherent impl blocks, macro defs, modules, statics, struct fields, traits, type aliases, and use statements = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/deprecation/deprecation-sanity.stderr b/tests/ui/deprecation/deprecation-sanity.stderr index c4b04438397e5..7bc5e57ba75ac 100644 --- a/tests/ui/deprecation/deprecation-sanity.stderr +++ b/tests/ui/deprecation/deprecation-sanity.stderr @@ -100,6 +100,8 @@ error: the `deprecated` attribute cannot be used on trait impl blocks | LL | #[deprecated = "hello"] | ^^^^^^^^^^ +LL | +LL | impl Default for X { | = help: the `deprecated` attribute can be applied to associated consts, associated types, constants, crates, data types, enum variants, foreign statics, functions, inherent impl blocks, macro defs, modules, statics, struct fields, traits, type aliases, and use statements = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/derives/derive-enum-repr-packed.stderr b/tests/ui/derives/derive-enum-repr-packed.stderr index 0f020bd7934a6..9aa9c88b58230 100644 --- a/tests/ui/derives/derive-enum-repr-packed.stderr +++ b/tests/ui/derives/derive-enum-repr-packed.stderr @@ -3,6 +3,7 @@ error: the `repr(packed)` attribute cannot be used on enums | LL | #[repr(packed)] | ^^^^^^^^^^^^ +LL | enum COption { | = help: the `repr(packed)` attribute can be applied to structs and unions diff --git a/tests/ui/diagnostic_namespace/do_not_recommend/incorrect-locations.current.stderr b/tests/ui/diagnostic_namespace/do_not_recommend/incorrect-locations.current.stderr index ab48b3b9a1b14..6926eaae3ce4c 100644 --- a/tests/ui/diagnostic_namespace/do_not_recommend/incorrect-locations.current.stderr +++ b/tests/ui/diagnostic_namespace/do_not_recommend/incorrect-locations.current.stderr @@ -3,6 +3,8 @@ warning: the `diagnostic::do_not_recommend` attribute cannot be used on constant | LL | #[diagnostic::do_not_recommend] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | const CONST: () = (); | = help: the `diagnostic::do_not_recommend` attribute can only be applied to trait impl blocks = note: `#[warn(misplaced_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default @@ -12,6 +14,8 @@ warning: the `diagnostic::do_not_recommend` attribute cannot be used on statics | LL | #[diagnostic::do_not_recommend] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | static STATIC: () = (); | = help: the `diagnostic::do_not_recommend` attribute can only be applied to trait impl blocks @@ -20,6 +24,8 @@ warning: the `diagnostic::do_not_recommend` attribute cannot be used on type ali | LL | #[diagnostic::do_not_recommend] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | type Type = (); | = help: the `diagnostic::do_not_recommend` attribute can only be applied to trait impl blocks @@ -28,6 +34,8 @@ warning: the `diagnostic::do_not_recommend` attribute cannot be used on enums | LL | #[diagnostic::do_not_recommend] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | enum Enum {} | = help: the `diagnostic::do_not_recommend` attribute can only be applied to trait impl blocks @@ -36,6 +44,8 @@ warning: the `diagnostic::do_not_recommend` attribute cannot be used on inherent | LL | #[diagnostic::do_not_recommend] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | impl Enum {} | = help: the `diagnostic::do_not_recommend` attribute can only be applied to trait impl blocks @@ -44,6 +54,8 @@ warning: the `diagnostic::do_not_recommend` attribute cannot be used on foreign | LL | #[diagnostic::do_not_recommend] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | extern "C" {} | = help: the `diagnostic::do_not_recommend` attribute can only be applied to trait impl blocks @@ -52,6 +64,8 @@ warning: the `diagnostic::do_not_recommend` attribute cannot be used on function | LL | #[diagnostic::do_not_recommend] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | fn fun() {} | = help: the `diagnostic::do_not_recommend` attribute can only be applied to trait impl blocks @@ -60,6 +74,8 @@ warning: the `diagnostic::do_not_recommend` attribute cannot be used on structs | LL | #[diagnostic::do_not_recommend] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | struct Struct {} | = help: the `diagnostic::do_not_recommend` attribute can only be applied to trait impl blocks @@ -68,6 +84,8 @@ warning: the `diagnostic::do_not_recommend` attribute cannot be used on traits | LL | #[diagnostic::do_not_recommend] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | trait Trait {} | = help: the `diagnostic::do_not_recommend` attribute can only be applied to trait impl blocks diff --git a/tests/ui/diagnostic_namespace/do_not_recommend/incorrect-locations.next.stderr b/tests/ui/diagnostic_namespace/do_not_recommend/incorrect-locations.next.stderr index ab48b3b9a1b14..6926eaae3ce4c 100644 --- a/tests/ui/diagnostic_namespace/do_not_recommend/incorrect-locations.next.stderr +++ b/tests/ui/diagnostic_namespace/do_not_recommend/incorrect-locations.next.stderr @@ -3,6 +3,8 @@ warning: the `diagnostic::do_not_recommend` attribute cannot be used on constant | LL | #[diagnostic::do_not_recommend] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | const CONST: () = (); | = help: the `diagnostic::do_not_recommend` attribute can only be applied to trait impl blocks = note: `#[warn(misplaced_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default @@ -12,6 +14,8 @@ warning: the `diagnostic::do_not_recommend` attribute cannot be used on statics | LL | #[diagnostic::do_not_recommend] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | static STATIC: () = (); | = help: the `diagnostic::do_not_recommend` attribute can only be applied to trait impl blocks @@ -20,6 +24,8 @@ warning: the `diagnostic::do_not_recommend` attribute cannot be used on type ali | LL | #[diagnostic::do_not_recommend] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | type Type = (); | = help: the `diagnostic::do_not_recommend` attribute can only be applied to trait impl blocks @@ -28,6 +34,8 @@ warning: the `diagnostic::do_not_recommend` attribute cannot be used on enums | LL | #[diagnostic::do_not_recommend] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | enum Enum {} | = help: the `diagnostic::do_not_recommend` attribute can only be applied to trait impl blocks @@ -36,6 +44,8 @@ warning: the `diagnostic::do_not_recommend` attribute cannot be used on inherent | LL | #[diagnostic::do_not_recommend] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | impl Enum {} | = help: the `diagnostic::do_not_recommend` attribute can only be applied to trait impl blocks @@ -44,6 +54,8 @@ warning: the `diagnostic::do_not_recommend` attribute cannot be used on foreign | LL | #[diagnostic::do_not_recommend] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | extern "C" {} | = help: the `diagnostic::do_not_recommend` attribute can only be applied to trait impl blocks @@ -52,6 +64,8 @@ warning: the `diagnostic::do_not_recommend` attribute cannot be used on function | LL | #[diagnostic::do_not_recommend] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | fn fun() {} | = help: the `diagnostic::do_not_recommend` attribute can only be applied to trait impl blocks @@ -60,6 +74,8 @@ warning: the `diagnostic::do_not_recommend` attribute cannot be used on structs | LL | #[diagnostic::do_not_recommend] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | struct Struct {} | = help: the `diagnostic::do_not_recommend` attribute can only be applied to trait impl blocks @@ -68,6 +84,8 @@ warning: the `diagnostic::do_not_recommend` attribute cannot be used on traits | LL | #[diagnostic::do_not_recommend] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | trait Trait {} | = help: the `diagnostic::do_not_recommend` attribute can only be applied to trait impl blocks diff --git a/tests/ui/diagnostic_namespace/on_const/misplaced_attr.stderr b/tests/ui/diagnostic_namespace/on_const/misplaced_attr.stderr index 2f125078d458e..3999592cbae97 100644 --- a/tests/ui/diagnostic_namespace/on_const/misplaced_attr.stderr +++ b/tests/ui/diagnostic_namespace/on_const/misplaced_attr.stderr @@ -18,6 +18,8 @@ error: the `diagnostic::on_const` attribute cannot be used on structs | LL | #[diagnostic::on_const(message = "tadaa", note = "boing")] | ^^^^^^^^^^^^^^^^^^^^ +LL | +LL | pub struct Foo; | = help: the `diagnostic::on_const` attribute can only be applied to trait impl blocks @@ -26,6 +28,8 @@ error: the `diagnostic::on_const` attribute cannot be used on inherent impl bloc | LL | #[diagnostic::on_const(message = "tadaa", note = "boing")] | ^^^^^^^^^^^^^^^^^^^^ +LL | +LL | impl Foo { | = help: the `diagnostic::on_const` attribute can only be applied to trait impl blocks @@ -34,6 +38,8 @@ error: the `diagnostic::on_const` attribute cannot be used on trait methods in i | LL | #[diagnostic::on_const(message = "tadaa", note = "boing")] | ^^^^^^^^^^^^^^^^^^^^ +LL | +LL | fn partial_cmp(&self, other: &Foo) -> Option { | = help: the `diagnostic::on_const` attribute can only be applied to trait impl blocks diff --git a/tests/ui/diagnostic_namespace/on_move/report_warning_on_non_adt.stderr b/tests/ui/diagnostic_namespace/on_move/report_warning_on_non_adt.stderr index 010af259e4f33..d6a2b0459eb8d 100644 --- a/tests/ui/diagnostic_namespace/on_move/report_warning_on_non_adt.stderr +++ b/tests/ui/diagnostic_namespace/on_move/report_warning_on_non_adt.stderr @@ -3,6 +3,8 @@ warning: the `diagnostic::on_move` attribute cannot be used on traits | LL | #[diagnostic::on_move( | ^^^^^^^^^^^^^^^^^^^ +... +LL | trait MyTrait {} | = help: the `diagnostic::on_move` attribute can only be applied to data types = note: `#[warn(misplaced_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default diff --git a/tests/ui/diagnostic_namespace/on_type_error/report_warning_on_non_adt.stderr b/tests/ui/diagnostic_namespace/on_type_error/report_warning_on_non_adt.stderr index 9ef283dd436a0..14dd541402898 100644 --- a/tests/ui/diagnostic_namespace/on_type_error/report_warning_on_non_adt.stderr +++ b/tests/ui/diagnostic_namespace/on_type_error/report_warning_on_non_adt.stderr @@ -3,6 +3,8 @@ warning: the `diagnostic::on_type_error` attribute cannot be used on functions | LL | #[diagnostic::on_type_error(note = "custom on_type_error note: not an ADT")] | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | fn function() {} | = help: the `diagnostic::on_type_error` attribute can only be applied to data types = note: `#[warn(misplaced_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default @@ -12,6 +14,8 @@ warning: the `diagnostic::on_type_error` attribute cannot be used on statics | LL | #[diagnostic::on_type_error(note = "custom on_type_error note: not an ADT")] | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | static STATIC: i32 = 0; | = help: the `diagnostic::on_type_error` attribute can only be applied to data types @@ -20,6 +24,8 @@ warning: the `diagnostic::on_type_error` attribute cannot be used on modules | LL | #[diagnostic::on_type_error(note = "custom on_type_error note: not an ADT")] | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | mod module {} | = help: the `diagnostic::on_type_error` attribute can only be applied to data types @@ -28,6 +34,8 @@ warning: the `diagnostic::on_type_error` attribute cannot be used on traits | LL | #[diagnostic::on_type_error(note = "custom on_type_error note: not an ADT")] | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | trait Trait {} | = help: the `diagnostic::on_type_error` attribute can only be applied to data types @@ -36,6 +44,8 @@ warning: the `diagnostic::on_type_error` attribute cannot be used on type aliase | LL | #[diagnostic::on_type_error(note = "custom on_type_error note: not an ADT")] | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | type TypeAlias = i32; | = help: the `diagnostic::on_type_error` attribute can only be applied to data types @@ -44,6 +54,8 @@ warning: the `diagnostic::on_type_error` attribute cannot be used on inherent me | LL | #[diagnostic::on_type_error(note = "custom on_type_error note: not an ADT")] | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | fn method() {} | = help: the `diagnostic::on_type_error` attribute can only be applied to data types diff --git a/tests/ui/diagnostic_namespace/on_unimplemented/do_not_accept_options_of_the_internal_rustc_attribute.stderr b/tests/ui/diagnostic_namespace/on_unimplemented/do_not_accept_options_of_the_internal_rustc_attribute.stderr index 550132a4d8d71..9a831b18c2e85 100644 --- a/tests/ui/diagnostic_namespace/on_unimplemented/do_not_accept_options_of_the_internal_rustc_attribute.stderr +++ b/tests/ui/diagnostic_namespace/on_unimplemented/do_not_accept_options_of_the_internal_rustc_attribute.stderr @@ -157,6 +157,8 @@ warning: the `diagnostic::on_unimplemented` attribute cannot be used on trait im | LL | #[diagnostic::on_unimplemented(message = "Not allowed to apply it on a impl")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | impl Bar for i32 {} | = help: the `diagnostic::on_unimplemented` attribute can only be applied to traits = note: `#[warn(misplaced_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default diff --git a/tests/ui/diagnostic_namespace/on_unimplemented/do_not_fail_parsing_on_invalid_options_1.stderr b/tests/ui/diagnostic_namespace/on_unimplemented/do_not_fail_parsing_on_invalid_options_1.stderr index e47c8102d0b55..d89a733bb85ba 100644 --- a/tests/ui/diagnostic_namespace/on_unimplemented/do_not_fail_parsing_on_invalid_options_1.stderr +++ b/tests/ui/diagnostic_namespace/on_unimplemented/do_not_fail_parsing_on_invalid_options_1.stderr @@ -21,6 +21,8 @@ warning: the `diagnostic::on_unimplemented` attribute cannot be used on structs | LL | #[diagnostic::on_unimplemented(message = "Baz")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | struct Bar {} | = help: the `diagnostic::on_unimplemented` attribute can only be applied to traits = note: `#[warn(misplaced_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default diff --git a/tests/ui/diagnostic_namespace/on_unimplemented/on_impl_trait.stderr b/tests/ui/diagnostic_namespace/on_unimplemented/on_impl_trait.stderr index 0eb00461f5524..d6be54e4e368e 100644 --- a/tests/ui/diagnostic_namespace/on_unimplemented/on_impl_trait.stderr +++ b/tests/ui/diagnostic_namespace/on_unimplemented/on_impl_trait.stderr @@ -3,6 +3,8 @@ warning: the `diagnostic::on_unimplemented` attribute cannot be used on trait al | LL | #[diagnostic::on_unimplemented(message = "blah", label = "blah", note = "blah")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | trait Alias = Test; | = help: the `diagnostic::on_unimplemented` attribute can only be applied to traits = note: `#[warn(misplaced_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default diff --git a/tests/ui/diagnostic_namespace/on_unknown/incorrect_locations.stderr b/tests/ui/diagnostic_namespace/on_unknown/incorrect_locations.stderr index 150a5521792f5..b8edd75320701 100644 --- a/tests/ui/diagnostic_namespace/on_unknown/incorrect_locations.stderr +++ b/tests/ui/diagnostic_namespace/on_unknown/incorrect_locations.stderr @@ -3,6 +3,8 @@ warning: the `diagnostic::on_unknown` attribute cannot be used on extern crates | LL | #[diagnostic::on_unknown(message = "foo")] | ^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | extern crate std as other_std; | = help: the `diagnostic::on_unknown` attribute can be applied to crates, modules, and use statements = note: `#[warn(misplaced_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default @@ -12,6 +14,8 @@ warning: the `diagnostic::on_unknown` attribute cannot be used on constants | LL | #[diagnostic::on_unknown(message = "foo")] | ^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | const CONST: () = (); | = help: the `diagnostic::on_unknown` attribute can be applied to crates, modules, and use statements @@ -20,6 +24,8 @@ warning: the `diagnostic::on_unknown` attribute cannot be used on statics | LL | #[diagnostic::on_unknown(message = "foo")] | ^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | static STATIC: () = (); | = help: the `diagnostic::on_unknown` attribute can be applied to crates, modules, and use statements @@ -28,6 +34,8 @@ warning: the `diagnostic::on_unknown` attribute cannot be used on type aliases | LL | #[diagnostic::on_unknown(message = "foo")] | ^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | type Type = (); | = help: the `diagnostic::on_unknown` attribute can be applied to crates, modules, and use statements @@ -36,6 +44,8 @@ warning: the `diagnostic::on_unknown` attribute cannot be used on enums | LL | #[diagnostic::on_unknown(message = "foo")] | ^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | enum Enum {} | = help: the `diagnostic::on_unknown` attribute can be applied to crates, modules, and use statements @@ -44,6 +54,8 @@ warning: the `diagnostic::on_unknown` attribute cannot be used on inherent impl | LL | #[diagnostic::on_unknown(message = "foo")] | ^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | impl Enum {} | = help: the `diagnostic::on_unknown` attribute can be applied to crates, modules, and use statements @@ -52,6 +64,8 @@ warning: the `diagnostic::on_unknown` attribute cannot be used on foreign module | LL | #[diagnostic::on_unknown(message = "foo")] | ^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | extern "C" {} | = help: the `diagnostic::on_unknown` attribute can be applied to crates, modules, and use statements @@ -60,6 +74,8 @@ warning: the `diagnostic::on_unknown` attribute cannot be used on functions | LL | #[diagnostic::on_unknown(message = "foo")] | ^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | fn fun() {} | = help: the `diagnostic::on_unknown` attribute can be applied to crates, modules, and use statements @@ -68,6 +84,8 @@ warning: the `diagnostic::on_unknown` attribute cannot be used on structs | LL | #[diagnostic::on_unknown(message = "foo")] | ^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | struct Struct {} | = help: the `diagnostic::on_unknown` attribute can be applied to crates, modules, and use statements @@ -76,6 +94,8 @@ warning: the `diagnostic::on_unknown` attribute cannot be used on traits | LL | #[diagnostic::on_unknown(message = "foo")] | ^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | trait Trait {} | = help: the `diagnostic::on_unknown` attribute can be applied to crates, modules, and use statements @@ -84,6 +104,8 @@ warning: the `diagnostic::on_unknown` attribute cannot be used on trait impl blo | LL | #[diagnostic::on_unknown(message = "foo")] | ^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | impl Trait for i32 {} | = help: the `diagnostic::on_unknown` attribute can be applied to crates, modules, and use statements diff --git a/tests/ui/diagnostic_namespace/on_unknown/incorrect_unstable_positions.stderr b/tests/ui/diagnostic_namespace/on_unknown/incorrect_unstable_positions.stderr index f69a545526ca4..38d2fb7ffb944 100644 --- a/tests/ui/diagnostic_namespace/on_unknown/incorrect_unstable_positions.stderr +++ b/tests/ui/diagnostic_namespace/on_unknown/incorrect_unstable_positions.stderr @@ -3,6 +3,8 @@ warning: the `diagnostic::on_unknown` attribute cannot be used on expressions | LL | #[diagnostic::on_unknown(message = "anonymous block")] | ^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | {} | = help: the `diagnostic::on_unknown` attribute can be applied to crates, modules, and use statements = note: `#[warn(misplaced_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default diff --git a/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_non_macro.stderr b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_non_macro.stderr index bad26db7271a1..a00e21cd365fa 100644 --- a/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_non_macro.stderr +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_non_macro.stderr @@ -3,6 +3,8 @@ warning: the `diagnostic::on_unmatched_args` attribute cannot be used on structs | LL | #[diagnostic::on_unmatched_args(message = "not allowed here")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | struct Foo; | = help: the `diagnostic::on_unmatched_args` attribute can only be applied to macro defs = note: `#[warn(misplaced_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default diff --git a/tests/ui/eii/track_caller_static_errors.stderr b/tests/ui/eii/track_caller_static_errors.stderr index 78b13c96632eb..b0cf606ea7a37 100644 --- a/tests/ui/eii/track_caller_static_errors.stderr +++ b/tests/ui/eii/track_caller_static_errors.stderr @@ -3,6 +3,8 @@ error: the `track_caller` attribute cannot be used on foreign statics | LL | #[track_caller] | ^^^^^^^^^^^^ +LL | #[eii(sfoo)] +LL | static FOO: u64 = 42; | = help: the `track_caller` attribute can only be applied to functions diff --git a/tests/ui/enum-discriminant/eval-error.stderr b/tests/ui/enum-discriminant/eval-error.stderr index a90038f0682b3..0fcb7a5d2ec14 100644 --- a/tests/ui/enum-discriminant/eval-error.stderr +++ b/tests/ui/enum-discriminant/eval-error.stderr @@ -9,6 +9,8 @@ error: the `repr(packed)` attribute cannot be used on enums | LL | #[repr(u8, packed)] | ^^^^^^^^^^^^^^^^ +LL | +LL | enum Foo3 { | = help: the `repr(packed)` attribute can be applied to structs and unions diff --git a/tests/ui/error-codes/E0718.stderr b/tests/ui/error-codes/E0718.stderr index 8c0cd42415f4c..9f000f04e6c50 100644 --- a/tests/ui/error-codes/E0718.stderr +++ b/tests/ui/error-codes/E0718.stderr @@ -3,6 +3,7 @@ error: the `lang = "owned_box"` attribute cannot be used on statics | LL | #[lang = "owned_box"] | ^^^^^^^^^^^^^^^^^^ +LL | static X: u32 = 42; | = help: the `lang = "owned_box"` attribute can only be applied to structs diff --git a/tests/ui/extern/extern-no-mangle.stderr b/tests/ui/extern/extern-no-mangle.stderr index 210beb1e70929..d01fb78095879 100644 --- a/tests/ui/extern/extern-no-mangle.stderr +++ b/tests/ui/extern/extern-no-mangle.stderr @@ -3,6 +3,8 @@ warning: the `no_mangle` attribute cannot be used on statements | LL | #[no_mangle] | ^^^^^^^^^ +... +LL | let x = 0_u8; | = help: the `no_mangle` attribute can be applied to functions and statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -17,6 +19,8 @@ warning: the `no_mangle` attribute cannot be used on foreign statics | LL | #[no_mangle] | ^^^^^^^^^ +... +LL | pub static FOO: u8; | = help: the `no_mangle` attribute can be applied to functions and statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -26,6 +30,8 @@ warning: the `no_mangle` attribute cannot be used on foreign functions | LL | #[no_mangle] | ^^^^^^^^^ +... +LL | pub fn bar(); | = help: the `no_mangle` attribute can be applied to functions with a body and statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/extern/issue-47725.stderr b/tests/ui/extern/issue-47725.stderr index 2dd8a2191d89b..352ab19e78c06 100644 --- a/tests/ui/extern/issue-47725.stderr +++ b/tests/ui/extern/issue-47725.stderr @@ -15,6 +15,8 @@ warning: the `link_name` attribute cannot be used on structs | LL | #[link_name = "foo"] | ^^^^^^^^^ +... +LL | struct Foo; | = help: the `link_name` attribute can be applied to foreign functions and foreign statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -29,6 +31,8 @@ warning: the `link_name` attribute cannot be used on foreign modules | LL | #[link_name = "foobar"] | ^^^^^^^^^ +... +LL | extern "C" { | = help: the `link_name` attribute can be applied to foreign functions and foreign statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -38,6 +42,8 @@ warning: the `link_name` attribute cannot be used on foreign modules | LL | #[link_name] | ^^^^^^^^^ +... +LL | extern "C" { | = help: the `link_name` attribute can be applied to foreign functions and foreign statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/feature-gates/feature-gate-allow-internal-unstable-struct.stderr b/tests/ui/feature-gates/feature-gate-allow-internal-unstable-struct.stderr index 777f64319d1a6..c31aebe39ee3f 100644 --- a/tests/ui/feature-gates/feature-gate-allow-internal-unstable-struct.stderr +++ b/tests/ui/feature-gates/feature-gate-allow-internal-unstable-struct.stderr @@ -12,6 +12,8 @@ error: the `allow_internal_unstable` attribute cannot be used on structs | LL | #[allow_internal_unstable(something)] | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | struct S; | = help: the `allow_internal_unstable` attribute can be applied to functions and macro defs diff --git a/tests/ui/feature-gates/feature-gate-check-nested-macro-invocation.stderr b/tests/ui/feature-gates/feature-gate-check-nested-macro-invocation.stderr index cd6e6e385fbe9..84effb42564cb 100644 --- a/tests/ui/feature-gates/feature-gate-check-nested-macro-invocation.stderr +++ b/tests/ui/feature-gates/feature-gate-check-nested-macro-invocation.stderr @@ -20,6 +20,8 @@ LL | () => ( LL | #[allow_internal_unstable()] | ^^^^^^^^^^^^^^^^^^^^^^^ ... +LL | bar!(); +... LL | foo!(); | ------ in this macro invocation | diff --git a/tests/ui/feature-gates/feature-gate-repr-simd.stderr b/tests/ui/feature-gates/feature-gate-repr-simd.stderr index a43e9f4cea342..95936212ce1cd 100644 --- a/tests/ui/feature-gates/feature-gate-repr-simd.stderr +++ b/tests/ui/feature-gates/feature-gate-repr-simd.stderr @@ -33,6 +33,8 @@ error: the `repr(simd)` attribute cannot be used on unions | LL | #[repr(simd)] | ^^^^^^^^^^ +LL | +LL | union U {f: u32} | = help: the `repr(simd)` attribute can only be applied to structs @@ -51,6 +53,8 @@ error: the `repr(simd)` attribute cannot be used on enums | LL | #[repr(simd)] | ^^^^^^^^^^ +LL | +LL | enum E { X } | = help: the `repr(simd)` attribute can only be applied to structs diff --git a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr index 44f7d6942a3a1..3b2c296ca08d1 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr +++ b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr @@ -77,6 +77,8 @@ error: the `inline` attribute cannot be used on modules | LL | #[inline] | ^^^^^^ +LL | +LL | mod inline { | = help: the `inline` attribute can only be applied to functions @@ -117,6 +119,8 @@ error: the `no_link` attribute cannot be used on modules | LL | #[no_link] | ^^^^^^^ +LL | +LL | mod no_link { | = help: the `no_link` attribute can only be applied to extern crates @@ -141,6 +145,8 @@ error: the `no_link` attribute cannot be used on structs | LL | #[no_link] | ^^^^^^^ +LL | +LL | struct S { | = help: the `no_link` attribute can only be applied to extern crates @@ -165,6 +171,8 @@ error: the `export_name` attribute cannot be used on modules | LL | #[export_name = "2200"] | ^^^^^^^^^^^ +LL | +LL | mod export_name { | = help: the `export_name` attribute can be applied to functions and statics @@ -213,6 +221,8 @@ error: the `repr(C)` attribute cannot be used on modules | LL | #[repr(C)] | ^^^^^^^ +LL | +LL | mod repr { | = help: the `repr(C)` attribute can only be applied to data types @@ -253,6 +263,8 @@ error: the `repr(Rust)` attribute cannot be used on modules | LL | #[repr(Rust)] | ^^^^^^^^^^ +LL | +LL | mod repr_rust { | = help: the `repr(Rust)` attribute can only be applied to data types @@ -337,6 +349,8 @@ warning: the `no_link` attribute cannot be used on match arms | LL | #[no_link] | ^^^^^^^ +... +LL | _ => () | = help: the `no_link` attribute can only be applied to extern crates = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -346,6 +360,8 @@ warning: the `no_link` attribute cannot be used on struct fields | LL | #[no_link] | ^^^^^^^ +... +LL | field: () | = help: the `no_link` attribute can only be applied to extern crates = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -355,6 +371,8 @@ warning: the `no_link` attribute cannot be used on macro defs | LL | #[no_link] | ^^^^^^^ +... +LL | macro_rules! m{() => {}} | = help: the `no_link` attribute can only be applied to extern crates = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! 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 2d3b7658f9aae..f685a989c0aa6 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 @@ -329,6 +329,8 @@ warning: the `macro_export` attribute cannot be used on modules | LL | #[macro_export] | ^^^^^^^^^^^^ +... +LL | mod macro_export { | = help: the `macro_export` attribute can only be applied to macro defs = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -419,6 +421,8 @@ warning: the `automatically_derived` attribute cannot be used on modules | LL | #[automatically_derived] | ^^^^^^^^^^^^^^^^^^^^^ +... +LL | mod automatically_derived { | = help: the `automatically_derived` attribute can only be applied to trait impl blocks = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -482,6 +486,8 @@ warning: the `no_mangle` attribute cannot be used on modules | LL | #[no_mangle] | ^^^^^^^^^ +... +LL | mod no_mangle { | = help: the `no_mangle` attribute can be applied to functions and statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -527,6 +533,8 @@ warning: the `should_panic` attribute cannot be used on modules | LL | #[should_panic] | ^^^^^^^^^^^^ +... +LL | mod should_panic { | = help: the `should_panic` attribute can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -572,6 +580,8 @@ warning: the `ignore` attribute cannot be used on modules | LL | #[ignore] | ^^^^^^ +... +LL | mod ignore { | = help: the `ignore` attribute can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -759,6 +769,8 @@ warning: the `cold` attribute cannot be used on modules | LL | #[cold] | ^^^^ +... +LL | mod cold { | = help: the `cold` attribute can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -804,6 +816,8 @@ warning: the `link_name` attribute cannot be used on modules | LL | #[link_name = "1900"] | ^^^^^^^^^ +... +LL | mod link_name { | = help: the `link_name` attribute can be applied to foreign functions and foreign statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -813,6 +827,8 @@ warning: the `link_name` attribute cannot be used on foreign modules | LL | #[link_name = "1900"] | ^^^^^^^^^ +... +LL | extern "C" { } | = help: the `link_name` attribute can be applied to foreign functions and foreign statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -867,6 +883,8 @@ warning: the `link_section` attribute cannot be used on modules | LL | #[link_section = ",1800"] | ^^^^^^^^^^^^ +... +LL | mod link_section { | = help: the `link_section` attribute can be applied to functions and statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -912,6 +930,8 @@ warning: the `link_section` attribute cannot be used on traits | LL | #[link_section = ",1800"] | ^^^^^^^^^^^^ +... +LL | trait Tr { | = help: the `link_section` attribute can be applied to functions and statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -921,6 +941,8 @@ warning: the `link` attribute cannot be used on modules | LL | #[link(name = "x")] | ^^^^ +... +LL | mod link { | = help: the `link` attribute can only be applied to foreign modules = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -983,6 +1005,8 @@ warning: the `must_use` attribute cannot be used on modules | LL | #[must_use] | ^^^^^^^^ +... +LL | mod must_use { | = help: the `must_use` attribute can be applied to data types, functions, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -1597,6 +1621,8 @@ warning: the `link_section` attribute cannot be used on required trait methods | LL | #[link_section = ",1800"] | ^^^^^^^^^^^^ +... +LL | fn inside_tr_no_default(&self); | = help: the `link_section` attribute can be applied to functions with a body and statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/feature-gates/issue-43106-gating-of-proc_macro_derive.stderr b/tests/ui/feature-gates/issue-43106-gating-of-proc_macro_derive.stderr index e42c3ca651569..cbbf6df1c663a 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-proc_macro_derive.stderr +++ b/tests/ui/feature-gates/issue-43106-gating-of-proc_macro_derive.stderr @@ -9,6 +9,8 @@ error: the `proc_macro_derive` attribute cannot be used on modules | LL | #[proc_macro_derive(Test)] | ^^^^^^^^^^^^^^^^^ +LL | +LL | mod proc_macro_derive1 { | = help: the `proc_macro_derive` attribute can only be applied to functions diff --git a/tests/ui/ffi-attrs/ffi_const.stderr b/tests/ui/ffi-attrs/ffi_const.stderr index 66b5339b31e2d..afc1d703ff74e 100644 --- a/tests/ui/ffi-attrs/ffi_const.stderr +++ b/tests/ui/ffi-attrs/ffi_const.stderr @@ -3,6 +3,7 @@ error: the `ffi_const` attribute cannot be used on functions | LL | #[unsafe(ffi_const)] | ^^^^^^^^^ +LL | pub fn foo() {} | = help: the `ffi_const` attribute can only be applied to foreign functions @@ -11,6 +12,7 @@ error: the `ffi_const` attribute cannot be used on macro defs | LL | #[unsafe(ffi_const)] | ^^^^^^^^^ +LL | macro_rules! bar { | = help: the `ffi_const` attribute can only be applied to foreign functions @@ -19,6 +21,7 @@ error: the `ffi_const` attribute cannot be used on foreign statics | LL | #[unsafe(ffi_const)] | ^^^^^^^^^ +LL | static INT: i32; | = help: the `ffi_const` attribute can only be applied to foreign functions diff --git a/tests/ui/ffi-attrs/ffi_pure.stderr b/tests/ui/ffi-attrs/ffi_pure.stderr index 5c3b5ef9a812f..6bb104e2d3bd0 100644 --- a/tests/ui/ffi-attrs/ffi_pure.stderr +++ b/tests/ui/ffi-attrs/ffi_pure.stderr @@ -3,6 +3,7 @@ error: the `ffi_pure` attribute cannot be used on functions | LL | #[unsafe(ffi_pure)] | ^^^^^^^^ +LL | pub fn foo() {} | = help: the `ffi_pure` attribute can only be applied to foreign functions @@ -11,6 +12,7 @@ error: the `ffi_pure` attribute cannot be used on macro defs | LL | #[unsafe(ffi_pure)] | ^^^^^^^^ +LL | macro_rules! bar { | = help: the `ffi_pure` attribute can only be applied to foreign functions @@ -19,6 +21,7 @@ error: the `ffi_pure` attribute cannot be used on foreign statics | LL | #[unsafe(ffi_pure)] | ^^^^^^^^ +LL | static INT: i32; | = help: the `ffi_pure` attribute can only be applied to foreign functions diff --git a/tests/ui/force-inlining/invalid.stderr b/tests/ui/force-inlining/invalid.stderr index 686c105286b31..148df5ddde938 100644 --- a/tests/ui/force-inlining/invalid.stderr +++ b/tests/ui/force-inlining/invalid.stderr @@ -69,6 +69,8 @@ error: the `rustc_force_inline` attribute cannot be used on extern crates | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | extern crate std as other_std; | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -77,6 +79,8 @@ error: the `rustc_force_inline` attribute cannot be used on use statements | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | use std::collections::HashMap; | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -85,6 +89,8 @@ error: the `rustc_force_inline` attribute cannot be used on statics | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | static _FOO: &'static str = "FOO"; | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -93,6 +99,8 @@ error: the `rustc_force_inline` attribute cannot be used on constants | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | const _BAR: u32 = 3; | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -101,6 +109,8 @@ error: the `rustc_force_inline` attribute cannot be used on modules | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | mod foo { } | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -109,6 +119,8 @@ error: the `rustc_force_inline` attribute cannot be used on foreign modules | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | unsafe extern "C" { | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -117,6 +129,8 @@ error: the `rustc_force_inline` attribute cannot be used on foreign statics | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | static X: &'static u32; | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -125,6 +139,8 @@ error: the `rustc_force_inline` attribute cannot be used on foreign types | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | type Y; | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -133,6 +149,8 @@ error: the `rustc_force_inline` attribute cannot be used on foreign functions | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | fn foo(); | = help: the `rustc_force_inline` attribute can only be applied to functions with a body @@ -141,6 +159,8 @@ error: the `rustc_force_inline` attribute cannot be used on type aliases | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | type Foo = u32; | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -149,6 +169,8 @@ error: the `rustc_force_inline` attribute cannot be used on enums | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | enum Bar<#[rustc_force_inline] T> { | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -165,6 +187,8 @@ error: the `rustc_force_inline` attribute cannot be used on enum variants | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | Baz(std::marker::PhantomData), | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -173,6 +197,8 @@ error: the `rustc_force_inline` attribute cannot be used on structs | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | struct Qux { | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -181,6 +207,8 @@ error: the `rustc_force_inline` attribute cannot be used on struct fields | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | field: u32, | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -189,6 +217,8 @@ error: the `rustc_force_inline` attribute cannot be used on unions | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | union FooBar { | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -197,6 +227,8 @@ error: the `rustc_force_inline` attribute cannot be used on traits | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | trait FooBaz { | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -205,6 +237,8 @@ error: the `rustc_force_inline` attribute cannot be used on associated types | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | type Foo; | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -213,6 +247,8 @@ error: the `rustc_force_inline` attribute cannot be used on associated consts | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | const Bar: i32; | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -221,6 +257,8 @@ error: the `rustc_force_inline` attribute cannot be used on provided trait metho | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | fn foo() {} | = help: the `rustc_force_inline` attribute can be applied to functions and inherent methods @@ -229,6 +267,8 @@ error: the `rustc_force_inline` attribute cannot be used on trait aliases | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | trait FooQux = FooBaz; | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -237,6 +277,8 @@ error: the `rustc_force_inline` attribute cannot be used on inherent impl blocks | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | impl Bar { | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -245,6 +287,8 @@ error: the `rustc_force_inline` attribute cannot be used on trait impl blocks | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | impl FooBaz for Bar { | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -253,6 +297,8 @@ error: the `rustc_force_inline` attribute cannot be used on macro defs | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | macro_rules! barqux { ($foo:tt) => { $foo }; } | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -285,6 +331,8 @@ error: the `rustc_force_inline` attribute cannot be used on statements | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | let _z = 3; | = help: the `rustc_force_inline` attribute can only be applied to functions @@ -293,6 +341,8 @@ error: the `rustc_force_inline` attribute cannot be used on match arms | LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | 1 => (), | = help: the `rustc_force_inline` attribute can only be applied to functions diff --git a/tests/ui/internal-lints/query_stability_incorrect.stderr b/tests/ui/internal-lints/query_stability_incorrect.stderr index 4347e548b2deb..f70760ef9e93b 100644 --- a/tests/ui/internal-lints/query_stability_incorrect.stderr +++ b/tests/ui/internal-lints/query_stability_incorrect.stderr @@ -3,6 +3,8 @@ error: the `rustc_lint_query_instability` attribute cannot be used on structs | LL | #[rustc_lint_query_instability] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | struct Foo; | = help: the `rustc_lint_query_instability` attribute can only be applied to functions diff --git a/tests/ui/internal/internal-unstable.stderr b/tests/ui/internal/internal-unstable.stderr index f3e41f6c2a646..f59248b5ae827 100644 --- a/tests/ui/internal/internal-unstable.stderr +++ b/tests/ui/internal/internal-unstable.stderr @@ -9,6 +9,8 @@ error: the `allow_internal_unstable` attribute cannot be used on struct fields | LL | #[allow_internal_unstable] | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | baz: u8, | = help: the `allow_internal_unstable` attribute can be applied to functions and macro defs @@ -23,6 +25,8 @@ error: the `allow_internal_unstable` attribute cannot be used on match arms | LL | #[allow_internal_unstable] | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | _ => {} | = help: the `allow_internal_unstable` attribute can be applied to functions and macro defs diff --git a/tests/ui/layout/debug.stderr b/tests/ui/layout/debug.stderr index 0618810d223f3..0b5afffeb52e0 100644 --- a/tests/ui/layout/debug.stderr +++ b/tests/ui/layout/debug.stderr @@ -9,6 +9,7 @@ error: the `rustc_dump_layout` attribute cannot be used on constants | LL | #[rustc_dump_layout(debug)] | ^^^^^^^^^^^^^^^^^ +LL | const C: () = (); | = help: the `rustc_dump_layout` attribute can be applied to data types and type aliases @@ -17,6 +18,7 @@ error: the `rustc_dump_layout` attribute cannot be used on associated consts | LL | #[rustc_dump_layout(debug)] | ^^^^^^^^^^^^^^^^^ +LL | const C: () = (); | = help: the `rustc_dump_layout` attribute can be applied to data types and type aliases diff --git a/tests/ui/layout/thaw-transmute-invalid-enum.stderr b/tests/ui/layout/thaw-transmute-invalid-enum.stderr index 76492027503c0..bafa5951e58db 100644 --- a/tests/ui/layout/thaw-transmute-invalid-enum.stderr +++ b/tests/ui/layout/thaw-transmute-invalid-enum.stderr @@ -14,6 +14,8 @@ error: the `repr(packed)` attribute cannot be used on enums | LL | #[repr(C, packed(2))] | ^^^^^^^^^^^^^^^^^^ +LL | +LL | enum OxFF { | = help: the `repr(packed)` attribute can be applied to structs and unions diff --git a/tests/ui/layout/thaw-validate-invalid-enum.stderr b/tests/ui/layout/thaw-validate-invalid-enum.stderr index d4a54bca17cc1..585d6fc02c196 100644 --- a/tests/ui/layout/thaw-validate-invalid-enum.stderr +++ b/tests/ui/layout/thaw-validate-invalid-enum.stderr @@ -3,6 +3,8 @@ error: the `repr(packed)` attribute cannot be used on enums | LL | #[repr(packed)] | ^^^^^^^^^^^^ +LL | #[repr(u32)] +LL | enum E { | = help: the `repr(packed)` attribute can be applied to structs and unions diff --git a/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-not-foreign-fn.stderr b/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-not-foreign-fn.stderr index b4b81b2cfff37..6eb2221aeefda 100644 --- a/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-not-foreign-fn.stderr +++ b/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-not-foreign-fn.stderr @@ -3,6 +3,8 @@ error: the `link_ordinal` attribute cannot be used on structs | LL | #[link_ordinal(123)] | ^^^^^^^^^^^^ +LL | +LL | struct Foo {} | = help: the `link_ordinal` attribute can be applied to foreign functions and foreign statics @@ -11,6 +13,8 @@ error: the `link_ordinal` attribute cannot be used on functions | LL | #[link_ordinal(123)] | ^^^^^^^^^^^^ +LL | +LL | fn test() {} | = help: the `link_ordinal` attribute can be applied to foreign functions and foreign statics @@ -19,6 +23,8 @@ error: the `link_ordinal` attribute cannot be used on statics | LL | #[link_ordinal(42)] | ^^^^^^^^^^^^ +LL | +LL | static mut imported_val: i32 = 123; | = help: the `link_ordinal` attribute can be applied to foreign functions and foreign statics diff --git a/tests/ui/lint/fn_must_use.stderr b/tests/ui/lint/fn_must_use.stderr index 1277a6283c645..b6e94e8639148 100644 --- a/tests/ui/lint/fn_must_use.stderr +++ b/tests/ui/lint/fn_must_use.stderr @@ -3,6 +3,8 @@ warning: the `must_use` attribute cannot be used on trait methods in impl blocks | LL | #[must_use] | ^^^^^^^^ +... +LL | fn replace(&mut self, substitute: usize) -> usize { | = help: the `must_use` attribute can be applied to data types, foreign functions, functions, inherent methods, provided trait methods, required trait methods, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.stderr b/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.stderr index 6495da94137ed..0cc0d2f569ed4 100644 --- a/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.stderr +++ b/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.stderr @@ -3,6 +3,8 @@ error: the `repr(packed)` attribute cannot be used on enums | LL | #[repr(packed)] | ^^^^^^^^^^^^ +... +LL | enum E { | = help: the `repr(packed)` attribute can be applied to structs and unions diff --git a/tests/ui/lint/inline-trait-and-foreign-items.stderr b/tests/ui/lint/inline-trait-and-foreign-items.stderr index 859a5080ee453..8d277a376b37b 100644 --- a/tests/ui/lint/inline-trait-and-foreign-items.stderr +++ b/tests/ui/lint/inline-trait-and-foreign-items.stderr @@ -3,6 +3,7 @@ error: the `inline` attribute cannot be used on associated types | LL | #[inline] | ^^^^^^ +LL | type T; | = help: the `inline` attribute can only be applied to functions @@ -11,6 +12,7 @@ error: the `inline` attribute cannot be used on associated types | LL | #[inline] | ^^^^^^ +LL | type T = Self; | = help: the `inline` attribute can only be applied to functions @@ -19,6 +21,7 @@ error: the `inline` attribute cannot be used on associated types | LL | #[inline] | ^^^^^^ +LL | type U = impl Trait; | = help: the `inline` attribute can only be applied to functions @@ -27,6 +30,7 @@ error: the `inline` attribute cannot be used on foreign statics | LL | #[inline] | ^^^^^^ +LL | static X: u32; | = help: the `inline` attribute can only be applied to functions @@ -35,6 +39,7 @@ error: the `inline` attribute cannot be used on foreign types | LL | #[inline] | ^^^^^^ +LL | type T; | = help: the `inline` attribute can only be applied to functions @@ -43,6 +48,8 @@ warning: the `inline` attribute cannot be used on associated consts | LL | #[inline] | ^^^^^^ +LL | +LL | const X: u32; | = help: the `inline` attribute can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -57,6 +64,8 @@ warning: the `inline` attribute cannot be used on associated consts | LL | #[inline] | ^^^^^^ +LL | +LL | const X: u32 = 0; | = help: the `inline` attribute can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/lint/must_not_suspend/other_items.stderr b/tests/ui/lint/must_not_suspend/other_items.stderr index 700b70d653014..405fdc2b029d2 100644 --- a/tests/ui/lint/must_not_suspend/other_items.stderr +++ b/tests/ui/lint/must_not_suspend/other_items.stderr @@ -3,6 +3,7 @@ error: the `must_not_suspend` attribute cannot be used on modules | LL | #[must_not_suspend] | ^^^^^^^^^^^^^^^^ +LL | mod inner {} | = help: the `must_not_suspend` attribute can be applied to data types and traits diff --git a/tests/ui/lint/must_not_suspend/return.stderr b/tests/ui/lint/must_not_suspend/return.stderr index 9225e6bd42d7d..a4ab9a3079474 100644 --- a/tests/ui/lint/must_not_suspend/return.stderr +++ b/tests/ui/lint/must_not_suspend/return.stderr @@ -3,6 +3,7 @@ error: the `must_not_suspend` attribute cannot be used on functions | LL | #[must_not_suspend] | ^^^^^^^^^^^^^^^^ +LL | fn foo() -> i32 { | = help: the `must_not_suspend` attribute can be applied to data types and traits diff --git a/tests/ui/lint/rfc-2383-lint-reason/expect_lint_from_macro.stderr b/tests/ui/lint/rfc-2383-lint-reason/expect_lint_from_macro.stderr index ec0f260833ccf..b527312aca42b 100644 --- a/tests/ui/lint/rfc-2383-lint-reason/expect_lint_from_macro.stderr +++ b/tests/ui/lint/rfc-2383-lint-reason/expect_lint_from_macro.stderr @@ -3,6 +3,8 @@ warning: the `expect` attribute cannot be used on macro calls | LL | #[expect(unused_variables)] | ^^^^^^ +... +LL | trigger_unused_variables_macro!(); | = help: the `expect` attribute can be applied to associated consts, associated types, break expressions, const parameters, constants, crates, data types, enum variants, extern crates, for loops, foreign modules, foreign statics, function params, functions, global asms, impl blocks, lifetime parameters, loops, macro defs, match arms, modules, pattern fields, statics, struct fields, trait aliases, traits, type aliases, type parameters, use statements, and while loops = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/lint/unused/unused-attr-macro-rules.stderr b/tests/ui/lint/unused/unused-attr-macro-rules.stderr index d44a6359044a8..894ce5767cda4 100644 --- a/tests/ui/lint/unused/unused-attr-macro-rules.stderr +++ b/tests/ui/lint/unused/unused-attr-macro-rules.stderr @@ -3,6 +3,8 @@ error: the `macro_use` attribute cannot be used on macro defs | LL | #[macro_use] | ^^^^^^^^^ +... +LL | macro_rules! foo { | = help: the `macro_use` attribute can be applied to extern crates and modules = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -17,6 +19,8 @@ error: the `path` attribute cannot be used on macro defs | LL | #[path="foo"] | ^^^^ +... +LL | macro_rules! foo { | = help: the `path` attribute can only be applied to modules = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/lint/unused/unused_attributes-must_use.stderr b/tests/ui/lint/unused/unused_attributes-must_use.stderr index 18340f963801e..9765008b3cf1e 100644 --- a/tests/ui/lint/unused/unused_attributes-must_use.stderr +++ b/tests/ui/lint/unused/unused_attributes-must_use.stderr @@ -3,6 +3,8 @@ error: the `must_use` attribute cannot be used on macro calls | LL | #[must_use] | ^^^^^^^^ +... +LL | global_asm!(""); | = help: the `must_use` attribute can be applied to data types, functions, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -18,6 +20,8 @@ error: the `must_use` attribute cannot be used on extern crates | LL | #[must_use] | ^^^^^^^^ +LL | +LL | extern crate std as std2; | = help: the `must_use` attribute can be applied to data types, functions, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -27,6 +31,8 @@ error: the `must_use` attribute cannot be used on modules | LL | #[must_use] | ^^^^^^^^ +LL | +LL | mod test_mod {} | = help: the `must_use` attribute can be applied to data types, functions, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -36,6 +42,8 @@ error: the `must_use` attribute cannot be used on use statements | LL | #[must_use] | ^^^^^^^^ +LL | +LL | use std::arch::global_asm; | = help: the `must_use` attribute can be applied to data types, functions, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -45,6 +53,8 @@ error: the `must_use` attribute cannot be used on constants | LL | #[must_use] | ^^^^^^^^ +LL | +LL | const CONST: usize = 4; | = help: the `must_use` attribute can be applied to data types, functions, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -54,6 +64,8 @@ error: the `must_use` attribute cannot be used on statics | LL | #[must_use] | ^^^^^^^^ +... +LL | static STATIC: usize = 4; | = help: the `must_use` attribute can be applied to data types, functions, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -63,6 +75,8 @@ error: the `must_use` attribute cannot be used on inherent impl blocks | LL | #[must_use] | ^^^^^^^^ +LL | +LL | impl U { | = help: the `must_use` attribute can be applied to data types, functions, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -72,6 +86,8 @@ error: the `must_use` attribute cannot be used on foreign modules | LL | #[must_use] | ^^^^^^^^ +LL | +LL | extern "Rust" { | = help: the `must_use` attribute can be applied to data types, functions, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -81,6 +97,8 @@ error: the `must_use` attribute cannot be used on type aliases | LL | #[must_use] | ^^^^^^^^ +LL | +LL | type UseMe = (); | = help: the `must_use` attribute can be applied to data types, functions, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -99,6 +117,8 @@ error: the `must_use` attribute cannot be used on trait impl blocks | LL | #[must_use] | ^^^^^^^^ +LL | +LL | impl Use for () { | = help: the `must_use` attribute can be applied to data types, functions, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -108,6 +128,8 @@ error: the `must_use` attribute cannot be used on trait aliases | LL | #[must_use] | ^^^^^^^^ +LL | +LL | trait Alias = Use; | = help: the `must_use` attribute can be applied to data types, functions, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -117,6 +139,8 @@ error: the `must_use` attribute cannot be used on macro defs | LL | #[must_use] | ^^^^^^^^ +LL | +LL | macro_rules! cool_macro { | = help: the `must_use` attribute can be applied to data types, functions, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -126,6 +150,8 @@ error: the `must_use` attribute cannot be used on statements | LL | #[must_use] | ^^^^^^^^ +LL | +LL | let x = || {}; | = help: the `must_use` attribute can be applied to data types, functions, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -135,6 +161,8 @@ error: the `must_use` attribute cannot be used on closures | LL | let x = #[must_use] | ^^^^^^^^ +LL | +LL | || {}; | = help: the `must_use` attribute can be applied to data types, foreign functions, functions, methods, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -144,6 +172,8 @@ error: the `must_use` attribute cannot be used on match arms | LL | #[must_use] | ^^^^^^^^ +LL | +LL | Some(res) => res, | = help: the `must_use` attribute can be applied to data types, functions, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -171,6 +201,8 @@ error: the `must_use` attribute cannot be used on associated consts | LL | #[must_use] | ^^^^^^^^ +LL | +LL | const ASSOC_CONST: usize = 4; | = help: the `must_use` attribute can be applied to data types, functions, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -180,6 +212,8 @@ error: the `must_use` attribute cannot be used on associated types | LL | #[must_use] | ^^^^^^^^ +LL | +LL | type AssocTy; | = help: the `must_use` attribute can be applied to data types, functions, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -189,6 +223,8 @@ error: the `must_use` attribute cannot be used on trait methods in impl blocks | LL | #[must_use] | ^^^^^^^^ +LL | +LL | fn get_four(&self) -> usize { | = help: the `must_use` attribute can be applied to data types, foreign functions, functions, inherent methods, provided trait methods, required trait methods, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -198,6 +234,8 @@ error: the `must_use` attribute cannot be used on foreign statics | LL | #[must_use] | ^^^^^^^^ +LL | +LL | static FOREIGN_STATIC: usize; | = help: the `must_use` attribute can be applied to data types, functions, and traits = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/lint/warn-unused-inline-on-fn-prototypes.stderr b/tests/ui/lint/warn-unused-inline-on-fn-prototypes.stderr index 8f02673a03d96..09d28d6ec1f96 100644 --- a/tests/ui/lint/warn-unused-inline-on-fn-prototypes.stderr +++ b/tests/ui/lint/warn-unused-inline-on-fn-prototypes.stderr @@ -3,6 +3,8 @@ error: the `inline` attribute cannot be used on required trait methods | LL | #[inline] | ^^^^^^ +LL | +LL | fn foo(); | = help: the `inline` attribute can only be applied to functions with a body = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -17,6 +19,8 @@ error: the `inline` attribute cannot be used on foreign functions | LL | #[inline] | ^^^^^^ +LL | +LL | fn foo(); | = help: the `inline` attribute can only be applied to functions with a body = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/loop-match/invalid-attribute.stderr b/tests/ui/loop-match/invalid-attribute.stderr index 6c76d279d80c0..a79275b1f5c62 100644 --- a/tests/ui/loop-match/invalid-attribute.stderr +++ b/tests/ui/loop-match/invalid-attribute.stderr @@ -19,6 +19,8 @@ error: the `loop_match` attribute cannot be used on foreign functions | LL | #[loop_match] | ^^^^^^^^^^ +LL | #[const_continue] +LL | fn f(); | = help: the `loop_match` attribute can only be applied to loops @@ -27,6 +29,7 @@ error: the `const_continue` attribute cannot be used on foreign functions | LL | #[const_continue] | ^^^^^^^^^^^^^^ +LL | fn f(); | = help: the `const_continue` attribute can only be applied to break expressions @@ -35,6 +38,8 @@ error: the `loop_match` attribute cannot be used on structs | LL | #[loop_match] | ^^^^^^^^^^ +... +LL | struct S { | = help: the `loop_match` attribute can only be applied to loops @@ -43,6 +48,8 @@ error: the `const_continue` attribute cannot be used on structs | LL | #[const_continue] | ^^^^^^^^^^^^^^ +LL | #[repr(C)] +LL | struct S { | = help: the `const_continue` attribute can only be applied to break expressions @@ -51,6 +58,8 @@ error: the `loop_match` attribute cannot be used on required trait methods | LL | #[loop_match] | ^^^^^^^^^^ +LL | #[const_continue] +LL | extern "C" fn invoke(&self); | = help: the `loop_match` attribute can only be applied to loops @@ -59,6 +68,7 @@ error: the `const_continue` attribute cannot be used on required trait methods | LL | #[const_continue] | ^^^^^^^^^^^^^^ +LL | extern "C" fn invoke(&self); | = help: the `const_continue` attribute can only be applied to break expressions @@ -67,6 +77,8 @@ error: the `loop_match` attribute cannot be used on functions | LL | #[loop_match] | ^^^^^^^^^^ +LL | #[const_continue] +LL | extern "C" fn ok() {} | = help: the `loop_match` attribute can only be applied to loops @@ -75,6 +87,7 @@ error: the `const_continue` attribute cannot be used on functions | LL | #[const_continue] | ^^^^^^^^^^^^^^ +LL | extern "C" fn ok() {} | = help: the `const_continue` attribute can only be applied to break expressions @@ -83,6 +96,8 @@ error: the `loop_match` attribute cannot be used on closures | LL | #[loop_match] | ^^^^^^^^^^ +LL | #[const_continue] +LL | || {}; | = help: the `loop_match` attribute can only be applied to loops @@ -91,6 +106,7 @@ error: the `const_continue` attribute cannot be used on closures | LL | #[const_continue] | ^^^^^^^^^^^^^^ +LL | || {}; | = help: the `const_continue` attribute can only be applied to break expressions @@ -99,6 +115,8 @@ error: the `loop_match` attribute cannot be used on expressions | LL | #[loop_match] | ^^^^^^^^^^ +... +LL | 5 | = help: the `loop_match` attribute can only be applied to loops @@ -107,6 +125,8 @@ error: the `const_continue` attribute cannot be used on expressions | LL | #[const_continue] | ^^^^^^^^^^^^^^ +LL | +LL | 5 | = help: the `const_continue` attribute can only be applied to break expressions diff --git a/tests/ui/macros/issue-68060.stderr b/tests/ui/macros/issue-68060.stderr index fbcda462197c2..aa040cb3f9fee 100644 --- a/tests/ui/macros/issue-68060.stderr +++ b/tests/ui/macros/issue-68060.stderr @@ -3,6 +3,8 @@ error: the `target_feature` attribute cannot be used on closures | LL | #[target_feature(enable = "")] | ^^^^^^^^^^^^^^ +... +LL | |_| (), | = help: the `target_feature` attribute can be applied to functions and methods diff --git a/tests/ui/malformed/malformed-regressions.stderr b/tests/ui/malformed/malformed-regressions.stderr index 0dcdee9ccc990..37073a8be7f82 100644 --- a/tests/ui/malformed/malformed-regressions.stderr +++ b/tests/ui/malformed/malformed-regressions.stderr @@ -52,6 +52,8 @@ warning: the `link` attribute cannot be used on functions | LL | #[link] | ^^^^ +... +LL | fn main() {} | = help: the `link` attribute can only be applied to foreign modules = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -62,6 +64,8 @@ warning: the `link` attribute cannot be used on functions | LL | #[link = ""] | ^^^^ +... +LL | fn main() {} | = help: the `link` attribute can only be applied to foreign modules = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/marker_trait_attr/marker-attribute-on-non-trait.stderr b/tests/ui/marker_trait_attr/marker-attribute-on-non-trait.stderr index 0a9cde8461100..8082cd66cd8ce 100644 --- a/tests/ui/marker_trait_attr/marker-attribute-on-non-trait.stderr +++ b/tests/ui/marker_trait_attr/marker-attribute-on-non-trait.stderr @@ -3,6 +3,7 @@ error: the `marker` attribute cannot be used on structs | LL | #[marker] | ^^^^^^ +LL | struct Struct {} | = help: the `marker` attribute can only be applied to traits @@ -11,6 +12,7 @@ error: the `marker` attribute cannot be used on inherent impl blocks | LL | #[marker] | ^^^^^^ +LL | impl Struct {} | = help: the `marker` attribute can only be applied to traits @@ -19,6 +21,7 @@ error: the `marker` attribute cannot be used on unions | LL | #[marker] | ^^^^^^ +LL | union Union { | = help: the `marker` attribute can only be applied to traits @@ -27,6 +30,7 @@ error: the `marker` attribute cannot be used on constants | LL | #[marker] | ^^^^^^ +LL | const CONST: usize = 10; | = help: the `marker` attribute can only be applied to traits @@ -35,6 +39,7 @@ error: the `marker` attribute cannot be used on functions | LL | #[marker] | ^^^^^^ +LL | fn function() {} | = help: the `marker` attribute can only be applied to traits @@ -43,6 +48,7 @@ error: the `marker` attribute cannot be used on type aliases | LL | #[marker] | ^^^^^^ +LL | type Type = (); | = help: the `marker` attribute can only be applied to traits diff --git a/tests/ui/panic-handler/panic-handler-wrong-location.stderr b/tests/ui/panic-handler/panic-handler-wrong-location.stderr index a9c545d447c3c..26793b1b74021 100644 --- a/tests/ui/panic-handler/panic-handler-wrong-location.stderr +++ b/tests/ui/panic-handler/panic-handler-wrong-location.stderr @@ -5,6 +5,7 @@ error: the `panic_handler` attribute cannot be used on statics | LL | #[panic_handler] | ^^^^^^^^^^^^^ +LL | static X: u32 = 42; | = help: the `panic_handler` attribute can only be applied to functions diff --git a/tests/ui/pin-ergonomics/pin_v2-attr.stderr b/tests/ui/pin-ergonomics/pin_v2-attr.stderr index d58fce5e282b2..dc7e76081abb7 100644 --- a/tests/ui/pin-ergonomics/pin_v2-attr.stderr +++ b/tests/ui/pin-ergonomics/pin_v2-attr.stderr @@ -3,6 +3,7 @@ error: the `pin_v2` attribute cannot be used on macro calls | LL | #[pin_v2] | ^^^^^^ +LL | macro_def!(); | = help: the `pin_v2` attribute can only be applied to data types = note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute @@ -42,6 +43,7 @@ error: the `pin_v2` attribute cannot be used on enum variants | LL | #[pin_v2] | ^^^^^^ +LL | UnitVariant, | = help: the `pin_v2` attribute can only be applied to data types @@ -58,6 +60,7 @@ error: the `pin_v2` attribute cannot be used on struct fields | LL | #[pin_v2] | ^^^^^^ +LL | field: U, | = help: the `pin_v2` attribute can only be applied to data types @@ -66,6 +69,7 @@ error: the `pin_v2` attribute cannot be used on traits | LL | #[pin_v2] | ^^^^^^ +LL | trait Trait { | = help: the `pin_v2` attribute can only be applied to data types @@ -74,6 +78,7 @@ error: the `pin_v2` attribute cannot be used on associated consts | LL | #[pin_v2] | ^^^^^^ +LL | const ASSOC_CONST: () = (); | = help: the `pin_v2` attribute can only be applied to data types @@ -82,6 +87,7 @@ error: the `pin_v2` attribute cannot be used on associated types | LL | #[pin_v2] | ^^^^^^ +LL | type AssocType = (); | = help: the `pin_v2` attribute can only be applied to data types @@ -90,6 +96,7 @@ error: the `pin_v2` attribute cannot be used on required trait methods | LL | #[pin_v2] | ^^^^^^ +LL | fn method(); | = help: the `pin_v2` attribute can only be applied to data types @@ -98,6 +105,7 @@ error: the `pin_v2` attribute cannot be used on provided trait methods | LL | #[pin_v2] | ^^^^^^ +LL | fn method_with_body() {} | = help: the `pin_v2` attribute can only be applied to data types @@ -106,6 +114,7 @@ error: the `pin_v2` attribute cannot be used on trait aliases | LL | #[pin_v2] | ^^^^^^ +LL | trait TraitAlias = Trait; | = help: the `pin_v2` attribute can only be applied to data types @@ -114,6 +123,7 @@ error: the `pin_v2` attribute cannot be used on inherent impl blocks | LL | #[pin_v2] | ^^^^^^ +LL | impl Struct { | = help: the `pin_v2` attribute can only be applied to data types @@ -122,6 +132,7 @@ error: the `pin_v2` attribute cannot be used on delegations | LL | #[pin_v2] | ^^^^^^ +LL | reuse ::type_id; | = help: the `pin_v2` attribute can only be applied to data types @@ -130,6 +141,7 @@ error: the `pin_v2` attribute cannot be used on inherent methods | LL | #[pin_v2] | ^^^^^^ +LL | fn method() {} | = help: the `pin_v2` attribute can only be applied to data types @@ -138,6 +150,7 @@ error: the `pin_v2` attribute cannot be used on trait impl blocks | LL | #[pin_v2] | ^^^^^^ +LL | impl Trait for Enum { | = help: the `pin_v2` attribute can only be applied to data types @@ -146,6 +159,7 @@ error: the `pin_v2` attribute cannot be used on trait methods in impl blocks | LL | #[pin_v2] | ^^^^^^ +LL | fn method() {} | = help: the `pin_v2` attribute can only be applied to data types @@ -154,6 +168,7 @@ error: the `pin_v2` attribute cannot be used on extern crates | LL | #[pin_v2] | ^^^^^^ +LL | extern crate alloc; | = help: the `pin_v2` attribute can only be applied to data types @@ -162,6 +177,7 @@ error: the `pin_v2` attribute cannot be used on use statements | LL | #[pin_v2] | ^^^^^^ +LL | use std::pin::Pin; | = help: the `pin_v2` attribute can only be applied to data types @@ -170,6 +186,7 @@ error: the `pin_v2` attribute cannot be used on statics | LL | #[pin_v2] | ^^^^^^ +LL | static STATIC: () = (); | = help: the `pin_v2` attribute can only be applied to data types @@ -178,6 +195,7 @@ error: the `pin_v2` attribute cannot be used on constants | LL | #[pin_v2] | ^^^^^^ +LL | const CONST: () = (); | = help: the `pin_v2` attribute can only be applied to data types @@ -186,6 +204,7 @@ error: the `pin_v2` attribute cannot be used on functions | LL | #[pin_v2] | ^^^^^^ +LL | fn f(#[pin_v2] param: Foo) | = help: the `pin_v2` attribute can only be applied to data types @@ -202,6 +221,7 @@ error: the `pin_v2` attribute cannot be used on closures | LL | #[pin_v2] | ^^^^^^ +LL | || (); | = help: the `pin_v2` attribute can only be applied to data types @@ -210,6 +230,7 @@ error: the `pin_v2` attribute cannot be used on expressions | LL | #[pin_v2] | ^^^^^^ +LL | [(), (), ()]; | = help: the `pin_v2` attribute can only be applied to data types @@ -218,6 +239,7 @@ error: the `pin_v2` attribute cannot be used on struct fields | LL | #[pin_v2] | ^^^^^^ +LL | field: (), | = help: the `pin_v2` attribute can only be applied to data types @@ -226,6 +248,7 @@ error: the `pin_v2` attribute cannot be used on statements | LL | #[pin_v2] | ^^^^^^ +LL | let _: Foo<(), ()> = Foo::StructVariant { | = help: the `pin_v2` attribute can only be applied to data types @@ -234,6 +257,7 @@ error: the `pin_v2` attribute cannot be used on match arms | LL | #[pin_v2] | ^^^^^^ +LL | Foo::UnitVariant => {} | = help: the `pin_v2` attribute can only be applied to data types @@ -242,6 +266,7 @@ error: the `pin_v2` attribute cannot be used on pattern fields | LL | #[pin_v2] | ^^^^^^ +LL | field, | = help: the `pin_v2` attribute can only be applied to data types @@ -250,6 +275,8 @@ error: the `pin_v2` attribute cannot be used on where predicates | LL | #[pin_v2] | ^^^^^^ +LL | +LL | T:, | = help: the `pin_v2` attribute can only be applied to data types @@ -258,6 +285,7 @@ error: the `pin_v2` attribute cannot be used on modules | LL | #[pin_v2] | ^^^^^^ +LL | mod m {} | = help: the `pin_v2` attribute can only be applied to data types @@ -266,6 +294,7 @@ error: the `pin_v2` attribute cannot be used on foreign modules | LL | #[pin_v2] | ^^^^^^ +LL | extern "C" { | = help: the `pin_v2` attribute can only be applied to data types @@ -274,6 +303,7 @@ error: the `pin_v2` attribute cannot be used on foreign types | LL | #[pin_v2] | ^^^^^^ +LL | type ForeignTy; | = help: the `pin_v2` attribute can only be applied to data types @@ -282,6 +312,7 @@ error: the `pin_v2` attribute cannot be used on foreign statics | LL | #[pin_v2] | ^^^^^^ +LL | static EXTERN_STATIC: (); | = help: the `pin_v2` attribute can only be applied to data types @@ -290,6 +321,7 @@ error: the `pin_v2` attribute cannot be used on foreign functions | LL | #[pin_v2] | ^^^^^^ +LL | fn extern_fn(); | = help: the `pin_v2` attribute can only be applied to data types @@ -298,6 +330,7 @@ error: the `pin_v2` attribute cannot be used on type aliases | LL | #[pin_v2] | ^^^^^^ +LL | type Type = (); | = help: the `pin_v2` attribute can only be applied to data types @@ -306,6 +339,7 @@ error: the `pin_v2` attribute cannot be used on macro defs | LL | #[pin_v2] | ^^^^^^ +LL | macro_rules! macro_def { | = help: the `pin_v2` attribute can only be applied to data types diff --git a/tests/ui/proc-macro/ambiguous-builtin-attrs.stderr b/tests/ui/proc-macro/ambiguous-builtin-attrs.stderr index 882de640aa2f1..611721f9c6edb 100644 --- a/tests/ui/proc-macro/ambiguous-builtin-attrs.stderr +++ b/tests/ui/proc-macro/ambiguous-builtin-attrs.stderr @@ -99,6 +99,8 @@ error: the `repr(C)` attribute cannot be used on match arms | LL | #[repr(C)] | ^^^^^^^ +... +LL | _ => {} | = help: the `repr(C)` attribute can only be applied to data types diff --git a/tests/ui/proc-macro/illegal-proc-macro-derive-use.stderr b/tests/ui/proc-macro/illegal-proc-macro-derive-use.stderr index 1925eefe98c9a..2ba2042db8c21 100644 --- a/tests/ui/proc-macro/illegal-proc-macro-derive-use.stderr +++ b/tests/ui/proc-macro/illegal-proc-macro-derive-use.stderr @@ -9,6 +9,8 @@ error: the `proc_macro_derive` attribute cannot be used on structs | LL | #[proc_macro_derive(Foo)] | ^^^^^^^^^^^^^^^^^ +LL | +LL | pub struct Foo { | = help: the `proc_macro_derive` attribute can only be applied to functions diff --git a/tests/crashes/reborrow/coerce-shared-alias-projection.rs b/tests/ui/reborrow/coerce-shared-alias-projection.rs similarity index 90% rename from tests/crashes/reborrow/coerce-shared-alias-projection.rs rename to tests/ui/reborrow/coerce-shared-alias-projection.rs index 8497455de921a..0c7fa6ea7d978 100644 --- a/tests/crashes/reborrow/coerce-shared-alias-projection.rs +++ b/tests/ui/reborrow/coerce-shared-alias-projection.rs @@ -1,4 +1,7 @@ -//@ known-bug: unknown +//! Regression test for an ICE when coercing through `CoerceShared` impls whose target fields go +//! through type aliases and projections. These impls are currently rejected by coherence because +//! they have more than one non-ZST data field. + #![feature(reborrow)] #![allow(dead_code)] @@ -62,6 +65,7 @@ impl<'a, T> Clone for OuterAliasRef<'a, T> { impl<'a, T> Copy for OuterAliasRef<'a, T> {} impl<'a, T> CoerceShared> for OuterMut<'a, T> {} +//~^ ERROR struct OuterProjectionRef<'a, T: 'a> { inner: ProjectedInnerRef<'a, T>, @@ -77,6 +81,7 @@ impl<'a, T: 'a> Clone for OuterProjectionRef<'a, T> { impl<'a, T: 'a> Copy for OuterProjectionRef<'a, T> {} impl<'a, T: 'a> CoerceShared> for OuterMut<'a, T> {} +//~^ ERROR fn read_alias<'a>(outer: OuterAliasRef<'a, u32>) -> (&'a u32, usize) { (outer.inner.value, outer.tag) diff --git a/tests/ui/reborrow/coerce-shared-alias-projection.stderr b/tests/ui/reborrow/coerce-shared-alias-projection.stderr new file mode 100644 index 0000000000000..2ab03632efda7 --- /dev/null +++ b/tests/ui/reborrow/coerce-shared-alias-projection.stderr @@ -0,0 +1,26 @@ +error: implementing `CoerceShared` currently requires source and target to have at most one non-ZST reborrow data field + --> $DIR/coerce-shared-alias-projection.rs:67:1 + | +LL | impl<'a, T> CoerceShared> for OuterMut<'a, T> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^--------------------^^^^^^---------------^^^ + | | | | + | | | source type has 2 non-ZST reborrow data fields + | | target type has 2 non-ZST reborrow data fields + | in this `CoerceShared` implementation + | + = note: this is a temporary restriction until `CoerceShared` lowering supports non-trivially memcpy-compatible field layouts + +error: implementing `CoerceShared` currently requires source and target to have at most one non-ZST reborrow data field + --> $DIR/coerce-shared-alias-projection.rs:83:1 + | +LL | impl<'a, T: 'a> CoerceShared> for OuterMut<'a, T> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------------------^^^^^^---------------^^^ + | | | | + | | | source type has 2 non-ZST reborrow data fields + | | target type has 2 non-ZST reborrow data fields + | in this `CoerceShared` implementation + | + = note: this is a temporary restriction until `CoerceShared` lowering supports non-trivially memcpy-compatible field layouts + +error: aborting due to 2 previous errors + diff --git a/tests/crashes/reborrow/coerce-shared-different-layout.rs b/tests/ui/reborrow/coerce-shared-different-layout.rs similarity index 81% rename from tests/crashes/reborrow/coerce-shared-different-layout.rs rename to tests/ui/reborrow/coerce-shared-different-layout.rs index ad285bf0130d1..2f1357f1f6604 100644 --- a/tests/crashes/reborrow/coerce-shared-different-layout.rs +++ b/tests/ui/reborrow/coerce-shared-different-layout.rs @@ -1,4 +1,6 @@ -//@ known-bug: unknown +//! Regression test for an ICE when coercing through a `CoerceShared` impl whose source has more +//! data fields than its target. Coherence currently rejects such impls. + #![feature(reborrow)] #![allow(dead_code)] @@ -27,6 +29,7 @@ impl<'a, T> Clone for ImbrisRef<'a, T> { impl<'a, T> Copy for ImbrisRef<'a, T> {} impl<'a, T> CoerceShared> for ImbrisMut<'a, T> {} +//~^ ERROR fn ptr(value: ImbrisRef<'_, i32>) -> NonNull { value.ptr diff --git a/tests/ui/reborrow/coerce-shared-different-layout.stderr b/tests/ui/reborrow/coerce-shared-different-layout.stderr new file mode 100644 index 0000000000000..4ba287fd1e9b7 --- /dev/null +++ b/tests/ui/reborrow/coerce-shared-different-layout.stderr @@ -0,0 +1,14 @@ +error: implementing `CoerceShared` currently requires source and target to have at most one non-ZST reborrow data field + --> $DIR/coerce-shared-different-layout.rs:31:1 + | +LL | impl<'a, T> CoerceShared> for ImbrisMut<'a, T> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^----------------^^^^^^----------------^^^ + | | | | + | | | source type has 2 non-ZST reborrow data fields + | | target type has 1 non-ZST reborrow data fields + | in this `CoerceShared` implementation + | + = note: this is a temporary restriction until `CoerceShared` lowering supports non-trivially memcpy-compatible field layouts + +error: aborting due to 1 previous error + diff --git a/tests/crashes/reborrow/coerce-shared-marker-no-target-lifetime.rs b/tests/ui/reborrow/coerce-shared-marker-no-target-lifetime.rs similarity index 76% rename from tests/crashes/reborrow/coerce-shared-marker-no-target-lifetime.rs rename to tests/ui/reborrow/coerce-shared-marker-no-target-lifetime.rs index 3cdbf515371f2..200b583de56c8 100644 --- a/tests/crashes/reborrow/coerce-shared-marker-no-target-lifetime.rs +++ b/tests/ui/reborrow/coerce-shared-marker-no-target-lifetime.rs @@ -1,5 +1,6 @@ -//@ known-bug: unknown //@ edition: 2024 +//! Regression test for an ICE when coercing through a `CoerceShared` impl whose target has no +//! lifetime parameter. #![feature(reborrow)] @@ -17,5 +18,4 @@ fn method(_a: CustomMarkerRef) {} fn main() { let a = CustomMarker(PhantomData); method(a); - //~^ ERROR } diff --git a/tests/ui/reborrow/coerce-shared-marker-no-target-lifetime.stderr b/tests/ui/reborrow/coerce-shared-marker-no-target-lifetime.stderr new file mode 100644 index 0000000000000..267a14e60a2e9 --- /dev/null +++ b/tests/ui/reborrow/coerce-shared-marker-no-target-lifetime.stderr @@ -0,0 +1,8 @@ +error: implementing `CoerceShared` requires exactly one lifetime argument in the reborrowed type + --> $DIR/coerce-shared-marker-no-target-lifetime.rs:13:10 + | +LL | impl<'a> CoerceShared for CustomMarker<'a> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/crashes/reborrow/coerce-shared-multi-field.rs b/tests/ui/reborrow/coerce-shared-multi-field.rs similarity index 88% rename from tests/crashes/reborrow/coerce-shared-multi-field.rs rename to tests/ui/reborrow/coerce-shared-multi-field.rs index 3bf5b64064d4a..84241b30aaaa4 100644 --- a/tests/crashes/reborrow/coerce-shared-multi-field.rs +++ b/tests/ui/reborrow/coerce-shared-multi-field.rs @@ -1,4 +1,6 @@ -//@ known-bug: unknown +//! Regression test for an ICE when coercing through a `CoerceShared` impl with several non-ZST +//! data fields, which coherence currently rejects. + #![feature(reborrow)] #![allow(dead_code)] @@ -34,6 +36,7 @@ impl<'a, T> Clone for MatRef<'a, T> { impl<'a, T> Copy for MatRef<'a, T> {} impl<'a, T> CoerceShared> for MatMut<'a, T> {} +//~^ ERROR fn dims(mat: MatRef<'_, T>) -> (usize, usize, usize, usize) { let _ = mat.ptr; diff --git a/tests/ui/reborrow/coerce-shared-multi-field.stderr b/tests/ui/reborrow/coerce-shared-multi-field.stderr new file mode 100644 index 0000000000000..9953562d78988 --- /dev/null +++ b/tests/ui/reborrow/coerce-shared-multi-field.stderr @@ -0,0 +1,14 @@ +error: implementing `CoerceShared` currently requires source and target to have at most one non-ZST reborrow data field + --> $DIR/coerce-shared-multi-field.rs:38:1 + | +LL | impl<'a, T> CoerceShared> for MatMut<'a, T> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^-------------^^^^^^-------------^^^ + | | | | + | | | source type has 5 non-ZST reborrow data fields + | | target type has 5 non-ZST reborrow data fields + | in this `CoerceShared` implementation + | + = note: this is a temporary restriction until `CoerceShared` lowering supports non-trivially memcpy-compatible field layouts + +error: aborting due to 1 previous error + diff --git a/tests/crashes/reborrow/coerce-shared-nested.rs b/tests/ui/reborrow/coerce-shared-nested.rs similarity index 86% rename from tests/crashes/reborrow/coerce-shared-nested.rs rename to tests/ui/reborrow/coerce-shared-nested.rs index a916dde881ec5..30b029b5bf1c5 100644 --- a/tests/crashes/reborrow/coerce-shared-nested.rs +++ b/tests/ui/reborrow/coerce-shared-nested.rs @@ -1,4 +1,6 @@ -//@ known-bug: unknown +//! Regression test for an ICE when coercing through a `CoerceShared` impl with a nested +//! `CoerceShared` field next to another data field, which coherence currently rejects. + #![feature(reborrow)] #![allow(dead_code)] @@ -45,6 +47,7 @@ impl<'a, T> Clone for OuterRef<'a, T> { impl<'a, T> Copy for OuterRef<'a, T> {} impl<'a, T> CoerceShared> for OuterMut<'a, T> {} +//~^ ERROR fn get<'a>(outer: OuterRef<'a, i32>) -> (&'a i32, usize) { (outer.inner.value, outer.tag) diff --git a/tests/ui/reborrow/coerce-shared-nested.stderr b/tests/ui/reborrow/coerce-shared-nested.stderr new file mode 100644 index 0000000000000..3e246e6523b70 --- /dev/null +++ b/tests/ui/reborrow/coerce-shared-nested.stderr @@ -0,0 +1,14 @@ +error: implementing `CoerceShared` currently requires source and target to have at most one non-ZST reborrow data field + --> $DIR/coerce-shared-nested.rs:49:1 + | +LL | impl<'a, T> CoerceShared> for OuterMut<'a, T> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^---------------^^^^^^---------------^^^ + | | | | + | | | source type has 2 non-ZST reborrow data fields + | | target type has 2 non-ZST reborrow data fields + | in this `CoerceShared` implementation + | + = note: this is a temporary restriction until `CoerceShared` lowering supports non-trivially memcpy-compatible field layouts + +error: aborting due to 1 previous error + diff --git a/tests/crashes/reborrow/coerce-shared-tuple-phantom-position.rs b/tests/ui/reborrow/coerce-shared-tuple-phantom-position.rs similarity index 91% rename from tests/crashes/reborrow/coerce-shared-tuple-phantom-position.rs rename to tests/ui/reborrow/coerce-shared-tuple-phantom-position.rs index 0ada68c9c20f7..ca9fc23785096 100644 --- a/tests/crashes/reborrow/coerce-shared-tuple-phantom-position.rs +++ b/tests/ui/reborrow/coerce-shared-tuple-phantom-position.rs @@ -1,4 +1,6 @@ -//@ known-bug: unknown +//! Regression test for an ICE when coercing through `CoerceShared` impls whose tuple fields put +//! `PhantomData` at different positions in the source and the target. + #![feature(reborrow)] #![allow(dead_code)] @@ -9,6 +11,7 @@ struct SourceLeadingMut<'a, T>(PhantomData<&'a mut T>, &'a mut T); impl<'a, T> Reborrow for SourceLeadingMut<'a, T> {} struct SourceLeadingRef<'a, T>(&'a T); +//~^ ERROR impl<'a, T> Clone for SourceLeadingRef<'a, T> { fn clone(&self) -> Self { @@ -25,6 +28,7 @@ struct TargetLeadingMut<'a, T>(&'a mut T); impl<'a, T> Reborrow for TargetLeadingMut<'a, T> {} struct TargetLeadingRef<'a, T>(PhantomData<&'a T>, &'a T); +//~^ ERROR impl<'a, T> Clone for TargetLeadingRef<'a, T> { fn clone(&self) -> Self { @@ -46,6 +50,7 @@ struct InterleavedMut<'a, T, U>( impl<'a, T, U> Reborrow for InterleavedMut<'a, T, U> {} struct InterleavedRef<'a, T, U>(&'a T, PhantomData<&'a T>, &'a U, PhantomData<&'a U>); +//~^ ERROR impl<'a, T, U> Clone for InterleavedRef<'a, T, U> { fn clone(&self) -> Self { diff --git a/tests/ui/reborrow/coerce-shared-tuple-phantom-position.stderr b/tests/ui/reborrow/coerce-shared-tuple-phantom-position.stderr new file mode 100644 index 0000000000000..880e4212b74a1 --- /dev/null +++ b/tests/ui/reborrow/coerce-shared-tuple-phantom-position.stderr @@ -0,0 +1,29 @@ +error: implementing `CoerceShared` requires every target field to have a corresponding source field + --> $DIR/coerce-shared-tuple-phantom-position.rs:13:32 + | +LL | struct SourceLeadingRef<'a, T>(&'a T); + | ^^^^^ target field `0` has no corresponding source field +... +LL | impl<'a, T> CoerceShared> for SourceLeadingMut<'a, T> {} + | ----------------------- source type `SourceLeadingMut` does not contain field `0` + +error: implementing `CoerceShared` requires every target field to have a corresponding source field + --> $DIR/coerce-shared-tuple-phantom-position.rs:30:52 + | +LL | struct TargetLeadingRef<'a, T>(PhantomData<&'a T>, &'a T); + | ^^^^^ target field `1` has no corresponding source field +... +LL | impl<'a, T> CoerceShared> for TargetLeadingMut<'a, T> {} + | ----------------------- source type `TargetLeadingMut` does not contain field `1` + +error: implementing `CoerceShared` requires every target field to have a corresponding source field + --> $DIR/coerce-shared-tuple-phantom-position.rs:52:33 + | +LL | struct InterleavedRef<'a, T, U>(&'a T, PhantomData<&'a T>, &'a U, PhantomData<&'a U>); + | ^^^^^ target field `0` has no corresponding source field +... +LL | impl<'a, T, U> CoerceShared> for InterleavedMut<'a, T, U> {} + | ------------------------ source type `InterleavedMut` does not contain field `0` + +error: aborting due to 3 previous errors + diff --git a/tests/crashes/reborrow/corrected-field-mismatch-coerce-shared-issue-156315.rs b/tests/ui/reborrow/corrected-field-mismatch-coerce-shared.rs similarity index 63% rename from tests/crashes/reborrow/corrected-field-mismatch-coerce-shared-issue-156315.rs rename to tests/ui/reborrow/corrected-field-mismatch-coerce-shared.rs index 59e76ec36ab90..90bb578779666 100644 --- a/tests/crashes/reborrow/corrected-field-mismatch-coerce-shared-issue-156315.rs +++ b/tests/ui/reborrow/corrected-field-mismatch-coerce-shared.rs @@ -1,4 +1,6 @@ -//@ known-bug: unknown +//! Regression test for an ICE in borrowck when a `CoerceShared` coercion goes through an impl +//! whose target field does not correspond to the source field. +//! See . #![feature(reborrow)] diff --git a/tests/ui/reborrow/corrected-field-mismatch-coerce-shared.stderr b/tests/ui/reborrow/corrected-field-mismatch-coerce-shared.stderr new file mode 100644 index 0000000000000..48e92e04143d4 --- /dev/null +++ b/tests/ui/reborrow/corrected-field-mismatch-coerce-shared.stderr @@ -0,0 +1,14 @@ +error: implementing `CoerceShared` requires corresponding fields to match, be reborrowable with `CoerceShared`, or coerce a mutable reference field to a shared reference field + --> $DIR/corrected-field-mismatch-coerce-shared.rs:13:25 + | +LL | struct CustomMut<'a, T>(&'a mut T); + | --------- source field `0` has type `&'a mut T` +... +LL | struct CustomRef<'a, T>(&'a CustomMut<'a, T>); + | ^^^^^^^^^^^^^^^^^^^^ target field `0` has type `&'a CustomMut<'a, T>` +... +LL | impl<'a, T> CoerceShared> for CustomMut<'a, T> {} + | ------------------------------------------------------------------ required by this `CoerceShared` implementation + +error: aborting due to 1 previous error + diff --git a/tests/ui/reborrow/invalid-coerce-shared-in-const.rs b/tests/ui/reborrow/invalid-coerce-shared-in-const.rs new file mode 100644 index 0000000000000..b5b570cf4f9ec --- /dev/null +++ b/tests/ui/reborrow/invalid-coerce-shared-in-const.rs @@ -0,0 +1,22 @@ +//! Regression test for an ICE in const eval when a `CoerceShared` coercion goes through an impl +//! that coherence has already rejected. +//! See . + +#![feature(const_block_items)] +#![feature(reborrow)] +use std::marker::CoerceShared; +struct MyMut<'a>(&'a u8); +struct MyRef<'a> { + x: &'a (), + y: &'a (), +} + +impl<'a> CoerceShared> for MyMut<'a> {} +//~^ ERROR implementing `CoerceShared` requires source and target structs to use the same field style +const { + let value = 1; + foo(MyMut(&value)); +} +const fn foo(x: MyRef) {} + +fn main() {} diff --git a/tests/ui/reborrow/invalid-coerce-shared-in-const.stderr b/tests/ui/reborrow/invalid-coerce-shared-in-const.stderr new file mode 100644 index 0000000000000..76570b1f8e802 --- /dev/null +++ b/tests/ui/reborrow/invalid-coerce-shared-in-const.stderr @@ -0,0 +1,8 @@ +error: implementing `CoerceShared` requires source and target structs to use the same field style + --> $DIR/invalid-coerce-shared-in-const.rs:14:1 + | +LL | impl<'a> CoerceShared> for MyMut<'a> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/reborrow/invalid-coerce-shared-next-solver.rs b/tests/ui/reborrow/invalid-coerce-shared-next-solver.rs new file mode 100644 index 0000000000000..2b9e61aac2ea9 --- /dev/null +++ b/tests/ui/reborrow/invalid-coerce-shared-next-solver.rs @@ -0,0 +1,24 @@ +//@ compile-flags: -Znext-solver=globally +//! Regression test for an ICE in borrowck under the next solver when a `CoerceShared` coercion +//! goes through an impl that coherence has already rejected. +//! See . + +#![feature(reborrow)] +use std::marker::{CoerceShared, Reborrow}; + +struct CustomMut<'a, T>(&'a mut T); + +impl<'a, T> CoerceShared for CustomMut<'reborrow, T> {} +//~^ ERROR E0261 +//~| ERROR E0107 +//~| ERROR E0377 + +struct CustomRef<'a, T>(&'CustomMut T); +//~^ ERROR E0261 + +fn method(_a: CustomRef<'_, ()>) {} + +fn main() { + let a = CustomMut(&mut ()); + method(a); +} diff --git a/tests/ui/reborrow/invalid-coerce-shared-next-solver.stderr b/tests/ui/reborrow/invalid-coerce-shared-next-solver.stderr new file mode 100644 index 0000000000000..cec4602ecc37f --- /dev/null +++ b/tests/ui/reborrow/invalid-coerce-shared-next-solver.stderr @@ -0,0 +1,43 @@ +error[E0261]: use of undeclared lifetime name `'reborrow` + --> $DIR/invalid-coerce-shared-next-solver.rs:11:40 + | +LL | impl<'a, T> CoerceShared for CustomMut<'reborrow, T> {} + | ^^^^^^^^^ undeclared lifetime + | +help: consider introducing lifetime `'reborrow` here + | +LL | impl<'reborrow, 'a, T> CoerceShared for CustomMut<'reborrow, T> {} + | ++++++++++ + +error[E0261]: use of undeclared lifetime name `'CustomMut` + --> $DIR/invalid-coerce-shared-next-solver.rs:16:26 + | +LL | struct CustomRef<'a, T>(&'CustomMut T); + | ^^^^^^^^^^ undeclared lifetime + | +help: consider introducing lifetime `'CustomMut` here + | +LL | struct CustomRef<'CustomMut, 'a, T>(&'CustomMut T); + | +++++++++++ + +error[E0107]: missing generics for trait `CoerceShared` + --> $DIR/invalid-coerce-shared-next-solver.rs:11:13 + | +LL | impl<'a, T> CoerceShared for CustomMut<'reborrow, T> {} + | ^^^^^^^^^^^^ expected 1 generic argument + | +help: add missing generic argument + | +LL | impl<'a, T> CoerceShared for CustomMut<'reborrow, T> {} + | ++++++++ + +error[E0377]: the trait `CoerceShared` may only be implemented for a coercion between structures + --> $DIR/invalid-coerce-shared-next-solver.rs:11:1 + | +LL | impl<'a, T> CoerceShared for CustomMut<'reborrow, T> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0107, E0261, E0377. +For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/reborrow/invalid-coerce-shared-non-ref-target-field.rs b/tests/ui/reborrow/invalid-coerce-shared-non-ref-target-field.rs new file mode 100644 index 0000000000000..0f726e38792ff --- /dev/null +++ b/tests/ui/reborrow/invalid-coerce-shared-non-ref-target-field.rs @@ -0,0 +1,33 @@ +//! Regression test for an ICE in borrowck when a `CoerceShared` coercion goes through an impl +//! that maps a `&mut T` field to a field that is not a reference. +//! See . + +//! Test that a custom mut type (a wrapper over &mut T) implementing CoerceShared can be coerced +//! into its target. + +#![feature(reborrow)] +use std::marker::{CoerceShared, Reborrow}; + +#[allow(unused)] +struct CustomMut<'a, T>(&'a mut T); +impl<'a, T> Reborrow for CustomMut<'a, T> {} +impl<'a, T> CoerceShared> for CustomMut<'a, T> {} + +struct CustomRef<'a, T>([T; [16, 1usize]]); +//~^ ERROR E0308 +//~| ERROR implementing `CoerceShared` requires corresponding fields to match, be reborrowable with `CoerceShared`, or coerce a mutable reference field to a shared reference field +//~| ERROR E0392 + +impl<'a, T> Clone for CustomRef<'a, T> { + fn clone(&self) -> Self { + Self(self.0) + } +} +impl<'a, T> Copy for CustomRef<'a, T> {} + +fn method(_a: CustomRef<'_, ()>) {} + +fn main() { + let a = CustomMut(&mut ()); + method(a); +} diff --git a/tests/ui/reborrow/invalid-coerce-shared-non-ref-target-field.stderr b/tests/ui/reborrow/invalid-coerce-shared-non-ref-target-field.stderr new file mode 100644 index 0000000000000..b3701d2203215 --- /dev/null +++ b/tests/ui/reborrow/invalid-coerce-shared-non-ref-target-field.stderr @@ -0,0 +1,32 @@ +error[E0308]: mismatched types + --> $DIR/invalid-coerce-shared-non-ref-target-field.rs:16:29 + | +LL | struct CustomRef<'a, T>([T; [16, 1usize]]); + | ^^^^^^^^^^^^ expected `usize`, found `[usize; 2]` + | + = note: array length can only be `usize` + +error: implementing `CoerceShared` requires corresponding fields to match, be reborrowable with `CoerceShared`, or coerce a mutable reference field to a shared reference field + --> $DIR/invalid-coerce-shared-non-ref-target-field.rs:16:25 + | +LL | struct CustomMut<'a, T>(&'a mut T); + | --------- source field `0` has type `&'a mut T` +LL | impl<'a, T> Reborrow for CustomMut<'a, T> {} +LL | impl<'a, T> CoerceShared> for CustomMut<'a, T> {} + | ------------------------------------------------------------------ required by this `CoerceShared` implementation +LL | +LL | struct CustomRef<'a, T>([T; [16, 1usize]]); + | ^^^^^^^^^^^^^^^^^ target field `0` has type `[T; [16, 1usize]]` + +error[E0392]: lifetime parameter `'a` is never used + --> $DIR/invalid-coerce-shared-non-ref-target-field.rs:16:18 + | +LL | struct CustomRef<'a, T>([T; [16, 1usize]]); + | ^^ unused lifetime parameter + | + = help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0308, E0392. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/reborrow/invalid-coerce-shared-static-mut-field.rs b/tests/ui/reborrow/invalid-coerce-shared-static-mut-field.rs new file mode 100644 index 0000000000000..590f6fd3e3754 --- /dev/null +++ b/tests/ui/reborrow/invalid-coerce-shared-static-mut-field.rs @@ -0,0 +1,36 @@ +//! Regression test for an ICE in borrowck when a `CoerceShared` coercion goes through an impl +//! whose source contains a `&'static mut` field. +//! See . + +#![feature(reborrow)] +#![allow(dead_code)] + +use std::marker::{CoerceShared, Reborrow}; + +struct ReorderMut<'a> { + a: &'static mut u8, + b: &'a mut u16, +} + +impl<'a> Reborrow for ReorderMut<'a> {} + +#[derive(Clone, Copy)] +struct ReorderRef<'a> { + b: &'a u16, + a: &'a u8, + //~^ ERROR implementing `CoerceShared` requires corresponding fields to match, be reborrowable with `CoerceShared`, or coerce a mutable reference field to a shared reference field +} + +impl<'a> CoerceShared> for ReorderMut<'a> {} + +fn read(value: ReorderRef<'_>) -> (u16, u8) { + (*value.b, *value.a) +} + +fn main() { + let mut a = 1; + let mut b = 2; + let wrapped = ReorderMut { a: &mut a, b: &mut b }; + + assert_eq!(read(wrapped), (2, 1)); +} diff --git a/tests/ui/reborrow/invalid-coerce-shared-static-mut-field.stderr b/tests/ui/reborrow/invalid-coerce-shared-static-mut-field.stderr new file mode 100644 index 0000000000000..d4d086e3d143e --- /dev/null +++ b/tests/ui/reborrow/invalid-coerce-shared-static-mut-field.stderr @@ -0,0 +1,14 @@ +error: implementing `CoerceShared` requires corresponding fields to match, be reborrowable with `CoerceShared`, or coerce a mutable reference field to a shared reference field + --> $DIR/invalid-coerce-shared-static-mut-field.rs:20:5 + | +LL | a: &'static mut u8, + | ------------------ source field `a` has type `&'static mut u8` +... +LL | a: &'a u8, + | ^^^^^^^^^ target field `a` has type `&'a u8` +... +LL | impl<'a> CoerceShared> for ReorderMut<'a> {} + | ----------------------------------------------------------- required by this `CoerceShared` implementation + +error: aborting due to 1 previous error + diff --git a/tests/ui/reborrow/invalid-reborrow-derive-const-param.rs b/tests/ui/reborrow/invalid-reborrow-derive-const-param.rs new file mode 100644 index 0000000000000..f929f30b8d0db --- /dev/null +++ b/tests/ui/reborrow/invalid-reborrow-derive-const-param.rs @@ -0,0 +1,17 @@ +//! Regression test for an ICE in borrowck when a derived `Reborrow` impl is rejected because the +//! type has no lifetime parameter. The issue's own reproducer no longer reaches borrowck (its +//! features were renamed and its `{ (1, _) }` argument is now rejected earlier), so this is a +//! reduced variant that still hits the same ICE. +//! See . + +#![feature(reborrow)] + +use std::marker::Reborrow; + +#[derive(Reborrow)] +//~^ ERROR implementing `Reborrow` requires that a single lifetime parameter is passed between source and target +struct S; + +fn main() { + let _: S<1> = S::<1>; +} diff --git a/tests/ui/reborrow/invalid-reborrow-derive-const-param.stderr b/tests/ui/reborrow/invalid-reborrow-derive-const-param.stderr new file mode 100644 index 0000000000000..15c00224dd8f5 --- /dev/null +++ b/tests/ui/reborrow/invalid-reborrow-derive-const-param.stderr @@ -0,0 +1,8 @@ +error: implementing `Reborrow` requires that a single lifetime parameter is passed between source and target + --> $DIR/invalid-reborrow-derive-const-param.rs:11:10 + | +LL | #[derive(Reborrow)] + | ^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/reborrow/invalid-reborrow-impl-no-lifetime.rs b/tests/ui/reborrow/invalid-reborrow-impl-no-lifetime.rs new file mode 100644 index 0000000000000..bf9ebb7ce9e08 --- /dev/null +++ b/tests/ui/reborrow/invalid-reborrow-impl-no-lifetime.rs @@ -0,0 +1,19 @@ +//! Regression test for an ICE in borrowck when a `Reborrow` coercion goes through an impl +//! that coherence has already rejected. +//! See . + +#![feature(reborrow)] + +use std::marker::Reborrow; + +struct Thing; + +impl<'a> Reborrow for Thing {} +//~^ ERROR implementing `Reborrow` requires exactly one lifetime argument in the reborrowed type + +fn foo(_: Thing) {} + +fn main() { + let x = Thing; + foo(x); +} diff --git a/tests/ui/reborrow/invalid-reborrow-impl-no-lifetime.stderr b/tests/ui/reborrow/invalid-reborrow-impl-no-lifetime.stderr new file mode 100644 index 0000000000000..409ede2dd7035 --- /dev/null +++ b/tests/ui/reborrow/invalid-reborrow-impl-no-lifetime.stderr @@ -0,0 +1,8 @@ +error: implementing `Reborrow` requires exactly one lifetime argument in the reborrowed type + --> $DIR/invalid-reborrow-impl-no-lifetime.rs:11:1 + | +LL | impl<'a> Reborrow for Thing {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/reborrow/invalid-reborrow-impl-phantom-data-wrong-generics.rs b/tests/ui/reborrow/invalid-reborrow-impl-phantom-data-wrong-generics.rs new file mode 100644 index 0000000000000..aab853fbe9c9d --- /dev/null +++ b/tests/ui/reborrow/invalid-reborrow-impl-phantom-data-wrong-generics.rs @@ -0,0 +1,16 @@ +//! Regression test for an ICE in borrowck when a type is reborrowed through a `Reborrow` impl +//! that coherence has already rejected. +//! See . + +#![feature(reborrow)] +use std::marker::{PhantomData, Reborrow}; + +struct CustomMarker<'a>(PhantomData<&'a ()>); +impl<'a> Reborrow for PhantomData<'a> {} +//~^ ERROR E0107 +//~| ERROR E0107 +//~| ERROR implementing `Reborrow` requires exactly one lifetime argument in the reborrowed type + +fn main() { + let mut a = CustomMarker(PhantomData); +} diff --git a/tests/ui/reborrow/invalid-reborrow-impl-phantom-data-wrong-generics.stderr b/tests/ui/reborrow/invalid-reborrow-impl-phantom-data-wrong-generics.stderr new file mode 100644 index 0000000000000..9f9bd5008c81e --- /dev/null +++ b/tests/ui/reborrow/invalid-reborrow-impl-phantom-data-wrong-generics.stderr @@ -0,0 +1,28 @@ +error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supplied + --> $DIR/invalid-reborrow-impl-phantom-data-wrong-generics.rs:9:23 + | +LL | impl<'a> Reborrow for PhantomData<'a> {} + | ^^^^^^^^^^^---- help: remove the unnecessary generics + | | + | expected 0 lifetime arguments + +error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied + --> $DIR/invalid-reborrow-impl-phantom-data-wrong-generics.rs:9:23 + | +LL | impl<'a> Reborrow for PhantomData<'a> {} + | ^^^^^^^^^^^ expected 1 generic argument + | +help: add missing generic argument + | +LL | impl<'a> Reborrow for PhantomData<'a, T> {} + | +++ + +error: implementing `Reborrow` requires exactly one lifetime argument in the reborrowed type + --> $DIR/invalid-reborrow-impl-phantom-data-wrong-generics.rs:9:1 + | +LL | impl<'a> Reborrow for PhantomData<'a> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0107`. diff --git a/tests/crashes/reborrow/missing-generic-args-coerce-shared-issue-156315.rs b/tests/ui/reborrow/missing-generic-args-coerce-shared.rs similarity index 76% rename from tests/crashes/reborrow/missing-generic-args-coerce-shared-issue-156315.rs rename to tests/ui/reborrow/missing-generic-args-coerce-shared.rs index d365986901fe3..afde7c8ba8b9c 100644 --- a/tests/crashes/reborrow/missing-generic-args-coerce-shared-issue-156315.rs +++ b/tests/ui/reborrow/missing-generic-args-coerce-shared.rs @@ -1,4 +1,7 @@ -//@ known-bug: unknown +//! Regression test for an ICE in borrowck when a `CoerceShared` target field is missing generic +//! arguments. +//! See . + #![feature(reborrow)] // Malformed no-ICE regression: this intentionally keeps the missing generic arguments from the diff --git a/tests/ui/reborrow/missing-generic-args-coerce-shared.stderr b/tests/ui/reborrow/missing-generic-args-coerce-shared.stderr new file mode 100644 index 0000000000000..5fee90e841217 --- /dev/null +++ b/tests/ui/reborrow/missing-generic-args-coerce-shared.stderr @@ -0,0 +1,43 @@ +error[E0106]: missing lifetime specifier + --> $DIR/missing-generic-args-coerce-shared.rs:17:29 + | +LL | struct CustomRef<'a, T>(&'a CustomMut); + | ^^^^^^^^^ expected named lifetime parameter + | +help: consider using the `'a` lifetime + | +LL | struct CustomRef<'a, T>(&'a CustomMut<'a>); + | ++++ + +error[E0107]: missing generics for struct `CustomMut` + --> $DIR/missing-generic-args-coerce-shared.rs:17:29 + | +LL | struct CustomRef<'a, T>(&'a CustomMut); + | ^^^^^^^^^ expected 1 generic argument + | +note: struct defined here, with 1 generic parameter: `T` + --> $DIR/missing-generic-args-coerce-shared.rs:12:8 + | +LL | struct CustomMut<'a, T>(&'a mut T); + | ^^^^^^^^^ - +help: add missing generic argument + | +LL | struct CustomRef<'a, T>(&'a CustomMut); + | +++ + +error: implementing `CoerceShared` requires corresponding fields to match, be reborrowable with `CoerceShared`, or coerce a mutable reference field to a shared reference field + --> $DIR/missing-generic-args-coerce-shared.rs:17:25 + | +LL | struct CustomMut<'a, T>(&'a mut T); + | --------- source field `0` has type `&'a mut T` +... +LL | impl<'a, T> CoerceShared> for CustomMut<'a, T> {} + | ------------------------------------------------------------------ required by this `CoerceShared` implementation +LL | +LL | struct CustomRef<'a, T>(&'a CustomMut); + | ^^^^^^^^^^^^^ target field `0` has type `&'a CustomMut<'_, {type error}>` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0106, E0107. +For more information about an error, try `rustc --explain E0106`. diff --git a/tests/ui/repr/attr-usage-repr.stderr b/tests/ui/repr/attr-usage-repr.stderr index 3f34e2a3bc3ee..d5e5cfe4958a9 100644 --- a/tests/ui/repr/attr-usage-repr.stderr +++ b/tests/ui/repr/attr-usage-repr.stderr @@ -3,6 +3,7 @@ error: the `repr(C)` attribute cannot be used on functions | LL | #[repr(C)] | ^^^^^^^ +LL | fn f() {} | = help: the `repr(C)` attribute can only be applied to data types @@ -11,6 +12,7 @@ error: the `repr(i8)` attribute cannot be used on structs | LL | #[repr(i8)] | ^^^^^^^^ +LL | struct SInt(f64, f64); | = help: the `repr(i8)` attribute can only be applied to enums @@ -19,6 +21,7 @@ error: the `repr(packed)` attribute cannot be used on enums | LL | #[repr(packed)] | ^^^^^^^^^^^^ +LL | enum EPacked { | = help: the `repr(packed)` attribute can be applied to structs and unions @@ -27,6 +30,7 @@ error: the `repr(simd)` attribute cannot be used on enums | LL | #[repr(simd)] | ^^^^^^^^^^ +LL | enum ESimd { | = help: the `repr(simd)` attribute can only be applied to structs @@ -35,6 +39,8 @@ error: the `repr()` attribute cannot be used on type aliases | LL | #[repr()] | ^^^^^^ +LL | +LL | type SirThisIsAType = i32; | = help: the `repr()` attribute can only be applied to data types diff --git a/tests/ui/repr/invalid-repr-on-structs-74082.stderr b/tests/ui/repr/invalid-repr-on-structs-74082.stderr index c9c89f588140a..620da0d447986 100644 --- a/tests/ui/repr/invalid-repr-on-structs-74082.stderr +++ b/tests/ui/repr/invalid-repr-on-structs-74082.stderr @@ -3,6 +3,7 @@ error: the `repr(i128)` attribute cannot be used on structs | LL | #[repr(i128)] | ^^^^^^^^^^ +LL | struct Foo; | = help: the `repr(i128)` attribute can only be applied to enums @@ -11,6 +12,7 @@ error: the `repr(u128)` attribute cannot be used on structs | LL | #[repr(u128)] | ^^^^^^^^^^ +LL | struct Bar; | = help: the `repr(u128)` attribute can only be applied to enums diff --git a/tests/ui/repr/issue-83505-repr-simd.stderr b/tests/ui/repr/issue-83505-repr-simd.stderr index c6da78ea48c0f..72b9fdcd9247b 100644 --- a/tests/ui/repr/issue-83505-repr-simd.stderr +++ b/tests/ui/repr/issue-83505-repr-simd.stderr @@ -21,6 +21,8 @@ error: the `repr(simd)` attribute cannot be used on enums | LL | #[repr(simd)] | ^^^^^^^^^^ +... +LL | enum Es {} | = help: the `repr(simd)` attribute can only be applied to structs diff --git a/tests/ui/repr/repr-disallow-on-variant.stderr b/tests/ui/repr/repr-disallow-on-variant.stderr index 4b7b345ac2624..535228586c95a 100644 --- a/tests/ui/repr/repr-disallow-on-variant.stderr +++ b/tests/ui/repr/repr-disallow-on-variant.stderr @@ -3,6 +3,8 @@ error: the `repr(u8)` attribute cannot be used on enum variants | LL | #[repr(u8)] | ^^^^^^^^ +LL | +LL | Variant, | = help: the `repr(u8)` attribute can only be applied to enums diff --git a/tests/ui/repr/repr-empty-packed.stderr b/tests/ui/repr/repr-empty-packed.stderr index 1636242c18c77..d8492d6f3aa1e 100644 --- a/tests/ui/repr/repr-empty-packed.stderr +++ b/tests/ui/repr/repr-empty-packed.stderr @@ -3,6 +3,7 @@ error: the `repr(packed)` attribute cannot be used on enums | LL | #[repr(packed)] | ^^^^^^^^^^^^ +LL | pub enum Foo { | = help: the `repr(packed)` attribute can be applied to structs and unions diff --git a/tests/ui/repr/repr-transparent-other-items.stderr b/tests/ui/repr/repr-transparent-other-items.stderr index 82623ec47c83d..be8c538485f20 100644 --- a/tests/ui/repr/repr-transparent-other-items.stderr +++ b/tests/ui/repr/repr-transparent-other-items.stderr @@ -3,6 +3,7 @@ error: the `repr(transparent)` attribute cannot be used on functions | LL | #[repr(transparent)] | ^^^^^^^^^^^^^^^^^ +LL | fn cant_repr_this() {} | = help: the `repr(transparent)` attribute can only be applied to data types @@ -11,6 +12,7 @@ error: the `repr(transparent)` attribute cannot be used on statics | LL | #[repr(transparent)] | ^^^^^^^^^^^^^^^^^ +LL | static CANT_REPR_THIS: u32 = 0; | = help: the `repr(transparent)` attribute can only be applied to data types diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/invalid-attribute.stderr b/tests/ui/rfcs/rfc-2008-non-exhaustive/invalid-attribute.stderr index 09a6d30a0d9f1..ea5f1bd01b6fb 100644 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/invalid-attribute.stderr +++ b/tests/ui/rfcs/rfc-2008-non-exhaustive/invalid-attribute.stderr @@ -17,6 +17,8 @@ error: the `non_exhaustive` attribute cannot be used on traits | LL | #[non_exhaustive] | ^^^^^^^^^^^^^^ +LL | +LL | trait Bar { } | = help: the `non_exhaustive` attribute can be applied to data types and enum variants @@ -25,6 +27,8 @@ error: the `non_exhaustive` attribute cannot be used on unions | LL | #[non_exhaustive] | ^^^^^^^^^^^^^^ +LL | +LL | union Baz { | = help: the `non_exhaustive` attribute can be applied to enum variants, enums, and structs diff --git a/tests/ui/rfcs/rfc-2091-track-caller/macro-declaration.stderr b/tests/ui/rfcs/rfc-2091-track-caller/macro-declaration.stderr index d80d55064f639..9d789b42895f8 100644 --- a/tests/ui/rfcs/rfc-2091-track-caller/macro-declaration.stderr +++ b/tests/ui/rfcs/rfc-2091-track-caller/macro-declaration.stderr @@ -3,6 +3,8 @@ warning: the `track_caller` attribute cannot be used on macro defs | LL | #[track_caller] | ^^^^^^^^^^^^ +... +LL | macro_rules! _foo { | = help: the `track_caller` attribute can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/rfcs/rfc-2091-track-caller/only-for-fns.stderr b/tests/ui/rfcs/rfc-2091-track-caller/only-for-fns.stderr index c411acfdaa7e9..d9f5fe79312c0 100644 --- a/tests/ui/rfcs/rfc-2091-track-caller/only-for-fns.stderr +++ b/tests/ui/rfcs/rfc-2091-track-caller/only-for-fns.stderr @@ -3,6 +3,7 @@ error: the `track_caller` attribute cannot be used on structs | LL | #[track_caller] | ^^^^^^^^^^^^ +LL | struct S; | = help: the `track_caller` attribute can only be applied to functions diff --git a/tests/ui/rfcs/rfc-2565-param-attrs/param-attrs-builtin-attrs.stderr b/tests/ui/rfcs/rfc-2565-param-attrs/param-attrs-builtin-attrs.stderr index db2d8f161dba0..54bf349194741 100644 --- a/tests/ui/rfcs/rfc-2565-param-attrs/param-attrs-builtin-attrs.stderr +++ b/tests/ui/rfcs/rfc-2565-param-attrs/param-attrs-builtin-attrs.stderr @@ -385,6 +385,8 @@ LL | #[no_mangle] b: i32 warning: the `must_use` attribute cannot be used on function params --> $DIR/param-attrs-builtin-attrs.rs:29:7 | +LL | /// Bar +LL | LL | #[must_use] | ^^^^^^^^ | @@ -395,6 +397,8 @@ LL | #[must_use] warning: the `no_mangle` attribute cannot be used on function params --> $DIR/param-attrs-builtin-attrs.rs:35:7 | +LL | /// Bar +... LL | #[no_mangle] b: i32, | ^^^^^^^^^ | @@ -404,6 +408,8 @@ LL | #[no_mangle] b: i32, warning: the `must_use` attribute cannot be used on function params --> $DIR/param-attrs-builtin-attrs.rs:48:7 | +LL | /// Bar +LL | LL | #[must_use] | ^^^^^^^^ | @@ -413,6 +419,8 @@ LL | #[must_use] warning: the `no_mangle` attribute cannot be used on function params --> $DIR/param-attrs-builtin-attrs.rs:54:7 | +LL | /// Bar +... LL | #[no_mangle] b: i32, | ^^^^^^^^^ | @@ -422,6 +430,8 @@ LL | #[no_mangle] b: i32, warning: the `must_use` attribute cannot be used on function params --> $DIR/param-attrs-builtin-attrs.rs:203:11 | +LL | /// Bar +LL | LL | #[must_use] | ^^^^^^^^ | @@ -431,6 +441,8 @@ LL | #[must_use] warning: the `no_mangle` attribute cannot be used on function params --> $DIR/param-attrs-builtin-attrs.rs:209:11 | +LL | /// Bar +... LL | #[no_mangle] b: i32 | ^^^^^^^^^ | @@ -440,6 +452,8 @@ LL | #[no_mangle] b: i32 warning: the `must_use` attribute cannot be used on function params --> $DIR/param-attrs-builtin-attrs.rs:139:11 | +LL | /// Baz +LL | LL | #[must_use] | ^^^^^^^^ | @@ -449,6 +463,8 @@ LL | #[must_use] warning: the `no_mangle` attribute cannot be used on function params --> $DIR/param-attrs-builtin-attrs.rs:145:11 | +LL | /// Baz +... LL | #[no_mangle] b: i32, | ^^^^^^^^^ | @@ -458,6 +474,8 @@ LL | #[no_mangle] b: i32, warning: the `must_use` attribute cannot be used on function params --> $DIR/param-attrs-builtin-attrs.rs:158:11 | +LL | /// Baz +LL | LL | #[must_use] | ^^^^^^^^ | @@ -467,6 +485,8 @@ LL | #[must_use] warning: the `no_mangle` attribute cannot be used on function params --> $DIR/param-attrs-builtin-attrs.rs:164:11 | +LL | /// Baz +... LL | #[no_mangle] b: i32, | ^^^^^^^^^ | @@ -476,6 +496,8 @@ LL | #[no_mangle] b: i32, warning: the `must_use` attribute cannot be used on function params --> $DIR/param-attrs-builtin-attrs.rs:72:11 | +LL | /// Baz +LL | LL | #[must_use] | ^^^^^^^^ | @@ -485,6 +507,8 @@ LL | #[must_use] warning: the `no_mangle` attribute cannot be used on function params --> $DIR/param-attrs-builtin-attrs.rs:78:11 | +LL | /// Baz +... LL | #[no_mangle] b: i32, | ^^^^^^^^^ | @@ -494,6 +518,8 @@ LL | #[no_mangle] b: i32, warning: the `must_use` attribute cannot be used on function params --> $DIR/param-attrs-builtin-attrs.rs:91:11 | +LL | /// Baz +LL | LL | #[must_use] | ^^^^^^^^ | @@ -503,6 +529,8 @@ LL | #[must_use] warning: the `no_mangle` attribute cannot be used on function params --> $DIR/param-attrs-builtin-attrs.rs:97:11 | +LL | /// Baz +... LL | #[no_mangle] b: i32, | ^^^^^^^^^ | @@ -512,6 +540,8 @@ LL | #[no_mangle] b: i32, warning: the `must_use` attribute cannot be used on function params --> $DIR/param-attrs-builtin-attrs.rs:116:11 | +LL | /// Baz +LL | LL | #[must_use] | ^^^^^^^^ | @@ -521,6 +551,8 @@ LL | #[must_use] warning: the `no_mangle` attribute cannot be used on function params --> $DIR/param-attrs-builtin-attrs.rs:122:11 | +LL | /// Baz +... LL | #[no_mangle] b: i32, | ^^^^^^^^^ | @@ -530,6 +562,8 @@ LL | #[no_mangle] b: i32, warning: the `must_use` attribute cannot be used on function params --> $DIR/param-attrs-builtin-attrs.rs:182:11 | +LL | /// Baz +LL | LL | #[must_use] | ^^^^^^^^ | @@ -539,6 +573,8 @@ LL | #[must_use] warning: the `no_mangle` attribute cannot be used on function params --> $DIR/param-attrs-builtin-attrs.rs:188:11 | +LL | /// Baz +... LL | #[no_mangle] b: i32, | ^^^^^^^^^ | @@ -548,6 +584,8 @@ LL | #[no_mangle] b: i32, warning: the `must_use` attribute cannot be used on function params --> $DIR/param-attrs-builtin-attrs.rs:9:11 | +LL | /// Bar +LL | LL | #[must_use] | ^^^^^^^^ | @@ -557,6 +595,8 @@ LL | #[must_use] warning: the `no_mangle` attribute cannot be used on function params --> $DIR/param-attrs-builtin-attrs.rs:15:11 | +LL | /// Bar +... LL | #[no_mangle] b: i32, | ^^^^^^^^^ | diff --git a/tests/ui/sanitize-attr/valid-sanitize.stderr b/tests/ui/sanitize-attr/valid-sanitize.stderr index be6e9ad52dd85..a5dbd749233e2 100644 --- a/tests/ui/sanitize-attr/valid-sanitize.stderr +++ b/tests/ui/sanitize-attr/valid-sanitize.stderr @@ -11,6 +11,7 @@ error: the `sanitize` attribute cannot be used on type aliases | LL | #[sanitize(address = "off")] | ^^^^^^^^ +LL | type MyTypeAlias = (); | = help: the `sanitize` attribute can be applied to crates, functions, impl blocks, modules, and statics @@ -19,6 +20,7 @@ error: the `sanitize` attribute cannot be used on traits | LL | #[sanitize(address = "off")] | ^^^^^^^^ +LL | trait MyTrait { | = help: the `sanitize` attribute can be applied to crates, functions, impl blocks, modules, and statics @@ -27,6 +29,7 @@ error: the `sanitize` attribute cannot be used on associated consts | LL | #[sanitize(address = "off")] | ^^^^^^^^ +LL | const TRAIT_ASSOC_CONST: u32; | = help: the `sanitize` attribute can be applied to crates, functions, impl blocks, modules, and statics @@ -35,6 +38,7 @@ error: the `sanitize` attribute cannot be used on associated types | LL | #[sanitize(address = "off")] | ^^^^^^^^ +LL | type TraitAssocType; | = help: the `sanitize` attribute can be applied to crates, functions, impl blocks, modules, and statics @@ -43,6 +47,7 @@ error: the `sanitize` attribute cannot be used on required trait methods | LL | #[sanitize(address = "off")] | ^^^^^^^^ +LL | fn trait_method(&self); | = help: the `sanitize` attribute can be applied to crates, functions with a body, impl blocks, modules, and statics @@ -51,6 +56,7 @@ error: the `sanitize` attribute cannot be used on required trait methods | LL | #[sanitize(address = "off")] | ^^^^^^^^ +LL | fn trait_assoc_fn(); | = help: the `sanitize` attribute can be applied to crates, functions with a body, impl blocks, modules, and statics @@ -59,6 +65,7 @@ error: the `sanitize` attribute cannot be used on associated types | LL | #[sanitize(address = "off")] | ^^^^^^^^ +LL | type TraitAssocType = Self; | = help: the `sanitize` attribute can be applied to crates, functions, impl blocks, modules, and statics @@ -67,6 +74,7 @@ error: the `sanitize` attribute cannot be used on associated types | LL | #[sanitize(address = "off")] | ^^^^^^^^ +LL | type T = impl Copy; | = help: the `sanitize` attribute can be applied to crates, functions, impl blocks, modules, and statics @@ -75,6 +83,7 @@ error: the `sanitize` attribute cannot be used on structs | LL | #[sanitize(address = "off")] | ^^^^^^^^ +LL | struct MyStruct { | = help: the `sanitize` attribute can be applied to crates, functions, impl blocks, modules, and statics @@ -83,6 +92,7 @@ error: the `sanitize` attribute cannot be used on struct fields | LL | #[sanitize(address = "off")] | ^^^^^^^^ +LL | field: u32, | = help: the `sanitize` attribute can be applied to crates, functions, impl blocks, modules, and statics @@ -91,6 +101,7 @@ error: the `sanitize` attribute cannot be used on foreign statics | LL | #[sanitize(address = "off", thread = "on")] | ^^^^^^^^ +LL | static X: u32; | = help: the `sanitize` attribute can be applied to crates, functions, impl blocks, modules, and statics @@ -99,6 +110,7 @@ error: the `sanitize` attribute cannot be used on foreign types | LL | #[sanitize(address = "off", thread = "on")] | ^^^^^^^^ +LL | type T; | = help: the `sanitize` attribute can be applied to crates, functions, impl blocks, modules, and statics @@ -107,6 +119,7 @@ error: the `sanitize` attribute cannot be used on foreign functions | LL | #[sanitize(address = "off", thread = "on")] | ^^^^^^^^ +LL | fn foreign_fn(); | = help: the `sanitize` attribute can be applied to crates, functions with a body, impl blocks, modules, and statics @@ -115,6 +128,7 @@ error: the `sanitize` attribute cannot be used on statements | LL | #[sanitize(address = "off", thread = "on")] | ^^^^^^^^ +LL | let _ = (); | = help: the `sanitize` attribute can be applied to crates, functions, impl blocks, modules, and statics @@ -123,6 +137,7 @@ error: the `sanitize` attribute cannot be used on statements | LL | #[sanitize(address = "off")] | ^^^^^^^^ +LL | let _let_closure = || (); | = help: the `sanitize` attribute can be applied to crates, functions, impl blocks, modules, and statics @@ -131,6 +146,7 @@ error: the `sanitize` attribute cannot be used on match arms | LL | #[sanitize(address = "off")] | ^^^^^^^^ +LL | () => (), | = help: the `sanitize` attribute can be applied to crates, functions, impl blocks, modules, and statics @@ -139,6 +155,7 @@ error: the `sanitize` attribute cannot be used on expressions | LL | #[sanitize(address = "off")] | ^^^^^^^^ +LL | return (); | = help: the `sanitize` attribute can be applied to crates, functions, impl blocks, modules, and statics diff --git a/tests/ui/sanitizer/cfi/invalid-attr-encoding.stderr b/tests/ui/sanitizer/cfi/invalid-attr-encoding.stderr index b1e8908cfee31..f925a27cdd669 100644 --- a/tests/ui/sanitizer/cfi/invalid-attr-encoding.stderr +++ b/tests/ui/sanitizer/cfi/invalid-attr-encoding.stderr @@ -14,6 +14,7 @@ error: the `cfi_encoding` attribute cannot be used on traits | LL | #[cfi_encoding = "Foo"] | ^^^^^^^^^^^^ +LL | pub trait X {} | = help: the `cfi_encoding` attribute can only be applied to data types @@ -22,6 +23,7 @@ error: the `cfi_encoding` attribute cannot be used on type aliases | LL | #[cfi_encoding = "Bar"] | ^^^^^^^^^^^^ +LL | pub type Y = Type1; | = help: the `cfi_encoding` attribute can only be applied to data types diff --git a/tests/ui/scalable-vectors/invalid.stderr b/tests/ui/scalable-vectors/invalid.stderr index 5d028914244df..6f47f94806a03 100644 --- a/tests/ui/scalable-vectors/invalid.stderr +++ b/tests/ui/scalable-vectors/invalid.stderr @@ -9,6 +9,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on extern crates | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | extern crate std as other_std; | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -17,6 +19,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on use statements | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | use std::vec::Vec; | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -25,6 +29,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on statics | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | static _X: u32 = 0; | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -33,6 +39,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on constants | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | const _Y: u32 = 0; | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -41,6 +49,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on modules | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | mod bar { | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -49,6 +59,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on foreign modules | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | unsafe extern "C" { | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -57,6 +69,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on foreign statics | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | static X: &'static u32; | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -65,6 +79,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on foreign types | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | type Y; | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -73,6 +89,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on foreign functions | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | fn foo(); | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -81,6 +99,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on type aliases | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | type Foo = u32; | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -89,6 +109,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on enums | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | enum Bar<#[rustc_scalable_vector(4)] T> { | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -105,6 +127,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on enum variants | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | Baz(std::marker::PhantomData), | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -113,6 +137,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on struct fields | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | field: u32, | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -121,6 +147,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on unions | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | union FooBar { | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -129,6 +157,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on traits | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | trait FooBaz { | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -137,6 +167,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on associated types | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | type Foo; | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -145,6 +177,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on associated consts | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | const Bar: i32; | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -153,6 +187,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on provided trait me | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | fn foo() {} | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -161,6 +197,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on trait aliases | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | trait FooQux = FooBaz; | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -169,6 +207,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on inherent impl blo | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | impl Bar { | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -177,6 +217,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on inherent methods | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | fn foo() {} | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -185,6 +227,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on trait impl blocks | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | impl FooBaz for Bar { | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -193,6 +237,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on macro defs | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | macro_rules! barqux { ($foo:tt) => { $foo }; } | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -201,6 +247,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on functions | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | fn barqux(#[rustc_scalable_vector(4)] _x: u32) {} | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -217,6 +265,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on functions | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | async fn async_foo() {} | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -225,6 +275,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on functions | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | gen fn gen_foo() {} | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -233,6 +285,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on functions | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | async gen fn async_gen_foo() {} | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -257,6 +311,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on statements | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | let _z = 3; | = help: the `rustc_scalable_vector` attribute can only be applied to structs @@ -265,6 +321,8 @@ error: the `rustc_scalable_vector` attribute cannot be used on match arms | LL | #[rustc_scalable_vector(4)] | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | 1 => (), | = help: the `rustc_scalable_vector` attribute can only be applied to structs diff --git a/tests/ui/simd/repr-simd-on-enum.stderr b/tests/ui/simd/repr-simd-on-enum.stderr index 87f53f712c0e3..730ee499dca30 100644 --- a/tests/ui/simd/repr-simd-on-enum.stderr +++ b/tests/ui/simd/repr-simd-on-enum.stderr @@ -3,6 +3,7 @@ error: the `repr(simd)` attribute cannot be used on enums | LL | #[repr(simd)] | ^^^^^^^^^^ +LL | enum Aligned { | = help: the `repr(simd)` attribute can only be applied to structs diff --git a/tests/ui/splat/splat-non-fn-arg.stderr b/tests/ui/splat/splat-non-fn-arg.stderr index 64efa7238d56b..a227cf097be06 100644 --- a/tests/ui/splat/splat-non-fn-arg.stderr +++ b/tests/ui/splat/splat-non-fn-arg.stderr @@ -3,6 +3,7 @@ error: the `rustc_splat` attribute cannot be used on functions | LL | #[rustc_splat] | ^^^^^^^^^^^ +LL | fn tuple_args_bad((a, b): (u32, i8)) {} | = help: the `rustc_splat` attribute can only be applied to function params @@ -11,6 +12,7 @@ error: the `rustc_splat` attribute cannot be used on traits | LL | #[rustc_splat] | ^^^^^^^^^^^ +LL | trait FooTraitBad { | = help: the `rustc_splat` attribute can only be applied to function params @@ -19,6 +21,7 @@ error: the `rustc_splat` attribute cannot be used on inherent impl blocks | LL | #[rustc_splat] | ^^^^^^^^^^^ +LL | impl Foo { | = help: the `rustc_splat` attribute can only be applied to function params @@ -27,6 +30,7 @@ error: the `rustc_splat` attribute cannot be used on inherent methods | LL | #[rustc_splat] | ^^^^^^^^^^^ +LL | fn tuple_3_bad((a, b, c): (u32, i32, i8)) {} | = help: the `rustc_splat` attribute can only be applied to function params @@ -35,6 +39,7 @@ error: the `rustc_splat` attribute cannot be used on inherent methods | LL | #[rustc_splat] | ^^^^^^^^^^^ +LL | fn tuple_2_bad(self, (a, b): (u32, i8)) -> u32 { | = help: the `rustc_splat` attribute can only be applied to function params @@ -43,6 +48,7 @@ error: the `rustc_splat` attribute cannot be used on trait impl blocks | LL | #[rustc_splat] | ^^^^^^^^^^^ +LL | impl FooTraitBad for Foo { | = help: the `rustc_splat` attribute can only be applied to function params @@ -51,6 +57,7 @@ error: the `rustc_splat` attribute cannot be used on foreign modules | LL | #[rustc_splat] | ^^^^^^^^^^^ +LL | extern "C" { | = help: the `rustc_splat` attribute can only be applied to function params @@ -59,6 +66,7 @@ error: the `rustc_splat` attribute cannot be used on foreign functions | LL | #[rustc_splat] | ^^^^^^^^^^^ +LL | fn bar_2_bad(_: (u32, i8)); | = help: the `rustc_splat` attribute can only be applied to function params @@ -67,6 +75,7 @@ error: the `rustc_splat` attribute cannot be used on modules | LL | #[rustc_splat] | ^^^^^^^^^^^ +LL | mod foo_mod {} | = help: the `rustc_splat` attribute can only be applied to function params @@ -75,6 +84,7 @@ error: the `rustc_splat` attribute cannot be used on use statements | LL | #[rustc_splat] | ^^^^^^^^^^^ +LL | use std::mem; | = help: the `rustc_splat` attribute can only be applied to function params @@ -83,6 +93,7 @@ error: the `rustc_splat` attribute cannot be used on structs | LL | #[rustc_splat] | ^^^^^^^^^^^ +LL | struct FooStruct; | = help: the `rustc_splat` attribute can only be applied to function params diff --git a/tests/ui/target-feature/invalid-attribute.stderr b/tests/ui/target-feature/invalid-attribute.stderr index b6710e5ab28a6..a5c6e21ee73e0 100644 --- a/tests/ui/target-feature/invalid-attribute.stderr +++ b/tests/ui/target-feature/invalid-attribute.stderr @@ -3,6 +3,8 @@ error: the `target_feature` attribute cannot be used on extern crates | LL | #[target_feature(enable = "sse2")] | ^^^^^^^^^^^^^^ +LL | +LL | extern crate minicore; | = help: the `target_feature` attribute can only be applied to functions @@ -11,6 +13,8 @@ error: the `target_feature` attribute cannot be used on use statements | LL | #[target_feature(enable = "sse2")] | ^^^^^^^^^^^^^^ +LL | +LL | use minicore::mem::transmute; | = help: the `target_feature` attribute can only be applied to functions @@ -19,6 +23,8 @@ error: the `target_feature` attribute cannot be used on foreign modules | LL | #[target_feature(enable = "sse2")] | ^^^^^^^^^^^^^^ +LL | +LL | extern "Rust" {} | = help: the `target_feature` attribute can only be applied to functions @@ -69,6 +75,8 @@ error: the `target_feature` attribute cannot be used on modules | LL | #[target_feature(enable = "sse2")] | ^^^^^^^^^^^^^^ +LL | +LL | mod another {} | = help: the `target_feature` attribute can only be applied to functions @@ -77,6 +85,8 @@ error: the `target_feature` attribute cannot be used on constants | LL | #[target_feature(enable = "sse2")] | ^^^^^^^^^^^^^^ +LL | +LL | const FOO: usize = 7; | = help: the `target_feature` attribute can only be applied to functions @@ -85,6 +95,8 @@ error: the `target_feature` attribute cannot be used on structs | LL | #[target_feature(enable = "sse2")] | ^^^^^^^^^^^^^^ +LL | +LL | struct Foo; | = help: the `target_feature` attribute can only be applied to functions @@ -93,6 +105,8 @@ error: the `target_feature` attribute cannot be used on enums | LL | #[target_feature(enable = "sse2")] | ^^^^^^^^^^^^^^ +LL | +LL | enum Bar {} | = help: the `target_feature` attribute can only be applied to functions @@ -101,6 +115,8 @@ error: the `target_feature` attribute cannot be used on unions | LL | #[target_feature(enable = "sse2")] | ^^^^^^^^^^^^^^ +LL | +LL | union Qux { | = help: the `target_feature` attribute can only be applied to functions @@ -109,6 +125,8 @@ error: the `target_feature` attribute cannot be used on type aliases | LL | #[target_feature(enable = "sse2")] | ^^^^^^^^^^^^^^ +LL | +LL | type Uwu = (); | = help: the `target_feature` attribute can only be applied to functions @@ -117,6 +135,8 @@ error: the `target_feature` attribute cannot be used on traits | LL | #[target_feature(enable = "sse2")] | ^^^^^^^^^^^^^^ +LL | +LL | trait Baz {} | = help: the `target_feature` attribute can only be applied to functions @@ -125,6 +145,8 @@ error: the `target_feature` attribute cannot be used on statics | LL | #[target_feature(enable = "sse2")] | ^^^^^^^^^^^^^^ +LL | +LL | static A: () = (); | = help: the `target_feature` attribute can only be applied to functions @@ -133,6 +155,8 @@ error: the `target_feature` attribute cannot be used on trait impl blocks | LL | #[target_feature(enable = "sse2")] | ^^^^^^^^^^^^^^ +LL | +LL | impl Quux for u8 {} | = help: the `target_feature` attribute can only be applied to functions @@ -141,6 +165,8 @@ error: the `target_feature` attribute cannot be used on inherent impl blocks | LL | #[target_feature(enable = "sse2")] | ^^^^^^^^^^^^^^ +LL | +LL | impl Foo {} | = help: the `target_feature` attribute can only be applied to functions @@ -149,6 +175,8 @@ error: the `target_feature` attribute cannot be used on expressions | LL | #[target_feature(enable = "sse2")] | ^^^^^^^^^^^^^^ +LL | +LL | unsafe { | = help: the `target_feature` attribute can only be applied to functions @@ -157,6 +185,8 @@ error: the `target_feature` attribute cannot be used on closures | LL | #[target_feature(enable = "sse2")] | ^^^^^^^^^^^^^^ +LL | +LL | || {}; | = help: the `target_feature` attribute can be applied to functions and methods diff --git a/tests/ui/thread-local/non-static.stderr b/tests/ui/thread-local/non-static.stderr index f323d8270b3cc..e7c8ece7b0029 100644 --- a/tests/ui/thread-local/non-static.stderr +++ b/tests/ui/thread-local/non-static.stderr @@ -3,6 +3,8 @@ error: the `thread_local` attribute cannot be used on constants | LL | #[thread_local] | ^^^^^^^^^^^^ +LL | +LL | const A: u32 = 0; | = help: the `thread_local` attribute can be applied to foreign statics and statics @@ -11,6 +13,8 @@ error: the `thread_local` attribute cannot be used on functions | LL | #[thread_local] | ^^^^^^^^^^^^ +LL | +LL | fn main() { | = help: the `thread_local` attribute can be applied to foreign statics and statics @@ -27,6 +31,8 @@ error: the `thread_local` attribute cannot be used on struct fields | LL | #[thread_local] | ^^^^^^^^^^^^ +LL | +LL | a: String, | = help: the `thread_local` attribute can be applied to foreign statics and statics diff --git a/tests/ui/traits/alias/not-a-marker.stderr b/tests/ui/traits/alias/not-a-marker.stderr index 232ecb3c7c7ca..8fe8ec1fab8c4 100644 --- a/tests/ui/traits/alias/not-a-marker.stderr +++ b/tests/ui/traits/alias/not-a-marker.stderr @@ -3,6 +3,8 @@ error: the `marker` attribute cannot be used on trait aliases | LL | #[marker] | ^^^^^^ +LL | +LL | trait Foo = Send; | = help: the `marker` attribute can only be applied to traits diff --git a/tests/ui/traits/default-method/rustc_must_implement_one_of_misuse.stderr b/tests/ui/traits/default-method/rustc_must_implement_one_of_misuse.stderr index e4312d06041ea..94a29d7ca0f50 100644 --- a/tests/ui/traits/default-method/rustc_must_implement_one_of_misuse.stderr +++ b/tests/ui/traits/default-method/rustc_must_implement_one_of_misuse.stderr @@ -61,6 +61,8 @@ error: the `rustc_must_implement_one_of` attribute cannot be used on functions | LL | #[rustc_must_implement_one_of(abc, abc)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | fn function() {} | = help: the `rustc_must_implement_one_of` attribute can only be applied to traits @@ -69,6 +71,8 @@ error: the `rustc_must_implement_one_of` attribute cannot be used on structs | LL | #[rustc_must_implement_one_of(abc, xyz)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | struct Struct {} | = help: the `rustc_must_implement_one_of` attribute can only be applied to traits diff --git a/tests/ui/unstable-feature-bound/unstable_inherent_method.stderr b/tests/ui/unstable-feature-bound/unstable_inherent_method.stderr index 63ca539708f08..f4bfda99b5d46 100644 --- a/tests/ui/unstable-feature-bound/unstable_inherent_method.stderr +++ b/tests/ui/unstable-feature-bound/unstable_inherent_method.stderr @@ -3,6 +3,8 @@ error: the `unstable_feature_bound` attribute cannot be used on required trait m | LL | #[unstable_feature_bound(foo)] | ^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | fn foo(); | = help: the `unstable_feature_bound` attribute can be applied to functions, trait impl blocks, and traits @@ -11,6 +13,8 @@ error: the `unstable_feature_bound` attribute cannot be used on trait methods in | LL | #[unstable_feature_bound(foo)] | ^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | fn foo() {} | = help: the `unstable_feature_bound` attribute can be applied to functions, trait impl blocks, and traits diff --git a/triagebot.toml b/triagebot.toml index 60786ced590f0..35891af78fbdb 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -1104,6 +1104,10 @@ cc = ["@BoxyUwU"] message = "Some changes occurred in `rustc_ty_utils::consts.rs`" cc = ["@BoxyUwU"] +[mentions."compiler/rustc_ty_utils/src/layout/invariant.rs"] +message = "Layout invariants are being changed" +cc = ["@RalfJung"] + [mentions."compiler/rustc_trait_selection/src/solve/"] message = "Some changes occurred to the core trait solver" cc = ["@rust-lang/initiative-trait-system-refactor"]