Skip to content

Commit

Permalink
Use a public field instead of methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoTestard committed Jun 9, 2016
1 parent be53b20 commit 24b9e39
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 34 deletions.
23 changes: 7 additions & 16 deletions src/libsyntax/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub struct DiagnosticBuilder<'a> {
level: Level,
message: String,
code: Option<String>,
span: MultiSpan,
pub span: MultiSpan,
children: Vec<SubDiagnostic>,
}

Expand Down Expand Up @@ -302,20 +302,11 @@ impl<'a> DiagnosticBuilder<'a> {
self
}

pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self {
self.span = sp.into();
self
}

pub fn code(&mut self, s: String) -> &mut Self {
self.code = Some(s);
self
}

pub fn span(&self) -> &MultiSpan {
&self.span
}

pub fn message(&self) -> &str {
&self.message
}
Expand Down Expand Up @@ -425,7 +416,7 @@ impl Handler {
msg: &str)
-> DiagnosticBuilder<'a> {
let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
result.set_span(sp);
result.span = sp.into();
if !self.can_emit_warnings {
result.cancel();
}
Expand All @@ -437,7 +428,7 @@ impl Handler {
code: &str)
-> DiagnosticBuilder<'a> {
let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
result.set_span(sp);
result.span = sp.into();
result.code(code.to_owned());
if !self.can_emit_warnings {
result.cancel();
Expand All @@ -457,7 +448,7 @@ impl Handler {
-> DiagnosticBuilder<'a> {
self.bump_err_count();
let mut result = DiagnosticBuilder::new(self, Level::Error, msg);
result.set_span(sp);
result.span = sp.into();
result
}
pub fn struct_span_err_with_code<'a, S: Into<MultiSpan>>(&'a self,
Expand All @@ -467,7 +458,7 @@ impl Handler {
-> DiagnosticBuilder<'a> {
self.bump_err_count();
let mut result = DiagnosticBuilder::new(self, Level::Error, msg);
result.set_span(sp);
result.span = sp.into();
result.code(code.to_owned());
result
}
Expand All @@ -481,7 +472,7 @@ impl Handler {
-> DiagnosticBuilder<'a> {
self.bump_err_count();
let mut result = DiagnosticBuilder::new(self, Level::Fatal, msg);
result.set_span(sp);
result.span = sp.into();
result
}
pub fn struct_span_fatal_with_code<'a, S: Into<MultiSpan>>(&'a self,
Expand All @@ -491,7 +482,7 @@ impl Handler {
-> DiagnosticBuilder<'a> {
self.bump_err_count();
let mut result = DiagnosticBuilder::new(self, Level::Fatal, msg);
result.set_span(sp);
result.span = sp.into();
result.code(code.to_owned());
result
}
Expand Down
18 changes: 9 additions & 9 deletions src/libsyntax/ext/tt/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ pub fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> PResult<'a, Non
"tt" => {
p.quote_depth += 1; //but in theory, non-quoted tts might be useful
let res: ::parse::PResult<'a, _> = p.parse_token_tree();
let res = token::NtTT(P(try!(res)));
let res = token::NtTT(P(res?));
p.quote_depth -= 1;
return Ok(res);
}
Expand All @@ -522,18 +522,18 @@ pub fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> PResult<'a, Non
// check at the beginning and the parser checks after each bump
p.check_unknown_macro_variable();
match name {
"item" => match try!(p.parse_item()) {
"item" => match p.parse_item()? {
Some(i) => Ok(token::NtItem(i)),
None => Err(p.fatal("expected an item keyword"))
},
"block" => Ok(token::NtBlock(try!(p.parse_block()))),
"stmt" => match try!(p.parse_stmt()) {
"block" => Ok(token::NtBlock(p.parse_block()?)),
"stmt" => match p.parse_stmt()? {
Some(s) => Ok(token::NtStmt(P(s))),
None => Err(p.fatal("expected a statement"))
},
"pat" => Ok(token::NtPat(try!(p.parse_pat()))),
"expr" => Ok(token::NtExpr(try!(p.parse_expr()))),
"ty" => Ok(token::NtTy(try!(p.parse_ty()))),
"pat" => Ok(token::NtPat(p.parse_pat()?)),
"expr" => Ok(token::NtExpr(p.parse_expr()?)),
"ty" => Ok(token::NtTy(p.parse_ty()?)),
// this could be handled like a token, since it is one
"ident" => match p.token {
token::Ident(sn) => {
Expand All @@ -545,8 +545,8 @@ pub fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> PResult<'a, Non
Err(p.fatal(&format!("expected ident, found {}", &token_str[..])))
}
},
"path" => Ok(token::NtPath(Box::new(try!(p.parse_path(PathStyle::Type))))),
"meta" => Ok(token::NtMeta(try!(p.parse_meta_item()))),
"path" => Ok(token::NtPath(Box::new(p.parse_path(PathStyle::Type)?))),
"meta" => Ok(token::NtMeta(p.parse_meta_item()?)),
// this is not supposed to happen, since it has been checked
// when compiling the macro.
_ => p.span_bug(sp, "invalid fragment specifier")
Expand Down
10 changes: 3 additions & 7 deletions src/libsyntax/ext/tt/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
})
}
Failure(diag) => {
let sp = diag.span().primary_span();
let sp = diag.span.primary_span();
let mut new_diag = Some(diag);
if let Some(sp) = sp {
if sp.lo >= best_fail_spot.lo {
Expand All @@ -238,11 +238,9 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
match best_fail_diag {
None => cx.span_bug(sp, "internal error: ran no matchers"),
Some(mut diag) => {
let mut span = diag.span().clone();
for span in span.primary_spans_mut() {
for span in diag.span.primary_spans_mut() {
*span = span.substitute_dummy(sp);
}
diag.set_span(span);
diag.emit();
panic!(FatalError);
}
Expand Down Expand Up @@ -302,11 +300,9 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt,
&argument_gram) {
Success(m) => m,
Failure(mut diag) => {
let mut span = diag.span().clone();
for span in span.primary_spans_mut() {
for span in diag.span.primary_spans_mut() {
*span = span.substitute_dummy(def.span);
}
diag.set_span(span);
diag.emit();
panic!(FatalError);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ fn expand_mbe_matches(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
}
}
Failure(diag) => {
diag.span_help(sp, "expected Success, but got Failure");
panic!(diag);
diag.emit();
panic!("expected Success, but got Failure");
}
Error(_, s) => {
panic!("expected Success, but got Error: {}", s);
Expand Down

0 comments on commit 24b9e39

Please sign in to comment.