Skip to content

Commit fa98e52

Browse files
committed
Use Result<(), ErrorGuaranteed>
1 parent a458938 commit fa98e52

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

compiler/rustc_ast/src/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2872,7 +2872,7 @@ pub enum ModKind {
28722872
/// or with definition outlined to a separate file `mod foo;` and already loaded from it.
28732873
/// The inner span is from the first token past `{` to the last token until `}`,
28742874
/// or from the first to the last token in the loaded file.
2875-
Loaded(ThinVec<P<Item>>, Inline, ModSpans, bool),
2875+
Loaded(ThinVec<P<Item>>, Inline, ModSpans, Result<(), ErrorGuaranteed>),
28762876
/// Module with definition outlined to a separate file `mod foo;` but not yet loaded from it.
28772877
Unloaded,
28782878
}

compiler/rustc_ast_lowering/src/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
9090
fn lower_crate(&mut self, c: &Crate) {
9191
debug_assert_eq!(self.resolver.node_id_to_def_id[&CRATE_NODE_ID], CRATE_DEF_ID);
9292
self.with_lctx(CRATE_NODE_ID, |lctx| {
93-
let module = lctx.lower_mod(&c.items, &c.spans, false);
93+
let module = lctx.lower_mod(&c.items, &c.spans, Ok(()));
9494
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs);
9595
hir::OwnerNode::Crate(module)
9696
})
@@ -118,7 +118,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
118118
&mut self,
119119
items: &[P<Item>],
120120
spans: &ModSpans,
121-
had_parse_errors: bool,
121+
had_parse_errors: Result<(), ErrorGuaranteed>,
122122
) -> &'hir hir::Mod<'hir> {
123123
self.arena.alloc(hir::Mod {
124124
spans: hir::ModSpans {

compiler/rustc_expand/src/module.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub(crate) struct ParsedExternalMod {
3737
pub file_path: PathBuf,
3838
pub dir_path: PathBuf,
3939
pub dir_ownership: DirOwnership,
40-
pub had_parse_error: bool,
40+
pub had_parse_error: Result<(), ErrorGuaranteed>,
4141
}
4242

4343
pub enum ModError<'a> {
@@ -75,11 +75,12 @@ pub(crate) fn parse_external_mod(
7575
attrs.extend(inner_attrs);
7676
(items, inner_span, mp.file_path)
7777
};
78-
let had_parse_error = result.is_err();
7978

8079
// (1) ...instead, we return a dummy module.
81-
let (items, spans, file_path) =
82-
result.map_err(|err| err.report(sess, span)).unwrap_or_default();
80+
let ((items, spans, file_path), had_parse_error) = match result {
81+
Err(err) => (Default::default(), Err(err.report(sess, span))),
82+
Ok(result) => (result, Ok(())),
83+
};
8384

8485
// Extract the directory path for submodules of the module.
8586
let dir_path = file_path.parent().unwrap_or(&file_path).to_owned();

compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3075,7 +3075,7 @@ pub enum ClosureBinder {
30753075
pub struct Mod<'hir> {
30763076
pub spans: ModSpans,
30773077
pub item_ids: &'hir [ItemId],
3078-
pub had_parse_errors: bool,
3078+
pub had_parse_errors: Result<(), ErrorGuaranteed>,
30793079
}
30803080

30813081
#[derive(Copy, Clone, Debug, HashStable_Generic)]

compiler/rustc_parse/src/parser/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'a> Parser<'a> {
4545
let (inner_attrs, items, inner_span) =
4646
self.parse_mod(&token::CloseDelim(Delimiter::Brace))?;
4747
attrs.extend(inner_attrs);
48-
ModKind::Loaded(items, Inline::Yes, inner_span, false)
48+
ModKind::Loaded(items, Inline::Yes, inner_span, Ok(()))
4949
};
5050
Ok((id, ItemKind::Mod(safety, mod_kind)))
5151
}

compiler/rustc_resolve/src/build_reduced_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
781781
);
782782
self.r.define(parent, ident, TypeNS, (module, vis, sp, expansion));
783783

784-
if let ast::ModKind::Loaded(_, _, _, true) = mod_kind {
784+
if let ast::ModKind::Loaded(_, _, _, Err(_)) = mod_kind {
785785
self.r.mod_with_parse_errors.insert(def_id);
786786
}
787787

0 commit comments

Comments
 (0)