Rollup merge of #66878 - Mark-Simulacrum:sess-decouple, r=Centril
Move Sessions into (new) librustc_session This PR moves `ParseSess` and `Session` from their current locations into a new crate, `librustc_session`. There are several intents behind this change. librustc is a very large crate, and we want to split it up over time -- this movement removes the sizeable session module from it. It also helps allow for future movement of things not coupled to TyCtxt but coupled to Session out of the crate. This movement allows allows for a future follow-up PR which unifies Session and ParseSess, allowing for a single source of truth for APIs interested in global options throughout the compiler; the ParseSess is already created directly as a member of Session in the current compiler (i.e., we do not first construct a ParseSess and then move it into Session later in the compilation). This PR intentionally avoids changing numerous imports throughout the tree to new locations of the moved types; this is needless noise and can be done as needed. In the process of moving the sessions back, the lint system received an update as well -- notably, early buffered lints are no longer ad-hoc declared as enum pairs and later associated with proper lint declarations. They are still separately handled (buffered), it is a little unclear whether this is truly necessary, but regardless is left for future PRs. Many of the types moved back are sort of ad-hoc placed into the same crate (librustc_session) instead of creating other crates; it's unclear whether this is actually a good thing, but it seemed better than creating numerous tiny crates which served no purpose on their own.
This commit is contained in:
commit
b6602d2dd1
21
Cargo.lock
21
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",
|
||||
|
@ -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" }
|
||||
|
@ -5,7 +5,6 @@
|
||||
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};
|
||||
|
@ -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 @@
|
||||
#[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;
|
||||
|
||||
|
@ -12,6 +12,8 @@
|
||||
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 @@
|
||||
};
|
||||
}
|
||||
|
||||
/// 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 <https://github.com/rust-lang/rust/issues/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 @@ pub mod parser {
|
||||
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,
|
||||
|
@ -9,6 +9,7 @@
|
||||
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,
|
||||
|
@ -8,7 +8,7 @@
|
||||
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 @@ fn get_lint_level(&self,
|
||||
|
||||
// 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 @@ fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHas
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<HCX> HashStable<HCX> for LintId {
|
||||
#[inline]
|
||||
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {
|
||||
self.lint_name_raw().hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
|
||||
impl<HCX> ToStableHashKey<HCX> for LintId {
|
||||
type KeyType = &'static str;
|
||||
|
||||
#[inline]
|
||||
fn to_stable_hash_key(&self, _: &HCX) -> &'static str {
|
||||
self.lint_name_raw()
|
||||
}
|
||||
}
|
||||
|
@ -27,19 +27,14 @@
|
||||
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 @@
|
||||
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<FutureIncompatibleInfo>,
|
||||
|
||||
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<Edition>,
|
||||
}
|
||||
|
||||
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 @@ fn name(&self) -> &'static str {
|
||||
pub type LateLintPassObject = Box<dyn for<'a, 'tcx> 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<H: hash::Hasher>(&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<Level> {
|
||||
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<Level> {
|
||||
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 {
|
||||
|
@ -20,6 +20,7 @@
|
||||
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,
|
||||
|
@ -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![];
|
||||
|
@ -10,7 +10,7 @@
|
||||
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};
|
||||
|
@ -43,6 +43,7 @@
|
||||
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};
|
||||
|
@ -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" }
|
||||
|
@ -10,7 +10,7 @@
|
||||
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 @@ pub fn join(
|
||||
}
|
||||
};
|
||||
|
||||
sess.cgu_reuse_tracker.check_expected_reuse(sess);
|
||||
sess.cgu_reuse_tracker.check_expected_reuse(sess.diagnostic());
|
||||
|
||||
sess.abort_if_errors();
|
||||
|
||||
|
@ -25,8 +25,8 @@
|
||||
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;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use jobserver_crate::Client;
|
||||
pub use jobserver_crate::Client;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
lazy_static! {
|
||||
|
@ -828,7 +828,7 @@ fn describe_lints(sess: &Session, lint_store: &lint::LintStore, loaded_plugins:
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -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" }
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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" }
|
||||
|
@ -21,6 +21,8 @@
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc;
|
||||
#[macro_use]
|
||||
extern crate rustc_session;
|
||||
|
||||
mod array_into_iter;
|
||||
mod nonstandard_style;
|
||||
|
@ -4,7 +4,7 @@
|
||||
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,
|
||||
|
21
src/librustc_session/Cargo.toml
Normal file
21
src/librustc_session/Cargo.toml
Normal file
@ -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"
|
@ -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 @@ pub fn set_expectation(&self,
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ pub fn check_expected_reuse(&self, sess: &Session) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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 @@ pub struct Options {
|
||||
describe_lints: bool [UNTRACKED],
|
||||
output_types: OutputTypes [TRACKED],
|
||||
search_paths: Vec<SearchPath> [UNTRACKED],
|
||||
libs: Vec<(String, Option<String>, Option<cstore::NativeLibraryKind>)> [TRACKED],
|
||||
libs: Vec<(String, Option<String>, Option<NativeLibraryKind>)> [TRACKED],
|
||||
maybe_sysroot: Option<PathBuf> [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<String>),
|
||||
@ -781,7 +783,7 @@ pub fn $buildfn(matches: &getopts::Matches, error_format: ErrorOutputType) -> $s
|
||||
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<String>)>) -> ast::CrateConfig {
|
||||
pub fn to_crate_config(cfg: FxHashSet<(String, Option<String>)>) -> 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<String>, Option<cstore::NativeLibraryKind>)> {
|
||||
) -> Vec<(String, Option<String>, Option<NativeLibraryKind>)> {
|
||||
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 @@ pub fn needs_analysis(&self) -> bool {
|
||||
/// 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 @@ fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) {
|
||||
impl_dep_tracking_hash_via_hash!(Option<RelroLevel>);
|
||||
impl_dep_tracking_hash_via_hash!(Option<lint::Level>);
|
||||
impl_dep_tracking_hash_via_hash!(Option<PathBuf>);
|
||||
impl_dep_tracking_hash_via_hash!(Option<cstore::NativeLibraryKind>);
|
||||
impl_dep_tracking_hash_via_hash!(Option<NativeLibraryKind>);
|
||||
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 @@ fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) {
|
||||
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<Sanitizer>);
|
||||
impl_dep_tracking_hash_via_hash!(TargetTriple);
|
||||
@ -2940,7 +2945,7 @@ fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) {
|
||||
impl_dep_tracking_hash_for_sortable_vec_of!((
|
||||
String,
|
||||
Option<String>,
|
||||
Option<cstore::NativeLibraryKind>
|
||||
Option<NativeLibraryKind>
|
||||
));
|
||||
impl_dep_tracking_hash_for_sortable_vec_of!((String, u64));
|
||||
impl_dep_tracking_hash_for_sortable_vec_of!(Sanitizer);
|
@ -7,8 +7,9 @@
|
||||
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 @@ fn canonicalize(path: Option<PathBuf>) -> Option<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 @@ fn canonicalize(path: Option<PathBuf>) -> Option<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))
|
21
src/librustc_session/lib.rs
Normal file
21
src/librustc_session/lib.rs
Normal file
@ -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::*;
|
254
src/librustc_session/lint.rs
Normal file
254
src/librustc_session/lint.rs
Normal file
@ -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<Level> {
|
||||
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<Level> {
|
||||
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<FutureIncompatibleInfo>,
|
||||
|
||||
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<Edition>,
|
||||
}
|
||||
|
||||
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<H: std::hash::Hasher>(&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<HCX> HashStable<HCX> for LintId {
|
||||
#[inline]
|
||||
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {
|
||||
self.lint_name_raw().hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
|
||||
impl<HCX> ToStableHashKey<HCX> 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,
|
||||
};
|
||||
);
|
||||
}
|
39
src/librustc_session/node_id.rs
Normal file
39
src/librustc_session/node_id.rs
Normal file
@ -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<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||
s.emit_u32(self.as_u32())
|
||||
}
|
||||
}
|
||||
|
||||
impl rustc_serialize::UseSpecializedDecodable for NodeId {
|
||||
fn default_decode<D: Decoder>(d: &mut D) -> Result<NodeId, D::Error> {
|
||||
d.read_u32().map(NodeId::from_u32)
|
||||
}
|
||||
}
|
@ -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 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<Symbol>)>;
|
||||
|
||||
/// 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 @@ pub fn source_map(&self) -> &SourceMap {
|
||||
|
||||
pub fn buffer_lint(
|
||||
&self,
|
||||
lint_id: BufferedEarlyLintId,
|
||||
lint_id: &'static crate::lint::Lint,
|
||||
span: impl Into<MultiSpan>,
|
||||
id: NodeId,
|
||||
msg: &str,
|
@ -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<PathBuf>,
|
||||
}
|
||||
|
||||
#[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) {
|
@ -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 rustc_data_structures::impl_stable_hash_via_hash;
|
||||
|
||||
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_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::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 @@ pub fn span_note_without_error<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
|
||||
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 @@ pub fn init_incr_comp_session(
|
||||
|
||||
if let IncrCompSession::NotInitialized = *incr_comp_session {
|
||||
} else {
|
||||
bug!(
|
||||
panic!(
|
||||
"Trying to initialize IncrCompSession `{:?}`",
|
||||
*incr_comp_session
|
||||
)
|
||||
@ -698,7 +695,7 @@ pub fn finalize_incr_comp_session(&self, new_directory_path: PathBuf) {
|
||||
|
||||
if let IncrCompSession::Active { .. } = *incr_comp_session {
|
||||
} else {
|
||||
bug!(
|
||||
panic!(
|
||||
"trying to finalize `IncrCompSession` `{:?}`",
|
||||
*incr_comp_session
|
||||
);
|
||||
@ -719,7 +716,7 @@ pub fn mark_incr_comp_session_as_invalid(&self) {
|
||||
..
|
||||
} => session_directory.clone(),
|
||||
IncrCompSession::InvalidBecauseOfErrors { .. } => return,
|
||||
_ => bug!(
|
||||
_ => panic!(
|
||||
"trying to invalidate `IncrCompSession` `{:?}`",
|
||||
*incr_comp_session
|
||||
),
|
||||
@ -736,7 +733,7 @@ pub fn incr_comp_session_dir(&self) -> cell::Ref<'_, PathBuf> {
|
||||
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 @@ pub fn needs_plt(&self) -> bool {
|
||||
pub fn build_session(
|
||||
sopts: config::Options,
|
||||
local_crate_source_file: Option<PathBuf>,
|
||||
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<source_map::SourceMap>,
|
||||
emitter_dest: Option<Box<dyn Write + Send>>,
|
||||
) -> Box<dyn Emitter + sync::Send> {
|
||||
@ -1001,7 +998,7 @@ pub enum DiagnosticOutput {
|
||||
pub fn build_session_with_source_map(
|
||||
sopts: config::Options,
|
||||
local_crate_source_file: Option<PathBuf>,
|
||||
registry: errors::registry::Registry,
|
||||
registry: rustc_errors::registry::Registry,
|
||||
source_map: Lrc<source_map::SourceMap>,
|
||||
diagnostics_output: DiagnosticOutput,
|
||||
lint_caps: FxHashMap<lint::LintId, lint::Level>,
|
||||
@ -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<PathBuf>,
|
||||
span_diagnostic: errors::Handler,
|
||||
span_diagnostic: rustc_errors::Handler,
|
||||
source_map: Lrc<source_map::SourceMap>,
|
||||
driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
|
||||
) -> 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();
|
||||
}
|
||||
|
25
src/librustc_session/utils.rs
Normal file
25
src/librustc_session/utils.rs
Normal file
@ -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);
|
@ -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" }
|
||||
|
@ -30,9 +30,8 @@
|
||||
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 @@ pub fn as_angle_bracketed_args(&self) -> AngleBracketedArgs {
|
||||
}
|
||||
}
|
||||
|
||||
// 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<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||
s.emit_u32(self.as_u32())
|
||||
}
|
||||
}
|
||||
|
||||
impl rustc_serialize::UseSpecializedDecodable for NodeId {
|
||||
fn default_decode<D: Decoder>(d: &mut D) -> Result<NodeId, D::Error> {
|
||||
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<Ty>,
|
||||
}
|
||||
|
||||
/// The set of `MetaItem`s that define the compilation environment of the crate,
|
||||
/// used to drive conditional compilation.
|
||||
pub type CrateConfig = FxHashSet<(Name, Option<Symbol>)>;
|
||||
pub use rustc_session::parse::CrateConfig;
|
||||
|
||||
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
||||
pub struct Crate {
|
||||
|
@ -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 <https://github.com/rust-lang/rust/issues/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,
|
||||
|
||||
/// A lint Id that can be passed to `rustc::lint::Lint::from_parser_lint_id`.
|
||||
pub lint_id: BufferedEarlyLintId,
|
||||
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"
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ pub mod feature_gate {
|
||||
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;
|
||||
|
@ -924,7 +924,6 @@ pub fn new_parser_from_tts(&self, stream: TokenStream) -> parser::Parser<'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
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
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 @@ fn make_expr(mut self: Box<ExpandResult<'a>>) -> Option<P<ast::Expr>> {
|
||||
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",
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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};
|
||||
|
@ -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};
|
||||
|
@ -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,
|
||||
|
@ -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 {
|
||||
| ^^^^^^^^
|
||||
|
Loading…
Reference in New Issue
Block a user