1
Fork 0

Rollup merge of #81891 - CraftSpider:fn-header, r=jyn514

[rustdoc-json] Make `header` a vec of modifiers, and FunctionPointer consistent

Bumps version number and adds tests, this is a breaking change. I can split this into two (`is_unsafe` -> `header` and `header: Vec<Modifiers>`) if desired.

Rationale: Modifiers are individual notes on a function, it makes more sense for them to be a list of an independent enum over a String which is inconsistently exposing the HIR representation (prefix_str vs custom literals).
Function pointers currently only support `unsafe`, but there has been talk on and off about allowing them to also support `const`, and this makes handling their modifiers consistent with handling those of a function, allowing better shared code.

`@rustbot` modify labels: +A-rustdoc-json +T-rustdoc
CC: `@HeroicKatora`
r? `@jyn514`
This commit is contained in:
Dylan DPC 2021-02-14 16:54:45 +01:00 committed by GitHub
commit 641c3785dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 95 additions and 17 deletions

View file

@ -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,11 +281,20 @@ pub enum StructType {
Unit,
}
#[non_exhaustive]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "snake_case")]
pub enum Qualifiers {
Const,
Unsafe,
Async,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct Function {
pub decl: FnDecl,
pub generics: Generics,
pub header: String,
pub header: HashSet<Qualifiers>,
pub abi: String,
}
@ -293,7 +302,7 @@ pub struct Function {
pub struct Method {
pub decl: FnDecl,
pub generics: Generics,
pub header: String,
pub header: HashSet<Qualifiers>,
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<Qualifiers>,
pub abi: String,
}