about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-04-23 12:10:25 +0200
committerGitHub <noreply@github.com>2024-04-23 12:10:25 +0200
commit36316df9fe6c3e246153fe6e78967643cf08c148 (patch)
treec729390a09b2fe6d6f2bc0a8fd15012467a010b0
parent72e8fb42680a68d6a09ffad94300161aed50b832 (diff)
parent8b35be741fd1e46f81a3614478279d718701783e (diff)
downloadrust-36316df9fe6c3e246153fe6e78967643cf08c148.tar.gz
rust-36316df9fe6c3e246153fe6e78967643cf08c148.zip
Rollup merge of #124067 - RalfJung:weak-lang-items, r=davidtwco
weak lang items are not allowed to be #[track_caller]

For instance the panic handler will be called via this import
```rust
        extern "Rust" {
            #[lang = "panic_impl"]
            fn panic_impl(pi: &PanicInfo<'_>) -> !;
        }
```
A `#[track_caller]` would add an extra argument and thus make this the wrong signature.

The 2nd commit is a consistency rename; based on the docs [here](https://doc.rust-lang.org/unstable-book/language-features/lang-items.html) and [here](https://rustc-dev-guide.rust-lang.org/lang-items.html) I figured "lang item" is more widely used. (In the compiler output, "lang item" and "language item" seem to be pretty even.)
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0522.md2
-rw-r--r--compiler/rustc_feature/src/builtin_attrs.rs2
-rw-r--r--compiler/rustc_hir/src/lang_items.rs10
-rw-r--r--compiler/rustc_hir_analysis/src/check/intrinsic.rs6
-rw-r--r--compiler/rustc_metadata/src/rmeta/decoder.rs2
-rw-r--r--compiler/rustc_middle/src/middle/lang_items.rs2
-rw-r--r--compiler/rustc_mir_transform/src/deduce_param_attrs.rs2
-rw-r--r--compiler/rustc_mir_transform/src/lower_slice_len.rs2
-rw-r--r--compiler/rustc_passes/messages.ftl23
-rw-r--r--compiler/rustc_passes/src/check_attr.rs25
-rw-r--r--compiler/rustc_passes/src/errors.rs10
-rw-r--r--compiler/rustc_passes/src/lang_items.rs2
-rw-r--r--compiler/rustc_passes/src/weak_lang_items.rs2
-rw-r--r--compiler/rustc_resolve/src/lib.rs2
-rw-r--r--tests/ui/assoc-lang-items.stderr16
-rw-r--r--tests/ui/error-codes/E0522.rs2
-rw-r--r--tests/ui/error-codes/E0522.stderr4
-rw-r--r--tests/ui/error-codes/E0718.rs2
-rw-r--r--tests/ui/error-codes/E0718.stderr2
-rw-r--r--tests/ui/feature-gates/feature-gate-lang-items.rs4
-rw-r--r--tests/ui/feature-gates/feature-gate-lang-items.stderr6
-rw-r--r--tests/ui/lang-items/issue-83471.rs6
-rw-r--r--tests/ui/lang-items/issue-83471.stderr6
-rw-r--r--tests/ui/lang-items/issue-87573.rs4
-rw-r--r--tests/ui/lang-items/issue-87573.stderr4
-rw-r--r--tests/ui/lang-items/lang-item-generic-requirements.rs12
-rw-r--r--tests/ui/lang-items/lang-item-generic-requirements.stderr12
-rw-r--r--tests/ui/lang-items/start_lang_item_with_target_feature.rs2
-rw-r--r--tests/ui/lang-items/start_lang_item_with_target_feature.stderr4
-rw-r--r--tests/ui/panic-handler/panic-handler-with-target-feature.rs2
-rw-r--r--tests/ui/panic-handler/panic-handler-with-target-feature.stderr4
-rw-r--r--tests/ui/panic-handler/panic-handler-with-track-caller.rs14
-rw-r--r--tests/ui/panic-handler/panic-handler-with-track-caller.stderr11
-rw-r--r--tests/ui/panic-handler/panic-handler-wrong-location.rs2
-rw-r--r--tests/ui/panic-handler/panic-handler-wrong-location.stderr2
-rw-r--r--tests/ui/unknown-language-item.rs2
-rw-r--r--tests/ui/unknown-language-item.stderr4
37 files changed, 141 insertions, 78 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0522.md b/compiler/rustc_error_codes/src/error_codes/E0522.md
index 83272314a87..b0dd5a775ac 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0522.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0522.md
@@ -6,7 +6,7 @@ Erroneous code example:
 #![feature(lang_items)]
 
 #[lang = "cookie"]
-fn cookie() -> ! { // error: definition of an unknown language item: `cookie`
+fn cookie() -> ! { // error: definition of an unknown lang item: `cookie`
     loop {}
 }
 ```
diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs
index 4f62323231a..23b3f31b437 100644
--- a/compiler/rustc_feature/src/builtin_attrs.rs
+++ b/compiler/rustc_feature/src/builtin_attrs.rs
@@ -798,7 +798,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
     // ==========================================================================
     gated!(
         lang, Normal, template!(NameValueStr: "name"), DuplicatesOk, EncodeCrossCrate::No, lang_items,
-        "language items are subject to change",
+        "lang items are subject to change",
     ),
     rustc_attr!(
         rustc_pass_by_value, Normal, template!(Word), ErrorFollowing,
diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs
index 879476f890e..6aee1183a10 100644
--- a/compiler/rustc_hir/src/lang_items.rs
+++ b/compiler/rustc_hir/src/lang_items.rs
@@ -1,4 +1,4 @@
-//! Defines language items.
+//! Defines lang items.
 //!
 //! Language items are items that represent concepts intrinsic to the language
 //! itself. Examples are:
@@ -16,7 +16,7 @@ use rustc_macros::HashStable_Generic;
 use rustc_span::symbol::{kw, sym, Symbol};
 use rustc_span::Span;
 
-/// All of the language items, defined or not.
+/// All of the lang items, defined or not.
 /// Defined lang items can come from the current crate or its dependencies.
 #[derive(HashStable_Generic, Debug)]
 pub struct LanguageItems {
@@ -57,7 +57,7 @@ macro_rules! language_item_table {
     ) => {
 
         enum_from_u32! {
-            /// A representation of all the valid language items in Rust.
+            /// A representation of all the valid lang items in Rust.
             #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)]
             pub enum LangItem {
                 $(
@@ -177,7 +177,7 @@ language_item_table! {
     CoerceUnsized,           sym::coerce_unsized,      coerce_unsized_trait,       Target::Trait,          GenericRequirement::Minimum(1);
     DispatchFromDyn,         sym::dispatch_from_dyn,   dispatch_from_dyn_trait,    Target::Trait,          GenericRequirement::Minimum(1);
 
-    // language items relating to transmutability
+    // lang items relating to transmutability
     TransmuteOpts,           sym::transmute_opts,      transmute_opts,             Target::Struct,         GenericRequirement::Exact(0);
     TransmuteTrait,          sym::transmute_trait,     transmute_trait,            Target::Trait,          GenericRequirement::Exact(2);
 
@@ -304,7 +304,7 @@ language_item_table! {
     OwnedBox,                sym::owned_box,           owned_box,                  Target::Struct,         GenericRequirement::Minimum(1);
     GlobalAlloc,             sym::global_alloc_ty,     global_alloc_ty,            Target::Struct,         GenericRequirement::None;
 
-    // Experimental language item for Miri
+    // Experimental lang item for Miri
     PtrUnique,               sym::ptr_unique,          ptr_unique,                 Target::Struct,         GenericRequirement::Exact(1);
 
     PhantomData,             sym::phantom_data,        phantom_data,               Target::Struct,         GenericRequirement::Exact(1);
diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs
index fb4a76bf089..1aa73401303 100644
--- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs
+++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs
@@ -535,7 +535,7 @@ pub fn check_intrinsic_type(
 
             sym::va_start | sym::va_end => match mk_va_list_ty(hir::Mutability::Mut) {
                 Some((va_list_ref_ty, _)) => (0, 0, vec![va_list_ref_ty], Ty::new_unit(tcx)),
-                None => bug!("`va_list` language item needed for C-variadic intrinsics"),
+                None => bug!("`va_list` lang item needed for C-variadic intrinsics"),
             },
 
             sym::va_copy => match mk_va_list_ty(hir::Mutability::Not) {
@@ -543,12 +543,12 @@ pub fn check_intrinsic_type(
                     let va_list_ptr_ty = Ty::new_mut_ptr(tcx, va_list_ty);
                     (0, 0, vec![va_list_ptr_ty, va_list_ref_ty], Ty::new_unit(tcx))
                 }
-                None => bug!("`va_list` language item needed for C-variadic intrinsics"),
+                None => bug!("`va_list` lang item needed for C-variadic intrinsics"),
             },
 
             sym::va_arg => match mk_va_list_ty(hir::Mutability::Mut) {
                 Some((va_list_ref_ty, _)) => (1, 0, vec![va_list_ref_ty], param(0)),
-                None => bug!("`va_list` language item needed for C-variadic intrinsics"),
+                None => bug!("`va_list` lang item needed for C-variadic intrinsics"),
             },
 
             sym::nontemporal_store => {
diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs
index 596da58b091..c4ab4eb2657 100644
--- a/compiler/rustc_metadata/src/rmeta/decoder.rs
+++ b/compiler/rustc_metadata/src/rmeta/decoder.rs
@@ -1208,7 +1208,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
         tcx.arena.alloc_from_iter(self.root.stability_implications.decode(self))
     }
 
-    /// Iterates over the language items in the given crate.
+    /// Iterates over the lang items in the given crate.
     fn get_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [(DefId, LangItem)] {
         tcx.arena.alloc_from_iter(
             self.root
diff --git a/compiler/rustc_middle/src/middle/lang_items.rs b/compiler/rustc_middle/src/middle/lang_items.rs
index a4e193ba2c9..4fd1c1f4a1b 100644
--- a/compiler/rustc_middle/src/middle/lang_items.rs
+++ b/compiler/rustc_middle/src/middle/lang_items.rs
@@ -1,4 +1,4 @@
-//! Detecting language items.
+//! Detecting lang items.
 //!
 //! Language items are items that represent concepts intrinsic to the language
 //! itself. Examples are:
diff --git a/compiler/rustc_mir_transform/src/deduce_param_attrs.rs b/compiler/rustc_mir_transform/src/deduce_param_attrs.rs
index ca63f5550ae..370e930b740 100644
--- a/compiler/rustc_mir_transform/src/deduce_param_attrs.rs
+++ b/compiler/rustc_mir_transform/src/deduce_param_attrs.rs
@@ -160,7 +160,7 @@ pub fn deduced_param_attrs<'tcx>(
         return &[];
     }
 
-    // If the Freeze language item isn't present, then don't bother.
+    // If the Freeze lang item isn't present, then don't bother.
     if tcx.lang_items().freeze_trait().is_none() {
         return &[];
     }
diff --git a/compiler/rustc_mir_transform/src/lower_slice_len.rs b/compiler/rustc_mir_transform/src/lower_slice_len.rs
index 8137525a332..2267a621a83 100644
--- a/compiler/rustc_mir_transform/src/lower_slice_len.rs
+++ b/compiler/rustc_mir_transform/src/lower_slice_len.rs
@@ -21,7 +21,7 @@ impl<'tcx> MirPass<'tcx> for LowerSliceLenCalls {
 pub fn lower_slice_len_calls<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
     let language_items = tcx.lang_items();
     let Some(slice_len_fn_item_def_id) = language_items.slice_len_fn() else {
-        // there is no language item to compare to :)
+        // there is no lang item to compare to :)
         return;
     };
 
diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl
index 7fc523ffe0d..a545c170297 100644
--- a/compiler/rustc_passes/messages.ftl
+++ b/compiler/rustc_passes/messages.ftl
@@ -353,7 +353,7 @@ passes_incorrect_meta_item = expected a quoted string literal
 passes_incorrect_meta_item_suggestion = consider surrounding this with quotes
 
 passes_incorrect_target =
-    `{$name}` language item must be applied to a {$kind} with {$at_least ->
+    `{$name}` lang item must be applied to a {$kind} with {$at_least ->
         [true] at least {$num}
         *[false] {$num}
     } generic {$num ->
@@ -394,12 +394,21 @@ passes_invalid_macro_export_arguments = `{$name}` isn't a valid `#[macro_export]
 
 passes_invalid_macro_export_arguments_too_many_items = `#[macro_export]` can only take 1 or 0 arguments
 
+passes_lang_item_fn = {$name ->
+    [panic_impl] `#[panic_handler]`
+    *[other] `{$name}` lang item
+} function
+
 passes_lang_item_fn_with_target_feature =
-    `{$name}` language item function is not allowed to have `#[target_feature]`
-    .label = `{$name}` language item function is not allowed to have `#[target_feature]`
+    {passes_lang_item_fn} is not allowed to have `#[target_feature]`
+    .label = {passes_lang_item_fn} is not allowed to have `#[target_feature]`
+
+passes_lang_item_fn_with_track_caller =
+    {passes_lang_item_fn} is not allowed to have `#[track_caller]`
+    .label = {passes_lang_item_fn} is not allowed to have `#[target_feature]`
 
 passes_lang_item_on_incorrect_target =
-    `{$name}` language item must be applied to a {$expected_target}
+    `{$name}` lang item must be applied to a {$expected_target}
     .label = attribute should be applied to a {$expected_target}, not a {$actual_target}
 
 passes_layout_abi =
@@ -455,7 +464,7 @@ passes_missing_const_stab_attr =
     {$descr} has missing const stability attribute
 
 passes_missing_lang_item =
-    language item required, but not found: `{$name}`
+    lang item required, but not found: `{$name}`
     .note = this can occur when a binary crate with `#![no_std]` is compiled for a target where `{$name}` is defined in the standard library
     .help = you may be able to compile for a target that doesn't need `{$name}`, specify a target with `--target` or in `.cargo/config`
 
@@ -696,8 +705,8 @@ passes_unknown_feature =
     unknown feature `{$feature}`
 
 passes_unknown_lang_item =
-    definition of an unknown language item: `{$name}`
-    .label = definition of unknown language item `{$name}`
+    definition of an unknown lang item: `{$name}`
+    .label = definition of unknown lang item `{$name}`
 
 passes_unlabeled_cf_in_while_condition =
     `break` or `continue` with no label in the condition of a `while` loop
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs
index 1254ae8cfc8..a2388b3bd52 100644
--- a/compiler/rustc_passes/src/check_attr.rs
+++ b/compiler/rustc_passes/src/check_attr.rs
@@ -11,9 +11,9 @@ use rustc_data_structures::fx::FxHashMap;
 use rustc_errors::StashKey;
 use rustc_errors::{Applicability, DiagCtxt, IntoDiagArg, MultiSpan};
 use rustc_feature::{AttributeDuplicates, AttributeType, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
-use rustc_hir as hir;
 use rustc_hir::def_id::LocalModDefId;
 use rustc_hir::intravisit::{self, Visitor};
+use rustc_hir::{self as hir};
 use rustc_hir::{
     self, FnSig, ForeignItem, HirId, Item, ItemKind, TraitItem, CRATE_HIR_ID, CRATE_OWNER_ID,
 };
@@ -519,7 +519,26 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
                 self.dcx().emit_err(errors::NakedTrackedCaller { attr_span });
                 false
             }
-            Target::Fn | Target::Method(..) | Target::ForeignFn | Target::Closure => true,
+            Target::Fn => {
+                // `#[track_caller]` is not valid on weak lang items because they are called via
+                // `extern` declarations and `#[track_caller]` would alter their ABI.
+                if let Some((lang_item, _)) = hir::lang_items::extract(attrs)
+                    && let Some(item) = hir::LangItem::from_name(lang_item)
+                    && item.is_weak()
+                {
+                    let sig = self.tcx.hir_node(hir_id).fn_sig().unwrap();
+
+                    self.dcx().emit_err(errors::LangItemWithTrackCaller {
+                        attr_span,
+                        name: lang_item,
+                        sig_span: sig.span,
+                    });
+                    false
+                } else {
+                    true
+                }
+            }
+            Target::Method(..) | Target::ForeignFn | Target::Closure => true,
             // FIXME(#80564): We permit struct fields, match arms and macro defs to have an
             // `#[track_caller]` attribute with just a lint, because we previously
             // erroneously allowed it and some crates used it accidentally, to be compatible
@@ -602,7 +621,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
     ) -> bool {
         match target {
             Target::Fn => {
-                // `#[target_feature]` is not allowed in language items.
+                // `#[target_feature]` is not allowed in lang items.
                 if let Some((lang_item, _)) = hir::lang_items::extract(attrs)
                     // Calling functions with `#[target_feature]` is
                     // not unsafe on WASM, see #84988
diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs
index 3f26ea4507d..19b5e5495d6 100644
--- a/compiler/rustc_passes/src/errors.rs
+++ b/compiler/rustc_passes/src/errors.rs
@@ -820,6 +820,16 @@ pub struct MissingLangItem {
 }
 
 #[derive(Diagnostic)]
+#[diag(passes_lang_item_fn_with_track_caller)]
+pub struct LangItemWithTrackCaller {
+    #[primary_span]
+    pub attr_span: Span,
+    pub name: Symbol,
+    #[label]
+    pub sig_span: Span,
+}
+
+#[derive(Diagnostic)]
 #[diag(passes_lang_item_fn_with_target_feature)]
 pub struct LangItemWithTargetFeature {
     #[primary_span]
diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs
index d1368267224..c1da8928f30 100644
--- a/compiler/rustc_passes/src/lang_items.rs
+++ b/compiler/rustc_passes/src/lang_items.rs
@@ -1,4 +1,4 @@
-//! Detecting language items.
+//! Detecting lang items.
 //!
 //! Language items are items that represent concepts intrinsic to the language
 //! itself. Examples are:
diff --git a/compiler/rustc_passes/src/weak_lang_items.rs b/compiler/rustc_passes/src/weak_lang_items.rs
index 4eb0c6c275e..90691ca1790 100644
--- a/compiler/rustc_passes/src/weak_lang_items.rs
+++ b/compiler/rustc_passes/src/weak_lang_items.rs
@@ -14,7 +14,7 @@ use crate::errors::{
 };
 
 /// Checks the crate for usage of weak lang items, returning a vector of all the
-/// language items required by this crate, but not defined yet.
+/// lang items required by this crate, but not defined yet.
 pub fn check_crate(tcx: TyCtxt<'_>, items: &mut lang_items::LanguageItems, krate: &ast::Crate) {
     // These are never called by user code, they're generated by the compiler.
     // They will never implicitly be added to the `missing` array unless we do
diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs
index b8221d9d7f9..b5b6d899cc5 100644
--- a/compiler/rustc_resolve/src/lib.rs
+++ b/compiler/rustc_resolve/src/lib.rs
@@ -1042,7 +1042,7 @@ pub struct Resolver<'a, 'tcx> {
     block_map: NodeMap<Module<'a>>,
     /// A fake module that contains no definition and no prelude. Used so that
     /// some AST passes can generate identifiers that only resolve to local or
-    /// language items.
+    /// lang items.
     empty_module: Module<'a>,
     module_map: FxHashMap<DefId, Module<'a>>,
     binding_parent_modules: FxHashMap<NameBinding<'a>, Module<'a>>,
diff --git a/tests/ui/assoc-lang-items.stderr b/tests/ui/assoc-lang-items.stderr
index 040792fb1cd..59aec8e3fdc 100644
--- a/tests/ui/assoc-lang-items.stderr
+++ b/tests/ui/assoc-lang-items.stderr
@@ -1,26 +1,26 @@
-error[E0522]: definition of an unknown language item: `dummy_lang_item_1`
+error[E0522]: definition of an unknown lang item: `dummy_lang_item_1`
   --> $DIR/assoc-lang-items.rs:4:5
    |
 LL |     #[lang = "dummy_lang_item_1"]
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown language item `dummy_lang_item_1`
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown lang item `dummy_lang_item_1`
 
-error[E0522]: definition of an unknown language item: `dummy_lang_item_2`
+error[E0522]: definition of an unknown lang item: `dummy_lang_item_2`
   --> $DIR/assoc-lang-items.rs:7:5
    |
 LL |     #[lang = "dummy_lang_item_2"]
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown language item `dummy_lang_item_2`
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown lang item `dummy_lang_item_2`
 
-error[E0522]: definition of an unknown language item: `dummy_lang_item_3`
+error[E0522]: definition of an unknown lang item: `dummy_lang_item_3`
   --> $DIR/assoc-lang-items.rs:10:5
    |
 LL |     #[lang = "dummy_lang_item_3"]
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown language item `dummy_lang_item_3`
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown lang item `dummy_lang_item_3`
 
-error[E0522]: definition of an unknown language item: `dummy_lang_item_4`
+error[E0522]: definition of an unknown lang item: `dummy_lang_item_4`
   --> $DIR/assoc-lang-items.rs:17:5
    |
 LL |     #[lang = "dummy_lang_item_4"]
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown language item `dummy_lang_item_4`
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown lang item `dummy_lang_item_4`
 
 error: aborting due to 4 previous errors
 
diff --git a/tests/ui/error-codes/E0522.rs b/tests/ui/error-codes/E0522.rs
index 1414e82408c..ec9e6d25774 100644
--- a/tests/ui/error-codes/E0522.rs
+++ b/tests/ui/error-codes/E0522.rs
@@ -2,7 +2,7 @@
 
 #[lang = "cookie"]
 fn cookie() -> ! {
-//~^^ ERROR definition of an unknown language item: `cookie` [E0522]
+//~^^ ERROR definition of an unknown lang item: `cookie` [E0522]
     loop {}
 }
 
diff --git a/tests/ui/error-codes/E0522.stderr b/tests/ui/error-codes/E0522.stderr
index 66359cbacc8..82bbf079594 100644
--- a/tests/ui/error-codes/E0522.stderr
+++ b/tests/ui/error-codes/E0522.stderr
@@ -1,8 +1,8 @@
-error[E0522]: definition of an unknown language item: `cookie`
+error[E0522]: definition of an unknown lang item: `cookie`
   --> $DIR/E0522.rs:3:1
    |
 LL | #[lang = "cookie"]
-   | ^^^^^^^^^^^^^^^^^^ definition of unknown language item `cookie`
+   | ^^^^^^^^^^^^^^^^^^ definition of unknown lang item `cookie`
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/error-codes/E0718.rs b/tests/ui/error-codes/E0718.rs
index 909cae0ba25..358bc348ec7 100644
--- a/tests/ui/error-codes/E0718.rs
+++ b/tests/ui/error-codes/E0718.rs
@@ -1,7 +1,7 @@
 #![feature(lang_items)]
 
 // Box is expected to be a struct, so this will error.
-#[lang = "owned_box"] //~ ERROR language item must be applied to a struct
+#[lang = "owned_box"] //~ ERROR lang item must be applied to a struct
 static X: u32 = 42;
 
 fn main() {}
diff --git a/tests/ui/error-codes/E0718.stderr b/tests/ui/error-codes/E0718.stderr
index 9a3db136d23..ec7462765f8 100644
--- a/tests/ui/error-codes/E0718.stderr
+++ b/tests/ui/error-codes/E0718.stderr
@@ -1,4 +1,4 @@
-error[E0718]: `owned_box` language item must be applied to a struct
+error[E0718]: `owned_box` lang item must be applied to a struct
   --> $DIR/E0718.rs:4:1
    |
 LL | #[lang = "owned_box"]
diff --git a/tests/ui/feature-gates/feature-gate-lang-items.rs b/tests/ui/feature-gates/feature-gate-lang-items.rs
index 93262f2171b..d6fd5472a0c 100644
--- a/tests/ui/feature-gates/feature-gate-lang-items.rs
+++ b/tests/ui/feature-gates/feature-gate-lang-items.rs
@@ -1,5 +1,5 @@
-#[lang = "foo"] //~ ERROR language items are subject to change
-                //~^ ERROR definition of an unknown language item: `foo`
+#[lang = "foo"] //~ ERROR lang items are subject to change
+                //~^ ERROR definition of an unknown lang item: `foo`
 trait Foo {}
 
 fn main() {}
diff --git a/tests/ui/feature-gates/feature-gate-lang-items.stderr b/tests/ui/feature-gates/feature-gate-lang-items.stderr
index 54787e03784..c5caffbdc94 100644
--- a/tests/ui/feature-gates/feature-gate-lang-items.stderr
+++ b/tests/ui/feature-gates/feature-gate-lang-items.stderr
@@ -1,4 +1,4 @@
-error[E0658]: language items are subject to change
+error[E0658]: lang items are subject to change
   --> $DIR/feature-gate-lang-items.rs:1:1
    |
 LL | #[lang = "foo"]
@@ -7,11 +7,11 @@ LL | #[lang = "foo"]
    = help: add `#![feature(lang_items)]` to the crate attributes to enable
    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
 
-error[E0522]: definition of an unknown language item: `foo`
+error[E0522]: definition of an unknown lang item: `foo`
   --> $DIR/feature-gate-lang-items.rs:1:1
    |
 LL | #[lang = "foo"]
-   | ^^^^^^^^^^^^^^^ definition of unknown language item `foo`
+   | ^^^^^^^^^^^^^^^ definition of unknown lang item `foo`
 
 error: aborting due to 2 previous errors
 
diff --git a/tests/ui/lang-items/issue-83471.rs b/tests/ui/lang-items/issue-83471.rs
index b32aa034151..6be345ac507 100644
--- a/tests/ui/lang-items/issue-83471.rs
+++ b/tests/ui/lang-items/issue-83471.rs
@@ -5,12 +5,12 @@
 #![no_core]
 
 #[lang = "sized"]
-//~^ ERROR: language items are subject to change [E0658]
+//~^ ERROR: lang items are subject to change [E0658]
 trait Sized {}
 
 #[lang = "fn"]
-//~^ ERROR: language items are subject to change [E0658]
-//~| ERROR: `fn` language item must be applied to a trait with 1 generic argument
+//~^ ERROR: lang items are subject to change [E0658]
+//~| ERROR: `fn` lang item must be applied to a trait with 1 generic argument
 trait Fn {
     fn call(export_name);
     //~^ ERROR: expected type
diff --git a/tests/ui/lang-items/issue-83471.stderr b/tests/ui/lang-items/issue-83471.stderr
index 1f22d966dd7..244b2efeaf1 100644
--- a/tests/ui/lang-items/issue-83471.stderr
+++ b/tests/ui/lang-items/issue-83471.stderr
@@ -4,7 +4,7 @@ error[E0573]: expected type, found built-in attribute `export_name`
 LL |     fn call(export_name);
    |             ^^^^^^^^^^^ not a type
 
-error[E0658]: language items are subject to change
+error[E0658]: lang items are subject to change
   --> $DIR/issue-83471.rs:7:1
    |
 LL | #[lang = "sized"]
@@ -13,7 +13,7 @@ LL | #[lang = "sized"]
    = help: add `#![feature(lang_items)]` to the crate attributes to enable
    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
 
-error[E0658]: language items are subject to change
+error[E0658]: lang items are subject to change
   --> $DIR/issue-83471.rs:11:1
    |
 LL | #[lang = "fn"]
@@ -32,7 +32,7 @@ LL |     fn call(export_name);
    = note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>
    = note: `#[warn(anonymous_parameters)]` on by default
 
-error[E0718]: `fn` language item must be applied to a trait with 1 generic argument
+error[E0718]: `fn` lang item must be applied to a trait with 1 generic argument
   --> $DIR/issue-83471.rs:11:1
    |
 LL | #[lang = "fn"]
diff --git a/tests/ui/lang-items/issue-87573.rs b/tests/ui/lang-items/issue-87573.rs
index aeb0c245a72..7b805e8b0cd 100644
--- a/tests/ui/lang-items/issue-87573.rs
+++ b/tests/ui/lang-items/issue-87573.rs
@@ -18,11 +18,11 @@ trait Sync {}
 impl Sync for bool {}
 
 #[lang = "drop_in_place"]
-//~^ ERROR: `drop_in_place` language item must be applied to a function with at least 1 generic argument
+//~^ ERROR: `drop_in_place` lang item must be applied to a function with at least 1 generic argument
 fn drop_fn() {
     while false {}
 }
 
 #[lang = "start"]
-//~^ ERROR: `start` language item must be applied to a function with 1 generic argument
+//~^ ERROR: `start` lang item must be applied to a function with 1 generic argument
 fn start(){}
diff --git a/tests/ui/lang-items/issue-87573.stderr b/tests/ui/lang-items/issue-87573.stderr
index 25560cfa0e6..7085bb8c339 100644
--- a/tests/ui/lang-items/issue-87573.stderr
+++ b/tests/ui/lang-items/issue-87573.stderr
@@ -1,4 +1,4 @@
-error[E0718]: `drop_in_place` language item must be applied to a function with at least 1 generic argument
+error[E0718]: `drop_in_place` lang item must be applied to a function with at least 1 generic argument
   --> $DIR/issue-87573.rs:20:1
    |
 LL | #[lang = "drop_in_place"]
@@ -7,7 +7,7 @@ LL |
 LL | fn drop_fn() {
    |           - this function has 0 generic arguments
 
-error[E0718]: `start` language item must be applied to a function with 1 generic argument
+error[E0718]: `start` lang item must be applied to a function with 1 generic argument
   --> $DIR/issue-87573.rs:26:1
    |
 LL | #[lang = "start"]
diff --git a/tests/ui/lang-items/lang-item-generic-requirements.rs b/tests/ui/lang-items/lang-item-generic-requirements.rs
index 697790023d6..0f982df61e8 100644
--- a/tests/ui/lang-items/lang-item-generic-requirements.rs
+++ b/tests/ui/lang-items/lang-item-generic-requirements.rs
@@ -9,30 +9,30 @@ trait MySized {}
 
 #[lang = "add"]
 trait MyAdd<'a, T> {}
-//~^^ ERROR: `add` language item must be applied to a trait with 1 generic argument [E0718]
+//~^^ ERROR: `add` lang item must be applied to a trait with 1 generic argument [E0718]
 
 #[lang = "drop_in_place"]
-//~^ ERROR `drop_in_place` language item must be applied to a function with at least 1 generic
+//~^ ERROR `drop_in_place` lang item must be applied to a function with at least 1 generic
 fn my_ptr_drop() {}
 
 #[lang = "index"]
 trait MyIndex<'a, T> {}
-//~^^ ERROR: `index` language item must be applied to a trait with 1 generic argument [E0718]
+//~^^ ERROR: `index` lang item must be applied to a trait with 1 generic argument [E0718]
 
 #[lang = "phantom_data"]
-//~^ ERROR `phantom_data` language item must be applied to a struct with 1 generic argument
+//~^ ERROR `phantom_data` lang item must be applied to a struct with 1 generic argument
 struct MyPhantomData<T, U>;
 //~^ ERROR `T` is never used
 //~| ERROR `U` is never used
 
 #[lang = "owned_box"]
-//~^ ERROR `owned_box` language item must be applied to a struct with at least 1 generic argument
+//~^ ERROR `owned_box` lang item must be applied to a struct with at least 1 generic argument
 struct Foo;
 
 // When the `start` lang item is missing generics very odd things can happen, especially when
 // it comes to cross-crate monomorphization
 #[lang = "start"]
-//~^ ERROR `start` language item must be applied to a function with 1 generic argument [E0718]
+//~^ ERROR `start` lang item must be applied to a function with 1 generic argument [E0718]
 fn start(_: *const u8, _: isize, _: *const *const u8) -> isize {
     0
 }
diff --git a/tests/ui/lang-items/lang-item-generic-requirements.stderr b/tests/ui/lang-items/lang-item-generic-requirements.stderr
index 30abdf84046..3de67d65940 100644
--- a/tests/ui/lang-items/lang-item-generic-requirements.stderr
+++ b/tests/ui/lang-items/lang-item-generic-requirements.stderr
@@ -1,4 +1,4 @@
-error[E0718]: `add` language item must be applied to a trait with 1 generic argument
+error[E0718]: `add` lang item must be applied to a trait with 1 generic argument
   --> $DIR/lang-item-generic-requirements.rs:10:1
    |
 LL | #[lang = "add"]
@@ -6,7 +6,7 @@ LL | #[lang = "add"]
 LL | trait MyAdd<'a, T> {}
    |            ------- this trait has 2 generic arguments
 
-error[E0718]: `drop_in_place` language item must be applied to a function with at least 1 generic argument
+error[E0718]: `drop_in_place` lang item must be applied to a function with at least 1 generic argument
   --> $DIR/lang-item-generic-requirements.rs:14:1
    |
 LL | #[lang = "drop_in_place"]
@@ -15,7 +15,7 @@ LL |
 LL | fn my_ptr_drop() {}
    |               - this function has 0 generic arguments
 
-error[E0718]: `index` language item must be applied to a trait with 1 generic argument
+error[E0718]: `index` lang item must be applied to a trait with 1 generic argument
   --> $DIR/lang-item-generic-requirements.rs:18:1
    |
 LL | #[lang = "index"]
@@ -23,7 +23,7 @@ LL | #[lang = "index"]
 LL | trait MyIndex<'a, T> {}
    |              ------- this trait has 2 generic arguments
 
-error[E0718]: `phantom_data` language item must be applied to a struct with 1 generic argument
+error[E0718]: `phantom_data` lang item must be applied to a struct with 1 generic argument
   --> $DIR/lang-item-generic-requirements.rs:22:1
    |
 LL | #[lang = "phantom_data"]
@@ -32,7 +32,7 @@ LL |
 LL | struct MyPhantomData<T, U>;
    |                     ------ this struct has 2 generic arguments
 
-error[E0718]: `owned_box` language item must be applied to a struct with at least 1 generic argument
+error[E0718]: `owned_box` lang item must be applied to a struct with at least 1 generic argument
   --> $DIR/lang-item-generic-requirements.rs:28:1
    |
 LL | #[lang = "owned_box"]
@@ -41,7 +41,7 @@ LL |
 LL | struct Foo;
    |           - this struct has 0 generic arguments
 
-error[E0718]: `start` language item must be applied to a function with 1 generic argument
+error[E0718]: `start` lang item must be applied to a function with 1 generic argument
   --> $DIR/lang-item-generic-requirements.rs:34:1
    |
 LL | #[lang = "start"]
diff --git a/tests/ui/lang-items/start_lang_item_with_target_feature.rs b/tests/ui/lang-items/start_lang_item_with_target_feature.rs
index 4717304c5c6..eb712ba4092 100644
--- a/tests/ui/lang-items/start_lang_item_with_target_feature.rs
+++ b/tests/ui/lang-items/start_lang_item_with_target_feature.rs
@@ -11,7 +11,7 @@ pub trait Sized {}
 
 #[lang = "start"]
 #[target_feature(enable = "avx2")]
-//~^ ERROR `start` language item function is not allowed to have `#[target_feature]`
+//~^ ERROR `start` lang item function is not allowed to have `#[target_feature]`
 fn start<T>(_main: fn() -> T, _argc: isize, _argv: *const *const u8, _sigpipe: u8) -> isize {
     0
 }
diff --git a/tests/ui/lang-items/start_lang_item_with_target_feature.stderr b/tests/ui/lang-items/start_lang_item_with_target_feature.stderr
index bb0583dfde0..6214e3f8bc7 100644
--- a/tests/ui/lang-items/start_lang_item_with_target_feature.stderr
+++ b/tests/ui/lang-items/start_lang_item_with_target_feature.stderr
@@ -1,11 +1,11 @@
-error: `start` language item function is not allowed to have `#[target_feature]`
+error: `start` lang item function is not allowed to have `#[target_feature]`
   --> $DIR/start_lang_item_with_target_feature.rs:13:1
    |
 LL | #[target_feature(enable = "avx2")]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 LL |
 LL | fn start<T>(_main: fn() -> T, _argc: isize, _argv: *const *const u8, _sigpipe: u8) -> isize {
-   | ------------------------------------------------------------------------------------------- `start` language item function is not allowed to have `#[target_feature]`
+   | ------------------------------------------------------------------------------------------- `start` lang item function is not allowed to have `#[target_feature]`
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/panic-handler/panic-handler-with-target-feature.rs b/tests/ui/panic-handler/panic-handler-with-target-feature.rs
index 3dfdd2847bf..8d5ea0703af 100644
--- a/tests/ui/panic-handler/panic-handler-with-target-feature.rs
+++ b/tests/ui/panic-handler/panic-handler-with-target-feature.rs
@@ -9,7 +9,7 @@ use core::panic::PanicInfo;
 
 #[panic_handler]
 #[target_feature(enable = "avx2")]
-//~^ ERROR `panic_impl` language item function is not allowed to have `#[target_feature]`
+//~^ ERROR `#[panic_handler]` function is not allowed to have `#[target_feature]`
 fn panic(info: &PanicInfo) -> ! {
     unimplemented!();
 }
diff --git a/tests/ui/panic-handler/panic-handler-with-target-feature.stderr b/tests/ui/panic-handler/panic-handler-with-target-feature.stderr
index c38feab49c3..cb17da3a4ef 100644
--- a/tests/ui/panic-handler/panic-handler-with-target-feature.stderr
+++ b/tests/ui/panic-handler/panic-handler-with-target-feature.stderr
@@ -1,11 +1,11 @@
-error: `panic_impl` language item function is not allowed to have `#[target_feature]`
+error: `#[panic_handler]` function is not allowed to have `#[target_feature]`
   --> $DIR/panic-handler-with-target-feature.rs:11:1
    |
 LL | #[target_feature(enable = "avx2")]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 LL |
 LL | fn panic(info: &PanicInfo) -> ! {
-   | ------------------------------- `panic_impl` language item function is not allowed to have `#[target_feature]`
+   | ------------------------------- `#[panic_handler]` function is not allowed to have `#[target_feature]`
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/panic-handler/panic-handler-with-track-caller.rs b/tests/ui/panic-handler/panic-handler-with-track-caller.rs
new file mode 100644
index 00000000000..09c94139e16
--- /dev/null
+++ b/tests/ui/panic-handler/panic-handler-with-track-caller.rs
@@ -0,0 +1,14 @@
+//@ compile-flags:-C panic=abort
+//@ only-x86_64
+
+#![no_std]
+#![no_main]
+
+use core::panic::PanicInfo;
+
+#[panic_handler]
+#[track_caller]
+//~^ ERROR `#[panic_handler]` function is not allowed to have `#[track_caller]`
+fn panic(info: &PanicInfo) -> ! {
+    unimplemented!();
+}
diff --git a/tests/ui/panic-handler/panic-handler-with-track-caller.stderr b/tests/ui/panic-handler/panic-handler-with-track-caller.stderr
new file mode 100644
index 00000000000..9ed387fc8d1
--- /dev/null
+++ b/tests/ui/panic-handler/panic-handler-with-track-caller.stderr
@@ -0,0 +1,11 @@
+error: `#[panic_handler]` function is not allowed to have `#[track_caller]`
+  --> $DIR/panic-handler-with-track-caller.rs:10:1
+   |
+LL | #[track_caller]
+   | ^^^^^^^^^^^^^^^
+LL |
+LL | fn panic(info: &PanicInfo) -> ! {
+   | ------------------------------- `#[panic_handler]` function is not allowed to have `#[target_feature]`
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/panic-handler/panic-handler-wrong-location.rs b/tests/ui/panic-handler/panic-handler-wrong-location.rs
index fc3ef401e3d..49685ee4592 100644
--- a/tests/ui/panic-handler/panic-handler-wrong-location.rs
+++ b/tests/ui/panic-handler/panic-handler-wrong-location.rs
@@ -3,6 +3,6 @@
 #![no_std]
 #![no_main]
 
-#[panic_handler] //~ ERROR `panic_impl` language item must be applied to a function
+#[panic_handler] //~ ERROR `panic_impl` lang item must be applied to a function
 #[no_mangle]
 static X: u32 = 42;
diff --git a/tests/ui/panic-handler/panic-handler-wrong-location.stderr b/tests/ui/panic-handler/panic-handler-wrong-location.stderr
index ae3ed5ab12b..66ee91aa4c1 100644
--- a/tests/ui/panic-handler/panic-handler-wrong-location.stderr
+++ b/tests/ui/panic-handler/panic-handler-wrong-location.stderr
@@ -1,4 +1,4 @@
-error[E0718]: `panic_impl` language item must be applied to a function
+error[E0718]: `panic_impl` lang item must be applied to a function
   --> $DIR/panic-handler-wrong-location.rs:6:1
    |
 LL | #[panic_handler]
diff --git a/tests/ui/unknown-language-item.rs b/tests/ui/unknown-language-item.rs
index 20ffef71497..ce206d20358 100644
--- a/tests/ui/unknown-language-item.rs
+++ b/tests/ui/unknown-language-item.rs
@@ -3,7 +3,7 @@
 
 #[lang = "foo"]
 fn bar() -> ! {
-//~^^ ERROR definition of an unknown language item: `foo`
+//~^^ ERROR definition of an unknown lang item: `foo`
     loop {}
 }
 
diff --git a/tests/ui/unknown-language-item.stderr b/tests/ui/unknown-language-item.stderr
index 1e0256867c5..832f1342418 100644
--- a/tests/ui/unknown-language-item.stderr
+++ b/tests/ui/unknown-language-item.stderr
@@ -1,8 +1,8 @@
-error[E0522]: definition of an unknown language item: `foo`
+error[E0522]: definition of an unknown lang item: `foo`
   --> $DIR/unknown-language-item.rs:4:1
    |
 LL | #[lang = "foo"]
-   | ^^^^^^^^^^^^^^^ definition of unknown language item `foo`
+   | ^^^^^^^^^^^^^^^ definition of unknown lang item `foo`
 
 error: aborting due to 1 previous error