lisette_diagnostics/
embed.rs1use crate::LisetteDiagnostic;
2use syntax::ast::Span;
3
4pub fn defined_type(target: &str, span: Span) -> LisetteDiagnostic {
5 LisetteDiagnostic::error("Cannot embed this type")
6 .with_infer_code("embed_defined_type")
7 .with_span_label(&span, "not embeddable in this version")
8 .with_help(format!(
9 "Embedding `{}` is not supported in this version. Embed a record struct, an \
10 interface, or a pointer to one.",
11 target
12 ))
13}
14
15pub fn generic(target: &str, span: Span) -> LisetteDiagnostic {
16 LisetteDiagnostic::error("Cannot embed a generic type")
17 .with_infer_code("embed_generic")
18 .with_span_label(&span, "generic type")
19 .with_help(format!(
20 "Embedding `{}` is not supported in this version. Embed a non-generic struct, \
21 interface, or pointer.",
22 target
23 ))
24}
25
26pub fn imported_target(target: &str, span: Span) -> LisetteDiagnostic {
27 LisetteDiagnostic::error("Cannot embed an imported type yet")
28 .with_infer_code("embed_imported_target")
29 .with_span_label(&span, "imported embeds are not supported yet")
30 .with_help(format!(
31 "Embedding the imported Go type `{}` is not supported yet. For now, embed a \
32 Lisette struct or interface.",
33 target
34 ))
35}
36
37pub fn no_surface(target: &str, span: Span) -> LisetteDiagnostic {
38 LisetteDiagnostic::error("Type cannot be embedded")
39 .with_infer_code("embed_no_surface")
40 .with_span_label(&span, "no methods or fields to promote")
41 .with_help(format!(
42 "`{}` has no selector surface, so embedding it would promote nothing. \
43 Embed a struct, interface, or a named type with methods, or use a named field.",
44 target
45 ))
46}
47
48pub fn pointer_to_interface(target: &str, span: Span) -> LisetteDiagnostic {
49 LisetteDiagnostic::error("Cannot embed a pointer to an interface")
50 .with_infer_code("embed_pointer_to_interface")
51 .with_span_label(&span, "pointer to an interface")
52 .with_help(format!(
53 "`{}` embeds a pointer to an interface, which Go rejects. \
54 Embed the interface by value instead.",
55 target
56 ))
57}
58
59pub fn nested_ref(target: &str, span: Span) -> LisetteDiagnostic {
60 LisetteDiagnostic::error("Cannot embed a pointer to a pointer")
61 .with_infer_code("embed_nested_ref")
62 .with_span_label(&span, "pointer to a pointer")
63 .with_help(format!(
64 "`{}` embeds a pointer to a pointer, which Go rejects. \
65 Embed `T` or `Ref<T>`.",
66 target
67 ))
68}
69
70pub fn pointer_backed_newtype(target: &str, span: Span) -> LisetteDiagnostic {
71 LisetteDiagnostic::error("Cannot embed a pointer-backed type")
72 .with_infer_code("embed_pointer_backed_newtype")
73 .with_span_label(&span, "underlying type is a pointer")
74 .with_help(format!(
75 "`{}` is a defined type whose underlying type is a pointer, which Go rejects \
76 as an embedded field. Embed `T` or `Ref<T>`.",
77 target
78 ))
79}
80
81pub fn option_target(span: Span) -> LisetteDiagnostic {
82 LisetteDiagnostic::error("Cannot embed `Option<T>`")
83 .with_infer_code("embed_option_target")
84 .with_span_label(&span, "embedded type cannot be `Option`")
85 .with_help(
86 "An embed's nullability is the embedded type's own zero, so `embed` takes no \
87 `Option`. Embed `T` (or `Ref<T>` for a pointer) instead.",
88 )
89}