diff --git a/Cargo.lock b/Cargo.lock index 8fd0285a7e62a..b9a3e920e4b67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3205,6 +3205,7 @@ dependencies = [ "rustc_fs_util", "rustc_index", "rustc_macros", + "rustc_session", "rustc_target", "scoped-tls", "serialize", @@ -3518,6 +3519,7 @@ dependencies = [ "rustc_fs_util", "rustc_incremental", "rustc_index", + "rustc_session", "rustc_target", "serialize", "syntax", @@ -3634,6 +3636,7 @@ dependencies = [ "rustc", "rustc_data_structures", "rustc_fs_util", + "rustc_session", "serialize", "syntax", "syntax_pos", @@ -3697,6 +3700,7 @@ dependencies = [ "rustc_error_codes", "rustc_feature", "rustc_index", + "rustc_session", "rustc_target", "syntax", "syntax_pos", @@ -3884,6 +3888,22 @@ dependencies = [ "syntax_pos", ] +[[package]] +name = "rustc_session" +version = "0.0.0" +dependencies = [ + "log", + "num_cpus", + "rustc_data_structures", + "rustc_errors", + "rustc_feature", + "rustc_fs_util", + "rustc_index", + "rustc_target", + "serialize", + "syntax_pos", +] + [[package]] name = "rustc_target" version = "0.0.0" @@ -4463,6 +4483,7 @@ dependencies = [ "rustc_index", "rustc_lexer", "rustc_macros", + "rustc_session", "scoped-tls", "serialize", "smallvec 1.0.0", diff --git a/src/librustc/Cargo.toml b/src/librustc/Cargo.toml index fb30d6c519c90..f8ad6f8f30edb 100644 --- a/src/librustc/Cargo.toml +++ b/src/librustc/Cargo.toml @@ -39,3 +39,4 @@ rustc_fs_util = { path = "../librustc_fs_util" } smallvec = { version = "1.0", features = ["union", "may_dangle"] } measureme = "0.4" rustc_error_codes = { path = "../librustc_error_codes" } +rustc_session = { path = "../librustc_session" } diff --git a/src/librustc/dep_graph/mod.rs b/src/librustc/dep_graph/mod.rs index 43f3d7e89cd5c..a1321d50f28bb 100644 --- a/src/librustc/dep_graph/mod.rs +++ b/src/librustc/dep_graph/mod.rs @@ -5,7 +5,6 @@ mod prev; mod query; mod safe; mod serialized; -pub mod cgu_reuse_tracker; pub use self::dep_node::{DepNode, DepKind, DepConstructor, WorkProductId, RecoverKey, label_strs}; pub use self::graph::{DepGraph, WorkProduct, DepNodeIndex, DepNodeColor, TaskDeps, hash_result}; diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 481ae3b93291e..e708c5ab6e77d 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -64,7 +64,6 @@ #![recursion_limit="512"] #[macro_use] extern crate bitflags; -extern crate getopts; #[macro_use] extern crate scoped_tls; #[cfg(windows)] extern crate libc; @@ -74,10 +73,6 @@ extern crate libc; #[macro_use] extern crate syntax; #[macro_use] extern crate smallvec; -// Use the test crate here so we depend on getopts through it. This allow tools to link to both -// librustc_driver and libtest. -extern crate test as _; - #[cfg(test)] mod tests; @@ -113,7 +108,7 @@ pub mod middle { } pub mod mir; -pub mod session; +pub use rustc_session as session; pub mod traits; pub mod ty; diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index f8a592d22c19c..1aba73ec73d00 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -12,6 +12,8 @@ use syntax::ast; use syntax::edition::Edition; use syntax::source_map::Span; use syntax::symbol::Symbol; +use syntax::early_buffered_lints::{ILL_FORMED_ATTRIBUTE_INPUT, META_VARIABLE_MISUSE}; +use rustc_session::declare_lint; declare_lint! { pub EXCEEDING_BITSHIFTS, @@ -404,31 +406,6 @@ declare_lint! { }; } -/// Some lints that are buffered from `libsyntax`. See `syntax::early_buffered_lints`. -pub mod parser { - declare_lint! { - pub ILL_FORMED_ATTRIBUTE_INPUT, - Deny, - "ill-formed attribute inputs that were previously accepted and used in practice", - @future_incompatible = super::FutureIncompatibleInfo { - reference: "issue #57571 ", - edition: None, - }; - } - - declare_lint! { - pub META_VARIABLE_MISUSE, - Allow, - "possible meta-variable misuse at macro definition" - } - - declare_lint! { - pub INCOMPLETE_INCLUDE, - Deny, - "trailing content in included file" - } -} - declare_lint! { pub DEPRECATED_IN_FUTURE, Allow, @@ -520,8 +497,8 @@ declare_lint_pass! { PROC_MACRO_DERIVE_RESOLUTION_FALLBACK, MACRO_USE_EXTERN_CRATE, MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS, - parser::ILL_FORMED_ATTRIBUTE_INPUT, - parser::META_VARIABLE_MISUSE, + ILL_FORMED_ATTRIBUTE_INPUT, + META_VARIABLE_MISUSE, DEPRECATED_IN_FUTURE, AMBIGUOUS_ASSOCIATED_ITEMS, MUTABLE_BORROW_RESERVATION_CONFLICT, diff --git a/src/librustc/lint/internal.rs b/src/librustc/lint/internal.rs index 1c5f86f480147..10c0c63995ca2 100644 --- a/src/librustc/lint/internal.rs +++ b/src/librustc/lint/internal.rs @@ -9,6 +9,7 @@ use errors::Applicability; use rustc_data_structures::fx::FxHashMap; use syntax::ast::{Ident, Item, ItemKind}; use syntax::symbol::{sym, Symbol}; +use rustc_session::declare_tool_lint; declare_tool_lint! { pub rustc::DEFAULT_HASH_TYPES, diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs index 619ca724214c8..f29d1a3789aea 100644 --- a/src/librustc/lint/levels.rs +++ b/src/librustc/lint/levels.rs @@ -8,7 +8,7 @@ use crate::lint::{self, Lint, LintId, Level, LintSource}; use crate::session::Session; use crate::util::nodemap::FxHashMap; use errors::{Applicability, DiagnosticBuilder}; -use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher}; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use syntax::ast; use syntax::attr; use syntax::feature_gate; @@ -93,7 +93,7 @@ impl LintLevelSets { // If `level` is none then we actually assume the default level for this // lint. - let mut level = level.unwrap_or_else(|| lint.default_level(sess)); + let mut level = level.unwrap_or_else(|| lint.default_level(sess.edition())); // If we're about to issue a warning, check at the last minute for any // directives against the warnings "lint". If, for example, there's an @@ -566,19 +566,3 @@ impl<'a> HashStable> for LintLevelMap { }) } } - -impl HashStable for LintId { - #[inline] - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { - self.lint_name_raw().hash_stable(hcx, hasher); - } -} - -impl ToStableHashKey for LintId { - type KeyType = &'static str; - - #[inline] - fn to_stable_hash_key(&self, _: &HCX) -> &'static str { - self.lint_name_raw() - } -} diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index d84102ff3c5d8..a8d886866795e 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -27,19 +27,14 @@ use crate::hir::def_id::{CrateNum, LOCAL_CRATE}; use crate::hir::intravisit; use crate::hir; use crate::lint::builtin::BuiltinLintDiagnostics; -use crate::lint::builtin::parser::{ILL_FORMED_ATTRIBUTE_INPUT, META_VARIABLE_MISUSE}; -use crate::lint::builtin::parser::INCOMPLETE_INCLUDE; use crate::session::{Session, DiagnosticMessageId}; use crate::ty::TyCtxt; use crate::ty::query::Providers; use crate::util::nodemap::NodeMap; use errors::{DiagnosticBuilder, DiagnosticId}; -use std::{hash, ptr}; use syntax::ast; use syntax::source_map::{MultiSpan, ExpnKind, DesugaringKind}; -use syntax::early_buffered_lints::BufferedEarlyLintId; -use syntax::edition::Edition; -use syntax::symbol::{Symbol, sym}; +use syntax::symbol::Symbol; use syntax_pos::hygiene::MacroKind; use syntax_pos::Span; @@ -47,150 +42,7 @@ pub use crate::lint::context::{LateContext, EarlyContext, LintContext, LintStore check_crate, check_ast_crate, late_lint_mod, CheckLintNameResult, BufferedEarlyLint,}; -/// Specification of a single lint. -#[derive(Copy, Clone, Debug)] -pub struct Lint { - /// A string identifier for the lint. - /// - /// This identifies the lint in attributes and in command-line arguments. - /// In those contexts it is always lowercase, but this field is compared - /// in a way which is case-insensitive for ASCII characters. This allows - /// `declare_lint!()` invocations to follow the convention of upper-case - /// statics without repeating the name. - /// - /// The name is written with underscores, e.g., "unused_imports". - /// On the command line, underscores become dashes. - pub name: &'static str, - - /// Default level for the lint. - pub default_level: Level, - - /// Description of the lint or the issue it detects. - /// - /// e.g., "imports that are never used" - pub desc: &'static str, - - /// Starting at the given edition, default to the given lint level. If this is `None`, then use - /// `default_level`. - pub edition_lint_opts: Option<(Edition, Level)>, - - /// `true` if this lint is reported even inside expansions of external macros. - pub report_in_external_macro: bool, - - pub future_incompatible: Option, - - pub is_plugin: bool, -} - -/// Extra information for a future incompatibility lint. -#[derive(Copy, Clone, Debug)] -pub struct FutureIncompatibleInfo { - /// e.g., a URL for an issue/PR/RFC or error code - pub reference: &'static str, - /// If this is an edition fixing lint, the edition in which - /// this lint becomes obsolete - pub edition: Option, -} - -impl Lint { - pub const fn default_fields_for_macro() -> Self { - Lint { - name: "", - default_level: Level::Forbid, - desc: "", - edition_lint_opts: None, - is_plugin: false, - report_in_external_macro: false, - future_incompatible: None, - } - } - - /// Returns the `rust::lint::Lint` for a `syntax::early_buffered_lints::BufferedEarlyLintId`. - pub fn from_parser_lint_id(lint_id: BufferedEarlyLintId) -> &'static Self { - match lint_id { - BufferedEarlyLintId::IllFormedAttributeInput => ILL_FORMED_ATTRIBUTE_INPUT, - BufferedEarlyLintId::MetaVariableMisuse => META_VARIABLE_MISUSE, - BufferedEarlyLintId::IncompleteInclude => INCOMPLETE_INCLUDE, - } - } - - /// Gets the lint's name, with ASCII letters converted to lowercase. - pub fn name_lower(&self) -> String { - self.name.to_ascii_lowercase() - } - - pub fn default_level(&self, session: &Session) -> Level { - self.edition_lint_opts - .filter(|(e, _)| *e <= session.edition()) - .map(|(_, l)| l) - .unwrap_or(self.default_level) - } -} - -/// Declares a static item of type `&'static Lint`. -#[macro_export] -macro_rules! declare_lint { - ($vis: vis $NAME: ident, $Level: ident, $desc: expr) => ( - declare_lint!( - $vis $NAME, $Level, $desc, - ); - ); - ($vis: vis $NAME: ident, $Level: ident, $desc: expr, - $(@future_incompatible = $fi:expr;)? $($v:ident),*) => ( - $vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint { - name: stringify!($NAME), - default_level: $crate::lint::$Level, - desc: $desc, - edition_lint_opts: None, - is_plugin: false, - $($v: true,)* - $(future_incompatible: Some($fi),)* - ..$crate::lint::Lint::default_fields_for_macro() - }; - ); - ($vis: vis $NAME: ident, $Level: ident, $desc: expr, - $lint_edition: expr => $edition_level: ident - ) => ( - $vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint { - name: stringify!($NAME), - default_level: $crate::lint::$Level, - desc: $desc, - edition_lint_opts: Some(($lint_edition, $crate::lint::Level::$edition_level)), - report_in_external_macro: false, - is_plugin: false, - }; - ); -} - -#[macro_export] -macro_rules! declare_tool_lint { - ( - $(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level: ident, $desc: expr - ) => ( - declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, false} - ); - ( - $(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr, - report_in_external_macro: $rep:expr - ) => ( - declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, $rep} - ); - ( - $(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr, - $external:expr - ) => ( - $(#[$attr])* - $vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint { - name: &concat!(stringify!($tool), "::", stringify!($NAME)), - default_level: $crate::lint::$Level, - desc: $desc, - edition_lint_opts: None, - report_in_external_macro: $external, - future_incompatible: None, - is_plugin: true, - }; - ); -} +pub use rustc_session::lint::{Lint, LintId, Level, FutureIncompatibleInfo}; /// Declares a static `LintArray` and return it as an expression. #[macro_export] @@ -502,86 +354,6 @@ pub type EarlyLintPassObject = Box LateLintPass<'a, 'tcx> + sync::Send + sync::Sync + 'static>; -/// Identifies a lint known to the compiler. -#[derive(Clone, Copy, Debug)] -pub struct LintId { - // Identity is based on pointer equality of this field. - lint: &'static Lint, -} - -impl PartialEq for LintId { - fn eq(&self, other: &LintId) -> bool { - ptr::eq(self.lint, other.lint) - } -} - -impl Eq for LintId { } - -impl hash::Hash for LintId { - fn hash(&self, state: &mut H) { - let ptr = self.lint as *const Lint; - ptr.hash(state); - } -} - -impl LintId { - /// Gets the `LintId` for a `Lint`. - pub fn of(lint: &'static Lint) -> LintId { - LintId { - lint, - } - } - - pub fn lint_name_raw(&self) -> &'static str { - self.lint.name - } - - /// Gets the name of the lint. - pub fn to_string(&self) -> String { - self.lint.name_lower() - } -} - -/// Setting for how to handle a lint. -#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash, HashStable)] -pub enum Level { - Allow, Warn, Deny, Forbid, -} - -impl Level { - /// Converts a level to a lower-case string. - pub fn as_str(self) -> &'static str { - match self { - Allow => "allow", - Warn => "warn", - Deny => "deny", - Forbid => "forbid", - } - } - - /// Converts a lower-case string to a level. - pub fn from_str(x: &str) -> Option { - match x { - "allow" => Some(Allow), - "warn" => Some(Warn), - "deny" => Some(Deny), - "forbid" => Some(Forbid), - _ => None, - } - } - - /// Converts a symbol to a level. - pub fn from_symbol(x: Symbol) -> Option { - match x { - sym::allow => Some(Allow), - sym::warn => Some(Warn), - sym::deny => Some(Deny), - sym::forbid => Some(Forbid), - _ => None, - } - } -} - /// How a lint level was set. #[derive(Clone, Copy, PartialEq, Eq, HashStable)] pub enum LintSource { diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index 44c6f6b07f56c..324b01316fa4a 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -20,6 +20,7 @@ use rustc_target::spec::Target; use rustc_data_structures::sync::{self, MetadataRef}; use rustc_macros::HashStable; +pub use rustc_session::utils::NativeLibraryKind; pub use self::NativeLibraryKind::*; // lonely orphan structs and enums looking for a better home @@ -94,21 +95,6 @@ pub enum LinkagePreference { RequireStatic, } -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, - RustcEncodable, RustcDecodable, HashStable)] -pub enum NativeLibraryKind { - /// native static library (.a archive) - NativeStatic, - /// native static library, which doesn't get bundled into .rlibs - NativeStaticNobundle, - /// macOS-specific - NativeFramework, - /// Windows dynamic library without import library. - NativeRawDylib, - /// default way to specify a dynamic library - NativeUnknown, -} - #[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct NativeLibrary { pub kind: NativeLibraryKind, diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index 8581a5b220ac6..7515d30e46994 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -88,15 +88,7 @@ pub fn print_time_passes_entry(do_it: bool, what: &str, dur: Duration) { what); } -// Hack up our own formatting for the duration to make it easier for scripts -// to parse (always use the same number of decimal places and the same unit). -pub fn duration_to_secs_str(dur: Duration) -> String { - const NANOS_PER_SEC: f64 = 1_000_000_000.0; - let secs = dur.as_secs() as f64 + - dur.subsec_nanos() as f64 / NANOS_PER_SEC; - - format!("{:.3}", secs) -} +pub use rustc_session::utils::duration_to_secs_str; pub fn to_readable_str(mut val: usize) -> String { let mut groups = vec![]; diff --git a/src/librustc_codegen_llvm/back/lto.rs b/src/librustc_codegen_llvm/back/lto.rs index d0b065ccc848b..858dd59b26148 100644 --- a/src/librustc_codegen_llvm/back/lto.rs +++ b/src/librustc_codegen_llvm/back/lto.rs @@ -10,7 +10,7 @@ use rustc_codegen_ssa::back::lto::{SerializedModule, LtoModuleCodegen, ThinShare use rustc_codegen_ssa::traits::*; use errors::{FatalError, Handler}; use rustc::dep_graph::WorkProduct; -use rustc::dep_graph::cgu_reuse_tracker::CguReuse; +use rustc_session::cgu_reuse_tracker::CguReuse; use rustc::hir::def_id::LOCAL_CRATE; use rustc::middle::exported_symbols::SymbolExportLevel; use rustc::session::config::{self, Lto}; diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index acc221f0657c9..2ff5872370fd1 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -43,6 +43,7 @@ extern crate smallvec; extern crate syntax; extern crate syntax_pos; extern crate rustc_errors as errors; +extern crate rustc_session; use rustc_codegen_ssa::traits::*; use rustc_codegen_ssa::back::write::{CodegenContext, ModuleConfig, FatLTOInput}; diff --git a/src/librustc_codegen_ssa/Cargo.toml b/src/librustc_codegen_ssa/Cargo.toml index 478c3a9084c09..53d3c51b5f8c0 100644 --- a/src/librustc_codegen_ssa/Cargo.toml +++ b/src/librustc_codegen_ssa/Cargo.toml @@ -32,3 +32,4 @@ rustc_incremental = { path = "../librustc_incremental" } rustc_index = { path = "../librustc_index" } rustc_target = { path = "../librustc_target" } rustc_error_codes = { path = "../librustc_error_codes" } +rustc_session = { path = "../librustc_session" } diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs index 863b41ec15ec0..283295cadfcc5 100644 --- a/src/librustc_codegen_ssa/back/write.rs +++ b/src/librustc_codegen_ssa/back/write.rs @@ -10,7 +10,7 @@ use crate::traits::*; use rustc_incremental::{copy_cgu_workproducts_to_incr_comp_cache_dir, in_incr_comp_dir, in_incr_comp_dir_sess}; use rustc::dep_graph::{WorkProduct, WorkProductId, WorkProductFileKind}; -use rustc::dep_graph::cgu_reuse_tracker::CguReuseTracker; +use rustc_session::cgu_reuse_tracker::CguReuseTracker; use rustc::middle::cstore::EncodedMetadata; use rustc::session::config::{self, OutputFilenames, OutputType, Passes, Lto, Sanitizer, SwitchWithOptPath}; @@ -1752,7 +1752,7 @@ impl OngoingCodegen { } }; - sess.cgu_reuse_tracker.check_expected_reuse(sess); + sess.cgu_reuse_tracker.check_expected_reuse(sess.diagnostic()); sess.abort_if_errors(); diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs index e460a4a2e8c97..04e9159ff9116 100644 --- a/src/librustc_codegen_ssa/base.rs +++ b/src/librustc_codegen_ssa/base.rs @@ -25,8 +25,8 @@ use crate::mir::operand::OperandValue; use crate::mir::place::PlaceRef; use crate::traits::*; -use rustc::dep_graph::cgu_reuse_tracker::CguReuse; use rustc::hir; +use rustc_session::cgu_reuse_tracker::CguReuse; use rustc::hir::def_id::{DefId, LOCAL_CRATE}; use rustc::middle::cstore::EncodedMetadata; use rustc::middle::lang_items::StartFnLangItem; diff --git a/src/librustc_data_structures/jobserver.rs b/src/librustc_data_structures/jobserver.rs index b42ccb932b9dc..a811c88839d70 100644 --- a/src/librustc_data_structures/jobserver.rs +++ b/src/librustc_data_structures/jobserver.rs @@ -1,4 +1,4 @@ -use jobserver_crate::Client; +pub use jobserver_crate::Client; use lazy_static::lazy_static; lazy_static! { diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 93f4e73ccc311..05945504db237 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -828,7 +828,7 @@ Available lint options: fn sort_lints(sess: &Session, mut lints: Vec<&'static Lint>) -> Vec<&'static Lint> { // The sort doesn't case-fold but it's doubtful we care. - lints.sort_by_cached_key(|x: &&Lint| (x.default_level(sess), x.name)); + lints.sort_by_cached_key(|x: &&Lint| (x.default_level(sess.edition()), x.name)); lints } diff --git a/src/librustc_incremental/Cargo.toml b/src/librustc_incremental/Cargo.toml index 659c4c89fe33c..8dac7263f4d2c 100644 --- a/src/librustc_incremental/Cargo.toml +++ b/src/librustc_incremental/Cargo.toml @@ -19,3 +19,4 @@ rustc_serialize = { path = "../libserialize", package = "serialize" } syntax = { path = "../libsyntax" } syntax_pos = { path = "../libsyntax_pos" } rustc_fs_util = { path = "../librustc_fs_util" } +rustc_session = { path = "../librustc_session" } diff --git a/src/librustc_incremental/assert_module_sources.rs b/src/librustc_incremental/assert_module_sources.rs index 483b515f2ba4d..c2e3fa8f28d2f 100644 --- a/src/librustc_incremental/assert_module_sources.rs +++ b/src/librustc_incremental/assert_module_sources.rs @@ -22,7 +22,7 @@ //! was re-used. use rustc::hir::def_id::LOCAL_CRATE; -use rustc::dep_graph::cgu_reuse_tracker::*; +use rustc_session::cgu_reuse_tracker::*; use rustc::mir::mono::CodegenUnitNameBuilder; use rustc::ty::TyCtxt; use std::collections::BTreeSet; diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index f985a5b37558c..235184382c5cc 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -439,8 +439,7 @@ fn configure_and_expand_inner<'a>( sess.parse_sess.buffered_lints.with_lock(|buffered_lints| { info!("{} parse sess buffered_lints", buffered_lints.len()); for BufferedEarlyLint{id, span, msg, lint_id} in buffered_lints.drain(..) { - let lint = lint::Lint::from_parser_lint_id(lint_id); - resolver.lint_buffer().buffer_lint(lint, id, span, &msg); + resolver.lint_buffer().buffer_lint(lint_id, id, span, &msg); } }); diff --git a/src/librustc_lint/Cargo.toml b/src/librustc_lint/Cargo.toml index ed38243581b1a..e834b87896ddf 100644 --- a/src/librustc_lint/Cargo.toml +++ b/src/librustc_lint/Cargo.toml @@ -18,3 +18,4 @@ rustc_data_structures = { path = "../librustc_data_structures" } rustc_feature = { path = "../librustc_feature" } rustc_index = { path = "../librustc_index" } rustc_error_codes = { path = "../librustc_error_codes" } +rustc_session = { path = "../librustc_session" } diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index ab4063c421cd2..e60c025c3ef8b 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -21,6 +21,8 @@ #[macro_use] extern crate rustc; +#[macro_use] +extern crate rustc_session; mod array_into_iter; mod nonstandard_style; diff --git a/src/librustc_parse/validate_attr.rs b/src/librustc_parse/validate_attr.rs index 0fb348efece58..8601add3f6f96 100644 --- a/src/librustc_parse/validate_attr.rs +++ b/src/librustc_parse/validate_attr.rs @@ -4,7 +4,7 @@ use errors::{PResult, Applicability}; use rustc_feature::{AttributeTemplate, BUILTIN_ATTRIBUTE_MAP}; use syntax::ast::{self, Attribute, AttrKind, Ident, MacArgs, MetaItem, MetaItemKind}; use syntax::attr::mk_name_value_item_str; -use syntax::early_buffered_lints::BufferedEarlyLintId; +use syntax::early_buffered_lints::ILL_FORMED_ATTRIBUTE_INPUT; use syntax::sess::ParseSess; use syntax_pos::{Symbol, sym}; @@ -93,7 +93,7 @@ pub fn check_builtin_attribute( } if should_warn(name) { sess.buffer_lint( - BufferedEarlyLintId::IllFormedAttributeInput, + &ILL_FORMED_ATTRIBUTE_INPUT, meta.span, ast::CRATE_NODE_ID, &msg, diff --git a/src/librustc_session/Cargo.toml b/src/librustc_session/Cargo.toml new file mode 100644 index 0000000000000..dbbb4b92dea35 --- /dev/null +++ b/src/librustc_session/Cargo.toml @@ -0,0 +1,21 @@ +[package] +authors = ["The Rust Project Developers"] +name = "rustc_session" +version = "0.0.0" +edition = "2018" + +[lib] +name = "rustc_session" +path = "lib.rs" + +[dependencies] +log = "0.4" +rustc_errors = { path = "../librustc_errors" } +rustc_feature = { path = "../librustc_feature" } +rustc_target = { path = "../librustc_target" } +rustc_serialize = { path = "../libserialize", package = "serialize" } +rustc_data_structures = { path = "../librustc_data_structures" } +syntax_pos = { path = "../libsyntax_pos" } +rustc_index = { path = "../librustc_index" } +rustc_fs_util = { path = "../librustc_fs_util" } +num_cpus = "1.0" diff --git a/src/librustc/dep_graph/cgu_reuse_tracker.rs b/src/librustc_session/cgu_reuse_tracker.rs similarity index 95% rename from src/librustc/dep_graph/cgu_reuse_tracker.rs rename to src/librustc_session/cgu_reuse_tracker.rs index 13f6f95332973..193cf01dc74a9 100644 --- a/src/librustc/dep_graph/cgu_reuse_tracker.rs +++ b/src/librustc_session/cgu_reuse_tracker.rs @@ -2,10 +2,10 @@ //! compilation. This is used for incremental compilation tests and debug //! output. -use crate::session::Session; use rustc_data_structures::fx::FxHashMap; use std::sync::{Arc, Mutex}; use syntax_pos::Span; +use log::debug; #[derive(Copy, Clone, Debug, PartialEq, PartialOrd)] pub enum CguReuse { @@ -94,7 +94,7 @@ impl CguReuseTracker { } } - pub fn check_expected_reuse(&self, sess: &Session) { + pub fn check_expected_reuse(&self, diag: &rustc_errors::Handler) { if let Some(ref data) = self.data { let data = data.lock().unwrap(); @@ -120,14 +120,14 @@ impl CguReuseTracker { actual_reuse, at_least, expected_reuse); - sess.span_err(error_span.0, &msg); + diag.span_err(error_span.0, &msg); } } else { let msg = format!("CGU-reuse for `{}` (mangled: `{}`) was \ not recorded", cgu_user_name, cgu_name); - sess.span_fatal(error_span.0, &msg); + diag.span_fatal(error_span.0, &msg).raise(); } } } diff --git a/src/librustc/session/code_stats.rs b/src/librustc_session/code_stats.rs similarity index 100% rename from src/librustc/session/code_stats.rs rename to src/librustc_session/code_stats.rs diff --git a/src/librustc/session/config.rs b/src/librustc_session/config.rs similarity index 98% rename from src/librustc/session/config.rs rename to src/librustc_session/config.rs index 9a242d9d0769b..58113bb8cd6cb 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc_session/config.rs @@ -2,24 +2,24 @@ //! command-line options. use crate::lint; -use crate::middle::cstore; -use crate::session::{early_error, early_warn, Session}; -use crate::session::search_paths::SearchPath; +use crate::utils::NativeLibraryKind; +use crate::{early_error, early_warn, Session}; +use crate::search_paths::SearchPath; use rustc_data_structures::fx::FxHashSet; -use rustc_feature::UnstableFeatures; +use rustc_data_structures::impl_stable_hash_via_hash; use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, RelroLevel}; use rustc_target::spec::{Target, TargetTriple}; -use syntax; -use syntax::ast; -use syntax::source_map::{FileName, FilePathMapping}; -use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION}; -use syntax::symbol::{sym, Symbol}; +use syntax_pos::source_map::{FileName, FilePathMapping}; +use syntax_pos::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION}; +use syntax_pos::symbol::{sym, Symbol}; +use rustc_feature::UnstableFeatures; +use crate::parse::CrateConfig; -use errors::emitter::HumanReadableErrorType; -use errors::{ColorConfig, FatalError, Handler}; +use rustc_errors::emitter::HumanReadableErrorType; +use rustc_errors::{ColorConfig, FatalError, Handler}; use getopts; @@ -348,7 +348,7 @@ macro_rules! hash_option { ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, [TRACKED]) => ({ if $sub_hashes.insert(stringify!($opt_name), $opt_expr as &dyn dep_tracking::DepTrackingHash).is_some() { - bug!("duplicate key in CLI DepTrackingHash: {}", stringify!($opt_name)) + panic!("duplicate key in CLI DepTrackingHash: {}", stringify!($opt_name)) } }); } @@ -415,7 +415,7 @@ top_level_options!( describe_lints: bool [UNTRACKED], output_types: OutputTypes [TRACKED], search_paths: Vec [UNTRACKED], - libs: Vec<(String, Option, Option)> [TRACKED], + libs: Vec<(String, Option, Option)> [TRACKED], maybe_sysroot: Option [UNTRACKED], target_triple: TargetTriple [TRACKED], @@ -701,7 +701,7 @@ pub enum EntryFnType { impl_stable_hash_via_hash!(EntryFnType); -#[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash, Debug, HashStable)] +#[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash, Debug)] pub enum CrateType { Executable, Dylib, @@ -711,6 +711,8 @@ pub enum CrateType { ProcMacro, } +impl_stable_hash_via_hash!(CrateType); + #[derive(Clone, Hash)] pub enum Passes { Some(Vec), @@ -781,7 +783,7 @@ macro_rules! options { value, $outputname, key, type_desc)) } - (None, None) => bug!() + (None, None) => panic!() } } found = true; @@ -1535,7 +1537,7 @@ pub const fn default_lib_output() -> CrateType { CrateType::Rlib } -pub fn default_configuration(sess: &Session) -> ast::CrateConfig { +pub fn default_configuration(sess: &Session) -> CrateConfig { let end = &sess.target.target.target_endian; let arch = &sess.target.target.arch; let wordsz = &sess.target.target.target_pointer_width; @@ -1607,13 +1609,13 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig { /// Converts the crate `cfg!` configuration from `String` to `Symbol`. /// `rustc_interface::interface::Config` accepts this in the compiler configuration, /// but the symbol interner is not yet set up then, so we must convert it later. -pub fn to_crate_config(cfg: FxHashSet<(String, Option)>) -> ast::CrateConfig { +pub fn to_crate_config(cfg: FxHashSet<(String, Option)>) -> CrateConfig { cfg.into_iter() .map(|(a, b)| (Symbol::intern(&a), b.map(|b| Symbol::intern(&b)))) .collect() } -pub fn build_configuration(sess: &Session, mut user_cfg: ast::CrateConfig) -> ast::CrateConfig { +pub fn build_configuration(sess: &Session, mut user_cfg: CrateConfig) -> CrateConfig { // Combine the configuration requested by the session (command line) with // some default and generated configuration items. let default_cfg = default_configuration(sess); @@ -2379,7 +2381,7 @@ fn select_debuginfo( fn parse_libs( matches: &getopts::Matches, error_format: ErrorOutputType, -) -> Vec<(String, Option, Option)> { +) -> Vec<(String, Option, Option)> { matches .opt_strs("l") .into_iter() @@ -2390,10 +2392,12 @@ fn parse_libs( let kind = parts.next().unwrap(); let (name, kind) = match (parts.next(), kind) { (None, name) => (name, None), - (Some(name), "dylib") => (name, Some(cstore::NativeUnknown)), - (Some(name), "framework") => (name, Some(cstore::NativeFramework)), - (Some(name), "static") => (name, Some(cstore::NativeStatic)), - (Some(name), "static-nobundle") => (name, Some(cstore::NativeStaticNobundle)), + (Some(name), "dylib") => (name, Some(NativeLibraryKind::NativeUnknown)), + (Some(name), "framework") => (name, Some(NativeLibraryKind::NativeFramework)), + (Some(name), "static") => (name, Some(NativeLibraryKind::NativeStatic)), + (Some(name), "static-nobundle") => { + (name, Some(NativeLibraryKind::NativeStaticNobundle)) + } (_, s) => { early_error( error_format, @@ -2405,7 +2409,8 @@ fn parse_libs( ); } }; - if kind == Some(cstore::NativeStaticNobundle) && !nightly_options::is_nightly_build() { + if kind == Some(NativeLibraryKind::NativeStaticNobundle) && + !nightly_options::is_nightly_build() { early_error( error_format, &format!( @@ -2716,7 +2721,7 @@ pub mod nightly_options { use getopts; use rustc_feature::UnstableFeatures; use super::{ErrorOutputType, OptionStability, RustcOptGroup}; - use crate::session::early_error; + use crate::early_error; pub fn is_unstable_enabled(matches: &getopts::Matches) -> bool { is_nightly_build() @@ -2855,7 +2860,7 @@ impl PpMode { /// how the hash should be calculated when adding a new command-line argument. mod dep_tracking { use crate::lint; - use crate::middle::cstore; + use crate::utils::NativeLibraryKind; use std::collections::BTreeMap; use std::hash::Hash; use std::path::PathBuf; @@ -2863,9 +2868,9 @@ mod dep_tracking { use super::{CrateType, DebugInfo, ErrorOutputType, OptLevel, OutputTypes, Passes, Sanitizer, LtoCli, LinkerPluginLto, SwitchWithOptPath, SymbolManglingVersion}; - use rustc_feature::UnstableFeatures; use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel, TargetTriple}; - use syntax::edition::Edition; + use syntax_pos::edition::Edition; + use rustc_feature::UnstableFeatures; pub trait DepTrackingHash { fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType); @@ -2913,7 +2918,7 @@ mod dep_tracking { impl_dep_tracking_hash_via_hash!(Option); impl_dep_tracking_hash_via_hash!(Option); impl_dep_tracking_hash_via_hash!(Option); - impl_dep_tracking_hash_via_hash!(Option); + impl_dep_tracking_hash_via_hash!(Option); impl_dep_tracking_hash_via_hash!(CrateType); impl_dep_tracking_hash_via_hash!(MergeFunctions); impl_dep_tracking_hash_via_hash!(PanicStrategy); @@ -2924,7 +2929,7 @@ mod dep_tracking { impl_dep_tracking_hash_via_hash!(DebugInfo); impl_dep_tracking_hash_via_hash!(UnstableFeatures); impl_dep_tracking_hash_via_hash!(OutputTypes); - impl_dep_tracking_hash_via_hash!(cstore::NativeLibraryKind); + impl_dep_tracking_hash_via_hash!(NativeLibraryKind); impl_dep_tracking_hash_via_hash!(Sanitizer); impl_dep_tracking_hash_via_hash!(Option); impl_dep_tracking_hash_via_hash!(TargetTriple); @@ -2940,7 +2945,7 @@ mod dep_tracking { impl_dep_tracking_hash_for_sortable_vec_of!(( String, Option, - Option + Option )); impl_dep_tracking_hash_for_sortable_vec_of!((String, u64)); impl_dep_tracking_hash_for_sortable_vec_of!(Sanitizer); diff --git a/src/librustc/session/filesearch.rs b/src/librustc_session/filesearch.rs similarity index 96% rename from src/librustc/session/filesearch.rs rename to src/librustc_session/filesearch.rs index cf09d45ca38fc..a0bdc6a3254a1 100644 --- a/src/librustc/session/filesearch.rs +++ b/src/librustc_session/filesearch.rs @@ -7,8 +7,9 @@ use std::env; use std::fs; use std::path::{Path, PathBuf}; -use crate::session::search_paths::{SearchPath, PathKind}; +use crate::search_paths::{SearchPath, PathKind}; use rustc_fs_util::fix_windows_verbatim_for_gcc; +use log::debug; #[derive(Copy, Clone)] pub enum FileMatch { @@ -124,7 +125,7 @@ pub fn get_or_default_sysroot() -> PathBuf { // gcc chokes on verbatim paths which fs::canonicalize generates // so we try to avoid those kinds of paths. Ok(canon) => Some(fix_windows_verbatim_for_gcc(&canon)), - Err(e) => bug!("failed to get realpath: {}", e), + Err(e) => panic!("failed to get realpath: {}", e), } }) } @@ -133,7 +134,7 @@ pub fn get_or_default_sysroot() -> PathBuf { Ok(exe) => { match canonicalize(Some(exe)) { Some(mut p) => { p.pop(); p.pop(); p }, - None => bug!("can't determine value for sysroot") + None => panic!("can't determine value for sysroot") } } Err(ref e) => panic!(format!("failed to get current_exe: {}", e)) diff --git a/src/librustc_session/lib.rs b/src/librustc_session/lib.rs new file mode 100644 index 0000000000000..9d7c23100a0fe --- /dev/null +++ b/src/librustc_session/lib.rs @@ -0,0 +1,21 @@ +#![feature(test)] + +// Use the test crate here so we depend on getopts through it. This allow tools to link to both +// librustc_session and libtest. +extern crate test as _; +extern crate getopts; + +pub mod cgu_reuse_tracker; +pub mod utils; +#[macro_use] +pub mod lint; +pub mod node_id; +pub mod parse; + +mod code_stats; +pub mod config; +pub mod filesearch; +pub mod search_paths; + +mod session; +pub use session::*; diff --git a/src/librustc_session/lint.rs b/src/librustc_session/lint.rs new file mode 100644 index 0000000000000..faa6a7a4644e0 --- /dev/null +++ b/src/librustc_session/lint.rs @@ -0,0 +1,254 @@ +use syntax_pos::{MultiSpan, Symbol, sym}; +use syntax_pos::edition::Edition; +use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher}; +pub use self::Level::*; +use crate::node_id::NodeId; + +/// Setting for how to handle a lint. +#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)] +pub enum Level { + Allow, Warn, Deny, Forbid, +} + +rustc_data_structures::impl_stable_hash_via_hash!(Level); + +impl Level { + /// Converts a level to a lower-case string. + pub fn as_str(self) -> &'static str { + match self { + Level::Allow => "allow", + Level::Warn => "warn", + Level::Deny => "deny", + Level::Forbid => "forbid", + } + } + + /// Converts a lower-case string to a level. + pub fn from_str(x: &str) -> Option { + match x { + "allow" => Some(Level::Allow), + "warn" => Some(Level::Warn), + "deny" => Some(Level::Deny), + "forbid" => Some(Level::Forbid), + _ => None, + } + } + + /// Converts a symbol to a level. + pub fn from_symbol(x: Symbol) -> Option { + match x { + sym::allow => Some(Level::Allow), + sym::warn => Some(Level::Warn), + sym::deny => Some(Level::Deny), + sym::forbid => Some(Level::Forbid), + _ => None, + } + } +} + +/// Specification of a single lint. +#[derive(Copy, Clone, Debug)] +pub struct Lint { + /// A string identifier for the lint. + /// + /// This identifies the lint in attributes and in command-line arguments. + /// In those contexts it is always lowercase, but this field is compared + /// in a way which is case-insensitive for ASCII characters. This allows + /// `declare_lint!()` invocations to follow the convention of upper-case + /// statics without repeating the name. + /// + /// The name is written with underscores, e.g., "unused_imports". + /// On the command line, underscores become dashes. + pub name: &'static str, + + /// Default level for the lint. + pub default_level: Level, + + /// Description of the lint or the issue it detects. + /// + /// e.g., "imports that are never used" + pub desc: &'static str, + + /// Starting at the given edition, default to the given lint level. If this is `None`, then use + /// `default_level`. + pub edition_lint_opts: Option<(Edition, Level)>, + + /// `true` if this lint is reported even inside expansions of external macros. + pub report_in_external_macro: bool, + + pub future_incompatible: Option, + + pub is_plugin: bool, +} + +/// Extra information for a future incompatibility lint. +#[derive(Copy, Clone, Debug)] +pub struct FutureIncompatibleInfo { + /// e.g., a URL for an issue/PR/RFC or error code + pub reference: &'static str, + /// If this is an edition fixing lint, the edition in which + /// this lint becomes obsolete + pub edition: Option, +} + +impl Lint { + pub const fn default_fields_for_macro() -> Self { + Lint { + name: "", + default_level: Level::Forbid, + desc: "", + edition_lint_opts: None, + is_plugin: false, + report_in_external_macro: false, + future_incompatible: None, + } + } + + /// Gets the lint's name, with ASCII letters converted to lowercase. + pub fn name_lower(&self) -> String { + self.name.to_ascii_lowercase() + } + + pub fn default_level(&self, edition: Edition) -> Level { + self.edition_lint_opts + .filter(|(e, _)| *e <= edition) + .map(|(_, l)| l) + .unwrap_or(self.default_level) + } +} + +/// Identifies a lint known to the compiler. +#[derive(Clone, Copy, Debug)] +pub struct LintId { + // Identity is based on pointer equality of this field. + pub lint: &'static Lint, +} + +impl PartialEq for LintId { + fn eq(&self, other: &LintId) -> bool { + std::ptr::eq(self.lint, other.lint) + } +} + +impl Eq for LintId { } + +impl std::hash::Hash for LintId { + fn hash(&self, state: &mut H) { + let ptr = self.lint as *const Lint; + ptr.hash(state); + } +} + +impl LintId { + /// Gets the `LintId` for a `Lint`. + pub fn of(lint: &'static Lint) -> LintId { + LintId { + lint, + } + } + + pub fn lint_name_raw(&self) -> &'static str { + self.lint.name + } + + /// Gets the name of the lint. + pub fn to_string(&self) -> String { + self.lint.name_lower() + } +} + +impl HashStable for LintId { + #[inline] + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { + self.lint_name_raw().hash_stable(hcx, hasher); + } +} + +impl ToStableHashKey for LintId { + type KeyType = &'static str; + + #[inline] + fn to_stable_hash_key(&self, _: &HCX) -> &'static str { + self.lint_name_raw() + } +} + +/// Stores buffered lint info which can later be passed to `librustc`. +pub struct BufferedEarlyLint { + /// The span of code that we are linting on. + pub span: MultiSpan, + + /// The lint message. + pub msg: String, + + /// The `NodeId` of the AST node that generated the lint. + pub id: NodeId, + + /// A lint Id that can be passed to `rustc::lint::Lint::from_parser_lint_id`. + pub lint_id: &'static Lint, +} + +/// Declares a static item of type `&'static Lint`. +#[macro_export] +macro_rules! declare_lint { + ($vis: vis $NAME: ident, $Level: ident, $desc: expr) => ( + $crate::declare_lint!( + $vis $NAME, $Level, $desc, + ); + ); + ($vis: vis $NAME: ident, $Level: ident, $desc: expr, + $(@future_incompatible = $fi:expr;)? $($v:ident),*) => ( + $vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint { + name: stringify!($NAME), + default_level: $crate::lint::$Level, + desc: $desc, + edition_lint_opts: None, + is_plugin: false, + $($v: true,)* + $(future_incompatible: Some($fi),)* + ..$crate::lint::Lint::default_fields_for_macro() + }; + ); + ($vis: vis $NAME: ident, $Level: ident, $desc: expr, + $lint_edition: expr => $edition_level: ident + ) => ( + $vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint { + name: stringify!($NAME), + default_level: $crate::lint::$Level, + desc: $desc, + edition_lint_opts: Some(($lint_edition, $crate::lint::Level::$edition_level)), + report_in_external_macro: false, + is_plugin: false, + }; + ); +} + +#[macro_export] +macro_rules! declare_tool_lint { + ( + $(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level: ident, $desc: expr + ) => ( + $crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, false} + ); + ( + $(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr, + report_in_external_macro: $rep:expr + ) => ( + $crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, $rep} + ); + ( + $(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr, + $external:expr + ) => ( + $(#[$attr])* + $vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint { + name: &concat!(stringify!($tool), "::", stringify!($NAME)), + default_level: $crate::lint::$Level, + desc: $desc, + edition_lint_opts: None, + report_in_external_macro: $external, + future_incompatible: None, + is_plugin: true, + }; + ); +} diff --git a/src/librustc_session/node_id.rs b/src/librustc_session/node_id.rs new file mode 100644 index 0000000000000..7b14db20b95b1 --- /dev/null +++ b/src/librustc_session/node_id.rs @@ -0,0 +1,39 @@ +use std::fmt; +use rustc_index::vec::Idx; +use rustc_serialize::{Encoder, Decoder}; +use syntax_pos::ExpnId; + +rustc_index::newtype_index! { + pub struct NodeId { + ENCODABLE = custom + DEBUG_FORMAT = "NodeId({})" + } +} + +impl NodeId { + pub fn placeholder_from_expn_id(expn_id: ExpnId) -> Self { + NodeId::from_u32(expn_id.as_u32()) + } + + pub fn placeholder_to_expn_id(self) -> ExpnId { + ExpnId::from_u32(self.as_u32()) + } +} + +impl fmt::Display for NodeId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Display::fmt(&self.as_u32(), f) + } +} + +impl rustc_serialize::UseSpecializedEncodable for NodeId { + fn default_encode(&self, s: &mut S) -> Result<(), S::Error> { + s.emit_u32(self.as_u32()) + } +} + +impl rustc_serialize::UseSpecializedDecodable for NodeId { + fn default_decode(d: &mut D) -> Result { + d.read_u32().map(NodeId::from_u32) + } +} diff --git a/src/libsyntax/sess.rs b/src/librustc_session/parse.rs similarity index 93% rename from src/libsyntax/sess.rs rename to src/librustc_session/parse.rs index aa9217c1b69a8..09442f29b7a8a 100644 --- a/src/libsyntax/sess.rs +++ b/src/librustc_session/parse.rs @@ -1,10 +1,10 @@ //! Contains `ParseSess` which holds state living beyond what one `Parser` might. //! It also serves as an input to the parser itself. -use crate::ast::{CrateConfig, NodeId}; -use crate::early_buffered_lints::{BufferedEarlyLint, BufferedEarlyLintId}; +use crate::node_id::NodeId; +use crate::lint::BufferedEarlyLint; -use errors::{Applicability, emitter::SilentEmitter, Handler, ColorConfig, DiagnosticBuilder}; +use rustc_errors::{Applicability, emitter::SilentEmitter, Handler, ColorConfig, DiagnosticBuilder}; use rustc_data_structures::fx::{FxHashSet, FxHashMap}; use rustc_data_structures::sync::{Lrc, Lock, Once}; use rustc_feature::UnstableFeatures; @@ -16,6 +16,10 @@ use syntax_pos::source_map::{SourceMap, FilePathMapping}; use std::path::PathBuf; use std::str; +/// The set of keys (and, optionally, values) that define the compilation +/// environment of the crate, used to drive conditional compilation. +pub type CrateConfig = FxHashSet<(Symbol, Option)>; + /// Collected spans during parsing for places where a certain feature was /// used and should be feature gated accordingly in `check_crate`. #[derive(Default)] @@ -137,7 +141,7 @@ impl ParseSess { pub fn buffer_lint( &self, - lint_id: BufferedEarlyLintId, + lint_id: &'static crate::lint::Lint, span: impl Into, id: NodeId, msg: &str, diff --git a/src/librustc/session/search_paths.rs b/src/librustc_session/search_paths.rs similarity index 90% rename from src/librustc/session/search_paths.rs rename to src/librustc_session/search_paths.rs index 949dad751a101..b9f2ae7618b91 100644 --- a/src/librustc/session/search_paths.rs +++ b/src/librustc_session/search_paths.rs @@ -1,6 +1,6 @@ use std::path::{Path, PathBuf}; -use crate::session::{early_error, config}; -use crate::session::filesearch::make_target_lib_path; +use crate::{early_error, config}; +use crate::filesearch::make_target_lib_path; #[derive(Clone, Debug)] pub struct SearchPath { @@ -9,7 +9,7 @@ pub struct SearchPath { pub files: Vec, } -#[derive(PartialEq, Clone, Copy, Debug, HashStable)] +#[derive(PartialEq, Clone, Copy, Debug, Hash, Eq)] pub enum PathKind { Native, Crate, @@ -19,6 +19,8 @@ pub enum PathKind { All, } +rustc_data_structures::impl_stable_hash_via_hash!(PathKind); + impl PathKind { pub fn matches(&self, kind: PathKind) -> bool { match (self, kind) { diff --git a/src/librustc/session/mod.rs b/src/librustc_session/session.rs similarity index 96% rename from src/librustc/session/mod.rs rename to src/librustc_session/session.rs index f673ea3e771c5..9369c1771a35e 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc_session/session.rs @@ -1,36 +1,38 @@ -pub use self::code_stats::{DataTypeKind, SizeKind, FieldInfo, VariantInfo}; -use self::code_stats::CodeStats; +pub use crate::code_stats::{DataTypeKind, SizeKind, FieldInfo, VariantInfo}; +use crate::code_stats::CodeStats; -use crate::dep_graph::cgu_reuse_tracker::CguReuseTracker; +use crate::cgu_reuse_tracker::CguReuseTracker; use rustc_data_structures::fingerprint::Fingerprint; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use crate::lint; -use crate::session::config::{OutputType, PrintRequest, Sanitizer, SwitchWithOptPath}; -use crate::session::search_paths::{PathKind, SearchPath}; -use crate::util::nodemap::{FxHashMap, FxHashSet}; -use crate::util::common::{duration_to_secs_str, ErrorReported}; +use crate::filesearch; +use crate::config::{self, OutputType, PrintRequest, Sanitizer, SwitchWithOptPath}; +use crate::search_paths::{PathKind, SearchPath}; +use crate::utils::duration_to_secs_str; +use rustc_errors::ErrorReported; use rustc_data_structures::base_n; use rustc_data_structures::sync::{ self, Lrc, Lock, OneThread, Once, AtomicU64, AtomicUsize, Ordering, Ordering::SeqCst, }; - -use errors::{DiagnosticBuilder, DiagnosticId, Applicability}; -use errors::emitter::{Emitter, EmitterWriter}; -use errors::emitter::HumanReadableErrorType; -use errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter}; -use syntax::edition::Edition; -use errors::json::JsonEmitter; -use syntax::source_map; -use syntax::sess::ParseSess; +use rustc_data_structures::impl_stable_hash_via_hash; + +use rustc_errors::{DiagnosticBuilder, DiagnosticId, Applicability}; +use rustc_errors::emitter::{Emitter, EmitterWriter}; +use rustc_errors::emitter::HumanReadableErrorType; +use rustc_errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter}; +use syntax_pos::edition::Edition; +use rustc_errors::json::JsonEmitter; +use syntax_pos::source_map; +use crate::parse::ParseSess; use syntax_pos::{MultiSpan, Span}; use rustc_target::spec::{PanicStrategy, RelroLevel, Target, TargetTriple}; use rustc_data_structures::flock; -use rustc_data_structures::jobserver; +use rustc_data_structures::jobserver::{self, Client}; use rustc_data_structures::profiling::{SelfProfiler, SelfProfilerRef}; -use ::jobserver::Client; use std; use std::cell::{self, RefCell}; @@ -42,11 +44,6 @@ use std::path::PathBuf; use std::time::Duration; use std::sync::Arc; -mod code_stats; -pub mod config; -pub mod filesearch; -pub mod search_paths; - pub struct OptimizationFuel { /// If `-zfuel=crate=n` is specified, initially set to `n`, otherwise `0`. remaining: u64, @@ -335,7 +332,7 @@ impl Session { self.diagnostic().span_note_without_error(sp, msg) } - pub fn diagnostic(&self) -> &errors::Handler { + pub fn diagnostic(&self) -> &rustc_errors::Handler { &self.parse_sess.span_diagnostic } @@ -680,7 +677,7 @@ impl Session { if let IncrCompSession::NotInitialized = *incr_comp_session { } else { - bug!( + panic!( "Trying to initialize IncrCompSession `{:?}`", *incr_comp_session ) @@ -698,7 +695,7 @@ impl Session { if let IncrCompSession::Active { .. } = *incr_comp_session { } else { - bug!( + panic!( "trying to finalize `IncrCompSession` `{:?}`", *incr_comp_session ); @@ -719,7 +716,7 @@ impl Session { .. } => session_directory.clone(), IncrCompSession::InvalidBecauseOfErrors { .. } => return, - _ => bug!( + _ => panic!( "trying to invalidate `IncrCompSession` `{:?}`", *incr_comp_session ), @@ -736,7 +733,7 @@ impl Session { cell::Ref::map( incr_comp_session, |incr_comp_session| match *incr_comp_session { - IncrCompSession::NotInitialized => bug!( + IncrCompSession::NotInitialized => panic!( "trying to get session directory from `IncrCompSession`: {:?}", *incr_comp_session, ), @@ -916,7 +913,7 @@ impl Session { pub fn build_session( sopts: config::Options, local_crate_source_file: Option, - registry: errors::registry::Registry, + registry: rustc_errors::registry::Registry, ) -> Session { let file_path_mapping = sopts.file_path_mapping(); @@ -932,7 +929,7 @@ pub fn build_session( fn default_emitter( sopts: &config::Options, - registry: errors::registry::Registry, + registry: rustc_errors::registry::Registry, source_map: &Lrc, emitter_dest: Option>, ) -> Box { @@ -1001,7 +998,7 @@ pub enum DiagnosticOutput { pub fn build_session_with_source_map( sopts: config::Options, local_crate_source_file: Option, - registry: errors::registry::Registry, + registry: rustc_errors::registry::Registry, source_map: Lrc, diagnostics_output: DiagnosticOutput, lint_caps: FxHashMap, @@ -1032,9 +1029,9 @@ pub fn build_session_with_source_map( }; let emitter = default_emitter(&sopts, registry, &source_map, write_dest); - let diagnostic_handler = errors::Handler::with_emitter_and_flags( + let diagnostic_handler = rustc_errors::Handler::with_emitter_and_flags( emitter, - errors::HandlerFlags { + rustc_errors::HandlerFlags { can_emit_warnings, treat_err_as_bug, report_delayed_bugs, @@ -1056,7 +1053,7 @@ pub fn build_session_with_source_map( fn build_session_( sopts: config::Options, local_crate_source_file: Option, - span_diagnostic: errors::Handler, + span_diagnostic: rustc_errors::Handler, source_map: Lrc, driver_lint_caps: FxHashMap, ) -> Session { @@ -1281,9 +1278,9 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! { config::ErrorOutputType::Json { pretty, json_rendered } => Box::new(JsonEmitter::basic(pretty, json_rendered, false)), }; - let handler = errors::Handler::with_emitter(true, None, emitter); + let handler = rustc_errors::Handler::with_emitter(true, None, emitter); handler.struct_fatal(msg).emit(); - errors::FatalError.raise(); + rustc_errors::FatalError.raise(); } pub fn early_warn(output: config::ErrorOutputType, msg: &str) { @@ -1295,7 +1292,7 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) { config::ErrorOutputType::Json { pretty, json_rendered } => Box::new(JsonEmitter::basic(pretty, json_rendered, false)), }; - let handler = errors::Handler::with_emitter(true, None, emitter); + let handler = rustc_errors::Handler::with_emitter(true, None, emitter); handler.struct_warn(msg).emit(); } diff --git a/src/librustc_session/utils.rs b/src/librustc_session/utils.rs new file mode 100644 index 0000000000000..ad593398a52ba --- /dev/null +++ b/src/librustc_session/utils.rs @@ -0,0 +1,25 @@ +// Hack up our own formatting for the duration to make it easier for scripts +// to parse (always use the same number of decimal places and the same unit). +pub fn duration_to_secs_str(dur: std::time::Duration) -> String { + const NANOS_PER_SEC: f64 = 1_000_000_000.0; + let secs = dur.as_secs() as f64 + + dur.subsec_nanos() as f64 / NANOS_PER_SEC; + + format!("{:.3}", secs) +} + +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +pub enum NativeLibraryKind { + /// native static library (.a archive) + NativeStatic, + /// native static library, which doesn't get bundled into .rlibs + NativeStaticNobundle, + /// macOS-specific + NativeFramework, + /// Windows dynamic library without import library. + NativeRawDylib, + /// default way to specify a dynamic library + NativeUnknown, +} + +rustc_data_structures::impl_stable_hash_via_hash!(NativeLibraryKind); diff --git a/src/libsyntax/Cargo.toml b/src/libsyntax/Cargo.toml index 085c1760c8027..8a00bcbfe17c7 100644 --- a/src/libsyntax/Cargo.toml +++ b/src/libsyntax/Cargo.toml @@ -24,3 +24,4 @@ rustc_lexer = { path = "../librustc_lexer" } rustc_macros = { path = "../librustc_macros" } smallvec = { version = "1.0", features = ["union", "may_dangle"] } rustc_error_codes = { path = "../librustc_error_codes" } +rustc_session = { path = "../librustc_session" } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 8018e005b12d7..75ddf10514d97 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -30,9 +30,8 @@ use crate::token::{self, DelimToken}; use crate::tokenstream::{TokenStream, TokenTree, DelimSpan}; use syntax_pos::symbol::{kw, sym, Symbol}; -use syntax_pos::{Span, DUMMY_SP, ExpnId}; +use syntax_pos::{Span, DUMMY_SP}; -use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::Lrc; use rustc_data_structures::thin_vec::ThinVec; @@ -268,46 +267,7 @@ impl ParenthesizedArgs { } } -// hack to ensure that we don't try to access the private parts of `NodeId` in this module -mod node_id_inner { - use rustc_index::vec::Idx; - rustc_index::newtype_index! { - pub struct NodeId { - ENCODABLE = custom - DEBUG_FORMAT = "NodeId({})" - } - } -} - -pub use node_id_inner::NodeId; - -impl NodeId { - pub fn placeholder_from_expn_id(expn_id: ExpnId) -> Self { - NodeId::from_u32(expn_id.as_u32()) - } - - pub fn placeholder_to_expn_id(self) -> ExpnId { - ExpnId::from_u32(self.as_u32()) - } -} - -impl fmt::Display for NodeId { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(&self.as_u32(), f) - } -} - -impl rustc_serialize::UseSpecializedEncodable for NodeId { - fn default_encode(&self, s: &mut S) -> Result<(), S::Error> { - s.emit_u32(self.as_u32()) - } -} - -impl rustc_serialize::UseSpecializedDecodable for NodeId { - fn default_decode(d: &mut D) -> Result { - d.read_u32().map(NodeId::from_u32) - } -} +pub use rustc_session::node_id::NodeId; /// `NodeId` used to represent the root of the crate. pub const CRATE_NODE_ID: NodeId = NodeId::from_u32_const(0); @@ -470,9 +430,7 @@ pub struct WhereEqPredicate { pub rhs_ty: P, } -/// The set of `MetaItem`s that define the compilation environment of the crate, -/// used to drive conditional compilation. -pub type CrateConfig = FxHashSet<(Name, Option)>; +pub use rustc_session::parse::CrateConfig; #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct Crate { diff --git a/src/libsyntax/early_buffered_lints.rs b/src/libsyntax/early_buffered_lints.rs index 5cc953b906628..2c32894a23b06 100644 --- a/src/libsyntax/early_buffered_lints.rs +++ b/src/libsyntax/early_buffered_lints.rs @@ -3,28 +3,28 @@ //! Since we cannot have a dependency on `librustc`, we implement some types here that are somewhat //! redundant. Later, these types can be converted to types for use by the rest of the compiler. -use crate::ast::NodeId; -use syntax_pos::MultiSpan; +use rustc_session::lint::FutureIncompatibleInfo; +use rustc_session::declare_lint; +pub use rustc_session::lint::BufferedEarlyLint; -/// Since we cannot import `LintId`s from `rustc::lint`, we define some Ids here which can later be -/// passed to `rustc::lint::Lint::from_parser_lint_id` to get a `rustc::lint::Lint`. -pub enum BufferedEarlyLintId { - IllFormedAttributeInput, - MetaVariableMisuse, - IncompleteInclude, +declare_lint! { + pub ILL_FORMED_ATTRIBUTE_INPUT, + Deny, + "ill-formed attribute inputs that were previously accepted and used in practice", + @future_incompatible = FutureIncompatibleInfo { + reference: "issue #57571 ", + edition: None, + }; } -/// Stores buffered lint info which can later be passed to `librustc`. -pub struct BufferedEarlyLint { - /// The span of code that we are linting on. - pub span: MultiSpan, - - /// The lint message. - pub msg: String, - - /// The `NodeId` of the AST node that generated the lint. - pub id: NodeId, +declare_lint! { + pub META_VARIABLE_MISUSE, + Allow, + "possible meta-variable misuse at macro definition" +} - /// A lint Id that can be passed to `rustc::lint::Lint::from_parser_lint_id`. - pub lint_id: BufferedEarlyLintId, +declare_lint! { + pub INCOMPLETE_INCLUDE, + Deny, + "trailing content in included file" } diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 3dcdd4db6377a..a94742634cf17 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -102,7 +102,7 @@ pub mod ptr; pub mod show_span; pub use syntax_pos::edition; pub use syntax_pos::symbol; -pub mod sess; +pub use rustc_session::parse as sess; pub mod token; pub mod tokenstream; pub mod visit; diff --git a/src/libsyntax_expand/base.rs b/src/libsyntax_expand/base.rs index 50b69f1587848..a4449ca5b1d22 100644 --- a/src/libsyntax_expand/base.rs +++ b/src/libsyntax_expand/base.rs @@ -924,7 +924,6 @@ impl<'a> ExtCtxt<'a> { } pub fn source_map(&self) -> &'a SourceMap { self.parse_sess.source_map() } pub fn parse_sess(&self) -> &'a ParseSess { self.parse_sess } - pub fn cfg(&self) -> &ast::CrateConfig { &self.parse_sess.config } pub fn call_site(&self) -> Span { self.current_expansion.id.expn_data().call_site } diff --git a/src/libsyntax_expand/mbe/macro_check.rs b/src/libsyntax_expand/mbe/macro_check.rs index 837e04afd3401..dfc8d699dbe8d 100644 --- a/src/libsyntax_expand/mbe/macro_check.rs +++ b/src/libsyntax_expand/mbe/macro_check.rs @@ -107,7 +107,7 @@ use crate::mbe::{KleeneToken, TokenTree}; use syntax::ast::NodeId; -use syntax::early_buffered_lints::BufferedEarlyLintId; +use syntax::early_buffered_lints::META_VARIABLE_MISUSE; use syntax::token::{DelimToken, Token, TokenKind}; use syntax::sess::ParseSess; use syntax::symbol::{kw, sym}; @@ -623,5 +623,5 @@ fn ops_is_prefix( } fn buffer_lint(sess: &ParseSess, span: MultiSpan, node_id: NodeId, message: &str) { - sess.buffer_lint(BufferedEarlyLintId::MetaVariableMisuse, span, node_id, message); + sess.buffer_lint(&META_VARIABLE_MISUSE, span, node_id, message); } diff --git a/src/libsyntax_ext/source_util.rs b/src/libsyntax_ext/source_util.rs index 3d27af2f210a5..4aab68d7c0e8d 100644 --- a/src/libsyntax_ext/source_util.rs +++ b/src/libsyntax_ext/source_util.rs @@ -5,7 +5,7 @@ use syntax::ptr::P; use syntax::symbol::Symbol; use syntax::token; use syntax::tokenstream::TokenStream; -use syntax::early_buffered_lints::BufferedEarlyLintId; +use syntax::early_buffered_lints::INCOMPLETE_INCLUDE; use syntax_expand::panictry; use syntax_expand::base::{self, *}; @@ -101,7 +101,7 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt<'_>, sp: Span, tts: TokenStream) let r = panictry!(self.p.parse_expr()); if self.p.token != token::Eof { self.p.sess.buffer_lint( - BufferedEarlyLintId::IncompleteInclude, + &INCOMPLETE_INCLUDE, self.p.token.span, ast::CRATE_NODE_ID, "include macro expected single expression in source", diff --git a/src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs b/src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs index 68ea10fe735ad..e9ef58f29a8f5 100644 --- a/src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs +++ b/src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs @@ -1,8 +1,8 @@ #![feature(box_syntax, plugin, plugin_registrar, rustc_private)] #![crate_type = "dylib"] -#[macro_use] -extern crate rustc; +#[macro_use] extern crate rustc; +#[macro_use] extern crate rustc_session; extern crate rustc_driver; extern crate syntax; diff --git a/src/test/ui-fulldeps/auxiliary/lint-for-crate-rpass.rs b/src/test/ui-fulldeps/auxiliary/lint-for-crate-rpass.rs index 6874c921c1cc1..118ba1711191b 100644 --- a/src/test/ui-fulldeps/auxiliary/lint-for-crate-rpass.rs +++ b/src/test/ui-fulldeps/auxiliary/lint-for-crate-rpass.rs @@ -2,8 +2,8 @@ #![feature(plugin_registrar, rustc_private)] #![feature(box_syntax)] - #[macro_use] extern crate rustc; +#[macro_use] extern crate rustc_session; extern crate rustc_driver; extern crate syntax; diff --git a/src/test/ui-fulldeps/auxiliary/lint-for-crate.rs b/src/test/ui-fulldeps/auxiliary/lint-for-crate.rs index 1cd3e7b28dba7..49ca43d471ba9 100644 --- a/src/test/ui-fulldeps/auxiliary/lint-for-crate.rs +++ b/src/test/ui-fulldeps/auxiliary/lint-for-crate.rs @@ -4,6 +4,7 @@ #![feature(box_syntax)] #[macro_use] extern crate rustc; +#[macro_use] extern crate rustc_session; extern crate rustc_driver; extern crate syntax; diff --git a/src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs b/src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs index cb793b4349885..839c65a610755 100644 --- a/src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs +++ b/src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs @@ -4,8 +4,8 @@ #![feature(box_syntax, rustc_private)] // Load rustc as a plugin to get macros. -#[macro_use] -extern crate rustc; +#[macro_use] extern crate rustc; +#[macro_use] extern crate rustc_session; extern crate rustc_driver; use rustc::hir; diff --git a/src/test/ui-fulldeps/auxiliary/lint-plugin-test.rs b/src/test/ui-fulldeps/auxiliary/lint-plugin-test.rs index 40c37eb570e2d..bb96dba21fc2e 100644 --- a/src/test/ui-fulldeps/auxiliary/lint-plugin-test.rs +++ b/src/test/ui-fulldeps/auxiliary/lint-plugin-test.rs @@ -6,8 +6,8 @@ extern crate syntax; // Load rustc as a plugin to get macros -#[macro_use] -extern crate rustc; +#[macro_use] extern crate rustc; +#[macro_use] extern crate rustc_session; extern crate rustc_driver; use rustc::lint::{EarlyContext, LintContext, LintPass, EarlyLintPass, LintArray}; diff --git a/src/test/ui-fulldeps/auxiliary/lint-tool-test.rs b/src/test/ui-fulldeps/auxiliary/lint-tool-test.rs index 67135d595f448..1704909813797 100644 --- a/src/test/ui-fulldeps/auxiliary/lint-tool-test.rs +++ b/src/test/ui-fulldeps/auxiliary/lint-tool-test.rs @@ -4,8 +4,8 @@ extern crate syntax; // Load rustc as a plugin to get macros -#[macro_use] -extern crate rustc; +#[macro_use] extern crate rustc; +#[macro_use] extern crate rustc_session; extern crate rustc_driver; use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass, LintId}; diff --git a/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.rs b/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.rs index 0bfb32c6dc43b..7ce2a1dd9a62d 100644 --- a/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.rs +++ b/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.rs @@ -4,9 +4,11 @@ #![deny(rustc::lint_pass_impl_without_macro)] extern crate rustc; +extern crate rustc_session; use rustc::lint::{LintArray, LintPass}; -use rustc::{declare_lint, declare_lint_pass, impl_lint_pass}; +use rustc::{declare_lint_pass, impl_lint_pass}; +use rustc_session::declare_lint; declare_lint! { pub TEST_LINT, diff --git a/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr b/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr index 0dbdf4f5aa9e2..ad8670c6c83c8 100644 --- a/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr +++ b/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr @@ -1,5 +1,5 @@ error: implementing `LintPass` by hand - --> $DIR/lint_pass_impl_without_macro.rs:19:6 + --> $DIR/lint_pass_impl_without_macro.rs:21:6 | LL | impl LintPass for Foo { | ^^^^^^^^ @@ -12,7 +12,7 @@ LL | #![deny(rustc::lint_pass_impl_without_macro)] = help: try using `declare_lint_pass!` or `impl_lint_pass!` instead error: implementing `LintPass` by hand - --> $DIR/lint_pass_impl_without_macro.rs:29:14 + --> $DIR/lint_pass_impl_without_macro.rs:31:14 | LL | impl LintPass for Custom { | ^^^^^^^^