Skip to content

Commit 1812f60

Browse files
committed
Auto merge of rust-lang#2773 - RalfJung:rustup, r=RalfJung
Rustup
2 parents 0aaa9ea + 40cbe49 commit 1812f60

File tree

726 files changed

+4742
-4020
lines changed

Some content is hidden

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

726 files changed

+4742
-4020
lines changed

.github/ISSUE_TEMPLATE/ice.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
name: Internal Compiler Error
3+
about: Create a report for an internal compiler error in rustc.
4+
labels: C-bug, I-ICE, T-compiler
5+
---
6+
<!--
7+
Thank you for finding an Internal Compiler Error! 🧊 If possible, try to provide
8+
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
9+
how to create smaller examples.
10+
http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/
11+
-->
12+
13+
### Code
14+
15+
```Rust
16+
<code>
17+
```
18+
19+
20+
### Meta
21+
<!--
22+
If you're using the stable version of the compiler, you should also check if the
23+
bug also exists in the beta or nightly versions.
24+
-->
25+
26+
`rustc --version --verbose`:
27+
```
28+
<version>
29+
```
30+
31+
### Error output
32+
33+
```
34+
<output>
35+
```
36+
37+
<!--
38+
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
39+
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
40+
-->
41+
<details><summary><strong>Backtrace</strong></summary>
42+
<p>
43+
44+
```
45+
<backtrace>
46+
```
47+
48+
</p>
49+
</details>

.github/ISSUE_TEMPLATE/ice.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name: Internal Compiler Error
2-
description: Create a report for an internal compiler error in `rustc`
1+
name: Internal Compiler Error (Structured form)
2+
description: For now, you'll want to use the other ICE template, as GitHub forms have strict limits on the size of fields so backtraces cannot be pasted directly.
33
labels: ["C-bug", "I-ICE", "T-compiler"]
44
title: "[ICE]: "
55
body:
@@ -79,4 +79,4 @@ body:
7979
label: Anything else?
8080
description: If you have more details you want to give us to reproduce this issue, please add it here
8181
validations:
82-
required: false
82+
required: false

Cargo.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ dependencies = [
342342

343343
[[package]]
344344
name = "cargo"
345-
version = "0.69.0"
345+
version = "0.70.0"
346346
dependencies = [
347347
"anyhow",
348348
"base64",

compiler/rustc_abi/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,8 @@ pub enum PointerKind {
14561456
UniqueOwned,
14571457
}
14581458

1459+
/// Note that this information is advisory only, and backends are free to ignore it.
1460+
/// It can only be used to encode potential optimizations, but no critical information.
14591461
#[derive(Copy, Clone, Debug)]
14601462
pub struct PointeeInfo {
14611463
pub size: Size,

compiler/rustc_ast/src/util/comments.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,24 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
5858
// In case we have doc comments like `/**` or `/*!`, we want to remove stars if they are
5959
// present. However, we first need to strip the empty lines so they don't get in the middle
6060
// when we try to compute the "horizontal trim".
61-
let lines = if kind == CommentKind::Block {
62-
// Whatever happens, we skip the first line.
63-
let mut i = lines
64-
.get(0)
65-
.map(|l| if l.trim_start().starts_with('*') { 0 } else { 1 })
66-
.unwrap_or(0);
67-
let mut j = lines.len();
68-
69-
while i < j && lines[i].trim().is_empty() {
70-
i += 1;
71-
}
72-
while j > i && lines[j - 1].trim().is_empty() {
73-
j -= 1;
61+
let lines = match kind {
62+
CommentKind::Block => {
63+
// Whatever happens, we skip the first line.
64+
let mut i = lines
65+
.get(0)
66+
.map(|l| if l.trim_start().starts_with('*') { 0 } else { 1 })
67+
.unwrap_or(0);
68+
let mut j = lines.len();
69+
70+
while i < j && lines[i].trim().is_empty() {
71+
i += 1;
72+
}
73+
while j > i && lines[j - 1].trim().is_empty() {
74+
j -= 1;
75+
}
76+
&lines[i..j]
7477
}
75-
&lines[i..j]
76-
} else {
77-
lines
78+
CommentKind::Line => lines,
7879
};
7980

8081
for line in lines {

compiler/rustc_ast_pretty/src/pprust/state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub fn print_crate<'a>(
131131

132132
// Currently, in Rust 2018 we don't have `extern crate std;` at the crate
133133
// root, so this is not needed, and actually breaks things.
134-
if edition == Edition::Edition2015 {
134+
if edition.rust_2015() {
135135
// `#![no_std]`
136136
let fake_attr = attr::mk_attr_word(g, ast::AttrStyle::Inner, sym::no_std, DUMMY_SP);
137137
s.print_attribute(&fake_attr);

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
344344
} else {
345345
err.span_help(source_info.span, "try removing `&mut` here");
346346
}
347-
} else if decl.mutability == Mutability::Not {
347+
} else if decl.mutability.is_not() {
348348
if matches!(
349349
decl.local_info,
350350
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::ImplicitSelf(

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+6
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ impl Display for RegionName {
187187
}
188188
}
189189

190+
impl rustc_errors::IntoDiagnosticArg for RegionName {
191+
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
192+
self.to_string().into_diagnostic_arg()
193+
}
194+
}
195+
190196
impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
191197
pub(crate) fn mir_def_id(&self) -> hir::def_id::LocalDefId {
192198
self.body.source.def_id().expect_local()

compiler/rustc_borrowck/src/nll.rs

+2
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ pub(super) fn dump_mir_results<'tcx>(
369369
};
370370
}
371371

372+
#[allow(rustc::diagnostic_outside_of_impl)]
373+
#[allow(rustc::untranslatable_diagnostic)]
372374
pub(super) fn dump_annotation<'tcx>(
373375
infcx: &InferCtxt<'tcx>,
374376
body: &Body<'tcx>,

compiler/rustc_borrowck/src/session_diagnostics.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_errors::{IntoDiagnosticArg, MultiSpan};
1+
use rustc_errors::MultiSpan;
22
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
33
use rustc_middle::ty::{GenericArg, Ty};
44
use rustc_span::Span;
@@ -128,18 +128,6 @@ pub(crate) enum LifetimeReturnCategoryErr<'a> {
128128
},
129129
}
130130

131-
impl IntoDiagnosticArg for &RegionName {
132-
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
133-
format!("{}", self).into_diagnostic_arg()
134-
}
135-
}
136-
137-
impl IntoDiagnosticArg for RegionName {
138-
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
139-
format!("{}", self).into_diagnostic_arg()
140-
}
141-
}
142-
143131
#[derive(Subdiagnostic)]
144132
pub(crate) enum RequireStaticErr {
145133
#[note(borrowck_used_impl_require_static)]

compiler/rustc_borrowck/src/type_check/canonical.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
181181
user_ty: ty::UserType<'tcx>,
182182
span: Span,
183183
) {
184-
// FIXME: Ideally MIR types are normalized, but this is not always true.
185-
let mir_ty = self.normalize(mir_ty, Locations::All(span));
186-
187184
self.fully_perform_op(
188185
Locations::All(span),
189186
ConstraintCategory::Boring,
@@ -217,7 +214,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
217214
return;
218215
}
219216

217+
// FIXME: Ideally MIR types are normalized, but this is not always true.
220218
let mir_ty = self.normalize(mir_ty, Locations::All(span));
219+
221220
let cause = ObligationCause::dummy_with_span(span);
222221
let param_env = self.param_env;
223222
let op = |infcx: &'_ _| {

compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20282028
}
20292029
};
20302030

2031-
if ty_to_mut == Mutability::Mut && ty_mut == Mutability::Not {
2031+
if ty_to_mut.is_mut() && ty_mut.is_not() {
20322032
span_mirbug!(
20332033
self,
20342034
rvalue,

compiler/rustc_codegen_gcc/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ unsafe impl Sync for GccContext {}
200200
impl WriteBackendMethods for GccCodegenBackend {
201201
type Module = GccContext;
202202
type TargetMachine = ();
203+
type TargetMachineError = ();
203204
type ModuleBuffer = ModuleBuffer;
204205
type ThinData = ();
205206
type ThinBuffer = ThinBuffer;

compiler/rustc_codegen_llvm/src/back/lto.rs

+28-37
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::back::write::{self, save_temp_bitcode, DiagnosticHandlers};
2-
use crate::errors::DynamicLinkingWithLTO;
2+
use crate::errors::{
3+
DynamicLinkingWithLTO, LlvmError, LtoBitcodeFromRlib, LtoDisallowed, LtoDylib,
4+
};
35
use crate::llvm::{self, build_string};
46
use crate::{LlvmCodegenBackend, ModuleLlvm};
57
use object::read::archive::ArchiveFile;
@@ -77,15 +79,12 @@ fn prepare_lto(
7779
// Make sure we actually can run LTO
7880
for crate_type in cgcx.crate_types.iter() {
7981
if !crate_type_allows_lto(*crate_type) {
80-
let e = diag_handler.fatal(
81-
"lto can only be run for executables, cdylibs and \
82-
static library outputs",
83-
);
84-
return Err(e);
82+
diag_handler.emit_err(LtoDisallowed);
83+
return Err(FatalError);
8584
} else if *crate_type == CrateType::Dylib {
8685
if !cgcx.opts.unstable_opts.dylib_lto {
87-
return Err(diag_handler
88-
.fatal("lto cannot be used for `dylib` crate type without `-Zdylib-lto`"));
86+
diag_handler.emit_err(LtoDylib);
87+
return Err(FatalError);
8988
}
9089
}
9190
}
@@ -127,7 +126,10 @@ fn prepare_lto(
127126
let module = SerializedModule::FromRlib(data.to_vec());
128127
upstream_modules.push((module, CString::new(name).unwrap()));
129128
}
130-
Err(msg) => return Err(diag_handler.fatal(&msg)),
129+
Err(e) => {
130+
diag_handler.emit_err(e);
131+
return Err(FatalError);
132+
}
131133
}
132134
}
133135
}
@@ -140,7 +142,7 @@ fn prepare_lto(
140142
Ok((symbols_below_threshold, upstream_modules))
141143
}
142144

143-
fn get_bitcode_slice_from_object_data(obj: &[u8]) -> Result<&[u8], String> {
145+
fn get_bitcode_slice_from_object_data(obj: &[u8]) -> Result<&[u8], LtoBitcodeFromRlib> {
144146
let mut len = 0;
145147
let data =
146148
unsafe { llvm::LLVMRustGetBitcodeSliceFromObjectData(obj.as_ptr(), obj.len(), &mut len) };
@@ -155,8 +157,9 @@ fn get_bitcode_slice_from_object_data(obj: &[u8]) -> Result<&[u8], String> {
155157
Ok(bc)
156158
} else {
157159
assert!(len == 0);
158-
let msg = llvm::last_error().unwrap_or_else(|| "unknown LLVM error".to_string());
159-
Err(format!("failed to get bitcode from object file for LTO ({})", msg))
160+
Err(LtoBitcodeFromRlib {
161+
llvm_err: llvm::last_error().unwrap_or_else(|| "unknown LLVM error".to_string()),
162+
})
160163
}
161164
}
162165

@@ -328,10 +331,9 @@ fn fat_lto(
328331
});
329332
info!("linking {:?}", name);
330333
let data = bc_decoded.data();
331-
linker.add(data).map_err(|()| {
332-
let msg = format!("failed to load bitcode of module {:?}", name);
333-
write::llvm_err(diag_handler, &msg)
334-
})?;
334+
linker
335+
.add(data)
336+
.map_err(|()| write::llvm_err(diag_handler, LlvmError::LoadBitcode { name }))?;
335337
serialized_bitcode.push(bc_decoded);
336338
}
337339
drop(linker);
@@ -489,7 +491,7 @@ fn thin_lto(
489491
symbols_below_threshold.as_ptr(),
490492
symbols_below_threshold.len() as u32,
491493
)
492-
.ok_or_else(|| write::llvm_err(diag_handler, "failed to prepare thin LTO context"))?;
494+
.ok_or_else(|| write::llvm_err(diag_handler, LlvmError::PrepareThinLtoContext))?;
493495

494496
let data = ThinData(data);
495497

@@ -562,8 +564,7 @@ fn thin_lto(
562564
// session, overwriting the previous serialized data (if any).
563565
if let Some(path) = key_map_path {
564566
if let Err(err) = curr_key_map.save_to_file(&path) {
565-
let msg = format!("Error while writing ThinLTO key data: {}", err);
566-
return Err(write::llvm_err(diag_handler, &msg));
567+
return Err(write::llvm_err(diag_handler, LlvmError::WriteThinLtoKey { err }));
567568
}
568569
}
569570

@@ -689,8 +690,7 @@ pub unsafe fn optimize_thin_module(
689690

690691
let module_name = &thin_module.shared.module_names[thin_module.idx];
691692
let tm_factory_config = TargetMachineFactoryConfig::new(cgcx, module_name.to_str().unwrap());
692-
let tm =
693-
(cgcx.tm_factory)(tm_factory_config).map_err(|e| write::llvm_err(&diag_handler, &e))?;
693+
let tm = (cgcx.tm_factory)(tm_factory_config).map_err(|e| write::llvm_err(&diag_handler, e))?;
694694

695695
// Right now the implementation we've got only works over serialized
696696
// modules, so we create a fresh new LLVM context and parse the module
@@ -717,8 +717,7 @@ pub unsafe fn optimize_thin_module(
717717
let mut cu2 = ptr::null_mut();
718718
llvm::LLVMRustThinLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2);
719719
if !cu2.is_null() {
720-
let msg = "multiple source DICompileUnits found";
721-
return Err(write::llvm_err(&diag_handler, msg));
720+
return Err(write::llvm_err(&diag_handler, LlvmError::MultipleSourceDiCompileUnit));
722721
}
723722

724723
// Up next comes the per-module local analyses that we do for Thin LTO.
@@ -733,8 +732,7 @@ pub unsafe fn optimize_thin_module(
733732
let _timer =
734733
cgcx.prof.generic_activity_with_arg("LLVM_thin_lto_rename", thin_module.name());
735734
if !llvm::LLVMRustPrepareThinLTORename(thin_module.shared.data.0, llmod, target) {
736-
let msg = "failed to prepare thin LTO module";
737-
return Err(write::llvm_err(&diag_handler, msg));
735+
return Err(write::llvm_err(&diag_handler, LlvmError::PrepareThinLtoModule));
738736
}
739737
save_temp_bitcode(cgcx, &module, "thin-lto-after-rename");
740738
}
@@ -744,8 +742,7 @@ pub unsafe fn optimize_thin_module(
744742
.prof
745743
.generic_activity_with_arg("LLVM_thin_lto_resolve_weak", thin_module.name());
746744
if !llvm::LLVMRustPrepareThinLTOResolveWeak(thin_module.shared.data.0, llmod) {
747-
let msg = "failed to prepare thin LTO module";
748-
return Err(write::llvm_err(&diag_handler, msg));
745+
return Err(write::llvm_err(&diag_handler, LlvmError::PrepareThinLtoModule));
749746
}
750747
save_temp_bitcode(cgcx, &module, "thin-lto-after-resolve");
751748
}
@@ -755,8 +752,7 @@ pub unsafe fn optimize_thin_module(
755752
.prof
756753
.generic_activity_with_arg("LLVM_thin_lto_internalize", thin_module.name());
757754
if !llvm::LLVMRustPrepareThinLTOInternalize(thin_module.shared.data.0, llmod) {
758-
let msg = "failed to prepare thin LTO module";
759-
return Err(write::llvm_err(&diag_handler, msg));
755+
return Err(write::llvm_err(&diag_handler, LlvmError::PrepareThinLtoModule));
760756
}
761757
save_temp_bitcode(cgcx, &module, "thin-lto-after-internalize");
762758
}
@@ -765,8 +761,7 @@ pub unsafe fn optimize_thin_module(
765761
let _timer =
766762
cgcx.prof.generic_activity_with_arg("LLVM_thin_lto_import", thin_module.name());
767763
if !llvm::LLVMRustPrepareThinLTOImport(thin_module.shared.data.0, llmod, target) {
768-
let msg = "failed to prepare thin LTO module";
769-
return Err(write::llvm_err(&diag_handler, msg));
764+
return Err(write::llvm_err(&diag_handler, LlvmError::PrepareThinLtoModule));
770765
}
771766
save_temp_bitcode(cgcx, &module, "thin-lto-after-import");
772767
}
@@ -886,11 +881,7 @@ pub fn parse_module<'a>(
886881
diag_handler: &Handler,
887882
) -> Result<&'a llvm::Module, FatalError> {
888883
unsafe {
889-
llvm::LLVMRustParseBitcodeForLTO(cx, data.as_ptr(), data.len(), name.as_ptr()).ok_or_else(
890-
|| {
891-
let msg = "failed to parse bitcode for LTO module";
892-
write::llvm_err(diag_handler, msg)
893-
},
894-
)
884+
llvm::LLVMRustParseBitcodeForLTO(cx, data.as_ptr(), data.len(), name.as_ptr())
885+
.ok_or_else(|| write::llvm_err(diag_handler, LlvmError::ParseBitcode))
895886
}
896887
}

0 commit comments

Comments
 (0)