Skip to content

Commit

Permalink
Squashed a bunch of warnings (rust-lang#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsn authored and tedinski committed Apr 10, 2021
1 parent f0e6fea commit e9381e0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! this module lazily declares builtin functions in CBMC
use self::BuiltinFn::*;
use super::{Expr, Location, Symbol, SymbolTable, Type};
use super::{Expr, Location, Symbol, Type};

#[derive(Debug, Clone, Copy)]
pub enum BuiltinFn {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/gotoc/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct CurrentFnCtx<'tcx> {
/// the codegen instance for the current function
instance: Instance<'tcx>,
/// the def id for the current instance
def_id: DefId,
_def_id: DefId,
/// the mir for the current instance
mir: &'tcx Body<'tcx>,
/// the goto labels for all blocks
Expand All @@ -56,7 +56,7 @@ impl CurrentFnCtx<'tcx> {
Self {
instance,
mir: tcx.instance_mir(instance.def),
def_id: instance.def_id(),
_def_id: instance.def_id(),
labels: vec![],
block: vec![],
current_bb: None,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/gotoc/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ impl<'tcx> GotocCtx<'tcx> {
// initializers. For example, for a boolean static variable, the variable will have type
// CBool and the initializer will be a single byte (a one-character array) representing the
// bit pattern for the boolean value.
let alloc_typ_ref = self.ensure_struct(&format!("{}::struct", name), |ctx, name| {
let alloc_typ_ref = self.ensure_struct(&format!("{}::struct", name), |ctx, _| {
ctx.codegen_allocation_data(alloc)
.iter()
.enumerate()
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_codegen_llvm/src/gotoc/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
use super::cbmc::goto_program::{Expr, Type};
use super::metadata::*;
use super::typ::tuple_fld;
use rustc_ast::ast::Mutability;
use rustc_middle::ty::{self, Ty, TyS, VariantDef};
use rustc_middle::{
mir::{Field, Local, Place, ProjectionElem},
ty::layout::HasTyCtxt,
ty::{self, Ty, TyS, VariantDef},
};
use rustc_target::abi::{LayoutOf, TagEncoding, Variants};
use tracing::debug;
Expand Down
44 changes: 17 additions & 27 deletions compiler/rustc_codegen_llvm/src/gotoc/typ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl<'tcx> GotocCtx<'tcx> {
/// }
/// Ensures that the vtable is added to the symbol table.
fn codegen_trait_vtable_type(&mut self, t: &'tcx ty::TyS<'tcx>) -> Type {
self.ensure_struct(&self.vtable_name(t), |ctx, name| ctx.trait_vtable_field_types(t))
self.ensure_struct(&self.vtable_name(t), |ctx, _| ctx.trait_vtable_field_types(t))
}

/// a trait dyn Trait is translated to
Expand All @@ -150,7 +150,7 @@ impl<'tcx> GotocCtx<'tcx> {
/// void* vtable;
/// }
fn codegen_trait_fat_ptr_type(&mut self, t: &'tcx ty::TyS<'tcx>) -> Type {
self.ensure_struct(&self.normalized_trait_name(t), |ctx, name| {
self.ensure_struct(&self.normalized_trait_name(t), |ctx, _| {
// At this point in time, the vtable hasn't been codegen yet.
// However, all we need to know is its name, which we do know.
// See the comment on codegen_ty_ref.
Expand Down Expand Up @@ -313,7 +313,7 @@ impl<'tcx> GotocCtx<'tcx> {
// struct [T; n] {
// T _0[n];
// }
self.ensure_struct(&array_name, |ctx, name| {
self.ensure_struct(&array_name, |ctx, _| {
if et.is_unit() {
// we do not generate a struct with an array of units
vec![]
Expand Down Expand Up @@ -347,8 +347,8 @@ impl<'tcx> GotocCtx<'tcx> {
} else {
// we do not have to do two insertions for tuple because it is impossible for
// finite tuples to loop.
self.ensure_struct(&self.ty_mangled_name(ty), |tcx, name| {
tcx.codegen_ty_tuple_fields(name, ty, ts)
self.ensure_struct(&self.ty_mangled_name(ty), |tcx, _| {
tcx.codegen_ty_tuple_fields(ty, ts)
})
}
}
Expand Down Expand Up @@ -392,11 +392,10 @@ impl<'tcx> GotocCtx<'tcx> {

fn codegen_ty_tuple_fields(
&mut self,
name: &str,
t: Ty<'tcx>,
substs: ty::subst::SubstsRef<'tcx>,
) -> Vec<DatatypeComponent> {
self.codegen_ty_tuple_like(name, t, substs.iter().map(|g| g.expect_ty()).collect())
self.codegen_ty_tuple_like(t, substs.iter().map(|g| g.expect_ty()).collect())
}

fn codegen_struct_padding<T>(
Expand Down Expand Up @@ -434,7 +433,6 @@ impl<'tcx> GotocCtx<'tcx> {
/// * initial_offset - offset which has been accumulated in parent struct, in bits
fn codegen_struct_fields(
&mut self,
name: &str,
flds: Vec<(String, Ty<'tcx>)>,
layout: &Layout,
initial_offset: usize,
Expand Down Expand Up @@ -492,25 +490,19 @@ impl<'tcx> GotocCtx<'tcx> {
}
}

fn codegen_ty_tuple_like(
&mut self,
name: &str,
t: Ty<'tcx>,
tys: Vec<Ty<'tcx>>,
) -> Vec<DatatypeComponent> {
fn codegen_ty_tuple_like(&mut self, t: Ty<'tcx>, tys: Vec<Ty<'tcx>>) -> Vec<DatatypeComponent> {
let layout = self.layout_of(t);
let flds: Vec<_> = tys.iter().enumerate().map(|(i, t)| (tuple_fld(i), *t)).collect();
// tuple cannot have other initial offset
self.codegen_struct_fields(name, flds, layout.layout, 0)
self.codegen_struct_fields(flds, layout.layout, 0)
}

/// a closure is a struct of all its environments
/// that is, a closure is just a tuple with a unique type identifier, so that Fn related traits
/// can find its impl.
fn codegen_ty_closure(&mut self, t: Ty<'tcx>, substs: ty::subst::SubstsRef<'tcx>) -> Type {
let name = self.ty_mangled_name(t);
self.ensure_struct(&name, |ctx, name| {
ctx.codegen_ty_tuple_like(name, t, substs.as_closure().upvar_tys().collect())
self.ensure_struct(&self.ty_mangled_name(t), |ctx, _| {
ctx.codegen_ty_tuple_like(t, substs.as_closure().upvar_tys().collect())
})
}

Expand All @@ -524,7 +516,7 @@ impl<'tcx> GotocCtx<'tcx> {
ty::Adt(..) if self.is_unsized(t) => {
// https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp
let fat_ptr_name = format!("&{}", self.ty_mangled_name(t));
self.ensure_struct(&fat_ptr_name, |ctx, name| {
self.ensure_struct(&fat_ptr_name, |ctx, _| {
vec![
Type::datatype_component("data", ctx.codegen_ty(t).to_pointer()),
Type::datatype_component("len", Type::size_t()),
Expand Down Expand Up @@ -666,17 +658,16 @@ impl<'tcx> GotocCtx<'tcx> {
def: &'tcx AdtDef,
subst: &'tcx InternalSubsts<'tcx>,
) -> Type {
self.ensure_struct(&self.ty_mangled_name(ty), |ctx, name| {
self.ensure_struct(&self.ty_mangled_name(ty), |ctx, _| {
let variant = &def.variants.raw[0];
let layout = ctx.layout_of(ty);
ctx.codegen_variant_struct_fields(name, variant, subst, layout.layout, 0)
ctx.codegen_variant_struct_fields(variant, subst, layout.layout, 0)
})
}

/// generate a struct representing the layout of the variant
fn codegen_variant_struct_fields(
&mut self,
name: &str,
variant: &VariantDef,
subst: &'tcx InternalSubsts<'tcx>,
layout: &Layout,
Expand All @@ -687,7 +678,7 @@ impl<'tcx> GotocCtx<'tcx> {
.iter()
.map(|f| (f.ident.name.to_string(), f.ty(self.tcx, subst)))
.collect();
self.codegen_struct_fields(name, flds, layout, initial_offset)
self.codegen_struct_fields(flds, layout, initial_offset)
}

/// codegen unions
Expand All @@ -697,7 +688,7 @@ impl<'tcx> GotocCtx<'tcx> {
def: &'tcx AdtDef,
subst: &'tcx InternalSubsts<'tcx>,
) -> Type {
self.ensure_union(&self.ty_mangled_name(ty), |ctx, name| {
self.ensure_union(&self.ty_mangled_name(ty), |ctx, _| {
def.variants.raw[0]
.fields
.iter()
Expand Down Expand Up @@ -763,7 +754,7 @@ impl<'tcx> GotocCtx<'tcx> {
Some(variant) => {
// a single enum is pretty much like a struct
let layout = ctx.layout_of(ty).layout;
ctx.codegen_variant_struct_fields(name, variant, subst, layout, 0)
ctx.codegen_variant_struct_fields(variant, subst, layout, 0)
}
}
}
Expand Down Expand Up @@ -804,7 +795,6 @@ impl<'tcx> GotocCtx<'tcx> {
// dataful_variant is pretty much the only variant which contains the valid data
let variant = &adtdef.variants[*dataful_variant];
ctx.codegen_variant_struct_fields(
name,
variant,
subst,
&variants[*dataful_variant],
Expand Down Expand Up @@ -923,7 +913,7 @@ impl<'tcx> GotocCtx<'tcx> {
let case_name = format!("{}::{}", name, case.ident.name);
debug!("handling variant {}: {:?}", case_name, case);
self.ensure_struct(&case_name, |tcx, _| {
tcx.codegen_variant_struct_fields(&case_name, case, subst, variant, initial_offset)
tcx.codegen_variant_struct_fields(case, subst, variant, initial_offset)
})
}

Expand Down

0 comments on commit e9381e0

Please sign in to comment.