Skip to content

Commit 24b9e39

Browse files
committed
Use a public field instead of methods.
1 parent be53b20 commit 24b9e39

File tree

4 files changed

+21
-34
lines changed

4 files changed

+21
-34
lines changed

src/libsyntax/errors/mod.rs

+7-16
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub struct DiagnosticBuilder<'a> {
184184
level: Level,
185185
message: String,
186186
code: Option<String>,
187-
span: MultiSpan,
187+
pub span: MultiSpan,
188188
children: Vec<SubDiagnostic>,
189189
}
190190

@@ -302,20 +302,11 @@ impl<'a> DiagnosticBuilder<'a> {
302302
self
303303
}
304304

305-
pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self {
306-
self.span = sp.into();
307-
self
308-
}
309-
310305
pub fn code(&mut self, s: String) -> &mut Self {
311306
self.code = Some(s);
312307
self
313308
}
314309

315-
pub fn span(&self) -> &MultiSpan {
316-
&self.span
317-
}
318-
319310
pub fn message(&self) -> &str {
320311
&self.message
321312
}
@@ -425,7 +416,7 @@ impl Handler {
425416
msg: &str)
426417
-> DiagnosticBuilder<'a> {
427418
let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
428-
result.set_span(sp);
419+
result.span = sp.into();
429420
if !self.can_emit_warnings {
430421
result.cancel();
431422
}
@@ -437,7 +428,7 @@ impl Handler {
437428
code: &str)
438429
-> DiagnosticBuilder<'a> {
439430
let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
440-
result.set_span(sp);
431+
result.span = sp.into();
441432
result.code(code.to_owned());
442433
if !self.can_emit_warnings {
443434
result.cancel();
@@ -457,7 +448,7 @@ impl Handler {
457448
-> DiagnosticBuilder<'a> {
458449
self.bump_err_count();
459450
let mut result = DiagnosticBuilder::new(self, Level::Error, msg);
460-
result.set_span(sp);
451+
result.span = sp.into();
461452
result
462453
}
463454
pub fn struct_span_err_with_code<'a, S: Into<MultiSpan>>(&'a self,
@@ -467,7 +458,7 @@ impl Handler {
467458
-> DiagnosticBuilder<'a> {
468459
self.bump_err_count();
469460
let mut result = DiagnosticBuilder::new(self, Level::Error, msg);
470-
result.set_span(sp);
461+
result.span = sp.into();
471462
result.code(code.to_owned());
472463
result
473464
}
@@ -481,7 +472,7 @@ impl Handler {
481472
-> DiagnosticBuilder<'a> {
482473
self.bump_err_count();
483474
let mut result = DiagnosticBuilder::new(self, Level::Fatal, msg);
484-
result.set_span(sp);
475+
result.span = sp.into();
485476
result
486477
}
487478
pub fn struct_span_fatal_with_code<'a, S: Into<MultiSpan>>(&'a self,
@@ -491,7 +482,7 @@ impl Handler {
491482
-> DiagnosticBuilder<'a> {
492483
self.bump_err_count();
493484
let mut result = DiagnosticBuilder::new(self, Level::Fatal, msg);
494-
result.set_span(sp);
485+
result.span = sp.into();
495486
result.code(code.to_owned());
496487
result
497488
}

src/libsyntax/ext/tt/macro_parser.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ pub fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> PResult<'a, Non
513513
"tt" => {
514514
p.quote_depth += 1; //but in theory, non-quoted tts might be useful
515515
let res: ::parse::PResult<'a, _> = p.parse_token_tree();
516-
let res = token::NtTT(P(try!(res)));
516+
let res = token::NtTT(P(res?));
517517
p.quote_depth -= 1;
518518
return Ok(res);
519519
}
@@ -522,18 +522,18 @@ pub fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> PResult<'a, Non
522522
// check at the beginning and the parser checks after each bump
523523
p.check_unknown_macro_variable();
524524
match name {
525-
"item" => match try!(p.parse_item()) {
525+
"item" => match p.parse_item()? {
526526
Some(i) => Ok(token::NtItem(i)),
527527
None => Err(p.fatal("expected an item keyword"))
528528
},
529-
"block" => Ok(token::NtBlock(try!(p.parse_block()))),
530-
"stmt" => match try!(p.parse_stmt()) {
529+
"block" => Ok(token::NtBlock(p.parse_block()?)),
530+
"stmt" => match p.parse_stmt()? {
531531
Some(s) => Ok(token::NtStmt(P(s))),
532532
None => Err(p.fatal("expected a statement"))
533533
},
534-
"pat" => Ok(token::NtPat(try!(p.parse_pat()))),
535-
"expr" => Ok(token::NtExpr(try!(p.parse_expr()))),
536-
"ty" => Ok(token::NtTy(try!(p.parse_ty()))),
534+
"pat" => Ok(token::NtPat(p.parse_pat()?)),
535+
"expr" => Ok(token::NtExpr(p.parse_expr()?)),
536+
"ty" => Ok(token::NtTy(p.parse_ty()?)),
537537
// this could be handled like a token, since it is one
538538
"ident" => match p.token {
539539
token::Ident(sn) => {
@@ -545,8 +545,8 @@ pub fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> PResult<'a, Non
545545
Err(p.fatal(&format!("expected ident, found {}", &token_str[..])))
546546
}
547547
},
548-
"path" => Ok(token::NtPath(Box::new(try!(p.parse_path(PathStyle::Type))))),
549-
"meta" => Ok(token::NtMeta(try!(p.parse_meta_item()))),
548+
"path" => Ok(token::NtPath(Box::new(p.parse_path(PathStyle::Type)?))),
549+
"meta" => Ok(token::NtMeta(p.parse_meta_item()?)),
550550
// this is not supposed to happen, since it has been checked
551551
// when compiling the macro.
552552
_ => p.span_bug(sp, "invalid fragment specifier")

src/libsyntax/ext/tt/macro_rules.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
218218
})
219219
}
220220
Failure(diag) => {
221-
let sp = diag.span().primary_span();
221+
let sp = diag.span.primary_span();
222222
let mut new_diag = Some(diag);
223223
if let Some(sp) = sp {
224224
if sp.lo >= best_fail_spot.lo {
@@ -238,11 +238,9 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
238238
match best_fail_diag {
239239
None => cx.span_bug(sp, "internal error: ran no matchers"),
240240
Some(mut diag) => {
241-
let mut span = diag.span().clone();
242-
for span in span.primary_spans_mut() {
241+
for span in diag.span.primary_spans_mut() {
243242
*span = span.substitute_dummy(sp);
244243
}
245-
diag.set_span(span);
246244
diag.emit();
247245
panic!(FatalError);
248246
}
@@ -302,11 +300,9 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt,
302300
&argument_gram) {
303301
Success(m) => m,
304302
Failure(mut diag) => {
305-
let mut span = diag.span().clone();
306-
for span in span.primary_spans_mut() {
303+
for span in diag.span.primary_spans_mut() {
307304
*span = span.substitute_dummy(def.span);
308305
}
309-
diag.set_span(span);
310306
diag.emit();
311307
panic!(FatalError);
312308
}

src/test/run-pass-fulldeps/auxiliary/procedural_mbe_matching.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ fn expand_mbe_matches(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
5757
}
5858
}
5959
Failure(diag) => {
60-
diag.span_help(sp, "expected Success, but got Failure");
61-
panic!(diag);
60+
diag.emit();
61+
panic!("expected Success, but got Failure");
6262
}
6363
Error(_, s) => {
6464
panic!("expected Success, but got Error: {}", s);

0 commit comments

Comments
 (0)