Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d8db78b

Browse files
committedNov 2, 2024
remove support for extern-block const intrinsics
1 parent 5855aed commit d8db78b

File tree

15 files changed

+101
-213
lines changed

15 files changed

+101
-213
lines changed
 

‎compiler/rustc_attr/src/builtin.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,7 @@ pub fn find_stability(
273273
/// Collects stability info from `rustc_const_stable`/`rustc_const_unstable`/`rustc_promotable`
274274
/// attributes in `attrs`. Returns `None` if no stability attributes are found.
275275
///
276-
/// `is_const_fn` indicates whether this is a function marked as `const`. It will always
277-
/// be false for intrinsics in an `extern` block!
276+
/// `is_const_fn` indicates whether this is a function marked as `const`.
278277
pub fn find_const_stability(
279278
sess: &Session,
280279
attrs: &[Attribute],
@@ -330,7 +329,7 @@ pub fn find_const_stability(
330329
}
331330
}
332331

333-
// Merge promotable and not_exposed_on_stable into stability info
332+
// Merge promotable and const_stable_indirect into stability info
334333
if promotable {
335334
match &mut const_stab {
336335
Some((stab, _)) => stab.promotable = promotable,
@@ -352,10 +351,7 @@ pub fn find_const_stability(
352351
})
353352
}
354353
}
355-
_ => {
356-
// We ignore the `#[rustc_const_stable_indirect]` here, it should be picked up by
357-
// the `default_const_unstable` logic.
358-
}
354+
_ => {}
359355
}
360356
}
361357
// Make sure if `const_stable_indirect` is present, that is recorded. Also make sure all `const

‎compiler/rustc_const_eval/src/const_eval/fn_queries.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,9 @@ fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
2525
hir::Constness::Const
2626
}
2727
hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(impl_), .. }) => impl_.constness,
28-
hir::Node::ForeignItem(hir::ForeignItem { kind: hir::ForeignItemKind::Fn(..), .. }) => {
29-
// Intrinsics use `rustc_const_{un,}stable` attributes to indicate constness. All other
30-
// foreign items cannot be evaluated at compile-time.
31-
let is_const = if tcx.intrinsic(def_id).is_some() {
32-
tcx.lookup_const_stability(def_id).is_some()
33-
} else {
34-
false
35-
};
36-
if is_const { hir::Constness::Const } else { hir::Constness::NotConst }
28+
hir::Node::ForeignItem(_) => {
29+
// Foreign items cannot be evaluated at compile-time.
30+
hir::Constness::NotConst
3731
}
3832
hir::Node::Expr(e) if let hir::ExprKind::Closure(c) = e.kind => c.constness,
3933
_ => {

‎compiler/rustc_passes/src/stability.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
106106
def_id: LocalDefId,
107107
item_sp: Span,
108108
fn_sig: Option<&'tcx hir::FnSig<'tcx>>,
109-
is_foreign_item: bool,
110109
kind: AnnotationKind,
111110
inherit_deprecation: InheritDeprecation,
112111
inherit_const_stability: InheritConstStability,
@@ -175,11 +174,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
175174
// implied), check if the function/method is const or the parent impl block is const.
176175
if let Some(fn_sig) = fn_sig
177176
&& !fn_sig.header.is_const()
178-
// We have to exclude foreign items as they might be intrinsics. Sadly we can't check
179-
// their ABI; `fn_sig.abi` is *not* correct for foreign functions.
180-
&& !is_foreign_item
181177
&& const_stab.is_some()
182-
&& (!self.in_trait_impl || !self.tcx.is_const_fn(def_id.to_def_id()))
183178
{
184179
self.tcx.dcx().emit_err(errors::MissingConstErr { fn_sig_span: fn_sig.span });
185180
}
@@ -398,7 +393,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
398393
ctor_def_id,
399394
i.span,
400395
None,
401-
/* is_foreign_item */ false,
402396
AnnotationKind::Required,
403397
InheritDeprecation::Yes,
404398
InheritConstStability::No,
@@ -417,7 +411,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
417411
i.owner_id.def_id,
418412
i.span,
419413
fn_sig,
420-
/* is_foreign_item */ false,
421414
kind,
422415
InheritDeprecation::Yes,
423416
const_stab_inherit,
@@ -437,7 +430,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
437430
ti.owner_id.def_id,
438431
ti.span,
439432
fn_sig,
440-
/* is_foreign_item */ false,
441433
AnnotationKind::Required,
442434
InheritDeprecation::Yes,
443435
InheritConstStability::No,
@@ -461,7 +453,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
461453
ii.owner_id.def_id,
462454
ii.span,
463455
fn_sig,
464-
/* is_foreign_item */ false,
465456
kind,
466457
InheritDeprecation::Yes,
467458
InheritConstStability::No,
@@ -477,7 +468,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
477468
var.def_id,
478469
var.span,
479470
None,
480-
/* is_foreign_item */ false,
481471
AnnotationKind::Required,
482472
InheritDeprecation::Yes,
483473
InheritConstStability::No,
@@ -488,7 +478,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
488478
ctor_def_id,
489479
var.span,
490480
None,
491-
/* is_foreign_item */ false,
492481
AnnotationKind::Required,
493482
InheritDeprecation::Yes,
494483
InheritConstStability::No,
@@ -507,7 +496,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
507496
s.def_id,
508497
s.span,
509498
None,
510-
/* is_foreign_item */ false,
511499
AnnotationKind::Required,
512500
InheritDeprecation::Yes,
513501
InheritConstStability::No,
@@ -527,7 +515,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
527515
i.owner_id.def_id,
528516
i.span,
529517
fn_sig,
530-
/* is_foreign_item */ true,
531518
AnnotationKind::Required,
532519
InheritDeprecation::Yes,
533520
InheritConstStability::No,
@@ -550,7 +537,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
550537
p.def_id,
551538
p.span,
552539
None,
553-
/* is_foreign_item */ false,
554540
kind,
555541
InheritDeprecation::No,
556542
InheritConstStability::No,
@@ -712,7 +698,6 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index {
712698
CRATE_DEF_ID,
713699
tcx.hir().span(CRATE_HIR_ID),
714700
None,
715-
/* is_foreign_item */ false,
716701
AnnotationKind::Required,
717702
InheritDeprecation::Yes,
718703
InheritConstStability::No,

‎tests/ui/closures/coerce-unsafe-to-closure.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error[E0277]: expected a `FnOnce(&str)` closure, found `unsafe extern "rust-intrinsic" fn(_) -> _ {std::intrinsics::transmute::<_, _>}`
1+
error[E0277]: expected a `FnOnce(&str)` closure, found `unsafe fn(_) -> _ {std::intrinsics::transmute::<_, _>}`
22
--> $DIR/coerce-unsafe-to-closure.rs:2:44
33
|
44
LL | let x: Option<&[u8]> = Some("foo").map(std::mem::transmute);
55
| --- ^^^^^^^^^^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }`
66
| |
77
| required by a bound introduced by this call
88
|
9-
= help: the trait `FnOnce(&str)` is not implemented for fn item `unsafe extern "rust-intrinsic" fn(_) -> _ {std::intrinsics::transmute::<_, _>}`
9+
= help: the trait `FnOnce(&str)` is not implemented for fn item `unsafe fn(_) -> _ {std::intrinsics::transmute::<_, _>}`
1010
= note: unsafe function cannot be called generically without an unsafe block
1111
note: required by a bound in `Option::<T>::map`
1212
--> $SRC_DIR/core/src/option.rs:LL:COL
Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
11
#![feature(staged_api, rustc_attrs, intrinsics)]
22
#![stable(since="1.0.0", feature = "stable")]
33

4-
#[stable(since="1.0.0", feature = "stable")]
5-
pub mod old_way {
6-
extern "rust-intrinsic" {
7-
#[unstable(feature = "unstable", issue = "42")]
8-
pub fn size_of_val<T>(x: *const T) -> usize;
9-
10-
#[unstable(feature = "unstable", issue = "42")]
11-
#[rustc_const_unstable(feature = "unstable", issue = "42")]
12-
pub fn min_align_of_val<T>(x: *const T) -> usize;
13-
}
14-
}
15-
16-
#[stable(since="1.0.0", feature = "stable")]
17-
pub mod new_way {
18-
#[unstable(feature = "unstable", issue = "42")]
19-
#[rustc_intrinsic]
20-
pub const unsafe fn size_of_val<T>(x: *const T) -> usize { 42 }
21-
22-
#[unstable(feature = "unstable", issue = "42")]
23-
#[rustc_const_unstable(feature = "unstable", issue = "42")]
24-
#[rustc_intrinsic]
25-
pub const unsafe fn min_align_of_val<T>(x: *const T) -> usize { 42 }
26-
}
4+
#[unstable(feature = "unstable", issue = "42")]
5+
#[rustc_intrinsic]
6+
pub const unsafe fn size_of_val<T>(x: *const T) -> usize { 42 }
7+
8+
#[unstable(feature = "unstable", issue = "42")]
9+
#[rustc_const_unstable(feature = "unstable", issue = "42")]
10+
#[rustc_intrinsic]
11+
pub const unsafe fn min_align_of_val<T>(x: *const T) -> usize { 42 }

‎tests/ui/consts/const-eval/simd/insert_extract.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ run-pass
22
#![feature(repr_simd)]
3-
#![feature(intrinsics)]
3+
#![feature(intrinsics, rustc_attrs)]
44
#![feature(staged_api)]
55
#![stable(feature = "foo", since = "1.3.37")]
66
#![allow(non_camel_case_types)]
@@ -10,14 +10,18 @@
1010
#[repr(simd)] struct u16x2([u16; 2]);
1111
#[repr(simd)] struct f32x4([f32; 4]);
1212

13-
extern "rust-intrinsic" {
14-
#[stable(feature = "foo", since = "1.3.37")]
15-
#[rustc_const_stable(feature = "foo", since = "1.3.37")]
16-
fn simd_insert<T, U>(x: T, idx: u32, val: U) -> T;
13+
#[stable(feature = "foo", since = "1.3.37")]
14+
#[rustc_const_stable(feature = "foo", since = "1.3.37")]
15+
#[rustc_intrinsic]
16+
const unsafe fn simd_insert<T, U>(_x: T, _idx: u32, _val: U) -> T {
17+
unimplemented!()
18+
}
1719

18-
#[stable(feature = "foo", since = "1.3.37")]
19-
#[rustc_const_stable(feature = "foo", since = "1.3.37")]
20-
fn simd_extract<T, U>(x: T, idx: u32) -> U;
20+
#[stable(feature = "foo", since = "1.3.37")]
21+
#[rustc_const_stable(feature = "foo", since = "1.3.37")]
22+
#[rustc_intrinsic]
23+
const unsafe fn simd_extract<T, U>(_x: T, _idx: u32) -> U {
24+
unimplemented!()
2125
}
2226

2327
fn main() {

‎tests/ui/consts/const-unstable-intrinsic.rs

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,63 +14,39 @@ fn main() {
1414
const fn const_main() {
1515
let x = 42;
1616
unsafe {
17-
unstable_intrinsic::old_way::size_of_val(&x);
18-
//~^ERROR: unstable library feature 'unstable'
19-
//~|ERROR: cannot call non-const intrinsic
20-
unstable_intrinsic::old_way::min_align_of_val(&x);
21-
//~^ERROR: unstable library feature 'unstable'
22-
//~|ERROR: not yet stable as a const intrinsic
23-
unstable_intrinsic::new_way::size_of_val(&x);
17+
unstable_intrinsic::size_of_val(&x);
2418
//~^ERROR: unstable library feature 'unstable'
2519
//~|ERROR: cannot be (indirectly) exposed to stable
26-
unstable_intrinsic::new_way::min_align_of_val(&x);
20+
unstable_intrinsic::min_align_of_val(&x);
2721
//~^ERROR: unstable library feature 'unstable'
2822
//~|ERROR: not yet stable as a const intrinsic
2923

30-
old_way::size_of_val(&x);
31-
//~^ERROR: cannot call non-const intrinsic
32-
old_way::min_align_of_val(&x);
33-
//~^ERROR: cannot use `#[feature(local)]`
34-
new_way::size_of_val(&x);
24+
size_of_val(&x);
3525
//~^ERROR: cannot be (indirectly) exposed to stable
36-
new_way::min_align_of_val(&x);
26+
min_align_of_val(&x);
3727
//~^ERROR: cannot use `#[feature(local)]`
3828
}
3929
}
4030

41-
#[stable(since="1.0.0", feature = "stable")]
42-
pub mod old_way {
43-
extern "rust-intrinsic" {
44-
#[unstable(feature = "local", issue = "42")]
45-
pub fn size_of_val<T>(x: *const T) -> usize;
46-
47-
#[unstable(feature = "local", issue = "42")]
48-
#[rustc_const_unstable(feature = "local", issue = "42")]
49-
pub fn min_align_of_val<T>(x: *const T) -> usize;
50-
}
51-
}
52-
53-
#[stable(since="1.0.0", feature = "stable")]
54-
pub mod new_way {
55-
#[unstable(feature = "local", issue = "42")]
56-
#[rustc_intrinsic]
57-
pub const unsafe fn size_of_val<T>(x: *const T) -> usize { 42 }
31+
#[unstable(feature = "local", issue = "42")]
32+
#[rustc_intrinsic]
33+
pub const unsafe fn size_of_val<T>(x: *const T) -> usize { 42 }
5834

59-
#[unstable(feature = "local", issue = "42")]
60-
#[rustc_const_unstable(feature = "local", issue = "42")]
61-
#[rustc_intrinsic]
62-
pub const unsafe fn min_align_of_val<T>(x: *const T) -> usize { 42 }
63-
}
35+
#[unstable(feature = "local", issue = "42")]
36+
#[rustc_const_unstable(feature = "local", issue = "42")]
37+
#[rustc_intrinsic]
38+
pub const unsafe fn min_align_of_val<T>(x: *const T) -> usize { 42 }
6439

6540
#[stable(feature = "rust1", since = "1.0.0")]
6641
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
6742
#[inline]
6843
pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
6944
// Const stability attributes are not inherited from parent items.
70-
extern "rust-intrinsic" {
71-
fn copy<T>(src: *const T, dst: *mut T, count: usize);
45+
#[rustc_intrinsic]
46+
const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
47+
unimplemented!()
7248
}
7349

7450
unsafe { copy(src, dst, count) }
75-
//~^ ERROR cannot call non-const intrinsic
51+
//~^ ERROR cannot be (indirectly) exposed to stable
7652
}
Lines changed: 22 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0658]: use of unstable library feature 'unstable'
22
--> $DIR/const-unstable-intrinsic.rs:17:9
33
|
4-
LL | unstable_intrinsic::old_way::size_of_val(&x);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
LL | unstable_intrinsic::size_of_val(&x);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #42 <https://github.com/rust-lang/rust/issues/42> for more information
88
= help: add `#![feature(unstable)]` to the crate attributes to enable
@@ -11,99 +11,42 @@ LL | unstable_intrinsic::old_way::size_of_val(&x);
1111
error[E0658]: use of unstable library feature 'unstable'
1212
--> $DIR/const-unstable-intrinsic.rs:20:9
1313
|
14-
LL | unstable_intrinsic::old_way::min_align_of_val(&x);
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16-
|
17-
= note: see issue #42 <https://github.com/rust-lang/rust/issues/42> for more information
18-
= help: add `#![feature(unstable)]` to the crate attributes to enable
19-
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
20-
21-
error[E0658]: use of unstable library feature 'unstable'
22-
--> $DIR/const-unstable-intrinsic.rs:23:9
23-
|
24-
LL | unstable_intrinsic::new_way::size_of_val(&x);
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26-
|
27-
= note: see issue #42 <https://github.com/rust-lang/rust/issues/42> for more information
28-
= help: add `#![feature(unstable)]` to the crate attributes to enable
29-
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
30-
31-
error[E0658]: use of unstable library feature 'unstable'
32-
--> $DIR/const-unstable-intrinsic.rs:26:9
33-
|
34-
LL | unstable_intrinsic::new_way::min_align_of_val(&x);
35-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
LL | unstable_intrinsic::min_align_of_val(&x);
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3616
|
3717
= note: see issue #42 <https://github.com/rust-lang/rust/issues/42> for more information
3818
= help: add `#![feature(unstable)]` to the crate attributes to enable
3919
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
4020

41-
error: cannot call non-const intrinsic `size_of_val` in constant functions
21+
error: intrinsic `unstable_intrinsic::size_of_val` cannot be (indirectly) exposed to stable
4222
--> $DIR/const-unstable-intrinsic.rs:17:9
4323
|
44-
LL | unstable_intrinsic::old_way::size_of_val(&x);
45-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
46-
47-
error: `min_align_of_val` is not yet stable as a const intrinsic
48-
--> $DIR/const-unstable-intrinsic.rs:20:9
49-
|
50-
LL | unstable_intrinsic::old_way::min_align_of_val(&x);
51-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
52-
|
53-
= help: add `#![feature(unstable)]` to the crate attributes to enable
54-
55-
error: intrinsic `unstable_intrinsic::new_way::size_of_val` cannot be (indirectly) exposed to stable
56-
--> $DIR/const-unstable-intrinsic.rs:23:9
57-
|
58-
LL | unstable_intrinsic::new_way::size_of_val(&x);
59-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24+
LL | unstable_intrinsic::size_of_val(&x);
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6026
|
6127
= help: mark the caller as `#[rustc_const_unstable]`, or mark the intrinsic `#[rustc_const_stable_indirect]` (but this requires team approval)
6228

6329
error: `min_align_of_val` is not yet stable as a const intrinsic
64-
--> $DIR/const-unstable-intrinsic.rs:26:9
30+
--> $DIR/const-unstable-intrinsic.rs:20:9
6531
|
66-
LL | unstable_intrinsic::new_way::min_align_of_val(&x);
67-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32+
LL | unstable_intrinsic::min_align_of_val(&x);
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6834
|
6935
= help: add `#![feature(unstable)]` to the crate attributes to enable
7036

71-
error: cannot call non-const intrinsic `size_of_val` in constant functions
72-
--> $DIR/const-unstable-intrinsic.rs:30:9
73-
|
74-
LL | old_way::size_of_val(&x);
75-
| ^^^^^^^^^^^^^^^^^^^^^^^^
76-
77-
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(local)]`
78-
--> $DIR/const-unstable-intrinsic.rs:32:9
79-
|
80-
LL | old_way::min_align_of_val(&x);
81-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
82-
|
83-
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
37+
error: intrinsic `size_of_val` cannot be (indirectly) exposed to stable
38+
--> $DIR/const-unstable-intrinsic.rs:24:9
8439
|
85-
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
86-
LL | const fn const_main() {
87-
|
88-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
89-
|
90-
LL + #[rustc_allow_const_fn_unstable(local)]
91-
LL | const fn const_main() {
92-
|
93-
94-
error: intrinsic `new_way::size_of_val` cannot be (indirectly) exposed to stable
95-
--> $DIR/const-unstable-intrinsic.rs:34:9
96-
|
97-
LL | new_way::size_of_val(&x);
98-
| ^^^^^^^^^^^^^^^^^^^^^^^^
40+
LL | size_of_val(&x);
41+
| ^^^^^^^^^^^^^^^
9942
|
10043
= help: mark the caller as `#[rustc_const_unstable]`, or mark the intrinsic `#[rustc_const_stable_indirect]` (but this requires team approval)
10144

10245
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(local)]`
103-
--> $DIR/const-unstable-intrinsic.rs:36:9
46+
--> $DIR/const-unstable-intrinsic.rs:26:9
10447
|
105-
LL | new_way::min_align_of_val(&x);
106-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
48+
LL | min_align_of_val(&x);
49+
| ^^^^^^^^^^^^^^^^^^^^
10750
|
10851
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
10952
|
@@ -116,12 +59,14 @@ LL + #[rustc_allow_const_fn_unstable(local)]
11659
LL | const fn const_main() {
11760
|
11861

119-
error: cannot call non-const intrinsic `copy` in constant functions
120-
--> $DIR/const-unstable-intrinsic.rs:74:14
62+
error: intrinsic `copy::copy` cannot be (indirectly) exposed to stable
63+
--> $DIR/const-unstable-intrinsic.rs:50:14
12164
|
12265
LL | unsafe { copy(src, dst, count) }
12366
| ^^^^^^^^^^^^^^^^^^^^^
67+
|
68+
= help: mark the caller as `#[rustc_const_unstable]`, or mark the intrinsic `#[rustc_const_stable_indirect]` (but this requires team approval)
12469

125-
error: aborting due to 13 previous errors
70+
error: aborting due to 7 previous errors
12671

12772
For more information about this error, try `rustc --explain E0658`.

‎tests/ui/consts/copy-intrinsic.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
#![stable(feature = "dummy", since = "1.0.0")]
22

33
// ignore-tidy-linelength
4-
#![feature(intrinsics, staged_api)]
4+
#![feature(intrinsics, staged_api, rustc_attrs)]
55
use std::mem;
66

7-
extern "rust-intrinsic" {
8-
#[stable(feature = "dummy", since = "1.0.0")]
9-
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
10-
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
7+
#[stable(feature = "dummy", since = "1.0.0")]
8+
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
9+
#[rustc_intrinsic]
10+
const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
11+
unimplemented!()
12+
}
1113

12-
#[stable(feature = "dummy", since = "1.0.0")]
13-
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
14-
fn copy<T>(src: *const T, dst: *mut T, count: usize);
14+
#[stable(feature = "dummy", since = "1.0.0")]
15+
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
16+
#[rustc_intrinsic]
17+
const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
18+
unimplemented!()
1519
}
1620

1721
const COPY_ZERO: () = unsafe {

‎tests/ui/consts/copy-intrinsic.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error[E0080]: evaluation of constant value failed
2-
--> $DIR/copy-intrinsic.rs:30:5
2+
--> $DIR/copy-intrinsic.rs:34:5
33
|
44
LL | copy_nonoverlapping(0x100 as *const i32, dangle, 1);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: expected a pointer to 4 bytes of memory, but got 0x100[noalloc] which is a dangling pointer (it has no provenance)
66

77
error[E0080]: evaluation of constant value failed
8-
--> $DIR/copy-intrinsic.rs:39:5
8+
--> $DIR/copy-intrinsic.rs:43:5
99
|
1010
LL | copy_nonoverlapping(dangle, 0x100 as *mut i32, 1);
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: expected a pointer to 4 bytes of memory, but got ALLOC0+0x28 which is at or beyond the end of the allocation of size 4 bytes
1212

1313
error[E0080]: evaluation of constant value failed
14-
--> $DIR/copy-intrinsic.rs:46:5
14+
--> $DIR/copy-intrinsic.rs:50:5
1515
|
1616
LL | copy(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1));
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow computing total size of `copy`
1818

1919
error[E0080]: evaluation of constant value failed
20-
--> $DIR/copy-intrinsic.rs:52:5
20+
--> $DIR/copy-intrinsic.rs:56:5
2121
|
2222
LL | copy_nonoverlapping(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1));
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow computing total size of `copy_nonoverlapping`

‎tests/ui/intrinsics/reify-intrinsic.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ LL | let _: unsafe extern "rust-intrinsic" fn(isize) -> usize = std::mem::tr
77
| expected due to this
88
|
99
= note: expected fn pointer `unsafe extern "rust-intrinsic" fn(isize) -> usize`
10-
found fn item `unsafe extern "rust-intrinsic" fn(_) -> _ {std::intrinsics::transmute::<_, _>}`
10+
found fn item `unsafe fn(_) -> _ {std::intrinsics::transmute::<_, _>}`
1111

12-
error[E0606]: casting `unsafe extern "rust-intrinsic" fn(_) -> _ {std::intrinsics::transmute::<_, _>}` as `unsafe extern "rust-intrinsic" fn(isize) -> usize` is invalid
12+
error[E0606]: casting `unsafe fn(_) -> _ {std::intrinsics::transmute::<_, _>}` as `unsafe extern "rust-intrinsic" fn(isize) -> usize` is invalid
1313
--> $DIR/reify-intrinsic.rs:11:13
1414
|
1515
LL | let _ = std::mem::transmute as unsafe extern "rust-intrinsic" fn(isize) -> usize;

‎tests/ui/repr/16-bit-repr-c-enum.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ enum Foo {
2121
Bar,
2222
}
2323

24-
extern "rust-intrinsic" {
25-
#[stable(feature = "intrinsics_for_test", since = "3.3.3")]
26-
#[rustc_const_stable(feature = "intrinsics_for_test", since = "3.3.3")]
27-
#[rustc_safe_intrinsic]
28-
fn size_of<T>() -> usize;
24+
#[stable(feature = "intrinsics_for_test", since = "3.3.3")]
25+
#[rustc_const_stable(feature = "intrinsics_for_test", since = "3.3.3")]
26+
#[rustc_intrinsic]
27+
#[rustc_intrinsic_must_be_overridden]
28+
const fn size_of<T>() -> usize {
29+
loop {}
2930
}
3031

3132
#[lang="sized"]

‎tests/ui/stability-attribute/missing-const-stability.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,4 @@ impl const Bar for Foo {
3636
pub const unsafe fn size_of_val<T>(x: *const T) -> usize { 42 }
3737
//~^ ERROR function has missing const stability attribute
3838

39-
extern "rust-intrinsic" {
40-
#[stable(feature = "stable", since = "1.0.0")]
41-
#[rustc_const_stable_indirect]
42-
pub fn min_align_of_val<T>(x: *const T) -> usize;
43-
}
44-
4539
fn main() {}

‎tests/ui/target-feature/feature-hierarchy.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ trait Sized {}
1818
trait Copy {}
1919
impl Copy for bool {}
2020

21-
extern "rust-intrinsic" {
22-
#[stable(feature = "test", since = "1.0.0")]
23-
#[rustc_const_stable(feature = "test", since = "1.0.0")]
24-
fn unreachable() -> !;
21+
#[stable(feature = "test", since = "1.0.0")]
22+
#[rustc_const_stable(feature = "test", since = "1.0.0")]
23+
#[rustc_intrinsic]
24+
#[rustc_intrinsic_must_be_overridden]
25+
const unsafe fn unreachable() -> ! {
26+
loop {}
2527
}
2628

2729
#[rustc_builtin_macro]

‎tests/ui/target-feature/no-llvm-leaks.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ trait Sized {}
1616
trait Copy {}
1717
impl Copy for bool {}
1818

19-
extern "rust-intrinsic" {
20-
#[stable(feature = "test", since = "1.0.0")]
21-
#[rustc_const_stable(feature = "test", since = "1.0.0")]
22-
fn unreachable() -> !;
19+
#[stable(feature = "test", since = "1.0.0")]
20+
#[rustc_const_stable(feature = "test", since = "1.0.0")]
21+
#[rustc_intrinsic]
22+
#[rustc_intrinsic_must_be_overridden]
23+
const unsafe fn unreachable() -> ! {
24+
loop {}
2325
}
2426

2527
#[rustc_builtin_macro]

0 commit comments

Comments
 (0)
Please sign in to comment.