Skip to content

Commit

Permalink
cleanup: Remove ParseSess::injected_crate_name
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Nov 12, 2020
1 parent 9722952 commit 8766c04
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 16 deletions.
3 changes: 1 addition & 2 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ pub fn print_crate<'a>(
ann: &'a dyn PpAnn,
is_expanded: bool,
edition: Edition,
has_injected_crate: bool,
) -> String {
let mut s = State {
s: pp::mk_printer(),
Expand All @@ -119,7 +118,7 @@ pub fn print_crate<'a>(
insert_extra_parens: true,
};

if is_expanded && has_injected_crate {
if is_expanded && !krate.attrs.iter().any(|attr| attr.has_name(sym::no_core)) {
// We need to print `#![no_std]` (and its feature gate) so that
// compiling pretty-printed source won't inject libstd again.
// However, we don't want these attributes in the AST because
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_builtin_macros/src/standard_library_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ pub fn inject(
resolver: &mut dyn ResolverExpand,
sess: &Session,
alt_std_name: Option<Symbol>,
) -> (ast::Crate, Option<Symbol>) {
) -> ast::Crate {
let rust_2018 = sess.parse_sess.edition >= Edition::Edition2018;

// the first name in this list is the crate name of the crate with the prelude
let names: &[Symbol] = if sess.contains_name(&krate.attrs, sym::no_core) {
return (krate, None);
return krate;
} else if sess.contains_name(&krate.attrs, sym::no_std) {
if sess.contains_name(&krate.attrs, sym::compiler_builtins) {
&[sym::core]
Expand Down Expand Up @@ -81,5 +81,5 @@ pub fn inject(

krate.module.items.insert(0, use_item);

(krate, Some(name))
krate
}
2 changes: 0 additions & 2 deletions compiler/rustc_driver/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ pub fn print_after_parsing(
annotation.pp_ann(),
false,
parse.edition,
parse.injected_crate_name.get().is_some(),
)
})
} else {
Expand Down Expand Up @@ -449,7 +448,6 @@ pub fn print_after_hir_lowering<'tcx>(
annotation.pp_ann(),
true,
parse.edition,
parse.injected_crate_name.get().is_some(),
)
})
}
Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,12 @@ fn configure_and_expand_inner<'a>(

krate = sess.time("crate_injection", || {
let alt_std_name = sess.opts.alt_std_name.as_ref().map(|s| Symbol::intern(s));
let (krate, name) = rustc_builtin_macros::standard_library_imports::inject(
rustc_builtin_macros::standard_library_imports::inject(
krate,
&mut resolver,
&sess,
alt_std_name,
);
if let Some(name) = name {
sess.parse_sess.injected_crate_name.set(name).expect("not yet initialized");
}
krate
)
});

util::check_attr_crate_type(&sess, &krate.attrs, &mut resolver.lint_buffer());
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_session/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::lint::{BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId};
use rustc_ast::node_id::NodeId;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::{Lock, Lrc, OnceCell};
use rustc_data_structures::sync::{Lock, Lrc};
use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler};
use rustc_errors::{error_code, Applicability, DiagnosticBuilder};
use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures};
Expand Down Expand Up @@ -129,7 +129,6 @@ pub struct ParseSess {
/// operation token that followed it, but that the parser cannot identify without further
/// analysis.
pub ambiguous_block_expr_parse: Lock<FxHashMap<Span, Span>>,
pub injected_crate_name: OnceCell<Symbol>,
pub gated_spans: GatedSpans,
pub symbol_gallery: SymbolGallery,
/// The parser has reached `Eof` due to an unclosed brace. Used to silence unnecessary errors.
Expand Down Expand Up @@ -158,7 +157,6 @@ impl ParseSess {
source_map,
buffered_lints: Lock::new(vec![]),
ambiguous_block_expr_parse: Lock::new(FxHashMap::default()),
injected_crate_name: OnceCell::new(),
gated_spans: GatedSpans::default(),
symbol_gallery: SymbolGallery::default(),
reached_eof: Lock::new(false),
Expand Down

0 comments on commit 8766c04

Please sign in to comment.