Tweak wording of non-const traits used as const bounds
Use verbose suggestions and add additional labels/notes. Add more test cases for stable/nightly and feature enabled/disabled.
This commit is contained in:
@@ -1637,11 +1637,23 @@ fn check_impl_constness(
|
||||
}
|
||||
|
||||
let trait_name = tcx.item_name(trait_def_id).to_string();
|
||||
let (local_trait_span, suggestion_pre) =
|
||||
match (trait_def_id.is_local(), tcx.sess.is_nightly_build()) {
|
||||
(true, true) => (
|
||||
Some(tcx.def_span(trait_def_id).shrink_to_lo()),
|
||||
if tcx.features().const_trait_impl() {
|
||||
""
|
||||
} else {
|
||||
"enable `#![feature(const_trait_impl)]` in your crate and "
|
||||
},
|
||||
),
|
||||
(false, _) | (_, false) => (None, ""),
|
||||
};
|
||||
Some(tcx.dcx().emit_err(errors::ConstImplForNonConstTrait {
|
||||
trait_ref_span: hir_trait_ref.path.span,
|
||||
trait_name,
|
||||
local_trait_span:
|
||||
trait_def_id.as_local().map(|_| tcx.def_span(trait_def_id).shrink_to_lo()),
|
||||
local_trait_span,
|
||||
suggestion_pre,
|
||||
marking: (),
|
||||
adding: (),
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user