Skip to content

Commit 2acf32d

Browse files
committed
Auto merge of rust-lang#70483 - Centril:rollup-slli4yf, r=Centril
Rollup of 5 pull requests Successful merges: - rust-lang#70345 (Remove `no_integrated_as` mode.) - rust-lang#70434 (suggest `;` on expr `mac!()` which is good as stmt `mac!()`) - rust-lang#70457 (non-exhastive diagnostic: add note re. scrutinee type) - rust-lang#70478 (Refactor type_of for constants) - rust-lang#70480 (clarify hir_id <-> node_id method names) Failed merges: r? @ghost
2 parents 0bf7c2a + a023e61 commit 2acf32d

File tree

86 files changed

+485
-253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+485
-253
lines changed

src/librustc/hir/map/collector.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
241241
// Make sure that the DepNode of some node coincides with the HirId
242242
// owner of that node.
243243
if cfg!(debug_assertions) {
244-
let node_id = self.definitions.hir_to_node_id(hir_id);
245-
assert_eq!(self.definitions.node_to_hir_id(node_id), hir_id);
244+
let node_id = self.definitions.hir_id_to_node_id(hir_id);
245+
assert_eq!(self.definitions.node_id_to_hir_id(node_id), hir_id);
246246

247247
if hir_id.owner != self.current_dep_node_owner {
248248
let node_str = match self.definitions.opt_local_def_id(node_id) {
@@ -342,7 +342,9 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
342342
debug!("visit_item: {:?}", i);
343343
debug_assert_eq!(
344344
i.hir_id.owner,
345-
self.definitions.opt_local_def_id(self.definitions.hir_to_node_id(i.hir_id)).unwrap()
345+
self.definitions
346+
.opt_local_def_id(self.definitions.hir_id_to_node_id(i.hir_id))
347+
.unwrap()
346348
);
347349
self.with_dep_node_owner(i.hir_id.owner, i, |this, hash| {
348350
this.insert_with_hash(i.span, i.hir_id, Node::Item(i), hash);
@@ -374,7 +376,9 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
374376
fn visit_trait_item(&mut self, ti: &'hir TraitItem<'hir>) {
375377
debug_assert_eq!(
376378
ti.hir_id.owner,
377-
self.definitions.opt_local_def_id(self.definitions.hir_to_node_id(ti.hir_id)).unwrap()
379+
self.definitions
380+
.opt_local_def_id(self.definitions.hir_id_to_node_id(ti.hir_id))
381+
.unwrap()
378382
);
379383
self.with_dep_node_owner(ti.hir_id.owner, ti, |this, hash| {
380384
this.insert_with_hash(ti.span, ti.hir_id, Node::TraitItem(ti), hash);
@@ -388,7 +392,9 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
388392
fn visit_impl_item(&mut self, ii: &'hir ImplItem<'hir>) {
389393
debug_assert_eq!(
390394
ii.hir_id.owner,
391-
self.definitions.opt_local_def_id(self.definitions.hir_to_node_id(ii.hir_id)).unwrap()
395+
self.definitions
396+
.opt_local_def_id(self.definitions.hir_id_to_node_id(ii.hir_id))
397+
.unwrap()
392398
);
393399
self.with_dep_node_owner(ii.hir_id.owner, ii, |this, hash| {
394400
this.insert_with_hash(ii.span, ii.hir_id, Node::ImplItem(ii), hash);

src/librustc/hir/map/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<'hir> Map<'hir> {
161161
#[inline]
162162
pub fn local_def_id_from_node_id(&self, node: NodeId) -> DefId {
163163
self.opt_local_def_id_from_node_id(node).unwrap_or_else(|| {
164-
let hir_id = self.node_to_hir_id(node);
164+
let hir_id = self.node_id_to_hir_id(node);
165165
bug!(
166166
"local_def_id_from_node_id: no entry for `{}`, which has a map of `{:?}`",
167167
node,
@@ -184,7 +184,7 @@ impl<'hir> Map<'hir> {
184184

185185
#[inline]
186186
pub fn opt_local_def_id(&self, hir_id: HirId) -> Option<DefId> {
187-
let node_id = self.hir_to_node_id(hir_id);
187+
let node_id = self.hir_id_to_node_id(hir_id);
188188
self.opt_local_def_id_from_node_id(node_id)
189189
}
190190

@@ -204,13 +204,13 @@ impl<'hir> Map<'hir> {
204204
}
205205

206206
#[inline]
207-
pub fn hir_to_node_id(&self, hir_id: HirId) -> NodeId {
208-
self.tcx.definitions.hir_to_node_id(hir_id)
207+
pub fn hir_id_to_node_id(&self, hir_id: HirId) -> NodeId {
208+
self.tcx.definitions.hir_id_to_node_id(hir_id)
209209
}
210210

211211
#[inline]
212-
pub fn node_to_hir_id(&self, node_id: NodeId) -> HirId {
213-
self.tcx.definitions.node_to_hir_id(node_id)
212+
pub fn node_id_to_hir_id(&self, node_id: NodeId) -> HirId {
213+
self.tcx.definitions.node_id_to_hir_id(node_id)
214214
}
215215

216216
#[inline]

src/librustc/ich/hcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'a> StableHashingContext<'a> {
137137

138138
#[inline]
139139
pub fn node_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
140-
self.definitions.node_to_hir_id(node_id)
140+
self.definitions.node_id_to_hir_id(node_id)
141141
}
142142

143143
#[inline]

src/librustc/ty/context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1126,11 +1126,11 @@ impl<'tcx> TyCtxt<'tcx> {
11261126

11271127
let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default();
11281128
for (k, v) in resolutions.trait_map {
1129-
let hir_id = definitions.node_to_hir_id(k);
1129+
let hir_id = definitions.node_id_to_hir_id(k);
11301130
let map = trait_map.entry(hir_id.owner).or_default();
11311131
let v = v
11321132
.into_iter()
1133-
.map(|tc| tc.map_import_ids(|id| definitions.node_to_hir_id(id)))
1133+
.map(|tc| tc.map_import_ids(|id| definitions.node_id_to_hir_id(id)))
11341134
.collect();
11351135
map.insert(hir_id.local_id, StableVec::new(v));
11361136
}
@@ -1154,7 +1154,7 @@ impl<'tcx> TyCtxt<'tcx> {
11541154
.map(|(k, v)| {
11551155
let exports: Vec<_> = v
11561156
.into_iter()
1157-
.map(|e| e.map_id(|id| definitions.node_to_hir_id(id)))
1157+
.map(|e| e.map_id(|id| definitions.node_id_to_hir_id(id)))
11581158
.collect();
11591159
(k, exports)
11601160
})

src/librustc_codegen_llvm/back/write.rs

+25-38
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ use crate::ModuleLlvm;
1616
use log::debug;
1717
use rustc::bug;
1818
use rustc::ty::TyCtxt;
19-
use rustc_codegen_ssa::back::write::{
20-
run_assembler, BitcodeSection, CodegenContext, EmitObj, ModuleConfig,
21-
};
19+
use rustc_codegen_ssa::back::write::{BitcodeSection, CodegenContext, EmitObj, ModuleConfig};
2220
use rustc_codegen_ssa::traits::*;
2321
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen, RLIB_BYTECODE_EXTENSION};
2422
use rustc_data_structures::small_c_str::SmallCStr;
@@ -734,53 +732,41 @@ pub(crate) unsafe fn codegen(
734732
})?;
735733
}
736734

737-
let config_emit_object_code = matches!(config.emit_obj, EmitObj::ObjectCode(_));
738-
739-
if config.emit_asm || (config_emit_object_code && config.no_integrated_as) {
735+
if config.emit_asm {
740736
let _timer = cgcx
741737
.prof
742738
.generic_activity_with_arg("LLVM_module_codegen_emit_asm", &module.name[..]);
743739
let path = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name);
744740

745-
// We can't use the same module for asm and binary output, because that triggers
746-
// various errors like invalid IR or broken binaries, so we might have to clone the
747-
// module to produce the asm output
748-
let llmod = if config_emit_object_code { llvm::LLVMCloneModule(llmod) } else { llmod };
741+
// We can't use the same module for asm and object code output,
742+
// because that triggers various errors like invalid IR or broken
743+
// binaries. So we must clone the module to produce the asm output
744+
// if we are also producing object code.
745+
let llmod = if let EmitObj::ObjectCode(_) = config.emit_obj {
746+
llvm::LLVMCloneModule(llmod)
747+
} else {
748+
llmod
749+
};
749750
with_codegen(tm, llmod, config.no_builtins, |cpm| {
750751
write_output_file(diag_handler, tm, cpm, llmod, &path, llvm::FileType::AssemblyFile)
751752
})?;
752753
}
753754

754755
match config.emit_obj {
755756
EmitObj::ObjectCode(_) => {
756-
if !config.no_integrated_as {
757-
let _timer = cgcx.prof.generic_activity_with_arg(
758-
"LLVM_module_codegen_emit_obj",
759-
&module.name[..],
760-
);
761-
with_codegen(tm, llmod, config.no_builtins, |cpm| {
762-
write_output_file(
763-
diag_handler,
764-
tm,
765-
cpm,
766-
llmod,
767-
&obj_out,
768-
llvm::FileType::ObjectFile,
769-
)
770-
})?;
771-
} else {
772-
let _timer = cgcx.prof.generic_activity_with_arg(
773-
"LLVM_module_codegen_asm_to_obj",
774-
&module.name[..],
775-
);
776-
let assembly =
777-
cgcx.output_filenames.temp_path(OutputType::Assembly, module_name);
778-
run_assembler(cgcx, diag_handler, &assembly, &obj_out);
779-
780-
if !config.emit_asm && !cgcx.save_temps {
781-
drop(fs::remove_file(&assembly));
782-
}
783-
}
757+
let _timer = cgcx
758+
.prof
759+
.generic_activity_with_arg("LLVM_module_codegen_emit_obj", &module.name[..]);
760+
with_codegen(tm, llmod, config.no_builtins, |cpm| {
761+
write_output_file(
762+
diag_handler,
763+
tm,
764+
cpm,
765+
llmod,
766+
&obj_out,
767+
llvm::FileType::ObjectFile,
768+
)
769+
})?;
784770
}
785771

786772
EmitObj::Bitcode => {
@@ -802,6 +788,7 @@ pub(crate) unsafe fn codegen(
802788

803789
drop(handlers);
804790
}
791+
805792
Ok(module.into_compiled_module(
806793
config.emit_obj != EmitObj::None,
807794
config.emit_bc,

src/librustc_codegen_ssa/back/write.rs

+1-65
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use super::command::Command;
2-
use super::link::{self, get_linker, remove};
1+
use super::link::{self, remove};
32
use super::linker::LinkerInfo;
43
use super::lto::{self, SerializedModule};
54
use super::symbol_export::symbol_name_for_instance_in_crate;
@@ -116,7 +115,6 @@ pub struct ModuleConfig {
116115
pub merge_functions: bool,
117116
pub inline_threshold: Option<usize>,
118117
pub new_llvm_pass_manager: Option<bool>,
119-
pub no_integrated_as: bool,
120118
}
121119

122120
impl ModuleConfig {
@@ -140,7 +138,6 @@ impl ModuleConfig {
140138
emit_ir: false,
141139
emit_asm: false,
142140
emit_obj: EmitObj::None,
143-
no_integrated_as: false,
144141

145142
verify_llvm_ir: false,
146143
no_prepopulate_passes: false,
@@ -202,12 +199,6 @@ impl ModuleConfig {
202199
}
203200
}
204201

205-
/// Assembler name and command used by codegen when no_integrated_as is enabled
206-
pub struct AssemblerCommand {
207-
name: PathBuf,
208-
cmd: Command,
209-
}
210-
211202
// HACK(eddyb) work around `#[derive]` producing wrong bounds for `Clone`.
212203
pub struct TargetMachineFactory<B: WriteBackendMethods>(
213204
pub Arc<dyn Fn() -> Result<B::TargetMachine, String> + Send + Sync>,
@@ -260,8 +251,6 @@ pub struct CodegenContext<B: WriteBackendMethods> {
260251
pub cgu_reuse_tracker: CguReuseTracker,
261252
// Channel back to the main control thread to send messages to
262253
pub coordinator_send: Sender<Box<dyn Any + Send>>,
263-
// The assembler command if no_integrated_as option is enabled, None otherwise
264-
pub assembler_cmd: Option<Arc<AssemblerCommand>>,
265254
}
266255

267256
impl<B: WriteBackendMethods> CodegenContext<B> {
@@ -415,9 +404,6 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
415404

416405
modules_config.emit_pre_lto_bc = need_pre_lto_bitcode_for_incr_comp(sess);
417406

418-
modules_config.no_integrated_as =
419-
tcx.sess.opts.cg.no_integrated_as || tcx.sess.target.target.options.no_integrated_as;
420-
421407
for output_type in sess.opts.output_types.keys() {
422408
match *output_type {
423409
OutputType::Bitcode => {
@@ -1030,17 +1016,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
10301016
each_linked_rlib_for_lto.push((cnum, path.to_path_buf()));
10311017
}));
10321018

1033-
let assembler_cmd = if modules_config.no_integrated_as {
1034-
// HACK: currently we use linker (gcc) as our assembler
1035-
let (linker, flavor) = link::linker_and_flavor(sess);
1036-
1037-
let (name, mut cmd) = get_linker(sess, &linker, flavor);
1038-
cmd.args(&sess.target.target.options.asm_args);
1039-
Some(Arc::new(AssemblerCommand { name, cmd }))
1040-
} else {
1041-
None
1042-
};
1043-
10441019
let ol = if tcx.sess.opts.debugging_opts.no_codegen
10451020
|| !tcx.sess.opts.output_types.should_codegen()
10461021
{
@@ -1076,7 +1051,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
10761051
target_pointer_width: tcx.sess.target.target.target_pointer_width.clone(),
10771052
target_arch: tcx.sess.target.target.arch.clone(),
10781053
debuginfo: tcx.sess.opts.debuginfo,
1079-
assembler_cmd,
10801054
};
10811055

10821056
// This is the "main loop" of parallel work happening for parallel codegen.
@@ -1610,44 +1584,6 @@ fn spawn_work<B: ExtraBackendMethods>(cgcx: CodegenContext<B>, work: WorkItem<B>
16101584
});
16111585
}
16121586

1613-
pub fn run_assembler<B: ExtraBackendMethods>(
1614-
cgcx: &CodegenContext<B>,
1615-
handler: &Handler,
1616-
assembly: &Path,
1617-
object: &Path,
1618-
) {
1619-
let assembler = cgcx.assembler_cmd.as_ref().expect("cgcx.assembler_cmd is missing?");
1620-
1621-
let pname = &assembler.name;
1622-
let mut cmd = assembler.cmd.clone();
1623-
cmd.arg("-c").arg("-o").arg(object).arg(assembly);
1624-
debug!("{:?}", cmd);
1625-
1626-
match cmd.output() {
1627-
Ok(prog) => {
1628-
if !prog.status.success() {
1629-
let mut note = prog.stderr.clone();
1630-
note.extend_from_slice(&prog.stdout);
1631-
1632-
handler
1633-
.struct_err(&format!(
1634-
"linking with `{}` failed: {}",
1635-
pname.display(),
1636-
prog.status
1637-
))
1638-
.note(&format!("{:?}", &cmd))
1639-
.note(str::from_utf8(&note[..]).unwrap())
1640-
.emit();
1641-
handler.abort_if_errors();
1642-
}
1643-
}
1644-
Err(e) => {
1645-
handler.err(&format!("could not exec the linker `{}`: {}", pname.display(), e));
1646-
handler.abort_if_errors();
1647-
}
1648-
}
1649-
}
1650-
16511587
enum SharedEmitterMessage {
16521588
Diagnostic(Diagnostic),
16531589
InlineAsmError(u32, String),

src/librustc_expand/mbe/macro_rules.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ fn suggest_slice_pat(e: &mut DiagnosticBuilder<'_>, site_span: Span, parser: &Pa
8686
fn emit_frag_parse_err(
8787
mut e: DiagnosticBuilder<'_>,
8888
parser: &Parser<'_>,
89+
orig_parser: &mut Parser<'_>,
8990
site_span: Span,
9091
macro_ident: ast::Ident,
9192
arm_span: Span,
@@ -118,6 +119,21 @@ fn emit_frag_parse_err(
118119
AstFragmentKind::Pat if macro_ident.name == sym::vec => {
119120
suggest_slice_pat(&mut e, site_span, parser);
120121
}
122+
// Try a statement if an expression is wanted but failed and suggest adding `;` to call.
123+
AstFragmentKind::Expr => match parse_ast_fragment(orig_parser, AstFragmentKind::Stmts) {
124+
Err(mut err) => err.cancel(),
125+
Ok(_) => {
126+
e.note(
127+
"the macro call doesn't expand to an expression, but it can expand to a statement",
128+
);
129+
e.span_suggestion_verbose(
130+
site_span.shrink_to_hi(),
131+
"add `;` to interpret the expansion as a statement",
132+
";".to_string(),
133+
Applicability::MaybeIncorrect,
134+
);
135+
}
136+
},
121137
_ => annotate_err_with_kind(&mut e, kind, site_span),
122138
};
123139
e.emit();
@@ -126,10 +142,11 @@ fn emit_frag_parse_err(
126142
impl<'a> ParserAnyMacro<'a> {
127143
crate fn make(mut self: Box<ParserAnyMacro<'a>>, kind: AstFragmentKind) -> AstFragment {
128144
let ParserAnyMacro { site_span, macro_ident, ref mut parser, arm_span } = *self;
145+
let snapshot = &mut parser.clone();
129146
let fragment = match parse_ast_fragment(parser, kind) {
130147
Ok(f) => f,
131148
Err(err) => {
132-
emit_frag_parse_err(err, parser, site_span, macro_ident, arm_span, kind);
149+
emit_frag_parse_err(err, parser, snapshot, site_span, macro_ident, arm_span, kind);
133150
return kind.dummy(site_span);
134151
}
135152
};

src/librustc_hir/definitions.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,13 @@ impl Definitions {
353353
}
354354
}
355355

356-
// FIXME(eddyb) rename to `hir_id_to_node_id`.
357356
#[inline]
358-
pub fn hir_to_node_id(&self, hir_id: hir::HirId) -> ast::NodeId {
357+
pub fn hir_id_to_node_id(&self, hir_id: hir::HirId) -> ast::NodeId {
359358
self.hir_id_to_node_id[&hir_id]
360359
}
361360

362-
// FIXME(eddyb) rename to `node_id_to_hir_id`.
363361
#[inline]
364-
pub fn node_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
362+
pub fn node_id_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
365363
self.node_id_to_hir_id[node_id]
366364
}
367365

0 commit comments

Comments
 (0)