Skip to content

Commit 3dac70f

Browse files
committed
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>
1 parent 74cea9f commit 3dac70f

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

compiler/rustc_error_messages/locales/en-US/typeck.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,6 @@ typeck-add-return-type-missing-here = a return type might be missing here
9090
typeck-expected-default-return-type = expected `()` because of default return type
9191
9292
typeck-expected-return-type = expected `{$expected}` because of return type
93+
94+
typeck-unconstrained-opaque-type = unconstrained opaque type
95+
.note = `{$name}` must be used in combination with a concrete type within the same module

compiler/rustc_typeck/src/collect/type_of.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_span::{Span, DUMMY_SP};
1414

1515
use super::ItemCtxt;
1616
use super::{bad_placeholder, is_suggestable_infer_ty};
17+
use crate::errors::UnconstrainedOpaqueType;
1718

1819
/// Computes the relevant generic parameter for a potential generic const argument.
1920
///
@@ -682,13 +683,10 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
682683
match locator.found {
683684
Some(hidden) => hidden.ty,
684685
None => {
685-
let span = tcx.def_span(def_id);
686-
let name = tcx.item_name(tcx.local_parent(def_id).to_def_id());
687-
let label = format!(
688-
"`{}` must be used in combination with a concrete type within the same module",
689-
name
690-
);
691-
tcx.sess.struct_span_err(span, "unconstrained opaque type").note(&label).emit();
686+
tcx.sess.emit_err(UnconstrainedOpaqueType {
687+
span: tcx.def_span(def_id),
688+
name: tcx.item_name(tcx.local_parent(def_id).to_def_id()),
689+
});
692690
tcx.ty_error()
693691
}
694692
}

compiler/rustc_typeck/src/errors.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,12 @@ pub enum ExpectedReturnTypeLabel<'tcx> {
228228
expected: Ty<'tcx>,
229229
},
230230
}
231+
232+
#[derive(SessionDiagnostic)]
233+
#[error(slug = "typeck-unconstrained-opaque-type")]
234+
#[note]
235+
pub struct UnconstrainedOpaqueType {
236+
#[primary_span]
237+
pub span: Span,
238+
pub name: Symbol,
239+
}

0 commit comments

Comments
 (0)