-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move span_bug and bug helper functions to util
- Loading branch information
1 parent
ed246fc
commit a8e19be
Showing
4 changed files
with
54 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// These functions are used by macro expansion for bug! and span_bug! | ||
|
||
use ty::tls; | ||
use std::fmt; | ||
use syntax_pos::{Span, MultiSpan}; | ||
|
||
#[cold] | ||
#[inline(never)] | ||
pub fn bug_fmt(file: &'static str, line: u32, args: fmt::Arguments) -> ! { | ||
// this wrapper mostly exists so I don't have to write a fully | ||
// qualified path of None::<Span> inside the bug!() macro definition | ||
opt_span_bug_fmt(file, line, None::<Span>, args); | ||
} | ||
|
||
#[cold] | ||
#[inline(never)] | ||
pub fn span_bug_fmt<S: Into<MultiSpan>>( | ||
file: &'static str, | ||
line: u32, | ||
span: S, | ||
args: fmt::Arguments, | ||
) -> ! { | ||
opt_span_bug_fmt(file, line, Some(span), args); | ||
} | ||
|
||
fn opt_span_bug_fmt<S: Into<MultiSpan>>( | ||
file: &'static str, | ||
line: u32, | ||
span: Option<S>, | ||
args: fmt::Arguments, | ||
) -> ! { | ||
tls::with_opt(move |tcx| { | ||
let msg = format!("{}:{}: {}", file, line, args); | ||
match (tcx, span) { | ||
(Some(tcx), Some(span)) => tcx.sess.diagnostic().span_bug(span, &msg), | ||
(Some(tcx), None) => tcx.sess.diagnostic().bug(&msg), | ||
(None, _) => panic!(msg), | ||
} | ||
}); | ||
unreachable!(); | ||
} |