Skip to content

Use def_path_str for def id arg in UnsupportedOpInfo #138732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2025
Merged
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
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const_eval_expected_inbounds_pointer =
}

const_eval_extern_static =
cannot access extern static ({$did})
cannot access extern static `{$did}`
const_eval_extern_type_field = `extern type` field does not have a known offset

const_eval_fn_ptr_call =
Expand Down Expand Up @@ -381,7 +381,7 @@ const_eval_thread_local_access =
thread-local statics cannot be accessed at compile-time

const_eval_thread_local_static =
cannot access thread local static ({$did})
cannot access thread local static `{$did}`
const_eval_too_generic =
encountered overly generic constant
const_eval_too_many_caller_args =
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_const_eval/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,7 @@ impl ReportErrorExt for UnsupportedOpInfo {
UnsupportedOpInfo::ExternStatic(_) => const_eval_extern_static,
}
}

fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
use UnsupportedOpInfo::*;

Expand All @@ -917,9 +918,9 @@ impl ReportErrorExt for UnsupportedOpInfo {
OverwritePartialPointer(ptr) | ReadPartialPointer(ptr) => {
diag.arg("ptr", ptr);
}
ThreadLocalStatic(did) | ExternStatic(did) => {
diag.arg("did", format!("{did:?}"));
}
ThreadLocalStatic(did) | ExternStatic(did) => rustc_middle::ty::tls::with(|tcx| {
diag.arg("did", tcx.def_path_str(did));
Copy link
Member

Choose a reason for hiding this comment

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

Does DefId not implement IntoDiagArg so that we can pass it here directly?

}),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/consts/miri_unleashed/extern-static.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ error[E0080]: could not evaluate static initializer
--> $DIR/extern-static.rs:11:25
|
LL | unsafe { let _val = DATA; }
| ^^^^ cannot access extern static (DefId(0:4 ~ extern_static[c41e]::{extern#0}::DATA))
| ^^^^ cannot access extern static `DATA`

error[E0080]: could not evaluate static initializer
--> $DIR/extern-static.rs:16:14
|
LL | unsafe { DATA = 0; }
| ^^^^^^^^ cannot access extern static (DefId(0:4 ~ extern_static[c41e]::{extern#0}::DATA))
| ^^^^^^^^ cannot access extern static `DATA`

error: aborting due to 2 previous errors

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/consts/miri_unleashed/tls.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ error[E0080]: could not evaluate static initializer
--> $DIR/tls.rs:11:25
|
LL | unsafe { let _val = A; }
| ^ cannot access thread local static (DefId(0:4 ~ tls[ca29]::A))
| ^ cannot access thread local static `A`

error[E0080]: could not evaluate static initializer
--> $DIR/tls.rs:20:26
|
LL | unsafe { let _val = &A; }
| ^ cannot access thread local static (DefId(0:4 ~ tls[ca29]::A))
| ^ cannot access thread local static `A`

warning: skipping const checks
|
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/extern/issue-28324.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0080]: could not evaluate static initializer
--> $DIR/issue-28324.rs:5:23
|
LL | pub static BAZ: u32 = *&error_message_count;
| ^^^^^^^^^^^^^^^^^^^^^ cannot access extern static (DefId(0:4 ~ issue_28324[8ec4]::{extern#0}::error_message_count))
| ^^^^^^^^^^^^^^^^^^^^^ cannot access extern static `error_message_count`

error[E0133]: use of extern static is unsafe and requires unsafe function or block
--> $DIR/issue-28324.rs:5:25
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/statics/issue-14227.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0080]: could not evaluate static initializer
--> $DIR/issue-14227.rs:4:21
|
LL | static CRASH: u32 = symbol;
| ^^^^^^ cannot access extern static (DefId(0:4 ~ issue_14227[1133]::{extern#0}::symbol))
| ^^^^^^ cannot access extern static `symbol`

error[E0133]: use of extern static is unsafe and requires unsafe function or block
--> $DIR/issue-14227.rs:4:21
Expand Down
Loading