rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.24k stars 1.51k forks source link

`rc_buffer` expands type aliases, which breaks scoping #6238

Open jyn514 opened 3 years ago

jyn514 commented 3 years ago

I tried this code (https://github.com/rust-lang/rust/blob/a6ff925f8b5598a1f6d84964525baa1d4a08fd63/compiler/rustc_infer/src/infer/region_constraints/mod.rs#L545):

type Lrc = std::rc::Rc;

fn f(choice_regions: &Lrc<Vec<ty::Region<'tcx>>>)

I expected to see this happen: Clippy suggests Lrc<[ty::Region<'tcx>]>

Instead, this happened: Clippy suggests Rc<[ty::Region<'tcx>]>

The following errors were reported:
error[E0412]: cannot find type `Rc` in this scope
   --> compiler/rustc_infer/src/infer/region_constraints/mod.rs:545:26
    |
545 |         choice_regions: &Rc<[ty::Region<'tcx>]>,
    |                          ^^ not found in this scope
    |
help: consider importing one of these items
    |
3   | use crate::infer::combine::ast::mut_visit::process::imp::process_inner::sys::ext::net::sys_common::wtf8::Rc;
    |
3   | use std::rc::Rc;

warning: usage of `Rc<T>` when T is a buffer type
   --> compiler/rustc_infer/src/infer/region_constraints/mod.rs:545:26
    |
545 |         choice_regions: &Lrc<Vec<ty::Region<'tcx>>>,
    |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Rc<[ty::Region<'tcx>]>`
    |
    = note: `#[warn(clippy::rc_buffer)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#rc_buffer

Meta

jyn514 commented 3 years ago

And related: unnecessary_cast expands c_uint to u32, which will break on platforms where it's u16 or u64.

diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs
index f122fa14e70..568959631d9 100644
--- a/compiler/rustc_codegen_llvm/src/builder.rs
+++ b/compiler/rustc_codegen_llvm/src/builder.rs
@@ -1420,7 +1420,7 @@ pub(crate) fn phi(

     fn add_incoming_to_phi(&mut self, phi: &'ll Value, val: &'ll Value, bb: &'ll BasicBlock) {
         unsafe {
-            llvm::LLVMAddIncoming(phi, &val, &bb, 1 as c_uint);
+            llvm::LLVMAddIncoming(phi, &val, &bb, 1_u32);
         }
     }

(in practice, c_uint is always u32, but this could be relevant if this were c_ulong or something.)

kraktus commented 1 year ago

since https://github.com/rust-lang/rust-clippy/pull/8596 unnecessary_cast does not lint type aliases at all anymore, so I guess this can be closed

jyn514 commented 1 year ago

@kraktus what about rc_buffer?