Skip to content

Commit 6488861

Browse files
authored
Rollup merge of rust-lang#77856 - GuillaumeGomez:automatic-links-lint, r=jyn514
Add automatic_links lint Fixes rust-lang#77501. r? @jyn514
2 parents 4969437 + d7272ea commit 6488861

File tree

14 files changed

+373
-4
lines changed

14 files changed

+373
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4233,6 +4233,7 @@ dependencies = [
42334233
"itertools 0.9.0",
42344234
"minifier",
42354235
"pulldown-cmark 0.8.0",
4236+
"regex",
42364237
"rustc-rayon",
42374238
"serde",
42384239
"serde_json",

compiler/rustc_lint/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use rustc_hir::def_id::LocalDefId;
6363
use rustc_middle::ty::query::Providers;
6464
use rustc_middle::ty::TyCtxt;
6565
use rustc_session::lint::builtin::{
66-
BARE_TRAIT_OBJECTS, BROKEN_INTRA_DOC_LINKS, ELIDED_LIFETIMES_IN_PATHS,
66+
AUTOMATIC_LINKS, BARE_TRAIT_OBJECTS, BROKEN_INTRA_DOC_LINKS, ELIDED_LIFETIMES_IN_PATHS,
6767
EXPLICIT_OUTLIVES_REQUIREMENTS, INVALID_CODEBLOCK_ATTRIBUTES, INVALID_HTML_TAGS,
6868
MISSING_DOC_CODE_EXAMPLES, PRIVATE_DOC_TESTS,
6969
};
@@ -307,6 +307,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
307307

308308
add_lint_group!(
309309
"rustdoc",
310+
AUTOMATIC_LINKS,
310311
BROKEN_INTRA_DOC_LINKS,
311312
PRIVATE_INTRA_DOC_LINKS,
312313
INVALID_CODEBLOCK_ATTRIBUTES,

compiler/rustc_session/src/lint/builtin.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,17 @@ declare_lint! {
18911891
"detects invalid HTML tags in doc comments"
18921892
}
18931893

1894+
declare_lint! {
1895+
/// The `automatic_links` lint detects when a URL could be written using
1896+
/// only angle brackets. This is a `rustdoc` only lint, see the
1897+
/// documentation in the [rustdoc book].
1898+
///
1899+
/// [rustdoc book]: ../../../rustdoc/lints.html#automatic_links
1900+
pub AUTOMATIC_LINKS,
1901+
Warn,
1902+
"detects URLs that could be written using only angle brackets"
1903+
}
1904+
18941905
declare_lint! {
18951906
/// The `where_clauses_object_safety` lint detects for [object safety] of
18961907
/// [where clauses].
@@ -2711,6 +2722,7 @@ declare_lint_pass! {
27112722
MISSING_DOC_CODE_EXAMPLES,
27122723
INVALID_HTML_TAGS,
27132724
PRIVATE_DOC_TESTS,
2725+
AUTOMATIC_LINKS,
27142726
WHERE_CLAUSES_OBJECT_SAFETY,
27152727
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
27162728
MACRO_USE_EXTERN_CRATE,

library/core/src/intrinsics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! This includes changes in the stability of the constness.
1010
//!
1111
//! In order to make an intrinsic usable at compile-time, one needs to copy the implementation
12-
//! from https://github.com/rust-lang/miri/blob/master/src/shims/intrinsics.rs to
12+
//! from <https://github.com/rust-lang/miri/blob/master/src/shims/intrinsics.rs> to
1313
//! `compiler/rustc_mir/src/interpret/intrinsics.rs` and add a
1414
//! `#[rustc_const_unstable(feature = "foo", issue = "01234")]` to the intrinsic.
1515
//!

library/core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ pub mod primitive;
284284
unused_imports,
285285
unsafe_op_in_unsafe_fn
286286
)]
287+
#[cfg_attr(not(bootstrap), allow(automatic_links))]
287288
// FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is
288289
// merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
289290
#[allow(clashing_extern_declarations)]

library/core/src/num/dec2flt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
//!
3434
//! Primarily, this module and its children implement the algorithms described in:
3535
//! "How to Read Floating Point Numbers Accurately" by William D. Clinger,
36-
//! available online: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.45.4152
36+
//! available online: <http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.45.4152>
3737
//!
3838
//! In addition, there are numerous helper functions that are used in the paper but not available
3939
//! in Rust (or at least in core). Our version is additionally complicated by the need to handle

library/core/src/slice/sort.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Slice sorting
22
//!
33
//! This module contains a sorting algorithm based on Orson Peters' pattern-defeating quicksort,
4-
//! published at: https://github.com/orlp/pdqsort
4+
//! published at: <https://github.com/orlp/pdqsort>
55
//!
66
//! Unstable sorting is compatible with libcore because it doesn't allocate memory, unlike our
77
//! stable sorting implementation.

src/doc/rustdoc/src/lints.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,40 @@ warning: unclosed HTML tag `h1`
285285
286286
warning: 2 warnings emitted
287287
```
288+
289+
## automatic_links
290+
291+
This lint is **nightly-only** and **warns by default**. It detects links which
292+
could use the "automatic" link syntax. For example:
293+
294+
```rust
295+
/// http://hello.rs
296+
/// [http://a.com](http://a.com)
297+
/// [http://b.com]
298+
///
299+
/// [http://b.com]: http://b.com
300+
pub fn foo() {}
301+
```
302+
303+
Which will give:
304+
305+
```text
306+
warning: this URL is not a hyperlink
307+
--> foo.rs:3:5
308+
|
309+
3 | /// http://hello.rs
310+
| ^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://hello.rs>`
311+
|
312+
313+
warning: unneeded long form for URL
314+
--> foo.rs:4:5
315+
|
316+
4 | /// [http://a.com](http://a.com)
317+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://a.com>`
318+
319+
warning: unneeded long form for URL
320+
--> foo.rs:5:5
321+
|
322+
5 | /// [http://b.com]
323+
| ^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://b.com>`
324+
```

src/librustdoc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ serde_json = "1.0"
1616
smallvec = "1.0"
1717
tempfile = "3"
1818
itertools = "0.9"
19+
regex = "1"
1920

2021
[dev-dependencies]
2122
expect-test = "1.0"

src/librustdoc/core.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,13 @@ pub fn run_core(
330330
let invalid_codeblock_attributes_name = rustc_lint::builtin::INVALID_CODEBLOCK_ATTRIBUTES.name;
331331
let invalid_html_tags = rustc_lint::builtin::INVALID_HTML_TAGS.name;
332332
let renamed_and_removed_lints = rustc_lint::builtin::RENAMED_AND_REMOVED_LINTS.name;
333+
let automatic_links = rustc_lint::builtin::AUTOMATIC_LINKS.name;
333334
let unknown_lints = rustc_lint::builtin::UNKNOWN_LINTS.name;
334335

335336
// In addition to those specific lints, we also need to allow those given through
336337
// command line, otherwise they'll get ignored and we don't want that.
337338
let lints_to_show = vec![
339+
automatic_links.to_owned(),
338340
intra_link_resolution_failure_name.to_owned(),
339341
missing_docs.to_owned(),
340342
missing_doc_example.to_owned(),

0 commit comments

Comments
 (0)