Skip to content

Commit

Permalink
Unrolled build for rust-lang#137955
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#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.
  • Loading branch information
rust-timer authored Mar 4, 2025
2 parents 2010bba + dfed028 commit d7de830
Show file tree
Hide file tree
Showing 44 changed files with 17 additions and 76 deletions.
21 changes: 17 additions & 4 deletions src/tools/tidy/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ const ANNOTATIONS_TO_IGNORE: &[&str] = &[
"//@ normalize-stderr",
];

const LINELENGTH_CHECK: &str = "linelength";

// If you edit this, also edit where it gets used in `check` (calling `contains_ignore_directives`)
const CONFIGURABLE_CHECKS: [&str; 11] = [
"cr",
"undocumented-unsafe",
"tab",
"linelength",
LINELENGTH_CHECK,
"filelength",
"end-whitespace",
"trailing-newlines",
Expand Down Expand Up @@ -250,14 +252,24 @@ enum Directive {
// Use a fixed size array in the return type to catch mistakes with changing `CONFIGURABLE_CHECKS`
// without changing the code in `check` easier.
fn contains_ignore_directives<const N: usize>(
path_str: &str,
can_contain: bool,
contents: &str,
checks: [&str; N],
) -> [Directive; N] {
if !can_contain {
// The rustdoc-json test syntax often requires very long lines, so the checks
// for long lines aren't really useful.
let always_ignore_linelength = path_str.contains("rustdoc-json");

if !can_contain && !always_ignore_linelength {
return [Directive::Deny; N];
}

checks.map(|check| {
if check == LINELENGTH_CHECK && always_ignore_linelength {
return Directive::Ignore(false);
}

// Update `can_contain` when changing this
if contents.contains(&format!("// ignore-tidy-{check}"))
|| contents.contains(&format!("# ignore-tidy-{check}"))
Expand Down Expand Up @@ -367,6 +379,7 @@ pub fn check(path: &Path, bad: &mut bool) {

walk(path, skip, &mut |entry, contents| {
let file = entry.path();
let path_str = file.to_string_lossy();
let filename = file.file_name().unwrap().to_string_lossy();

let is_css_file = filename.ends_with(".css");
Expand Down Expand Up @@ -422,7 +435,7 @@ pub fn check(path: &Path, bad: &mut bool) {
mut skip_copyright,
mut skip_dbg,
mut skip_odd_backticks,
] = contains_ignore_directives(can_contain, &contents, CONFIGURABLE_CHECKS);
] = contains_ignore_directives(&path_str, can_contain, &contents, CONFIGURABLE_CHECKS);
let mut leading_new_lines = false;
let mut trailing_new_lines = 0;
let mut lines = 0;
Expand Down Expand Up @@ -502,7 +515,7 @@ pub fn check(path: &Path, bad: &mut bool) {
let contains_potential_directive =
possible_line_start && (line.contains("-tidy") || line.contains("tidy-"));
let has_recognized_ignore_directive =
contains_ignore_directives(can_contain, line, CONFIGURABLE_CHECKS)
contains_ignore_directives(&path_str, can_contain, line, CONFIGURABLE_CHECKS)
.into_iter()
.any(|directive| matches!(directive, Directive::Ignore(_)));
let has_alphabetical_directive = line.contains("tidy-alphabetical-start")
Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc-json/enums/discriminant/limits.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ignore-tidy-linelength
#![feature(repr128)]
#![allow(incomplete_features)]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

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

pub enum Foo {
//@ is "$.index[*][?(@.name=='Has')].inner.variant.discriminant" '{"expr":"0", "value":"0"}'
Has = 0,
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/enums/discriminant/struct.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

#[repr(i32)]
//@ is "$.index[*][?(@.name=='Foo')].attrs" '["#[attr=\"Repr([ReprInt(SignedInt(I32))])\")]\n"]'
pub enum Foo {
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/enums/discriminant/tuple.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

#[repr(u32)]
//@ is "$.index[*][?(@.name=='Foo')].attrs" '["#[attr=\"Repr([ReprInt(UnsignedInt(U32))])\")]\n"]'
pub enum Foo {
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/enums/kind.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

pub enum Foo {
//@ set Unit = "$.index[*][?(@.name=='Unit')].id"
//@ is "$.index[*][?(@.name=='Unit')].inner.variant.kind" '"plain"'
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/fn_pointer/abi.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

#![feature(abi_vectorcall)]

//@ is "$.index[*][?(@.name=='AbiRust')].inner.type_alias.type.function_pointer.header.abi" \"Rust\"
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/fn_pointer/generics.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

//@ count "$.index[*][?(@.name=='WithHigherRankTraitBounds')].inner.type_alias.type.function_pointer.sig.inputs[*]" 1
//@ is "$.index[*][?(@.name=='WithHigherRankTraitBounds')].inner.type_alias.type.function_pointer.sig.inputs[0][0]" '"val"'
//@ is "$.index[*][?(@.name=='WithHigherRankTraitBounds')].inner.type_alias.type.function_pointer.sig.inputs[0][1].borrowed_ref.lifetime" \"\'c\"
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/fn_pointer/qualifiers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

//@ is "$.index[*][?(@.name=='FnPointer')].inner.type_alias.type.function_pointer.header.is_unsafe" false
//@ is "$.index[*][?(@.name=='FnPointer')].inner.type_alias.type.function_pointer.header.is_const" false
//@ is "$.index[*][?(@.name=='FnPointer')].inner.type_alias.type.function_pointer.header.is_async" false
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/fns/abi.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

#![feature(abi_vectorcall)]

//@ is "$.index[*][?(@.name=='abi_rust')].inner.function.header.abi" \"Rust\"
Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc-json/fns/async_return.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ edition:2021
// ignore-tidy-linelength

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

Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/fns/generic_args.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

//@ set foo = "$.index[*][?(@.name=='Foo')].id"
pub trait Foo {}

Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/fns/generic_returns.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

//@ count "$.index[*][?(@.name=='generic_returns')].inner.module.items[*]" 2

//@ set foo = "$.index[*][?(@.name=='Foo')].id"
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/fns/generics.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

//@ set wham_id = "$.index[*][?(@.name=='Wham')].id"
pub trait Wham {}

Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/generic-associated-types/gats.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

pub trait Display {}

pub trait LendingIterator {
Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc-json/impl-trait-in-assoc-type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ignore-tidy-linelength
#![feature(impl_trait_in_assoc_type)]

pub struct AlwaysTrue;
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/lifetime/longest.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

//@ is "$.index[*][?(@.name=='longest')].inner.function.generics.params[0].name" \"\'a\"
//@ is "$.index[*][?(@.name=='longest')].inner.function.generics.params[0].kind" '{"lifetime": {"outlives": []}}'
//@ is "$.index[*][?(@.name=='longest')].inner.function.generics.params[0].kind" '{"lifetime": {"outlives": []}}'
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/lifetime/outlives.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

//@ count "$.index[*][?(@.name=='foo')].inner.function.generics.params[*]" 3
//@ is "$.index[*][?(@.name=='foo')].inner.function.generics.where_predicates" []
//@ is "$.index[*][?(@.name=='foo')].inner.function.generics.params[0].name" \"\'a\"
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/lifetime/outlives_in_param.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

//@ count '$.index[*][?(@.name=="outlives")].inner.function.generics.params[*]' 2
//@ is '$.index[*][?(@.name=="outlives")].inner.function.generics.params[0].name' \"\'a\"
//@ is '$.index[*][?(@.name=="outlives")].inner.function.generics.params[0].kind.lifetime.outlives' []
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/lifetime/outlives_in_where.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

//@ is '$.index[*][?(@.name=="on_lifetimes")].inner.function.generics.where_predicates' '[{"lifetime_predicate": {"lifetime": "'\''all", "outlives": ["'\''a", "'\''b", "'\''c"]}}]'
pub fn on_lifetimes<'a, 'b, 'c, 'all>()
where
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/methods/abi.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

#![feature(abi_vectorcall)]

//@ has "$.index[*][?(@.name=='Foo')]"
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/non_lifetime_binders.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

#![feature(non_lifetime_binders)]
#![allow(incomplete_features)]

Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc-json/path_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See https://github.com/rust-lang/rust/issues/135600
// and https://github.com/rust-lang/rust/pull/134880#issuecomment-2596386111
//
// ignore-tidy-linelength
//@ aux-build: defines_and_reexports.rs
extern crate defines_and_reexports;

Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc-json/reexport/doc_inline_external_crate.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Regression Test for https://github.com/rust-lang/rust/issues/110138
//@ aux-build: enum_with_discriminant.rs
// ignore-tidy-linelength

#[doc(inline)]
pub extern crate enum_with_discriminant;
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/reexport/export_extern_crate_as_self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
#![crate_name = "export_extern_crate_as_self"]

// ignore-tidy-linelength

//@ is "$.index[*][?(@.inner.module)].name" \"export_extern_crate_as_self\"
pub extern crate self as export_extern_crate_as_self; // Must be the same name as the crate already has
1 change: 0 additions & 1 deletion tests/rustdoc-json/reexport/private_twice_one_inline.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ aux-build:pub-struct.rs
// ignore-tidy-linelength

// Test for the ICE in https://github.com/rust-lang/rust/issues/83057
// An external type re-exported with different attributes shouldn't cause an error
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/reexport/private_two_names.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

// Test for the ICE in https://github.com/rust-lang/rust/issues/83720
// A pub-in-private type re-exported under two different names shouldn't cause an error

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

// Regression test for <https://github.com/rust-lang/rust/issues/97432>.

#![no_std]
Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc-json/return_private.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Regression test for <https://github.com/rust-lang/rust/issues/96161>.
// ignore-tidy-linelength

mod secret {
//@ set struct_secret = "$.index[*][?(@.name == 'Secret' && @.inner.struct)].id"
Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc-json/statics/extern.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ignore-tidy-linelength
//@ edition: 2021

extern "C" {
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/structs/with_primitives.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

//@ is "$.index[*][?(@.name=='WithPrimitives')].visibility" \"public\"
//@ has "$.index[*][?(@.name=='WithPrimitives')].inner.struct"
//@ is "$.index[*][?(@.name=='WithPrimitives')].inner.struct.generics.params[0].name" \"\'a\"
Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc-json/trait_alias.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ignore-tidy-linelength
#![feature(trait_alias)]

//@ set StrLike = "$.index[*][?(@.name=='StrLike')].id"
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/traits/private_supertrait.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

//@ !has "$.index[*][?(@.name == 'sealed')]"
mod sealed {
//@ set sealed_id = "$.index[*][?(@.name=='Sealed')].id"
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/traits/self.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

pub struct Foo;

// Check that Self is represented uniformly between inherent impls, trait impls,
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/traits/supertrait.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

//@ set loud_id = "$.index[*][?(@.name=='Loud')].id"
pub trait Loud {}

Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc-json/traits/trait_alias.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Regression test for <https://github.com/rust-lang/rust/issues/104923>
// ignore-tidy-linelength

#![feature(trait_alias)]

Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc-json/type/dyn.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ignore-tidy-linelength
use std::fmt::Debug;

//@ count "$.index[*][?(@.name=='dyn')].inner.module.items[*]" 3
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/type/fn_lifetime.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

//@ has "$.index[*][?(@.name=='GenericFn')].inner.type_alias"

//@ ismany "$.index[*][?(@.name=='GenericFn')].inner.type_alias.generics.params[*].name" \"\'a\"
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/type/generic_default.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

//@ set result = "$.index[*][?(@.name=='Result')].id"
pub enum Result<T, E> {
Ok(T),
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/type/hrtb.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-linelength

//@ is "$.index[*][?(@.name=='genfn')].inner.function.generics.where_predicates[0].bound_predicate.type" '{"generic": "F"}'
//@ is "$.index[*][?(@.name=='genfn')].inner.function.generics.where_predicates[0].bound_predicate.generic_params" '[{"kind": {"lifetime": {"outlives": []}},"name": "'\''a"},{"kind": {"lifetime": {"outlives": []}},"name": "'\''b"}]'
pub fn genfn<F>(f: F)
Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc-json/type/inherent_associated_type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ignore-tidy-linelength
#![feature(inherent_associated_types)]
#![allow(incomplete_features)]

Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc-json/type/inherent_associated_type_bound.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ignore-tidy-linelength
#![feature(inherent_associated_types)]
#![allow(incomplete_features)]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ignore-tidy-linelength
#![feature(inherent_associated_types)]
#![allow(incomplete_features)]

Expand Down

0 comments on commit d7de830

Please sign in to comment.