Skip to content

Commit 89e3ef9

Browse files
committed
cargo fmt; tweak error messages
1 parent 107b177 commit 89e3ef9

File tree

4 files changed

+101
-46
lines changed

4 files changed

+101
-46
lines changed

naga/src/front/wgsl/error.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ pub(crate) enum Error<'a> {
278278
AmbiguousCall {
279279
call_span: Span,
280280
alternatives: Vec<String>,
281-
},
281+
},
282282
FunctionReturnsVoid(Span),
283283
FunctionMustUseUnused(Span),
284284
FunctionMustUseReturnsVoid(Span, Span),
@@ -410,7 +410,8 @@ impl<'a> Error<'a> {
410410
"workgroup size separator (`,`) or a closing parenthesis".to_string()
411411
}
412412
ExpectedToken::GlobalItem => concat!(
413-
"global item (`struct`, `const`, `var`, `alias`, `fn`, `diagnostic`, `enable`, `requires`, `;`) ",
413+
"global item (`struct`, `const`, `var`, `alias`, ",
414+
"`fn`, `diagnostic`, `enable`, `requires`, `;`) ",
414415
"or the end of the file"
415416
)
416417
.to_string(),
@@ -836,17 +837,19 @@ impl<'a> Error<'a> {
836837
ref overloads,
837838
} => {
838839
let message = format!(
839-
"For the preceding argument types, `{function}` accepts only {max_arguments} arguments"
840+
"Given the types of arguments passed, \
841+
`{function}` accepts only {max_arguments} arguments"
840842
);
841843
let labels = vec![
842844
(call_span, "This function call has too many arguments".into()),
843845
(arg_span, "This is the first excess argument".into())
844846
];
845847
let mut notes = vec![
846-
format!("These are the only overloads of `{function}` that could accept the preceding arguments:"),
848+
format!("These are the only overloads of `{function}` \
849+
that accept the initial arguments:"),
847850
];
848851
notes.extend(overloads.iter().map(|o| format!("overload: {o}")));
849-
852+
850853
ParseError { message, labels, notes }
851854
}
852855
Error::WrongArgumentType {
@@ -862,7 +865,7 @@ impl<'a> Error<'a> {
862865
arg_index + 1,
863866
);
864867
let labels = vec![
865-
(call_span, "The arguments to this function call have incorrect types".into()),
868+
(call_span, "the function being called".into()),
866869
(arg_span, format!(
867870
"This argument has type `{found}`",
868871
).into())

naga/src/front/wgsl/lower/mod.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -2304,11 +2304,11 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
23042304
if arguments.len() < min_arguments || max_arguments < arguments.len() {
23052305
return Err(Error::WrongArgumentCount {
23062306
span,
2307-
expected: min_arguments as u32 .. max_arguments as u32,
2308-
found: arguments.len() as u32
2307+
expected: min_arguments as u32..max_arguments as u32,
2308+
found: arguments.len() as u32,
23092309
});
23102310
}
2311-
2311+
23122312
let mut unconverted_arguments = Vec::with_capacity(arguments.len());
23132313
for (i, &arg) in arguments.iter().enumerate() {
23142314
let lowered = self.expression_for_abstract(arg, ctx)?;
@@ -2353,9 +2353,9 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
23532353
// handy. The typifier will expect to be able to find
23542354
// the return type in `Module::special_types`.
23552355
if i == 0 {
2356-
use crate::TypeInner as Ti;
23572356
use crate::MathFunction as Mf;
23582357
use crate::PredeclaredType as Pt;
2358+
use crate::TypeInner as Ti;
23592359

23602360
let size_and_scalar = match ty {
23612361
&Ti::Scalar(scalar) => Some((None, scalar)),
@@ -2387,11 +2387,17 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
23872387
};
23882388

23892389
let mut converted_arguments = Vec::with_capacity(arguments.len());
2390-
for (i, (&ast, unconverted)) in arguments.iter().zip(unconverted_arguments).enumerate() {
2390+
for (i, (&ast, unconverted)) in
2391+
arguments.iter().zip(unconverted_arguments).enumerate()
2392+
{
23912393
let converted = match rule.leaf_scalar(i) {
23922394
Some(goal_scalar) => {
23932395
let arg_span = ctx.ast_expressions.get_span(ast);
2394-
ctx.try_automatic_conversion_for_leaf_scalar(unconverted, goal_scalar, arg_span)?
2396+
ctx.try_automatic_conversion_for_leaf_scalar(
2397+
unconverted,
2398+
goal_scalar,
2399+
arg_span,
2400+
)?
23952401
}
23962402
// No conversion is necessary.
23972403
None => unconverted,

naga/src/proc/builtins/list.rs

+29-19
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,13 @@ impl Rule {
6767

6868
let mut overload = format!("fn {name}(");
6969
for (i, arg) in self.subexpressions.iter().enumerate() {
70-
write!(&mut overload, "{}{}",
71-
if i > 0 { ", " } else { "" },
72-
Wgslish(arg)
73-
).unwrap();
70+
write!(
71+
&mut overload,
72+
"{}{}",
73+
if i > 0 { ", " } else { "" },
74+
Wgslish(arg)
75+
)
76+
.unwrap();
7477
}
7578
write!(&mut overload, ") -> {}", Wgslish(&self.conclusion)).unwrap();
7679
overload
@@ -85,24 +88,33 @@ impl super::OverloadSet for List {
8588
}
8689

8790
fn min_subexpressions(&self) -> usize {
88-
self.members().fold(None, |best, (_, rule)| {
89-
// This is different from `max_subexpressions` because
90-
// `<Option as PartialOrd>` doesn't work the way we'd like.
91-
let len = rule.subexpressions.len();
92-
Some(match best {
93-
Some(best) => std::cmp::max(best, len),
94-
None => len
91+
self.members()
92+
.fold(None, |best, (_, rule)| {
93+
// This is different from `max_subexpressions` because
94+
// `<Option as PartialOrd>` doesn't work the way we'd like.
95+
let len = rule.subexpressions.len();
96+
Some(match best {
97+
Some(best) => std::cmp::max(best, len),
98+
None => len,
99+
})
95100
})
96-
}).unwrap()
101+
.unwrap()
97102
}
98103

99104
fn max_subexpressions(&self) -> usize {
100-
self.members().fold(None, |n, (_, rule)| {
101-
std::cmp::max(n, Some(rule.subexpressions.len()))
102-
}).unwrap()
105+
self.members()
106+
.fold(None, |n, (_, rule)| {
107+
std::cmp::max(n, Some(rule.subexpressions.len()))
108+
})
109+
.unwrap()
103110
}
104111

105-
fn arg(&self, i: usize, ty: &crate::TypeInner, types: &crate::UniqueArena<crate::Type>) -> Self {
112+
fn arg(
113+
&self,
114+
i: usize,
115+
ty: &crate::TypeInner,
116+
types: &crate::UniqueArena<crate::Type>,
117+
) -> Self {
106118
use crate::common::wgsl::Wgslish;
107119
self.filter(|rule| {
108120
log::debug!("JIMB: arg {i} of type {} in rule {rule:?}", Wgslish(ty));
@@ -140,9 +152,7 @@ impl super::OverloadSet for List {
140152

141153
fn allowed_args(&self, i: usize) -> Vec<String> {
142154
self.members()
143-
.map(|(_, rule)| {
144-
crate::common::wgsl::Wgslish(&rule.subexpressions[i]).to_string()
145-
})
155+
.map(|(_, rule)| crate::common::wgsl::Wgslish(&rule.subexpressions[i]).to_string())
146156
.collect()
147157
}
148158
}

naga/src/proc/builtins/mod.rs

+51-15
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ pub trait OverloadSet: Clone + std::fmt::Debug {
4646
/// Return the subset of `self` that could accept a value of type
4747
/// `ty` for the `i`'th subexpression, once feasible automatic
4848
/// conversions have been applied.
49-
fn arg(&self, i: usize, ty: &crate::TypeInner, types: &crate::UniqueArena<crate::Type>) -> Self;
49+
fn arg(&self, i: usize, ty: &crate::TypeInner, types: &crate::UniqueArena<crate::Type>)
50+
-> Self;
5051

5152
/// Limit `self` to overloads whose subexpressions are all concrete types.
5253
///
@@ -166,7 +167,12 @@ impl OverloadSet for AnyOverloadSet {
166167
}
167168
}
168169

169-
fn arg(&self, i: usize, ty: &crate::TypeInner, types: &crate::UniqueArena<crate::Type>) -> Self {
170+
fn arg(
171+
&self,
172+
i: usize,
173+
ty: &crate::TypeInner,
174+
types: &crate::UniqueArena<crate::Type>,
175+
) -> Self {
170176
match *self {
171177
AnyOverloadSet::List(ref list) => AnyOverloadSet::List(list.arg(i, ty, types)),
172178
}
@@ -180,7 +186,7 @@ impl OverloadSet for AnyOverloadSet {
180186

181187
fn most_preferred(&self) -> Option<AnyRule> {
182188
match *self {
183-
AnyOverloadSet::List(ref list) => list.most_preferred().map(AnyRule::List)
189+
AnyOverloadSet::List(ref list) => list.most_preferred().map(AnyRule::List),
184190
}
185191
}
186192

@@ -227,17 +233,44 @@ impl crate::MathFunction {
227233
use crate::TypeInner as Ti;
228234
use crate::VectorSize as Vs;
229235

230-
const VEC2F: Ti = Ti::Vector { size: Vs::Bi, scalar: Sc::F32 };
231-
const VEC3F: Ti = Ti::Vector { size: Vs::Tri, scalar: Sc::F32 };
232-
const VEC4F: Ti = Ti::Vector { size: Vs::Quad, scalar: Sc::F32 };
233-
234-
const VEC2AF: Ti = Ti::Vector { size: Vs::Bi, scalar: Sc::ABSTRACT_FLOAT };
235-
const VEC3AF: Ti = Ti::Vector { size: Vs::Tri, scalar: Sc::ABSTRACT_FLOAT };
236-
const VEC4AF: Ti = Ti::Vector { size: Vs::Quad, scalar: Sc::ABSTRACT_FLOAT };
237-
238-
const VEC2I: Ti = Ti::Vector { size: Vs::Bi, scalar: Sc::I32 };
239-
const VEC3I: Ti = Ti::Vector { size: Vs::Tri, scalar: Sc::I32 };
240-
const VEC4I: Ti = Ti::Vector { size: Vs::Quad, scalar: Sc::I32 };
236+
const VEC2F: Ti = Ti::Vector {
237+
size: Vs::Bi,
238+
scalar: Sc::F32,
239+
};
240+
const VEC3F: Ti = Ti::Vector {
241+
size: Vs::Tri,
242+
scalar: Sc::F32,
243+
};
244+
const VEC4F: Ti = Ti::Vector {
245+
size: Vs::Quad,
246+
scalar: Sc::F32,
247+
};
248+
249+
const VEC2AF: Ti = Ti::Vector {
250+
size: Vs::Bi,
251+
scalar: Sc::ABSTRACT_FLOAT,
252+
};
253+
const VEC3AF: Ti = Ti::Vector {
254+
size: Vs::Tri,
255+
scalar: Sc::ABSTRACT_FLOAT,
256+
};
257+
const VEC4AF: Ti = Ti::Vector {
258+
size: Vs::Quad,
259+
scalar: Sc::ABSTRACT_FLOAT,
260+
};
261+
262+
const VEC2I: Ti = Ti::Vector {
263+
size: Vs::Bi,
264+
scalar: Sc::I32,
265+
};
266+
const VEC3I: Ti = Ti::Vector {
267+
size: Vs::Tri,
268+
scalar: Sc::I32,
269+
};
270+
const VEC4I: Ti = Ti::Vector {
271+
size: Vs::Quad,
272+
scalar: Sc::I32,
273+
};
241274

242275
static COMPONENT_WISE_FLOAT: &[list::Rule] = &[
243276
list::Rule {
@@ -291,7 +324,10 @@ impl crate::MathFunction {
291324
conclusion: Ti::Scalar(Sc::F32),
292325
},
293326
list::Rule {
294-
subexpressions: &[Ti::Scalar(Sc::ABSTRACT_FLOAT), Ti::Scalar(Sc::ABSTRACT_FLOAT)],
327+
subexpressions: &[
328+
Ti::Scalar(Sc::ABSTRACT_FLOAT),
329+
Ti::Scalar(Sc::ABSTRACT_FLOAT),
330+
],
295331
conclusion: Ti::Scalar(Sc::ABSTRACT_FLOAT),
296332
},
297333
list::Rule {

0 commit comments

Comments
 (0)