Skip to content

Commit 23718a3

Browse files
committed
suggest adding const_trait_impl if error because of that
1 parent e7fea8c commit 23718a3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
730730
substs,
731731
span: *fn_span,
732732
from_hir_call: *from_hir_call,
733+
feature: Some(sym::const_trait_impl),
733734
});
734735
return;
735736
}
@@ -802,6 +803,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
802803
substs,
803804
span: *fn_span,
804805
from_hir_call: *from_hir_call,
806+
feature: None,
805807
});
806808
return;
807809
}
@@ -844,6 +846,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
844846
substs,
845847
span: *fn_span,
846848
from_hir_call: *from_hir_call,
849+
feature: None,
847850
});
848851
return;
849852
}
@@ -903,6 +906,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
903906
substs,
904907
span: *fn_span,
905908
from_hir_call: *from_hir_call,
909+
feature: None,
906910
});
907911
return;
908912
}

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ pub struct FnCallNonConst<'tcx> {
111111
pub substs: SubstsRef<'tcx>,
112112
pub span: Span,
113113
pub from_hir_call: bool,
114+
pub feature: Option<Symbol>,
114115
}
115116

116117
impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
@@ -119,7 +120,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
119120
ccx: &ConstCx<'_, 'tcx>,
120121
_: Span,
121122
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
122-
let FnCallNonConst { caller, callee, substs, span, from_hir_call } = *self;
123+
let FnCallNonConst { caller, callee, substs, span, from_hir_call, feature } = *self;
123124
let ConstCx { tcx, param_env, .. } = *ccx;
124125

125126
let diag_trait = |err, self_ty: Ty<'_>, trait_id| {
@@ -318,6 +319,13 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
318319
ccx.const_kind(),
319320
));
320321

322+
if let Some(feature) = feature && ccx.tcx.sess.is_nightly_build() {
323+
err.help(&format!(
324+
"add `#![feature({})]` to the crate attributes to enable",
325+
feature,
326+
));
327+
}
328+
321329
if let ConstContext::Static(_) = ccx.const_kind() {
322330
err.note("consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell");
323331
}

0 commit comments

Comments
 (0)