Skip to content

Remove some dead or leftover code related to rustc-intrinsic abi removal #139530

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
Apr 10, 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: 3 additions & 1 deletion compiler/rustc_error_codes/src/error_codes/E0622.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#### Note: this error code is no longer emitted by the compiler.

An intrinsic was declared without being a function.

Erroneous code example:

```compile_fail,E0622
```no_run
#![feature(intrinsics)]
#![allow(internal_features)]

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ E0618: 0618,
E0619: 0619,
E0620: 0620,
E0621: 0621,
E0622: 0622,
Copy link
Member

Choose a reason for hiding this comment

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

Please don't remove it but instead add a comment after with // REMOVED: explanation

Copy link
Member

@RalfJung RalfJung Apr 8, 2025

Choose a reason for hiding this comment

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

Dealing with no-longer emitted error codes is a pain. Some time ago, I added some comments at the top of this file to explain what one has to do (which I had to figure out by trial and error as nothing seemed documented). Not sure how to make this more visible.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed but --explain is still supposed to work. ^^'

Copy link
Contributor

@Skgland Skgland Apr 10, 2025

Choose a reason for hiding this comment

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

Wouldn't it make sense to keep this error for misused #[rustc_intrinsic]?
Currently that annotation appears to be silently ignored (or ICE) when misapplied playground

For this reason I hadn't removed the check motioned in #139530 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

This is an internal attribute, having it ICE is entirely fine.

Having it silently ignored is a bit unfortunate; not sure if there's an ways way to avoid that -- probably only after the attribute refactor (Cc @jdonszelmann )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, rustc_* attributes are excluded from the "must have logic to check whether they are used in the correct place" rule. Some have impls regardless, but most do not.

E0622: 0622, // REMOVED: rustc-intrinsic ABI was removed
E0623: 0623,
E0624: 0624,
E0625: 0625,
Expand Down
11 changes: 0 additions & 11 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,6 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
def_id,
tcx.def_ident_span(def_id).unwrap(),
i.name,
ExternAbi::Rust,
)
}
}
Expand Down Expand Up @@ -787,16 +786,6 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
for item in items {
let def_id = item.id.owner_id.def_id;

if tcx.has_attr(def_id, sym::rustc_intrinsic) {
intrinsic::check_intrinsic_type(
tcx,
item.id.owner_id.def_id,
item.span,
item.ident.name,
abi,
);
}
Comment on lines -790 to -798
Copy link
Member

Choose a reason for hiding this comment

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

So this was for extern blocks with functions marked as #[rustc_intrinsic]? That was never even a thing, was it?

So yeah I agree with removing this.^^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it was just something I overlooked in the transition PR where an ABI check was turned into an attr check. Not explicitly added for the attr


let generics = tcx.generics_of(def_id);
let own_counts = generics.own_counts();
if generics.own_params.len() - own_counts.lifetimes != 0 {
Expand Down
33 changes: 9 additions & 24 deletions compiler/rustc_hir_analysis/src/check/intrinsic.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! Type-checking for the `#[rustc_intrinsic]` intrinsics that the compiler exposes.

use rustc_abi::ExternAbi;
use rustc_errors::codes::*;
use rustc_errors::{DiagMessage, struct_span_code_err};
use rustc_hir::{self as hir, Safety};
use rustc_errors::DiagMessage;
use rustc_hir::{self as hir};
use rustc_middle::bug;
use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
use rustc_middle::ty::{self, Ty, TyCtxt};
Expand All @@ -26,17 +25,10 @@ fn equate_intrinsic_type<'tcx>(
sig: ty::PolyFnSig<'tcx>,
) {
let (generics, span) = match tcx.hir_node_by_def_id(def_id) {
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn { generics, .. }, .. })
| hir::Node::ForeignItem(hir::ForeignItem {
kind: hir::ForeignItemKind::Fn(_, _, generics),
..
}) => (tcx.generics_of(def_id), generics.span),
_ => {
struct_span_code_err!(tcx.dcx(), span, E0622, "intrinsic must be a function")
.with_span_label(span, "expected a function")
.emit();
return;
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn { generics, .. }, .. }) => {
(tcx.generics_of(def_id), generics.span)
}
_ => tcx.dcx().span_bug(span, "intrinsic must be a function"),
};
let own_counts = generics.own_counts();

Expand Down Expand Up @@ -70,13 +62,7 @@ fn equate_intrinsic_type<'tcx>(
}

/// Returns the unsafety of the given intrinsic.
pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hir::Safety {
let has_safe_attr = if tcx.has_attr(intrinsic_id, sym::rustc_intrinsic) {
tcx.fn_sig(intrinsic_id).skip_binder().safety()
} else {
// Old-style intrinsics are never safe
Safety::Unsafe
};
fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hir::Safety {
let is_in_list = match tcx.item_name(intrinsic_id.into()) {
// When adding a new intrinsic to this list,
// it's usually worth updating that intrinsic's documentation
Expand Down Expand Up @@ -148,7 +134,7 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -
_ => hir::Safety::Unsafe,
};

if has_safe_attr != is_in_list {
if tcx.fn_sig(intrinsic_id).skip_binder().safety() != is_in_list {
tcx.dcx().struct_span_err(
tcx.def_span(intrinsic_id),
DiagMessage::from(format!(
Expand All @@ -163,12 +149,11 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -

/// Remember to add all intrinsics here, in `compiler/rustc_codegen_llvm/src/intrinsic.rs`,
/// and in `library/core/src/intrinsics.rs`.
pub fn check_intrinsic_type(
pub(crate) fn check_intrinsic_type(
tcx: TyCtxt<'_>,
intrinsic_id: LocalDefId,
span: Span,
intrinsic_name: Symbol,
abi: ExternAbi,
) {
let generics = tcx.generics_of(intrinsic_id);
let param = |n| {
Expand Down Expand Up @@ -706,7 +691,7 @@ pub fn check_intrinsic_type(
};
(n_tps, 0, n_cts, inputs, output, safety)
};
let sig = tcx.mk_fn_sig(inputs, output, false, safety, abi);
let sig = tcx.mk_fn_sig(inputs, output, false, safety, ExternAbi::Rust);
let sig = ty::Binder::bind_with_vars(sig, bound_vars);
equate_intrinsic_type(tcx, span, intrinsic_id, n_tps, n_lts, n_cts, sig)
}
14 changes: 0 additions & 14 deletions tests/ui/error-codes/E0622.rs

This file was deleted.

9 changes: 0 additions & 9 deletions tests/ui/error-codes/E0622.stderr

This file was deleted.

Loading