Skip to content

Commit b000cf0

Browse files
Add lint for intra link resolution failure
1 parent 40f20b5 commit b000cf0

File tree

5 files changed

+76
-9
lines changed

5 files changed

+76
-9
lines changed

src/librustc/lint/builtin.rs

Lines changed: 7 additions & 0 deletions
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_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_LINK_RESOLUTION_FAILURE,
354361
)
355362
}
356363
}

src/librustdoc/clean/mod.rs

Lines changed: 15 additions & 5 deletions
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_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_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,7 +1310,10 @@ 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_LINK_RESOLUTION_FAILURE,
1314+
NodeId::new(0),
1315+
sp,
1316+
&msg)
13071317
};
13081318
diag.emit();
13091319
}

src/librustdoc/core.rs

Lines changed: 24 additions & 4 deletions
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,36 @@ 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_LINK_RESOLUTION_FAILURE.name;
191+
let warnings_lint_name = lint::builtin::WARNINGS.name;
192+
let lints = lint::builtin::HardwiredLints.get_lints()
193+
.iter()
194+
.filter_map(|lint| {
195+
if lint.name == warnings_lint_name {
196+
None
197+
} else {
198+
let level = if lint.name == intra_link_resolution_failure_name {
199+
lint::Warn
200+
} else {
201+
lint::Allow
202+
};
203+
Some((lint.name_lower(), level))
204+
}
205+
})
206+
.collect::<Vec<_>>();
191207

192208
let host_triple = TargetTriple::from_triple(config::host_triple());
193209
// plays with error output here!
194210
let sessopts = config::Options {
195211
maybe_sysroot,
196212
search_paths,
197213
crate_types: vec![config::CrateTypeRlib],
198-
lint_opts: if !allow_warnings { vec![(warning_lint, lint::Allow)] } else { vec![] },
199-
lint_cap: Some(lint::Allow),
214+
lint_opts: if !allow_warnings {
215+
lints
216+
} else {
217+
vec![]
218+
},
219+
lint_cap: Some(lint::Warn),
200220
cg,
201221
externs,
202222
target_triple: triple.unwrap_or(host_triple),
Lines changed: 14 additions & 0 deletions
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_link_resolution_failure)]
12+
13+
/// [v2] //~ ERROR
14+
pub fn foo() {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
warning: [v2] cannot be resolved, ignoring it...
2+
--> src/test/rustdoc-ui/deny-intra-link-resolution-failure.rs:13:1
3+
|
4+
LL | /// [v2] //~ ERROR
5+
| ^^^^^^^^^^^^^^^^^^
6+
|
7+
note: lint level defined here
8+
--> src/test/rustdoc-ui/deny-intra-link-resolution-failure.rs:11:9
9+
|
10+
LL | #![deny(intra_link_resolution_failure)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
= note: the link appears in this line:
13+
14+
[v2] //~ ERROR
15+
^^
16+

0 commit comments

Comments
 (0)