Skip to content

Commit

Permalink
Rollup merge of #100355 - camelid:has2-rename, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
rustdoc: Rename `@has FILE PATTERN` to `@hasraw FILE PATTERN`

Fixes #100354.
  • Loading branch information
compiler-errors authored Aug 13, 2022
2 parents 75b7e52 + 0d588e9 commit 4b51df3
Show file tree
Hide file tree
Showing 71 changed files with 310 additions and 304 deletions.
22 changes: 13 additions & 9 deletions src/etc/htmldocck.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
`PATH` is relative to the output directory. It can be given as `-`
which repeats the most recently used `PATH`.
* `@has PATH PATTERN` and `@matches PATH PATTERN` checks for
the occurrence of the given pattern `PATTERN` in the specified file.
* `@hasraw PATH PATTERN` and `@matchesraw PATH PATTERN` checks
for the occurrence of the given pattern `PATTERN` in the specified file.
Only one occurrence of the pattern is enough.
For `@has`, `PATTERN` is a whitespace-normalized (every consecutive
For `@hasraw`, `PATTERN` is a whitespace-normalized (every consecutive
whitespace being replaced by one single space character) string.
The entire file is also whitespace-normalized including newlines.
For `@matches`, `PATTERN` is a Python-supported regular expression.
For `@matchesraw`, `PATTERN` is a Python-supported regular expression.
The file remains intact but the regexp is matched without the `MULTILINE`
and `IGNORECASE` options. You can still use a prefix `(?m)` or `(?i)`
to override them, and `\A` and `\Z` for definitely matching
Expand Down Expand Up @@ -542,19 +542,23 @@ def get_nb_matching_elements(cache, c, regexp, stop_at_first):
def check_command(c, cache):
try:
cerr = ""
if c.cmd == 'has' or c.cmd == 'matches': # string test
regexp = (c.cmd == 'matches')
if len(c.args) == 1 and not regexp: # @has <path> = file existence
if c.cmd in ['has', 'hasraw', 'matches', 'matchesraw']: # string test
regexp = c.cmd.startswith('matches')

# @has <path> = file existence
if len(c.args) == 1 and not regexp and 'raw' not in c.cmd:
try:
cache.get_file(c.args[0])
ret = True
except FailedCheck as err:
cerr = str(err)
ret = False
elif len(c.args) == 2: # @has/matches <path> <pat> = string test
# @hasraw/matchesraw <path> <pat> = string test
elif len(c.args) == 2 and 'raw' in c.cmd:
cerr = "`PATTERN` did not match"
ret = check_string(cache.get_file(c.args[0]), c.args[1], regexp)
elif len(c.args) == 3: # @has/matches <path> <pat> <match> = XML tree test
# @has/matches <path> <pat> <match> = XML tree test
elif len(c.args) == 3 and 'raw' not in c.cmd:
cerr = "`XPATH PATTERN` did not match"
ret = get_nb_matching_elements(cache, c, regexp, True) != 0
else:
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ mod private_module {
}

// @has foo/all.html '//a[@href="struct.ReexportedStruct.html"]' 'ReexportedStruct'
// @!has foo/all.html 'private_module'
// @!hasraw foo/all.html 'private_module'
pub use private_module::ReexportedStruct;
8 changes: 4 additions & 4 deletions src/test/rustdoc/assoc-consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub trait Foo {
const FOO: usize = 12 + 1;
// @has - '//*[@id="associatedconstant.FOO_NO_DEFAULT"]' 'const FOO_NO_DEFAULT: bool'
const FOO_NO_DEFAULT: bool;
// @!has - FOO_HIDDEN
// @!hasraw - FOO_HIDDEN
#[doc(hidden)]
const FOO_HIDDEN: u8 = 0;
}
Expand All @@ -18,7 +18,7 @@ impl Foo for Bar {
const FOO: usize = 12;
// @has - '//*[@id="associatedconstant.FOO_NO_DEFAULT"]' 'const FOO_NO_DEFAULT: bool'
const FOO_NO_DEFAULT: bool = false;
// @!has - FOO_HIDDEN
// @!hasraw - FOO_HIDDEN
#[doc(hidden)]
const FOO_HIDDEN: u8 = 0;
}
Expand Down Expand Up @@ -50,9 +50,9 @@ impl Bar {
}

impl Bar {
// @!has assoc_consts/struct.Bar.html 'BAR_PRIVATE'
// @!hasraw assoc_consts/struct.Bar.html 'BAR_PRIVATE'
const BAR_PRIVATE: char = 'a';
// @!has assoc_consts/struct.Bar.html 'BAR_HIDDEN'
// @!hasraw assoc_consts/struct.Bar.html 'BAR_HIDDEN'
#[doc(hidden)]
pub const BAR_HIDDEN: &'static str = "a";
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/rustdoc/const-display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub const fn foo() -> u32 { 42 }
pub const unsafe fn foo_unsafe() -> u32 { 42 }

// @has 'foo/fn.foo2.html' '//pre' 'pub const fn foo2() -> u32'
// @!has - '//span[@class="since"]'
// @!hasraw - '//span[@class="since"]'
#[unstable(feature = "humans", issue = "none")]
pub const fn foo2() -> u32 { 42 }

Expand All @@ -32,7 +32,7 @@ pub const fn bar2() -> u32 { 42 }


// @has 'foo/fn.foo2_gated.html' '//pre' 'pub const unsafe fn foo2_gated() -> u32'
// @!has - '//span[@class="since"]'
// @!hasraw - '//span[@class="since"]'
#[unstable(feature = "foo2", issue = "none")]
pub const unsafe fn foo2_gated() -> u32 { 42 }

Expand All @@ -43,7 +43,7 @@ pub const unsafe fn foo2_gated() -> u32 { 42 }
pub const unsafe fn bar2_gated() -> u32 { 42 }

// @has 'foo/fn.bar_not_gated.html' '//pre' 'pub const unsafe fn bar_not_gated() -> u32'
// @!has - '//span[@class="since"]'
// @!hasraw - '//span[@class="since"]'
pub const unsafe fn bar_not_gated() -> u32 { 42 }

pub struct Foo;
Expand Down
36 changes: 18 additions & 18 deletions src/test/rustdoc/deprecated-impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ pub struct Foo0;

impl Foo0 {
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.1: fn_with_doc'
// @has - 'fn_with_doc short'
// @has - 'fn_with_doc full'
// @hasraw - 'fn_with_doc short'
// @hasraw - 'fn_with_doc full'
/// fn_with_doc short
///
/// fn_with_doc full
Expand Down Expand Up @@ -52,8 +52,8 @@ pub struct Foo1;

impl Bar for Foo1 {
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.3: fn_empty_with_doc'
// @has - 'fn_empty_with_doc_impl short'
// @has - 'fn_empty_with_doc_impl full'
// @hasraw - 'fn_empty_with_doc_impl short'
// @hasraw - 'fn_empty_with_doc_impl full'
/// fn_empty_with_doc_impl short
///
/// fn_empty_with_doc_impl full
Expand All @@ -63,8 +63,8 @@ impl Bar for Foo1 {
fn fn_empty_without_doc() {}

// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.5: fn_def_with_doc'
// @has - 'fn_def_with_doc_impl short'
// @has - 'fn_def_with_doc_impl full'
// @hasraw - 'fn_def_with_doc_impl short'
// @hasraw - 'fn_def_with_doc_impl full'
/// fn_def_with_doc_impl short
///
/// fn_def_with_doc_impl full
Expand All @@ -74,8 +74,8 @@ impl Bar for Foo1 {
fn fn_def_without_doc() {}

// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.7: fn_def_def_with_doc'
// @has - 'fn_def_def_with_doc short'
// @!has - 'fn_def_def_with_doc full'
// @hasraw - 'fn_def_def_with_doc short'
// @!hasraw - 'fn_def_def_with_doc full'

// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.8: fn_def_def_without_doc'
}
Expand All @@ -85,34 +85,34 @@ pub struct Foo2;

impl Bar for Foo2 {
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.3: fn_empty_with_doc'
// @has - 'fn_empty_with_doc short'
// @!has - 'fn_empty_with_doc full'
// @hasraw - 'fn_empty_with_doc short'
// @!hasraw - 'fn_empty_with_doc full'
fn fn_empty_with_doc() {}

// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.4: fn_empty_without_doc'
// @has - 'fn_empty_without_doc_impl short'
// @has - 'fn_empty_without_doc_impl full'
// @hasraw - 'fn_empty_without_doc_impl short'
// @hasraw - 'fn_empty_without_doc_impl full'
/// fn_empty_without_doc_impl short
///
/// fn_empty_without_doc_impl full
fn fn_empty_without_doc() {}

// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.5: fn_def_with_doc'
// @has - 'fn_def_with_doc short'
// @!has - 'fn_def_with_doc full'
// @hasraw - 'fn_def_with_doc short'
// @!hasraw - 'fn_def_with_doc full'
fn fn_def_with_doc() {}

// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.6: fn_def_without_doc'
// @has - 'fn_def_without_doc_impl short'
// @has - 'fn_def_without_doc_impl full'
// @hasraw - 'fn_def_without_doc_impl short'
// @hasraw - 'fn_def_without_doc_impl full'
/// fn_def_without_doc_impl short
///
/// fn_def_without_doc_impl full
fn fn_def_without_doc() {}

// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.7: fn_def_def_with_doc'
// @has - 'fn_def_def_with_doc short'
// @!has - 'fn_def_def_with_doc full'
// @hasraw - 'fn_def_def_with_doc short'
// @!hasraw - 'fn_def_def_with_doc full'

// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.8: fn_def_def_without_doc'
}
12 changes: 6 additions & 6 deletions src/test/rustdoc/elided-lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,33 @@ pub struct Ref<'a>(&'a u32);
type ARef<'a> = Ref<'a>;

// @has foo/fn.test1.html
// @matches - "Ref</a>&lt;'_&gt;"
// @matchesraw - "Ref</a>&lt;'_&gt;"
pub fn test1(a: &u32) -> Ref {
Ref(a)
}

// @has foo/fn.test2.html
// @matches - "Ref</a>&lt;'_&gt;"
// @matchesraw - "Ref</a>&lt;'_&gt;"
pub fn test2(a: &u32) -> Ref<'_> {
Ref(a)
}

// @has foo/fn.test3.html
// @matches - "Ref</a>&lt;'_&gt;"
// @matchesraw - "Ref</a>&lt;'_&gt;"
pub fn test3(a: &u32) -> ARef {
Ref(a)
}

// @has foo/fn.test4.html
// @matches - "Ref</a>&lt;'_&gt;"
// @matchesraw - "Ref</a>&lt;'_&gt;"
pub fn test4(a: &u32) -> ARef<'_> {
Ref(a)
}

// Ensure external paths in inlined docs also display elided lifetime
// @has foo/bar/fn.test5.html
// @matches - "Ref</a>&lt;'_&gt;"
// @matchesraw - "Ref</a>&lt;'_&gt;"
// @has foo/bar/fn.test6.html
// @matches - "Ref</a>&lt;'_&gt;"
// @matchesraw - "Ref</a>&lt;'_&gt;"
#[doc(inline)]
pub extern crate bar;
6 changes: 3 additions & 3 deletions src/test/rustdoc/empty-mod-private.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// compile-flags: --document-private-items

// @has 'empty_mod_private/index.html' '//a[@href="foo/index.html"]' 'foo'
// @has 'empty_mod_private/sidebar-items.js' 'foo'
// @hasraw 'empty_mod_private/sidebar-items.js' 'foo'
// @matches 'empty_mod_private/foo/index.html' '//h1' 'Module empty_mod_private::foo'
mod foo {}

// @has 'empty_mod_private/index.html' '//a[@href="bar/index.html"]' 'bar'
// @has 'empty_mod_private/sidebar-items.js' 'bar'
// @hasraw 'empty_mod_private/sidebar-items.js' 'bar'
// @matches 'empty_mod_private/bar/index.html' '//h1' 'Module empty_mod_private::bar'
mod bar {
// @has 'empty_mod_private/bar/index.html' '//a[@href="baz/index.html"]' 'baz'
// @has 'empty_mod_private/bar/sidebar-items.js' 'baz'
// @hasraw 'empty_mod_private/bar/sidebar-items.js' 'baz'
// @matches 'empty_mod_private/bar/baz/index.html' '//h1' 'Module empty_mod_private::bar::baz'
mod baz {}
}
6 changes: 3 additions & 3 deletions src/test/rustdoc/empty-mod-public.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// @has 'empty_mod_public/index.html' '//a[@href="foo/index.html"]' 'foo'
// @has 'empty_mod_public/sidebar-items.js' 'foo'
// @hasraw 'empty_mod_public/sidebar-items.js' 'foo'
// @matches 'empty_mod_public/foo/index.html' '//h1' 'Module empty_mod_public::foo'
pub mod foo {}

// @has 'empty_mod_public/index.html' '//a[@href="bar/index.html"]' 'bar'
// @has 'empty_mod_public/sidebar-items.js' 'bar'
// @hasraw 'empty_mod_public/sidebar-items.js' 'bar'
// @matches 'empty_mod_public/bar/index.html' '//h1' 'Module empty_mod_public::bar'
pub mod bar {
// @has 'empty_mod_public/bar/index.html' '//a[@href="baz/index.html"]' 'baz'
// @has 'empty_mod_public/bar/sidebar-items.js' 'baz'
// @hasraw 'empty_mod_public/bar/sidebar-items.js' 'baz'
// @matches 'empty_mod_public/bar/baz/index.html' '//h1' 'Module empty_mod_public::bar::baz'
pub mod baz {}
}
2 changes: 1 addition & 1 deletion src/test/rustdoc/empty-section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
pub struct Foo;

// @has foo/struct.Foo.html
// @!has - 'Auto Trait Implementations'
// @!hasraw - 'Auto Trait Implementations'
impl !Send for Foo {}
impl !Sync for Foo {}
impl !std::marker::Unpin for Foo {}
Expand Down
4 changes: 2 additions & 2 deletions src/test/rustdoc/generic-associated-types/issue-94683.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ pub trait Trait {
// Make sure that the elided lifetime shows up

// @has foo/type.T.html
// @has - "pub type T = "
// @has - "&lt;'_&gt;"
// @hasraw - "pub type T = "
// @hasraw - "&lt;'_&gt;"
pub type T = fn(&<() as Trait>::Gat<'_>);
4 changes: 2 additions & 2 deletions src/test/rustdoc/hidden-impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub mod __hidden {
}

// @has foo/trait.Clone.html
// @!has - 'Foo'
// @!hasraw - 'Foo'
// @has implementors/core/clone/trait.Clone.js
// @!has - 'Foo'
// @!hasraw - 'Foo'
pub use std::clone::Clone;
2 changes: 1 addition & 1 deletion src/test/rustdoc/hidden-line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
/// ```
pub fn foo() {}

// @!has hidden_line/fn.foo.html invisible
// @!hasraw hidden_line/fn.foo.html invisible
// @matches - //pre "#\[derive\(PartialEq\)\] // Bar"
8 changes: 4 additions & 4 deletions src/test/rustdoc/hidden-methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ pub mod hidden {
}

// @has foo/struct.Foo.html
// @!has - 'Methods'
// @!hasraw - 'Methods'
// @!has - '//code' 'impl Foo'
// @!has - 'this_should_be_hidden'
// @!hasraw - 'this_should_be_hidden'
pub use hidden::Foo;

// @has foo/struct.Bar.html
// @!has - 'Methods'
// @!hasraw - 'Methods'
// @!has - '//code' 'impl Bar'
// @!has - 'this_should_be_hidden'
// @!hasraw - 'this_should_be_hidden'
pub use hidden::Bar;
4 changes: 2 additions & 2 deletions src/test/rustdoc/hide-unstable-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

extern crate unstable_trait;

// @has foo/struct.Foo.html 'bar'
// @has foo/struct.Foo.html 'bar2'
// @hasraw foo/struct.Foo.html 'bar'
// @hasraw foo/struct.Foo.html 'bar2'
#[doc(inline)]
pub use unstable_trait::Foo;
8 changes: 4 additions & 4 deletions src/test/rustdoc/impl-parts-crosscrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ pub struct Bar<T> { t: T }
// full impl string. Instead, just make sure something from each part
// is mentioned.

// @has implementors/rustdoc_impl_parts_crosscrate/trait.AnAutoTrait.js Bar
// @has - Send
// @has - !AnAutoTrait
// @has - Copy
// @hasraw implementors/rustdoc_impl_parts_crosscrate/trait.AnAutoTrait.js Bar
// @hasraw - Send
// @hasraw - !AnAutoTrait
// @hasraw - Copy
impl<T: Send> !rustdoc_impl_parts_crosscrate::AnAutoTrait for Bar<T>
where T: Copy {}
4 changes: 2 additions & 2 deletions src/test/rustdoc/impl-trait-alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
trait MyTrait {}
impl MyTrait for i32 {}

// @has impl_trait_alias/type.Foo.html 'Foo'
// @hasraw impl_trait_alias/type.Foo.html 'Foo'
/// debug type
pub type Foo = impl MyTrait;

// @has impl_trait_alias/fn.foo.html 'foo'
// @hasraw impl_trait_alias/fn.foo.html 'foo'
/// debug function
pub fn foo() -> Foo {
1
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/inline_cross/add-docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ extern crate inner;


// @has add_docs/struct.MyStruct.html
// @has add_docs/struct.MyStruct.html "Doc comment from ‘pub use’, Doc comment from definition"
// @hasraw add_docs/struct.MyStruct.html "Doc comment from ‘pub use’, Doc comment from definition"
/// Doc comment from 'pub use',
pub use inner::MyStruct;
4 changes: 2 additions & 2 deletions src/test/rustdoc/inline_cross/assoc-items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
extern crate assoc_items;

// @has foo/struct.MyStruct.html
// @!has - 'PrivateConst'
// @!hasraw - 'PrivateConst'
// @has - '//*[@id="associatedconstant.PublicConst"]' 'pub const PublicConst: u8'
// @has - '//*[@class="docblock"]' 'docs for PublicConst'
// @!has - 'private_method'
// @!hasraw - 'private_method'
// @has - '//*[@id="method.public_method"]' 'pub fn public_method()'
// @has - '//*[@class="docblock"]' 'docs for public_method'
// @has - '//*[@id="associatedconstant.ConstNoDefault"]' 'const ConstNoDefault: i16'
Expand Down
Loading

0 comments on commit 4b51df3

Please sign in to comment.