Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e3029ab
Improve duplicate derive Copy/Clone diagnostics
VulnBandit Oct 2, 2024
10b60eb
add third help hint to diagnostic error E0027
duncpro Oct 22, 2024
a645342
More test for non-exhaustive C-like enums in FFI
nyurik Oct 29, 2024
981dc02
Revert "Avoid nested replacement ranges" from #129346.
nnethercote Nov 4, 2024
e9161db
Fix invalid coverage computation when `--output-format=json` is enabled
GuillaumeGomez Nov 4, 2024
0eff07e
Add UI regressions tests for rustdoc `--show-coverage` option
GuillaumeGomez Nov 4, 2024
5dfbc03
Rename `DocContext::is_json` into `DocContext::is_json_output`
GuillaumeGomez Nov 4, 2024
c88ba28
document `type_implements_trait`
mejrs Nov 4, 2024
75c943e
Update books
rustbot Nov 4, 2024
4872b6b
Improve example of `impl Pattern for &[char]`
eduardosm Nov 4, 2024
107b4fd
docs: fix grammar in doc comment at unix/process.rs
SnirBroshi Nov 4, 2024
f4b72dc
Move two attribute lints to be early pass (post expansion)
jdonszelmann Nov 4, 2024
7934f26
convert all const-callable intrinsics into the new form (without exte…
RalfJung Nov 1, 2024
10723c2
remove support for extern-block const intrinsics
RalfJung Nov 1, 2024
1f0ed2b
add new rustc_const_stable_intrinsic attribute for const-stable intri…
RalfJung Nov 1, 2024
5069434
most const intrinsics don't need an explicit rustc_const_unstable any…
RalfJung Nov 2, 2024
a741b33
when an intrinsic has a const-stable fallback body, we can easily exp…
RalfJung Nov 2, 2024
e37a3a8
Explain how to evaluate an obligation
mejrs Nov 5, 2024
972fef2
Rollup merge of #131153 - VulnBandit:copy_impl_vuln, r=compiler-errors
workingjubilee Nov 5, 2024
c17cf1d
Rollup merge of #132025 - duncpro:E0027, r=compiler-errors
workingjubilee Nov 5, 2024
56aa51e
Rollup merge of #132303 - nyurik:non-exhaustive-err, r=compiler-errors
workingjubilee Nov 5, 2024
23ef001
Rollup merge of #132492 - RalfJung:const-intrinsics, r=compiler-errors
workingjubilee Nov 5, 2024
f8ac0e7
Rollup merge of #132587 - nnethercote:revert-avoid-nested-replacement…
workingjubilee Nov 5, 2024
b3fc9e6
Rollup merge of #132596 - GuillaumeGomez:show-coverage, r=notriddle
workingjubilee Nov 5, 2024
d70e2e3
Rollup merge of #132598 - jdonszelmann:move-lints-to-early, r=xFrednet
workingjubilee Nov 5, 2024
3d4dd74
Rollup merge of #132601 - rustbot:docs-update, r=ehuss
workingjubilee Nov 5, 2024
67477ca
Rollup merge of #132606 - eduardosm:char-slice-str-pattern-doc, r=tgr…
workingjubilee Nov 5, 2024
33ebfff
Rollup merge of #132608 - mejrs:type_impls_trait, r=compiler-errors
workingjubilee Nov 5, 2024
7bff6ff
Rollup merge of #132609 - NotWearingPants:patch-1, r=Amanieu
workingjubilee Nov 5, 2024
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
Prev Previous commit
Next Next commit
remove support for extern-block const intrinsics
  • Loading branch information
RalfJung committed Nov 4, 2024
commit 10723c28964d582814ea8e07dbd8fa7367e0eaee
10 changes: 3 additions & 7 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ pub fn find_stability(
/// Collects stability info from `rustc_const_stable`/`rustc_const_unstable`/`rustc_promotable`
/// attributes in `attrs`. Returns `None` if no stability attributes are found.
///
/// `is_const_fn` indicates whether this is a function marked as `const`. It will always
/// be false for intrinsics in an `extern` block!
/// `is_const_fn` indicates whether this is a function marked as `const`.
pub fn find_const_stability(
sess: &Session,
attrs: &[Attribute],
Expand Down Expand Up @@ -330,7 +329,7 @@ pub fn find_const_stability(
}
}

// Merge promotable and not_exposed_on_stable into stability info
// Merge promotable and const_stable_indirect into stability info
if promotable {
match &mut const_stab {
Some((stab, _)) => stab.promotable = promotable,
Expand All @@ -352,10 +351,7 @@ pub fn find_const_stability(
})
}
}
_ => {
// We ignore the `#[rustc_const_stable_indirect]` here, it should be picked up by
// the `default_const_unstable` logic.
}
_ => {}
}
}
// Make sure if `const_stable_indirect` is present, that is recorded. Also make sure all `const
Expand Down
12 changes: 3 additions & 9 deletions compiler/rustc_const_eval/src/const_eval/fn_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@ fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
hir::Constness::Const
}
hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(impl_), .. }) => impl_.constness,
hir::Node::ForeignItem(hir::ForeignItem { kind: hir::ForeignItemKind::Fn(..), .. }) => {
// Intrinsics use `rustc_const_{un,}stable` attributes to indicate constness. All other
// foreign items cannot be evaluated at compile-time.
let is_const = if tcx.intrinsic(def_id).is_some() {
tcx.lookup_const_stability(def_id).is_some()
} else {
false
};
if is_const { hir::Constness::Const } else { hir::Constness::NotConst }
hir::Node::ForeignItem(_) => {
// Foreign items cannot be evaluated at compile-time.
hir::Constness::NotConst
}
hir::Node::Expr(e) if let hir::ExprKind::Closure(c) = e.kind => c.constness,
_ => {
Expand Down
15 changes: 0 additions & 15 deletions compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
def_id: LocalDefId,
item_sp: Span,
fn_sig: Option<&'tcx hir::FnSig<'tcx>>,
is_foreign_item: bool,
kind: AnnotationKind,
inherit_deprecation: InheritDeprecation,
inherit_const_stability: InheritConstStability,
Expand Down Expand Up @@ -175,11 +174,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
// implied), check if the function/method is const or the parent impl block is const.
if let Some(fn_sig) = fn_sig
&& !fn_sig.header.is_const()
// We have to exclude foreign items as they might be intrinsics. Sadly we can't check
// their ABI; `fn_sig.abi` is *not* correct for foreign functions.
&& !is_foreign_item
&& const_stab.is_some()
&& (!self.in_trait_impl || !self.tcx.is_const_fn(def_id.to_def_id()))
{
self.tcx.dcx().emit_err(errors::MissingConstErr { fn_sig_span: fn_sig.span });
}
Expand Down Expand Up @@ -398,7 +393,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
ctor_def_id,
i.span,
None,
/* is_foreign_item */ false,
AnnotationKind::Required,
InheritDeprecation::Yes,
InheritConstStability::No,
Expand All @@ -417,7 +411,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
i.owner_id.def_id,
i.span,
fn_sig,
/* is_foreign_item */ false,
kind,
InheritDeprecation::Yes,
const_stab_inherit,
Expand All @@ -437,7 +430,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
ti.owner_id.def_id,
ti.span,
fn_sig,
/* is_foreign_item */ false,
AnnotationKind::Required,
InheritDeprecation::Yes,
InheritConstStability::No,
Expand All @@ -461,7 +453,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
ii.owner_id.def_id,
ii.span,
fn_sig,
/* is_foreign_item */ false,
kind,
InheritDeprecation::Yes,
InheritConstStability::No,
Expand All @@ -477,7 +468,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
var.def_id,
var.span,
None,
/* is_foreign_item */ false,
AnnotationKind::Required,
InheritDeprecation::Yes,
InheritConstStability::No,
Expand All @@ -488,7 +478,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
ctor_def_id,
var.span,
None,
/* is_foreign_item */ false,
AnnotationKind::Required,
InheritDeprecation::Yes,
InheritConstStability::No,
Expand All @@ -507,7 +496,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
s.def_id,
s.span,
None,
/* is_foreign_item */ false,
AnnotationKind::Required,
InheritDeprecation::Yes,
InheritConstStability::No,
Expand All @@ -527,7 +515,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
i.owner_id.def_id,
i.span,
fn_sig,
/* is_foreign_item */ true,
AnnotationKind::Required,
InheritDeprecation::Yes,
InheritConstStability::No,
Expand All @@ -550,7 +537,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
p.def_id,
p.span,
None,
/* is_foreign_item */ false,
kind,
InheritDeprecation::No,
InheritConstStability::No,
Expand Down Expand Up @@ -712,7 +698,6 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index {
CRATE_DEF_ID,
tcx.hir().span(CRATE_HIR_ID),
None,
/* is_foreign_item */ false,
AnnotationKind::Required,
InheritDeprecation::Yes,
InheritConstStability::No,
Expand Down
28 changes: 17 additions & 11 deletions tests/rustdoc/const-intrinsic.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
#![feature(intrinsics)]
#![feature(intrinsics, rustc_attrs)]
#![feature(staged_api)]

#![crate_name = "foo"]
#![stable(since="1.0.0", feature="rust1")]

extern "rust-intrinsic" {
//@ has 'foo/fn.transmute.html'
//@ has - '//pre[@class="rust item-decl"]' 'pub const unsafe extern "rust-intrinsic" fn transmute<T, U>(_: T) -> U'
#[stable(since="1.0.0", feature="rust1")]
#[rustc_const_stable(feature = "const_transmute", since = "1.56.0")]
pub fn transmute<T, U>(_: T) -> U;
//@ has 'foo/fn.transmute.html'
//@ has - '//pre[@class="rust item-decl"]' 'pub const unsafe fn transmute<T, U>(_: T) -> U'
#[stable(since="1.0.0", feature="rust1")]
#[rustc_const_stable(feature = "const_transmute", since = "1.56.0")]
#[rustc_intrinsic]
#[rustc_intrinsic_must_be_overridden]
pub const unsafe fn transmute<T, U>(_: T) -> U {
loop {}
}

//@ has 'foo/fn.unreachable.html'
//@ has - '//pre[@class="rust item-decl"]' 'pub unsafe extern "rust-intrinsic" fn unreachable() -> !'
#[stable(since="1.0.0", feature="rust1")]
pub fn unreachable() -> !;
//@ has 'foo/fn.unreachable.html'
//@ has - '//pre[@class="rust item-decl"]' 'pub unsafe fn unreachable() -> !'
#[stable(since="1.0.0", feature="rust1")]
#[rustc_intrinsic]
#[rustc_intrinsic_must_be_overridden]
pub unsafe fn unreachable() -> ! {
loop {}
}

extern "C" {
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/closures/coerce-unsafe-to-closure.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error[E0277]: expected a `FnOnce(&str)` closure, found `unsafe extern "rust-intrinsic" fn(_) -> _ {std::intrinsics::transmute::<_, _>}`
error[E0277]: expected a `FnOnce(&str)` closure, found `unsafe fn(_) -> _ {std::intrinsics::transmute::<_, _>}`
--> $DIR/coerce-unsafe-to-closure.rs:2:44
|
LL | let x: Option<&[u8]> = Some("foo").map(std::mem::transmute);
| --- ^^^^^^^^^^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }`
| |
| required by a bound introduced by this call
|
= help: the trait `FnOnce(&str)` is not implemented for fn item `unsafe extern "rust-intrinsic" fn(_) -> _ {std::intrinsics::transmute::<_, _>}`
= help: the trait `FnOnce(&str)` is not implemented for fn item `unsafe fn(_) -> _ {std::intrinsics::transmute::<_, _>}`
= note: unsafe function cannot be called generically without an unsafe block
note: required by a bound in `Option::<T>::map`
--> $SRC_DIR/core/src/option.rs:LL:COL
Expand Down
31 changes: 8 additions & 23 deletions tests/ui/consts/auxiliary/unstable_intrinsic.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
#![feature(staged_api, rustc_attrs, intrinsics)]
#![stable(since="1.0.0", feature = "stable")]

#[stable(since="1.0.0", feature = "stable")]
pub mod old_way {
extern "rust-intrinsic" {
#[unstable(feature = "unstable", issue = "42")]
pub fn size_of_val<T>(x: *const T) -> usize;

#[unstable(feature = "unstable", issue = "42")]
#[rustc_const_unstable(feature = "unstable", issue = "42")]
pub fn min_align_of_val<T>(x: *const T) -> usize;
}
}

#[stable(since="1.0.0", feature = "stable")]
pub mod new_way {
#[unstable(feature = "unstable", issue = "42")]
#[rustc_intrinsic]
pub const unsafe fn size_of_val<T>(x: *const T) -> usize { 42 }

#[unstable(feature = "unstable", issue = "42")]
#[rustc_const_unstable(feature = "unstable", issue = "42")]
#[rustc_intrinsic]
pub const unsafe fn min_align_of_val<T>(x: *const T) -> usize { 42 }
}
#[unstable(feature = "unstable", issue = "42")]
#[rustc_intrinsic]
pub const unsafe fn size_of_val<T>(x: *const T) -> usize { 42 }

#[unstable(feature = "unstable", issue = "42")]
#[rustc_const_unstable(feature = "unstable", issue = "42")]
#[rustc_intrinsic]
pub const unsafe fn min_align_of_val<T>(x: *const T) -> usize { 42 }
20 changes: 12 additions & 8 deletions tests/ui/consts/const-eval/simd/insert_extract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ run-pass
#![feature(repr_simd)]
#![feature(intrinsics)]
#![feature(intrinsics, rustc_attrs)]
#![feature(staged_api)]
#![stable(feature = "foo", since = "1.3.37")]
#![allow(non_camel_case_types)]
Expand All @@ -10,14 +10,18 @@
#[repr(simd)] struct u16x2([u16; 2]);
#[repr(simd)] struct f32x4([f32; 4]);

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

#[stable(feature = "foo", since = "1.3.37")]
#[rustc_const_stable(feature = "foo", since = "1.3.37")]
fn simd_extract<T, U>(x: T, idx: u32) -> U;
#[stable(feature = "foo", since = "1.3.37")]
#[rustc_const_stable(feature = "foo", since = "1.3.37")]
#[rustc_intrinsic]
const unsafe fn simd_extract<T, U>(_x: T, _idx: u32) -> U {
unimplemented!()
}

fn main() {
Expand Down
54 changes: 15 additions & 39 deletions tests/ui/consts/const-unstable-intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,39 @@ fn main() {
const fn const_main() {
let x = 42;
unsafe {
unstable_intrinsic::old_way::size_of_val(&x);
//~^ERROR: unstable library feature `unstable`
//~|ERROR: cannot call non-const intrinsic
unstable_intrinsic::old_way::min_align_of_val(&x);
//~^ERROR: unstable library feature `unstable`
//~|ERROR: not yet stable as a const intrinsic
unstable_intrinsic::new_way::size_of_val(&x);
unstable_intrinsic::size_of_val(&x);
//~^ERROR: unstable library feature `unstable`
//~|ERROR: cannot be (indirectly) exposed to stable
unstable_intrinsic::new_way::min_align_of_val(&x);
unstable_intrinsic::min_align_of_val(&x);
//~^ERROR: unstable library feature `unstable`
//~|ERROR: not yet stable as a const intrinsic

old_way::size_of_val(&x);
//~^ERROR: cannot call non-const intrinsic
old_way::min_align_of_val(&x);
//~^ERROR: cannot use `#[feature(local)]`
new_way::size_of_val(&x);
size_of_val(&x);
//~^ERROR: cannot be (indirectly) exposed to stable
new_way::min_align_of_val(&x);
min_align_of_val(&x);
//~^ERROR: cannot use `#[feature(local)]`
}
}

#[stable(since="1.0.0", feature = "stable")]
pub mod old_way {
extern "rust-intrinsic" {
#[unstable(feature = "local", issue = "42")]
pub fn size_of_val<T>(x: *const T) -> usize;

#[unstable(feature = "local", issue = "42")]
#[rustc_const_unstable(feature = "local", issue = "42")]
pub fn min_align_of_val<T>(x: *const T) -> usize;
}
}

#[stable(since="1.0.0", feature = "stable")]
pub mod new_way {
#[unstable(feature = "local", issue = "42")]
#[rustc_intrinsic]
pub const unsafe fn size_of_val<T>(x: *const T) -> usize { 42 }
#[unstable(feature = "local", issue = "42")]
#[rustc_intrinsic]
pub const unsafe fn size_of_val<T>(x: *const T) -> usize { 42 }

#[unstable(feature = "local", issue = "42")]
#[rustc_const_unstable(feature = "local", issue = "42")]
#[rustc_intrinsic]
pub const unsafe fn min_align_of_val<T>(x: *const T) -> usize { 42 }
}
#[unstable(feature = "local", issue = "42")]
#[rustc_const_unstable(feature = "local", issue = "42")]
#[rustc_intrinsic]
pub const unsafe fn min_align_of_val<T>(x: *const T) -> usize { 42 }

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

unsafe { copy(src, dst, count) }
//~^ ERROR cannot call non-const intrinsic
//~^ ERROR cannot be (indirectly) exposed to stable
}
Loading