@@ -12,8 +12,6 @@ use rustc_hir::{
12
12
Path ,
13
13
} ;
14
14
use rustc_interface:: { interface, Queries } ;
15
- use rustc_lint:: LintStore ;
16
- use rustc_lint_defs:: { declare_tool_lint, Lint , LintId } ;
17
15
use rustc_middle:: hir:: map:: Map ;
18
16
use rustc_middle:: middle:: privacy:: AccessLevels ;
19
17
use rustc_middle:: ty:: { ParamEnv , Ty , TyCtxt } ;
@@ -28,7 +26,6 @@ use rustc_span::DUMMY_SP;
28
26
29
27
use std:: cell:: RefCell ;
30
28
use std:: collections:: hash_map:: Entry ;
31
- use std:: lazy:: SyncLazy as Lazy ;
32
29
use std:: mem;
33
30
use std:: rc:: Rc ;
34
31
@@ -232,164 +229,6 @@ crate fn new_handler(
232
229
)
233
230
}
234
231
235
- /// This function is used to setup the lint initialization. By default, in rustdoc, everything
236
- /// is "allowed". Depending if we run in test mode or not, we want some of them to be at their
237
- /// default level. For example, the "INVALID_CODEBLOCK_ATTRIBUTES" lint is activated in both
238
- /// modes.
239
- ///
240
- /// A little detail easy to forget is that there is a way to set the lint level for all lints
241
- /// through the "WARNINGS" lint. To prevent this to happen, we set it back to its "normal" level
242
- /// inside this function.
243
- ///
244
- /// It returns a tuple containing:
245
- /// * Vector of tuples of lints' name and their associated "max" level
246
- /// * HashMap of lint id with their associated "max" level
247
- pub ( crate ) fn init_lints < F > (
248
- mut allowed_lints : Vec < String > ,
249
- lint_opts : Vec < ( String , lint:: Level ) > ,
250
- filter_call : F ,
251
- ) -> ( Vec < ( String , lint:: Level ) > , FxHashMap < lint:: LintId , lint:: Level > )
252
- where
253
- F : Fn ( & lint:: Lint ) -> Option < ( String , lint:: Level ) > ,
254
- {
255
- let warnings_lint_name = lint:: builtin:: WARNINGS . name ;
256
-
257
- allowed_lints. push ( warnings_lint_name. to_owned ( ) ) ;
258
- allowed_lints. extend ( lint_opts. iter ( ) . map ( |( lint, _) | lint) . cloned ( ) ) ;
259
-
260
- let lints = || {
261
- lint:: builtin:: HardwiredLints :: get_lints ( )
262
- . into_iter ( )
263
- . chain ( rustc_lint:: SoftLints :: get_lints ( ) . into_iter ( ) )
264
- } ;
265
-
266
- let lint_opts = lints ( )
267
- . filter_map ( |lint| {
268
- // Permit feature-gated lints to avoid feature errors when trying to
269
- // allow all lints.
270
- if lint. feature_gate . is_some ( ) || allowed_lints. iter ( ) . any ( |l| lint. name == l) {
271
- None
272
- } else {
273
- filter_call ( lint)
274
- }
275
- } )
276
- . chain ( lint_opts. into_iter ( ) )
277
- . collect :: < Vec < _ > > ( ) ;
278
-
279
- let lint_caps = lints ( )
280
- . filter_map ( |lint| {
281
- // We don't want to allow *all* lints so let's ignore
282
- // those ones.
283
- if allowed_lints. iter ( ) . any ( |l| lint. name == l) {
284
- None
285
- } else {
286
- Some ( ( lint:: LintId :: of ( lint) , lint:: Allow ) )
287
- }
288
- } )
289
- . collect ( ) ;
290
- ( lint_opts, lint_caps)
291
- }
292
-
293
- declare_tool_lint ! {
294
- /// The `broken_intra_doc_links` lint detects failures in resolving
295
- /// intra-doc link targets. This is a `rustdoc` only lint, see the
296
- /// documentation in the [rustdoc book].
297
- ///
298
- /// [rustdoc book]: ../../../rustdoc/lints.html#broken_intra_doc_links
299
- pub rustdoc:: BROKEN_INTRA_DOC_LINKS ,
300
- Warn ,
301
- "failures in resolving intra-doc link targets"
302
- }
303
-
304
- declare_tool_lint ! {
305
- /// This is a subset of `broken_intra_doc_links` that warns when linking from
306
- /// a public item to a private one. This is a `rustdoc` only lint, see the
307
- /// documentation in the [rustdoc book].
308
- ///
309
- /// [rustdoc book]: ../../../rustdoc/lints.html#private_intra_doc_links
310
- pub rustdoc:: PRIVATE_INTRA_DOC_LINKS ,
311
- Warn ,
312
- "linking from a public item to a private one"
313
- }
314
-
315
- declare_tool_lint ! {
316
- /// The `invalid_codeblock_attributes` lint detects code block attributes
317
- /// in documentation examples that have potentially mis-typed values. This
318
- /// is a `rustdoc` only lint, see the documentation in the [rustdoc book].
319
- ///
320
- /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_codeblock_attributes
321
- pub rustdoc:: INVALID_CODEBLOCK_ATTRIBUTES ,
322
- Warn ,
323
- "codeblock attribute looks a lot like a known one"
324
- }
325
-
326
- declare_tool_lint ! {
327
- /// The `missing_doc_code_examples` lint detects publicly-exported items
328
- /// without code samples in their documentation. This is a `rustdoc` only
329
- /// lint, see the documentation in the [rustdoc book].
330
- ///
331
- /// [rustdoc book]: ../../../rustdoc/lints.html#missing_doc_code_examples
332
- pub rustdoc:: MISSING_DOC_CODE_EXAMPLES ,
333
- Allow ,
334
- "detects publicly-exported items without code samples in their documentation"
335
- }
336
-
337
- declare_tool_lint ! {
338
- /// The `private_doc_tests` lint detects code samples in docs of private
339
- /// items not documented by `rustdoc`. This is a `rustdoc` only lint, see
340
- /// the documentation in the [rustdoc book].
341
- ///
342
- /// [rustdoc book]: ../../../rustdoc/lints.html#private_doc_tests
343
- pub rustdoc:: PRIVATE_DOC_TESTS ,
344
- Allow ,
345
- "detects code samples in docs of private items not documented by rustdoc"
346
- }
347
-
348
- declare_tool_lint ! {
349
- /// The `invalid_html_tags` lint detects invalid HTML tags. This is a
350
- /// `rustdoc` only lint, see the documentation in the [rustdoc book].
351
- ///
352
- /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_html_tags
353
- pub rustdoc:: INVALID_HTML_TAGS ,
354
- Allow ,
355
- "detects invalid HTML tags in doc comments"
356
- }
357
-
358
- declare_tool_lint ! {
359
- /// The `non_autolinks` lint detects when a URL could be written using
360
- /// only angle brackets. This is a `rustdoc` only lint, see the
361
- /// documentation in the [rustdoc book].
362
- ///
363
- /// [rustdoc book]: ../../../rustdoc/lints.html#non_autolinks
364
- pub rustdoc:: NON_AUTOLINKS ,
365
- Warn ,
366
- "detects URLs that could be written using only angle brackets"
367
- }
368
-
369
- static RUSTDOC_LINTS : Lazy < Vec < & ' static Lint > > = Lazy :: new ( || {
370
- vec ! [
371
- BROKEN_INTRA_DOC_LINKS ,
372
- PRIVATE_INTRA_DOC_LINKS ,
373
- MISSING_DOC_CODE_EXAMPLES ,
374
- PRIVATE_DOC_TESTS ,
375
- INVALID_CODEBLOCK_ATTRIBUTES ,
376
- INVALID_HTML_TAGS ,
377
- NON_AUTOLINKS ,
378
- ]
379
- } ) ;
380
-
381
- crate fn register_lints ( _sess : & Session , lint_store : & mut LintStore ) {
382
- lint_store. register_lints ( & * * RUSTDOC_LINTS ) ;
383
- lint_store. register_group (
384
- true ,
385
- "rustdoc" ,
386
- None ,
387
- RUSTDOC_LINTS . iter ( ) . map ( |& lint| LintId :: of ( lint) ) . collect ( ) ,
388
- ) ;
389
- lint_store
390
- . register_renamed ( "intra_doc_link_resolution_failure" , "rustdoc::broken_intra_doc_links" ) ;
391
- }
392
-
393
232
/// Parse, resolve, and typecheck the given crate.
394
233
crate fn create_config (
395
234
RustdocOptions {
@@ -418,8 +257,8 @@ crate fn create_config(
418
257
let cpath = Some ( input. clone ( ) ) ;
419
258
let input = Input :: File ( input) ;
420
259
421
- // In addition to those specific lints, we also need to allow those given through
422
- // command line, otherwise they'll get ignored and we don't want that .
260
+ // By default, rustdoc ignores all lints.
261
+ // Specifically unblock lints relevant to documentation or the lint machinery itself .
423
262
let mut lints_to_show = vec ! [
424
263
// it's unclear whether these should be part of rustdoc directly
425
264
rustc_lint:: builtin:: MISSING_DOCS . name. to_string( ) ,
@@ -428,12 +267,12 @@ crate fn create_config(
428
267
rustc_lint:: builtin:: RENAMED_AND_REMOVED_LINTS . name. to_string( ) ,
429
268
rustc_lint:: builtin:: UNKNOWN_LINTS . name. to_string( ) ,
430
269
] ;
431
- lints_to_show. extend ( RUSTDOC_LINTS . iter ( ) . map ( |lint| lint. name . to_string ( ) ) ) ;
270
+ lints_to_show. extend ( crate :: lint :: RUSTDOC_LINTS . iter ( ) . map ( |lint| lint. name . to_string ( ) ) ) ;
432
271
433
- let ( lint_opts, lint_caps) = init_lints ( lints_to_show, lint_opts, |lint| {
272
+ let ( lint_opts, lint_caps) = crate :: lint :: init_lints ( lints_to_show, lint_opts, |lint| {
434
273
// FIXME: why is this necessary?
435
- if lint. name == BROKEN_INTRA_DOC_LINKS . name
436
- || lint. name == INVALID_CODEBLOCK_ATTRIBUTES . name
274
+ if lint. name == crate :: lint :: BROKEN_INTRA_DOC_LINKS . name
275
+ || lint. name == crate :: lint :: INVALID_CODEBLOCK_ATTRIBUTES . name
437
276
{
438
277
None
439
278
} else {
@@ -474,7 +313,7 @@ crate fn create_config(
474
313
diagnostic_output : DiagnosticOutput :: Default ,
475
314
stderr : None ,
476
315
lint_caps,
477
- register_lints : Some ( box register_lints) ,
316
+ register_lints : Some ( box crate :: lint :: register_lints) ,
478
317
override_queries : Some ( |_sess, providers, _external_providers| {
479
318
// Most lints will require typechecking, so just don't run them.
480
319
providers. lint_mod = |_, _| { } ;
0 commit comments