Structured suggestion for "missing feature
intrinsic"
``` error: `size_of_val` is not yet stable as a const intrinsic --> $DIR/const-unstable-intrinsic.rs:17:9 | LL | unstable_intrinsic::size_of_val(&x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: add `#![feature(unstable)]` to the crate attributes to enable help: add `#![feature(unstable)]` to the crate attributes to enable | LL + #![feature("unstable")] | ```
This commit is contained in:
parent
a47fee50bd
commit
7175da59d3
5 changed files with 27 additions and 4 deletions
|
@ -424,7 +424,7 @@ const_eval_unstable_in_stable_exposed =
|
||||||
.bypass_sugg = otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
.bypass_sugg = otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
||||||
|
|
||||||
const_eval_unstable_intrinsic = `{$name}` is not yet stable as a const intrinsic
|
const_eval_unstable_intrinsic = `{$name}` is not yet stable as a const intrinsic
|
||||||
.help = add `#![feature({$feature})]` to the crate attributes to enable
|
const_eval_unstable_intrinsic_suggestion = add `#![feature({$feature})]` to the crate attributes to enable
|
||||||
|
|
||||||
const_eval_unterminated_c_string =
|
const_eval_unterminated_c_string =
|
||||||
reading a null-terminated string starting at {$pointer} with no null found before end of allocation
|
reading a null-terminated string starting at {$pointer} with no null found before end of allocation
|
||||||
|
|
|
@ -819,10 +819,17 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
||||||
feature,
|
feature,
|
||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
|
let suggestion =
|
||||||
|
tcx.hir_crate_items(()).definitions().next().and_then(|id| {
|
||||||
|
tcx.crate_level_attribute_injection_span(
|
||||||
|
tcx.local_def_id_to_hir_id(id),
|
||||||
|
)
|
||||||
|
});
|
||||||
self.check_op(ops::IntrinsicUnstable {
|
self.check_op(ops::IntrinsicUnstable {
|
||||||
name: intrinsic.name,
|
name: intrinsic.name,
|
||||||
feature,
|
feature,
|
||||||
const_stable_indirect: is_const_stable,
|
const_stable_indirect: is_const_stable,
|
||||||
|
suggestion,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Some(ConstStability { level: StabilityLevel::Stable { .. }, .. }) => {
|
Some(ConstStability { level: StabilityLevel::Stable { .. }, .. }) => {
|
||||||
|
|
|
@ -447,6 +447,7 @@ pub(crate) struct IntrinsicUnstable {
|
||||||
pub name: Symbol,
|
pub name: Symbol,
|
||||||
pub feature: Symbol,
|
pub feature: Symbol,
|
||||||
pub const_stable_indirect: bool,
|
pub const_stable_indirect: bool,
|
||||||
|
pub suggestion: Option<Span>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> NonConstOp<'tcx> for IntrinsicUnstable {
|
impl<'tcx> NonConstOp<'tcx> for IntrinsicUnstable {
|
||||||
|
@ -466,6 +467,8 @@ impl<'tcx> NonConstOp<'tcx> for IntrinsicUnstable {
|
||||||
span,
|
span,
|
||||||
name: self.name,
|
name: self.name,
|
||||||
feature: self.feature,
|
feature: self.feature,
|
||||||
|
suggestion: self.suggestion,
|
||||||
|
help: self.suggestion.is_none(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,12 +123,19 @@ pub(crate) struct UnstableConstFn {
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(const_eval_unstable_intrinsic)]
|
#[diag(const_eval_unstable_intrinsic)]
|
||||||
#[help]
|
|
||||||
pub(crate) struct UnstableIntrinsic {
|
pub(crate) struct UnstableIntrinsic {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub name: Symbol,
|
pub name: Symbol,
|
||||||
pub feature: Symbol,
|
pub feature: Symbol,
|
||||||
|
#[suggestion(
|
||||||
|
const_eval_unstable_intrinsic_suggestion,
|
||||||
|
code = "#![feature({feature})]\n",
|
||||||
|
applicability = "machine-applicable"
|
||||||
|
)]
|
||||||
|
pub suggestion: Option<Span>,
|
||||||
|
#[help(const_eval_unstable_intrinsic_suggestion)]
|
||||||
|
pub help: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
|
|
@ -24,7 +24,10 @@ error: `size_of_val` is not yet stable as a const intrinsic
|
||||||
LL | unstable_intrinsic::size_of_val(&x);
|
LL | unstable_intrinsic::size_of_val(&x);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= help: add `#![feature(unstable)]` to the crate attributes to enable
|
help: add `#![feature(unstable)]` to the crate attributes to enable
|
||||||
|
|
|
||||||
|
LL + #![feature(unstable)]
|
||||||
|
|
|
||||||
|
|
||||||
error: `min_align_of_val` is not yet stable as a const intrinsic
|
error: `min_align_of_val` is not yet stable as a const intrinsic
|
||||||
--> $DIR/const-unstable-intrinsic.rs:20:9
|
--> $DIR/const-unstable-intrinsic.rs:20:9
|
||||||
|
@ -32,7 +35,10 @@ error: `min_align_of_val` is not yet stable as a const intrinsic
|
||||||
LL | unstable_intrinsic::min_align_of_val(&x);
|
LL | unstable_intrinsic::min_align_of_val(&x);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= help: add `#![feature(unstable)]` to the crate attributes to enable
|
help: add `#![feature(unstable)]` to the crate attributes to enable
|
||||||
|
|
|
||||||
|
LL + #![feature(unstable)]
|
||||||
|
|
|
||||||
|
|
||||||
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(local)]`
|
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(local)]`
|
||||||
--> $DIR/const-unstable-intrinsic.rs:24:9
|
--> $DIR/const-unstable-intrinsic.rs:24:9
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue