Skip to content

Commit

Permalink
Auto merge of rust-lang#122117 - matthiaskrgr:rollup-3yrv3j6, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#122015 (Add better explanation for `rustc_index::IndexVec`)
 - rust-lang#122061 (Clarify FatalErrorHandler)
 - rust-lang#122062 (Explicitly assign constructed C++ classes)
 - rust-lang#122072 (Refer to "slice" instead of "vector" in Ord and PartialOrd trait impl of slices)
 - rust-lang#122088 (Remove unnecessary fixme on new thread stack size)
 - rust-lang#122094 (Remove outdated footnote "missing-stack-probe" in platform-support)
 - rust-lang#122107 (Temporarily make allow-by-default the `non_local_definitions` lint)
 - rust-lang#122109 (compiletest: Add a `//@ needs-threads` directive)

Failed merges:

 - rust-lang#122104 (Rust is a proper name: rust → Rust)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Mar 7, 2024
2 parents 7d3702e + 5642b04 commit d03b986
Show file tree
Hide file tree
Showing 93 changed files with 279 additions and 200 deletions.
19 changes: 18 additions & 1 deletion compiler/rustc_index/src/vec.rs
Expand Up @@ -12,7 +12,24 @@ use std::vec;
use crate::{Idx, IndexSlice};

/// An owned contiguous collection of `T`s, indexed by `I` rather than by `usize`.
/// Its purpose is to avoid mixing indexes.
///
/// ## Why use this instead of a `Vec`?
///
/// An `IndexVec` allows element access only via a specific associated index type, meaning that
/// trying to use the wrong index type (possibly accessing an invalid element) will fail at
/// compile time.
///
/// It also documents what the index is indexing: in a `HashMap<usize, Something>` it's not
/// immediately clear what the `usize` means, while a `HashMap<FieldIdx, Something>` makes it obvious.
///
/// ```compile_fail
/// use rustc_index::{Idx, IndexVec};
///
/// fn f<I1: Idx, I2: Idx>(vec1: IndexVec<I1, u8>, idx1: I1, idx2: I2) {
/// &vec1[idx1]; // Ok
/// &vec1[idx2]; // Compile error!
/// }
/// ```
///
/// While it's possible to use `u32` or `usize` directly for `I`,
/// you almost certainly want to use a [`newtype_index!`]-generated type instead.
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_lint/src/non_local_def.rs
Expand Up @@ -14,6 +14,7 @@ declare_lint! {
/// ### Example
///
/// ```rust
/// #![warn(non_local_definitions)]
/// trait MyTrait {}
/// struct MyStruct;
///
Expand All @@ -36,7 +37,7 @@ declare_lint! {
/// All nested bodies (functions, enum discriminant, array length, consts) (expect for
/// `const _: Ty = { ... }` in top-level module, which is still undecided) are checked.
pub NON_LOCAL_DEFINITIONS,
Warn,
Allow,
"checks for non-local definitions",
report_in_external_macro
}
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp
Expand Up @@ -120,7 +120,7 @@ extern "C" void LLVMRustCoverageWriteFilenamesSectionToBuffer(
}
auto FilenamesWriter =
coverage::CoverageFilenamesSectionWriter(ArrayRef<std::string>(FilenameRefs));
RawRustStringOstream OS(BufferOut);
auto OS = RawRustStringOstream(BufferOut);
FilenamesWriter.write(OS);
}

Expand Down Expand Up @@ -160,31 +160,31 @@ extern "C" void LLVMRustCoverageWriteMappingToBuffer(
ArrayRef<unsigned>(VirtualFileMappingIDs, NumVirtualFileMappingIDs),
Expressions,
MappingRegions);
RawRustStringOstream OS(BufferOut);
auto OS = RawRustStringOstream(BufferOut);
CoverageMappingWriter.write(OS);
}

extern "C" LLVMValueRef LLVMRustCoverageCreatePGOFuncNameVar(
LLVMValueRef F,
const char *FuncName,
size_t FuncNameLen) {
StringRef FuncNameRef(FuncName, FuncNameLen);
auto FuncNameRef = StringRef(FuncName, FuncNameLen);
return wrap(createPGOFuncNameVar(*cast<Function>(unwrap(F)), FuncNameRef));
}

extern "C" uint64_t LLVMRustCoverageHashByteArray(
const char *Bytes,
size_t NumBytes) {
StringRef StrRef(Bytes, NumBytes);
auto StrRef = StringRef(Bytes, NumBytes);
return IndexedInstrProf::ComputeHash(StrRef);
}

static void WriteSectionNameToString(LLVMModuleRef M,
InstrProfSectKind SK,
RustStringRef Str) {
Triple TargetTriple(unwrap(M)->getTargetTriple());
auto TargetTriple = Triple(unwrap(M)->getTargetTriple());
auto name = getInstrProfSectionName(SK, TargetTriple.getObjectFormat());
RawRustStringOstream OS(Str);
auto OS = RawRustStringOstream(Str);
OS << name;
}

Expand All @@ -200,7 +200,7 @@ extern "C" void LLVMRustCoverageWriteFuncSectionNameToString(LLVMModuleRef M,

extern "C" void LLVMRustCoverageWriteMappingVarNameToString(RustStringRef Str) {
auto name = getCoverageMappingVarName();
RawRustStringOstream OS(Str);
auto OS = RawRustStringOstream(Str);
OS << name;
}

Expand Down
42 changes: 21 additions & 21 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Expand Up @@ -77,9 +77,9 @@ extern "C" void LLVMRustTimeTraceProfilerFinishThread() {
}

extern "C" void LLVMRustTimeTraceProfilerFinish(const char* FileName) {
StringRef FN(FileName);
auto FN = StringRef(FileName);
std::error_code EC;
raw_fd_ostream OS(FN, EC, sys::fs::CD_CreateAlways);
auto OS = raw_fd_ostream(FN, EC, sys::fs::CD_CreateAlways);

timeTraceProfilerWrite(OS);
timeTraceProfilerCleanup();
Expand Down Expand Up @@ -424,7 +424,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
auto CM = fromRust(RustCM);

std::string Error;
Triple Trip(Triple::normalize(TripleStr));
auto Trip = Triple(Triple::normalize(TripleStr));
const llvm::Target *TheTarget =
TargetRegistry::lookupTarget(Trip.getTriple(), Error);
if (TheTarget == nullptr) {
Expand Down Expand Up @@ -537,8 +537,8 @@ extern "C" void LLVMRustDisposeTargetMachine(LLVMTargetMachineRef TM) {
// TargetLibraryInfo pass, so we use this method to do so.
extern "C" void LLVMRustAddLibraryInfo(LLVMPassManagerRef PMR, LLVMModuleRef M,
bool DisableSimplifyLibCalls) {
Triple TargetTriple(unwrap(M)->getTargetTriple());
TargetLibraryInfoImpl TLII(TargetTriple);
auto TargetTriple = Triple(unwrap(M)->getTargetTriple());
auto TLII = TargetLibraryInfoImpl(TargetTriple);
if (DisableSimplifyLibCalls)
TLII.disableAllFunctions();
unwrap(PMR)->add(new TargetLibraryInfoWrapperPass(TLII));
Expand Down Expand Up @@ -589,25 +589,25 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target, LLVMPassManagerRef PMR,

std::string ErrorInfo;
std::error_code EC;
raw_fd_ostream OS(Path, EC, sys::fs::OF_None);
auto OS = raw_fd_ostream(Path, EC, sys::fs::OF_None);
if (EC)
ErrorInfo = EC.message();
if (ErrorInfo != "") {
LLVMRustSetLastError(ErrorInfo.c_str());
return LLVMRustResult::Failure;
}

buffer_ostream BOS(OS);
auto BOS = buffer_ostream(OS);
if (DwoPath) {
raw_fd_ostream DOS(DwoPath, EC, sys::fs::OF_None);
auto DOS = raw_fd_ostream(DwoPath, EC, sys::fs::OF_None);
EC.clear();
if (EC)
ErrorInfo = EC.message();
if (ErrorInfo != "") {
LLVMRustSetLastError(ErrorInfo.c_str());
return LLVMRustResult::Failure;
}
buffer_ostream DBOS(DOS);
auto DBOS = buffer_ostream(DOS);
unwrap(Target)->addPassesToEmitFile(*PM, BOS, &DBOS, FileType, false);
PM->run(*unwrap(M));
} else {
Expand Down Expand Up @@ -796,7 +796,7 @@ LLVMRustOptimize(
DebugInfoForProfiling);
}

PassBuilder PB(TM, PTO, PGOOpt, &PIC);
auto PB = PassBuilder(TM, PTO, PGOOpt, &PIC);
LoopAnalysisManager LAM;
FunctionAnalysisManager FAM;
CGSCCAnalysisManager CGAM;
Expand Down Expand Up @@ -1112,16 +1112,16 @@ extern "C" LLVMRustResult
LLVMRustPrintModule(LLVMModuleRef M, const char *Path, DemangleFn Demangle) {
std::string ErrorInfo;
std::error_code EC;
raw_fd_ostream OS(Path, EC, sys::fs::OF_None);
auto OS = raw_fd_ostream(Path, EC, sys::fs::OF_None);
if (EC)
ErrorInfo = EC.message();
if (ErrorInfo != "") {
LLVMRustSetLastError(ErrorInfo.c_str());
return LLVMRustResult::Failure;
}

RustAssemblyAnnotationWriter AAW(Demangle);
formatted_raw_ostream FOS(OS);
auto AAW = RustAssemblyAnnotationWriter(Demangle);
auto FOS = formatted_raw_ostream(OS);
unwrap(M)->print(FOS, &AAW);

return LLVMRustResult::Success;
Expand Down Expand Up @@ -1281,8 +1281,8 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
// Load each module's summary and merge it into one combined index
for (int i = 0; i < num_modules; i++) {
auto module = &modules[i];
StringRef buffer(module->data, module->len);
MemoryBufferRef mem_buffer(buffer, module->identifier);
auto buffer = StringRef(module->data, module->len);
auto mem_buffer = MemoryBufferRef(buffer, module->identifier);

Ret->ModuleMap[module->identifier] = mem_buffer;

Expand Down Expand Up @@ -1485,7 +1485,7 @@ LLVMRustPrepareThinLTOImport(const LLVMRustThinLTOData *Data, LLVMModuleRef M,
return MOrErr;
};
bool ClearDSOLocal = clearDSOLocalOnDeclarations(Mod, Target);
FunctionImporter Importer(Data->Index, Loader, ClearDSOLocal);
auto Importer = FunctionImporter(Data->Index, Loader, ClearDSOLocal);
Expected<bool> Result = Importer.importFunctions(Mod, ImportList);
if (!Result) {
LLVMRustSetLastError(toString(Result.takeError()).c_str());
Expand All @@ -1510,7 +1510,7 @@ extern "C" LLVMRustThinLTOBuffer*
LLVMRustThinLTOBufferCreate(LLVMModuleRef M, bool is_thin) {
auto Ret = std::make_unique<LLVMRustThinLTOBuffer>();
{
raw_string_ostream OS(Ret->data);
auto OS = raw_string_ostream(Ret->data);
{
if (is_thin) {
PassBuilder PB;
Expand Down Expand Up @@ -1557,8 +1557,8 @@ LLVMRustParseBitcodeForLTO(LLVMContextRef Context,
const char *data,
size_t len,
const char *identifier) {
StringRef Data(data, len);
MemoryBufferRef Buffer(Data, identifier);
auto Data = StringRef(data, len);
auto Buffer = MemoryBufferRef(Data, identifier);
unwrap(Context)->enableDebugTypeODRUniquing();
Expected<std::unique_ptr<Module>> SrcOrError =
parseBitcodeFile(Buffer, *unwrap(Context));
Expand All @@ -1576,8 +1576,8 @@ extern "C" const char *LLVMRustGetSliceFromObjectDataByName(const char *data,
const char *name,
size_t *out_len) {
*out_len = 0;
StringRef Data(data, len);
MemoryBufferRef Buffer(Data, ""); // The id is unused.
auto Data = StringRef(data, len);
auto Buffer = MemoryBufferRef(Data, ""); // The id is unused.
file_magic Type = identify_magic(Buffer.getBuffer());
Expected<std::unique_ptr<object::ObjectFile>> ObjFileOrError =
object::ObjectFile::createObjectFile(Buffer, Type);
Expand Down

0 comments on commit d03b986

Please sign in to comment.