Rollup merge of #79005 - petrochenkov:noinjected, r=davidtwco
cleanup: Remove `ParseSess::injected_crate_name` Its only remaining use is in pretty-printing where the necessary information can be easily re-computed.
This commit is contained in:
commit
f32191f78f
@ -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(),
|
||||
@ -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
|
||||
|
@ -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]
|
||||
@ -81,5 +81,5 @@ pub fn inject(
|
||||
|
||||
krate.module.items.insert(0, use_item);
|
||||
|
||||
(krate, Some(name))
|
||||
krate
|
||||
}
|
||||
|
@ -404,7 +404,6 @@ pub fn print_after_parsing(
|
||||
annotation.pp_ann(),
|
||||
false,
|
||||
parse.edition,
|
||||
parse.injected_crate_name.get().is_some(),
|
||||
)
|
||||
})
|
||||
} else {
|
||||
@ -446,7 +445,6 @@ pub fn print_after_hir_lowering<'tcx>(
|
||||
annotation.pp_ann(),
|
||||
true,
|
||||
parse.edition,
|
||||
parse.injected_crate_name.get().is_some(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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};
|
||||
@ -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.
|
||||
@ -158,7 +157,6 @@ pub fn with_span_handler(handler: Handler, source_map: Lrc<SourceMap>) -> Self {
|
||||
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),
|
||||
|
Loading…
Reference in New Issue
Block a user