MCPcopy Create free account
hub / github.com/dtolnay/thiserror / check_non_field_attrs

Function check_non_field_attrs

impl/src/valid.rs:109–149  ·  view source on GitHub ↗
(attrs: &Attrs)

Source from the content-addressed store, hash-verified

107}
108
109fn check_non_field_attrs(attrs: &Attrs) -> Result<()> {
110 if let Some(from) = &attrs.from {
111 return Err(Error::new_spanned(
112 from.original,
113 "not expected here; the #[from] attribute belongs on a specific field",
114 ));
115 }
116 if let Some(source) = &attrs.source {
117 return Err(Error::new_spanned(
118 source.original,
119 "not expected here; the #[source] attribute belongs on a specific field",
120 ));
121 }
122 if let Some(backtrace) = &attrs.backtrace {
123 return Err(Error::new_spanned(
124 backtrace,
125 "not expected here; the #[backtrace] attribute belongs on a specific field",
126 ));
127 }
128 if attrs.transparent.is_some() {
129 if let Some(display) = &attrs.display {
130 return Err(Error::new_spanned(
131 display.original,
132 "cannot have both #[error(transparent)] and a display attribute",
133 ));
134 }
135 if let Some(fmt) = &attrs.fmt {
136 return Err(Error::new_spanned(
137 fmt.original,
138 "cannot have both #[error(transparent)] and #[error(fmt = ...)]",
139 ));
140 }
141 } else if let (Some(display), Some(_)) = (&attrs.display, &attrs.fmt) {
142 return Err(Error::new_spanned(
143 display.original,
144 "cannot have both #[error(fmt = ...)] and a format arguments attribute",
145 ));
146 }
147
148 Ok(())
149}
150
151fn check_field_attrs(fields: &[Field]) -> Result<()> {
152 let mut from_field = None;

Callers 1

validateMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected