diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2024-12-28 18:20:44 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2025-01-18 21:13:27 +0000 |
| commit | a47fee50bd2740caa91b6d658fa6e808466de5a5 (patch) | |
| tree | f603e65096141554fe05378403f56757703d3ae4 /compiler/rustc_const_eval/src/check_consts/check.rs | |
| parent | bcd0683e5dce1945b5d940714742e7502883bb5c (diff) | |
| download | rust-a47fee50bd2740caa91b6d658fa6e808466de5a5.tar.gz rust-a47fee50bd2740caa91b6d658fa6e808466de5a5.zip | |
Structured suggestion for "missing `feature` in unstable fn call"
When encountering a call corresponding to an item marked as unstable behind a feature flag, provide a structured suggestion pointing at where in the crate the `#![feature(..)]` needs to be written. ``` error: `foobar` is not yet stable as a const fn --> $DIR/const-stability-attribute-implies-no-feature.rs:12:5 | LL | foobar(); | ^^^^^^^^ | help: add `#![feature(const_foobar)]` to the crate attributes to enable | LL + #![feature(const_foobar)] | ``` Fix #81370.
Diffstat (limited to 'compiler/rustc_const_eval/src/check_consts/check.rs')
| -rw-r--r-- | compiler/rustc_const_eval/src/check_consts/check.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/compiler/rustc_const_eval/src/check_consts/check.rs b/compiler/rustc_const_eval/src/check_consts/check.rs index 6c940124193..94fb039512a 100644 --- a/compiler/rustc_const_eval/src/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/check_consts/check.rs @@ -911,16 +911,23 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { // regular stability. feature == sym::rustc_private && issue == NonZero::new(27812) - && self.tcx.sess.opts.unstable_opts.force_unstable_if_unmarked + && tcx.sess.opts.unstable_opts.force_unstable_if_unmarked }; // Even if the feature is enabled, we still need check_op to double-check // this if the callee is not safe to expose on stable. if !feature_enabled || !callee_safe_to_expose_on_stable { + let suggestion_span = + 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::FnCallUnstable { def_id: callee, feature, feature_enabled, safe_to_expose_on_stable: callee_safe_to_expose_on_stable, + suggestion_span, }); } } |
