Skip to content

Commit 40cb4eb

Browse files
committed
Fix clippy warnings on latest nightly
1 parent 4fca66f commit 40cb4eb

File tree

9 files changed

+117
-109
lines changed

9 files changed

+117
-109
lines changed

crates/cuda_builder/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ struct RustcOutput {
835835
}
836836

837837
fn get_last_artifact(out: &str) -> Option<PathBuf> {
838-
let artifacts =
838+
let mut artifacts =
839839
out.lines()
840840
.filter_map(|line| match serde_json::from_str::<RustcOutput>(line) {
841841
Ok(line) => Some(line),
@@ -846,9 +846,7 @@ fn get_last_artifact(out: &str) -> Option<PathBuf> {
846846
}
847847
});
848848

849-
let last = artifacts
850-
.filter(|line| line.reason == "compiler-artifact")
851-
.next_back()?;
849+
let last = artifacts.rfind(|line| line.reason == "compiler-artifact")?;
852850

853851
let mut filenames = last
854852
.filenames

crates/cuda_std/src/thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ pub fn index() -> u32 {
236236

237237
#[inline(always)]
238238
pub fn index_1d() -> u32 {
239-
thread_idx_x() as u32 + block_idx_x() as u32 * block_dim_x() as u32
239+
thread_idx_x() + block_idx_x() * block_dim_x()
240240
}
241241

242242
#[inline(always)]

crates/gpu_rand/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
#![deny(missing_docs)]
4141
#![deny(missing_debug_implementations)]
4242
#![allow(clippy::unreadable_literal)]
43-
#![feature(doc_cfg)]
44-
4543
pub mod xoroshiro;
4644

4745
mod default;

crates/rustc_codegen_nvvm/src/allocator.rs

Lines changed: 99 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -9,111 +9,122 @@ use rustc_middle::ty::TyCtxt;
99
use rustc_symbol_mangling::mangle_internal_symbol;
1010

1111
// adapted from rustc_codegen_llvm
12-
pub(crate) unsafe fn codegen(
12+
pub(crate) fn codegen(
1313
tcx: TyCtxt<'_>,
1414
mods: &mut LlvmMod,
1515
_module_name: &str,
1616
methods: &[AllocatorMethod],
1717
) {
18-
let llcx = &*mods.llcx;
19-
let llmod = mods.llmod.as_ref().unwrap();
20-
let usize = target::usize_ty(llcx);
21-
let i8 = llvm::LLVMInt8TypeInContext(llcx);
22-
let i8p = llvm::LLVMPointerType(i8, 0);
23-
let void = llvm::LLVMVoidTypeInContext(llcx);
18+
unsafe {
19+
let llcx = &*mods.llcx;
20+
let llmod = mods.llmod.as_ref().unwrap();
21+
let usize = target::usize_ty(llcx);
22+
let i8 = llvm::LLVMInt8TypeInContext(llcx);
23+
let i8p = llvm::LLVMPointerType(i8, 0);
24+
let void = llvm::LLVMVoidTypeInContext(llcx);
2425

25-
let mut used = Vec::new();
26+
let mut used = Vec::new();
2627

27-
for method in methods {
28-
let mut args = Vec::with_capacity(method.inputs.len());
29-
for input in method.inputs {
30-
match input.ty {
31-
AllocatorTy::Layout => {
32-
args.push(usize);
33-
args.push(usize);
28+
for method in methods {
29+
let mut args = Vec::with_capacity(method.inputs.len());
30+
for input in method.inputs {
31+
match input.ty {
32+
AllocatorTy::Layout => {
33+
args.push(usize);
34+
args.push(usize);
35+
}
36+
AllocatorTy::Ptr => args.push(i8p),
37+
AllocatorTy::Usize => args.push(usize),
38+
AllocatorTy::Never | AllocatorTy::ResultPtr | AllocatorTy::Unit => {
39+
panic!("invalid allocator arg")
40+
}
3441
}
35-
AllocatorTy::Ptr => args.push(i8p),
36-
AllocatorTy::Usize => args.push(usize),
37-
AllocatorTy::Never | AllocatorTy::ResultPtr | AllocatorTy::Unit => {
38-
panic!("invalid allocator arg")
42+
}
43+
44+
let no_return = matches!(method.output, AllocatorTy::Never);
45+
let output = match method.output {
46+
AllocatorTy::ResultPtr => Some(i8p),
47+
AllocatorTy::Never | AllocatorTy::Unit => None,
48+
AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
49+
panic!("invalid allocator output")
3950
}
51+
};
52+
53+
let ty = llvm::LLVMFunctionType(
54+
output.unwrap_or(void),
55+
args.as_ptr(),
56+
args.len() as c_uint,
57+
False,
58+
);
59+
let from_name = mangle_internal_symbol(tcx, &global_fn_name(method.name));
60+
let llfn = llvm::LLVMRustGetOrInsertFunction(
61+
llmod,
62+
from_name.as_ptr().cast(),
63+
from_name.len(),
64+
ty,
65+
);
66+
used.push(llfn);
67+
if no_return {
68+
llvm::Attribute::NoReturn.apply_llfn(llvm::AttributePlace::Function, llfn);
4069
}
41-
}
4270

43-
let no_return = matches!(method.output, AllocatorTy::Never);
44-
let output = match method.output {
45-
AllocatorTy::ResultPtr => Some(i8p),
46-
AllocatorTy::Never | AllocatorTy::Unit => None,
47-
AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
48-
panic!("invalid allocator output")
71+
let to_name = mangle_internal_symbol(tcx, &default_fn_name(method.name));
72+
let callee = llvm::LLVMRustGetOrInsertFunction(
73+
llmod,
74+
to_name.as_ptr().cast(),
75+
to_name.len(),
76+
ty,
77+
);
78+
used.push(callee);
79+
if no_return {
80+
llvm::Attribute::NoReturn.apply_llfn(llvm::AttributePlace::Function, callee);
4981
}
50-
};
82+
llvm::LLVMRustSetVisibility(callee, llvm::Visibility::Hidden);
5183

52-
let ty = llvm::LLVMFunctionType(
53-
output.unwrap_or(void),
54-
args.as_ptr(),
55-
args.len() as c_uint,
56-
False,
57-
);
58-
let from_name = mangle_internal_symbol(tcx, &global_fn_name(method.name));
59-
let llfn = llvm::LLVMRustGetOrInsertFunction(
60-
llmod,
61-
from_name.as_ptr().cast(),
62-
from_name.len(),
63-
ty,
64-
);
65-
used.push(llfn);
66-
if no_return {
67-
llvm::Attribute::NoReturn.apply_llfn(llvm::AttributePlace::Function, llfn);
84+
let llbb = llvm::LLVMAppendBasicBlockInContext(llcx, llfn, c"entry".as_ptr().cast());
85+
let llbuilder = llvm::LLVMCreateBuilderInContext(llcx);
86+
llvm::LLVMPositionBuilderAtEnd(llbuilder, llbb);
87+
let args = args
88+
.iter()
89+
.enumerate()
90+
.map(|(i, _)| llvm::LLVMGetParam(llfn, i as c_uint))
91+
.collect::<Vec<_>>();
92+
let ret = llvm::LLVMRustBuildCall(
93+
llbuilder,
94+
callee,
95+
args.as_ptr(),
96+
args.len() as c_uint,
97+
None,
98+
);
99+
llvm::LLVMSetTailCall(ret, True);
100+
if output.is_some() {
101+
llvm::LLVMBuildRet(llbuilder, ret);
102+
} else {
103+
llvm::LLVMBuildRetVoid(llbuilder);
104+
}
105+
llvm::LLVMDisposeBuilder(llbuilder);
68106
}
69107

70-
let to_name = mangle_internal_symbol(tcx, &default_fn_name(method.name));
71-
let callee =
72-
llvm::LLVMRustGetOrInsertFunction(llmod, to_name.as_ptr().cast(), to_name.len(), ty);
73-
used.push(callee);
74-
if no_return {
75-
llvm::Attribute::NoReturn.apply_llfn(llvm::AttributePlace::Function, callee);
76-
}
77-
llvm::LLVMRustSetVisibility(callee, llvm::Visibility::Hidden);
108+
let shim_ty = llvm::LLVMFunctionType(void, std::ptr::null(), 0, False);
109+
let shim_name = mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE);
110+
let shim = llvm::LLVMRustGetOrInsertFunction(
111+
llmod,
112+
shim_name.as_ptr().cast(),
113+
shim_name.len(),
114+
shim_ty,
115+
);
116+
used.push(shim);
78117

79-
let llbb = llvm::LLVMAppendBasicBlockInContext(llcx, llfn, c"entry".as_ptr().cast());
80-
let llbuilder = llvm::LLVMCreateBuilderInContext(llcx);
81-
llvm::LLVMPositionBuilderAtEnd(llbuilder, llbb);
82-
let args = args
83-
.iter()
84-
.enumerate()
85-
.map(|(i, _)| llvm::LLVMGetParam(llfn, i as c_uint))
86-
.collect::<Vec<_>>();
87-
let ret =
88-
llvm::LLVMRustBuildCall(llbuilder, callee, args.as_ptr(), args.len() as c_uint, None);
89-
llvm::LLVMSetTailCall(ret, True);
90-
if output.is_some() {
91-
llvm::LLVMBuildRet(llbuilder, ret);
92-
} else {
93-
llvm::LLVMBuildRetVoid(llbuilder);
118+
let ptr_ty = llvm::LLVMPointerType(llvm::LLVMInt8TypeInContext(llcx), 0);
119+
for used in &mut used {
120+
*used = llvm::LLVMConstBitCast(used, ptr_ty);
94121
}
95-
llvm::LLVMDisposeBuilder(llbuilder);
96-
}
97-
98-
let shim_ty = llvm::LLVMFunctionType(void, std::ptr::null(), 0, False);
99-
let shim_name = mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE);
100-
let shim = llvm::LLVMRustGetOrInsertFunction(
101-
llmod,
102-
shim_name.as_ptr().cast(),
103-
shim_name.len(),
104-
shim_ty,
105-
);
106-
used.push(shim);
107122

108-
let ptr_ty = llvm::LLVMPointerType(llvm::LLVMInt8TypeInContext(llcx), 0);
109-
for used in &mut used {
110-
*used = llvm::LLVMConstBitCast(*used, ptr_ty);
123+
let section = c"llvm.metadata";
124+
let array = llvm::LLVMConstArray(ptr_ty, used.as_ptr(), used.len() as u32);
125+
let g = llvm::LLVMAddGlobal(llmod, llvm::LLVMTypeOf(array), c"llvm.used".as_ptr().cast());
126+
llvm::LLVMSetInitializer(g, array);
127+
llvm::LLVMRustSetLinkage(g, llvm::Linkage::AppendingLinkage);
128+
llvm::LLVMSetSection(g, section.as_ptr());
111129
}
112-
113-
let section = c"llvm.metadata";
114-
let array = llvm::LLVMConstArray(ptr_ty, used.as_ptr(), used.len() as u32);
115-
let g = llvm::LLVMAddGlobal(llmod, llvm::LLVMTypeOf(array), c"llvm.used".as_ptr().cast());
116-
llvm::LLVMSetInitializer(g, array);
117-
llvm::LLVMRustSetLinkage(g, llvm::Linkage::AppendingLinkage);
118-
llvm::LLVMSetSection(g, section.as_ptr());
119130
}

crates/rustc_codegen_nvvm/src/const_ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
200200
}),
201201
)))
202202
.unwrap_memory();
203-
let init = const_alloc_to_llvm(self, alloc, /*static*/ false);
203+
let _ = const_alloc_to_llvm(self, alloc, /*static*/ false);
204204
let value = self.static_addr_of(alloc, None);
205205
(value, AddressSpace::ZERO)
206206
}

crates/rustc_codegen_nvvm/src/context.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ pub(crate) struct CodegenCx<'ll, 'tcx> {
6464
pub remapped_integer_args:
6565
RefCell<FxHashMap<&'ll Type, (Option<&'ll Type>, Vec<(usize, &'ll Type)>)>>,
6666

67-
/// Cache of emitted const globals (value -> global)
68-
pub const_globals: RefCell<FxHashMap<&'ll Value, &'ll Value>>,
69-
7067
/// List of globals for static variables which need to be passed to the
7168
/// LLVM function ReplaceAllUsesWith (RAUW) when codegen is complete.
7269
/// (We have to make sure we don't invalidate any Values referring
@@ -148,7 +145,6 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
148145
vtables: Default::default(),
149146
const_cstr_cache: Default::default(),
150147
remapped_integer_args: Default::default(),
151-
const_globals: Default::default(),
152148
statics_to_rauw: RefCell::new(Vec::new()),
153149
used_statics: RefCell::new(Vec::new()),
154150
compiler_used_statics: RefCell::new(Vec::new()),
@@ -265,7 +261,11 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
265261
pub fn static_addrspace(&self, instance: Instance<'tcx>) -> AddressSpace {
266262
let ty = instance.ty(self.tcx, self.typing_env());
267263
let is_mutable = self.tcx().is_mutable_static(instance.def_id());
268-
let attrs = self.tcx.get_all_attrs(instance.def_id()); // TODO: replace with get_attrs
264+
let attrs = if let Some(def_id) = instance.def_id().as_local() {
265+
self.tcx.hir_attrs(self.tcx.local_def_id_to_hir_id(def_id))
266+
} else {
267+
self.tcx.attrs_for_def(instance.def_id())
268+
};
269269
let nvvm_attrs = NvvmAttributes::parse(self, attrs);
270270

271271
if let Some(addr) = nvvm_attrs.addrspace {

crates/rustc_codegen_nvvm/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,7 @@ impl ExtraBackendMethods for NvvmCodegenBackend {
337337
methods: &[AllocatorMethod],
338338
) -> LlvmMod {
339339
let mut module_llvm = LlvmMod::new(module_name);
340-
unsafe {
341-
allocator::codegen(tcx, &mut module_llvm, module_name, methods);
342-
}
340+
allocator::codegen(tcx, &mut module_llvm, module_name, methods);
343341
module_llvm
344342
}
345343

crates/rustc_codegen_nvvm/src/mono_item.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
9191
attributes::from_fn_attrs(self, lldecl, instance);
9292

9393
let def_id = instance.def_id();
94-
let attrs = self.tcx.get_all_attrs(def_id); // TODO: Replace with get_attrs
94+
let attrs = if let Some(def_id) = def_id.as_local() {
95+
self.tcx.hir_attrs(self.tcx.local_def_id_to_hir_id(def_id))
96+
} else {
97+
self.tcx.attrs_for_def(def_id)
98+
};
9599
let nvvm_attrs = NvvmAttributes::parse(self, attrs);
96100

97101
unsafe {

crates/rustc_codegen_nvvm/src/ty.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,10 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
403403

404404
fn immediate_llvm_type<'a>(&self, cx: &CodegenCx<'a, 'tcx>) -> &'a Type {
405405
match self.backend_repr {
406-
BackendRepr::Scalar(ref scalar) => {
407-
if scalar.is_bool() {
408-
return cx.type_i1();
409-
}
406+
BackendRepr::Scalar(ref scalar) if scalar.is_bool() => {
407+
return cx.type_i1();
410408
}
409+
BackendRepr::Scalar(..) => {}
411410
BackendRepr::ScalarPair(..) => {
412411
// An immediate pair always contains just the two elements, without any padding
413412
// filler, as it should never be stored to memory.

0 commit comments

Comments
 (0)