<commit_before>//! # Lints in the Rust compiler
//!
//! This currently only contains the definitions and implementations
//! of most of the lints that `rustc` supports directly, it does not
//! contain the infrastructure for defining/registering lints. That is
//! available in `rustc::lint` and `rustc_plugin` respectively.
//!
//! ## Note
//!
//! This API is completely unstable and subject to change.

#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
      html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
      html_root_url = "https://doc.rust-lang.org/nightly/")]

#![cfg_attr(test, feature(test))]
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(nll)]
#![feature(quote)]
#![feature(rustc_diagnostic_macros)]

#![recursion_limit="256"]

#[macro_use]
extern crate syntax;
#[macro_use]
extern crate rustc;
#[macro_use]
extern crate log;
extern crate rustc_target;
extern crate syntax_pos;
extern crate rustc_data_structures;

mod diagnostics;
mod nonstandard_style;
pub mod builtin;
mod types;
mod unused;

use rustc::lint;
use rustc::lint::{LateContext, LateLintPass, LintPass, LintArray};
use rustc::lint::builtin::{
    BARE_TRAIT_OBJECTS,
    ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
    ELIDED_LIFETIMES_IN_PATHS,
    EXPLICIT_OUTLIVES_REQUIREMENTS,
    INTRA_DOC_LINK_RESOLUTION_FAILURE,
    MISSING_DOC_CODE_EXAMPLES,
    PRIVATE_DOC_TESTS,
    parser::QUESTION_MARK_MACRO_SEP
};
use rustc::session;
use rustc::util;
use rustc::hir;

use syntax::ast;
use syntax::edition::Edition;
use syntax_pos::Span;

use session::Session;
use lint::LintId;
use lint::FutureIncompatibleInfo;

use nonstandard_style::*;
use builtin::*;
use types::*;
use unused::*;

/// Useful for other parts of the compiler.
pub use builtin::SoftLints;

/// Tell the `LintStore` about all the built-in lints (the ones
/// defined in this crate and the ones defined in
/// `rustc::lint::builtin`).
pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
    macro_rules! add_early_builtin {
        ($sess:ident, $($name:ident),*,) => (
            {$(
                store.register_early_pass($sess, false, box $name);
            )*}
        )
    }

    macro_rules! add_pre_expansion_builtin {
        ($sess:ident, $($name:ident),*,) => (
            {$(
                store.register_pre_expansion_pass($sess, box $name);
            )*}
        )
    }

    macro_rules! add_early_builtin_with_new {
        ($sess:ident, $($name:ident),*,) => (
            {$(
                store.register_early_pass($sess, false, box $name::new());
            )*}
        )
    }

    macro_rules! add_lint_group {
        ($sess:ident, $name:expr, $($lint:ident),*) => (
            store.register_group($sess, false, $name, None, vec![$(LintId::of($lint)),*]);
        )
    }

    add_pre_expansion_builtin!(sess,
        KeywordIdents,
    );

    add_early_builtin!(sess,
                       UnusedParens,
                       UnusedImportBraces,
                       AnonymousParameters,
                       UnusedDocComment,
                       BadRepr,
                       EllipsisInclusiveRangePatterns,
                       NonCamelCaseTypes,
                       );

    add_early_builtin_with_new!(sess,
                                DeprecatedAttr,
                                );

    late_lint_methods!(declare_combined_late_lint_pass, [BuiltinCombinedLateLintPass, [
        HardwiredLints: HardwiredLints,
        WhileTrue: WhileTrue,
        ImproperCTypes: ImproperCTypes,
        VariantSizeDifferences: VariantSizeDifferences,
        BoxPointers: BoxPointers,
        UnusedAttributes: UnusedAttributes,
        PathStatements: PathStatements,
        UnusedResults: UnusedResults,
        NonSnakeCase: NonSnakeCase,
        NonUpperCaseGlobals: NonUpperCaseGlobals,
        NonShorthandFieldPatterns: NonShorthandFieldPatterns,
        UnsafeCode: UnsafeCode,
        UnusedAllocation: UnusedAllocation,
        MissingCopyImplementations: MissingCopyImplementations,
        UnstableFeatures: UnstableFeatures,
        InvalidNoMangleItems: InvalidNoMangleItems,
        PluginAsLibrary: PluginAsLibrary,
        MutableTransmutes: MutableTransmutes,
        UnionsWithDropFields: UnionsWithDropFields,
        UnreachablePub: UnreachablePub,
        UnnameableTestItems: UnnameableTestItems::new(),
        TypeAliasBounds: TypeAliasBounds,
        UnusedBrokenConst: UnusedBrokenConst,
        TrivialConstraints: TrivialConstraints,
        TypeLimits: TypeLimits::new(),
        MissingDoc: MissingDoc::new(),
        MissingDebugImplementations: MissingDebugImplementations::new(),
        ExplicitOutlivesRequirements: ExplicitOutlivesRequirements,
    ]], ['tcx]);

    store.register_late_pass(sess, false, box BuiltinCombinedLateLintPass::new());

    add_lint_group!(sess,
                    "nonstandard_style",
                    NON_CAMEL_CASE_TYPES,
                    NON_SNAKE_CASE,
                    NON_UPPER_CASE_GLOBALS);

    add_lint_group!(sess,
                    "unused",
                    UNUSED_IMPORTS,
                    UNUSED_VARIABLES,<commit_msg>Run lint for unsafe on the ast<commit_after>//! # Lints in the Rust compiler
//!
//! This currently only contains the definitions and implementations
//! of most of the lints that `rustc` supports directly, it does not
//! contain the infrastructure for defining/registering lints. That is
//! available in `rustc::lint` and `rustc_plugin` respectively.
//!
//! ## Note
//!
//! This API is completely unstable and subject to change.

#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
      html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
      html_root_url = "https://doc.rust-lang.org/nightly/")]

#![cfg_attr(test, feature(test))]
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(nll)]
#![feature(quote)]
#![feature(rustc_diagnostic_macros)]

#![recursion_limit="256"]

#[macro_use]
extern crate syntax;
#[macro_use]
extern crate rustc;
#[macro_use]
extern crate log;
extern crate rustc_target;
extern crate syntax_pos;
extern crate rustc_data_structures;

mod diagnostics;
mod nonstandard_style;
pub mod builtin;
mod types;
mod unused;

use rustc::lint;
use rustc::lint::{LateContext, LateLintPass, LintPass, LintArray};
use rustc::lint::builtin::{
    BARE_TRAIT_OBJECTS,
    ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
    ELIDED_LIFETIMES_IN_PATHS,
    EXPLICIT_OUTLIVES_REQUIREMENTS,
    INTRA_DOC_LINK_RESOLUTION_FAILURE,
    MISSING_DOC_CODE_EXAMPLES,
    PRIVATE_DOC_TESTS,
    parser::QUESTION_MARK_MACRO_SEP
};
use rustc::session;
use rustc::util;
use rustc::hir;

use syntax::ast;
use syntax::edition::Edition;
use syntax_pos::Span;

use session::Session;
use lint::LintId;
use lint::FutureIncompatibleInfo;

use nonstandard_style::*;
use builtin::*;
use types::*;
use unused::*;

/// Useful for other parts of the compiler.
pub use builtin::SoftLints;

/// Tell the `LintStore` about all the built-in lints (the ones
/// defined in this crate and the ones defined in
/// `rustc::lint::builtin`).
pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
    macro_rules! add_early_builtin {
        ($sess:ident, $($name:ident),*,) => (
            {$(
                store.register_early_pass($sess, false, box $name);
            )*}
        )
    }

    macro_rules! add_pre_expansion_builtin {
        ($sess:ident, $($name:ident),*,) => (
            {$(
                store.register_pre_expansion_pass($sess, box $name);
            )*}
        )
    }

    macro_rules! add_early_builtin_with_new {
        ($sess:ident, $($name:ident),*,) => (
            {$(
                store.register_early_pass($sess, false, box $name::new());
            )*}
        )
    }

    macro_rules! add_lint_group {
        ($sess:ident, $name:expr, $($lint:ident),*) => (
            store.register_group($sess, false, $name, None, vec![$(LintId::of($lint)),*]);
        )
    }

    add_pre_expansion_builtin!(sess,
        KeywordIdents,
    );

    add_early_builtin!(sess,
                       UnusedParens,
                       UnusedImportBraces,
                       UnsafeCode,
                       AnonymousParameters,
                       UnusedDocComment,
                       BadRepr,
                       EllipsisInclusiveRangePatterns,
                       NonCamelCaseTypes,
                       );

    add_early_builtin_with_new!(sess,
                                DeprecatedAttr,
                                );

    late_lint_methods!(declare_combined_late_lint_pass, [BuiltinCombinedLateLintPass, [
        HardwiredLints: HardwiredLints,
        WhileTrue: WhileTrue,
        ImproperCTypes: ImproperCTypes,
        VariantSizeDifferences: VariantSizeDifferences,
        BoxPointers: BoxPointers,
        UnusedAttributes: UnusedAttributes,
        PathStatements: PathStatements,
        UnusedResults: UnusedResults,
        NonSnakeCase: NonSnakeCase,
        NonUpperCaseGlobals: NonUpperCaseGlobals,
        NonShorthandFieldPatterns: NonShorthandFieldPatterns,
        UnusedAllocation: UnusedAllocation,
        MissingCopyImplementations: MissingCopyImplementations,
        UnstableFeatures: UnstableFeatures,
        InvalidNoMangleItems: InvalidNoMangleItems,
        PluginAsLibrary: PluginAsLibrary,
        MutableTransmutes: MutableTransmutes,
        UnionsWithDropFields: UnionsWithDropFields,
        UnreachablePub: UnreachablePub,
        UnnameableTestItems: UnnameableTestItems::new(),
        TypeAliasBounds: TypeAliasBounds,
        UnusedBrokenConst: UnusedBrokenConst,
        TrivialConstraints: TrivialConstraints,
        TypeLimits: TypeLimits::new(),
        MissingDoc: MissingDoc::new(),
        MissingDebugImplementations: MissingDebugImplementations::new(),
        ExplicitOutlivesRequirements: ExplicitOutlivesRequirements,
    ]], ['tcx]);

    store.register_late_pass(sess, false, box BuiltinCombinedLateLintPass::new());

    add_lint_group!(sess,
                    "nonstandard_style",
                    NON_CAMEL_CASE_TYPES,
                    NON_SNAKE_CASE,
                    NON_UPPER_CASE_GLOBALS);

    add_lint_group!(sess,
                    "unused",
                    UNUSED_IMPORTS,
                    UNUSED_VARIABLES,
{'fraction_non_alphanumeric': 0.10828697487051601, 'fraction_numerical': 0.0019182812200268559, 'mean_word_length': 2.798542805100182, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6781474', 'n_tokens_mistral': 3391, 'n_tokens_neox': 3213, 'n_words': 590}