@@ -205,6 +205,56 @@ pub fn new_handler(
205205 )
206206}
207207
208+ /// This function is used to setup the lint initialization. By default, in rustdoc, everything
209+ /// is "allowed". Depending if we run in test mode or not, we want some of them to be at their
210+ /// default level. For example, the "INVALID_CODEBLOCK_ATTRIBUTE" lint is activated in both
211+ /// modes.
212+ ///
213+ /// A little detail easy to forget is that there is a way to set the lint level for all lints
214+ /// through the "WARNINGS" lint. To prevent this to happen, we set it back to its "normal" level
215+ /// inside this function.
216+ ///
217+ /// It returns a tuple containing:
218+ /// * Vector of tuples of lints' name and their associated "max" level
219+ /// * HashMap of lint id with their associated "max" level
220+ pub fn init_lints < F > (
221+ mut whitelisted_lints : Vec < String > ,
222+ lint_opts : Vec < ( String , lint:: Level ) > ,
223+ filter_call : F ,
224+ ) -> ( Vec < ( String , lint:: Level ) > , FxHashMap < lint:: LintId , lint:: Level > )
225+ where
226+ F : Fn ( & lint:: Lint ) -> Option < ( String , lint:: Level ) > ,
227+ {
228+ let warnings_lint_name = lint:: builtin:: WARNINGS . name ;
229+
230+ whitelisted_lints. push ( warnings_lint_name. to_owned ( ) ) ;
231+ whitelisted_lints. extend ( lint_opts. iter ( ) . map ( |( lint, _) | lint) . cloned ( ) ) ;
232+
233+ let lints = || {
234+ lint:: builtin:: HardwiredLints :: get_lints ( )
235+ . into_iter ( )
236+ . chain ( rustc_lint:: SoftLints :: get_lints ( ) . into_iter ( ) )
237+ } ;
238+
239+ let lint_opts = lints ( )
240+ . filter_map ( |lint| if lint. name == warnings_lint_name { None } else { filter_call ( lint) } )
241+ . chain ( lint_opts. into_iter ( ) )
242+ . collect :: < Vec < _ > > ( ) ;
243+
244+ let lint_caps = lints ( )
245+ . filter_map ( |lint| {
246+ // We don't want to whitelist *all* lints so let's
247+ // ignore those ones.
248+ if whitelisted_lints. iter ( ) . any ( |l| lint. name == l) {
249+ None
250+ } else {
251+ Some ( ( lint:: LintId :: of ( lint) , lint:: Allow ) )
252+ }
253+ } )
254+ . collect ( ) ;
255+ ( lint_opts, lint_caps)
256+ }
257+
208258pub fn run_core ( options : RustdocOptions ) -> ( clean:: Crate , RenderInfo , RenderOptions ) {
209259 // Parse, resolve, and typecheck the given crate.
210260
@@ -248,7 +298,6 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
248298 let input = Input :: File ( input) ;
249299
250300 let intra_link_resolution_failure_name = lint:: builtin:: INTRA_DOC_LINK_RESOLUTION_FAILURE . name ;
251- let warnings_lint_name = lint:: builtin:: WARNINGS . name ;
252301 let missing_docs = rustc_lint:: builtin:: MISSING_DOCS . name ;
253302 let missing_doc_example = rustc_lint:: builtin:: MISSING_DOC_CODE_EXAMPLES . name ;
254303 let private_doc_tests = rustc_lint:: builtin:: PRIVATE_DOC_TESTS . name ;
@@ -257,8 +306,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
257306
258307 // In addition to those specific lints, we also need to whitelist those given through
259308 // command line, otherwise they'll get ignored and we don't want that.
260- let mut whitelisted_lints = vec ! [
261- warnings_lint_name. to_owned( ) ,
309+ let whitelisted_lints = vec ! [
262310 intra_link_resolution_failure_name. to_owned( ) ,
263311 missing_docs. to_owned( ) ,
264312 missing_doc_example. to_owned( ) ,
@@ -267,39 +315,15 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
267315 invalid_codeblock_attribute_name. to_owned( ) ,
268316 ] ;
269317
270- whitelisted_lints. extend ( lint_opts. iter ( ) . map ( |( lint, _) | lint) . cloned ( ) ) ;
271-
272- let lints = || {
273- lint:: builtin:: HardwiredLints :: get_lints ( )
274- . into_iter ( )
275- . chain ( rustc_lint:: SoftLints :: get_lints ( ) . into_iter ( ) )
276- } ;
277-
278- let lint_opts = lints ( )
279- . filter_map ( |lint| {
280- if lint. name == warnings_lint_name
281- || lint. name == intra_link_resolution_failure_name
282- || lint. name == invalid_codeblock_attribute_name
283- {
284- None
285- } else {
286- Some ( ( lint. name_lower ( ) , lint:: Allow ) )
287- }
288- } )
289- . chain ( lint_opts. into_iter ( ) )
290- . collect :: < Vec < _ > > ( ) ;
291-
292- let lint_caps = lints ( )
293- . filter_map ( |lint| {
294- // We don't want to whitelist *all* lints so let's
295- // ignore those ones.
296- if whitelisted_lints. iter ( ) . any ( |l| lint. name == l) {
297- None
298- } else {
299- Some ( ( lint:: LintId :: of ( lint) , lint:: Allow ) )
300- }
301- } )
302- . collect ( ) ;
318+ let ( lint_opts, lint_caps) = init_lints ( whitelisted_lints, lint_opts, |lint| {
319+ if lint. name == intra_link_resolution_failure_name
320+ || lint. name == invalid_codeblock_attribute_name
321+ {
322+ None
323+ } else {
324+ Some ( ( lint. name_lower ( ) , lint:: Allow ) )
325+ }
326+ } ) ;
303327
304328 let crate_types = if proc_macro_crate {
305329 vec ! [ config:: CrateType :: ProcMacro ]
0 commit comments