Skip to content

Commit

Permalink
Rename non_autolinks -> bare_urls
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 committed Apr 5, 2021
1 parent 6f89468 commit ef4e5b9
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 45 deletions.
3 changes: 2 additions & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ pub mod primitive;
unused_imports,
unsafe_op_in_unsafe_fn
)]
#[allow(rustdoc::non_autolinks)]
#[cfg_attr(bootstrap, allow(rustdoc::non_autolinks))]
#[cfg_attr(not(bootstrap), allow(rustdoc::bare_urls))]
// FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is
// merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
#[allow(clashing_extern_declarations)]
Expand Down
23 changes: 8 additions & 15 deletions src/doc/rustdoc/src/lints.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,40 +294,33 @@ warning: unclosed HTML tag `h1`
warning: 2 warnings emitted
```

## non_autolinks
## bare_urls

This lint is **nightly-only** and **warns by default**. It detects links which
could use the "automatic" link syntax. For example:
This lint is **nightly-only** and **warns by default**. It detects URLs which are not links.
For example:

```rust
/// http://example.org
/// [http://example.com](http://example.com)
/// [http://example.net]
///
/// [http://example.com]: http://example.com
pub fn foo() {}
```

Which will give:

```text
warning: this URL is not a hyperlink
--> foo.rs:1:5
--> links.rs:1:5
|
1 | /// http://example.org
| ^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://example.org>`
|
= note: `#[warn(rustdoc::non_autolinks)]` on by default
warning: unneeded long form for URL
--> foo.rs:2:5
|
2 | /// [http://example.com](http://example.com)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://example.com>`
= note: `#[warn(rustdoc::bare_urls)]` on by default
warning: this URL is not a hyperlink
--> foo.rs:3:6
--> links.rs:3:6
|
3 | /// [http://example.net]
| ^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://example.net>`
warning: 2 warnings emitted
```
15 changes: 8 additions & 7 deletions src/librustdoc/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,13 @@ declare_rustdoc_lint! {
}

declare_rustdoc_lint! {
/// The `non_autolinks` lint detects when a URL could be written using
/// only angle brackets. This is a `rustdoc` only lint, see the
/// documentation in the [rustdoc book].
/// The `non_autolinks` lint detects when a URL is not a hyperlink.
/// This is a `rustdoc` only lint, see the documentation in the [rustdoc book].
///
/// [rustdoc book]: ../../../rustdoc/lints.html#non_autolinks
NON_AUTOLINKS,
/// [rustdoc book]: ../../../rustdoc/lints.html#bare_urls
BARE_URLS,
Warn,
"detects URLs that could be written using only angle brackets"
"detects URLs that are not hyperlinks"
}

crate static RUSTDOC_LINTS: Lazy<Vec<&'static Lint>> = Lazy::new(|| {
Expand All @@ -166,7 +165,7 @@ crate static RUSTDOC_LINTS: Lazy<Vec<&'static Lint>> = Lazy::new(|| {
PRIVATE_DOC_TESTS,
INVALID_CODEBLOCK_ATTRIBUTES,
INVALID_HTML_TAGS,
NON_AUTOLINKS,
BARE_URLS,
MISSING_CRATE_LEVEL_DOCS,
]
});
Expand All @@ -185,4 +184,6 @@ crate fn register_lints(_sess: &Session, lint_store: &mut LintStore) {
}
lint_store
.register_renamed("intra_doc_link_resolution_failure", "rustdoc::broken_intra_doc_links");
lint_store.register_renamed("non_autolinks", "rustdoc::bare_urls");
lint_store.register_renamed("rustdoc::non_autolinks", "rustdoc::bare_urls");
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use rustc_errors::Applicability;
use std::lazy::SyncLazy;
use std::mem;

crate const CHECK_NON_AUTOLINKS: Pass = Pass {
name: "check-non-autolinks",
run: check_non_autolinks,
description: "detects URLs that could be linkified",
crate const CHECK_BARE_URLS: Pass = Pass {
name: "check-bare-urls",
run: check_bare_urls,
description: "detects URLs that are not hyperlinks",
};

const URL_REGEX: SyncLazy<Regex> = SyncLazy::new(|| {
Expand All @@ -26,11 +26,11 @@ const URL_REGEX: SyncLazy<Regex> = SyncLazy::new(|| {
.expect("failed to build regex")
});

struct NonAutolinksLinter<'a, 'tcx> {
struct BareUrlsLinter<'a, 'tcx> {
cx: &'a mut DocContext<'tcx>,
}

impl<'a, 'tcx> NonAutolinksLinter<'a, 'tcx> {
impl<'a, 'tcx> BareUrlsLinter<'a, 'tcx> {
fn find_raw_urls(
&self,
text: &str,
Expand All @@ -52,11 +52,11 @@ impl<'a, 'tcx> NonAutolinksLinter<'a, 'tcx> {
}
}

crate fn check_non_autolinks(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
NonAutolinksLinter { cx }.fold_crate(krate)
crate fn check_bare_urls(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
BareUrlsLinter { cx }.fold_crate(krate)
}

impl<'a, 'tcx> DocFolder for NonAutolinksLinter<'a, 'tcx> {
impl<'a, 'tcx> DocFolder for BareUrlsLinter<'a, 'tcx> {
fn fold_item(&mut self, item: Item) -> Option<Item> {
let hir_id = match DocContext::as_local_hir_id(self.cx.tcx, item.def_id) {
Some(hir_id) => hir_id,
Expand All @@ -71,7 +71,7 @@ impl<'a, 'tcx> DocFolder for NonAutolinksLinter<'a, 'tcx> {
let sp = super::source_span_for_markdown_range(cx.tcx, &dox, &range, &item.attrs)
.or_else(|| span_of_attrs(&item.attrs))
.unwrap_or(item.span.inner());
cx.tcx.struct_span_lint_hir(crate::lint::NON_AUTOLINKS, hir_id, sp, |lint| {
cx.tcx.struct_span_lint_hir(crate::lint::BARE_URLS, hir_id, sp, |lint| {
lint.build(msg)
.span_suggestion(
sp,
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/passes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use crate::core::DocContext;
mod stripper;
crate use stripper::*;

mod non_autolinks;
crate use self::non_autolinks::CHECK_NON_AUTOLINKS;
mod bare_urls;
crate use self::bare_urls::CHECK_BARE_URLS;

mod strip_hidden;
crate use self::strip_hidden::STRIP_HIDDEN;
Expand Down Expand Up @@ -90,7 +90,7 @@ crate const PASSES: &[Pass] = &[
COLLECT_TRAIT_IMPLS,
CALCULATE_DOC_COVERAGE,
CHECK_INVALID_HTML_TAGS,
CHECK_NON_AUTOLINKS,
CHECK_BARE_URLS,
];

/// The list of passes run by default.
Expand All @@ -105,7 +105,7 @@ crate const DEFAULT_PASSES: &[ConditionalPass] = &[
ConditionalPass::always(CHECK_CODE_BLOCK_SYNTAX),
ConditionalPass::always(CHECK_INVALID_HTML_TAGS),
ConditionalPass::always(PROPAGATE_DOC_CFG),
ConditionalPass::always(CHECK_NON_AUTOLINKS),
ConditionalPass::always(CHECK_BARE_URLS),
];

/// The list of default passes run when `--doc-coverage` is passed to rustdoc.
Expand Down
6 changes: 5 additions & 1 deletion src/test/rustdoc-ui/unknown-renamed-lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
//~^ ERROR unknown lint: `rustdoc::x`
#![deny(intra_doc_link_resolution_failure)]
//~^ ERROR renamed to `rustdoc::broken_intra_doc_links`

#![deny(non_autolinks)]
//~^ ERROR renamed to `rustdoc::bare_urls`
#![deny(rustdoc::non_autolinks)]
//~^ ERROR renamed to `rustdoc::bare_urls`

#![deny(private_doc_tests)]
// FIXME: the old names for rustdoc lints should warn by default once `rustdoc::` makes it to the
// stable channel.

Expand Down
18 changes: 15 additions & 3 deletions src/test/rustdoc-ui/unknown-renamed-lints.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,31 @@ note: the lint level is defined here
LL | #![deny(renamed_and_removed_lints)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: lint `non_autolinks` has been renamed to `rustdoc::bare_urls`
--> $DIR/unknown-renamed-lints.rs:11:9
|
LL | #![deny(non_autolinks)]
| ^^^^^^^^^^^^^ help: use the new name: `rustdoc::bare_urls`

error: lint `rustdoc::non_autolinks` has been renamed to `rustdoc::bare_urls`
--> $DIR/unknown-renamed-lints.rs:13:9
|
LL | #![deny(rustdoc::non_autolinks)]
| ^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `rustdoc::bare_urls`

error: lint `rustdoc` has been removed: use `rustdoc::all` instead
--> $DIR/unknown-renamed-lints.rs:16:9
--> $DIR/unknown-renamed-lints.rs:20:9
|
LL | #![deny(rustdoc)]
| ^^^^^^^

error: unknown lint: `rustdoc::intra_doc_link_resolution_failure`
--> $DIR/unknown-renamed-lints.rs:20:9
--> $DIR/unknown-renamed-lints.rs:24:9
|
LL | #![deny(rustdoc::intra_doc_link_resolution_failure)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: Compilation failed, aborting rustdoc

error: aborting due to 6 previous errors
error: aborting due to 8 previous errors

4 changes: 2 additions & 2 deletions src/test/rustdoc-ui/url-improvements.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(rustdoc::non_autolinks)]
#![deny(rustdoc::bare_urls)]

/// https://somewhere.com
//~^ ERROR this URL is not a hyperlink
Expand Down Expand Up @@ -51,7 +51,7 @@ pub fn c() {}
/// [should_not.lint](should_not.lint)
pub fn everything_is_fine_here() {}

#[allow(rustdoc::non_autolinks)]
#[allow(rustdoc::bare_urls)]
pub mod foo {
/// https://somewhere.com/a?hello=12&bye=11#xyz
pub fn bar() {}
Expand Down
4 changes: 2 additions & 2 deletions src/test/rustdoc-ui/url-improvements.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ LL | /// https://somewhere.com
note: the lint level is defined here
--> $DIR/url-improvements.rs:1:9
|
LL | #![deny(rustdoc::non_autolinks)]
| ^^^^^^^^^^^^^^^^^^^^^^
LL | #![deny(rustdoc::bare_urls)]
| ^^^^^^^^^^^^^^^^^^

error: this URL is not a hyperlink
--> $DIR/url-improvements.rs:5:5
Expand Down

0 comments on commit ef4e5b9

Please sign in to comment.