Skip to content

Commit cb440f0

Browse files
Utilize Resolver lint buffer during HIR lowering
1 parent 1033298 commit cb440f0

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

src/librustc/hir/lowering.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use crate::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX};
4343
use crate::hir::def::{Namespace, Res, DefKind, PartialRes, PerNS};
4444
use crate::hir::{GenericArg, ConstArg};
4545
use crate::hir::ptr::P;
46+
use crate::lint;
4647
use crate::lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
4748
ELIDED_LIFETIMES_IN_PATHS};
4849
use crate::middle::cstore::CrateStore;
@@ -184,6 +185,8 @@ pub trait Resolver {
184185
) -> (ast::Path, Res<NodeId>);
185186

186187
fn has_derives(&self, node_id: NodeId, derives: SpecialDerives) -> bool;
188+
189+
fn lint_buffer(&mut self) -> &mut lint::LintBuffer;
187190
}
188191

189192
type NtToTokenstream = fn(&Nonterminal, &ParseSess, Span) -> TokenStream;
@@ -1857,7 +1860,7 @@ impl<'a> LoweringContext<'a> {
18571860
GenericArgs::Parenthesized(ref data) => match parenthesized_generic_args {
18581861
ParenthesizedGenericArgs::Ok => self.lower_parenthesized_parameter_data(data),
18591862
ParenthesizedGenericArgs::Warn => {
1860-
self.sess.buffer_lint(
1863+
self.resolver.lint_buffer().buffer_lint(
18611864
PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
18621865
CRATE_NODE_ID,
18631866
data.span,
@@ -1953,7 +1956,7 @@ impl<'a> LoweringContext<'a> {
19531956
}
19541957
AnonymousLifetimeMode::PassThrough |
19551958
AnonymousLifetimeMode::ReportError => {
1956-
self.sess.buffer_lint_with_diagnostic(
1959+
self.resolver.lint_buffer().buffer_lint_with_diagnostic(
19571960
ELIDED_LIFETIMES_IN_PATHS,
19581961
CRATE_NODE_ID,
19591962
path_span,
@@ -3346,15 +3349,15 @@ impl<'a> LoweringContext<'a> {
33463349
}
33473350
}
33483351

3349-
fn maybe_lint_bare_trait(&self, span: Span, id: NodeId, is_global: bool) {
3352+
fn maybe_lint_bare_trait(&mut self, span: Span, id: NodeId, is_global: bool) {
33503353
// FIXME(davidtwco): This is a hack to detect macros which produce spans of the
33513354
// call site which do not have a macro backtrace. See #61963.
33523355
let is_macro_callsite = self.sess.source_map()
33533356
.span_to_snippet(span)
33543357
.map(|snippet| snippet.starts_with("#["))
33553358
.unwrap_or(true);
33563359
if !is_macro_callsite {
3357-
self.sess.buffer_lint_with_diagnostic(
3360+
self.resolver.lint_buffer().buffer_lint_with_diagnostic(
33583361
builtin::BARE_TRAIT_OBJECTS,
33593362
id,
33603363
span,

src/librustc/session/mod.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl Session {
363363
self.diagnostic().span_note_without_error(sp, msg)
364364
}
365365

366-
pub fn buffer_lint<S: Into<MultiSpan>>(
366+
pub fn buffer_lint_late<S: Into<MultiSpan>>(
367367
&self,
368368
lint: &'static lint::Lint,
369369
id: ast::NodeId,
@@ -372,13 +372,13 @@ impl Session {
372372
) {
373373
match *self.buffered_lints.borrow_mut() {
374374
Some(ref mut buffer) => {
375-
buffer.add_lint(lint, id, sp.into(), msg, BuiltinLintDiagnostics::Normal)
375+
buffer.buffer_lint(lint, id, sp, msg);
376376
}
377377
None => bug!("can't buffer lints after HIR lowering"),
378378
}
379379
}
380380

381-
pub fn buffer_lint_with_diagnostic<S: Into<MultiSpan>>(
381+
pub fn buffer_lint_with_diagnostic_late<S: Into<MultiSpan>>(
382382
&self,
383383
lint: &'static lint::Lint,
384384
id: ast::NodeId,
@@ -387,7 +387,9 @@ impl Session {
387387
diagnostic: BuiltinLintDiagnostics,
388388
) {
389389
match *self.buffered_lints.borrow_mut() {
390-
Some(ref mut buffer) => buffer.add_lint(lint, id, sp.into(), msg, diagnostic),
390+
Some(ref mut buffer) => buffer.buffer_lint_with_diagnostic(
391+
lint, id, sp.into(), msg, diagnostic,
392+
),
391393
None => bug!("can't buffer lints after HIR lowering"),
392394
}
393395
}

src/librustc_interface/util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
559559
None
560560
);
561561
if let Some(candidate) = lev_candidate {
562-
session.buffer_lint_with_diagnostic(
562+
session.buffer_lint_with_diagnostic_late(
563563
lint::builtin::UNKNOWN_CRATE_TYPES,
564564
ast::CRATE_NODE_ID,
565565
span,
@@ -572,7 +572,7 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
572572
)
573573
);
574574
} else {
575-
session.buffer_lint(
575+
session.buffer_lint_late(
576576
lint::builtin::UNKNOWN_CRATE_TYPES,
577577
ast::CRATE_NODE_ID,
578578
span,

src/librustc_resolve/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,10 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
10821082
let expn_id = self.definitions.expansion_that_defined(def_id.index);
10831083
self.has_derives(expn_id, derives)
10841084
}
1085+
1086+
fn lint_buffer(&mut self) -> &mut lint::LintBuffer {
1087+
&mut self.lint_buffer
1088+
}
10851089
}
10861090

10871091
impl<'a> Resolver<'a> {

0 commit comments

Comments
 (0)