From 23623a08d6a181864a7b8609682eee27534b12f4 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Tue, 5 Mar 2024 20:04:24 -0800 Subject: Explicitly assign constructed C++ classes C++ style guides I am aware of recommend specifically preferring = syntax for any classes with fairly obvious constructors[^0] that do not perform any complicated logic in their constructor. I contend that all constructors that the `rustc_llvm` code uses qualify. This has only become more common since C++ 17 guaranteed many cases of copy initialization elision. The other detail is that I tried to ask another contributor with infinitely more C++ experience than me (i.e. any) what this constructor syntax was, and they thought it was a macro. I know of no other language that has adopted this same syntax. As the rustc codebase features many contributors experienced in many other languages, using a less... unique... style has many other benefits in making this code more lucid and maintainable, which is something it direly needs. [^0]: e.g. https://abseil.io/tips/88 --- .../rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp') diff --git a/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp index 627be997513..60789b07e54 100644 --- a/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp @@ -120,7 +120,7 @@ extern "C" void LLVMRustCoverageWriteFilenamesSectionToBuffer( } auto FilenamesWriter = coverage::CoverageFilenamesSectionWriter(ArrayRef(FilenameRefs)); - RawRustStringOstream OS(BufferOut); + auto OS = RawRustStringOstream(BufferOut); FilenamesWriter.write(OS); } @@ -160,7 +160,7 @@ extern "C" void LLVMRustCoverageWriteMappingToBuffer( ArrayRef(VirtualFileMappingIDs, NumVirtualFileMappingIDs), Expressions, MappingRegions); - RawRustStringOstream OS(BufferOut); + auto OS = RawRustStringOstream(BufferOut); CoverageMappingWriter.write(OS); } @@ -168,23 +168,23 @@ 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(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; } @@ -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; } -- cgit 1.4.1-3-g733a5