Rollup merge of #127452 - fee1-dead-contrib:fx-intrinsic-counting, r=fmease
Fix intrinsic const parameter counting with `effects` r? project-const-traits
This commit is contained in:
commit
73593b9aca
@ -26,15 +26,12 @@ fn equate_intrinsic_type<'tcx>(
|
|||||||
n_cts: usize,
|
n_cts: usize,
|
||||||
sig: ty::PolyFnSig<'tcx>,
|
sig: ty::PolyFnSig<'tcx>,
|
||||||
) {
|
) {
|
||||||
let (own_counts, span) = match tcx.hir_node_by_def_id(def_id) {
|
let (generics, span) = match tcx.hir_node_by_def_id(def_id) {
|
||||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, generics, _), .. })
|
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, generics, _), .. })
|
||||||
| hir::Node::ForeignItem(hir::ForeignItem {
|
| hir::Node::ForeignItem(hir::ForeignItem {
|
||||||
kind: hir::ForeignItemKind::Fn(.., generics, _),
|
kind: hir::ForeignItemKind::Fn(.., generics, _),
|
||||||
..
|
..
|
||||||
}) => {
|
}) => (tcx.generics_of(def_id), generics.span),
|
||||||
let own_counts = tcx.generics_of(def_id).own_counts();
|
|
||||||
(own_counts, generics.span)
|
|
||||||
}
|
|
||||||
_ => {
|
_ => {
|
||||||
struct_span_code_err!(tcx.dcx(), span, E0622, "intrinsic must be a function")
|
struct_span_code_err!(tcx.dcx(), span, E0622, "intrinsic must be a function")
|
||||||
.with_span_label(span, "expected a function")
|
.with_span_label(span, "expected a function")
|
||||||
@ -42,6 +39,7 @@ fn equate_intrinsic_type<'tcx>(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let own_counts = generics.own_counts();
|
||||||
|
|
||||||
let gen_count_ok = |found: usize, expected: usize, descr: &str| -> bool {
|
let gen_count_ok = |found: usize, expected: usize, descr: &str| -> bool {
|
||||||
if found != expected {
|
if found != expected {
|
||||||
@ -57,9 +55,17 @@ fn equate_intrinsic_type<'tcx>(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// the host effect param should be invisible as it shouldn't matter
|
||||||
|
// whether effects is enabled for the intrinsic provider crate.
|
||||||
|
let consts_count = if generics.host_effect_index.is_some() {
|
||||||
|
own_counts.consts - 1
|
||||||
|
} else {
|
||||||
|
own_counts.consts
|
||||||
|
};
|
||||||
|
|
||||||
if gen_count_ok(own_counts.lifetimes, n_lts, "lifetime")
|
if gen_count_ok(own_counts.lifetimes, n_lts, "lifetime")
|
||||||
&& gen_count_ok(own_counts.types, n_tps, "type")
|
&& gen_count_ok(own_counts.types, n_tps, "type")
|
||||||
&& gen_count_ok(own_counts.consts, n_cts, "const")
|
&& gen_count_ok(consts_count, n_cts, "const")
|
||||||
{
|
{
|
||||||
let _ = check_function_signature(
|
let _ = check_function_signature(
|
||||||
tcx,
|
tcx,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Check that intrinsics that do not get overridden, but are marked as such,
|
//! Check that intrinsics that do not get overridden, but are marked as such,
|
||||||
//! cause an error instead of silently invoking the body.
|
//! cause an error instead of silently invoking the body.
|
||||||
#![feature(rustc_attrs/* , effects*/)] // FIXME(effects)
|
#![feature(rustc_attrs)]
|
||||||
//@ build-fail
|
//@ build-fail
|
||||||
//@ failure-status:101
|
//@ failure-status:101
|
||||||
//@ normalize-stderr-test ".*note: .*\n\n" -> ""
|
//@ normalize-stderr-test ".*note: .*\n\n" -> ""
|
||||||
|
52
tests/ui/intrinsics/safe-intrinsic-mismatch.effects.stderr
Normal file
52
tests/ui/intrinsics/safe-intrinsic-mismatch.effects.stderr
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
error: using `#![feature(effects)]` without enabling next trait solver globally
|
||||||
|
|
|
||||||
|
= note: the next trait solver must be enabled globally for the effects feature to work correctly
|
||||||
|
= help: use `-Znext-solver` to enable
|
||||||
|
|
||||||
|
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `size_of`
|
||||||
|
--> $DIR/safe-intrinsic-mismatch.rs:11:5
|
||||||
|
|
|
||||||
|
LL | fn size_of<T>() -> usize;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `size_of`
|
||||||
|
--> $DIR/safe-intrinsic-mismatch.rs:11:5
|
||||||
|
|
|
||||||
|
LL | fn size_of<T>() -> usize;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||||
|
|
||||||
|
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `assume`
|
||||||
|
--> $DIR/safe-intrinsic-mismatch.rs:16:1
|
||||||
|
|
|
||||||
|
LL | const fn assume(_b: bool) {}
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error[E0308]: intrinsic has wrong type
|
||||||
|
--> $DIR/safe-intrinsic-mismatch.rs:16:16
|
||||||
|
|
|
||||||
|
LL | const fn assume(_b: bool) {}
|
||||||
|
| ^ expected unsafe fn, found safe fn
|
||||||
|
|
|
||||||
|
= note: expected signature `unsafe fn(_)`
|
||||||
|
found signature `fn(_)`
|
||||||
|
|
||||||
|
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `const_deallocate`
|
||||||
|
--> $DIR/safe-intrinsic-mismatch.rs:20:1
|
||||||
|
|
|
||||||
|
LL | const fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {}
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error[E0308]: intrinsic has wrong type
|
||||||
|
--> $DIR/safe-intrinsic-mismatch.rs:20:26
|
||||||
|
|
|
||||||
|
LL | const fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {}
|
||||||
|
| ^ expected unsafe fn, found safe fn
|
||||||
|
|
|
||||||
|
= note: expected signature `unsafe fn(_, _, _)`
|
||||||
|
found signature `fn(_, _, _)`
|
||||||
|
|
||||||
|
error: aborting due to 7 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0308`.
|
@ -1,6 +1,11 @@
|
|||||||
|
//@ revisions: stock effects
|
||||||
#![feature(intrinsics)]
|
#![feature(intrinsics)]
|
||||||
#![feature(rustc_attrs)]
|
#![feature(rustc_attrs)]
|
||||||
// FIXME(effects) do this with revisions #![feature(effects)]
|
// as effects insert a const generic param to const intrinsics,
|
||||||
|
// check here that it doesn't report a const param mismatch either
|
||||||
|
// enabling or disabling effects.
|
||||||
|
#![cfg_attr(effects, feature(effects))]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
extern "rust-intrinsic" {
|
extern "rust-intrinsic" {
|
||||||
fn size_of<T>() -> usize; //~ ERROR intrinsic safety mismatch
|
fn size_of<T>() -> usize; //~ ERROR intrinsic safety mismatch
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `size_of`
|
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `size_of`
|
||||||
--> $DIR/safe-intrinsic-mismatch.rs:6:5
|
--> $DIR/safe-intrinsic-mismatch.rs:11:5
|
||||||
|
|
|
|
||||||
LL | fn size_of<T>() -> usize;
|
LL | fn size_of<T>() -> usize;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `size_of`
|
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `size_of`
|
||||||
--> $DIR/safe-intrinsic-mismatch.rs:6:5
|
--> $DIR/safe-intrinsic-mismatch.rs:11:5
|
||||||
|
|
|
|
||||||
LL | fn size_of<T>() -> usize;
|
LL | fn size_of<T>() -> usize;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
@ -13,13 +13,13 @@ LL | fn size_of<T>() -> usize;
|
|||||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||||
|
|
||||||
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `assume`
|
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `assume`
|
||||||
--> $DIR/safe-intrinsic-mismatch.rs:11:1
|
--> $DIR/safe-intrinsic-mismatch.rs:16:1
|
||||||
|
|
|
|
||||||
LL | const fn assume(_b: bool) {}
|
LL | const fn assume(_b: bool) {}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0308]: intrinsic has wrong type
|
error[E0308]: intrinsic has wrong type
|
||||||
--> $DIR/safe-intrinsic-mismatch.rs:11:16
|
--> $DIR/safe-intrinsic-mismatch.rs:16:16
|
||||||
|
|
|
|
||||||
LL | const fn assume(_b: bool) {}
|
LL | const fn assume(_b: bool) {}
|
||||||
| ^ expected unsafe fn, found safe fn
|
| ^ expected unsafe fn, found safe fn
|
||||||
@ -28,13 +28,13 @@ LL | const fn assume(_b: bool) {}
|
|||||||
found signature `fn(_)`
|
found signature `fn(_)`
|
||||||
|
|
||||||
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `const_deallocate`
|
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `const_deallocate`
|
||||||
--> $DIR/safe-intrinsic-mismatch.rs:15:1
|
--> $DIR/safe-intrinsic-mismatch.rs:20:1
|
||||||
|
|
|
|
||||||
LL | const fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {}
|
LL | const fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0308]: intrinsic has wrong type
|
error[E0308]: intrinsic has wrong type
|
||||||
--> $DIR/safe-intrinsic-mismatch.rs:15:26
|
--> $DIR/safe-intrinsic-mismatch.rs:20:26
|
||||||
|
|
|
|
||||||
LL | const fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {}
|
LL | const fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {}
|
||||||
| ^ expected unsafe fn, found safe fn
|
| ^ expected unsafe fn, found safe fn
|
@ -1,12 +1,16 @@
|
|||||||
//@ known-bug: #110395
|
//@ known-bug: #110395
|
||||||
|
//@ failure-status: 101
|
||||||
|
//@ normalize-stderr-test ".*note: .*\n\n" -> ""
|
||||||
|
//@ normalize-stderr-test "thread 'rustc' panicked.*:\n.*\n" -> ""
|
||||||
|
//@ rustc-env:RUST_BACKTRACE=0
|
||||||
// FIXME(effects) check-pass
|
// FIXME(effects) check-pass
|
||||||
// FIXME(effects) fix intrinsics const parameter counting
|
//@ compile-flags: -Znext-solver
|
||||||
|
|
||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
#![feature(no_core, lang_items, unboxed_closures, auto_traits, intrinsics, rustc_attrs, staged_api)]
|
#![feature(no_core, lang_items, unboxed_closures, auto_traits, intrinsics, rustc_attrs, staged_api)]
|
||||||
#![feature(fundamental)]
|
#![feature(fundamental, marker_trait_attr)]
|
||||||
#![feature(const_trait_impl, effects, const_mut_refs)]
|
#![feature(const_trait_impl, effects, const_mut_refs)]
|
||||||
#![allow(internal_features)]
|
#![allow(internal_features, incomplete_features)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_core]
|
#![no_core]
|
||||||
#![stable(feature = "minicore", since = "1.0.0")]
|
#![stable(feature = "minicore", since = "1.0.0")]
|
||||||
@ -532,3 +536,35 @@ fn rt_fn() {}
|
|||||||
|
|
||||||
const_eval_select((), const_fn, rt_fn);
|
const_eval_select((), const_fn, rt_fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod effects {
|
||||||
|
use super::Sized;
|
||||||
|
|
||||||
|
#[lang = "EffectsNoRuntime"]
|
||||||
|
pub struct NoRuntime;
|
||||||
|
#[lang = "EffectsMaybe"]
|
||||||
|
pub struct Maybe;
|
||||||
|
#[lang = "EffectsRuntime"]
|
||||||
|
pub struct Runtime;
|
||||||
|
|
||||||
|
#[lang = "EffectsCompat"]
|
||||||
|
pub trait Compat<#[rustc_runtime] const RUNTIME: bool> {}
|
||||||
|
|
||||||
|
impl Compat<false> for NoRuntime {}
|
||||||
|
impl Compat<true> for Runtime {}
|
||||||
|
impl<#[rustc_runtime] const RUNTIME: bool> Compat<RUNTIME> for Maybe {}
|
||||||
|
|
||||||
|
#[lang = "EffectsTyCompat"]
|
||||||
|
#[marker]
|
||||||
|
pub trait TyCompat<T: ?Sized> {}
|
||||||
|
|
||||||
|
impl<T: ?Sized> TyCompat<T> for T {}
|
||||||
|
impl<T: ?Sized> TyCompat<T> for Maybe {}
|
||||||
|
impl<T: ?Sized> TyCompat<Maybe> for T {}
|
||||||
|
|
||||||
|
#[lang = "EffectsIntersection"]
|
||||||
|
pub trait Intersection {
|
||||||
|
#[lang = "EffectsIntersectionOutput"]
|
||||||
|
type Output: ?Sized;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,17 +1,13 @@
|
|||||||
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
|
error: the compiler unexpectedly panicked. this is a bug.
|
||||||
--> $DIR/minicore.rs:8:30
|
|
||||||
|
|
|
||||||
LL | #![feature(const_trait_impl, effects, const_mut_refs)]
|
|
||||||
| ^^^^^^^
|
|
||||||
|
|
|
||||||
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
|
|
||||||
= note: `#[warn(incomplete_features)]` on by default
|
|
||||||
|
|
||||||
error: requires `EffectsCompat` lang_item
|
query stack during panic:
|
||||||
--> $DIR/minicore.rs:455:9
|
#0 [check_well_formed] checking that `<impl at $DIR/minicore.rs:459:1: 459:36>` is well-formed
|
||||||
|
|
#1 [check_mod_type_wf] checking that types are well-formed in top-level module
|
||||||
LL | impl<T: Clone> Clone for RefCell<T> {
|
end of query stack
|
||||||
| ^^^^^
|
|
||||||
|
|
||||||
error: aborting due to 1 previous error; 1 warning emitted
|
error: the compiler unexpectedly panicked. this is a bug.
|
||||||
|
|
||||||
|
query stack during panic:
|
||||||
|
#0 [check_well_formed] checking that `drop` is well-formed
|
||||||
|
#1 [check_mod_type_wf] checking that types are well-formed in top-level module
|
||||||
|
end of query stack
|
||||||
|
Loading…
Reference in New Issue
Block a user