Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/clippy-tracing/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ macro_rules! create_check_visitor_function {
($func_name:ident, $item:ident) => {
fn $func_name(&mut self, i: &syn::$item) {
let attr = check_attributes(&i.attrs);
if !attr.instrumented && !attr.test && i.sig.constness.is_none() {
if !attr.instrumented && !attr.test && i.sig.constness.is_none() && i.sig.abi.is_none()
{
self.0 = Some(i.span());
} else {
self.visit_block(&i.block);
Expand Down Expand Up @@ -162,7 +163,8 @@ macro_rules! create_fix_visitor_function {
fn $func_name(&mut self, i: &syn::$item) {
let attr = check_attributes(&i.attrs);

if !attr.instrumented && !attr.test && i.sig.constness.is_none() {
if !attr.instrumented && !attr.test && i.sig.constness.is_none() && i.sig.abi.is_none()
{
let line = i.span().start().line;

let attr_string = instrument(&i.sig, self.suffix, self.cfg_attr);
Expand Down
30 changes: 30 additions & 0 deletions src/clippy-tracing/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,36 @@ mod tests {
check_file(GIVEN, &path);
}

#[test]
fn fix_skips_extern_c_fn() {
const GIVEN: &str = "extern \"C\" fn handle_signal() {}\nfn normal() {}";
const EXPECTED: &str =
"extern \"C\" fn handle_signal() {}\n#[log_instrument::instrument]\nfn normal() {}";
fix(GIVEN, EXPECTED, None);
}

#[test]
fn check_skips_extern_c_fn() {
const GIVEN: &str = "extern \"C\" fn handle_signal() {}";
let path = setup(GIVEN);
let output = Command::new(BINARY)
.args(["--action", "check", "--path", &path])
.output()
.unwrap();
assert_eq!(output.status.code(), Some(0));
assert_eq!(output.stdout, []);
assert_eq!(output.stderr, []);
remove_file(path).unwrap();
}

#[test]
fn fix_skips_extern_c_fn_in_impl() {
const GIVEN: &str =
"struct S;\nimpl S {\n extern \"C\" fn callback() {}\n fn normal() {}\n}";
const EXPECTED: &str = "struct S;\nimpl S {\n extern \"C\" fn callback() {}\n #[log_instrument::instrument]\n fn normal() {}\n}";
fix(GIVEN, EXPECTED, None);
}

#[test]
fn readme_custom_suffix() {
const GIVEN: &str = r#"fn main() {
Expand Down
42 changes: 38 additions & 4 deletions src/vmm/src/logger/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ impl Logger {

/// Applies the given logger configuration the logger.
pub fn update(&self, config: LoggerConfig) -> Result<(), LoggerUpdateError> {
// Open the file before acquiring the lock so that instrumented callees
// (e.g. open_file_nonblock with tracing enabled) can log without
// re-entering the locked Logger.
let file = config
.log_path
.map(|p| open_file_nonblock(&p))
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config.log_path.map(|p| ...) moves log_path out of config, but config is used again below (level/show_level/show_log_origin/module). This will not compile due to a partial move. Consider borrowing the path (e.g., config.log_path.as_ref() / as_deref()) or destructuring config into locals before opening the file.

Suggested change
.map(|p| open_file_nonblock(&p))
.as_ref()
.map(|p| open_file_nonblock(p))

Copilot uses AI. Check for mistakes.
.transpose()
.map_err(LoggerUpdateError)?;

let mut guard = self.0.lock().unwrap();
log::set_max_level(
config
Expand All @@ -61,11 +70,9 @@ impl Logger {
.unwrap_or(DEFAULT_LEVEL),
);

if let Some(log_path) = config.log_path {
let file = open_file_nonblock(&log_path).map_err(LoggerUpdateError)?;

if let Some(file) = file {
guard.target = Some(file);
};
}

if let Some(show_level) = config.show_level {
guard.format.show_level = show_level;
Expand Down Expand Up @@ -343,6 +350,33 @@ mod tests {
);
}

#[test]
fn test_logger_update_with_log_path() {
let logger = Logger(Mutex::new(LoggerConfiguration {
target: None,
filter: LogFilter { module: None },
format: LogFormat {
show_level: false,
show_log_origin: false,
},
}));

let tmp = vmm_sys_util::tempfile::TempFile::new().unwrap();
let path = tmp.as_path().to_path_buf();

logger
.update(LoggerConfig {
log_path: Some(path),
level: None,
show_level: None,
show_log_origin: None,
module: None,
})
.unwrap();

assert!(logger.0.lock().unwrap().target.is_some());
}

#[test]
fn logger() {
// Get temp file path.
Expand Down