Skip to content

Commit 0f8f490

Browse files
committed
Auto merge of #51382 - GuillaumeGomez:intra-link-lint, r=QuietMisdreavus
Add lint for intra link resolution failure This PR is almost done, just remains this note: ``` note: requested on the command line with `-W intra-link-resolution-failure` ``` I have no idea why my lint is considered as being passed through command line and wasn't able to find where it was set. If anyone has an idea, it'd be very helpful! cc @QuietMisdreavus
2 parents 68da15e + 6a03884 commit 0f8f490

File tree

11 files changed

+133
-11
lines changed

11 files changed

+133
-11
lines changed

src/librustc/lint/builtin.rs

+7
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,12 @@ declare_lint! {
298298
"detects duplicate macro exports"
299299
}
300300

301+
declare_lint! {
302+
pub INTRA_DOC_LINK_RESOLUTION_FAILURE,
303+
Warn,
304+
"warn about documentation intra links resolution failure"
305+
}
306+
301307
/// Does nothing as a lint pass, but registers some `Lint`s
302308
/// which are used by other parts of the compiler.
303309
#[derive(Copy, Clone)]
@@ -351,6 +357,7 @@ impl LintPass for HardwiredLints {
351357
UNSTABLE_NAME_COLLISIONS,
352358
DUPLICATE_ASSOCIATED_TYPE_BINDINGS,
353359
DUPLICATE_MACRO_EXPORTS,
360+
INTRA_DOC_LINK_RESOLUTION_FAILURE,
354361
)
355362
}
356363
}

src/librustc_lint/builtin.rs

+33
Original file line numberDiff line numberDiff line change
@@ -1665,3 +1665,36 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints {
16651665
}
16661666
}
16671667
}
1668+
1669+
/// Does nothing as a lint pass, but registers some `Lint`s
1670+
/// which are used by other parts of the compiler.
1671+
#[derive(Copy, Clone)]
1672+
pub struct SoftLints;
1673+
1674+
impl LintPass for SoftLints {
1675+
fn get_lints(&self) -> LintArray {
1676+
lint_array!(
1677+
WHILE_TRUE,
1678+
BOX_POINTERS,
1679+
NON_SHORTHAND_FIELD_PATTERNS,
1680+
UNSAFE_CODE,
1681+
MISSING_DOCS,
1682+
MISSING_COPY_IMPLEMENTATIONS,
1683+
MISSING_DEBUG_IMPLEMENTATIONS,
1684+
ANONYMOUS_PARAMETERS,
1685+
UNUSED_DOC_COMMENTS,
1686+
UNCONDITIONAL_RECURSION,
1687+
PLUGIN_AS_LIBRARY,
1688+
PRIVATE_NO_MANGLE_FNS,
1689+
PRIVATE_NO_MANGLE_STATICS,
1690+
NO_MANGLE_CONST_ITEMS,
1691+
NO_MANGLE_GENERIC_ITEMS,
1692+
MUTABLE_TRANSMUTES,
1693+
UNSTABLE_FEATURES,
1694+
UNIONS_WITH_DROP_FIELDS,
1695+
UNREACHABLE_PUB,
1696+
TYPE_ALIAS_BOUNDS,
1697+
TRIVIAL_BOUNDS,
1698+
)
1699+
}
1700+
}

src/librustc_lint/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ use builtin::*;
6060
use types::*;
6161
use unused::*;
6262

63+
/// Useful for other parts of the compiler.
64+
pub use builtin::SoftLints;
65+
6366
/// Tell the `LintStore` about all the built-in lints (the ones
6467
/// defined in this crate and the ones defined in
6568
/// `rustc::lint::builtin`).

src/librustdoc/clean/mod.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub use self::Visibility::{Public, Inherited};
2121

2222
use syntax;
2323
use rustc_target::spec::abi::Abi;
24-
use syntax::ast::{self, AttrStyle, Ident};
24+
use syntax::ast::{self, AttrStyle, NodeId, Ident};
2525
use syntax::attr;
2626
use syntax::codemap::{dummy_spanned, Spanned};
2727
use syntax::feature_gate::UnstableFeatures;
@@ -46,9 +46,10 @@ use rustc::middle::stability;
4646
use rustc::util::nodemap::{FxHashMap, FxHashSet};
4747
use rustc_typeck::hir_ty_to_ty;
4848
use rustc::infer::region_constraints::{RegionConstraintData, Constraint};
49+
use rustc::lint as lint;
50+
4951
use std::collections::hash_map::Entry;
5052
use std::fmt;
51-
5253
use std::default::Default;
5354
use std::{mem, slice, vec};
5455
use std::iter::{FromIterator, once};
@@ -1283,10 +1284,16 @@ fn resolution_failure(
12831284
link_range.end + code_dox_len,
12841285
);
12851286

1286-
diag = cx.sess().struct_span_warn(sp, &msg);
1287+
diag = cx.tcx.struct_span_lint_node(lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE,
1288+
NodeId::new(0),
1289+
sp,
1290+
&msg);
12871291
diag.span_label(sp, "cannot be resolved, ignoring");
12881292
} else {
1289-
diag = cx.sess().struct_span_warn(sp, &msg);
1293+
diag = cx.tcx.struct_span_lint_node(lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE,
1294+
NodeId::new(0),
1295+
sp,
1296+
&msg);
12901297

12911298
let last_new_line_offset = dox[..link_range.start].rfind('\n').map_or(0, |n| n + 1);
12921299
let line = dox[last_new_line_offset..].lines().next().unwrap_or("");
@@ -1303,8 +1310,13 @@ fn resolution_failure(
13031310
}
13041311
diag
13051312
} else {
1306-
cx.sess().struct_span_warn(sp, &msg)
1313+
cx.tcx.struct_span_lint_node(lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE,
1314+
NodeId::new(0),
1315+
sp,
1316+
&msg)
13071317
};
1318+
diag.help("to escape `[` and `]` characters, just add '\\' before them like \
1319+
`\\[` or `\\]`");
13081320
diag.emit();
13091321
}
13101322

src/librustdoc/core.rs

+21-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc::middle::cstore::CrateStore;
1717
use rustc::middle::privacy::AccessLevels;
1818
use rustc::ty::{self, TyCtxt, AllArenas};
1919
use rustc::hir::map as hir_map;
20-
use rustc::lint;
20+
use rustc::lint::{self, LintPass};
2121
use rustc::session::config::ErrorOutputType;
2222
use rustc::util::nodemap::{FxHashMap, FxHashSet};
2323
use rustc_resolve as resolve;
@@ -187,16 +187,33 @@ pub fn run_core(search_paths: SearchPaths,
187187
_ => None
188188
};
189189

190-
let warning_lint = lint::builtin::WARNINGS.name_lower();
190+
let intra_link_resolution_failure_name = lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE.name;
191+
let warnings_lint_name = lint::builtin::WARNINGS.name;
192+
let lints = lint::builtin::HardwiredLints.get_lints()
193+
.iter()
194+
.chain(rustc_lint::SoftLints.get_lints())
195+
.filter_map(|lint| {
196+
if lint.name == warnings_lint_name ||
197+
lint.name == intra_link_resolution_failure_name {
198+
None
199+
} else {
200+
Some((lint.name_lower(), lint::Allow))
201+
}
202+
})
203+
.collect::<Vec<_>>();
191204

192205
let host_triple = TargetTriple::from_triple(config::host_triple());
193206
// plays with error output here!
194207
let sessopts = config::Options {
195208
maybe_sysroot,
196209
search_paths,
197210
crate_types: vec![config::CrateTypeRlib],
198-
lint_opts: if !allow_warnings { vec![(warning_lint, lint::Allow)] } else { vec![] },
199-
lint_cap: Some(lint::Allow),
211+
lint_opts: if !allow_warnings {
212+
lints
213+
} else {
214+
vec![]
215+
},
216+
lint_cap: Some(lint::Forbid),
200217
cg,
201218
externs,
202219
target_triple: triple.unwrap_or(host_triple),

src/libstd/sys/unix/ext/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
3636
#![stable(feature = "rust1", since = "1.0.0")]
3737
#![doc(cfg(unix))]
38+
#![allow(missing_docs)]
3839

3940
pub mod io;
4041
pub mod ffi;

src/libstd/sys/windows/ext/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
1919
#![stable(feature = "rust1", since = "1.0.0")]
2020
#![doc(cfg(windows))]
21+
#![allow(missing_docs)]
2122

2223
pub mod ffi;
2324
pub mod fs;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![deny(intra_doc_link_resolution_failure)]
12+
13+
/// [v2] //~ ERROR
14+
pub fn foo() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: `[v2]` cannot be resolved, ignoring it...
2+
--> $DIR/deny-intra-link-resolution-failure.rs:13:6
3+
|
4+
13 | /// [v2] //~ ERROR
5+
| ^^ cannot be resolved, ignoring
6+
|
7+
note: lint level defined here
8+
--> $DIR/deny-intra-link-resolution-failure.rs:11:9
9+
|
10+
11 | #![deny(intra_doc_link_resolution_failure)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
= help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]`
13+

src/test/rustdoc-ui/intra-links-warning.stderr

+21
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,65 @@ warning: `[Foo::baz]` cannot be resolved, ignoring it...
33
|
44
13 | //! Test with [Foo::baz], [Bar::foo], ...
55
| ^^^^^^^^ cannot be resolved, ignoring
6+
|
7+
= note: #[warn(intra_doc_link_resolution_failure)] on by default
8+
= help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]`
69

710
warning: `[Bar::foo]` cannot be resolved, ignoring it...
811
--> $DIR/intra-links-warning.rs:13:35
912
|
1013
13 | //! Test with [Foo::baz], [Bar::foo], ...
1114
| ^^^^^^^^ cannot be resolved, ignoring
15+
|
16+
= help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]`
1217

1318
warning: `[Uniooon::X]` cannot be resolved, ignoring it...
1419
--> $DIR/intra-links-warning.rs:14:13
1520
|
1621
14 | //! , [Uniooon::X] and [Qux::Z].
1722
| ^^^^^^^^^^ cannot be resolved, ignoring
23+
|
24+
= help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]`
1825

1926
warning: `[Qux::Z]` cannot be resolved, ignoring it...
2027
--> $DIR/intra-links-warning.rs:14:30
2128
|
2229
14 | //! , [Uniooon::X] and [Qux::Z].
2330
| ^^^^^^ cannot be resolved, ignoring
31+
|
32+
= help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]`
2433

2534
warning: `[Uniooon::X]` cannot be resolved, ignoring it...
2635
--> $DIR/intra-links-warning.rs:16:14
2736
|
2837
16 | //! , [Uniooon::X] and [Qux::Z].
2938
| ^^^^^^^^^^ cannot be resolved, ignoring
39+
|
40+
= help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]`
3041

3142
warning: `[Qux::Z]` cannot be resolved, ignoring it...
3243
--> $DIR/intra-links-warning.rs:16:31
3344
|
3445
16 | //! , [Uniooon::X] and [Qux::Z].
3546
| ^^^^^^ cannot be resolved, ignoring
47+
|
48+
= help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]`
3649

3750
warning: `[Qux:Y]` cannot be resolved, ignoring it...
3851
--> $DIR/intra-links-warning.rs:18:13
3952
|
4053
18 | /// [Qux:Y]
4154
| ^^^^^ cannot be resolved, ignoring
55+
|
56+
= help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]`
4257

4358
warning: `[BarA]` cannot be resolved, ignoring it...
4459
--> $DIR/intra-links-warning.rs:24:10
4560
|
4661
24 | /// bar [BarA] bar
4762
| ^^^^ cannot be resolved, ignoring
63+
|
64+
= help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]`
4865

4966
warning: `[BarB]` cannot be resolved, ignoring it...
5067
--> $DIR/intra-links-warning.rs:28:1
@@ -60,6 +77,7 @@ warning: `[BarB]` cannot be resolved, ignoring it...
6077

6178
bar [BarB] bar
6279
^^^^
80+
= help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]`
6381

6482
warning: `[BarC]` cannot be resolved, ignoring it...
6583
--> $DIR/intra-links-warning.rs:35:1
@@ -77,6 +95,7 @@ warning: `[BarC]` cannot be resolved, ignoring it...
7795

7896
bar [BarC] bar
7997
^^^^
98+
= help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]`
8099

81100
warning: `[BarD]` cannot be resolved, ignoring it...
82101
--> $DIR/intra-links-warning.rs:48:1
@@ -88,6 +107,7 @@ warning: `[BarD]` cannot be resolved, ignoring it...
88107

89108
bar [BarD] bar
90109
^^^^
110+
= help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]`
91111

92112
warning: `[BarF]` cannot be resolved, ignoring it...
93113
--> $DIR/intra-links-warning.rs:53:9
@@ -102,4 +122,5 @@ warning: `[BarF]` cannot be resolved, ignoring it...
102122

103123
bar [BarF] bar
104124
^^^^
125+
= help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]`
105126

src/test/rustdoc/cap-lints.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
// therefore should not concern itself with the lints.
1414
#[deny(warnings)]
1515

16-
// @has cap_lints/struct.foo.html //pre '#[must_use]'
16+
// @has cap_lints/struct.Foo.html //pre '#[must_use]'
1717
#[must_use]
18-
pub struct foo {
18+
pub struct Foo {
1919
field: i32,
2020
}

0 commit comments

Comments
 (0)