cleanup: Remove `ParseSess::injected_crate_name`

This commit is contained in:
Vadim Petrochenkov 2020-11-13 00:35:46 +03:00
parent 9722952f0b
commit 8766c0452c
5 changed files with 7 additions and 16 deletions

View File

@ -109,7 +109,6 @@ pub fn print_crate<'a>(
ann: &'a dyn PpAnn, ann: &'a dyn PpAnn,
is_expanded: bool, is_expanded: bool,
edition: Edition, edition: Edition,
has_injected_crate: bool,
) -> String { ) -> String {
let mut s = State { let mut s = State {
s: pp::mk_printer(), s: pp::mk_printer(),
@ -119,7 +118,7 @@ pub fn print_crate<'a>(
insert_extra_parens: true, 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 // We need to print `#![no_std]` (and its feature gate) so that
// compiling pretty-printed source won't inject libstd again. // compiling pretty-printed source won't inject libstd again.
// However, we don't want these attributes in the AST because // However, we don't want these attributes in the AST because

View File

@ -13,12 +13,12 @@ pub fn inject(
resolver: &mut dyn ResolverExpand, resolver: &mut dyn ResolverExpand,
sess: &Session, sess: &Session,
alt_std_name: Option<Symbol>, alt_std_name: Option<Symbol>,
) -> (ast::Crate, Option<Symbol>) { ) -> ast::Crate {
let rust_2018 = sess.parse_sess.edition >= Edition::Edition2018; 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 // 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) { 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) { } else if sess.contains_name(&krate.attrs, sym::no_std) {
if sess.contains_name(&krate.attrs, sym::compiler_builtins) { if sess.contains_name(&krate.attrs, sym::compiler_builtins) {
&[sym::core] &[sym::core]
@ -81,5 +81,5 @@ pub fn inject(
krate.module.items.insert(0, use_item); krate.module.items.insert(0, use_item);
(krate, Some(name)) krate
} }

View File

@ -407,7 +407,6 @@ pub fn print_after_parsing(
annotation.pp_ann(), annotation.pp_ann(),
false, false,
parse.edition, parse.edition,
parse.injected_crate_name.get().is_some(),
) )
}) })
} else { } else {
@ -449,7 +448,6 @@ pub fn print_after_hir_lowering<'tcx>(
annotation.pp_ann(), annotation.pp_ann(),
true, true,
parse.edition, parse.edition,
parse.injected_crate_name.get().is_some(),
) )
}) })
} }

View File

@ -239,16 +239,12 @@ fn configure_and_expand_inner<'a>(
krate = sess.time("crate_injection", || { krate = sess.time("crate_injection", || {
let alt_std_name = sess.opts.alt_std_name.as_ref().map(|s| Symbol::intern(s)); 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, krate,
&mut resolver, &mut resolver,
&sess, &sess,
alt_std_name, 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()); util::check_attr_crate_type(&sess, &krate.attrs, &mut resolver.lint_buffer());

View File

@ -4,7 +4,7 @@
use crate::lint::{BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId}; use crate::lint::{BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId};
use rustc_ast::node_id::NodeId; use rustc_ast::node_id::NodeId;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; 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::{emitter::SilentEmitter, ColorConfig, Handler};
use rustc_errors::{error_code, Applicability, DiagnosticBuilder}; use rustc_errors::{error_code, Applicability, DiagnosticBuilder};
use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures}; use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures};
@ -129,7 +129,6 @@ pub struct ParseSess {
/// operation token that followed it, but that the parser cannot identify without further /// operation token that followed it, but that the parser cannot identify without further
/// analysis. /// analysis.
pub ambiguous_block_expr_parse: Lock<FxHashMap<Span, Span>>, pub ambiguous_block_expr_parse: Lock<FxHashMap<Span, Span>>,
pub injected_crate_name: OnceCell<Symbol>,
pub gated_spans: GatedSpans, pub gated_spans: GatedSpans,
pub symbol_gallery: SymbolGallery, pub symbol_gallery: SymbolGallery,
/// The parser has reached `Eof` due to an unclosed brace. Used to silence unnecessary errors. /// The parser has reached `Eof` due to an unclosed brace. Used to silence unnecessary errors.
@ -158,7 +157,6 @@ impl ParseSess {
source_map, source_map,
buffered_lints: Lock::new(vec![]), buffered_lints: Lock::new(vec![]),
ambiguous_block_expr_parse: Lock::new(FxHashMap::default()), ambiguous_block_expr_parse: Lock::new(FxHashMap::default()),
injected_crate_name: OnceCell::new(),
gated_spans: GatedSpans::default(), gated_spans: GatedSpans::default(),
symbol_gallery: SymbolGallery::default(), symbol_gallery: SymbolGallery::default(),
reached_eof: Lock::new(false), reached_eof: Lock::new(false),