Skip to main content

DiagnosticCode

Enum DiagnosticCode 

Source
pub enum DiagnosticCode {
Show 35 variants SyntaxError, ParamTypeCheck, AssignTypeCheck, UndefinedField, UndefinedName, Redefinition, Unused, UnnecessaryBranch, ArgumentCount, ReturnTypeMismatch, MacroRedefined, ConceptNotSatisfied, IncludeNotFound, MissingInclude, AccessInvisible, MissingReturn, AssignmentInCondition, ModuleNote, BracesAroundStatements, UseNullptr, UseOverride, SimplifyBooleanExpr, ElseAfterReturn, CStyleCast, UseAuto, MacroParentheses, ImplicitBoolConversion, DanglingReturn, DanglingField, UseAfterFree, UeNaming, UeGenerateBody, UeGeneratedHeader, UeMacroScope, UeSpecifier,
}
Expand description

One rule this analysis has.

See the module documentation for the three spellings of a rule and for why the code is derived.

Variants§

§

SyntaxError

The file does not parse — see super::syntax_error.

§

ParamTypeCheck

An argument’s type does not convert to the parameter it is passed for — see super::param_type_check.

§

AssignTypeCheck

A value does not convert to the type it is assigned to or initialised as — see super::assign_type_check.

§

UndefinedField

A member access on a type that does not declare that member — see super::undefined_field.

§

UndefinedName

A name nothing declares is read at this position — see super::undefined_name.

§

Redefinition

A name declared twice in one scope, where the language has no reading for it — see super::redefinition.

§

Unused

A declaration nothing uses — see super::unused.

§

UnnecessaryBranch

A branch the program cannot take, or a condition that is already decided — see super::unnecessary_branch.

§

ArgumentCount

More arguments than the callee takes, or fewer than it needs — see super::argument_count.

§

ReturnTypeMismatch

A return whose expression does not convert to the function’s return type — see super::return_type_mismatch.

§

MacroRedefined

A macro defined twice with different replacement lists — see super::macro_redefined.

§

ConceptNotSatisfied

An argument whose type does not satisfy the concept constraining its parameter — see super::concept_not_satisfied.

§

IncludeNotFound

A #include that names a file nobody can find — see super::include_not_found.

Separate from DiagnosticCode::SyntaxError for the reason a reader needs it separate: the file parses perfectly, and what is missing is a file it named.

§

MissingInclude

A type this file uses but does not include or import — see [super::missing_include].

The finding a reader turns into a fix: Widget w; compiles only because something upstream happened to include widget.h, and the file should say so itself. The rule never names the standard library — see the module.

§

AccessInvisible

A member reached from somewhere that may not reach it - see super::access_invisible.

§

MissingReturn

A function declared to return something whose body never returns - see super::missing_return.

§

AssignmentInCondition

= where the reader almost certainly meant == - see super::assignment_in_condition.

§

ModuleNote

A note about a module import, which the analysis knows rather than complains about — see Session::notes_about_the_modules.

Not a check: nothing is wrong with the file, and the reader is told where a file they named is. It is a code because it is a diagnostic a client shows, and the point of the enum is that everything shown has one.

§

BracesAroundStatements

if (x) / for (…) / while (…) whose body is a single statement — see [super::braces_around_statements].

§

UseNullptr

NULL where nullptr is meant — see [super::use_nullptr].

§

UseOverride

A virtual member function that overrides without saying override — see [super::use_override].

§

SimplifyBooleanExpr

if (x == true) and its siblings — see [super::simplify_boolean_expr].

§

ElseAfterReturn

An else after a branch that returns — see [super::else_after_return].

§

CStyleCast

A C-style cast — see [super::cstyle_cast].

§

UseAuto

An iterator declared by its full spelling — see [super::use_auto].

§

MacroParentheses

A macro body that needs its own parentheses — see [super::macro_parentheses].

§

ImplicitBoolConversion

A non-boolean value used as a condition — see [super::implicit_bool_conversion].

§

DanglingReturn

A reference, pointer or view of something that dies when the function returns — see [super::dangling_return].

§

DanglingField

A view, reference or pointer member that borrows something which does not outlive the object — see [super::dangling_field].

§

UseAfterFree

A pointer read after the memory it refers to was freed — see [super::use_after_free].

§

UeNaming

A type declared with Unreal Engine’s UCLASS/USTRUCT/UENUM and a name missing the prefix the engine requires — see [super::ue_naming].

§

UeGenerateBody

A UCLASS/USTRUCT whose body writes no GENERATED_BODY() — see [super::ue_generate_body].

§

UeGeneratedHeader

A file with reflection annotations and no *.generated.h include, or one that is not the last include — see [super::ue_generated_header].

§

UeMacroScope

A UPROPERTY/UFUNCTION on something the build tool does not reflect — see [super::ue_macro_scope].

§

UeSpecifier

A reflection specifier the engine does not know, which the build tool silently ignores — see [super::ue_specifier].

Implementations§

Source§

impl DiagnosticCode

Source

pub const ALL: [DiagnosticCode; 35]

Every code, in the order a list reads in.

The order is the one the module documentation of super describes: what the text is (the parse), then what it says about types, then what it says about a whole body, then the two that are about the reading rather than the program. A consumer that shows a settings screen, or a test that asserts every rule has a name and a module, iterates this.

Source

pub fn name(self) -> &'static str

The code a client is shown, and the spelling a config file uses: kebab case, and the module’s file name is the snake-case form of it (param-type-check ↔ param_type_check.rs).

The match has no _ arm on purpose. A new variant without a name is a compile error, which is the only way to be sure that no rule ever reaches a client unnamed.

Source

pub fn from_name(name: &str) -> Option<DiagnosticCode>

The code as a rule, or None for a code this build does not have.

The inverse of DiagnosticCode::name, and the round trip is asserted for every variant. A config reader uses this so that a misspelled rule is reported — treating an unknown name as “no rules” turns a typo into a silently disabled analysis, which is the failure mode this layer’s contract is written against.

Source

pub fn severity(self) -> RuleSeverity

How a client should draw it.

This crate does not speak LSP — the severities are its own, and the server maps them — for the reason it does not speak LSP anywhere else: the analysis is usable by a batch tool that has no protocol at all.

Source

pub fn tags(self) -> &'static [RuleTag]

What a client may grey out — the protocol’s DiagnosticTag, as this crate’s own vocabulary.

A tag is not a severity: a warning can be tagged Unnecessary and so can a hint. It says why the reader is being told, which is what a client needs to render the code as struck through rather than merely underlined — the difference between “look at this” and “this does nothing”.

Per code rather than per finding, for the same reason severity is: “nothing uses this name” is what the rule says, and it says it about every finding it produces.

Source

pub fn is_a_complaint(self) -> bool

Is this code a claim that something is wrong, as opposed to something the reader is told?

DiagnosticCode::ModuleNote is the only one that is not, and the distinction is the one the diagnostics channel already makes: a note draws no squiggle and does not count towards “this file has problems”.

Source

pub fn is_cpp_only(self) -> bool

Is this rule about C++ only? — the question a C project’s diagnostics turn on.

Two kinds of code answer yes, and they are one answer for the same reason: a rule that names C++ grammar cannot fire in a C file, and a rule that names C++ style must not. cstyle-cast is the second kind — in C, a C-style cast is the only cast there is, so telling a C program to write static_cast is telling it to write C++. use-nullptr is the same: NULL is what C has, and C23’s nullptr is a different question from the modernise one. implicit-bool-conversion belongs here too, because an int in a condition is the language’s own idiom in C, and a reader who turns this server on for a C project asked for C to be read rather than rewritten.

Measured before this existed: a C corpus configured with -std=c17 answered 14 cstyle-cast findings telling the program to write static_cast, and the same shape of noise was available to every rule below.

A project that states no language gets all of them: “not told” is not “C”, and a feature disappearing without a word is worse than a finding a project can switch off.

Source

pub fn is_unreal_only(self) -> bool

Does this rule only make sense in Unreal Engine code? — the switch [unreal] enable turns.

The two answers are one kind: ue-naming and ue-generate-body name conventions and macros of that engine, and a project that never writes UCLASS() has nothing for them to say. Like DiagnosticCode::is_cpp_only, “not told” is not the answer either way — a project that does not say it is Unreal is not treated as one.

Trait Implementations§

Source§

impl Clone for DiagnosticCode

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for DiagnosticCode

Source§

impl Debug for DiagnosticCode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for DiagnosticCode

Source§

impl Hash for DiagnosticCode

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for DiagnosticCode

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for DiagnosticCode

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for DiagnosticCode

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for DiagnosticCode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.