Skip to content

Commit 9d0ae58

Browse files
committed
Auto merge of #70351 - Centril:rollup-tveoq3w, r=Centril
Rollup of 8 pull requests Successful merges: - #68884 (Make the `type_of` return a generic type for generators) - #69788 (Fix sequence of Type and Trait in optin-builtin-traits in Unstable Book) - #70074 (Expand: nix all fatal errors) - #70077 (Store idents for `DefPathData` into crate metadata) - #70213 (traits/fulfill: allow `stalled_on` to track `ty::Const::Infer(_)` (unused yet).) - #70259 (Use Reveal::All in MIR optimizations) - #70284 (correctly handle const params in type_of) - #70289 (Refactor `codegen`) Failed merges: r? @ghost
2 parents 342c5f3 + 170112c commit 9d0ae58

File tree

126 files changed

+1527
-654
lines changed

Some content is hidden

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

126 files changed

+1527
-654
lines changed

src/doc/unstable-book/src/language-features/optin-builtin-traits.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ has explicitly opted out via a negative impl.
1616
[`Sync`]: https://doc.rust-lang.org/std/marker/trait.Sync.html
1717

1818
```rust,ignore
19-
impl !Type for Trait
19+
impl !Trait for Type
2020
```
2121

2222
Example:

src/librustc_builtin_macros/cmdline_attrs.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use rustc_ast::ast::{self, AttrItem, AttrStyle};
44
use rustc_ast::attr::mk_attr;
55
use rustc_ast::token;
6-
use rustc_expand::panictry;
76
use rustc_session::parse::ParseSess;
87
use rustc_span::FileName;
98

@@ -16,7 +15,13 @@ pub fn inject(mut krate: ast::Crate, parse_sess: &ParseSess, attrs: &[String]) -
1615
);
1716

1817
let start_span = parser.token.span;
19-
let AttrItem { path, args } = panictry!(parser.parse_attr_item());
18+
let AttrItem { path, args } = match parser.parse_attr_item() {
19+
Ok(ai) => ai,
20+
Err(mut err) => {
21+
err.emit();
22+
continue;
23+
}
24+
};
2025
let end_span = parser.token.span;
2126
if parser.token != token::Eof {
2227
parse_sess.span_diagnostic.span_err(start_span.to(end_span), "invalid crate attribute");

src/librustc_builtin_macros/source_util.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc_ast::tokenstream::TokenStream;
55
use rustc_ast_pretty::pprust;
66
use rustc_expand::base::{self, *};
77
use rustc_expand::module::DirectoryOwnership;
8-
use rustc_expand::panictry;
98
use rustc_parse::{self, new_parser_from_file, parser::Parser};
109
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
1110
use rustc_span::symbol::Symbol;
@@ -126,7 +125,7 @@ pub fn expand_include<'cx>(
126125
}
127126
impl<'a> base::MacResult for ExpandResult<'a> {
128127
fn make_expr(mut self: Box<ExpandResult<'a>>) -> Option<P<ast::Expr>> {
129-
let r = panictry!(self.p.parse_expr());
128+
let r = base::parse_expr(&mut self.p)?;
130129
if self.p.token != token::Eof {
131130
self.p.sess.buffer_lint(
132131
&INCOMPLETE_INCLUDE,
@@ -141,18 +140,17 @@ pub fn expand_include<'cx>(
141140
fn make_items(mut self: Box<ExpandResult<'a>>) -> Option<SmallVec<[P<ast::Item>; 1]>> {
142141
let mut ret = SmallVec::new();
143142
while self.p.token != token::Eof {
144-
match panictry!(self.p.parse_item()) {
145-
Some(item) => ret.push(item),
146-
None => {
143+
match self.p.parse_item() {
144+
Err(mut err) => {
145+
err.emit();
146+
break;
147+
}
148+
Ok(Some(item)) => ret.push(item),
149+
Ok(None) => {
147150
let token = pprust::token_to_string(&self.p.token);
148-
self.p
149-
.sess
150-
.span_diagnostic
151-
.span_fatal(
152-
self.p.token.span,
153-
&format!("expected item, found `{}`", token),
154-
)
155-
.raise();
151+
let msg = format!("expected item, found `{}`", token);
152+
self.p.struct_span_err(self.p.token.span, &msg).emit();
153+
break;
156154
}
157155
}
158156
}

src/librustc_builtin_macros/test.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ pub fn expand_test_or_bench(
7474
return vec![];
7575
}
7676

77-
let item = if let Annotatable::Item(i) = item {
78-
i
79-
} else {
80-
cx.parse_sess
81-
.span_diagnostic
82-
.span_fatal(
83-
item.span(),
77+
let item = match item {
78+
Annotatable::Item(i) => i,
79+
other => {
80+
cx.struct_span_err(
81+
other.span(),
8482
"`#[test]` attribute is only allowed on non associated functions",
8583
)
86-
.raise();
84+
.emit();
85+
return vec![other];
86+
}
8787
};
8888

8989
if let ast::ItemKind::MacCall(_) = item.kind {

src/librustc_builtin_macros/test_harness.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,14 @@ fn is_test_case(i: &ast::Item) -> bool {
345345

346346
fn get_test_runner(sd: &rustc_errors::Handler, krate: &ast::Crate) -> Option<ast::Path> {
347347
let test_attr = attr::find_by_name(&krate.attrs, sym::test_runner)?;
348-
test_attr.meta_item_list().map(|meta_list| {
349-
if meta_list.len() != 1 {
350-
sd.span_fatal(test_attr.span, "`#![test_runner(..)]` accepts exactly 1 argument")
351-
.raise()
352-
}
353-
match meta_list[0].meta_item() {
354-
Some(meta_item) if meta_item.is_word() => meta_item.path.clone(),
355-
_ => sd.span_fatal(test_attr.span, "`test_runner` argument must be a path").raise(),
356-
}
357-
})
348+
let meta_list = test_attr.meta_item_list()?;
349+
let span = test_attr.span;
350+
match &*meta_list {
351+
[single] => match single.meta_item() {
352+
Some(meta_item) if meta_item.is_word() => return Some(meta_item.path.clone()),
353+
_ => sd.struct_span_err(span, "`test_runner` argument must be a path").emit(),
354+
},
355+
_ => sd.struct_span_err(span, "`#![test_runner(..)]` accepts exactly 1 argument").emit(),
356+
}
357+
None
358358
}

src/librustc_codegen_llvm/back/write.rs

+82-92
Original file line numberDiff line numberDiff line change
@@ -16,7 +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::{run_assembler, CodegenContext, ModuleConfig};
19+
use rustc_codegen_ssa::back::write::{run_assembler, CodegenContext, EmbedBitcode, ModuleConfig};
2020
use rustc_codegen_ssa::traits::*;
2121
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen, RLIB_BYTECODE_EXTENSION};
2222
use rustc_data_structures::small_c_str::SmallCStr;
@@ -634,30 +634,24 @@ pub(crate) unsafe fn codegen(
634634
f(cpm)
635635
}
636636

637-
// If we don't have the integrated assembler, then we need to emit asm
638-
// from LLVM and use `gcc` to create the object file.
639-
let asm_to_obj = config.emit_obj && config.no_integrated_as;
640-
641-
// Change what we write and cleanup based on whether obj files are
642-
// just llvm bitcode. In that case write bitcode, and possibly
643-
// delete the bitcode if it wasn't requested. Don't generate the
644-
// machine code, instead copy the .o file from the .bc
645-
let write_bc = config.emit_bc || config.obj_is_bitcode;
646-
let rm_bc = !config.emit_bc && config.obj_is_bitcode;
647-
let write_obj = config.emit_obj && !config.obj_is_bitcode && !asm_to_obj;
648-
let copy_bc_to_obj = config.emit_obj && config.obj_is_bitcode;
637+
// Two things to note:
638+
// - If object files are just LLVM bitcode we write bitcode, copy it to
639+
// the .o file, and delete the bitcode if it wasn't otherwise
640+
// requested.
641+
// - If we don't have the integrated assembler then we need to emit
642+
// asm from LLVM and use `gcc` to create the object file.
649643

650644
let bc_out = cgcx.output_filenames.temp_path(OutputType::Bitcode, module_name);
651645
let obj_out = cgcx.output_filenames.temp_path(OutputType::Object, module_name);
652646

653-
if write_bc || config.emit_bc_compressed || config.embed_bitcode {
647+
if config.bitcode_needed() {
654648
let _timer = cgcx
655649
.prof
656650
.generic_activity_with_arg("LLVM_module_codegen_make_bitcode", &module.name[..]);
657651
let thin = ThinBuffer::new(llmod);
658652
let data = thin.data();
659653

660-
if write_bc {
654+
if config.emit_bc || config.obj_is_bitcode {
661655
let _timer = cgcx.prof.generic_activity_with_arg(
662656
"LLVM_module_codegen_emit_bitcode",
663657
&module.name[..],
@@ -668,7 +662,7 @@ pub(crate) unsafe fn codegen(
668662
}
669663
}
670664

671-
if config.embed_bitcode {
665+
if config.embed_bitcode == EmbedBitcode::Full {
672666
let _timer = cgcx.prof.generic_activity_with_arg(
673667
"LLVM_module_codegen_embed_bitcode",
674668
&module.name[..],
@@ -688,81 +682,75 @@ pub(crate) unsafe fn codegen(
688682
diag_handler.err(&msg);
689683
}
690684
}
691-
} else if config.embed_bitcode_marker {
685+
} else if config.embed_bitcode == EmbedBitcode::Marker {
692686
embed_bitcode(cgcx, llcx, llmod, None);
693687
}
694688

695-
{
696-
if config.emit_ir {
697-
let _timer = cgcx
698-
.prof
699-
.generic_activity_with_arg("LLVM_module_codegen_emit_ir", &module.name[..]);
700-
let out = cgcx.output_filenames.temp_path(OutputType::LlvmAssembly, module_name);
701-
let out_c = path_to_c_string(&out);
702-
703-
extern "C" fn demangle_callback(
704-
input_ptr: *const c_char,
705-
input_len: size_t,
706-
output_ptr: *mut c_char,
707-
output_len: size_t,
708-
) -> size_t {
709-
let input = unsafe {
710-
slice::from_raw_parts(input_ptr as *const u8, input_len as usize)
711-
};
712-
713-
let input = match str::from_utf8(input) {
714-
Ok(s) => s,
715-
Err(_) => return 0,
716-
};
717-
718-
let output = unsafe {
719-
slice::from_raw_parts_mut(output_ptr as *mut u8, output_len as usize)
720-
};
721-
let mut cursor = io::Cursor::new(output);
722-
723-
let demangled = match rustc_demangle::try_demangle(input) {
724-
Ok(d) => d,
725-
Err(_) => return 0,
726-
};
727-
728-
if write!(cursor, "{:#}", demangled).is_err() {
729-
// Possible only if provided buffer is not big enough
730-
return 0;
731-
}
732-
733-
cursor.position() as size_t
689+
if config.emit_ir {
690+
let _timer = cgcx
691+
.prof
692+
.generic_activity_with_arg("LLVM_module_codegen_emit_ir", &module.name[..]);
693+
let out = cgcx.output_filenames.temp_path(OutputType::LlvmAssembly, module_name);
694+
let out_c = path_to_c_string(&out);
695+
696+
extern "C" fn demangle_callback(
697+
input_ptr: *const c_char,
698+
input_len: size_t,
699+
output_ptr: *mut c_char,
700+
output_len: size_t,
701+
) -> size_t {
702+
let input =
703+
unsafe { slice::from_raw_parts(input_ptr as *const u8, input_len as usize) };
704+
705+
let input = match str::from_utf8(input) {
706+
Ok(s) => s,
707+
Err(_) => return 0,
708+
};
709+
710+
let output = unsafe {
711+
slice::from_raw_parts_mut(output_ptr as *mut u8, output_len as usize)
712+
};
713+
let mut cursor = io::Cursor::new(output);
714+
715+
let demangled = match rustc_demangle::try_demangle(input) {
716+
Ok(d) => d,
717+
Err(_) => return 0,
718+
};
719+
720+
if write!(cursor, "{:#}", demangled).is_err() {
721+
// Possible only if provided buffer is not big enough
722+
return 0;
734723
}
735724

736-
let result = llvm::LLVMRustPrintModule(llmod, out_c.as_ptr(), demangle_callback);
737-
result.into_result().map_err(|()| {
738-
let msg = format!("failed to write LLVM IR to {}", out.display());
739-
llvm_err(diag_handler, &msg)
740-
})?;
725+
cursor.position() as size_t
741726
}
742727

743-
if config.emit_asm || asm_to_obj {
744-
let _timer = cgcx
745-
.prof
746-
.generic_activity_with_arg("LLVM_module_codegen_emit_asm", &module.name[..]);
747-
let path = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name);
728+
let result = llvm::LLVMRustPrintModule(llmod, out_c.as_ptr(), demangle_callback);
729+
result.into_result().map_err(|()| {
730+
let msg = format!("failed to write LLVM IR to {}", out.display());
731+
llvm_err(diag_handler, &msg)
732+
})?;
733+
}
748734

749-
// We can't use the same module for asm and binary output, because that triggers
750-
// various errors like invalid IR or broken binaries, so we might have to clone the
751-
// module to produce the asm output
752-
let llmod = if config.emit_obj { llvm::LLVMCloneModule(llmod) } else { llmod };
753-
with_codegen(tm, llmod, config.no_builtins, |cpm| {
754-
write_output_file(
755-
diag_handler,
756-
tm,
757-
cpm,
758-
llmod,
759-
&path,
760-
llvm::FileType::AssemblyFile,
761-
)
762-
})?;
763-
}
735+
let config_emit_normal_obj = config.emit_obj && !config.obj_is_bitcode;
764736

765-
if write_obj {
737+
if config.emit_asm || (config_emit_normal_obj && config.no_integrated_as) {
738+
let _timer = cgcx
739+
.prof
740+
.generic_activity_with_arg("LLVM_module_codegen_emit_asm", &module.name[..]);
741+
let path = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name);
742+
743+
// We can't use the same module for asm and binary output, because that triggers
744+
// various errors like invalid IR or broken binaries, so we might have to clone the
745+
// module to produce the asm output
746+
let llmod = if config.emit_obj { llvm::LLVMCloneModule(llmod) } else { llmod };
747+
with_codegen(tm, llmod, config.no_builtins, |cpm| {
748+
write_output_file(diag_handler, tm, cpm, llmod, &path, llvm::FileType::AssemblyFile)
749+
})?;
750+
}
751+
752+
if config_emit_normal_obj {
753+
if !config.no_integrated_as {
766754
let _timer = cgcx
767755
.prof
768756
.generic_activity_with_arg("LLVM_module_codegen_emit_obj", &module.name[..]);
@@ -776,7 +764,7 @@ pub(crate) unsafe fn codegen(
776764
llvm::FileType::ObjectFile,
777765
)
778766
})?;
779-
} else if asm_to_obj {
767+
} else {
780768
let _timer = cgcx
781769
.prof
782770
.generic_activity_with_arg("LLVM_module_codegen_asm_to_obj", &module.name[..]);
@@ -789,17 +777,19 @@ pub(crate) unsafe fn codegen(
789777
}
790778
}
791779

792-
if copy_bc_to_obj {
793-
debug!("copying bitcode {:?} to obj {:?}", bc_out, obj_out);
794-
if let Err(e) = link_or_copy(&bc_out, &obj_out) {
795-
diag_handler.err(&format!("failed to copy bitcode to object file: {}", e));
780+
if config.obj_is_bitcode {
781+
if config.emit_obj {
782+
debug!("copying bitcode {:?} to obj {:?}", bc_out, obj_out);
783+
if let Err(e) = link_or_copy(&bc_out, &obj_out) {
784+
diag_handler.err(&format!("failed to copy bitcode to object file: {}", e));
785+
}
796786
}
797-
}
798787

799-
if rm_bc {
800-
debug!("removing_bitcode {:?}", bc_out);
801-
if let Err(e) = fs::remove_file(&bc_out) {
802-
diag_handler.err(&format!("failed to remove bitcode: {}", e));
788+
if !config.emit_bc {
789+
debug!("removing_bitcode {:?}", bc_out);
790+
if let Err(e) = fs::remove_file(&bc_out) {
791+
diag_handler.err(&format!("failed to remove bitcode: {}", e));
792+
}
803793
}
804794
}
805795

0 commit comments

Comments
 (0)