Skip to content

Commit b94cd7a

Browse files
committed
Auto merge of #31250 - nrc:more-aborts, r=@nikomatsakis
With this PR we can save-analysis on code with errors, essential foundation work for IDE support.
2 parents 7cae6b5 + 185a0e5 commit b94cd7a

File tree

16 files changed

+210
-170
lines changed

16 files changed

+210
-170
lines changed

src/librustc/middle/resolve_lifetime.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,12 @@ type Scope<'a> = &'a ScopeChain<'a>;
9393

9494
static ROOT_SCOPE: ScopeChain<'static> = RootScope;
9595

96-
pub fn krate(sess: &Session, krate: &hir::Crate, def_map: &DefMap) -> NamedRegionMap {
96+
pub fn krate(sess: &Session,
97+
krate: &hir::Crate,
98+
def_map: &DefMap)
99+
-> Result<NamedRegionMap, usize> {
97100
let mut named_region_map = NodeMap();
98-
sess.abort_if_new_errors(|| {
101+
try!(sess.track_errors(|| {
99102
krate.visit_all_items(&mut LifetimeContext {
100103
sess: sess,
101104
named_region_map: &mut named_region_map,
@@ -104,8 +107,8 @@ pub fn krate(sess: &Session, krate: &hir::Crate, def_map: &DefMap) -> NamedRegio
104107
trait_ref_hack: false,
105108
labels_in_fn: vec![],
106109
});
107-
});
108-
named_region_map
110+
}));
111+
Ok(named_region_map)
109112
}
110113

111114
impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {

src/librustc/middle/ty/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,16 @@ impl<'tcx> ctxt<'tcx> {
19151915
})
19161916
}
19171917

1918+
pub fn expr_ty_adjusted_opt(&self, expr: &hir::Expr) -> Option<Ty<'tcx>> {
1919+
self.expr_ty_opt(expr).map(|t| t.adjust(self,
1920+
expr.span,
1921+
expr.id,
1922+
self.tables.borrow().adjustments.get(&expr.id),
1923+
|method_call| {
1924+
self.tables.borrow().method_map.get(&method_call).map(|method| method.ty)
1925+
}))
1926+
}
1927+
19181928
pub fn expr_span(&self, id: NodeId) -> Span {
19191929
match self.map.find(id) {
19201930
Some(ast_map::NodeExpr(e)) => {

src/librustc/session/mod.rs

+16-15
Original file line numberDiff line numberDiff line change
@@ -179,24 +179,13 @@ impl Session {
179179
pub fn track_errors<F, T>(&self, f: F) -> Result<T, usize>
180180
where F: FnOnce() -> T
181181
{
182-
let count = self.err_count();
182+
let old_count = self.err_count();
183183
let result = f();
184-
let count = self.err_count() - count;
185-
if count == 0 {
184+
let errors = self.err_count() - old_count;
185+
if errors == 0 {
186186
Ok(result)
187187
} else {
188-
Err(count)
189-
}
190-
}
191-
pub fn abort_if_new_errors<F, T>(&self, f: F) -> T
192-
where F: FnOnce() -> T
193-
{
194-
match self.track_errors(f) {
195-
Ok(result) => result,
196-
Err(_) => {
197-
self.abort_if_errors();
198-
unreachable!();
199-
}
188+
Err(errors)
200189
}
201190
}
202191
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
@@ -515,3 +504,15 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
515504
};
516505
emitter.emit(None, msg, None, errors::Level::Warning);
517506
}
507+
508+
// Err(0) means compilation was stopped, but no errors were found.
509+
// This would be better as a dedicated enum, but using try! is so convenient.
510+
pub type CompileResult = Result<(), usize>;
511+
512+
pub fn compile_result_from_err_count(err_count: usize) -> CompileResult {
513+
if err_count == 0 {
514+
Ok(())
515+
} else {
516+
Err(err_count)
517+
}
518+
}

0 commit comments

Comments
 (0)