Skip to content

Commit eaac45a

Browse files
committed
Auto merge of #66565 - Mark-Simulacrum:syntax-cfg-mod, r=petrochenkov
Move process_configure_mod to rustc_parse This removes the hack in favor of perhaps a less principled, but less painful, approach. This also supports my work to decouple `Session` from librustc, as `ParseSess` currently has `Attribute` as "part" of it but after this PR will no longer do so.
2 parents 564f2d3 + 70805e6 commit eaac45a

File tree

19 files changed

+34
-58
lines changed

19 files changed

+34
-58
lines changed

src/librustc/session/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use syntax::edition::Edition;
2424
use syntax::feature_gate;
2525
use errors::json::JsonEmitter;
2626
use syntax::source_map;
27-
use syntax::sess::{ParseSess, ProcessCfgMod};
27+
use syntax::sess::ParseSess;
2828
use syntax_pos::{MultiSpan, Span};
2929

3030
use rustc_target::spec::{PanicStrategy, RelroLevel, Target, TargetTriple};
@@ -925,7 +925,6 @@ pub fn build_session(
925925
sopts: config::Options,
926926
local_crate_source_file: Option<PathBuf>,
927927
registry: errors::registry::Registry,
928-
process_cfg_mod: ProcessCfgMod,
929928
) -> Session {
930929
let file_path_mapping = sopts.file_path_mapping();
931930

@@ -936,7 +935,6 @@ pub fn build_session(
936935
Lrc::new(source_map::SourceMap::new(file_path_mapping)),
937936
DiagnosticOutput::Default,
938937
Default::default(),
939-
process_cfg_mod,
940938
)
941939
}
942940

@@ -1015,7 +1013,6 @@ pub fn build_session_with_source_map(
10151013
source_map: Lrc<source_map::SourceMap>,
10161014
diagnostics_output: DiagnosticOutput,
10171015
lint_caps: FxHashMap<lint::LintId, lint::Level>,
1018-
process_cfg_mod: ProcessCfgMod,
10191016
) -> Session {
10201017
// FIXME: This is not general enough to make the warning lint completely override
10211018
// normal diagnostic warnings, since the warning lint can also be denied and changed
@@ -1061,7 +1058,6 @@ pub fn build_session_with_source_map(
10611058
diagnostic_handler,
10621059
source_map,
10631060
lint_caps,
1064-
process_cfg_mod,
10651061
)
10661062
}
10671063

@@ -1071,7 +1067,6 @@ fn build_session_(
10711067
span_diagnostic: errors::Handler,
10721068
source_map: Lrc<source_map::SourceMap>,
10731069
driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
1074-
process_cfg_mod: ProcessCfgMod,
10751070
) -> Session {
10761071
let self_profiler =
10771072
if let SwitchWithOptPath::Enabled(ref d) = sopts.debugging_opts.self_profile {
@@ -1109,7 +1104,6 @@ fn build_session_(
11091104
let parse_sess = ParseSess::with_span_handler(
11101105
span_diagnostic,
11111106
source_map,
1112-
process_cfg_mod,
11131107
);
11141108
let sysroot = match &sopts.maybe_sysroot {
11151109
Some(sysroot) => sysroot.clone(),

src/librustc_interface/interface.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use syntax::ast::{self, MetaItemKind};
2121
use syntax::token;
2222
use syntax::source_map::{FileName, FileLoader, SourceMap};
2323
use syntax::sess::ParseSess;
24-
use syntax_expand::config::process_configure_mod;
2524
use syntax_pos::edition;
2625

2726
pub type Result<T> = result::Result<T, ErrorReported>;
@@ -69,7 +68,7 @@ impl Compiler {
6968
pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String>)> {
7069
syntax::with_default_globals(move || {
7170
let cfg = cfgspecs.into_iter().map(|s| {
72-
let sess = ParseSess::with_silent_emitter(process_configure_mod);
71+
let sess = ParseSess::with_silent_emitter();
7372
let filename = FileName::cfg_spec_source_code(&s);
7473
let mut parser = new_parser_from_source_str(&sess, filename, s.to_string());
7574

src/librustc_interface/tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel};
1717
use syntax::symbol::sym;
1818
use syntax::edition::{Edition, DEFAULT_EDITION};
1919
use syntax;
20-
use syntax_expand::config::process_configure_mod;
2120
use rustc_data_structures::fx::FxHashSet;
2221
use rustc_errors::{ColorConfig, emitter::HumanReadableErrorType, registry};
2322

@@ -32,7 +31,7 @@ fn build_session_options_and_crate_config(matches: getopts::Matches) -> (Options
3231
fn mk_session(matches: getopts::Matches) -> (Session, CfgSpecs) {
3332
let registry = registry::Registry::new(&[]);
3433
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
35-
let sess = build_session(sessopts, None, registry, process_configure_mod);
34+
let sess = build_session(sessopts, None, registry);
3635
(sess, cfg)
3736
}
3837

src/librustc_interface/util.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use syntax::util::lev_distance::find_best_match_for_name;
3131
use syntax::source_map::{FileLoader, RealFileLoader, SourceMap};
3232
use syntax::symbol::{Symbol, sym};
3333
use syntax::{self, ast, attr};
34-
use syntax_expand::config::process_configure_mod;
3534
use syntax_pos::edition::Edition;
3635
#[cfg(not(parallel_compiler))]
3736
use std::{thread, panic};
@@ -81,7 +80,6 @@ pub fn create_session(
8180
source_map.clone(),
8281
diagnostic_output,
8382
lint_caps,
84-
process_configure_mod,
8583
);
8684

8785
sess.prof.register_queries(|profiler| {

src/libsyntax_expand/config.rs renamed to src/librustc_parse/config.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
use rustc_parse::validate_attr;
1+
//! Process the potential `cfg` attributes on a module.
2+
//! Also determine if the module should be included in this configuration.
3+
//!
4+
//! This module properly belongs in syntax_expand, but for now it's tied into
5+
//! parsing, so we leave it here to avoid complicated out-of-line dependencies.
6+
//!
7+
//! A principled solution to this wrong location would be to implement [#64197].
8+
//!
9+
//! [#64197]: https://github.com/rust-lang/rust/issues/64197
10+
11+
use crate::validate_attr;
212
use syntax::attr::HasAttrs;
313
use syntax::feature_gate::{
414
feature_err,
@@ -113,7 +123,7 @@ impl<'a> StripUnconfigured<'a> {
113123
return vec![];
114124
}
115125

116-
let res = rustc_parse::parse_in_attr(self.sess, &attr, |p| p.parse_cfg_attr());
126+
let res = crate::parse_in_attr(self.sess, &attr, |p| p.parse_cfg_attr());
117127
let (cfg_predicate, expanded_attrs) = match res {
118128
Ok(result) => result,
119129
Err(mut e) => {

src/librustc_parse/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub mod parser;
2525
use parser::{Parser, emit_unclosed_delims, make_unclosed_delims_error};
2626
pub mod lexer;
2727
pub mod validate_attr;
28+
#[macro_use]
29+
pub mod config;
2830

2931
#[derive(Clone)]
3032
pub struct Directory<'a> {

src/librustc_parse/parser/module.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ impl<'a> Parser<'a> {
4040

4141
/// Parses a `mod <foo> { ... }` or `mod <foo>;` item.
4242
pub(super) fn parse_item_mod(&mut self, outer_attrs: &[Attribute]) -> PResult<'a, ItemInfo> {
43-
// HACK(Centril): See documentation on `ParseSess::process_cfg_mod`.
44-
let (in_cfg, outer_attrs) = (self.sess.process_cfg_mod)(
43+
let (in_cfg, outer_attrs) = crate::config::process_configure_mod(
4544
self.sess,
4645
self.cfg_mods,
4746
outer_attrs,

src/librustdoc/html/highlight.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use syntax::token::{self, Token};
1616
use syntax::sess::ParseSess;
1717
use syntax::source_map::SourceMap;
1818
use syntax::symbol::{kw, sym};
19-
use syntax_expand::config::process_configure_mod;
2019
use syntax_pos::{Span, FileName};
2120

2221
/// Highlights `src`, returning the HTML output.
@@ -34,7 +33,7 @@ pub fn render_with_highlighting(
3433
class, tooltip).unwrap();
3534
}
3635

37-
let sess = ParseSess::with_silent_emitter(process_configure_mod);
36+
let sess = ParseSess::with_silent_emitter();
3837
let fm = sess.source_map().new_source_file(
3938
FileName::Custom(String::from("rustdoc-highlighting")),
4039
src.to_owned(),

src/librustdoc/passes/check_code_block_syntax.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use rustc_parse::lexer::{StringReader as Lexer};
33
use syntax::token;
44
use syntax::sess::ParseSess;
55
use syntax::source_map::FilePathMapping;
6-
use syntax_expand::config::process_configure_mod;
76
use syntax_pos::{InnerSpan, FileName};
87

98
use crate::clean;
@@ -28,7 +27,7 @@ struct SyntaxChecker<'a, 'tcx> {
2827

2928
impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> {
3029
fn check_rust_syntax(&self, item: &clean::Item, dox: &str, code_block: RustCodeBlock) {
31-
let sess = ParseSess::new(FilePathMapping::empty(), process_configure_mod);
30+
let sess = ParseSess::new(FilePathMapping::empty());
3231
let source_file = sess.source_map().new_source_file(
3332
FileName::Custom(String::from("doctest")),
3433
dox[code_block.code].to_owned(),

src/librustdoc/test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use std::path::PathBuf;
1717
use std::process::{self, Command, Stdio};
1818
use std::str;
1919
use syntax::symbol::sym;
20-
use syntax_expand::config::process_configure_mod;
2120
use syntax_pos::{BytePos, DUMMY_SP, Pos, Span, FileName};
2221
use tempfile::Builder as TempFileBuilder;
2322
use testing;
@@ -415,7 +414,7 @@ pub fn make_test(s: &str,
415414
let emitter = EmitterWriter::new(box io::sink(), None, false, false, false, None, false);
416415
// FIXME(misdreavus): pass `-Z treat-err-as-bug` to the doctest parser
417416
let handler = Handler::with_emitter(false, None, box emitter);
418-
let sess = ParseSess::with_span_handler(handler, cm, process_configure_mod);
417+
let sess = ParseSess::with_span_handler(handler, cm);
419418

420419
let mut found_main = false;
421420
let mut found_extern_crate = cratename.is_none();

0 commit comments

Comments
 (0)