typeck: port "unconstrained opaque type" diag

Port the "unconstrained opaque type" diagnostic to using the diagnostic
derive.

Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
David Wood 2022-05-04 07:27:12 +01:00
parent 74cea9fdb9
commit 3dac70fcc0
3 changed files with 17 additions and 7 deletions

View File

@ -90,3 +90,6 @@ typeck-add-return-type-missing-here = a return type might be missing here
typeck-expected-default-return-type = expected `()` because of default return type
typeck-expected-return-type = expected `{$expected}` because of return type
typeck-unconstrained-opaque-type = unconstrained opaque type
.note = `{$name}` must be used in combination with a concrete type within the same module

View File

@ -14,6 +14,7 @@ use rustc_span::{Span, DUMMY_SP};
use super::ItemCtxt;
use super::{bad_placeholder, is_suggestable_infer_ty};
use crate::errors::UnconstrainedOpaqueType;
/// Computes the relevant generic parameter for a potential generic const argument.
///
@ -682,13 +683,10 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
match locator.found {
Some(hidden) => hidden.ty,
None => {
let span = tcx.def_span(def_id);
let name = tcx.item_name(tcx.local_parent(def_id).to_def_id());
let label = format!(
"`{}` must be used in combination with a concrete type within the same module",
name
);
tcx.sess.struct_span_err(span, "unconstrained opaque type").note(&label).emit();
tcx.sess.emit_err(UnconstrainedOpaqueType {
span: tcx.def_span(def_id),
name: tcx.item_name(tcx.local_parent(def_id).to_def_id()),
});
tcx.ty_error()
}
}

View File

@ -228,3 +228,12 @@ pub enum ExpectedReturnTypeLabel<'tcx> {
expected: Ty<'tcx>,
},
}
#[derive(SessionDiagnostic)]
#[error(slug = "typeck-unconstrained-opaque-type")]
#[note]
pub struct UnconstrainedOpaqueType {
#[primary_span]
pub span: Span,
pub name: Symbol,
}