1
Fork 0

Auto-generate lint documentation.

This commit is contained in:
Eric Huss 2020-09-08 15:09:57 -07:00
parent a055c5a1bd
commit 45c1e0ae07
22 changed files with 3914 additions and 1567 deletions

View file

@ -4,6 +4,32 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_span::symbol::Symbol;
declare_lint! {
/// The `non_ascii_idents` lint detects non-ASCII identifiers.
///
/// ### Example
///
/// ```rust,compile_fail
/// # #![allow(unused)]
/// #![feature(non_ascii_idents)]
/// #![deny(non_ascii_idents)]
/// fn main() {
/// let föö = 1;
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Currently on stable Rust, identifiers must contain ASCII characters.
/// The [`non_ascii_idents`] nightly-only feature allows identifiers to
/// contain non-ASCII characters. This lint allows projects that wish to
/// retain the limit of only using ASCII characters to switch this lint to
/// "forbid" (for example to ease collaboration or for security reasons).
/// See [RFC 2457] for more details.
///
/// [`non_ascii_idents`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/non-ascii-idents.html
/// [RFC 2457]: https://github.com/rust-lang/rfcs/blob/master/text/2457-non-ascii-idents.md
pub NON_ASCII_IDENTS,
Allow,
"detects non-ASCII identifiers",
@ -11,6 +37,37 @@ declare_lint! {
}
declare_lint! {
/// The `uncommon_codepoints` lint detects uncommon Unicode codepoints in
/// identifiers.
///
/// ### Example
///
/// ```rust
/// # #![allow(unused)]
/// #![feature(non_ascii_idents)]
/// const µ: f64 = 0.000001;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// With the [`non_ascii_idents`] nightly-only feature enabled,
/// identifiers are allowed to use non-ASCII characters. This lint warns
/// about using characters which are not commonly used, and may cause
/// visual confusion.
///
/// This lint is triggered by identifiers that contain a codepoint that is
/// not part of the set of "Allowed" codepoints as described by [Unicode®
/// Technical Standard #39 Unicode Security Mechanisms Section 3.1 General
/// Security Profile for Identifiers][TR39Allowed].
///
/// Note that the set of uncommon codepoints may change over time. Beware
/// that if you "forbid" this lint that existing code may fail in the
/// future.
///
/// [`non_ascii_idents`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/non-ascii-idents.html
/// [TR39Allowed]: https://www.unicode.org/reports/tr39/#General_Security_Profile
pub UNCOMMON_CODEPOINTS,
Warn,
"detects uncommon Unicode codepoints in identifiers",
@ -18,6 +75,43 @@ declare_lint! {
}
declare_lint! {
/// The `confusable_idents` lint detects visually confusable pairs between
/// identifiers.
///
/// ### Example
///
/// ```rust
/// #![feature(non_ascii_idents)]
///
/// // Latin Capital Letter E With Caron
/// pub const Ě: i32 = 1;
/// // Latin Capital Letter E With Breve
/// pub const Ĕ: i32 = 2;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// With the [`non_ascii_idents`] nightly-only feature enabled,
/// identifiers are allowed to use non-ASCII characters. This lint warns
/// when different identifiers may appear visually similar, which can
/// cause confusion.
///
/// The confusable detection algorithm is based on [Unicode® Technical
/// Standard #39 Unicode Security Mechanisms Section 4 Confusable
/// Detection][TR39Confusable]. For every distinct identifier X execute
/// the function `skeleton(X)`. If there exist two distinct identifiers X
/// and Y in the same crate where `skeleton(X) = skeleton(Y)` report it.
/// The compiler uses the same mechanism to check if an identifier is too
/// similar to a keyword.
///
/// Note that the set of confusable characters may change over time.
/// Beware that if you "forbid" this lint that existing code may fail in
/// the future.
///
/// [`non_ascii_idents`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/non-ascii-idents.html
/// [TR39Confusable]: https://www.unicode.org/reports/tr39/#Confusable_Detection
pub CONFUSABLE_IDENTS,
Warn,
"detects visually confusable pairs between identifiers",
@ -25,6 +119,41 @@ declare_lint! {
}
declare_lint! {
/// The `mixed_script_confusables` lint detects visually confusable
/// characters in identifiers between different [scripts].
///
/// [scripts]: https://en.wikipedia.org/wiki/Script_(Unicode)
///
/// ### Example
///
/// ```rust
/// #![feature(non_ascii_idents)]
///
/// // The Japanese katakana character エ can be confused with the Han character 工.
/// const エ: &'static str = "アイウ";
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// With the [`non_ascii_idents`] nightly-only feature enabled,
/// identifiers are allowed to use non-ASCII characters. This lint warns
/// when characters between different scripts may appear visually similar,
/// which can cause confusion.
///
/// If the crate contains other identifiers in the same script that have
/// non-confusable characters, then this lint will *not* be issued. For
/// example, if the example given above has another identifier with
/// katakana characters (such as `let カタカナ = 123;`), then this indicates
/// that you are intentionally using katakana, and it will not warn about
/// it.
///
/// Note that the set of confusable characters may change over time.
/// Beware that if you "forbid" this lint that existing code may fail in
/// the future.
///
/// [`non_ascii_idents`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/non-ascii-idents.html
pub MIXED_SCRIPT_CONFUSABLES,
Warn,
"detects Unicode scripts whose mixed script confusables codepoints are solely used",