suggest adding const_trait_impl if error because of that
This commit is contained in:
parent
e7fea8c7e6
commit
23718a3cc2
2 changed files with 13 additions and 1 deletions
|
@ -730,6 +730,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
||||||
substs,
|
substs,
|
||||||
span: *fn_span,
|
span: *fn_span,
|
||||||
from_hir_call: *from_hir_call,
|
from_hir_call: *from_hir_call,
|
||||||
|
feature: Some(sym::const_trait_impl),
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -802,6 +803,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
||||||
substs,
|
substs,
|
||||||
span: *fn_span,
|
span: *fn_span,
|
||||||
from_hir_call: *from_hir_call,
|
from_hir_call: *from_hir_call,
|
||||||
|
feature: None,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -844,6 +846,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
||||||
substs,
|
substs,
|
||||||
span: *fn_span,
|
span: *fn_span,
|
||||||
from_hir_call: *from_hir_call,
|
from_hir_call: *from_hir_call,
|
||||||
|
feature: None,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -903,6 +906,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
||||||
substs,
|
substs,
|
||||||
span: *fn_span,
|
span: *fn_span,
|
||||||
from_hir_call: *from_hir_call,
|
from_hir_call: *from_hir_call,
|
||||||
|
feature: None,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,6 +111,7 @@ pub struct FnCallNonConst<'tcx> {
|
||||||
pub substs: SubstsRef<'tcx>,
|
pub substs: SubstsRef<'tcx>,
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub from_hir_call: bool,
|
pub from_hir_call: bool,
|
||||||
|
pub feature: Option<Symbol>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
|
@ -119,7 +120,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
ccx: &ConstCx<'_, 'tcx>,
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
_: Span,
|
_: Span,
|
||||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||||
let FnCallNonConst { caller, callee, substs, span, from_hir_call } = *self;
|
let FnCallNonConst { caller, callee, substs, span, from_hir_call, feature } = *self;
|
||||||
let ConstCx { tcx, param_env, .. } = *ccx;
|
let ConstCx { tcx, param_env, .. } = *ccx;
|
||||||
|
|
||||||
let diag_trait = |err, self_ty: Ty<'_>, trait_id| {
|
let diag_trait = |err, self_ty: Ty<'_>, trait_id| {
|
||||||
|
@ -318,6 +319,13 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
ccx.const_kind(),
|
ccx.const_kind(),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
if let Some(feature) = feature && ccx.tcx.sess.is_nightly_build() {
|
||||||
|
err.help(&format!(
|
||||||
|
"add `#![feature({})]` to the crate attributes to enable",
|
||||||
|
feature,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
if let ConstContext::Static(_) = ccx.const_kind() {
|
if let ConstContext::Static(_) = ccx.const_kind() {
|
||||||
err.note("consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell");
|
err.note("consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue