-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rustdoc-json] Make header
a vec of modifiers, and FunctionPointer consistent
#81891
Changes from 4 commits
a26fa74
ce02b7f
0a91dae
ffa5280
be4ea06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
//! These types are the public API exposed through the `--output-format json` flag. The [`Crate`] | ||
//! struct is the root of the JSON blob and all other items are contained within. | ||
|
||
use std::collections::HashMap; | ||
use std::collections::{HashMap, HashSet}; | ||
use std::path::PathBuf; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
@@ -281,19 +281,28 @@ pub enum StructType { | |
Unit, | ||
} | ||
|
||
#[non_exhaustive] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other things may be added as modifiers in the language, or There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One detail with the addition of new variants would be that the order is not quite arbitrary. The grammar apppears to be currently:
So while technically permitting the forward compatible addition of new qualifiers, a pretty-printer might still be confused by their order and not produce syntactically valid method/type declarations. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True. Joshua said that we should use sets over vecs specifically so order is not guaranteed as part of the contract. I think that plus |
||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)] | ||
#[serde(rename_all = "snake_case")] | ||
pub enum Modifiers { | ||
CraftSpider marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Const, | ||
Unsafe, | ||
Async, | ||
jyn514 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] | ||
pub struct Function { | ||
pub decl: FnDecl, | ||
pub generics: Generics, | ||
pub header: String, | ||
pub header: HashSet<Modifiers>, | ||
pub abi: String, | ||
} | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] | ||
pub struct Method { | ||
pub decl: FnDecl, | ||
pub generics: Generics, | ||
pub header: String, | ||
pub header: HashSet<Modifiers>, | ||
pub abi: String, | ||
pub has_body: bool, | ||
} | ||
|
@@ -404,9 +413,9 @@ pub enum Type { | |
|
||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] | ||
pub struct FunctionPointer { | ||
pub is_unsafe: bool, | ||
pub generic_params: Vec<GenericParamDef>, | ||
pub decl: FnDecl, | ||
pub generic_params: Vec<GenericParamDef>, | ||
pub header: HashSet<Modifiers>, | ||
pub abi: String, | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// @has header.json "$.index[*][?(@.name=='FnPointer')].inner.type.inner.header" "[]" | ||
pub type FnPointer = fn(); | ||
|
||
// @has - "$.index[*][?(@.name=='UnsafePointer')].inner.type.inner.header" '["unsafe"]' | ||
pub type UnsafePointer = unsafe fn(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// edition:2018 | ||
|
||
// @has header.json "$.index[*][?(@.name=='nothing_fn')].inner.header" "[]" | ||
pub fn nothing_fn() {} | ||
|
||
// @has - "$.index[*][?(@.name=='const_fn')].inner.header" '["const"]' | ||
pub const fn const_fn() {} | ||
|
||
// @has - "$.index[*][?(@.name=='async_fn')].inner.header" '["async"]' | ||
pub async fn async_fn() {} | ||
|
||
// @count - "$.index[*][?(@.name=='async_unsafe_fn')].inner.header[*]" 2 | ||
// @has - "$.index[*][?(@.name=='async_unsafe_fn')].inner.header[*]" '"async"' | ||
// @has - "$.index[*][?(@.name=='async_unsafe_fn')].inner.header[*]" '"unsafe"' | ||
pub async unsafe fn async_unsafe_fn() {} | ||
|
||
// @count - "$.index[*][?(@.name=='const_unsafe_fn')].inner.header[*]" 2 | ||
// @has - "$.index[*][?(@.name=='const_unsafe_fn')].inner.header[*]" '"const"' | ||
// @has - "$.index[*][?(@.name=='const_unsafe_fn')].inner.header[*]" '"unsafe"' | ||
pub const unsafe fn const_unsafe_fn() {} | ||
CraftSpider marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// It's impossible for a function to be both const and async, so no test for that |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// edition:2018 | ||
|
||
pub struct Foo; | ||
|
||
impl Foo { | ||
// @has header.json "$.index[*][?(@.name=='nothing_meth')].inner.header" "[]" | ||
pub fn nothing_meth() {} | ||
|
||
// @has - "$.index[*][?(@.name=='const_meth')].inner.header" '["const"]' | ||
pub const fn const_meth() {} | ||
|
||
// @has - "$.index[*][?(@.name=='async_meth')].inner.header" '["async"]' | ||
pub async fn async_meth() {} | ||
|
||
// @count - "$.index[*][?(@.name=='async_unsafe_meth')].inner.header[*]" 2 | ||
// @has - "$.index[*][?(@.name=='async_unsafe_meth')].inner.header[*]" '"async"' | ||
// @has - "$.index[*][?(@.name=='async_unsafe_meth')].inner.header[*]" '"unsafe"' | ||
pub async unsafe fn async_unsafe_meth() {} | ||
|
||
// @count - "$.index[*][?(@.name=='const_unsafe_meth')].inner.header[*]" 2 | ||
// @has - "$.index[*][?(@.name=='const_unsafe_meth')].inner.header[*]" '"const"' | ||
// @has - "$.index[*][?(@.name=='const_unsafe_meth')].inner.header[*]" '"unsafe"' | ||
pub const unsafe fn const_unsafe_meth() {} | ||
|
||
// It's impossible for a method to be both const and async, so no test for that | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previous implementation looks wrong, other call(s) of check_decl are
["inner"]["decl"]
, and it doesn't look like there should ever be an["inner"]["inner"]
in the output.