From 77095e6a50159a6d89b62e35b528545559cf2420 Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Wed, 31 May 2023 14:48:00 +0000 Subject: [PATCH] Address rust-lang/rust#111748 --- cargo-dylint/tests/boundary_toolchains.rs | 5 ++++- driver/src/lib.rs | 15 +++++++++------ utils/linting/src/lib.rs | 3 ++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/cargo-dylint/tests/boundary_toolchains.rs b/cargo-dylint/tests/boundary_toolchains.rs index 574b1983e..efc66ab44 100644 --- a/cargo-dylint/tests/boundary_toolchains.rs +++ b/cargo-dylint/tests/boundary_toolchains.rs @@ -8,7 +8,10 @@ use test_log::test; // smoelius: The channel date is one day later than the `rustc --version` date. // smoelius: Put recent boundaries first, since they're more likely to cause problems. // smoelius: The relevant PRs and merge commits appear before each boundary. -const BOUNDARIES: [(&str, &str); 4] = [ +const BOUNDARIES: [(&str, &str); 5] = [ + // https://github.com/rust-lang/rust/pull/111748 + // https://github.com/rust-lang/rust/commit/70e04bd88d85cab8ed110ace5a278fab106d0ef5 + ("2023-05-29", "2023-05-30"), // https://github.com/rust-lang/rust/pull/111633 // https://github.com/rust-lang/rust/commit/08efb9d652c840715d15954592426e2befe13b36 ("2023-05-18", "2023-05-19"), diff --git a/driver/src/lib.rs b/driver/src/lib.rs index 816e76cb4..5aecf9c02 100644 --- a/driver/src/lib.rs +++ b/driver/src/lib.rs @@ -119,14 +119,17 @@ impl Callbacks { let lib = result.unwrap_or_else(|err| { // smoelius: rust-lang/rust#111633 changed the type of `early_error`'s `msg` // argument from `&str` to `impl Into`. + // smoelius: And rust-lang/rust#111748 made it that `msg` is borrowed for + // `'static`. Since the program is about to exit, it's probably fine to leak the + // string. + let msg = format!( + "could not load library `{}`: {}", + path.to_string_lossy(), + err + ); rustc_session::early_error( rustc_session::config::ErrorOutputType::default(), - format!( - "could not load library `{}`: {}", - path.to_string_lossy(), - err - ) - .as_str(), + Box::leak(msg.into_boxed_str()) as &str, ); }); diff --git a/utils/linting/src/lib.rs b/utils/linting/src/lib.rs index 706281273..ec7b7d0cd 100644 --- a/utils/linting/src/lib.rs +++ b/utils/linting/src/lib.rs @@ -455,9 +455,10 @@ pub fn config_toml(name: &str) -> ConfigResult> { /// etc. includes a call to `init_config`. pub fn init_config(sess: &rustc_session::Session) { try_init_config(sess).unwrap_or_else(|err| { + let msg = format!("could not read configuration file: {err}"); rustc_session::early_error( rustc_session::config::ErrorOutputType::default(), - format!("could not read configuration file: {err}").as_str(), + Box::leak(msg.into_boxed_str()) as &str, ); }); }