Skip to content

Commit

Permalink
Auto merge of #56566 - ljedrz:fix_clippy_errors, r=cramertj
Browse files Browse the repository at this point in the history
codegen_utils, driver: fix clippy errors

- remove a superfluous conversion
- remove an explicit `return`
- rename `MetadataOnlyCodegenBackend::new` to `::boxed`
- single-arm `match` > `if let`
  • Loading branch information
bors committed Dec 7, 2018
2 parents f504d3f + adaeb10 commit 1c3236a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
21 changes: 9 additions & 12 deletions src/librustc_codegen_utils/codegen_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ impl MetadataLoader for NoLlvmMetadataLoader {

let mut buf = Vec::new();
io::copy(&mut file, &mut buf).unwrap();
let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into();
return Ok(rustc_erase_owner!(buf.map_owner_box()));
let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf);
Ok(rustc_erase_owner!(buf.map_owner_box()))
}

fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result<MetadataRef, String> {
Expand All @@ -103,7 +103,7 @@ pub struct OngoingCodegen {
}

impl MetadataOnlyCodegenBackend {
pub fn new() -> Box<dyn CodegenBackend> {
pub fn boxed() -> Box<dyn CodegenBackend> {
box MetadataOnlyCodegenBackend(())
}
}
Expand Down Expand Up @@ -165,23 +165,20 @@ impl CodegenBackend for MetadataOnlyCodegenBackend {
tcx,
collector::MonoItemCollectionMode::Eager
).0 {
match mono_item {
MonoItem::Fn(inst) => {
let def_id = inst.def_id();
if def_id.is_local() {
let _ = inst.def.is_inline(tcx);
let _ = tcx.codegen_fn_attrs(def_id);
}
if let MonoItem::Fn(inst) = mono_item {
let def_id = inst.def_id();
if def_id.is_local() {
let _ = inst.def.is_inline(tcx);
let _ = tcx.codegen_fn_attrs(def_id);
}
_ => {}
}
}
tcx.sess.abort_if_errors();

let metadata = tcx.encode_metadata();

box OngoingCodegen {
metadata: metadata,
metadata,
metadata_version: tcx.metadata_encoding_version().to_vec(),
crate_name: tcx.crate_name(LOCAL_CRATE),
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ pub fn get_codegen_backend(sess: &Session) -> Box<dyn CodegenBackend> {
.unwrap_or(&sess.target.target.options.codegen_backend);
let backend = match &codegen_name[..] {
"metadata_only" => {
rustc_codegen_utils::codegen_backend::MetadataOnlyCodegenBackend::new
rustc_codegen_utils::codegen_backend::MetadataOnlyCodegenBackend::boxed
}
filename if filename.contains(".") => {
load_backend_from_dylib(filename.as_ref())
Expand Down Expand Up @@ -291,7 +291,7 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend> {
// let's just return a dummy creation function which won't be used in
// general anyway.
if cfg!(test) {
return rustc_codegen_utils::codegen_backend::MetadataOnlyCodegenBackend::new
return rustc_codegen_utils::codegen_backend::MetadataOnlyCodegenBackend::boxed
}

let target = session::config::host_triple();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ impl CodegenBackend for TheBackend {
/// This is the entrypoint for a hot plugged rustc_codegen_llvm
#[no_mangle]
pub fn __rustc_codegen_backend() -> Box<CodegenBackend> {
Box::new(TheBackend(MetadataOnlyCodegenBackend::new()))
Box::new(TheBackend(MetadataOnlyCodegenBackend::boxed()))
}

0 comments on commit 1c3236a

Please sign in to comment.