Skip to content

Commit 15982fe

Browse files
committed
Better trick for allowing trailing comma at forward!
1 parent 0269e66 commit 15982fe

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/librustc_errors/diagnostic_builder.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub struct DiagnosticBuilder<'a> {
3939
/// it easy to declare such methods on the builder.
4040
macro_rules! forward {
4141
// Forward pattern for &self -> &Self
42-
(pub fn $n:ident(&self, $($name:ident: $ty:ty,)*) -> &Self) => {
42+
(pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)*) -> &Self) => {
4343
pub fn $n(&self, $($name: $ty),*) -> &Self {
4444
#[allow(deprecated)]
4545
self.diagnostic.$n($($name),*);
@@ -48,7 +48,7 @@ macro_rules! forward {
4848
};
4949

5050
// Forward pattern for &mut self -> &mut Self
51-
(pub fn $n:ident(&mut self, $($name:ident: $ty:ty,)*) -> &mut Self) => {
51+
(pub fn $n:ident(&mut self, $($name:ident: $ty:ty),* $(,)*) -> &mut Self) => {
5252
pub fn $n(&mut self, $($name: $ty),*) -> &mut Self {
5353
#[allow(deprecated)]
5454
self.diagnostic.$n($($name),*);
@@ -58,8 +58,11 @@ macro_rules! forward {
5858

5959
// Forward pattern for &mut self -> &mut Self, with S: Into<MultiSpan>
6060
// type parameter. No obvious way to make this more generic.
61-
(pub fn $n:ident<S: Into<MultiSpan>>(&mut self, $($name:ident: $ty:ty,)*) -> &mut Self) => {
62-
pub fn $n<S: Into<MultiSpan>>(&mut self, $($name: $ty,)*) -> &mut Self {
61+
(pub fn $n:ident<S: Into<MultiSpan>>(
62+
&mut self,
63+
$($name:ident: $ty:ty),*
64+
$(,)*) -> &mut Self) => {
65+
pub fn $n<S: Into<MultiSpan>>(&mut self, $($name: $ty),*) -> &mut Self {
6366
#[allow(deprecated)]
6467
self.diagnostic.$n($($name),*);
6568
self
@@ -158,14 +161,14 @@ impl<'a> DiagnosticBuilder<'a> {
158161
found_extra: &dyn fmt::Display,
159162
) -> &mut Self);
160163

161-
forward!(pub fn note(&mut self, msg: &str,) -> &mut Self);
164+
forward!(pub fn note(&mut self, msg: &str) -> &mut Self);
162165
forward!(pub fn span_note<S: Into<MultiSpan>>(&mut self,
163166
sp: S,
164167
msg: &str,
165168
) -> &mut Self);
166-
forward!(pub fn warn(&mut self, msg: &str,) -> &mut Self);
167-
forward!(pub fn span_warn<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str,) -> &mut Self);
168-
forward!(pub fn help(&mut self , msg: &str,) -> &mut Self);
169+
forward!(pub fn warn(&mut self, msg: &str) -> &mut Self);
170+
forward!(pub fn span_warn<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self);
171+
forward!(pub fn help(&mut self , msg: &str) -> &mut Self);
169172
forward!(pub fn span_help<S: Into<MultiSpan>>(&mut self,
170173
sp: S,
171174
msg: &str,
@@ -269,8 +272,8 @@ impl<'a> DiagnosticBuilder<'a> {
269272
);
270273
self
271274
}
272-
forward!(pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S,) -> &mut Self);
273-
forward!(pub fn code(&mut self, s: DiagnosticId,) -> &mut Self);
275+
forward!(pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self);
276+
forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self);
274277

275278
pub fn allow_suggestions(&mut self, allow: bool) -> &mut Self {
276279
self.allow_suggestions = allow;

0 commit comments

Comments
 (0)