compiler/rustc_ast_lowering/src/errors.rs RUST 531 lines View on github.com → Search inside
1use rustc_errors::codes::*;2use rustc_errors::{DiagArgFromDisplay, DiagSymbolList};3use rustc_macros::{Diagnostic, Subdiagnostic};4use rustc_span::{Ident, Span, Symbol};56#[derive(Diagnostic)]7#[diag("parenthesized type parameters may only be used with a `Fn` trait", code = E0214)]8pub(crate) struct GenericTypeWithParentheses {9    #[primary_span]10    #[label("only `Fn` traits may use parentheses")]11    pub span: Span,12    #[subdiagnostic]13    pub sub: Option<UseAngleBrackets>,14}1516#[derive(Subdiagnostic)]17#[multipart_suggestion("use angle brackets instead", applicability = "maybe-incorrect")]18pub(crate) struct UseAngleBrackets {19    #[suggestion_part(code = "<")]20    pub open_param: Span,21    #[suggestion_part(code = ">")]22    pub close_param: Span,23}2425#[derive(Diagnostic)]26#[diag("invalid ABI: found `{$abi}`", code = E0703)]27#[note("invoke `{$command}` for a full list of supported calling conventions")]28pub(crate) struct InvalidAbi {29    #[primary_span]30    #[label("invalid ABI")]31    pub span: Span,32    pub abi: Symbol,33    pub command: String,34    #[subdiagnostic]35    pub suggestion: Option<InvalidAbiSuggestion>,36}3738#[derive(Diagnostic)]39#[diag("default fields are not supported in tuple structs")]40pub(crate) struct TupleStructWithDefault {41    #[primary_span]42    #[label("default fields are only supported on structs")]43    pub span: Span,44}4546#[derive(Subdiagnostic)]47#[suggestion(48    "there's a similarly named valid ABI `{$suggestion}`",49    code = "\"{suggestion}\"",50    applicability = "maybe-incorrect",51    style = "verbose"52)]53pub(crate) struct InvalidAbiSuggestion {54    #[primary_span]55    pub span: Span,56    pub suggestion: String,57}5859#[derive(Diagnostic)]60#[diag("parenthesized generic arguments cannot be used in associated type constraints")]61pub(crate) struct AssocTyParentheses {62    #[primary_span]63    pub span: Span,64    #[subdiagnostic]65    pub sub: AssocTyParenthesesSub,66}6768#[derive(Subdiagnostic)]69pub(crate) enum AssocTyParenthesesSub {70    #[multipart_suggestion("remove these parentheses")]71    Empty {72        #[suggestion_part(code = "")]73        parentheses_span: Span,74    },75    #[multipart_suggestion("use angle brackets instead")]76    NotEmpty {77        #[suggestion_part(code = "<")]78        open_param: Span,79        #[suggestion_part(code = ">")]80        close_param: Span,81    },82}8384#[derive(Diagnostic)]85#[diag("`impl Trait` is not allowed in {$position}", code = E0562)]86#[note("`impl Trait` is only allowed in arguments and return types of functions and methods")]87pub(crate) struct MisplacedImplTrait<'a> {88    #[primary_span]89    pub span: Span,90    pub position: DiagArgFromDisplay<'a>,91}9293#[derive(Diagnostic)]94#[diag("associated type bounds are not allowed in `dyn` types")]95pub(crate) struct MisplacedAssocTyBinding {96    #[primary_span]97    pub span: Span,98    #[suggestion(99        "use `impl Trait` to introduce a type instead",100        code = " = impl",101        applicability = "maybe-incorrect",102        style = "verbose"103    )]104    pub suggestion: Option<Span>,105}106107#[derive(Diagnostic)]108#[diag("in expressions, `_` can only be used on the left-hand side of an assignment")]109pub(crate) struct UnderscoreExprLhsAssign {110    #[primary_span]111    #[label("`_` not allowed here")]112    pub span: Span,113}114115#[derive(Diagnostic)]116#[diag("`await` is only allowed inside `async` functions and blocks", code = E0728)]117pub(crate) struct AwaitOnlyInAsyncFnAndBlocks {118    #[primary_span]119    #[label("only allowed inside `async` functions and blocks")]120    pub await_kw_span: Span,121    #[label("this is not `async`")]122    pub item_span: Option<Span>,123}124125#[derive(Diagnostic)]126#[diag("too many parameters for a coroutine (expected 0 or 1 parameters)", code = E0628)]127pub(crate) struct CoroutineTooManyParameters {128    #[primary_span]129    pub fn_decl_span: Span,130}131132#[derive(Diagnostic)]133#[diag("closures cannot be static", code = E0697)]134pub(crate) struct ClosureCannotBeStatic {135    #[primary_span]136    pub fn_decl_span: Span,137}138139#[derive(Diagnostic)]140#[diag("functional record updates are not allowed in destructuring assignments")]141pub(crate) struct FunctionalRecordUpdateDestructuringAssignment {142    #[primary_span]143    #[suggestion(144        "consider removing the trailing pattern",145        code = "",146        applicability = "machine-applicable"147    )]148    pub span: Span,149}150151#[derive(Diagnostic)]152#[diag("`async` coroutines are not yet supported", code = E0727)]153pub(crate) struct AsyncCoroutinesNotSupported {154    #[primary_span]155    pub span: Span,156}157158#[derive(Diagnostic)]159#[diag("inline assembly is unsupported on this target", code = E0472)]160pub(crate) struct InlineAsmUnsupportedTarget {161    #[primary_span]162    pub span: Span,163}164165#[derive(Diagnostic)]166#[diag("the `att_syntax` option is only supported on x86")]167pub(crate) struct AttSyntaxOnlyX86 {168    #[primary_span]169    pub span: Span,170}171172#[derive(Diagnostic)]173#[diag("`{$prev_name}` ABI specified multiple times")]174pub(crate) struct AbiSpecifiedMultipleTimes {175    #[primary_span]176    pub abi_span: Span,177    pub prev_name: Symbol,178    #[label("previously specified here")]179    pub prev_span: Span,180    #[note("these ABIs are equivalent on the current target")]181    pub equivalent: bool,182}183184#[derive(Diagnostic)]185#[diag("`clobber_abi` is not supported on this target")]186pub(crate) struct ClobberAbiNotSupported {187    #[primary_span]188    pub abi_span: Span,189}190191#[derive(Diagnostic)]192#[note("the following ABIs are supported on this target: {$supported_abis}")]193#[diag("invalid ABI for `clobber_abi`")]194pub(crate) struct InvalidAbiClobberAbi<'a> {195    #[primary_span]196    pub abi_span: Span,197    pub supported_abis: DiagSymbolList<&'a str>,198}199200#[derive(Diagnostic)]201#[diag("invalid register `{$reg}`: {$error}")]202pub(crate) struct InvalidRegister<'a> {203    #[primary_span]204    pub op_span: Span,205    pub reg: Symbol,206    pub error: &'a str,207}208209#[derive(Diagnostic)]210#[note(211    "the following register classes are supported on this target: {$supported_register_classes}"212)]213#[diag("invalid register class `{$reg_class}`: unknown register class")]214pub(crate) struct InvalidRegisterClass {215    #[primary_span]216    pub op_span: Span,217    pub reg_class: Symbol,218    pub supported_register_classes: DiagSymbolList<Symbol>,219}220221#[derive(Diagnostic)]222#[diag("invalid asm template modifier `{$modifier}` for this register class")]223pub(crate) struct InvalidAsmTemplateModifierRegClass {224    #[primary_span]225    #[label("template modifier")]226    pub placeholder_span: Span,227    #[label("argument")]228    pub op_span: Span,229    pub modifier: String,230    #[subdiagnostic]231    pub sub: InvalidAsmTemplateModifierRegClassSub,232}233234#[derive(Subdiagnostic)]235pub(crate) enum InvalidAsmTemplateModifierRegClassSub {236    #[note(237        "the `{$class_name}` register class supports the following template modifiers: {$modifiers}"238    )]239    SupportModifier { class_name: Symbol, modifiers: DiagSymbolList<char> },240    #[note("the `{$class_name}` register class does not support template modifiers")]241    DoesNotSupportModifier { class_name: Symbol },242}243244#[derive(Diagnostic)]245#[diag("asm template modifiers are not allowed for `const` arguments")]246pub(crate) struct InvalidAsmTemplateModifierConst {247    #[primary_span]248    #[label("template modifier")]249    pub placeholder_span: Span,250    #[label("argument")]251    pub op_span: Span,252}253254#[derive(Diagnostic)]255#[diag("asm template modifiers are not allowed for `sym` arguments")]256pub(crate) struct InvalidAsmTemplateModifierSym {257    #[primary_span]258    #[label("template modifier")]259    pub placeholder_span: Span,260    #[label("argument")]261    pub op_span: Span,262}263264#[derive(Diagnostic)]265#[diag("asm template modifiers are not allowed for `label` arguments")]266pub(crate) struct InvalidAsmTemplateModifierLabel {267    #[primary_span]268    #[label("template modifier")]269    pub placeholder_span: Span,270    #[label("argument")]271    pub op_span: Span,272}273274#[derive(Diagnostic)]275#[diag(276    "register class `{$reg_class_name}` can only be used as a clobber, not as an input or output"277)]278pub(crate) struct RegisterClassOnlyClobber {279    #[primary_span]280    pub op_span: Span,281    pub reg_class_name: Symbol,282}283284#[derive(Diagnostic)]285#[diag("register class `{$reg_class_name}` can only be used as a clobber in stable")]286pub(crate) struct RegisterClassOnlyClobberStable {287    #[primary_span]288    pub op_span: Span,289    pub reg_class_name: Symbol,290}291292#[derive(Diagnostic)]293#[diag("register `{$reg1_name}` conflicts with register `{$reg2_name}`")]294pub(crate) struct RegisterConflict<'a> {295    #[primary_span]296    #[label("register `{$reg1_name}`")]297    pub op_span1: Span,298    #[label("register `{$reg2_name}`")]299    pub op_span2: Span,300    pub reg1_name: &'a str,301    pub reg2_name: &'a str,302    #[help("use `lateout` instead of `out` to avoid conflict")]303    pub in_out: Option<Span>,304}305306#[derive(Diagnostic)]307#[help("remove this and bind each tuple field independently")]308#[diag("`{$ident_name} @` is not allowed in a {$ctx}")]309pub(crate) struct SubTupleBinding<'a> {310    #[primary_span]311    #[label("this is only allowed in slice patterns")]312    #[suggestion(313        "if you don't need to use the contents of {$ident}, discard the tuple's remaining fields",314        style = "verbose",315        code = "..",316        applicability = "maybe-incorrect"317    )]318    pub span: Span,319    pub ident: Ident,320    pub ident_name: Symbol,321    pub ctx: &'a str,322}323324#[derive(Diagnostic)]325#[diag("`..` can only be used once per {$ctx} pattern")]326pub(crate) struct ExtraDoubleDot<'a> {327    #[primary_span]328    #[label("can only be used once per {$ctx} pattern")]329    pub span: Span,330    #[label("previously used here")]331    pub prev_span: Span,332    pub ctx: &'a str,333}334335#[derive(Diagnostic)]336#[note("only allowed in tuple, tuple struct, and slice patterns")]337#[diag("`..` patterns are not allowed here")]338pub(crate) struct MisplacedDoubleDot {339    #[primary_span]340    pub span: Span,341}342343#[derive(Diagnostic)]344#[diag("`match` arm with no body")]345pub(crate) struct MatchArmWithNoBody {346    #[primary_span]347    pub span: Span,348    #[suggestion(349        "add a body after the pattern",350        code = " => todo!(),",351        applicability = "has-placeholders"352    )]353    pub suggestion: Span,354}355356#[derive(Diagnostic)]357#[diag("a never pattern is always unreachable")]358pub(crate) struct NeverPatternWithBody {359    #[primary_span]360    #[label("this will never be executed")]361    #[suggestion("remove this expression", code = "", applicability = "maybe-incorrect")]362    pub span: Span,363}364365#[derive(Diagnostic)]366#[diag("a guard on a never pattern will never be run")]367pub(crate) struct NeverPatternWithGuard {368    #[primary_span]369    #[suggestion("remove this guard", code = "", applicability = "maybe-incorrect")]370    pub span: Span,371}372373#[derive(Diagnostic)]374#[diag("arbitrary expressions aren't allowed in patterns")]375pub(crate) struct ArbitraryExpressionInPattern {376    #[primary_span]377    pub span: Span,378    #[note("the `expr` fragment specifier forces the metavariable's content to be an expression")]379    pub pattern_from_macro_note: bool,380    #[help("use a named `const`-item or an `if`-guard (`x if x == const {\"{ ... }\"}`) instead")]381    pub const_block_in_pattern_help: bool,382}383384#[derive(Diagnostic)]385#[diag("inclusive range with no end")]386pub(crate) struct InclusiveRangeWithNoEnd {387    #[primary_span]388    pub span: Span,389}390391#[derive(Subdiagnostic)]392#[multipart_suggestion(393    "use the right argument notation and remove the return type",394    applicability = "machine-applicable",395    style = "verbose"396)]397/// Given `T: Tr<m() -> Ret>` or `T: Tr<m(Ty) -> Ret>`, suggest `T: Tr<m(..)>`.398pub(crate) struct RTNSuggestion {399    #[suggestion_part(code = "")]400    pub output: Span,401    #[suggestion_part(code = "(..)")]402    pub input: Span,403}404405#[derive(Diagnostic)]406pub(crate) enum BadReturnTypeNotation {407    #[diag("argument types not allowed with return type notation")]408    Inputs {409        #[primary_span]410        #[suggestion(411            "remove the input types",412            code = "(..)",413            applicability = "machine-applicable",414            style = "verbose"415        )]416        span: Span,417    },418    #[diag("return type not allowed with return type notation")]419    Output {420        #[primary_span]421        span: Span,422        #[subdiagnostic]423        suggestion: RTNSuggestion,424    },425    #[diag("return type notation arguments must be elided with `..`")]426    NeedsDots {427        #[primary_span]428        #[suggestion(429            "use the correct syntax by adding `..` to the arguments",430            code = "(..)",431            applicability = "machine-applicable",432            style = "verbose"433        )]434        span: Span,435    },436    #[diag("return type notation not allowed in this position yet")]437    Position {438        #[primary_span]439        span: Span,440    },441}442443#[derive(Diagnostic)]444#[diag("defaults for generic parameters are not allowed in `for<...>` binders")]445pub(crate) struct GenericParamDefaultInBinder {446    #[primary_span]447    pub span: Span,448}449450#[derive(Diagnostic)]451#[diag("`async` bound modifier only allowed on trait, not `{$descr}`")]452pub(crate) struct AsyncBoundNotOnTrait {453    #[primary_span]454    pub span: Span,455    pub descr: &'static str,456}457458#[derive(Diagnostic)]459#[diag("`async` bound modifier only allowed on `Fn`/`FnMut`/`FnOnce` traits")]460pub(crate) struct AsyncBoundOnlyForFnTraits {461    #[primary_span]462    pub span: Span,463}464465#[derive(Diagnostic)]466#[diag("`use<...>` precise capturing syntax not allowed in argument-position `impl Trait`")]467pub(crate) struct NoPreciseCapturesOnApit {468    #[primary_span]469    pub span: Span,470}471472#[derive(Diagnostic)]473#[diag("`yield` can only be used in `#[coroutine]` closures, or `gen` blocks")]474pub(crate) struct YieldInClosure {475    #[primary_span]476    pub span: Span,477    #[suggestion(478        "use `#[coroutine]` to make this closure a coroutine",479        code = "#[coroutine] ",480        applicability = "maybe-incorrect",481        style = "verbose"482    )]483    pub suggestion: Option<Span>,484}485486#[derive(Diagnostic)]487#[diag(488    "invalid argument to a legacy const generic: cannot have const blocks, closures, async blocks or items"489)]490pub(crate) struct InvalidLegacyConstGenericArg {491    #[primary_span]492    pub span: Span,493    #[subdiagnostic]494    pub suggestion: UseConstGenericArg,495}496497#[derive(Subdiagnostic)]498#[multipart_suggestion(499    "try using a const generic argument instead",500    applicability = "maybe-incorrect"501)]502pub(crate) struct UseConstGenericArg {503    #[suggestion_part(code = "::<{const_args}>")]504    pub end_of_fn: Span,505    pub const_args: String,506    pub other_args: String,507    #[suggestion_part(code = "{other_args}")]508    pub call_args: Span,509}510511#[derive(Diagnostic)]512#[diag("unions cannot have default field values")]513pub(crate) struct UnionWithDefault {514    #[primary_span]515    pub span: Span,516}517518#[derive(Diagnostic)]519#[diag("failed to resolve delegation callee")]520pub(crate) struct UnresolvedDelegationCallee {521    #[primary_span]522    pub span: Span,523}524525#[derive(Diagnostic)]526#[diag("encountered a cycle during delegation signature resolution")]527pub(crate) struct CycleInDelegationSignatureResolution {528    #[primary_span]529    pub span: Span,530}

Code quality findings 2

Info: Wildcard imports (`use some::path::*;`) can obscure the origin of names and lead to conflicts. Prefer importing specific items explicitly.
info maintainability wildcard-import
use rustc_errors::codes::*;
Maintainability Info: `todo!()` or `unimplemented!()` macros indicate incomplete code paths that will panic at runtime if reached. Ensure these are replaced with actual logic before production use.
info correctness todo-unimplemented
code = " => todo!(),",

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.