Skip to content

Commit ea1ff8c

Browse files
Utilize Resolver lint buffer during HIR lowering
1 parent bb0c930 commit ea1ff8c

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

src/librustc/hir/lowering.rs

Lines changed: 7 additions & 4 deletions
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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ impl Session {
366366
self.diagnostic().span_note_without_error(sp, msg)
367367
}
368368

369-
pub fn buffer_lint<S: Into<MultiSpan>>(
369+
pub fn buffer_lint_late<S: Into<MultiSpan>>(
370370
&self,
371371
lint: &'static lint::Lint,
372372
id: ast::NodeId,
@@ -375,13 +375,13 @@ impl Session {
375375
) {
376376
match *self.buffered_lints.borrow_mut() {
377377
Some(ref mut buffer) => {
378-
buffer.add_lint(lint, id, sp.into(), msg, BuiltinLintDiagnostics::Normal)
378+
buffer.buffer_lint(lint, id, sp, msg);
379379
}
380380
None => bug!("can't buffer lints after HIR lowering"),
381381
}
382382
}
383383

384-
pub fn buffer_lint_with_diagnostic<S: Into<MultiSpan>>(
384+
pub fn buffer_lint_with_diagnostic_late<S: Into<MultiSpan>>(
385385
&self,
386386
lint: &'static lint::Lint,
387387
id: ast::NodeId,
@@ -390,7 +390,9 @@ impl Session {
390390
diagnostic: BuiltinLintDiagnostics,
391391
) {
392392
match *self.buffered_lints.borrow_mut() {
393-
Some(ref mut buffer) => buffer.add_lint(lint, id, sp.into(), msg, diagnostic),
393+
Some(ref mut buffer) => buffer.buffer_lint_with_diagnostic(
394+
lint, id, sp.into(), msg, diagnostic,
395+
),
394396
None => bug!("can't buffer lints after HIR lowering"),
395397
}
396398
}

src/librustc_interface/util.rs

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,10 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
10831083
let expn_id = self.definitions.expansion_that_defined(def_id.index);
10841084
self.has_derives(expn_id, derives)
10851085
}
1086+
1087+
fn lint_buffer(&mut self) -> &mut lint::LintBuffer {
1088+
&mut self.lint_buffer
1089+
}
10861090
}
10871091

10881092
impl<'a> Resolver<'a> {

0 commit comments

Comments
 (0)