//! 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, Attribute};
-use crate::early_buffered_lints::{BufferedEarlyLint, BufferedEarlyLintId};
-use crate::source_map::{SourceMap, FilePathMapping};
-use crate::feature_gate::UnstableFeatures;
+use crate::ast::{CrateConfig, NodeId};
+use crate::early_buffered_lints::BufferedEarlyLint;
use 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;
use syntax_pos::{Symbol, Span, MultiSpan};
use syntax_pos::edition::Edition;
use syntax_pos::hygiene::ExpnId;
+use syntax_pos::source_map::{SourceMap, FilePathMapping};
use std::path::PathBuf;
use std::str;
pub gated_spans: GatedSpans,
/// The parser has reached `Eof` due to an unclosed brace. Used to silence unnecessary errors.
pub reached_eof: Lock<bool>,
- /// Process the potential `cfg` attributes on a module.
- /// Also determine if the module should be included in this configuration.
- ///
- /// HACK(Centril): This is used to break a cyclic dependency between
- /// the parser and cfg-stripping as defined in `syntax_expand::config`.
- /// The dependency edge from the parser comes from `parse_item_mod`.
- /// A principled solution to this hack would be to implement [#64197].
- ///
- /// [#64197]: https://github.com/rust-lang/rust/issues/64197
- pub process_cfg_mod: ProcessCfgMod,
}
-pub type ProcessCfgMod = fn(&ParseSess, bool, &[Attribute]) -> (bool, Vec<Attribute>);
-
impl ParseSess {
- pub fn new(file_path_mapping: FilePathMapping, process_cfg_mod: ProcessCfgMod) -> Self {
+ pub fn new(file_path_mapping: FilePathMapping) -> Self {
let cm = Lrc::new(SourceMap::new(file_path_mapping));
let handler = Handler::with_tty_emitter(
ColorConfig::Auto,
None,
Some(cm.clone()),
);
- ParseSess::with_span_handler(handler, cm, process_cfg_mod)
+ ParseSess::with_span_handler(handler, cm)
}
pub fn with_span_handler(
handler: Handler,
source_map: Lrc<SourceMap>,
- process_cfg_mod: ProcessCfgMod,
) -> Self {
Self {
span_diagnostic: handler,
- process_cfg_mod,
unstable_features: UnstableFeatures::from_environment(),
config: FxHashSet::default(),
edition: ExpnId::root().expn_data().edition,
}
}
- pub fn with_silent_emitter(process_cfg_mod: ProcessCfgMod) -> Self {
+ pub fn with_silent_emitter() -> Self {
let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let handler = Handler::with_emitter(false, None, Box::new(SilentEmitter));
- ParseSess::with_span_handler(handler, cm, process_cfg_mod)
+ ParseSess::with_span_handler(handler, cm)
}
#[inline]
pub fn buffer_lint(
&self,
- lint_id: BufferedEarlyLintId,
+ lint_id: &'static rustc_session::lint::Lint,
span: impl Into<MultiSpan>,
id: NodeId,
msg: &str,