Skip to content

Commit f32191f

Browse files
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.
2 parents e0c378a + 8766c04 commit f32191f

File tree

5 files changed

+7
-16
lines changed

5 files changed

+7
-16
lines changed

Diff for: compiler/rustc_ast_pretty/src/pprust/state.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ pub fn print_crate<'a>(
109109
ann: &'a dyn PpAnn,
110110
is_expanded: bool,
111111
edition: Edition,
112-
has_injected_crate: bool,
113112
) -> String {
114113
let mut s = State {
115114
s: pp::mk_printer(),
@@ -119,7 +118,7 @@ pub fn print_crate<'a>(
119118
insert_extra_parens: true,
120119
};
121120

122-
if is_expanded && has_injected_crate {
121+
if is_expanded && !krate.attrs.iter().any(|attr| attr.has_name(sym::no_core)) {
123122
// We need to print `#![no_std]` (and its feature gate) so that
124123
// compiling pretty-printed source won't inject libstd again.
125124
// However, we don't want these attributes in the AST because

Diff for: compiler/rustc_builtin_macros/src/standard_library_imports.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ pub fn inject(
1313
resolver: &mut dyn ResolverExpand,
1414
sess: &Session,
1515
alt_std_name: Option<Symbol>,
16-
) -> (ast::Crate, Option<Symbol>) {
16+
) -> ast::Crate {
1717
let rust_2018 = sess.parse_sess.edition >= Edition::Edition2018;
1818

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

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

84-
(krate, Some(name))
84+
krate
8585
}

Diff for: compiler/rustc_driver/src/pretty.rs

-2
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ pub fn print_after_parsing(
404404
annotation.pp_ann(),
405405
false,
406406
parse.edition,
407-
parse.injected_crate_name.get().is_some(),
408407
)
409408
})
410409
} else {
@@ -446,7 +445,6 @@ pub fn print_after_hir_lowering<'tcx>(
446445
annotation.pp_ann(),
447446
true,
448447
parse.edition,
449-
parse.injected_crate_name.get().is_some(),
450448
)
451449
})
452450
}

Diff for: compiler/rustc_interface/src/passes.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,12 @@ fn configure_and_expand_inner<'a>(
239239

240240
krate = sess.time("crate_injection", || {
241241
let alt_std_name = sess.opts.alt_std_name.as_ref().map(|s| Symbol::intern(s));
242-
let (krate, name) = rustc_builtin_macros::standard_library_imports::inject(
242+
rustc_builtin_macros::standard_library_imports::inject(
243243
krate,
244244
&mut resolver,
245245
&sess,
246246
alt_std_name,
247-
);
248-
if let Some(name) = name {
249-
sess.parse_sess.injected_crate_name.set(name).expect("not yet initialized");
250-
}
251-
krate
247+
)
252248
});
253249

254250
util::check_attr_crate_type(&sess, &krate.attrs, &mut resolver.lint_buffer());

Diff for: compiler/rustc_session/src/parse.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use crate::lint::{BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId};
55
use rustc_ast::node_id::NodeId;
66
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
7-
use rustc_data_structures::sync::{Lock, Lrc, OnceCell};
7+
use rustc_data_structures::sync::{Lock, Lrc};
88
use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler};
99
use rustc_errors::{error_code, Applicability, DiagnosticBuilder};
1010
use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures};
@@ -129,7 +129,6 @@ pub struct ParseSess {
129129
/// operation token that followed it, but that the parser cannot identify without further
130130
/// analysis.
131131
pub ambiguous_block_expr_parse: Lock<FxHashMap<Span, Span>>,
132-
pub injected_crate_name: OnceCell<Symbol>,
133132
pub gated_spans: GatedSpans,
134133
pub symbol_gallery: SymbolGallery,
135134
/// The parser has reached `Eof` due to an unclosed brace. Used to silence unnecessary errors.
@@ -158,7 +157,6 @@ impl ParseSess {
158157
source_map,
159158
buffered_lints: Lock::new(vec![]),
160159
ambiguous_block_expr_parse: Lock::new(FxHashMap::default()),
161-
injected_crate_name: OnceCell::new(),
162160
gated_spans: GatedSpans::default(),
163161
symbol_gallery: SymbolGallery::default(),
164162
reached_eof: Lock::new(false),

0 commit comments

Comments
 (0)