1
Fork 0

Rename lint to non_autolinks

This commit is contained in:
Guillaume Gomez 2020-10-31 15:14:44 +01:00
parent 6be97e2250
commit 9d114506c6
9 changed files with 38 additions and 37 deletions

View file

@ -69,7 +69,7 @@ use rustc_middle::ty::TyCtxt;
use rustc_session::lint::builtin::{ use rustc_session::lint::builtin::{
BARE_TRAIT_OBJECTS, BROKEN_INTRA_DOC_LINKS, ELIDED_LIFETIMES_IN_PATHS, BARE_TRAIT_OBJECTS, BROKEN_INTRA_DOC_LINKS, ELIDED_LIFETIMES_IN_PATHS,
EXPLICIT_OUTLIVES_REQUIREMENTS, INVALID_CODEBLOCK_ATTRIBUTES, INVALID_HTML_TAGS, EXPLICIT_OUTLIVES_REQUIREMENTS, INVALID_CODEBLOCK_ATTRIBUTES, INVALID_HTML_TAGS,
MISSING_DOC_CODE_EXAMPLES, PRIVATE_DOC_TESTS, URL_IMPROVEMENTS, MISSING_DOC_CODE_EXAMPLES, NON_AUTOLINKS, PRIVATE_DOC_TESTS,
}; };
use rustc_span::symbol::{Ident, Symbol}; use rustc_span::symbol::{Ident, Symbol};
use rustc_span::Span; use rustc_span::Span;
@ -313,7 +313,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
add_lint_group!( add_lint_group!(
"rustdoc", "rustdoc",
URL_IMPROVEMENTS, NON_AUTOLINKS,
BROKEN_INTRA_DOC_LINKS, BROKEN_INTRA_DOC_LINKS,
PRIVATE_INTRA_DOC_LINKS, PRIVATE_INTRA_DOC_LINKS,
INVALID_CODEBLOCK_ATTRIBUTES, INVALID_CODEBLOCK_ATTRIBUTES,

View file

@ -1891,12 +1891,12 @@ declare_lint! {
} }
declare_lint! { declare_lint! {
/// The `url_improvements` lint detects when a URL could be written using /// The `non_autolinks` lint detects when a URL could be written using
/// only angle brackets. This is a `rustdoc` only lint, see the /// only angle brackets. This is a `rustdoc` only lint, see the
/// documentation in the [rustdoc book]. /// documentation in the [rustdoc book].
/// ///
/// [rustdoc book]: ../../../rustdoc/lints.html#url_improvements /// [rustdoc book]: ../../../rustdoc/lints.html#non_autolinks
pub URL_IMPROVEMENTS, pub NON_AUTOLINKS,
Warn, Warn,
"detects URLs that could be written using only angle brackets" "detects URLs that could be written using only angle brackets"
} }
@ -2806,7 +2806,7 @@ declare_lint_pass! {
MISSING_DOC_CODE_EXAMPLES, MISSING_DOC_CODE_EXAMPLES,
INVALID_HTML_TAGS, INVALID_HTML_TAGS,
PRIVATE_DOC_TESTS, PRIVATE_DOC_TESTS,
URL_IMPROVEMENTS, NON_AUTOLINKS,
WHERE_CLAUSES_OBJECT_SAFETY, WHERE_CLAUSES_OBJECT_SAFETY,
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK, PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
MACRO_USE_EXTERN_CRATE, MACRO_USE_EXTERN_CRATE,

View file

@ -287,7 +287,7 @@ pub mod primitive;
unused_imports, unused_imports,
unsafe_op_in_unsafe_fn unsafe_op_in_unsafe_fn
)] )]
#[cfg_attr(not(bootstrap), allow(url_improvements))] #[cfg_attr(not(bootstrap), allow(non_autolinks))]
// FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is // 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. // merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
#[allow(clashing_extern_declarations)] #[allow(clashing_extern_declarations)]

View file

@ -286,7 +286,7 @@ warning: unclosed HTML tag `h1`
warning: 2 warnings emitted warning: 2 warnings emitted
``` ```
## url_improvements ## non_autolinks
This lint is **nightly-only** and **warns by default**. It detects links which This lint is **nightly-only** and **warns by default**. It detects links which
could use the "automatic" link syntax. For example: could use the "automatic" link syntax. For example:
@ -309,7 +309,7 @@ warning: this URL is not a hyperlink
1 | /// http://example.org 1 | /// http://example.org
| ^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://example.org>` | ^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://example.org>`
| |
= note: `#[warn(url_improvements)]` on by default = note: `#[warn(non_autolinks)]` on by default
warning: unneeded long form for URL warning: unneeded long form for URL
--> foo.rs:2:5 --> foo.rs:2:5

View file

@ -330,7 +330,7 @@ pub fn run_core(
let invalid_codeblock_attributes_name = rustc_lint::builtin::INVALID_CODEBLOCK_ATTRIBUTES.name; let invalid_codeblock_attributes_name = rustc_lint::builtin::INVALID_CODEBLOCK_ATTRIBUTES.name;
let invalid_html_tags = rustc_lint::builtin::INVALID_HTML_TAGS.name; let invalid_html_tags = rustc_lint::builtin::INVALID_HTML_TAGS.name;
let renamed_and_removed_lints = rustc_lint::builtin::RENAMED_AND_REMOVED_LINTS.name; let renamed_and_removed_lints = rustc_lint::builtin::RENAMED_AND_REMOVED_LINTS.name;
let url_improvements = rustc_lint::builtin::URL_IMPROVEMENTS.name; let non_autolinks = rustc_lint::builtin::NON_AUTOLINKS.name;
let unknown_lints = rustc_lint::builtin::UNKNOWN_LINTS.name; let unknown_lints = rustc_lint::builtin::UNKNOWN_LINTS.name;
// In addition to those specific lints, we also need to allow those given through // In addition to those specific lints, we also need to allow those given through
@ -345,7 +345,7 @@ pub fn run_core(
invalid_html_tags.to_owned(), invalid_html_tags.to_owned(),
renamed_and_removed_lints.to_owned(), renamed_and_removed_lints.to_owned(),
unknown_lints.to_owned(), unknown_lints.to_owned(),
url_improvements.to_owned(), non_autolinks.to_owned(),
]; ];
let (lint_opts, lint_caps) = init_lints(lints_to_show, lint_opts, |lint| { let (lint_opts, lint_caps) = init_lints(lints_to_show, lint_opts, |lint| {

View file

@ -11,8 +11,8 @@ use crate::core::DocContext;
mod stripper; mod stripper;
pub use stripper::*; pub use stripper::*;
mod url_improvements; mod non_autolinks;
pub use self::url_improvements::CHECK_URL_IMPROVEMENTS; pub use self::non_autolinks::CHECK_NON_AUTOLINKS;
mod collapse_docs; mod collapse_docs;
pub use self::collapse_docs::COLLAPSE_DOCS; pub use self::collapse_docs::COLLAPSE_DOCS;
@ -93,7 +93,7 @@ pub const PASSES: &[Pass] = &[
COLLECT_TRAIT_IMPLS, COLLECT_TRAIT_IMPLS,
CALCULATE_DOC_COVERAGE, CALCULATE_DOC_COVERAGE,
CHECK_INVALID_HTML_TAGS, CHECK_INVALID_HTML_TAGS,
CHECK_URL_IMPROVEMENTS, CHECK_NON_AUTOLINKS,
]; ];
/// The list of passes run by default. /// The list of passes run by default.
@ -109,7 +109,7 @@ pub const DEFAULT_PASSES: &[ConditionalPass] = &[
ConditionalPass::always(CHECK_CODE_BLOCK_SYNTAX), ConditionalPass::always(CHECK_CODE_BLOCK_SYNTAX),
ConditionalPass::always(CHECK_INVALID_HTML_TAGS), ConditionalPass::always(CHECK_INVALID_HTML_TAGS),
ConditionalPass::always(PROPAGATE_DOC_CFG), ConditionalPass::always(PROPAGATE_DOC_CFG),
ConditionalPass::always(CHECK_URL_IMPROVEMENTS), ConditionalPass::always(CHECK_NON_AUTOLINKS),
]; ];
/// The list of default passes run when `--doc-coverage` is passed to rustdoc. /// The list of default passes run when `--doc-coverage` is passed to rustdoc.

View file

@ -10,9 +10,9 @@ use rustc_errors::Applicability;
use rustc_feature::UnstableFeatures; use rustc_feature::UnstableFeatures;
use rustc_session::lint; use rustc_session::lint;
pub const CHECK_URL_IMPROVEMENTS: Pass = Pass { pub const CHECK_NON_AUTOLINKS: Pass = Pass {
name: "check-url-improvements", name: "check-non-autolinks",
run: check_url_improvements, run: check_non_autolinks,
description: "detects URLS that could be written using angle brackets", description: "detects URLS that could be written using angle brackets",
}; };
@ -23,14 +23,14 @@ const URL_REGEX: &str = concat!(
r"\b([-a-zA-Z0-9@:%_\+.~#?&/=]*)" // optional query or url fragments r"\b([-a-zA-Z0-9@:%_\+.~#?&/=]*)" // optional query or url fragments
); );
struct UrlImprovementsLinter<'a, 'tcx> { struct NonAutolinksLinter<'a, 'tcx> {
cx: &'a DocContext<'tcx>, cx: &'a DocContext<'tcx>,
regex: Regex, regex: Regex,
} }
impl<'a, 'tcx> UrlImprovementsLinter<'a, 'tcx> { impl<'a, 'tcx> NonAutolinksLinter<'a, 'tcx> {
fn new(cx: &'a DocContext<'tcx>) -> Self { fn new(cx: &'a DocContext<'tcx>) -> Self {
UrlImprovementsLinter { cx, regex: Regex::new(URL_REGEX).expect("failed to build regex") } Self { cx, regex: Regex::new(URL_REGEX).expect("failed to build regex") }
} }
fn find_raw_urls( fn find_raw_urls(
@ -53,17 +53,17 @@ impl<'a, 'tcx> UrlImprovementsLinter<'a, 'tcx> {
} }
} }
pub fn check_url_improvements(krate: Crate, cx: &DocContext<'_>) -> Crate { pub fn check_non_autolinks(krate: Crate, cx: &DocContext<'_>) -> Crate {
if !UnstableFeatures::from_environment().is_nightly_build() { if !UnstableFeatures::from_environment().is_nightly_build() {
krate krate
} else { } else {
let mut coll = UrlImprovementsLinter::new(cx); let mut coll = NonAutolinksLinter::new(cx);
coll.fold_crate(krate) coll.fold_crate(krate)
} }
} }
impl<'a, 'tcx> DocFolder for UrlImprovementsLinter<'a, 'tcx> { impl<'a, 'tcx> DocFolder for NonAutolinksLinter<'a, 'tcx> {
fn fold_item(&mut self, item: Item) -> Option<Item> { fn fold_item(&mut self, item: Item) -> Option<Item> {
let hir_id = match self.cx.as_local_hir_id(item.def_id) { let hir_id = match self.cx.as_local_hir_id(item.def_id) {
Some(hir_id) => hir_id, Some(hir_id) => hir_id,
@ -78,7 +78,7 @@ impl<'a, 'tcx> DocFolder for UrlImprovementsLinter<'a, 'tcx> {
let sp = super::source_span_for_markdown_range(cx, &dox, &range, &item.attrs) let sp = super::source_span_for_markdown_range(cx, &dox, &range, &item.attrs)
.or_else(|| span_of_attrs(&item.attrs)) .or_else(|| span_of_attrs(&item.attrs))
.unwrap_or(item.source.span()); .unwrap_or(item.source.span());
cx.tcx.struct_span_lint_hir(lint::builtin::URL_IMPROVEMENTS, hir_id, sp, |lint| { cx.tcx.struct_span_lint_hir(lint::builtin::NON_AUTOLINKS, hir_id, sp, |lint| {
lint.build(msg) lint.build(msg)
.span_suggestion( .span_suggestion(
sp, sp,
@ -103,7 +103,8 @@ impl<'a, 'tcx> DocFolder for UrlImprovementsLinter<'a, 'tcx> {
Event::End(Tag::Link(_, url, _)) => { Event::End(Tag::Link(_, url, _)) => {
// NOTE: links cannot be nested, so we don't need to // NOTE: links cannot be nested, so we don't need to
// check `kind` // check `kind`
if url.as_ref() == title && !ignore && self.regex.matches(url) { if url.as_ref() == title && !ignore && self.regex.is_match(&url)
{
report_diag( report_diag(
self.cx, self.cx,
"unneeded long form for URL", "unneeded long form for URL",

View file

@ -1,11 +1,11 @@
#![deny(url_improvements)] #![deny(non_autolinks)]
/// [http://a.com](http://a.com) /// [http://aa.com](http://aa.com)
//~^ ERROR unneeded long form for URL //~^ ERROR unneeded long form for URL
/// [http://b.com] /// [http://bb.com]
//~^ ERROR unneeded long form for URL //~^ ERROR unneeded long form for URL
/// ///
/// [http://b.com]: http://b.com /// [http://bb.com]: http://bb.com
/// ///
/// [http://c.com][http://c.com] /// [http://c.com][http://c.com]
pub fn a() {} pub fn a() {}
@ -59,7 +59,7 @@ pub fn c() {}
/// [should_not.lint](should_not.lint) /// [should_not.lint](should_not.lint)
pub fn everything_is_fine_here() {} pub fn everything_is_fine_here() {}
#[allow(url_improvements)] #[allow(non_autolinks)]
pub mod foo { pub mod foo {
/// https://somewhere.com/a?hello=12&bye=11#xyz /// https://somewhere.com/a?hello=12&bye=11#xyz
pub fn bar() {} pub fn bar() {}

View file

@ -1,20 +1,20 @@
error: unneeded long form for URL error: unneeded long form for URL
--> $DIR/url-improvements.rs:3:5 --> $DIR/url-improvements.rs:3:5
| |
LL | /// [http://a.com](http://a.com) LL | /// [http://aa.com](http://aa.com)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://a.com>` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://aa.com>`
| |
note: the lint level is defined here note: the lint level is defined here
--> $DIR/url-improvements.rs:1:9 --> $DIR/url-improvements.rs:1:9
| |
LL | #![deny(url_improvements)] LL | #![deny(non_autolinks)]
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
error: unneeded long form for URL error: unneeded long form for URL
--> $DIR/url-improvements.rs:5:5 --> $DIR/url-improvements.rs:5:5
| |
LL | /// [http://b.com] LL | /// [http://bb.com]
| ^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://b.com>` | ^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://bb.com>`
error: this URL is not a hyperlink error: this URL is not a hyperlink
--> $DIR/url-improvements.rs:13:5 --> $DIR/url-improvements.rs:13:5