Change:
In some external crate, say : Main crate: : With , this gives the following ICE: <details<summary<strongBacktrace</strong</summary<p</p</detailsThis is because the lint to insert the name in the diagnostic message (this delays a good path bug), then the lint because it's in an external macro, which means we don't emit any diagnostic which triggers the good path bug. This ICE is currently preventing rustc from building with enabled. I see several ways to fix this: don't print the function name. It arguably carries little value, with the span already pointing to the offending function call, and brings THIR unsafeck in line with MIR unsafeck (cc ). 't trim the path. This might lead to longer messages but other lints already do this so it is probably acceptable? 't create the lint if we're in an external macro and we know the lint will be cancelled anyway. It's a little hacky and breaks down if changes are made to lint emission. the lint emission API to allow lint messages to be lazily evaluated. label +A-diagnostics +requires-nightly claim <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOT_END --
Error: Label thir-unsafeck can only be set by Rust team members Please file an issue on GitHub at if there's a problem with this bot, or reach out on on Zulip.
Would not trimming the path also be acceptable ? (via )
It looks like some lints are already not trimming paths so this is probably acceptable? I can do that if that's the preferred option.
claim

Discussion:
use rustc_hir as hir; use rustc_middle::mir::BorrowKind; use rustc_middle::thir::*; <ins> use rustc_middle::ty::print::with_no_trimmed_paths; </ins> use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt}; use rustc_session::lint::builtin::{UNSAFE_OP_IN_UNSAFE_FN, UNUSED_UNSAFE}; use rustc_session::lint::Level;

hir_id: hir::HirId, span: Span, ) { <ins> // FIXME: ideally we would want to trim the def paths, but this is not // feasible with the current lint emission API (see issue #106126). </ins> match self { <del> CallToUnsafeFunction(did) if did.is_some() => tcx.emit_spanned_lint( </del> <ins> CallToUnsafeFunction(Some(did)) => tcx.emit_spanned_lint( </ins> UNSAFE_OP_IN_UNSAFE_FN, hir_id, span, UnsafeOpInUnsafeFnCallToUnsafeFunctionRequiresUnsafe { span, <del> function: &tcx.def_path_str(did.unwrap()), </del> <ins> function: &with_no_trimmed_paths!(tcx.def_path_str(*did)), </ins> }, ), <del> CallToUnsafeFunction(..) => tcx.emit_spanned_lint( </del> <ins> CallToUnsafeFunction(None) => tcx.emit_spanned_lint( </ins> UNSAFE_OP_IN_UNSAFE_FN, hir_id, span,

span, UnsafeOpInUnsafeFnCallToFunctionWithRequiresUnsafe { span, <del> function: &tcx.def_path_str(*did), </del> <ins> function: &with_no_trimmed_paths!(tcx.def_path_str(*did)), </ins> }, ), }

unsafe_op_in_unsafe_fn_allowed: bool, ) { match self { <del> CallToUnsafeFunction(did) if did.is_some() && unsafe_op_in_unsafe_fn_allowed => { </del> <ins> CallToUnsafeFunction(Some(did)) if unsafe_op_in_unsafe_fn_allowed => { </ins> tcx.sess.emit_err(CallToUnsafeFunctionRequiresUnsafeUnsafeOpInUnsafeFnAllowed { span, <del> function: &tcx.def_path_str(did.unwrap()), </del> <ins> function: &tcx.def_path_str(*did), </ins> }); } <del> CallToUnsafeFunction(did) if did.is_some() => { </del> <ins> CallToUnsafeFunction(Some(did)) => { </ins> tcx.sess.emit_err(CallToUnsafeFunctionRequiresUnsafe { span, <del> function: &tcx.def_path_str(did.unwrap()), </del> <ins> function: &tcx.def_path_str(*did), </ins> }); } <del> CallToUnsafeFunction(..) if unsafe_op_in_unsafe_fn_allowed => { </del> <ins> CallToUnsafeFunction(None) if unsafe_op_in_unsafe_fn_allowed => { </ins> tcx.sess.emit_err( CallToUnsafeFunctionRequiresUnsafeNamelessUnsafeOpInUnsafeFnAllowed { span }, ); } <del> CallToUnsafeFunction(..) => { </del> <ins> CallToUnsafeFunction(None) => { </ins> tcx.sess.emit_err(CallToUnsafeFunctionRequiresUnsafeNameless { span }); } UseOfInlineAssembly if unsafe_op_in_unsafe_fn_allowed => {

<ins> #[macro_export] macro_rules! foo { () => { unsafe fn __unsf() {} unsafe fn __foo() { __unsf(); } }; } </ins>

<ins> // Regression test for #106126. // check-pass // aux-build:issue-106126.rs #![deny(unsafe_op_in_unsafe_fn)] #[macro_use] extern crate issue_106126; foo!(); fn main() {} </ins>