Skip to content

Commit 1164c94

Browse files
committed
Fix visiting twice
1 parent 8660832 commit 1164c94

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ use rustc_errors::{error_code, pluralize, struct_span_err, Applicability};
1717
use rustc_parse::validate_attr;
1818
use rustc_session::lint::builtin::PATTERNS_IN_FNS_WITHOUT_BODY;
1919
use rustc_session::lint::{BuiltinLintDiagnostics, LintBuffer};
20-
use rustc_session::{DiagnosticMessageId, Session};
20+
use rustc_session::Session;
2121
use rustc_span::source_map::Spanned;
2222
use rustc_span::symbol::{kw, sym, Ident};
2323
use rustc_span::Span;
24-
use std::convert::TryInto;
2524
use std::mem;
2625
use std::ops::DerefMut;
2726

@@ -1177,6 +1176,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11771176
let kind = FnKind::Fn(FnCtxt::Free, item.ident, sig, &item.vis, body.as_deref());
11781177
self.visit_fn(kind, item.span, item.id);
11791178
walk_list!(self, visit_attribute, &item.attrs);
1179+
return; // Avoid visiting again.
11801180
}
11811181
ItemKind::ForeignMod(ForeignMod { unsafety, .. }) => {
11821182
let old_item = mem::replace(&mut self.extern_mod, Some(item));
@@ -1440,19 +1440,10 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
14401440
match bound {
14411441
GenericBound::Trait(_, TraitBoundModifier::MaybeConst) => {
14421442
if !self.is_tilde_const_allowed {
1443-
let msg = "`~const` is not allowed here";
1444-
let id_span_msg = (
1445-
DiagnosticMessageId::StabilityId(67792.try_into().ok()),
1446-
Some(bound.span()),
1447-
msg.to_owned(),
1448-
);
1449-
let fresh = self.session.one_time_diagnostics.borrow_mut().insert(id_span_msg);
1450-
if fresh {
1451-
self.err_handler()
1452-
.struct_span_err(bound.span(), msg)
1453-
.note("only allowed on bounds on traits' associated types, const fns, const impls and its associated functions")
1454-
.emit();
1455-
}
1443+
self.err_handler()
1444+
.struct_span_err(bound.span(), "`~const` is not allowed here")
1445+
.note("only allowed on bounds on traits' associated types, const fns, const impls and its associated functions")
1446+
.emit();
14561447
}
14571448
}
14581449

0 commit comments

Comments
 (0)