Skip to content

Commit e2d40b2

Browse files
authored
Rollup merge of #137955 - Noratrieb:rustdoc-json-long-lines, r=aDotInTheVoid,jieyouxu
Always allow rustdoc-json tests to contain long lines The rustdoc-json test syntax often requires very long lines, so the checks for long lines aren't really useful. `@aDotInTheVoid` told me she'd like this and r? jieyouxu you're gonna tell me that the implementation is terrible. at least the performance seems reasonable: 2.5s after and 2.5s before.
2 parents 61f3ec4 + dfed028 commit e2d40b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+17
-76
lines changed

src/tools/tidy/src/style.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ const ANNOTATIONS_TO_IGNORE: &[&str] = &[
7272
"//@ normalize-stderr",
7373
];
7474

75+
const LINELENGTH_CHECK: &str = "linelength";
76+
7577
// If you edit this, also edit where it gets used in `check` (calling `contains_ignore_directives`)
7678
const CONFIGURABLE_CHECKS: [&str; 11] = [
7779
"cr",
7880
"undocumented-unsafe",
7981
"tab",
80-
"linelength",
82+
LINELENGTH_CHECK,
8183
"filelength",
8284
"end-whitespace",
8385
"trailing-newlines",
@@ -250,14 +252,24 @@ enum Directive {
250252
// Use a fixed size array in the return type to catch mistakes with changing `CONFIGURABLE_CHECKS`
251253
// without changing the code in `check` easier.
252254
fn contains_ignore_directives<const N: usize>(
255+
path_str: &str,
253256
can_contain: bool,
254257
contents: &str,
255258
checks: [&str; N],
256259
) -> [Directive; N] {
257-
if !can_contain {
260+
// The rustdoc-json test syntax often requires very long lines, so the checks
261+
// for long lines aren't really useful.
262+
let always_ignore_linelength = path_str.contains("rustdoc-json");
263+
264+
if !can_contain && !always_ignore_linelength {
258265
return [Directive::Deny; N];
259266
}
267+
260268
checks.map(|check| {
269+
if check == LINELENGTH_CHECK && always_ignore_linelength {
270+
return Directive::Ignore(false);
271+
}
272+
261273
// Update `can_contain` when changing this
262274
if contents.contains(&format!("// ignore-tidy-{check}"))
263275
|| contents.contains(&format!("# ignore-tidy-{check}"))
@@ -367,6 +379,7 @@ pub fn check(path: &Path, bad: &mut bool) {
367379

368380
walk(path, skip, &mut |entry, contents| {
369381
let file = entry.path();
382+
let path_str = file.to_string_lossy();
370383
let filename = file.file_name().unwrap().to_string_lossy();
371384

372385
let is_css_file = filename.ends_with(".css");
@@ -422,7 +435,7 @@ pub fn check(path: &Path, bad: &mut bool) {
422435
mut skip_copyright,
423436
mut skip_dbg,
424437
mut skip_odd_backticks,
425-
] = contains_ignore_directives(can_contain, &contents, CONFIGURABLE_CHECKS);
438+
] = contains_ignore_directives(&path_str, can_contain, &contents, CONFIGURABLE_CHECKS);
426439
let mut leading_new_lines = false;
427440
let mut trailing_new_lines = 0;
428441
let mut lines = 0;
@@ -502,7 +515,7 @@ pub fn check(path: &Path, bad: &mut bool) {
502515
let contains_potential_directive =
503516
possible_line_start && (line.contains("-tidy") || line.contains("tidy-"));
504517
let has_recognized_ignore_directive =
505-
contains_ignore_directives(can_contain, line, CONFIGURABLE_CHECKS)
518+
contains_ignore_directives(&path_str, can_contain, line, CONFIGURABLE_CHECKS)
506519
.into_iter()
507520
.any(|directive| matches!(directive, Directive::Ignore(_)));
508521
let has_alphabetical_directive = line.contains("tidy-alphabetical-start")

tests/rustdoc-json/enums/discriminant/limits.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ignore-tidy-linelength
21
#![feature(repr128)]
32
#![allow(incomplete_features)]
43

tests/rustdoc-json/enums/discriminant/num_underscore_and_suffix.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
#[repr(u32)]
42
pub enum Foo {
53
//@ is "$.index[*][?(@.name=='Basic')].inner.variant.discriminant.value" '"0"'

tests/rustdoc-json/enums/discriminant/only_some_have_discriminant.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
pub enum Foo {
42
//@ is "$.index[*][?(@.name=='Has')].inner.variant.discriminant" '{"expr":"0", "value":"0"}'
53
Has = 0,

tests/rustdoc-json/enums/discriminant/struct.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
#[repr(i32)]
42
//@ is "$.index[*][?(@.name=='Foo')].attrs" '["#[attr=\"Repr([ReprInt(SignedInt(I32))])\")]\n"]'
53
pub enum Foo {

tests/rustdoc-json/enums/discriminant/tuple.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
#[repr(u32)]
42
//@ is "$.index[*][?(@.name=='Foo')].attrs" '["#[attr=\"Repr([ReprInt(UnsignedInt(U32))])\")]\n"]'
53
pub enum Foo {

tests/rustdoc-json/enums/kind.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
pub enum Foo {
42
//@ set Unit = "$.index[*][?(@.name=='Unit')].id"
53
//@ is "$.index[*][?(@.name=='Unit')].inner.variant.kind" '"plain"'

tests/rustdoc-json/fn_pointer/abi.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
#![feature(abi_vectorcall)]
42

53
//@ is "$.index[*][?(@.name=='AbiRust')].inner.type_alias.type.function_pointer.header.abi" \"Rust\"

tests/rustdoc-json/fn_pointer/generics.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
//@ count "$.index[*][?(@.name=='WithHigherRankTraitBounds')].inner.type_alias.type.function_pointer.sig.inputs[*]" 1
42
//@ is "$.index[*][?(@.name=='WithHigherRankTraitBounds')].inner.type_alias.type.function_pointer.sig.inputs[0][0]" '"val"'
53
//@ is "$.index[*][?(@.name=='WithHigherRankTraitBounds')].inner.type_alias.type.function_pointer.sig.inputs[0][1].borrowed_ref.lifetime" \"\'c\"

tests/rustdoc-json/fn_pointer/qualifiers.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
//@ is "$.index[*][?(@.name=='FnPointer')].inner.type_alias.type.function_pointer.header.is_unsafe" false
42
//@ is "$.index[*][?(@.name=='FnPointer')].inner.type_alias.type.function_pointer.header.is_const" false
53
//@ is "$.index[*][?(@.name=='FnPointer')].inner.type_alias.type.function_pointer.header.is_async" false

tests/rustdoc-json/fns/abi.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
#![feature(abi_vectorcall)]
42

53
//@ is "$.index[*][?(@.name=='abi_rust')].inner.function.header.abi" \"Rust\"

tests/rustdoc-json/fns/async_return.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ edition:2021
2-
// ignore-tidy-linelength
32

43
// Regression test for <https://github.com/rust-lang/rust/issues/101199>
54

tests/rustdoc-json/fns/generic_args.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
//@ set foo = "$.index[*][?(@.name=='Foo')].id"
42
pub trait Foo {}
53

tests/rustdoc-json/fns/generic_returns.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
//@ count "$.index[*][?(@.name=='generic_returns')].inner.module.items[*]" 2
42

53
//@ set foo = "$.index[*][?(@.name=='Foo')].id"

tests/rustdoc-json/fns/generics.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
//@ set wham_id = "$.index[*][?(@.name=='Wham')].id"
42
pub trait Wham {}
53

tests/rustdoc-json/generic-associated-types/gats.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
pub trait Display {}
42

53
pub trait LendingIterator {

tests/rustdoc-json/impl-trait-in-assoc-type.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ignore-tidy-linelength
21
#![feature(impl_trait_in_assoc_type)]
32

43
pub struct AlwaysTrue;

tests/rustdoc-json/lifetime/longest.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
//@ is "$.index[*][?(@.name=='longest')].inner.function.generics.params[0].name" \"\'a\"
42
//@ is "$.index[*][?(@.name=='longest')].inner.function.generics.params[0].kind" '{"lifetime": {"outlives": []}}'
53
//@ is "$.index[*][?(@.name=='longest')].inner.function.generics.params[0].kind" '{"lifetime": {"outlives": []}}'

tests/rustdoc-json/lifetime/outlives.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
//@ count "$.index[*][?(@.name=='foo')].inner.function.generics.params[*]" 3
42
//@ is "$.index[*][?(@.name=='foo')].inner.function.generics.where_predicates" []
53
//@ is "$.index[*][?(@.name=='foo')].inner.function.generics.params[0].name" \"\'a\"

tests/rustdoc-json/lifetime/outlives_in_param.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
//@ count '$.index[*][?(@.name=="outlives")].inner.function.generics.params[*]' 2
42
//@ is '$.index[*][?(@.name=="outlives")].inner.function.generics.params[0].name' \"\'a\"
53
//@ is '$.index[*][?(@.name=="outlives")].inner.function.generics.params[0].kind.lifetime.outlives' []

tests/rustdoc-json/lifetime/outlives_in_where.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
//@ is '$.index[*][?(@.name=="on_lifetimes")].inner.function.generics.where_predicates' '[{"lifetime_predicate": {"lifetime": "'\''all", "outlives": ["'\''a", "'\''b", "'\''c"]}}]'
42
pub fn on_lifetimes<'a, 'b, 'c, 'all>()
53
where

tests/rustdoc-json/methods/abi.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
#![feature(abi_vectorcall)]
42

53
//@ has "$.index[*][?(@.name=='Foo')]"

tests/rustdoc-json/non_lifetime_binders.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
#![feature(non_lifetime_binders)]
42
#![allow(incomplete_features)]
53

tests/rustdoc-json/path_name.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// See https://github.com/rust-lang/rust/issues/135600
44
// and https://github.com/rust-lang/rust/pull/134880#issuecomment-2596386111
55
//
6-
// ignore-tidy-linelength
76
//@ aux-build: defines_and_reexports.rs
87
extern crate defines_and_reexports;
98

tests/rustdoc-json/reexport/doc_inline_external_crate.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Regression Test for https://github.com/rust-lang/rust/issues/110138
22
//@ aux-build: enum_with_discriminant.rs
3-
// ignore-tidy-linelength
43

54
#[doc(inline)]
65
pub extern crate enum_with_discriminant;

tests/rustdoc-json/reexport/export_extern_crate_as_self.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@
22
33
#![crate_name = "export_extern_crate_as_self"]
44

5-
// ignore-tidy-linelength
6-
75
//@ is "$.index[*][?(@.inner.module)].name" \"export_extern_crate_as_self\"
86
pub extern crate self as export_extern_crate_as_self; // Must be the same name as the crate already has

tests/rustdoc-json/reexport/private_twice_one_inline.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ aux-build:pub-struct.rs
2-
// ignore-tidy-linelength
32

43
// Test for the ICE in https://github.com/rust-lang/rust/issues/83057
54
// An external type re-exported with different attributes shouldn't cause an error

tests/rustdoc-json/reexport/private_two_names.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
// Test for the ICE in https://github.com/rust-lang/rust/issues/83720
42
// A pub-in-private type re-exported under two different names shouldn't cause an error
53

tests/rustdoc-json/reexport/same_type_reexported_more_than_once.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
// Regression test for <https://github.com/rust-lang/rust/issues/97432>.
42

53
#![no_std]

tests/rustdoc-json/return_private.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Regression test for <https://github.com/rust-lang/rust/issues/96161>.
2-
// ignore-tidy-linelength
32

43
mod secret {
54
//@ set struct_secret = "$.index[*][?(@.name == 'Secret' && @.inner.struct)].id"

tests/rustdoc-json/statics/extern.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ignore-tidy-linelength
21
//@ edition: 2021
32

43
extern "C" {

tests/rustdoc-json/structs/with_primitives.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
//@ is "$.index[*][?(@.name=='WithPrimitives')].visibility" \"public\"
42
//@ has "$.index[*][?(@.name=='WithPrimitives')].inner.struct"
53
//@ is "$.index[*][?(@.name=='WithPrimitives')].inner.struct.generics.params[0].name" \"\'a\"

tests/rustdoc-json/trait_alias.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ignore-tidy-linelength
21
#![feature(trait_alias)]
32

43
//@ set StrLike = "$.index[*][?(@.name=='StrLike')].id"

tests/rustdoc-json/traits/private_supertrait.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
//@ !has "$.index[*][?(@.name == 'sealed')]"
42
mod sealed {
53
//@ set sealed_id = "$.index[*][?(@.name=='Sealed')].id"

tests/rustdoc-json/traits/self.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
pub struct Foo;
42

53
// Check that Self is represented uniformly between inherent impls, trait impls,

tests/rustdoc-json/traits/supertrait.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
//@ set loud_id = "$.index[*][?(@.name=='Loud')].id"
42
pub trait Loud {}
53

tests/rustdoc-json/traits/trait_alias.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Regression test for <https://github.com/rust-lang/rust/issues/104923>
2-
// ignore-tidy-linelength
32

43
#![feature(trait_alias)]
54

tests/rustdoc-json/type/dyn.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ignore-tidy-linelength
21
use std::fmt::Debug;
32

43
//@ count "$.index[*][?(@.name=='dyn')].inner.module.items[*]" 3

tests/rustdoc-json/type/fn_lifetime.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
//@ has "$.index[*][?(@.name=='GenericFn')].inner.type_alias"
42

53
//@ ismany "$.index[*][?(@.name=='GenericFn')].inner.type_alias.generics.params[*].name" \"\'a\"

tests/rustdoc-json/type/generic_default.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
//@ set result = "$.index[*][?(@.name=='Result')].id"
42
pub enum Result<T, E> {
53
Ok(T),

tests/rustdoc-json/type/hrtb.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-linelength
2-
31
//@ is "$.index[*][?(@.name=='genfn')].inner.function.generics.where_predicates[0].bound_predicate.type" '{"generic": "F"}'
42
//@ is "$.index[*][?(@.name=='genfn')].inner.function.generics.where_predicates[0].bound_predicate.generic_params" '[{"kind": {"lifetime": {"outlives": []}},"name": "'\''a"},{"kind": {"lifetime": {"outlives": []}},"name": "'\''b"}]'
53
pub fn genfn<F>(f: F)

tests/rustdoc-json/type/inherent_associated_type.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ignore-tidy-linelength
21
#![feature(inherent_associated_types)]
32
#![allow(incomplete_features)]
43

tests/rustdoc-json/type/inherent_associated_type_bound.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ignore-tidy-linelength
21
#![feature(inherent_associated_types)]
32
#![allow(incomplete_features)]
43

tests/rustdoc-json/type/inherent_associated_type_projections.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ignore-tidy-linelength
21
#![feature(inherent_associated_types)]
32
#![allow(incomplete_features)]
43

0 commit comments

Comments
 (0)