probe-rs / rtt-target

Target side implementation of the RTT (Real-Time Transfer) I/O protocol
MIT License
115 stars 29 forks source link

Rust analyzer doesn't like `rtt_init_target` #30

Closed tgross35 closed 1 year ago

tgross35 commented 1 year ago

With this simple code, RA throws the error: "field up of Channels is private":

#![no_std]
#![no_main]

#[cortex_m_rt::entry]
fn main() -> ! {
    rtt_target::rtt_init_print!();
    loop {}
}

#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
    loop {}
}
image

This expands to:

Full macro expansion ``` #![feature(prelude_import)] #![no_std] #![no_main] #[prelude_import] use core::prelude::rust_2021::*; #[macro_use] extern crate core; #[macro_use] extern crate compiler_builtins; #[doc(hidden)] #[export_name = "main"] pub unsafe extern "C" fn __cortex_m_rt_main_trampoline() { __cortex_m_rt_main() } fn __cortex_m_rt_main() -> ! { let channels = { use core::mem::MaybeUninit; use core::ptr; use ::rtt_target::UpChannel; use ::rtt_target::DownChannel; use ::rtt_target::rtt::*; #[repr(C)] pub struct RttControlBlock { header: RttHeader, up_channels: [RttChannel; (1 + 0)], down_channels: [RttChannel; (0)], } #[used] #[no_mangle] #[export_name = "_SEGGER_RTT"] pub static mut CONTROL_BLOCK: MaybeUninit = MaybeUninit::uninit(); unsafe { ptr::write_bytes(CONTROL_BLOCK.as_mut_ptr(), 0, 1); let cb = &mut *CONTROL_BLOCK.as_mut_ptr(); let mut name: *const u8 = core::ptr::null(); name = "Terminal\u{0}".as_bytes().as_ptr(); let mut mode = ::rtt_target::ChannelMode::NoBlockSkip; mode = ::rtt_target::ChannelMode::NoBlockSkip; cb.up_channels[0] .init( name, mode, { static mut _RTT_CHANNEL_BUFFER: MaybeUninit<[u8; 1024]> = MaybeUninit::uninit(); _RTT_CHANNEL_BUFFER.as_mut_ptr() }, ); cb.header.init(cb.up_channels.len(), cb.down_channels.len()); pub struct Channels { up: (UpChannel,), } Channels { up: (UpChannel::new(&mut cb.up_channels[0] as *mut _),), } } }; ::rtt_target::set_print_channel(channels.up.0); loop {} } #[panic_handler] fn panic(_info: &core::panic::PanicInfo) -> ! { loop {} } ```

It seems like the complaint is likely at ::rtt_target::set_print_channel(channels.up.0); and I think a fix would be from updating the below block:

pub struct Channels {
    /* make this `pub` */  up: (UpChannel,),
}

But I'm still trying to figure out where this comes from in source.

RA is in the wrong here since it compiles correctly (and weirdly puts the squiggles in the wrong place) but it's probably easier to fix on this end.

tgross35 commented 1 year ago

This should be closed with #21