Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run compiler callbacks even when there are errors. #31250

Merged
merged 4 commits into from
Feb 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ type Scope<'a> = &'a ScopeChain<'a>;

static ROOT_SCOPE: ScopeChain<'static> = RootScope;

pub fn krate(sess: &Session, krate: &hir::Crate, def_map: &DefMap) -> NamedRegionMap {
pub fn krate(sess: &Session,
krate: &hir::Crate,
def_map: &DefMap)
-> Result<NamedRegionMap, usize> {
let mut named_region_map = NodeMap();
sess.abort_if_new_errors(|| {
try!(sess.track_errors(|| {
krate.visit_all_items(&mut LifetimeContext {
sess: sess,
named_region_map: &mut named_region_map,
Expand All @@ -104,8 +107,8 @@ pub fn krate(sess: &Session, krate: &hir::Crate, def_map: &DefMap) -> NamedRegio
trait_ref_hack: false,
labels_in_fn: vec![],
});
});
named_region_map
}));
Ok(named_region_map)
}

impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
Expand Down
10 changes: 10 additions & 0 deletions src/librustc/middle/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,16 @@ impl<'tcx> ctxt<'tcx> {
})
}

pub fn expr_ty_adjusted_opt(&self, expr: &hir::Expr) -> Option<Ty<'tcx>> {
self.expr_ty_opt(expr).map(|t| t.adjust(self,
expr.span,
expr.id,
self.tables.borrow().adjustments.get(&expr.id),
|method_call| {
self.tables.borrow().method_map.get(&method_call).map(|method| method.ty)
}))
}

pub fn expr_span(&self, id: NodeId) -> Span {
match self.map.find(id) {
Some(ast_map::NodeExpr(e)) => {
Expand Down
31 changes: 16 additions & 15 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,24 +179,13 @@ impl Session {
pub fn track_errors<F, T>(&self, f: F) -> Result<T, usize>
where F: FnOnce() -> T
{
let count = self.err_count();
let old_count = self.err_count();
let result = f();
let count = self.err_count() - count;
if count == 0 {
let errors = self.err_count() - old_count;
if errors == 0 {
Ok(result)
} else {
Err(count)
}
}
pub fn abort_if_new_errors<F, T>(&self, f: F) -> T
where F: FnOnce() -> T
{
match self.track_errors(f) {
Ok(result) => result,
Err(_) => {
self.abort_if_errors();
unreachable!();
}
Err(errors)
}
}
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
Expand Down Expand Up @@ -515,3 +504,15 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
};
emitter.emit(None, msg, None, errors::Level::Warning);
}

// Err(0) means compilation was stopped, but no errors were found.
// This would be better as a dedicated enum, but using try! is so convenient.
pub type CompileResult = Result<(), usize>;

pub fn compile_result_from_err_count(err_count: usize) -> CompileResult {
if err_count == 0 {
Ok(())
} else {
Err(err_count)
}
}
Loading