Skip to content

Commit

Permalink
clippy: missing_transmute_annotations (solana-labs#1343)
Browse files Browse the repository at this point in the history
* clippy: missing_transmute_annotations

* Revert "clippy: missing_transmute_annotations"

This reverts commit 01b5fe5.

* update types

* update types

* update types

* update types

* feedback

* add one more missing type

* Revert "feedback"

This reverts commit 420ee23.

* update types
  • Loading branch information
yihau authored May 17, 2024
1 parent 8c67696 commit 8f9fc2a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
5 changes: 3 additions & 2 deletions program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ thread_local! {
static INVOKE_CONTEXT: RefCell<Option<usize>> = const { RefCell::new(None) };
}
fn set_invoke_context(new: &mut InvokeContext) {
INVOKE_CONTEXT
.with(|invoke_context| unsafe { invoke_context.replace(Some(transmute::<_, usize>(new))) });
INVOKE_CONTEXT.with(|invoke_context| unsafe {
invoke_context.replace(Some(transmute::<&mut InvokeContext, usize>(new)))
});
}
fn get_invoke_context<'a, 'b>() -> &'a mut InvokeContext<'b> {
let ptr = INVOKE_CONTEXT.with(|invoke_context| match *invoke_context.borrow() {
Expand Down
6 changes: 5 additions & 1 deletion programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,11 @@ fn execute<'a, 'b: 'a>(
) -> Result<(), Box<dyn std::error::Error>> {
// We dropped the lifetime tracking in the Executor by setting it to 'static,
// thus we need to reintroduce the correct lifetime of InvokeContext here again.
let executable = unsafe { mem::transmute::<_, &'a Executable<InvokeContext<'b>>>(executable) };
let executable = unsafe {
mem::transmute::<&'a Executable<InvokeContext<'static>>, &'a Executable<InvokeContext<'b>>>(
executable,
)
};
let log_collector = invoke_context.get_log_collector();
let transaction_context = &invoke_context.transaction_context;
let instruction_context = transaction_context.get_current_instruction_context()?;
Expand Down
8 changes: 6 additions & 2 deletions programs/loader-v4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,12 @@ fn execute<'a, 'b: 'a>(
) -> Result<(), Box<dyn std::error::Error>> {
// We dropped the lifetime tracking in the Executor by setting it to 'static,
// thus we need to reintroduce the correct lifetime of InvokeContext here again.
let executable =
unsafe { std::mem::transmute::<_, &'a Executable<InvokeContext<'b>>>(executable) };
let executable = unsafe {
std::mem::transmute::<
&'a Executable<InvokeContext<'static>>,
&'a Executable<InvokeContext<'b>>,
>(executable)
};
let log_collector = invoke_context.get_log_collector();
let stack_height = invoke_context.get_stack_height();
let transaction_context = &invoke_context.transaction_context;
Expand Down
6 changes: 3 additions & 3 deletions programs/sbf/rust/invoke/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ fn do_nested_invokes(num_nested_invokes: u64, accounts: &[AccountInfo]) -> Progr
}

solana_program::entrypoint!(process_instruction);
fn process_instruction(
fn process_instruction<'a>(
program_id: &Pubkey,
accounts: &[AccountInfo],
accounts: &[AccountInfo<'a>],
instruction_data: &[u8],
) -> ProgramResult {
msg!("invoke Rust program");
Expand Down Expand Up @@ -1158,7 +1158,7 @@ fn process_instruction(
let mut lamports = account.lamports();
account
.lamports
.replace(unsafe { mem::transmute(&mut lamports) });
.replace(unsafe { mem::transmute::<&'_ mut u64, &'a mut u64>(&mut lamports) });
let callee_program_id = accounts[CALLEE_PROGRAM_INDEX].key;

invoke(
Expand Down
4 changes: 2 additions & 2 deletions unified-scheduler-logic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ mod utils {
#[cfg_attr(miri, ignore)]
fn test_ub_illegally_created_multiple_tokens() {
// Unauthorized token minting!
let mut token1 = unsafe { mem::transmute(()) };
let mut token2 = unsafe { mem::transmute(()) };
let mut token1 = unsafe { mem::transmute::<(), Token<FakeQueue>>(()) };
let mut token2 = unsafe { mem::transmute::<(), Token<FakeQueue>>(()) };

let queue = TokenCell::new(FakeQueue {
v: Vec::with_capacity(20),
Expand Down

0 comments on commit 8f9fc2a

Please sign in to comment.