Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #88774

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1f5568d
Emit proper errors when on missing closure braces
Aug 16, 2021
3bdda1c
Fix grammatical error in error message
Sep 1, 2021
eabe41c
Fix misplaced match arm
Sep 1, 2021
e8e76b7
Put the expr error inside the closure body
Sep 1, 2021
dbe56f4
Add ruby-style closure ui tests
Sep 1, 2021
733bdd0
fix(rustc): suggest `items` be borrowed in `for i in items[x..]`
notriddle Sep 2, 2021
f23003d
fix(test): update with `&mut` suggestion
notriddle Sep 2, 2021
3a334a0
Add comment about ruby_style_closure status
Sep 2, 2021
191bb83
Put some notes in a separate note block
Sep 3, 2021
1beee86
Merge branch 'master' into scrabsha/closure-missing-braces
Sep 3, 2021
41ac2c6
Fix merge imports
Sep 3, 2021
4107396
Group closure-related spans in a structure
Sep 3, 2021
208a5fd
Use `summary_opts()` for Markdown summaries
camelid Sep 4, 2021
2cc7b7c
Enable all main body Markdown options for summaries
camelid Sep 4, 2021
e9e8b61
Rename clo -> closure
Sep 4, 2021
f91161d
last_closure_body -> current_closure
Sep 4, 2021
99c46c0
Slightly reword the error message
Sep 6, 2021
4a915ac
fix ICE on hidden tuple variant fields
Emilgardis Sep 4, 2021
d6ff916
test: add case for mutating iterator
notriddle Sep 7, 2021
532bb80
RustWrapper: avoid deleted unclear attribute methods
durin42 Sep 7, 2021
484b79b
RustWrapper: just use the *AtIndex funcs directly
durin42 Sep 7, 2021
4d04540
RustWrapper: remove some uses of AttrBuilder
durin42 Sep 8, 2021
8549598
Improve error when an .rlib can't be parsed
jyn514 Aug 26, 2021
c86c634
Allow missing code examples in trait impls.
hnj2 Sep 8, 2021
e8342de
Rollup merge of #88368 - jyn514:metadata-error, r=petrochenkov
GuillaumeGomez Sep 9, 2021
09de880
Rollup merge of #88546 - scrabsha:scrabsha/closure-missing-braces, r=…
GuillaumeGomez Sep 9, 2021
2471041
Rollup merge of #88578 - notriddle:notriddle/suggest-add-reference-to…
GuillaumeGomez Sep 9, 2021
ff0f5f9
Rollup merge of #88632 - camelid:md-opts, r=CraftSpider
GuillaumeGomez Sep 9, 2021
fa7834a
Rollup merge of #88639 - Emilgardis:fix-issue-88600, r=GuillaumeGomez
GuillaumeGomez Sep 9, 2021
f31ac61
Rollup merge of #88732 - durin42:llvm-14-attrs-2, r=nikic
GuillaumeGomez Sep 9, 2021
26a98a7
Rollup merge of #88745 - hnj2:allow-trait-impl-missing-code, r=Guilla…
GuillaumeGomez Sep 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ E0782: include_str!("./error_codes/E0782.md"),
E0783: include_str!("./error_codes/E0783.md"),
E0784: include_str!("./error_codes/E0784.md"),
E0785: include_str!("./error_codes/E0785.md"),
E0786: include_str!("./error_codes/E0786.md"),
;
// E0006, // merged with E0005
// E0008, // cannot bind by-move into a pattern guard
Expand Down
14 changes: 14 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0786.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
A metadata file was invalid.

Erroneous code example:

```ignore (needs extern files)
use ::foo; // error: found invalid metadata files for crate `foo`
```

When loading crates, each crate must have a valid metadata file.
Invalid files could be caused by filesystem corruption,
an IO error while reading the file, or (rarely) a bug in the compiler itself.

Consider deleting the file and recreating it,
or reporting a bug against the compiler.
56 changes: 31 additions & 25 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,56 +203,57 @@ static Attribute::AttrKind fromRust(LLVMRustAttribute Kind) {
report_fatal_error("bad AttributeKind");
}

template<typename T> static inline void AddAttribute(T *t, unsigned Index, Attribute Attr) {
#if LLVM_VERSION_LT(14, 0)
t->addAttribute(Index, Attr);
#else
t->addAttributeAtIndex(Index, Attr);
#endif
}

extern "C" void LLVMRustAddCallSiteAttribute(LLVMValueRef Instr, unsigned Index,
LLVMRustAttribute RustAttr) {
CallBase *Call = unwrap<CallBase>(Instr);
Attribute Attr = Attribute::get(Call->getContext(), fromRust(RustAttr));
Call->addAttribute(Index, Attr);
AddAttribute(Call, Index, Attr);
}

extern "C" void LLVMRustAddCallSiteAttrString(LLVMValueRef Instr, unsigned Index,
const char *Name) {
CallBase *Call = unwrap<CallBase>(Instr);
Attribute Attr = Attribute::get(Call->getContext(), Name);
Call->addAttribute(Index, Attr);
AddAttribute(Call, Index, Attr);
}


extern "C" void LLVMRustAddAlignmentCallSiteAttr(LLVMValueRef Instr,
unsigned Index,
uint32_t Bytes) {
CallBase *Call = unwrap<CallBase>(Instr);
AttrBuilder B;
B.addAlignmentAttr(Bytes);
Call->setAttributes(Call->getAttributes().addAttributes(
Call->getContext(), Index, B));
Attribute Attr = Attribute::getWithAlignment(Call->getContext(), Align(Bytes));
AddAttribute(Call, Index, Attr);
}

extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr,
unsigned Index,
uint64_t Bytes) {
CallBase *Call = unwrap<CallBase>(Instr);
AttrBuilder B;
B.addDereferenceableAttr(Bytes);
Call->setAttributes(Call->getAttributes().addAttributes(
Call->getContext(), Index, B));
Attribute Attr = Attribute::getWithDereferenceableBytes(Call->getContext(), Bytes);
AddAttribute(Call, Index, Attr);
}

extern "C" void LLVMRustAddDereferenceableOrNullCallSiteAttr(LLVMValueRef Instr,
unsigned Index,
uint64_t Bytes) {
CallBase *Call = unwrap<CallBase>(Instr);
AttrBuilder B;
B.addDereferenceableOrNullAttr(Bytes);
Call->setAttributes(Call->getAttributes().addAttributes(
Call->getContext(), Index, B));
Attribute Attr = Attribute::getWithDereferenceableOrNullBytes(Call->getContext(), Bytes);
AddAttribute(Call, Index, Attr);
}

extern "C" void LLVMRustAddByValCallSiteAttr(LLVMValueRef Instr, unsigned Index,
LLVMTypeRef Ty) {
CallBase *Call = unwrap<CallBase>(Instr);
Attribute Attr = Attribute::getWithByValType(Call->getContext(), unwrap(Ty));
Call->addAttribute(Index, Attr);
AddAttribute(Call, Index, Attr);
}

extern "C" void LLVMRustAddStructRetCallSiteAttr(LLVMValueRef Instr, unsigned Index,
Expand All @@ -263,44 +264,44 @@ extern "C" void LLVMRustAddStructRetCallSiteAttr(LLVMValueRef Instr, unsigned In
#else
Attribute Attr = Attribute::get(Call->getContext(), Attribute::StructRet);
#endif
Call->addAttribute(Index, Attr);
AddAttribute(Call, Index, Attr);
}

extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned Index,
LLVMRustAttribute RustAttr) {
Function *A = unwrap<Function>(Fn);
Attribute Attr = Attribute::get(A->getContext(), fromRust(RustAttr));
A->addAttribute(Index, Attr);
AddAttribute(A, Index, Attr);
}

extern "C" void LLVMRustAddAlignmentAttr(LLVMValueRef Fn,
unsigned Index,
uint32_t Bytes) {
Function *A = unwrap<Function>(Fn);
A->addAttribute(Index, Attribute::getWithAlignment(
AddAttribute(A, Index, Attribute::getWithAlignment(
A->getContext(), llvm::Align(Bytes)));
}

extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index,
uint64_t Bytes) {
Function *A = unwrap<Function>(Fn);
A->addAttribute(Index, Attribute::getWithDereferenceableBytes(A->getContext(),
AddAttribute(A, Index, Attribute::getWithDereferenceableBytes(A->getContext(),
Bytes));
}

extern "C" void LLVMRustAddDereferenceableOrNullAttr(LLVMValueRef Fn,
unsigned Index,
uint64_t Bytes) {
Function *A = unwrap<Function>(Fn);
A->addAttribute(Index, Attribute::getWithDereferenceableOrNullBytes(
AddAttribute(A, Index, Attribute::getWithDereferenceableOrNullBytes(
A->getContext(), Bytes));
}

extern "C" void LLVMRustAddByValAttr(LLVMValueRef Fn, unsigned Index,
LLVMTypeRef Ty) {
Function *F = unwrap<Function>(Fn);
Attribute Attr = Attribute::getWithByValType(F->getContext(), unwrap(Ty));
F->addAttribute(Index, Attr);
AddAttribute(F, Index, Attr);
}

extern "C" void LLVMRustAddStructRetAttr(LLVMValueRef Fn, unsigned Index,
Expand All @@ -311,15 +312,15 @@ extern "C" void LLVMRustAddStructRetAttr(LLVMValueRef Fn, unsigned Index,
#else
Attribute Attr = Attribute::get(F->getContext(), Attribute::StructRet);
#endif
F->addAttribute(Index, Attr);
AddAttribute(F, Index, Attr);
}

extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn,
unsigned Index,
const char *Name,
const char *Value) {
Function *F = unwrap<Function>(Fn);
F->addAttribute(Index, Attribute::get(
AddAttribute(F, Index, Attribute::get(
F->getContext(), StringRef(Name), StringRef(Value)));
}

Expand All @@ -330,7 +331,12 @@ extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn,
Attribute Attr = Attribute::get(F->getContext(), fromRust(RustAttr));
AttrBuilder B(Attr);
auto PAL = F->getAttributes();
auto PALNew = PAL.removeAttributes(F->getContext(), Index, B);
AttributeList PALNew;
#if LLVM_VERSION_LT(14, 0)
PALNew = PAL.removeAttributes(F->getContext(), Index, B);
#else
PALNew = PAL.removeAttributesAtIndex(F->getContext(), Index, B);
#endif
F->setAttributes(PALNew);
}

Expand Down
89 changes: 74 additions & 15 deletions compiler/rustc_metadata/src/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ impl<'a> CrateLocator<'a> {
self.crate_rejections.via_kind.clear();
self.crate_rejections.via_version.clear();
self.crate_rejections.via_filename.clear();
self.crate_rejections.via_invalid.clear();
}

crate fn maybe_load_library_crate(&mut self) -> Result<Option<Library>, CrateError> {
Expand Down Expand Up @@ -538,7 +539,16 @@ impl<'a> CrateLocator<'a> {
continue;
}
}
Err(err) => {
Err(MetadataError::LoadFailure(err)) => {
// The file was present and created by the same compiler version, but we
// couldn't load it for some reason. Give a hard error instead of silently
// ignoring it, but only if we would have given an error anyway.
self.crate_rejections
.via_invalid
.push(CrateMismatch { path: lib, got: err });
continue;
}
Err(err @ MetadataError::NotPresent(_)) => {
warn!("no metadata found: {}", err);
continue;
}
Expand Down Expand Up @@ -716,25 +726,28 @@ impl<'a> CrateLocator<'a> {
fn get_metadata_section(
target: &Target,
flavor: CrateFlavor,
filename: &Path,
filename: &'p Path,
loader: &dyn MetadataLoader,
) -> Result<MetadataBlob, String> {
) -> Result<MetadataBlob, MetadataError<'p>> {
if !filename.exists() {
return Err(format!("no such file: '{}'", filename.display()));
return Err(MetadataError::NotPresent(filename));
}
let raw_bytes: MetadataRef = match flavor {
CrateFlavor::Rlib => loader.get_rlib_metadata(target, filename)?,
CrateFlavor::Rlib => {
loader.get_rlib_metadata(target, filename).map_err(MetadataError::LoadFailure)?
}
CrateFlavor::Dylib => {
let buf = loader.get_dylib_metadata(target, filename)?;
let buf =
loader.get_dylib_metadata(target, filename).map_err(MetadataError::LoadFailure)?;
// The header is uncompressed
let header_len = METADATA_HEADER.len();
debug!("checking {} bytes of metadata-version stamp", header_len);
let header = &buf[..cmp::min(header_len, buf.len())];
if header != METADATA_HEADER {
return Err(format!(
"incompatible metadata version found: '{}'",
return Err(MetadataError::LoadFailure(format!(
"invalid metadata version found: {}",
filename.display()
));
)));
}

// Header is okay -> inflate the actual metadata
Expand All @@ -744,17 +757,28 @@ fn get_metadata_section(
match FrameDecoder::new(compressed_bytes).read_to_end(&mut inflated) {
Ok(_) => rustc_erase_owner!(OwningRef::new(inflated).map_owner_box()),
Err(_) => {
return Err(format!("failed to decompress metadata: {}", filename.display()));
return Err(MetadataError::LoadFailure(format!(
"failed to decompress metadata: {}",
filename.display()
)));
}
}
}
CrateFlavor::Rmeta => {
// mmap the file, because only a small fraction of it is read.
let file = std::fs::File::open(filename)
.map_err(|_| format!("failed to open rmeta metadata: '{}'", filename.display()))?;
let file = std::fs::File::open(filename).map_err(|_| {
MetadataError::LoadFailure(format!(
"failed to open rmeta metadata: '{}'",
filename.display()
))
})?;
let mmap = unsafe { Mmap::map(file) };
let mmap = mmap
.map_err(|_| format!("failed to mmap rmeta metadata: '{}'", filename.display()))?;
let mmap = mmap.map_err(|_| {
MetadataError::LoadFailure(format!(
"failed to mmap rmeta metadata: '{}'",
filename.display()
))
})?;

rustc_erase_owner!(OwningRef::new(mmap).map_owner_box())
}
Expand All @@ -763,7 +787,10 @@ fn get_metadata_section(
if blob.is_compatible() {
Ok(blob)
} else {
Err(format!("incompatible metadata version found: '{}'", filename.display()))
Err(MetadataError::LoadFailure(format!(
"invalid metadata version found: {}",
filename.display()
)))
}
}

Expand Down Expand Up @@ -842,6 +869,7 @@ struct CrateRejections {
via_kind: Vec<CrateMismatch>,
via_version: Vec<CrateMismatch>,
via_filename: Vec<CrateMismatch>,
via_invalid: Vec<CrateMismatch>,
}

/// Candidate rejection reasons collected during crate search.
Expand Down Expand Up @@ -871,6 +899,24 @@ crate enum CrateError {
NonDylibPlugin(Symbol),
}

enum MetadataError<'a> {
/// The file was missing.
NotPresent(&'a Path),
/// The file was present and invalid.
LoadFailure(String),
}

impl fmt::Display for MetadataError<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
MetadataError::NotPresent(filename) => {
f.write_str(&format!("no such file: '{}'", filename.display()))
}
MetadataError::LoadFailure(msg) => f.write_str(msg),
}
}
}

impl CrateError {
crate fn report(self, sess: &Session, span: Span, missing_core: bool) -> ! {
let mut err = match self {
Expand Down Expand Up @@ -1044,6 +1090,19 @@ impl CrateError {
}
err.note(&msg);
err
} else if !locator.crate_rejections.via_invalid.is_empty() {
let mut err = struct_span_err!(
sess,
span,
E0786,
"found invalid metadata files for crate `{}`{}",
crate_name,
add,
);
for CrateMismatch { path: _, got } in locator.crate_rejections.via_invalid {
err.note(&got);
}
err
} else {
let mut err = struct_span_err!(
sess,
Expand Down
Loading