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