Critical: Use of 'unsafe' keyword bypasses Rust's safety guarantees. Requires careful auditing, clear justification (FFI, specific optimizations), and minimal scope.
code = "unsafe ",
1//! Errors emitted by ast_passes.23use rustc_abi::ExternAbi;4use rustc_errors::codes::*;5use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic};6use rustc_macros::{Diagnostic, Subdiagnostic};7use rustc_span::{Ident, Span, Symbol};89#[derive(Diagnostic)]10#[diag("visibility qualifiers are not permitted here", code = E0449)]11pub(crate) struct VisibilityNotPermitted {12 #[primary_span]13 pub span: Span,14 #[subdiagnostic]15 pub note: VisibilityNotPermittedNote,16 #[suggestion("remove the qualifier", code = "", applicability = "machine-applicable")]17 pub remove_qualifier_sugg: Span,18}1920#[derive(Subdiagnostic)]21pub(crate) enum VisibilityNotPermittedNote {22 #[note("enum variants and their fields always share the visibility of the enum they are in")]23 EnumVariant,24 #[note("trait items always share the visibility of their trait")]25 TraitImpl,26 #[note("place qualifiers on individual impl items instead")]27 IndividualImplItems,28 #[note("place qualifiers on individual foreign items instead")]29 IndividualForeignItems,30}31#[derive(Diagnostic)]32#[diag("redundant `const` fn marker in const impl")]33pub(crate) struct ImplFnConst {34 #[primary_span]35 #[suggestion("remove the `const`", code = "", applicability = "machine-applicable")]36 pub span: Span,37 #[label("this declares all associated functions implicitly const")]38 pub parent_constness: Span,39}4041#[derive(Diagnostic)]42#[diag("functions in {$in_impl ->43 [true] trait impls44 *[false] traits45 } cannot be declared const", code = E0379)]46pub(crate) struct TraitFnConst {47 #[primary_span]48 #[label(49 "functions in {$in_impl ->50 [true] trait impls51 *[false] traits52 } cannot be const"53 )]54 pub span: Span,55 pub in_impl: bool,56 #[label("this declares all associated functions implicitly const")]57 pub const_context_label: Option<Span>,58 #[suggestion(59 "remove the `const`{$requires_multiple_changes ->60 [true] {\" ...\"}61 *[false] {\"\"}62 }",63 code = ""64 )]65 pub remove_const_sugg: (Span, Applicability),66 pub requires_multiple_changes: bool,67 #[suggestion(68 "... and declare the impl to be const instead",69 code = "const ",70 applicability = "maybe-incorrect"71 )]72 pub make_impl_const_sugg: Option<Span>,73 #[suggestion(74 "... and declare the trait to be const instead",75 code = "const ",76 applicability = "maybe-incorrect"77 )]78 pub make_trait_const_sugg: Option<Span>,79}8081#[derive(Diagnostic)]82#[diag(83 "async functions are not allowed in `const` {$context ->84 [trait_impl] trait impls85 [impl] impls86 *[trait] traits87 }"88)]89pub(crate) struct AsyncFnInConstTraitOrTraitImpl {90 #[primary_span]91 pub async_keyword: Span,92 pub context: &'static str,93 #[label("associated functions of `const` cannot be declared `async`")]94 pub const_keyword: Span,95}9697#[derive(Diagnostic)]98#[diag("bounds cannot be used in this context")]99pub(crate) struct ForbiddenBound {100 #[primary_span]101 pub spans: Vec<Span>,102}103104#[derive(Diagnostic)]105#[diag("late-bound const parameters cannot be used currently")]106pub(crate) struct ForbiddenConstParam {107 #[primary_span]108 pub const_param_spans: Vec<Span>,109}110111#[derive(Diagnostic)]112#[diag("function can not have more than {$max_num_args} arguments")]113pub(crate) struct FnParamTooMany {114 #[primary_span]115 pub span: Span,116 pub max_num_args: usize,117}118119#[derive(Diagnostic)]120#[diag("`...` must be the last argument of a C-variadic function")]121pub(crate) struct FnParamCVarArgsNotLast {122 #[primary_span]123 pub span: Span,124}125126#[derive(Diagnostic)]127#[diag("documentation comments cannot be applied to function parameters")]128pub(crate) struct FnParamDocComment {129 #[primary_span]130 #[label("doc comments are not allowed here")]131 pub span: Span,132}133134#[derive(Diagnostic)]135#[diag(136 "allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters"137)]138pub(crate) struct FnParamForbiddenAttr {139 #[primary_span]140 pub span: Span,141}142143#[derive(Diagnostic)]144#[diag("`self` parameter is only allowed in associated functions")]145#[note("associated functions are those in `impl` or `trait` definitions")]146pub(crate) struct FnParamForbiddenSelf {147 #[primary_span]148 #[label("not semantically valid as function parameter")]149 pub span: Span,150}151152#[derive(Diagnostic)]153#[diag("`default` is only allowed on items in trait impls")]154pub(crate) struct ForbiddenDefault {155 #[primary_span]156 pub span: Span,157 #[label("`default` because of this")]158 pub def_span: Span,159}160161#[derive(Diagnostic)]162#[diag("`final` is only allowed on associated functions in traits")]163pub(crate) struct ForbiddenFinal {164 #[primary_span]165 pub span: Span,166 #[label("`final` because of this")]167 pub def_span: Span,168}169170#[derive(Diagnostic)]171#[diag("`final` is only allowed on associated functions if they have a body")]172pub(crate) struct ForbiddenFinalWithoutBody {173 #[primary_span]174 pub span: Span,175 #[label("`final` because of this")]176 pub def_span: Span,177}178179#[derive(Diagnostic)]180#[diag("associated constant in `impl` without body")]181pub(crate) struct AssocConstWithoutBody {182 #[primary_span]183 pub span: Span,184 #[suggestion(185 "provide a definition for the constant",186 code = " = <expr>;",187 applicability = "has-placeholders"188 )]189 pub replace_span: Span,190}191192#[derive(Diagnostic)]193#[diag("associated function in `impl` without body")]194pub(crate) struct AssocFnWithoutBody {195 #[primary_span]196 pub span: Span,197 #[suggestion(198 "provide a definition for the function",199 code = " {{ <body> }}",200 applicability = "has-placeholders"201 )]202 pub replace_span: Span,203}204205#[derive(Diagnostic)]206#[diag("associated type in `impl` without body")]207pub(crate) struct AssocTypeWithoutBody {208 #[primary_span]209 pub span: Span,210 #[suggestion(211 "provide a definition for the type",212 code = " = <type>;",213 applicability = "has-placeholders"214 )]215 pub replace_span: Span,216}217218#[derive(Diagnostic)]219#[diag("free constant item without body")]220pub(crate) struct ConstWithoutBody {221 #[primary_span]222 pub span: Span,223 #[suggestion(224 "provide a definition for the constant",225 code = " = <expr>;",226 applicability = "has-placeholders"227 )]228 pub replace_span: Span,229}230231#[derive(Diagnostic)]232#[diag("free static item without body")]233pub(crate) struct StaticWithoutBody {234 #[primary_span]235 pub span: Span,236 #[suggestion(237 "provide a definition for the static",238 code = " = <expr>;",239 applicability = "has-placeholders"240 )]241 pub replace_span: Span,242}243244#[derive(Diagnostic)]245#[diag("free type alias without body")]246pub(crate) struct TyAliasWithoutBody {247 #[primary_span]248 pub span: Span,249 #[suggestion(250 "provide a definition for the type",251 code = " = <type>;",252 applicability = "has-placeholders"253 )]254 pub replace_span: Span,255}256257#[derive(Diagnostic)]258#[diag("free function without a body")]259pub(crate) struct FnWithoutBody {260 #[primary_span]261 pub span: Span,262 #[suggestion(263 "provide a definition for the function",264 code = " {{ <body> }}",265 applicability = "has-placeholders"266 )]267 pub replace_span: Span,268 #[subdiagnostic]269 pub extern_block_suggestion: Option<ExternBlockSuggestion>,270}271272#[derive(Subdiagnostic)]273pub(crate) enum ExternBlockSuggestion {274 #[multipart_suggestion(275 "if you meant to declare an externally defined function, use an `extern` block",276 applicability = "maybe-incorrect"277 )]278 Implicit {279 #[suggestion_part(code = "extern {{")]280 start_span: Span,281 #[suggestion_part(code = " }}")]282 end_span: Span,283 },284 #[multipart_suggestion(285 "if you meant to declare an externally defined function, use an `extern` block",286 applicability = "maybe-incorrect"287 )]288 Explicit {289 #[suggestion_part(code = "extern \"{abi}\" {{")]290 start_span: Span,291 #[suggestion_part(code = " }}")]292 end_span: Span,293 abi: Symbol,294 },295}296297#[derive(Diagnostic)]298#[diag("items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers")]299pub(crate) struct InvalidSafetyOnExtern {300 #[primary_span]301 pub item_span: Span,302 #[suggestion(303 "add `unsafe` to this `extern` block",304 code = "unsafe ",305 applicability = "machine-applicable",306 style = "verbose"307 )]308 pub block: Option<Span>,309}310311#[derive(Diagnostic)]312#[diag(313 "items outside of `unsafe extern {\"{ }\"}` cannot be declared with `safe` safety qualifier"314)]315pub(crate) struct InvalidSafetyOnItem {316 #[primary_span]317 pub span: Span,318}319320#[derive(Diagnostic)]321#[diag("function pointers cannot be declared with `safe` safety qualifier")]322pub(crate) struct InvalidSafetyOnFnPtr {323 #[primary_span]324 pub span: Span,325}326327#[derive(Diagnostic)]328#[diag("static items cannot be declared with `unsafe` safety qualifier outside of `extern` block")]329pub(crate) struct UnsafeStatic {330 #[primary_span]331 pub span: Span,332}333334#[derive(Diagnostic)]335#[diag("bounds on `type`s in {$ctx} have no effect")]336pub(crate) struct BoundInContext<'a> {337 #[primary_span]338 pub span: Span,339 pub ctx: &'a str,340}341342#[derive(Diagnostic)]343#[diag("`type`s inside `extern` blocks cannot have {$descr}")]344#[note("for more information, visit https://doc.rust-lang.org/std/keyword.extern.html")]345pub(crate) struct ExternTypesCannotHave<'a> {346 #[primary_span]347 #[suggestion("remove the {$remove_descr}", code = "", applicability = "maybe-incorrect")]348 pub span: Span,349 pub descr: &'a str,350 pub remove_descr: &'a str,351 #[label("`extern` block begins here")]352 pub block_span: Span,353}354355#[derive(Diagnostic)]356#[diag("incorrect `{$kind}` inside `extern` block")]357#[note("for more information, visit https://doc.rust-lang.org/std/keyword.extern.html")]358pub(crate) struct BodyInExtern<'a> {359 #[primary_span]360 #[label("cannot have a body")]361 pub span: Span,362 #[label("the invalid body")]363 pub body: Span,364 #[label(365 "`extern` blocks define existing foreign {$kind}s and {$kind}s inside of them cannot have a body"366 )]367 pub block: Span,368 pub kind: &'a str,369}370371#[derive(Diagnostic)]372#[diag("incorrect function inside `extern` block")]373#[help(374 "you might have meant to write a function accessible through FFI, which can be done by writing `extern fn` outside of the `extern` block"375)]376#[note("for more information, visit https://doc.rust-lang.org/std/keyword.extern.html")]377pub(crate) struct FnBodyInExtern {378 #[primary_span]379 #[label("cannot have a body")]380 pub span: Span,381 #[suggestion("remove the invalid body", code = ";", applicability = "maybe-incorrect")]382 pub body: Span,383 #[label(384 "`extern` blocks define existing foreign functions and functions inside of them cannot have a body"385 )]386 pub block: Span,387}388389#[derive(Diagnostic)]390#[diag("functions in `extern` blocks cannot have `{$kw}` qualifier")]391pub(crate) struct FnQualifierInExtern {392 #[primary_span]393 #[suggestion("remove the `{$kw}` qualifier", code = "", applicability = "maybe-incorrect")]394 pub span: Span,395 #[label("in this `extern` block")]396 pub block: Span,397 pub kw: &'static str,398}399400#[derive(Diagnostic)]401#[diag("items in `extern` blocks cannot use non-ascii identifiers")]402#[note(403 "this limitation may be lifted in the future; see issue #83942 <https://github.com/rust-lang/rust/issues/83942> for more information"404)]405pub(crate) struct ExternItemAscii {406 #[primary_span]407 pub span: Span,408 #[label("in this `extern` block")]409 pub block: Span,410}411412#[derive(Diagnostic)]413#[diag("`...` is not supported for non-extern functions")]414#[help(415 "only `extern \"C\"` and `extern \"C-unwind\"` functions may have a C variable argument list"416)]417pub(crate) struct CVariadicNoExtern {418 #[primary_span]419 pub span: Span,420}421422#[derive(Diagnostic)]423#[diag("functions with a C variable argument list must be unsafe")]424pub(crate) struct CVariadicMustBeUnsafe {425 #[primary_span]426 pub span: Span,427428 #[suggestion(429 "add the `unsafe` keyword to this definition",430 applicability = "maybe-incorrect",431 code = "unsafe ",432 style = "verbose"433 )]434 pub unsafe_span: Span,435}436437#[derive(Diagnostic)]438#[diag("`...` is not supported for `extern \"{$abi}\"` functions")]439#[help(440 "only `extern \"C\"` and `extern \"C-unwind\"` functions may have a C variable argument list"441)]442pub(crate) struct CVariadicBadExtern {443 #[primary_span]444 pub span: Span,445 pub abi: &'static str,446 #[label("`extern \"{$abi}\"` because of this")]447 pub extern_span: Span,448}449450#[derive(Diagnostic)]451#[diag("`...` is not supported for `extern \"{$abi}\"` naked functions")]452#[help("C-variadic function must have a compatible calling convention")]453pub(crate) struct CVariadicBadNakedExtern {454 #[primary_span]455 pub span: Span,456 pub abi: &'static str,457 #[label("`extern \"{$abi}\"` because of this")]458 pub extern_span: Span,459}460461#[derive(Diagnostic)]462#[diag("`{$kind}` items in this context need a name")]463pub(crate) struct ItemUnderscore<'a> {464 #[primary_span]465 #[label("`_` is not a valid name for this `{$kind}` item")]466 pub span: Span,467 pub kind: &'a str,468}469470#[derive(Diagnostic)]471#[diag("`#[no_mangle]` requires ASCII identifier", code = E0754)]472pub(crate) struct NoMangleAscii {473 #[primary_span]474 pub span: Span,475}476477#[derive(Diagnostic)]478#[diag("trying to load file for module `{$name}` with non-ascii identifier name", code = E0754)]479#[help("consider using the `#[path]` attribute to specify filesystem path")]480pub(crate) struct ModuleNonAscii {481 #[primary_span]482 pub span: Span,483 pub name: Symbol,484}485486#[derive(Diagnostic)]487#[diag("auto traits cannot have generic parameters", code = E0567)]488pub(crate) struct AutoTraitGeneric {489 #[primary_span]490 #[suggestion(491 "remove the parameters",492 code = "",493 applicability = "machine-applicable",494 style = "tool-only"495 )]496 pub span: Span,497 #[label("auto trait cannot have generic parameters")]498 pub ident: Span,499}500501#[derive(Diagnostic)]502#[diag("auto traits cannot have super traits or lifetime bounds", code = E0568)]503pub(crate) struct AutoTraitBounds {504 #[primary_span]505 pub span: Vec<Span>,506 #[suggestion(507 "remove the super traits or lifetime bounds",508 code = "",509 applicability = "machine-applicable",510 style = "tool-only"511 )]512 pub removal: Span,513 #[label("auto traits cannot have super traits or lifetime bounds")]514 pub ident: Span,515}516517#[derive(Diagnostic)]518#[diag("auto traits cannot have associated items", code = E0380)]519pub(crate) struct AutoTraitItems {520 #[primary_span]521 pub spans: Vec<Span>,522 #[suggestion(523 "remove the associated items",524 code = "",525 applicability = "machine-applicable",526 style = "tool-only"527 )]528 pub total: Span,529 #[label("auto traits cannot have associated items")]530 pub ident: Span,531}532533#[derive(Diagnostic)]534#[diag("auto traits cannot be const")]535#[help("remove the `const` keyword")]536pub(crate) struct ConstAutoTrait {537 #[primary_span]538 pub span: Span,539}540541#[derive(Diagnostic)]542#[diag("generic arguments must come before the first constraint")]543pub(crate) struct ArgsBeforeConstraint {544 #[primary_span]545 pub arg_spans: Vec<Span>,546 #[label(547 "{$constraint_len ->548 [one] constraint549 *[other] constraints550 }"551 )]552 pub constraints: Span,553 #[label(554 "generic {$args_len ->555 [one] argument556 *[other] arguments557 }"558 )]559 pub args: Span,560 #[suggestion(561 "move the {$constraint_len ->562 [one] constraint563 *[other] constraints564 } after the generic {$args_len ->565 [one] argument566 *[other] arguments567 }",568 code = "{suggestion}",569 applicability = "machine-applicable",570 style = "verbose"571 )]572 pub data: Span,573 pub suggestion: String,574 pub constraint_len: usize,575 pub args_len: usize,576 #[subdiagnostic]577 pub constraint_spans: EmptyLabelManySpans,578 #[subdiagnostic]579 pub arg_spans2: EmptyLabelManySpans,580}581582pub(crate) struct EmptyLabelManySpans(pub Vec<Span>);583584// The derive for `Vec<Span>` does multiple calls to `span_label`, adding commas between each585impl Subdiagnostic for EmptyLabelManySpans {586 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {587 diag.span_labels(self.0, "");588 }589}590591#[derive(Diagnostic)]592#[diag("patterns aren't allowed in function pointer types", code = E0561)]593pub(crate) struct PatternFnPointer {594 #[primary_span]595 pub span: Span,596}597598#[derive(Diagnostic)]599#[diag("only a single explicit lifetime bound is permitted", code = E0226)]600pub(crate) struct TraitObjectBound {601 #[primary_span]602 pub span: Span,603}604605#[derive(Diagnostic)]606#[diag("nested `impl Trait` is not allowed", code = E0666)]607pub(crate) struct NestedImplTrait {608 #[primary_span]609 pub span: Span,610 #[label("outer `impl Trait`")]611 pub outer: Span,612 #[label("nested `impl Trait` here")]613 pub inner: Span,614}615616#[derive(Diagnostic)]617#[diag("at least one trait must be specified")]618pub(crate) struct AtLeastOneTrait {619 #[primary_span]620 pub span: Span,621}622623#[derive(Diagnostic)]624#[diag("{$param_ord} parameters must be declared prior to {$max_param} parameters")]625pub(crate) struct OutOfOrderParams<'a> {626 #[primary_span]627 pub spans: Vec<Span>,628 #[suggestion(629 "reorder the parameters: lifetimes, then consts and types",630 code = "{ordered_params}",631 applicability = "machine-applicable"632 )]633 pub sugg_span: Span,634 pub param_ord: String,635 pub max_param: String,636 pub ordered_params: &'a str,637}638639#[derive(Diagnostic)]640#[diag("`impl Trait for .. {\"{}\"}` is an obsolete syntax")]641#[help("use `auto trait Trait {\"{}\"}` instead")]642pub(crate) struct ObsoleteAuto {643 #[primary_span]644 pub span: Span,645}646647#[derive(Diagnostic)]648#[diag("negative impls cannot be unsafe", code = E0198)]649pub(crate) struct UnsafeNegativeImpl {650 #[primary_span]651 pub span: Span,652 #[label("negative because of this")]653 pub negative: Span,654 #[label("unsafe because of this")]655 pub r#unsafe: Span,656}657658#[derive(Diagnostic)]659#[diag("{$kind} cannot be declared unsafe")]660pub(crate) struct UnsafeItem {661 #[primary_span]662 pub span: Span,663 pub kind: &'static str,664}665666#[derive(Diagnostic)]667#[diag("extern blocks must be unsafe")]668pub(crate) struct MissingUnsafeOnExtern {669 #[primary_span]670 pub span: Span,671}672673#[derive(Diagnostic)]674#[diag("extern blocks should be unsafe")]675pub(crate) struct MissingUnsafeOnExternLint {676 #[suggestion(677 "needs `unsafe` before the extern keyword",678 code = "unsafe ",679 applicability = "machine-applicable"680 )]681 pub suggestion: Span,682}683684#[derive(Diagnostic)]685#[diag("unions cannot have zero fields")]686pub(crate) struct FieldlessUnion {687 #[primary_span]688 pub span: Span,689}690691#[derive(Diagnostic)]692#[diag("where clauses are not allowed after the type for type aliases")]693#[note("see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information")]694pub(crate) struct WhereClauseAfterTypeAlias {695 #[primary_span]696 pub span: Span,697 #[help("add `#![feature(lazy_type_alias)]` to the crate attributes to enable")]698 pub help: bool,699}700701#[derive(Diagnostic)]702#[diag("where clauses are not allowed before the type for type aliases")]703#[note("see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information")]704pub(crate) struct WhereClauseBeforeTypeAlias {705 #[primary_span]706 pub span: Span,707 #[subdiagnostic]708 pub sugg: WhereClauseBeforeTypeAliasSugg,709}710711#[derive(Subdiagnostic)]712pub(crate) enum WhereClauseBeforeTypeAliasSugg {713 #[suggestion("remove this `where`", applicability = "machine-applicable", code = "")]714 Remove {715 #[primary_span]716 span: Span,717 },718 #[multipart_suggestion(719 "move it to the end of the type declaration",720 applicability = "machine-applicable",721 style = "verbose"722 )]723 Move {724 #[suggestion_part(code = "")]725 left: Span,726 snippet: String,727 #[suggestion_part(code = "{snippet}")]728 right: Span,729 },730}731732#[derive(Diagnostic)]733#[diag("generic parameters with a default must be trailing")]734pub(crate) struct GenericDefaultTrailing {735 #[primary_span]736 pub span: Span,737}738739#[derive(Diagnostic)]740#[diag("nested quantification of lifetimes", code = E0316)]741pub(crate) struct NestedLifetimes {742 #[primary_span]743 pub span: Span,744}745746#[derive(Diagnostic)]747#[diag("const trait bounds are not allowed in trait object types")]748pub(crate) struct ConstBoundTraitObject {749 #[primary_span]750 pub span: Span,751}752753// FIXME(const_trait_impl): Consider making the note/reason the message of the diagnostic.754// FIXME(const_trait_impl): Provide structured suggestions (e.g., add `const` here).755#[derive(Diagnostic)]756#[diag("`[const]` is not allowed here")]757pub(crate) struct TildeConstDisallowed {758 #[primary_span]759 pub span: Span,760 #[subdiagnostic]761 pub reason: TildeConstReason,762}763764#[derive(Subdiagnostic, Copy, Clone)]765pub(crate) enum TildeConstReason {766 #[note("closures cannot have `[const]` trait bounds")]767 Closure,768 #[note("this function is not `const`, so it cannot have `[const]` trait bounds")]769 Function {770 #[primary_span]771 ident: Span,772 },773 #[note("this trait is not `const`, so it cannot have `[const]` trait bounds")]774 Trait {775 #[primary_span]776 span: Span,777 },778 #[note("this impl is not `const`, so it cannot have `[const]` trait bounds")]779 TraitImpl {780 #[primary_span]781 span: Span,782 },783 #[note("inherent impls cannot have `[const]` trait bounds")]784 Impl {785 #[primary_span]786 span: Span,787 },788 #[note("associated types in non-`const` traits cannot have `[const]` trait bounds")]789 TraitAssocTy {790 #[primary_span]791 span: Span,792 },793 #[note("associated types in non-const impls cannot have `[const]` trait bounds")]794 TraitImplAssocTy {795 #[primary_span]796 span: Span,797 },798 #[note("inherent associated types cannot have `[const]` trait bounds")]799 InherentAssocTy {800 #[primary_span]801 span: Span,802 },803 #[note("structs cannot have `[const]` trait bounds")]804 Struct {805 #[primary_span]806 span: Span,807 },808 #[note("enums cannot have `[const]` trait bounds")]809 Enum {810 #[primary_span]811 span: Span,812 },813 #[note("unions cannot have `[const]` trait bounds")]814 Union {815 #[primary_span]816 span: Span,817 },818 #[note("anonymous constants cannot have `[const]` trait bounds")]819 AnonConst {820 #[primary_span]821 span: Span,822 },823 #[note("trait objects cannot have `[const]` trait bounds")]824 TraitObject,825 #[note("this item cannot have `[const]` trait bounds")]826 Item,827}828829#[derive(Diagnostic)]830#[diag("functions cannot be both `const` and `{$coroutine_kind}`")]831pub(crate) struct ConstAndCoroutine {832 #[primary_span]833 pub spans: Vec<Span>,834 #[label("`const` because of this")]835 pub const_span: Span,836 #[label("`{$coroutine_kind}` because of this")]837 pub coroutine_span: Span,838 #[label("{\"\"}")]839 pub span: Span,840 pub coroutine_kind: &'static str,841}842843#[derive(Diagnostic)]844#[diag("functions cannot be both `{$coroutine_kind}` and C-variadic")]845pub(crate) struct CoroutineAndCVariadic {846 #[primary_span]847 pub spans: Vec<Span>,848 pub coroutine_kind: &'static str,849 #[label("`{$coroutine_kind}` because of this")]850 pub coroutine_span: Span,851 #[label("C-variadic because of this")]852 pub variadic_span: Span,853}854855#[derive(Diagnostic)]856#[diag("the `{$target}` target does not support c-variadic functions")]857pub(crate) struct CVariadicNotSupported<'a> {858 #[primary_span]859 pub variadic_span: Span,860 pub target: &'a str,861}862863#[derive(Diagnostic)]864#[diag("patterns aren't allowed in foreign function declarations", code = E0130)]865// FIXME: deduplicate with rustc_lint (`BuiltinLintDiag::PatternsInFnsWithoutBody`)866pub(crate) struct PatternInForeign {867 #[primary_span]868 #[label("pattern not allowed in foreign function")]869 pub span: Span,870}871872#[derive(Diagnostic)]873#[diag("patterns aren't allowed in functions without bodies", code = E0642)]874// FIXME: deduplicate with rustc_lint (`BuiltinLintDiag::PatternsInFnsWithoutBody`)875pub(crate) struct PatternInBodiless {876 #[primary_span]877 #[label("pattern not allowed in function without body")]878 pub span: Span,879}880881#[derive(Diagnostic)]882#[diag("equality constraints are not yet supported in `where` clauses")]883#[note("see issue #20041 <https://github.com/rust-lang/rust/issues/20041> for more information")]884pub(crate) struct EqualityInWhere {885 #[primary_span]886 #[label("not supported")]887 pub span: Span,888 #[subdiagnostic]889 pub assoc: Option<AssociatedSuggestion>,890 #[subdiagnostic]891 pub assoc2: Option<AssociatedSuggestion2>,892}893894#[derive(Subdiagnostic)]895#[suggestion(896 "if `{$ident}` is an associated type you're trying to set, use the associated type binding syntax",897 code = "{param}: {path}",898 style = "verbose",899 applicability = "maybe-incorrect"900)]901pub(crate) struct AssociatedSuggestion {902 #[primary_span]903 pub span: Span,904 pub ident: Ident,905 pub param: Ident,906 pub path: String,907}908909#[derive(Subdiagnostic)]910#[multipart_suggestion(911 "if `{$trait_segment}::{$potential_assoc}` is an associated type you're trying to set, use the associated type binding syntax",912 applicability = "maybe-incorrect"913)]914pub(crate) struct AssociatedSuggestion2 {915 #[suggestion_part(code = "{args}")]916 pub span: Span,917 pub args: String,918 #[suggestion_part(code = "")]919 pub predicate: Span,920 pub trait_segment: Ident,921 pub potential_assoc: Ident,922}923924#[derive(Diagnostic)]925#[diag("`#![feature]` may not be used on the {$channel} release channel", code = E0554)]926pub(crate) struct FeatureOnNonNightly {927 #[primary_span]928 pub span: Span,929 pub channel: &'static str,930 #[subdiagnostic]931 pub stable_features: Vec<StableFeature>,932 #[suggestion("remove the attribute", code = "", applicability = "machine-applicable")]933 pub sugg: Option<Span>,934}935936#[derive(Subdiagnostic)]937#[help(938 "the feature `{$name}` has been stable since `{$since}` and no longer requires an attribute to enable"939)]940pub(crate) struct StableFeature {941 pub name: Symbol,942 pub since: Symbol,943}944945#[derive(Diagnostic)]946#[diag("`{$f1}` and `{$f2}` are incompatible, using them at the same time is not allowed")]947#[help("remove one of these features")]948pub(crate) struct IncompatibleFeatures {949 #[primary_span]950 pub spans: Vec<Span>,951 pub f1: Symbol,952 pub f2: Symbol,953}954955#[derive(Diagnostic)]956#[diag("`{$parent}` requires {$missing} to be enabled")]957#[help("enable all of these features")]958pub(crate) struct MissingDependentFeatures {959 #[primary_span]960 pub parent_span: Span,961 pub parent: Symbol,962 pub missing: String,963}964965#[derive(Diagnostic)]966#[diag("negative bounds are not supported")]967pub(crate) struct NegativeBoundUnsupported {968 #[primary_span]969 pub span: Span,970}971972#[derive(Diagnostic)]973#[diag("associated type constraints not allowed on negative bounds")]974pub(crate) struct ConstraintOnNegativeBound {975 #[primary_span]976 pub span: Span,977}978979#[derive(Diagnostic)]980#[diag("parenthetical notation may not be used for negative bounds")]981pub(crate) struct NegativeBoundWithParentheticalNotation {982 #[primary_span]983 pub span: Span,984}985986#[derive(Diagnostic)]987#[diag("`match` arm with no body")]988pub(crate) struct MatchArmWithNoBody {989 #[primary_span]990 pub span: Span,991 // We include the braces around `todo!()` so that a comma is optional, and we don't have to have992 // any logic looking at the arm being replaced if there was a comma already or not for the993 // resulting code to be correct.994 #[suggestion(995 "add a body after the pattern",996 code = " => {{ todo!() }}",997 applicability = "has-placeholders",998 style = "verbose"999 )]1000 pub suggestion: Span,1001}10021003#[derive(Diagnostic)]1004#[diag("`use<...>` precise capturing syntax not allowed in {$loc}")]1005pub(crate) struct PreciseCapturingNotAllowedHere {1006 #[primary_span]1007 pub span: Span,1008 pub loc: &'static str,1009}10101011#[derive(Diagnostic)]1012#[diag("duplicate `use<...>` precise capturing syntax")]1013pub(crate) struct DuplicatePreciseCapturing {1014 #[primary_span]1015 pub bound1: Span,1016 #[label("second `use<...>` here")]1017 pub bound2: Span,1018}10191020#[derive(Diagnostic)]1021#[diag("`extern` declarations without an explicit ABI are disallowed")]1022#[help("prior to Rust 2024, a default ABI was inferred")]1023pub(crate) struct MissingAbi {1024 #[primary_span]1025 #[suggestion("specify an ABI", code = "extern \"<abi>\"", applicability = "has-placeholders")]1026 pub span: Span,1027}10281029#[derive(Diagnostic)]1030#[diag("`extern` declarations without an explicit ABI are deprecated")]1031pub(crate) struct MissingAbiSugg {1032 #[suggestion(1033 "explicitly specify the {$default_abi} ABI",1034 code = "extern {default_abi}",1035 applicability = "machine-applicable"1036 )]1037 pub span: Span,1038 pub default_abi: ExternAbi,1039}10401041#[derive(Diagnostic)]1042#[diag("foreign functions with the \"custom\" ABI cannot be safe")]1043pub(crate) struct AbiCustomSafeForeignFunction {1044 #[primary_span]1045 pub span: Span,10461047 #[suggestion(1048 "remove the `safe` keyword from this definition",1049 applicability = "maybe-incorrect",1050 code = "",1051 style = "verbose"1052 )]1053 pub safe_span: Span,1054}10551056#[derive(Diagnostic)]1057#[diag("functions with the \"custom\" ABI must be unsafe")]1058pub(crate) struct AbiCustomSafeFunction {1059 #[primary_span]1060 pub span: Span,1061 pub abi: ExternAbi,10621063 #[suggestion(1064 "add the `unsafe` keyword to this definition",1065 applicability = "maybe-incorrect",1066 code = "unsafe ",1067 style = "verbose"1068 )]1069 pub unsafe_span: Span,1070}10711072#[derive(Diagnostic)]1073#[diag("functions with the {$abi} ABI cannot be `{$coroutine_kind_str}`")]1074pub(crate) struct AbiCannotBeCoroutine {1075 #[primary_span]1076 pub span: Span,1077 pub abi: ExternAbi,10781079 #[suggestion(1080 "remove the `{$coroutine_kind_str}` keyword from this definition",1081 applicability = "maybe-incorrect",1082 code = "",1083 style = "verbose"1084 )]1085 pub coroutine_kind_span: Span,1086 pub coroutine_kind_str: &'static str,1087}10881089#[derive(Diagnostic)]1090#[diag("invalid signature for `extern {$abi}` function")]1091#[note("functions with the {$abi} ABI cannot have any parameters or return type")]1092pub(crate) struct AbiMustNotHaveParametersOrReturnType {1093 #[primary_span]1094 pub spans: Vec<Span>,1095 pub abi: ExternAbi,10961097 #[suggestion(1098 "remove the parameters and return type",1099 applicability = "maybe-incorrect",1100 code = "{padding}fn {symbol}()",1101 style = "verbose"1102 )]1103 pub suggestion_span: Span,1104 pub symbol: Symbol,1105 pub padding: &'static str,1106}11071108#[derive(Diagnostic)]1109#[diag("invalid signature for `extern {$abi}` function")]1110#[note("functions with the {$abi} ABI cannot have a return type")]1111pub(crate) struct AbiMustNotHaveReturnType {1112 #[primary_span]1113 #[help("remove the return type")]1114 pub span: Span,1115 pub abi: ExternAbi,1116}11171118#[derive(Diagnostic)]1119#[diag("invalid signature for `extern \"x86-interrupt\"` function")]1120#[note(1121 "functions with the \"x86-interrupt\" ABI must be have either 1 or 2 parameters (but found {$param_count})"1122)]1123pub(crate) struct AbiX86Interrupt {1124 #[primary_span]1125 pub spans: Vec<Span>,1126 pub param_count: usize,1127}11281129#[derive(Diagnostic)]1130#[diag("scalable vectors must be tuple structs")]1131pub(crate) struct ScalableVectorNotTupleStruct {1132 #[primary_span]1133 pub span: Span,1134}11351136#[derive(Diagnostic)]1137#[diag("scalable vectors are not supported on this architecture")]1138pub(crate) struct ScalableVectorBadArch {1139 #[primary_span]1140 pub span: Span,1141}11421143#[derive(Diagnostic)]1144#[diag("`#[track_caller]` can only be used with the Rust ABI", code = E0737)]1145pub(crate) struct RequiresRustAbi {1146 #[primary_span]1147 #[label("using `#[track_caller]` here")]1148 pub track_caller_span: Span,1149 #[label("not using the Rust ABI because of this")]1150 pub extern_abi_span: Span,1151}11521153#[derive(Diagnostic)]1154#[diag("visibility qualifiers have no effect on `const _` declarations")]1155#[note("`const _` does not declare a name, so there is nothing for the qualifier to apply to")]1156pub(crate) struct UnusedVisibility {1157 #[suggestion(1158 "remove the qualifier",1159 style = "short",1160 code = "",1161 applicability = "machine-applicable"1162 )]1163 pub span: Span,1164}11651166#[derive(Subdiagnostic)]1167#[suggestion(1168 "remove `mut` from the parameter",1169 code = "{ident}",1170 applicability = "machine-applicable"1171)]1172pub(crate) struct PatternsInFnsWithoutBodySub {1173 #[primary_span]1174 pub span: Span,11751176 pub ident: Ident,1177}11781179#[derive(Diagnostic)]1180pub(crate) enum PatternsInFnsWithoutBody {1181 #[diag("patterns aren't allowed in foreign function declarations")]1182 Foreign {1183 #[subdiagnostic]1184 sub: PatternsInFnsWithoutBodySub,1185 },1186 #[diag("patterns aren't allowed in functions without bodies")]1187 Bodiless {1188 #[subdiagnostic]1189 sub: PatternsInFnsWithoutBodySub,1190 },1191}11921193#[derive(Diagnostic)]1194#[diag("where clause not allowed here")]1195#[note("see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information")]1196pub(crate) struct DeprecatedWhereClauseLocation {1197 #[subdiagnostic]1198 pub suggestion: DeprecatedWhereClauseLocationSugg,1199}12001201#[derive(Subdiagnostic)]1202pub(crate) enum DeprecatedWhereClauseLocationSugg {1203 #[multipart_suggestion(1204 "move it to the end of the type declaration",1205 applicability = "machine-applicable"1206 )]1207 MoveToEnd {1208 #[suggestion_part(code = "")]1209 left: Span,1210 #[suggestion_part(code = "{sugg}")]1211 right: Span,12121213 sugg: String,1214 },1215 #[suggestion("remove this `where`", code = "", applicability = "machine-applicable")]1216 RemoveWhere {1217 #[primary_span]1218 span: Span,1219 },1220}
Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.