Skip to content

Commit 0cbc1cd

Browse files
committed
Avoid unnecessary enum
Just use a boolean instead.
1 parent cf844d2 commit 0cbc1cd

File tree

3 files changed

+20
-48
lines changed

3 files changed

+20
-48
lines changed

src/librustc_interface/passes.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,6 @@ fn configure_and_expand_inner<'a>(
233233
resolver_arenas: &'a ResolverArenas<'a>,
234234
metadata_loader: &'a MetadataLoaderDyn,
235235
) -> Result<(ast::Crate, Resolver<'a>)> {
236-
use rustc_resolve::IgnoreState;
237-
238236
log::trace!("configure_and_expand_inner");
239237
pre_expansion_lint(sess, lint_store, &krate);
240238

@@ -413,10 +411,7 @@ fn configure_and_expand_inner<'a>(
413411
println!("{}", json::as_json(&krate));
414412
}
415413

416-
// If we're actually rustdoc then avoid giving a name resolution error for `cfg()` items.
417-
let ignore_bodies =
418-
if sess.opts.actually_rustdoc { IgnoreState::Ignore } else { IgnoreState::Report };
419-
resolver.resolve_crate(&krate, ignore_bodies);
414+
resolver.resolve_crate(&krate);
420415

421416
// Needs to go *after* expansion to be able to check the results of macro expansion.
422417
sess.time("complete_gated_feature_checking", || {

src/librustc_resolve/late.rs

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -376,19 +376,6 @@ struct DiagnosticMetadata<'ast> {
376376
current_let_binding: Option<(Span, Option<Span>, Option<Span>)>,
377377
}
378378

379-
/// Keeps track of whether errors should be reported.
380-
///
381-
/// Used by rustdoc to ignore errors in function bodies.
382-
/// This is just a fancy boolean so it can have doc-comments.
383-
#[derive(Copy, Clone, Debug)]
384-
pub enum IgnoreState {
385-
/// We are at global scope or in a trait implementation, so all errors should be reported.
386-
Report,
387-
/// We are in a function body, so errors shouldn't be reported.
388-
Ignore,
389-
// Note that we don't need to worry about macros, which must always be resolved (or we wouldn't have gotten to the late pass).
390-
}
391-
392379
struct LateResolutionVisitor<'a, 'b, 'ast> {
393380
r: &'b mut Resolver<'a>,
394381

@@ -408,12 +395,12 @@ struct LateResolutionVisitor<'a, 'b, 'ast> {
408395
/// Fields used to add information to diagnostic errors.
409396
diagnostic_metadata: DiagnosticMetadata<'ast>,
410397

411-
/// State used to know whether to ignore resolution errors for item bodies.
398+
/// State used to know whether to ignore resolution errors for function bodies.
412399
///
413400
/// In particular, rustdoc uses this to avoid giving errors for `cfg()` items.
414401
/// In most cases this will be `None`, in which case errors will always be reported.
415402
/// If it is `Some(_)`, then it will be updated when entering a nested function or trait body.
416-
ignore_bodies: Option<IgnoreState>,
403+
in_func_body: bool,
417404
}
418405

419406
/// Walks the whole crate in DFS order, visiting each item, resolving names as it goes.
@@ -517,18 +504,18 @@ impl<'a, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
517504

518505
visit::walk_fn_ret_ty(this, &declaration.output);
519506

520-
let previous_ignore = this.ignore_bodies.take();
521-
// Ignore errors in function bodies if originally passed `ignore_state: true`
507+
let previous_state = this.in_func_body;
508+
// Ignore errors in function bodies if this is rustdoc
522509
// Be sure not to set this until the function signature has been resolved.
523-
this.ignore_bodies = previous_ignore.and(Some(IgnoreState::Ignore));
510+
this.in_func_body = true;
524511
// Resolve the function body, potentially inside the body of an async closure
525512
match fn_kind {
526513
FnKind::Fn(.., body) => walk_list!(this, visit_block, body),
527514
FnKind::Closure(_, body) => this.visit_expr(body),
528515
};
529516

530517
debug!("(resolving function) leaving function");
531-
this.ignore_bodies = previous_ignore;
518+
this.in_func_body = previous_state;
532519
})
533520
});
534521
self.diagnostic_metadata.current_function = previous_value;
@@ -652,10 +639,7 @@ impl<'a, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
652639
}
653640

654641
impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
655-
fn new(
656-
resolver: &'b mut Resolver<'a>,
657-
ignore_bodies: IgnoreState,
658-
) -> LateResolutionVisitor<'a, 'b, 'ast> {
642+
fn new(resolver: &'b mut Resolver<'a>) -> LateResolutionVisitor<'a, 'b, 'ast> {
659643
// During late resolution we only track the module component of the parent scope,
660644
// although it may be useful to track other components as well for diagnostics.
661645
let graph_root = resolver.graph_root;
@@ -672,11 +656,8 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
672656
label_ribs: Vec::new(),
673657
current_trait_ref: None,
674658
diagnostic_metadata: DiagnosticMetadata::default(),
675-
ignore_bodies: match ignore_bodies {
676-
// errors at module scope should always be reported
677-
IgnoreState::Ignore => Some(IgnoreState::Report),
678-
IgnoreState::Report => None,
679-
},
659+
// errors at module scope should always be reported
660+
in_func_body: false,
680661
}
681662
}
682663

@@ -1194,9 +1175,9 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
11941175
impl_items: &'ast [P<AssocItem>],
11951176
) {
11961177
debug!("resolve_implementation");
1197-
let old_ignore = self.ignore_bodies.take();
1178+
let old_ignore = self.in_func_body;
11981179
// Never ignore errors in trait implementations.
1199-
self.ignore_bodies = old_ignore.and(Some(IgnoreState::Report));
1180+
self.in_func_body = false;
12001181
// If applicable, create a rib for the type parameters.
12011182
self.with_generic_param_rib(generics, ItemRibKind(HasGenericParams::Yes), |this| {
12021183
// Dummy self type for better errors if `Self` is used in the trait path.
@@ -1292,7 +1273,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
12921273
});
12931274
});
12941275
});
1295-
self.ignore_bodies = old_ignore;
1276+
self.in_func_body = old_ignore;
12961277
}
12971278

12981279
fn check_trait_item<F>(&mut self, ident: Ident, ns: Namespace, span: Span, err: F)
@@ -1900,20 +1881,17 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
19001881

19011882
/// A wrapper around [`Resolver::report_error`].
19021883
///
1903-
/// This doesn't emit errors for function bodies if `ignore_bodies` is set.
1884+
/// This doesn't emit errors for function bodies if this is r
19041885
fn report_error(&self, span: Span, resolution_error: ResolutionError<'_>) {
19051886
if self.should_report_errs() {
19061887
self.r.report_error(span, resolution_error);
19071888
}
19081889
}
19091890

19101891
#[inline]
1892+
/// If we're actually rustdoc then avoid giving a name resolution error for `cfg()` items.
19111893
fn should_report_errs(&self) -> bool {
1912-
debug!("should_report_errs(state={:?})", self.ignore_bodies);
1913-
match self.ignore_bodies {
1914-
None | Some(IgnoreState::Report) => true,
1915-
Some(IgnoreState::Ignore) => false,
1916-
}
1894+
!(self.r.session.opts.actually_rustdoc && self.in_func_body)
19171895
}
19181896

19191897
// Resolve in alternative namespaces if resolution in the primary namespace fails.
@@ -2412,8 +2390,8 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
24122390
}
24132391

24142392
impl<'a> Resolver<'a> {
2415-
pub(crate) fn late_resolve_crate(&mut self, krate: &Crate, ignore_bodies: IgnoreState) {
2416-
let mut late_resolution_visitor = LateResolutionVisitor::new(self, ignore_bodies);
2393+
pub(crate) fn late_resolve_crate(&mut self, krate: &Crate) {
2394+
let mut late_resolution_visitor = LateResolutionVisitor::new(self);
24172395
visit::walk_crate(&mut late_resolution_visitor, krate);
24182396
for (id, span) in late_resolution_visitor.diagnostic_metadata.unused_labels.iter() {
24192397
self.lint_buffer.buffer_lint(lint::builtin::UNUSED_LABELS, *id, *span, "unused label");

src/librustc_resolve/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#![feature(or_patterns)]
1616
#![recursion_limit = "256"]
1717

18-
pub use late::IgnoreState;
1918
pub use rustc_hir::def::{Namespace, PerNS};
2019

2120
use Determinacy::*;
@@ -1442,13 +1441,13 @@ impl<'a> Resolver<'a> {
14421441
}
14431442

14441443
/// Entry point to crate resolution.
1445-
pub fn resolve_crate(&mut self, krate: &Crate, ignore_bodies: IgnoreState) {
1444+
pub fn resolve_crate(&mut self, krate: &Crate) {
14461445
let _prof_timer = self.session.prof.generic_activity("resolve_crate");
14471446

14481447
ImportResolver { r: self }.finalize_imports();
14491448
self.finalize_macro_resolutions();
14501449

1451-
self.late_resolve_crate(krate, ignore_bodies);
1450+
self.late_resolve_crate(krate);
14521451

14531452
self.check_unused(krate);
14541453
self.report_errors(krate);

0 commit comments

Comments
 (0)