提交 4d1a30c9 编写于 作者: V Vadim Petrochenkov

Remove most of `PartialEq` impls from AST and HIR structures

上级 0a8275f8
......@@ -81,7 +81,7 @@ impl serialize::UseSpecializedDecodable for CrateNum {}
/// Since the DefIndex is mostly treated as an opaque ID, you probably
/// don't have to care about these address spaces.
#[derive(Clone, Eq, Ord, PartialOrd, PartialEq, Hash, Copy)]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
pub struct DefIndex(u32);
/// The crate root is always assigned index 0 by the AST Map code,
......@@ -150,7 +150,7 @@ pub fn as_raw_u32(&self) -> u32 {
impl serialize::UseSpecializedEncodable for DefIndex {}
impl serialize::UseSpecializedDecodable for DefIndex {}
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
#[derive(Copy, Clone, Hash)]
pub enum DefIndexAddressSpace {
Low = 0,
High = 1,
......@@ -165,7 +165,7 @@ pub fn index(&self) -> usize {
/// A DefId identifies a particular *definition*, by combining a crate
/// index and a def index.
#[derive(Clone, Eq, Ord, PartialOrd, PartialEq, Hash, Copy)]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
pub struct DefId {
pub krate: CrateNum,
pub index: DefIndex,
......@@ -216,7 +216,7 @@ impl serialize::UseSpecializedDecodable for DefId {}
/// few cases where we know that only DefIds from the local crate are expected
/// and a DefId from a different crate would signify a bug somewhere. This
/// is when LocalDefId comes in handy.
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct LocalDefId(DefIndex);
impl LocalDefId {
......
......@@ -51,7 +51,7 @@
use std::cmp;
use std::u32;
#[derive(Copy, Clone, PartialEq, Eq)]
#[derive(Copy, Clone)]
pub enum FnKind<'a> {
/// #[xxx] pub async/const/extern "Abi" fn foo()
ItemFn(Name, &'a Generics, FnHeader, &'a Visibility, &'a [Attribute]),
......@@ -1115,7 +1115,7 @@ pub fn walk_defaultness<'v, V: Visitor<'v>>(_: &mut V, _: &'v Defaultness) {
// would be to walk it.
}
#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, PartialEq, Eq)]
#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct IdRange {
pub min: NodeId,
pub max: NodeId,
......
......@@ -238,7 +238,7 @@ pub fn lower_crate(
}.lower_crate(krate)
}
#[derive(Copy, Clone, PartialEq, Eq)]
#[derive(Copy, Clone, PartialEq)]
enum ParamMode {
/// Any path in a type context.
Explicit,
......@@ -1927,7 +1927,7 @@ fn lower_fn_decl(
variadic: decl.variadic,
has_implicit_self: decl.inputs.get(0).map_or(false, |arg| match arg.ty.node {
TyKind::ImplicitSelf => true,
TyKind::Rptr(_, ref mt) => mt.ty.node == TyKind::ImplicitSelf,
TyKind::Rptr(_, ref mt) => mt.ty.node.is_implicit_self(),
_ => false,
}),
})
......
......@@ -171,7 +171,7 @@ pub struct Definitions {
/// A unique identifier that we can use to lookup a definition
/// precisely. It combines the index of the definition's parent (if
/// any) with a `DisambiguatedDefPathData`.
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
#[derive(Clone, PartialEq, Debug, Hash, RustcEncodable, RustcDecodable)]
pub struct DefKey {
/// Parent path.
pub parent: Option<DefIndex>,
......@@ -223,13 +223,13 @@ fn root_parent_stable_hash(crate_name: &str,
/// between them. This introduces some artificial ordering dependency
/// but means that if you have (e.g.) two impls for the same type in
/// the same module, they do get distinct def-ids.
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
#[derive(Clone, PartialEq, Debug, Hash, RustcEncodable, RustcDecodable)]
pub struct DisambiguatedDefPathData {
pub data: DefPathData,
pub disambiguator: u32
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
#[derive(Clone, Debug, Hash, RustcEncodable, RustcDecodable)]
pub struct DefPath {
/// the path leading from the crate root to the item
pub data: Vec<DisambiguatedDefPathData>,
......@@ -311,7 +311,7 @@ pub fn to_filename_friendly_no_crate(&self) -> String {
}
}
#[derive(Clone, Debug, Eq, PartialEq, Hash, RustcEncodable, RustcDecodable)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
pub enum DefPathData {
// Root: these should only be used for the root nodes, because
// they are treated specially by the `def_path` function.
......@@ -668,8 +668,7 @@ pub fn to_string(&self) -> String {
(pub enum GlobalMetaDataKind {
$($variant:ident),*
}) => (
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash,
RustcEncodable, RustcDecodable)]
#[derive(Clone, Copy, Debug, Hash, RustcEncodable, RustcDecodable)]
pub enum GlobalMetaDataKind {
$($variant),*
}
......
此差异已折叠。
......@@ -1914,7 +1914,9 @@ pub fn print_pat(&mut self, pat: &hir::Pat) -> io::Result<()> {
if !before.is_empty() {
self.word_space(",")?;
}
if p.node != PatKind::Wild {
if let PatKind::Wild = p.node {
// Print nothing
} else {
self.print_pat(&p)?;
}
self.s.word("..")?;
......@@ -2033,7 +2035,9 @@ fn print_closure_args(&mut self, decl: &hir::FnDecl, body_id: hir::BodyId) -> io
s.ann.nested(s, Nested::BodyArgPat(body_id, i))?;
i += 1;
if ty.node != hir::TyInfer {
if let hir::TyInfer = ty.node {
// Print nothing
} else {
s.s.word(":")?;
s.s.space()?;
s.print_type(ty)?;
......
......@@ -111,7 +111,7 @@ pub(super) fn try_report_anon_anon_conflict(&self) -> Option<ErrorReported> {
let (span_1, span_2, main_label, span_label) = match (sup_is_ret_type, sub_is_ret_type) {
(None, None) => {
let (main_label_1, span_label_1) = if ty_sup == ty_sub {
let (main_label_1, span_label_1) = if ty_sup.id == ty_sub.id {
(
format!("this type is declared with multiple lifetimes..."),
format!(
......
......@@ -174,7 +174,7 @@ pub struct ImplHeader<'tcx> {
pub predicates: Vec<Predicate<'tcx>>,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct AssociatedItem {
pub def_id: DefId,
pub ident: Ident,
......
......@@ -397,7 +397,7 @@ fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
hir::ItemUnion(..) => "a union",
hir::ItemTrait(.., ref trait_item_refs) => {
// Issue #11592, traits are always considered exported, even when private.
if it.vis.node == hir::VisibilityKind::Inherited {
if let hir::VisibilityKind::Inherited = it.vis.node {
self.private_traits.insert(it.id);
for trait_item_ref in trait_item_refs {
self.private_traits.insert(trait_item_ref.id.node_id);
......@@ -414,7 +414,7 @@ fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
if let Some(node_id) = cx.tcx.hir.as_local_node_id(real_trait) {
match cx.tcx.hir.find(node_id) {
Some(hir_map::NodeItem(item)) => {
if item.vis.node == hir::VisibilityKind::Inherited {
if let hir::VisibilityKind::Inherited = item.vis.node {
for impl_item_ref in impl_item_refs {
self.private_traits.insert(impl_item_ref.id.node_id);
}
......
......@@ -60,19 +60,21 @@ fn invalid_non_exhaustive_attribute(&self, variant: &Variant) {
}
fn invalid_visibility(&self, vis: &Visibility, note: Option<&str>) {
if vis.node != VisibilityKind::Inherited {
let mut err = struct_span_err!(self.session,
vis.span,
E0449,
"unnecessary visibility qualifier");
if vis.node == VisibilityKind::Public {
err.span_label(vis.span, "`pub` not permitted here because it's implied");
}
if let Some(note) = note {
err.note(note);
}
err.emit();
if let VisibilityKind::Inherited = vis.node {
return
}
let mut err = struct_span_err!(self.session,
vis.span,
E0449,
"unnecessary visibility qualifier");
if vis.node.is_public() {
err.span_label(vis.span, "`pub` not permitted here because it's implied");
}
if let Some(note) = note {
err.note(note);
}
err.emit();
}
fn check_decl_no_pat<ReportFn: Fn(Span, bool)>(&self, decl: &FnDecl, report_err: ReportFn) {
......@@ -268,7 +270,7 @@ fn visit_item(&mut self, item: &'a Item) {
match item.node {
ItemKind::Impl(unsafety, polarity, _, _, Some(..), ref ty, ref impl_items) => {
self.invalid_visibility(&item.vis, None);
if ty.node == TyKind::Err {
if let TyKind::Err = ty.node {
self.err_handler()
.struct_span_err(item.span, "`impl Trait for .. {}` is an obsolete syntax")
.help("use `auto trait Trait {}` instead").emit();
......
......@@ -86,7 +86,7 @@ fn visit_item(&mut self, item: &'a ast::Item) {
// because this means that they were generated in some fashion by the
// compiler and we don't need to consider them.
if let ast::ItemKind::Use(..) = item.node {
if item.vis.node == ast::VisibilityKind::Public || item.span.is_dummy() {
if item.vis.node.is_pub() || item.span.is_dummy() {
return;
}
}
......
......@@ -456,7 +456,7 @@ enum AliasPossibility {
Maybe,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, Debug)]
enum PathSource<'a> {
// Type paths `Path`.
Type,
......
......@@ -65,14 +65,14 @@
macro_rules! access_from {
($save_ctxt:expr, $vis:expr, $id:expr) => {
Access {
public: $vis.node == ast::VisibilityKind::Public,
public: $vis.node.is_public(),
reachable: $save_ctxt.analysis.access_levels.is_reachable($id),
}
};
($save_ctxt:expr, $item:expr) => {
Access {
public: $item.vis.node == ast::VisibilityKind::Public,
public: $item.vis.node.is_public(),
reachable: $save_ctxt.analysis.access_levels.is_reachable($item.id),
}
};
......@@ -523,7 +523,7 @@ fn process_struct(
.iter()
.enumerate()
.filter_map(|(i, f)| {
if include_priv_fields || f.vis.node == ast::VisibilityKind::Public {
if include_priv_fields || f.vis.node.is_public() {
f.ident
.map(|i| i.to_string())
.or_else(|| Some(i.to_string()))
......
......@@ -119,7 +119,7 @@ enum ProbeResult {
Match,
}
#[derive(Debug, PartialEq, Eq, Clone)]
#[derive(Debug, PartialEq, Clone)]
pub struct Pick<'tcx> {
pub item: ty::AssociatedItem,
pub kind: PickKind<'tcx>,
......
......@@ -754,7 +754,7 @@ fn from_iter<T>(iter: T) -> Self
}
}
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Default, Hash)]
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Default, Hash)]
pub struct Attributes {
pub doc_strings: Vec<DocFragment>,
pub other_attrs: Vec<ast::Attribute>,
......@@ -974,6 +974,18 @@ pub fn links(&self, krate: &CrateNum) -> Vec<(String, String)> {
}
}
impl PartialEq for Attributes {
fn eq(&self, rhs: &Self) -> bool {
self.doc_strings == rhs.doc_strings &&
self.cfg == rhs.cfg &&
self.span == rhs.span &&
self.links == rhs.links &&
self.other_attrs.id == rhs.other_attrs.id
}
}
impl Eq for Attributes {}
impl AttributesExt for Attributes {
fn lists<'a>(&'a self, name: &'a str) -> ListAttributesIter<'a> {
self.other_attrs.lists(name)
......@@ -1830,7 +1842,7 @@ fn clean(&self, cx: &DocContext) -> Type {
}
}
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)]
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug, Hash)]
pub enum GenericParamDefKind {
Lifetime,
Type {
......@@ -1841,6 +1853,8 @@ pub enum GenericParamDefKind {
},
}
impl Eq for GenericParamDefKind {}
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)]
pub struct GenericParamDef {
pub name: String,
......
......@@ -67,7 +67,7 @@ fn decode<D: Decoder>(d: &mut D) -> Result<VecDeque<T>, D::Error> {
impl<
K: Encodable + PartialEq + Ord,
V: Encodable + PartialEq
V: Encodable
> Encodable for BTreeMap<K, V> {
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> {
e.emit_map(self.len(), |e| {
......@@ -84,7 +84,7 @@ fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> {
impl<
K: Decodable + PartialEq + Ord,
V: Decodable + PartialEq
V: Decodable
> Decodable for BTreeMap<K, V> {
fn decode<D: Decoder>(d: &mut D) -> Result<BTreeMap<K, V>, D::Error> {
d.read_map(|d, len| {
......
此差异已折叠。
......@@ -725,7 +725,7 @@ fn resolve_macro(&mut self, scope: Mark, path: &ast::Path, kind: MacroKind, forc
fn check_unused_macros(&self);
}
#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum Determinacy {
Determined,
Undetermined,
......
......@@ -22,7 +22,7 @@
/// Contains the sub-token-trees of a "delimited" token tree, such as the contents of `(`. Note
/// that the delimiter itself might be `NoDelim`.
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct Delimited {
pub delim: token::DelimToken,
pub tts: Vec<TokenTree>,
......@@ -60,7 +60,7 @@ pub fn close_tt(&self, span: Span) -> TokenTree {
}
}
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct SequenceRepetition {
/// The sequence of token trees
pub tts: Vec<TokenTree>,
......@@ -74,7 +74,7 @@ pub struct SequenceRepetition {
/// A Kleene-style [repetition operator](http://en.wikipedia.org/wiki/Kleene_star)
/// for token sequences.
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
pub enum KleeneOp {
/// Kleene star (`*`) for zero or more repetitions
ZeroOrMore,
......@@ -85,7 +85,7 @@ pub enum KleeneOp {
/// Similar to `tokenstream::TokenTree`, except that `$i`, `$i:ident`, and `$(...)`
/// are "first-class" token trees. Useful for parsing macros.
#[derive(Debug, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
#[derive(Debug, Clone, PartialEq, RustcEncodable, RustcDecodable, Hash)]
pub enum TokenTree {
Token(Span, token::Token),
Delimited(Span, Lrc<Delimited>),
......
......@@ -632,7 +632,7 @@ pub fn walk_feature_fields<F>(&self, mut f: F)
// move that documentation into the relevant place in the other docs, and
// remove the chapter on the flag.
#[derive(PartialEq, Copy, Clone, Debug)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum AttributeType {
/// Normal, builtin attribute that is consumed
/// by the compiler before the unused_attribute check
......@@ -665,7 +665,7 @@ fn is_deprecated(&self) -> bool {
}
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, Debug)]
pub enum Stability {
Unstable,
// Argument is tracking issue link.
......@@ -1113,7 +1113,7 @@ pub fn is_builtin_attr(attr: &ast::Attribute) -> bool {
("target_has_atomic", "cfg_target_has_atomic", cfg_fn!(cfg_target_has_atomic)),
];
#[derive(Debug, Eq, PartialEq)]
#[derive(Debug)]
pub struct GatedCfg {
span: Span,
index: usize,
......@@ -1272,7 +1272,7 @@ pub enum GateIssue {
Library(Option<u32>)
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum GateStrength {
/// A hard error. (Most feature gates should use this.)
Hard,
......@@ -1704,7 +1704,9 @@ fn visit_ty(&mut self, ty: &'a ast::Ty) {
fn visit_fn_ret_ty(&mut self, ret_ty: &'a ast::FunctionRetTy) {
if let ast::FunctionRetTy::Ty(ref output_ty) = *ret_ty {
if output_ty.node != ast::TyKind::Never {
if let ast::TyKind::Never = output_ty.node {
// Do nothing
} else {
self.visit_ty(output_ty)
}
}
......@@ -2046,7 +2048,7 @@ pub fn check_crate(krate: &ast::Crate,
visit::walk_crate(visitor, krate);
}
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Clone, Copy, Hash)]
pub enum UnstableFeatures {
/// Hard errors for unstable features are active, as on
/// beta/stable channels.
......
......@@ -16,7 +16,7 @@
use parse::parser::{Parser, TokenType, PathStyle};
use tokenstream::TokenStream;
#[derive(PartialEq, Eq, Debug)]
#[derive(Debug)]
enum InnerAttributeParsePolicy<'a> {
Permitted,
NotPermitted { reason: &'a str },
......@@ -94,7 +94,7 @@ fn parse_attribute_with_inner_parse_policy(&mut self,
let lo = self.span;
self.bump();
if inner_parse_policy == InnerAttributeParsePolicy::Permitted {
if let InnerAttributeParsePolicy::Permitted = inner_parse_policy {
self.expected_tokens.push(TokenType::Token(token::Not));
}
let style = if self.token == token::Not {
......
......@@ -26,7 +26,7 @@
mod tokentrees;
mod unicode_chars;
#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Clone, Debug)]
pub struct TokenAndSpan {
pub tok: token::Token,
pub sp: Span,
......
......@@ -95,13 +95,13 @@ pub enum PathStyle {
Mod,
}
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, PartialEq, Debug)]
enum SemiColonMode {
Break,
Ignore,
}
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, PartialEq, Debug)]
enum BlockMode {
Break,
Ignore,
......@@ -376,7 +376,7 @@ fn next_desugared(&mut self) -> TokenAndSpan {
}
}
#[derive(PartialEq, Eq, Clone)]
#[derive(Clone, PartialEq)]
crate enum TokenType {
Token(token::Token),
Keyword(keywords::Keyword),
......@@ -522,7 +522,7 @@ fn dummy_arg(span: Span) -> Arg {
Arg { ty: P(ty), pat: pat, id: ast::DUMMY_NODE_ID }
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[derive(Copy, Clone, Debug)]
enum TokenExpectType {
Expect,
NoExpect,
......@@ -6999,7 +6999,7 @@ fn parse_item_(&mut self, attrs: Vec<Attribute>,
// Verify whether we have encountered a struct or method definition where the user forgot to
// add the `struct` or `fn` keyword after writing `pub`: `pub S {}`
if visibility.node == VisibilityKind::Public &&
if visibility.node.is_public() &&
self.check_ident() &&
self.look_ahead(1, |t| *t != token::Not)
{
......
......@@ -30,7 +30,7 @@
use std::mem;
use rustc_data_structures::sync::{Lrc, Lock};
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)]
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
pub enum BinOpToken {
Plus,
Minus,
......@@ -45,7 +45,7 @@ pub enum BinOpToken {
}
/// A delimiter token
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)]
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
pub enum DelimToken {
/// A round parenthesis: `(` or `)`
Paren,
......@@ -67,7 +67,7 @@ pub fn is_empty(self) -> bool {
}
}
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)]
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
pub enum Lit {
Byte(ast::Name),
Char(ast::Name),
......@@ -139,7 +139,7 @@ fn ident_can_begin_type(ident: ast::Ident, is_raw: bool) -> bool {
].contains(&ident.name)
}
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug)]
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Hash, Debug)]
pub enum Token {
/* Expression-operator symbols. */
Eq,
......@@ -638,7 +638,7 @@ pub fn interpolated_to_tokenstream(&self, sess: &ParseSess, span: Span)
}
}
#[derive(Clone, RustcEncodable, RustcDecodable, Eq, Hash)]
#[derive(Clone, RustcEncodable, RustcDecodable, Hash)]
/// For interpolation during macro expansion.
pub enum Nonterminal {
NtItem(P<ast::Item>),
......
......@@ -2641,7 +2641,9 @@ pub fn print_pat(&mut self, pat: &ast::Pat) -> io::Result<()> {
|s, p| s.print_pat(p))?;
if let Some(ref p) = *slice {
if !before.is_empty() { self.word_space(",")?; }
if p.node != PatKind::Wild {
if let PatKind::Wild = p.node {
// Print nothing
} else {
self.print_pat(p)?;
}
self.s.word("..")?;
......
......@@ -46,7 +46,7 @@
use rustc_data_structures::stable_hasher::{StableHasher, StableHasherResult,
HashStable};
/// An owned smart pointer.
#[derive(Hash, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Hash, PartialEq, Eq)]
pub struct P<T: ?Sized> {
ptr: Box<T>
}
......
......@@ -329,7 +329,6 @@ fn ignored_span(cx: &TestCtxt, sp: Span) -> Span {
sp.with_ctxt(cx.ctxt)
}
#[derive(PartialEq)]
enum HasTestSignature {
Yes,
No(BadTestSignature),
......@@ -354,7 +353,7 @@ fn has_test_signature(_cx: &TestCtxt, i: &ast::Item) -> HasTestSignature {
// type implements the `Termination` trait as `libtest` enforces that.
let has_output = match decl.output {
ast::FunctionRetTy::Default(..) => false,
ast::FunctionRetTy::Ty(ref t) if t.node == ast::TyKind::Tup(vec![]) => false,
ast::FunctionRetTy::Ty(ref t) if t.node.is_empty_tuple() => false,
_ => true
};
......
......@@ -36,7 +36,7 @@
use std::hash::{self, Hash};
/// A delimited sequence of token trees
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct Delimited {
/// The type of delimiter
pub delim: token::DelimToken,
......@@ -93,7 +93,7 @@ pub fn stream(&self) -> TokenStream {
///
/// The RHS of an MBE macro is the only place `SubstNt`s are substituted.
/// Nothing special happens to misnamed or misplaced `SubstNt`s.
#[derive(Debug, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
#[derive(Debug, Clone, PartialEq, RustcEncodable, RustcDecodable, Hash)]
pub enum TokenTree {
/// A single token
Token(Span, token::Token),
......
......@@ -11,12 +11,10 @@
use symbol::keywords;
use ast::{self, BinOpKind};
use std::cmp::Ordering;
/// Associative operator with precedence.
///
/// This is the enum which specifies operator precedence and fixity to the parser.
#[derive(Debug, PartialEq, Eq)]
#[derive(PartialEq, Debug)]
pub enum AssocOp {
/// `+`
Add,
......@@ -70,7 +68,7 @@ pub enum AssocOp {
Colon,
}
#[derive(Debug, PartialEq, Eq)]
#[derive(PartialEq, Debug)]
pub enum Fixity {
/// The operator is left-associative
Left,
......@@ -230,7 +228,7 @@ pub fn to_ast_binop(&self) -> Option<BinOpKind> {
pub const PREC_PAREN: i8 = 99;
pub const PREC_FORCE_PAREN: i8 = 100;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy)]
pub enum ExprPrecedence {
Closure,
Break,
......@@ -280,18 +278,6 @@ pub enum ExprPrecedence {
Async,
}
impl PartialOrd for ExprPrecedence {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.order().cmp(&other.order()))
}
}
impl Ord for ExprPrecedence {
fn cmp(&self, other: &Self) -> Ordering {
self.order().cmp(&other.order())
}
}
impl ExprPrecedence {
pub fn order(self) -> i8 {
match self {
......
......@@ -28,7 +28,7 @@
use parse::token::Token;
use tokenstream::{TokenTree, TokenStream};
#[derive(Copy, Clone, PartialEq, Eq)]
#[derive(Copy, Clone)]
pub enum FnKind<'a> {
/// fn foo() or extern "Abi" fn foo()
ItemFn(Ident, FnHeader, &'a Visibility, &'a Block),
......
......@@ -188,7 +188,6 @@
pub use self::SubstructureFields::*;
use std::cell::RefCell;
use std::collections::HashSet;
use std::vec;
use rustc_target::spec::abi::Abi;
......@@ -617,7 +616,6 @@ fn create_derived_impl(&self,
.map(|ty_param| ty_param.ident.name)
.collect();
let mut processed_field_types = HashSet::new();
for field_ty in field_tys {
let tys = find_type_parameters(&field_ty, &ty_param_names, self.span, cx);
......@@ -625,11 +623,9 @@ fn create_derived_impl(&self,
// if we have already handled this type, skip it
if let ast::TyKind::Path(_, ref p) = ty.node {
if p.segments.len() == 1 &&
ty_param_names.contains(&p.segments[0].ident.name) ||
processed_field_types.contains(&p.segments) {
ty_param_names.contains(&p.segments[0].ident.name) {
continue;
};
processed_field_types.insert(p.segments.clone());
}
let mut bounds: Vec<_> = self.additional_bounds
.iter()
......@@ -913,7 +909,7 @@ fn split_self_nonself_args
Self_ if nonstatic => {
self_args.push(arg_expr);
}
Ptr(ref ty, _) if **ty == Self_ && nonstatic => {
Ptr(ref ty, _) if (if let Self_ = **ty { true } else { false }) && nonstatic => {
self_args.push(cx.expr_deref(trait_.span, arg_expr))
}
_ => {
......
......@@ -24,8 +24,7 @@
use syntax_pos::symbol::keywords;
/// The types of pointers
#[derive(Clone, Eq, PartialEq)]
#[allow(dead_code)]
#[derive(Clone)]
pub enum PtrTy<'a> {
/// &'lifetime mut
Borrowed(Option<&'a str>, ast::Mutability),
......@@ -35,7 +34,7 @@ pub enum PtrTy<'a> {
/// A path, e.g. `::std::option::Option::<i32>` (global). Has support
/// for type parameters and a lifetime.
#[derive(Clone, Eq, PartialEq)]
#[derive(Clone)]
pub struct Path<'a> {
path: Vec<&'a str>,
lifetime: Option<&'a str>,
......@@ -43,7 +42,7 @@ pub struct Path<'a> {
kind: PathKind,
}
#[derive(Clone, Eq, PartialEq)]
#[derive(Clone)]
pub enum PathKind {
Local,
Global,
......@@ -107,7 +106,7 @@ pub fn to_path(&self,
}
/// A type. Supports pointers, Self, and literals
#[derive(Clone, Eq, PartialEq)]
#[derive(Clone)]
pub enum Ty<'a> {
Self_,
/// &/Box/ Ty
......
......@@ -12,7 +12,7 @@ pub mod printf {
use super::strcursor::StrCursor as Cur;
/// Represents a single `printf`-style substitution.
#[derive(Clone, Eq, PartialEq, Debug)]
#[derive(Clone, Debug)]
pub enum Substitution<'a> {
/// A formatted output substitution.
Format(Format<'a>),
......@@ -40,7 +40,7 @@ pub fn translate(&self) -> Option<String> {
}
}
#[derive(Clone, Eq, PartialEq, Debug)]
#[derive(Clone, Debug)]
/// A single `printf`-style formatting directive.
pub struct Format<'a> {
/// The entire original formatting directive.
......@@ -213,7 +213,7 @@ pub fn translate(&self) -> Option<String> {
}
/// A general number used in a `printf` formatting directive.
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
#[derive(Copy, Clone, Debug)]
pub enum Num {
// The range of these values is technically bounded by `NL_ARGMAX`... but, at least for GNU
// libc, it apparently has no real fixed limit. A `u16` is used here on the basis that it
......@@ -739,7 +739,7 @@ fn test_translation() {
pub mod shell {
use super::strcursor::StrCursor as Cur;
#[derive(Clone, Eq, PartialEq, Debug)]
#[derive(Clone, Debug)]
pub enum Substitution<'a> {
Ordinal(u8),
Name(&'a str),
......
......@@ -103,7 +103,7 @@ impl<'a> CollectProcMacros<'a> {
fn check_not_pub_in_root(&self, vis: &ast::Visibility, sp: Span) {
if self.is_proc_macro_crate &&
self.in_root &&
vis.node == ast::VisibilityKind::Public {
vis.node.is_public() {
self.handler.span_err(sp,
"`proc-macro` crate types cannot \
export any items other than functions \
......@@ -181,7 +181,7 @@ fn collect_custom_derive(&mut self, item: &'a ast::Item, attr: &'a ast::Attribut
Vec::new()
};
if self.in_root && item.vis.node == ast::VisibilityKind::Public {
if self.in_root && item.vis.node.is_public() {
self.derives.push(ProcMacroDerive {
span: item.span,
trait_name,
......@@ -206,7 +206,7 @@ fn collect_attr_proc_macro(&mut self, item: &'a ast::Item, attr: &'a ast::Attrib
return;
}
if self.in_root && item.vis.node == ast::VisibilityKind::Public {
if self.in_root && item.vis.node.is_public() {
self.attr_macros.push(ProcMacroDef {
span: item.span,
function_name: item.ident,
......@@ -229,7 +229,7 @@ fn collect_bang_proc_macro(&mut self, item: &'a ast::Item, attr: &'a ast::Attrib
return;
}
if self.in_root && item.vis.node == ast::VisibilityKind::Public {
if self.in_root && item.vis.node.is_public() {
self.bang_macros.push(ProcMacroDef {
span: item.span,
function_name: item.ident,
......@@ -271,7 +271,8 @@ fn visit_item(&mut self, item: &'a ast::Item) {
for attr in &item.attrs {
if is_proc_macro_attr(&attr) {
if let Some(prev_attr) = found_attr {
let msg = if attr.path == prev_attr.path {
let msg = if attr.path.segments[0].ident.name ==
prev_attr.path.segments[0].ident.name {
format!("Only one `#[{}]` attribute is allowed on any given function",
attr.path)
} else {
......
......@@ -12,7 +12,7 @@
use std::str::FromStr;
/// The edition of the compiler (RFC 2052)
#[derive(Clone, Copy, Hash, PartialOrd, Ord, Eq, PartialEq, Debug, RustcEncodable, RustcDecodable)]
#[derive(Clone, Copy, Hash, PartialEq, PartialOrd, Debug, RustcEncodable, RustcDecodable)]
#[non_exhaustive]
pub enum Edition {
// editions must be kept in order, oldest to newest
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册