From ea1ff8c07c3937cab6e8d02c2a9f0fbb508046a5 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Fri, 25 Oct 2019 09:20:18 -0400 Subject: [PATCH] Utilize Resolver lint buffer during HIR lowering --- src/librustc/hir/lowering.rs | 11 +++++++---- src/librustc/session/mod.rs | 10 ++++++---- src/librustc_interface/util.rs | 4 ++-- src/librustc_resolve/lib.rs | 4 ++++ 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 12ab44515c38..6b6032516ca7 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -43,6 +43,7 @@ use crate::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX}; use crate::hir::def::{Namespace, Res, DefKind, PartialRes, PerNS}; use crate::hir::{GenericArg, ConstArg}; use crate::hir::ptr::P; +use crate::lint; use crate::lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES, ELIDED_LIFETIMES_IN_PATHS}; use crate::middle::cstore::CrateStore; @@ -184,6 +185,8 @@ pub trait Resolver { ) -> (ast::Path, Res); fn has_derives(&self, node_id: NodeId, derives: SpecialDerives) -> bool; + + fn lint_buffer(&mut self) -> &mut lint::LintBuffer; } type NtToTokenstream = fn(&Nonterminal, &ParseSess, Span) -> TokenStream; @@ -1857,7 +1860,7 @@ impl<'a> LoweringContext<'a> { GenericArgs::Parenthesized(ref data) => match parenthesized_generic_args { ParenthesizedGenericArgs::Ok => self.lower_parenthesized_parameter_data(data), ParenthesizedGenericArgs::Warn => { - self.sess.buffer_lint( + self.resolver.lint_buffer().buffer_lint( PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES, CRATE_NODE_ID, data.span, @@ -1953,7 +1956,7 @@ impl<'a> LoweringContext<'a> { } AnonymousLifetimeMode::PassThrough | AnonymousLifetimeMode::ReportError => { - self.sess.buffer_lint_with_diagnostic( + self.resolver.lint_buffer().buffer_lint_with_diagnostic( ELIDED_LIFETIMES_IN_PATHS, CRATE_NODE_ID, path_span, @@ -3346,7 +3349,7 @@ impl<'a> LoweringContext<'a> { } } - fn maybe_lint_bare_trait(&self, span: Span, id: NodeId, is_global: bool) { + fn maybe_lint_bare_trait(&mut self, span: Span, id: NodeId, is_global: bool) { // FIXME(davidtwco): This is a hack to detect macros which produce spans of the // call site which do not have a macro backtrace. See #61963. let is_macro_callsite = self.sess.source_map() @@ -3354,7 +3357,7 @@ impl<'a> LoweringContext<'a> { .map(|snippet| snippet.starts_with("#[")) .unwrap_or(true); if !is_macro_callsite { - self.sess.buffer_lint_with_diagnostic( + self.resolver.lint_buffer().buffer_lint_with_diagnostic( builtin::BARE_TRAIT_OBJECTS, id, span, diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 81f0853201c0..9ab5b9f13b15 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -366,7 +366,7 @@ impl Session { self.diagnostic().span_note_without_error(sp, msg) } - pub fn buffer_lint>( + pub fn buffer_lint_late>( &self, lint: &'static lint::Lint, id: ast::NodeId, @@ -375,13 +375,13 @@ impl Session { ) { match *self.buffered_lints.borrow_mut() { Some(ref mut buffer) => { - buffer.add_lint(lint, id, sp.into(), msg, BuiltinLintDiagnostics::Normal) + buffer.buffer_lint(lint, id, sp, msg); } None => bug!("can't buffer lints after HIR lowering"), } } - pub fn buffer_lint_with_diagnostic>( + pub fn buffer_lint_with_diagnostic_late>( &self, lint: &'static lint::Lint, id: ast::NodeId, @@ -390,7 +390,9 @@ impl Session { diagnostic: BuiltinLintDiagnostics, ) { match *self.buffered_lints.borrow_mut() { - Some(ref mut buffer) => buffer.add_lint(lint, id, sp.into(), msg, diagnostic), + Some(ref mut buffer) => buffer.buffer_lint_with_diagnostic( + lint, id, sp.into(), msg, diagnostic, + ), None => bug!("can't buffer lints after HIR lowering"), } } diff --git a/src/librustc_interface/util.rs b/src/librustc_interface/util.rs index 8f11dc937272..196746593252 100644 --- a/src/librustc_interface/util.rs +++ b/src/librustc_interface/util.rs @@ -559,7 +559,7 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec Vec hir::lowering::Resolver for Resolver<'a> { let expn_id = self.definitions.expansion_that_defined(def_id.index); self.has_derives(expn_id, derives) } + + fn lint_buffer(&mut self) -> &mut lint::LintBuffer { + &mut self.lint_buffer + } } impl<'a> Resolver<'a> {