Skip to content

Commit e23dd66

Browse files
committed
Auto merge of #68474 - tmandry:rollup-6gmbet6, r=tmandry
Rollup of 10 pull requests Successful merges: - #67195 ([experiment] Add `-Z no-link` flag) - #68253 (add bare metal ARM Cortex-A targets to rustc) - #68361 (Unbreak linking with lld 9 on FreeBSD 13.0-CURRENT i386) - #68388 (Make `TooGeneric` error in WF checking a proper error) - #68409 (Micro-optimize OutputFilenames) - #68410 (Export weak symbols used by MemorySanitizer) - #68425 (Fix try-op diagnostic in E0277 for methods) - #68440 (bootstrap: update clippy subcmd decription) - #68441 (pprust: use as_deref) - #68462 (librustc_mir: don't allocate vectors where slices will do.) Failed merges: r? @ghost
2 parents d1e594f + bfac73c commit e23dd66

31 files changed

+388
-109
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3428,6 +3428,7 @@ dependencies = [
34283428
"rustc_session",
34293429
"rustc_span",
34303430
"rustc_target",
3431+
"serialize",
34313432
"smallvec 1.0.0",
34323433
"syntax",
34333434
]

src/bootstrap/flags.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Usage: x.py <subcommand> [options] [<paths>...]
104104
Subcommands:
105105
build Compile either the compiler or libraries
106106
check Compile either the compiler or libraries, using cargo check
107-
clippy Run clippy
107+
clippy Run clippy (uses rustup/cargo-installed clippy binary)
108108
fix Run cargo fix
109109
fmt Run rustfmt
110110
test Build and run some test suites

src/ci/docker/dist-various-1/Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ ENV TARGETS=$TARGETS,armebv7r-none-eabihf
160160
ENV TARGETS=$TARGETS,armv7r-none-eabi
161161
ENV TARGETS=$TARGETS,armv7r-none-eabihf
162162
ENV TARGETS=$TARGETS,thumbv7neon-unknown-linux-gnueabihf
163+
ENV TARGETS=$TARGETS,armv7a-none-eabi
163164

164165
# riscv targets currently do not need a C compiler, as compiler_builtins
165166
# doesn't currently have it enabled, and the riscv gcc compiler is not
@@ -173,6 +174,10 @@ ENV CC_mipsel_unknown_linux_musl=mipsel-openwrt-linux-gcc \
173174
CC_thumbv7neon_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc \
174175
AR_thumbv7neon_unknown_linux_gnueabihf=arm-linux-gnueabihf-ar \
175176
CXX_thumbv7neon_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ \
177+
CC_armv7a_none_eabi=arm-none-eabi-gcc \
178+
CC_armv7a_none_eabihf=arm-none-eabi-gcc \
179+
CFLAGS_armv7a_none_eabi=-march=armv7-a \
180+
CFLAGS_armv7a_none_eabihf=-march=armv7-a+vfpv3 \
176181
CC_riscv64gc_unknown_linux_gnu=riscv64-unknown-linux-gnu-gcc \
177182
AR_riscv64gc_unknown_linux_gnu=riscv64-unknown-linux-gnu-ar \
178183
CXX_riscv64gc_unknown_linux_gnu=riscv64-unknown-linux-gnu-g++ \

src/librustc/middle/cstore.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub use rustc_session::utils::NativeLibraryKind;
2727

2828
/// Where a crate came from on the local filesystem. One of these three options
2929
/// must be non-None.
30-
#[derive(PartialEq, Clone, Debug, HashStable)]
30+
#[derive(PartialEq, Clone, Debug, HashStable, RustcEncodable, RustcDecodable)]
3131
pub struct CrateSource {
3232
pub dylib: Option<(PathBuf, PathKind)>,
3333
pub rlib: Option<(PathBuf, PathKind)>,
@@ -75,7 +75,7 @@ impl DepKind {
7575
}
7676
}
7777

78-
#[derive(PartialEq, Clone, Debug)]
78+
#[derive(PartialEq, Clone, Debug, RustcEncodable, RustcDecodable)]
7979
pub enum LibSource {
8080
Some(PathBuf),
8181
MetadataOnly,
@@ -160,6 +160,7 @@ pub enum ExternCrateSource {
160160
Path,
161161
}
162162

163+
#[derive(RustcEncodable, RustcDecodable)]
163164
pub struct EncodedMetadata {
164165
pub raw_data: Vec<u8>,
165166
}

src/librustc/middle/dependency_format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub type DependencyList = Vec<Linkage>;
1919
/// This is local to the tcx, and is generally relevant to one session.
2020
pub type Dependencies = Vec<(config::CrateType, DependencyList)>;
2121

22-
#[derive(Copy, Clone, PartialEq, Debug, HashStable)]
22+
#[derive(Copy, Clone, PartialEq, Debug, HashStable, RustcEncodable, RustcDecodable)]
2323
pub enum Linkage {
2424
NotLinked,
2525
IncludedFromDylib,

src/librustc/traits/error_reporting/mod.rs

+23-11
Original file line numberDiff line numberDiff line change
@@ -919,17 +919,29 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
919919
report_object_safety_error(self.tcx, span, did, violations)
920920
}
921921

922-
// already reported in the query
923-
ConstEvalFailure(err) => {
924-
if let ErrorHandled::TooGeneric = err {
925-
// Silence this error, as it can be produced during intermediate steps
926-
// when a constant is not yet able to be evaluated (but will be later).
927-
return;
928-
}
929-
self.tcx.sess.delay_span_bug(
930-
span,
931-
&format!("constant in type had an ignored error: {:?}", err),
932-
);
922+
ConstEvalFailure(ErrorHandled::TooGeneric) => {
923+
// In this instance, we have a const expression containing an unevaluated
924+
// generic parameter. We have no idea whether this expression is valid or
925+
// not (e.g. it might result in an error), but we don't want to just assume
926+
// that it's okay, because that might result in post-monomorphisation time
927+
// errors. The onus is really on the caller to provide values that it can
928+
// prove are well-formed.
929+
let mut err = self
930+
.tcx
931+
.sess
932+
.struct_span_err(span, "constant expression depends on a generic parameter");
933+
// FIXME(const_generics): we should suggest to the user how they can resolve this
934+
// issue. However, this is currently not actually possible
935+
// (see https://github.com/rust-lang/rust/issues/66962#issuecomment-575907083).
936+
err.note("this may fail depending on what value the parameter takes");
937+
err
938+
}
939+
940+
// Already reported in the query.
941+
ConstEvalFailure(ErrorHandled::Reported) => {
942+
self.tcx
943+
.sess
944+
.delay_span_bug(span, &format!("constant in type had an ignored error"));
933945
return;
934946
}
935947

src/librustc/traits/error_reporting/on_unimplemented.rs

+34-20
Original file line numberDiff line numberDiff line change
@@ -59,31 +59,45 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
5959
fn describe_enclosure(&self, hir_id: hir::HirId) -> Option<&'static str> {
6060
let hir = &self.tcx.hir();
6161
let node = hir.find(hir_id)?;
62-
if let hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, _, body_id), .. }) = &node {
63-
self.describe_generator(*body_id).or_else(|| {
62+
match &node {
63+
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, _, body_id), .. }) => {
64+
self.describe_generator(*body_id).or_else(|| {
65+
Some(if let hir::FnHeader { asyncness: hir::IsAsync::Async, .. } = sig.header {
66+
"an async function"
67+
} else {
68+
"a function"
69+
})
70+
})
71+
}
72+
hir::Node::TraitItem(hir::TraitItem {
73+
kind: hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(body_id)),
74+
..
75+
}) => self.describe_generator(*body_id).or_else(|| Some("a trait method")),
76+
hir::Node::ImplItem(hir::ImplItem {
77+
kind: hir::ImplItemKind::Method(sig, body_id),
78+
..
79+
}) => self.describe_generator(*body_id).or_else(|| {
6480
Some(if let hir::FnHeader { asyncness: hir::IsAsync::Async, .. } = sig.header {
65-
"an async function"
81+
"an async method"
6682
} else {
67-
"a function"
83+
"a method"
6884
})
69-
})
70-
} else if let hir::Node::Expr(hir::Expr {
71-
kind: hir::ExprKind::Closure(_is_move, _, body_id, _, gen_movability),
72-
..
73-
}) = &node
74-
{
75-
self.describe_generator(*body_id).or_else(|| {
85+
}),
86+
hir::Node::Expr(hir::Expr {
87+
kind: hir::ExprKind::Closure(_is_move, _, body_id, _, gen_movability),
88+
..
89+
}) => self.describe_generator(*body_id).or_else(|| {
7690
Some(if gen_movability.is_some() { "an async closure" } else { "a closure" })
77-
})
78-
} else if let hir::Node::Expr(hir::Expr { .. }) = &node {
79-
let parent_hid = hir.get_parent_node(hir_id);
80-
if parent_hid != hir_id {
81-
return self.describe_enclosure(parent_hid);
82-
} else {
83-
None
91+
}),
92+
hir::Node::Expr(hir::Expr { .. }) => {
93+
let parent_hid = hir.get_parent_node(hir_id);
94+
if parent_hid != hir_id {
95+
return self.describe_enclosure(parent_hid);
96+
} else {
97+
None
98+
}
8499
}
85-
} else {
86-
None
100+
_ => None,
87101
}
88102
}
89103

src/librustc_codegen_llvm/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ rustc_incremental = { path = "../librustc_incremental" }
2828
rustc_index = { path = "../librustc_index" }
2929
rustc_llvm = { path = "../librustc_llvm" }
3030
rustc_session = { path = "../librustc_session" }
31+
rustc_serialize = { path = "../libserialize", package = "serialize" }
3132
rustc_target = { path = "../librustc_target" }
3233
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
3334
syntax = { path = "../libsyntax" }

src/librustc_codegen_llvm/lib.rs

+14
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use rustc_codegen_ssa::CompiledModule;
3333
use rustc_errors::{FatalError, Handler};
3434
use std::any::Any;
3535
use std::ffi::CStr;
36+
use std::fs;
3637
use std::sync::Arc;
3738
use syntax::expand::allocator::AllocatorKind;
3839

@@ -44,6 +45,7 @@ use rustc::ty::{self, TyCtxt};
4445
use rustc::util::common::ErrorReported;
4546
use rustc_codegen_ssa::ModuleCodegen;
4647
use rustc_codegen_utils::codegen_backend::CodegenBackend;
48+
use rustc_serialize::json;
4749

4850
mod back {
4951
pub mod archive;
@@ -298,6 +300,18 @@ impl CodegenBackend for LlvmCodegenBackend {
298300
return Ok(());
299301
}
300302

303+
if sess.opts.debugging_opts.no_link {
304+
// FIXME: use a binary format to encode the `.rlink` file
305+
let rlink_data = json::encode(&codegen_results).map_err(|err| {
306+
sess.fatal(&format!("failed to encode rlink: {}", err));
307+
})?;
308+
let rlink_file = outputs.with_extension("rlink");
309+
fs::write(&rlink_file, rlink_data).map_err(|err| {
310+
sess.fatal(&format!("failed to write file {}: {}", rlink_file.display(), err));
311+
})?;
312+
return Ok(());
313+
}
314+
301315
// Run the linker on any artifacts that resulted from the LLVM run.
302316
// This should produce either a finished executable or library.
303317
sess.time("link_crate", || {

src/librustc_codegen_ssa/back/linker.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc_target::spec::{LinkerFlavor, LldFlavor};
2020

2121
/// For all the linkers we support, and information they might
2222
/// need out of the shared crate context before we get rid of it.
23+
#[derive(RustcEncodable, RustcDecodable)]
2324
pub struct LinkerInfo {
2425
exports: FxHashMap<CrateType, Vec<String>>,
2526
}

src/librustc_codegen_ssa/back/symbol_export.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::Arc;
33

44
use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags;
55
use rustc::middle::exported_symbols::{metadata_symbol_name, ExportedSymbol, SymbolExportLevel};
6-
use rustc::session::config;
6+
use rustc::session::config::{self, Sanitizer};
77
use rustc::ty::query::Providers;
88
use rustc::ty::subst::SubstsRef;
99
use rustc::ty::Instance;
@@ -206,6 +206,16 @@ fn exported_symbols_provider_local(
206206
}));
207207
}
208208

209+
if let Some(Sanitizer::Memory) = tcx.sess.opts.debugging_opts.sanitizer {
210+
// Similar to profiling, preserve weak msan symbol during LTO.
211+
const MSAN_WEAK_SYMBOLS: [&str; 2] = ["__msan_track_origins", "__msan_keep_going"];
212+
213+
symbols.extend(MSAN_WEAK_SYMBOLS.iter().map(|sym| {
214+
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(sym));
215+
(exported_symbol, SymbolExportLevel::C)
216+
}));
217+
}
218+
209219
if tcx.sess.crate_types.borrow().contains(&config::CrateType::Dylib) {
210220
let symbol_name = metadata_symbol_name(tcx);
211221
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(&symbol_name));

src/librustc_codegen_ssa/lib.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<M> ModuleCodegen<M> {
8787
}
8888
}
8989

90-
#[derive(Debug)]
90+
#[derive(Debug, RustcEncodable, RustcDecodable)]
9191
pub struct CompiledModule {
9292
pub name: String,
9393
pub kind: ModuleKind,
@@ -101,7 +101,7 @@ pub struct CachedModuleCodegen {
101101
pub source: WorkProduct,
102102
}
103103

104-
#[derive(Copy, Clone, Debug, PartialEq)]
104+
#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
105105
pub enum ModuleKind {
106106
Regular,
107107
Metadata,
@@ -117,7 +117,14 @@ bitflags::bitflags! {
117117
}
118118

119119
/// Misc info we load from metadata to persist beyond the tcx.
120-
#[derive(Debug)]
120+
///
121+
/// Note: though `CrateNum` is only meaningful within the same tcx, information within `CrateInfo`
122+
/// is self-contained. `CrateNum` can be viewed as a unique identifier within a `CrateInfo`, where
123+
/// `used_crate_source` contains all `CrateSource` of the dependents, and maintains a mapping from
124+
/// identifiers (`CrateNum`) to `CrateSource`. The other fields map `CrateNum` to the crate's own
125+
/// additional properties, so that effectively we can retrieve each dependent crate's `CrateSource`
126+
/// and the corresponding properties without referencing information outside of a `CrateInfo`.
127+
#[derive(Debug, RustcEncodable, RustcDecodable)]
121128
pub struct CrateInfo {
122129
pub panic_runtime: Option<CrateNum>,
123130
pub compiler_builtins: Option<CrateNum>,
@@ -135,6 +142,7 @@ pub struct CrateInfo {
135142
pub dependency_formats: Lrc<Dependencies>,
136143
}
137144

145+
#[derive(RustcEncodable, RustcDecodable)]
138146
pub struct CodegenResults {
139147
pub crate_name: Symbol,
140148
pub modules: Vec<CompiledModule>,

src/librustc_hir/def_id.rs

+29-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use rustc_data_structures::AtomicRef;
22
use rustc_index::vec::Idx;
3+
use rustc_serialize::{Decoder, Encoder};
34
use std::fmt;
4-
use std::u32;
5+
use std::{u32, u64};
56

67
rustc_index::newtype_index! {
78
pub struct CrateId {
@@ -86,8 +87,18 @@ impl fmt::Display for CrateNum {
8687
}
8788
}
8889

89-
impl rustc_serialize::UseSpecializedEncodable for CrateNum {}
90-
impl rustc_serialize::UseSpecializedDecodable for CrateNum {}
90+
/// As a local identifier, a `CrateNum` is only meaningful within its context, e.g. within a tcx.
91+
/// Therefore, make sure to include the context when encode a `CrateNum`.
92+
impl rustc_serialize::UseSpecializedEncodable for CrateNum {
93+
fn default_encode<E: Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
94+
e.emit_u32(self.as_u32())
95+
}
96+
}
97+
impl rustc_serialize::UseSpecializedDecodable for CrateNum {
98+
fn default_decode<D: Decoder>(d: &mut D) -> Result<CrateNum, D::Error> {
99+
Ok(CrateNum::from_u32(d.read_u32()?))
100+
}
101+
}
91102

92103
rustc_index::newtype_index! {
93104
/// A DefIndex is an index into the hir-map for a crate, identifying a
@@ -135,8 +146,21 @@ impl DefId {
135146
}
136147
}
137148

138-
impl rustc_serialize::UseSpecializedEncodable for DefId {}
139-
impl rustc_serialize::UseSpecializedDecodable for DefId {}
149+
impl rustc_serialize::UseSpecializedEncodable for DefId {
150+
fn default_encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
151+
let krate = u64::from(self.krate.as_u32());
152+
let index = u64::from(self.index.as_u32());
153+
s.emit_u64((krate << 32) | index)
154+
}
155+
}
156+
impl rustc_serialize::UseSpecializedDecodable for DefId {
157+
fn default_decode<D: Decoder>(d: &mut D) -> Result<DefId, D::Error> {
158+
let def_id = d.read_u64()?;
159+
let krate = CrateNum::from_u32((def_id >> 32) as u32);
160+
let index = DefIndex::from_u32((def_id & 0xffffffff) as u32);
161+
Ok(DefId { krate, index })
162+
}
163+
}
140164

141165
pub fn default_def_id_debug(def_id: DefId, f: &mut fmt::Formatter<'_>) -> fmt::Result {
142166
f.debug_struct("DefId").field("krate", &def_id.krate).field("index", &def_id.index).finish()

src/librustc_interface/util.rs

+14-19
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,13 @@ pub fn build_output_filenames(
550550
.or_else(|| attr::find_crate_name(attrs).map(|n| n.to_string()))
551551
.unwrap_or_else(|| input.filestem().to_owned());
552552

553-
OutputFilenames {
554-
out_directory: dirpath,
555-
out_filestem: stem,
556-
single_output_file: None,
557-
extra: sess.opts.cg.extra_filename.clone(),
558-
outputs: sess.opts.output_types.clone(),
559-
}
553+
OutputFilenames::new(
554+
dirpath,
555+
stem,
556+
None,
557+
sess.opts.cg.extra_filename.clone(),
558+
sess.opts.output_types.clone(),
559+
)
560560
}
561561

562562
Some(ref out_file) => {
@@ -578,18 +578,13 @@ pub fn build_output_filenames(
578578
sess.warn("ignoring --out-dir flag due to -o flag");
579579
}
580580

581-
OutputFilenames {
582-
out_directory: out_file.parent().unwrap_or_else(|| Path::new("")).to_path_buf(),
583-
out_filestem: out_file
584-
.file_stem()
585-
.unwrap_or_default()
586-
.to_str()
587-
.unwrap()
588-
.to_string(),
589-
single_output_file: ofile,
590-
extra: sess.opts.cg.extra_filename.clone(),
591-
outputs: sess.opts.output_types.clone(),
592-
}
581+
OutputFilenames::new(
582+
out_file.parent().unwrap_or_else(|| Path::new("")).to_path_buf(),
583+
out_file.file_stem().unwrap_or_default().to_str().unwrap().to_string(),
584+
ofile,
585+
sess.opts.cg.extra_filename.clone(),
586+
sess.opts.output_types.clone(),
587+
)
593588
}
594589
}
595590
}

0 commit comments

Comments
 (0)