1
Fork 0

Auto merge of #104673 - matthiaskrgr:rollup-85f65ov, r=matthiaskrgr

Rollup of 9 pull requests

Successful merges:

 - #104420 (Fix doc example for `wrapping_abs`)
 - #104499 (rustdoc JSON: Use `Function` everywhere and remove `Method`)
 - #104500 (`rustc_ast`: remove `ref` patterns)
 - #104511 (Mark functions created for `raw-dylib` on x86 with DllImport storage class)
 - #104595 (Add `PolyExistentialPredicate` type alias)
 - #104605 (deduplicate constant evaluation in cranelift backend)
 - #104628 (Revert "Update CI to use Android NDK r25b")
 - #104662 (Streamline deriving on packed structs.)
 - #104667 (Revert formatting changes of a test)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2022-11-21 15:22:54 +00:00
commit 1cbc45942d
49 changed files with 415 additions and 499 deletions

View file

@ -175,9 +175,9 @@ impl GenericArgs {
} }
pub fn span(&self) -> Span { pub fn span(&self) -> Span {
match *self { match self {
AngleBracketed(ref data) => data.span, AngleBracketed(data) => data.span,
Parenthesized(ref data) => data.span, Parenthesized(data) => data.span,
} }
} }
} }
@ -312,8 +312,8 @@ pub enum GenericBound {
impl GenericBound { impl GenericBound {
pub fn span(&self) -> Span { pub fn span(&self) -> Span {
match self { match self {
GenericBound::Trait(ref t, ..) => t.span, GenericBound::Trait(t, ..) => t.span,
GenericBound::Outlives(ref l) => l.ident.span, GenericBound::Outlives(l) => l.ident.span,
} }
} }
} }
@ -1115,23 +1115,23 @@ impl Expr {
/// If this is not the case, name resolution does not resolve `N` when using /// If this is not the case, name resolution does not resolve `N` when using
/// `min_const_generics` as more complex expressions are not supported. /// `min_const_generics` as more complex expressions are not supported.
pub fn is_potential_trivial_const_param(&self) -> bool { pub fn is_potential_trivial_const_param(&self) -> bool {
let this = if let ExprKind::Block(ref block, None) = self.kind { let this = if let ExprKind::Block(block, None) = &self.kind
if block.stmts.len() == 1 { && block.stmts.len() == 1
if let StmtKind::Expr(ref expr) = block.stmts[0].kind { expr } else { self } && let StmtKind::Expr(expr) = &block.stmts[0].kind
} else { {
self expr
}
} else { } else {
self self
}; };
if let ExprKind::Path(None, ref path) = this.kind { if let ExprKind::Path(None, path) = &this.kind
if path.segments.len() == 1 && path.segments[0].args.is_none() { && path.segments.len() == 1
return true; && path.segments[0].args.is_none()
} {
true
} else {
false
} }
false
} }
pub fn to_bound(&self) -> Option<GenericBound> { pub fn to_bound(&self) -> Option<GenericBound> {
@ -2393,9 +2393,9 @@ pub enum FnRetTy {
impl FnRetTy { impl FnRetTy {
pub fn span(&self) -> Span { pub fn span(&self) -> Span {
match *self { match self {
FnRetTy::Default(span) => span, &FnRetTy::Default(span) => span,
FnRetTy::Ty(ref ty) => ty.span, FnRetTy::Ty(ty) => ty.span,
} }
} }
} }
@ -2657,8 +2657,8 @@ pub enum VariantData {
impl VariantData { impl VariantData {
/// Return the fields of this variant. /// Return the fields of this variant.
pub fn fields(&self) -> &[FieldDef] { pub fn fields(&self) -> &[FieldDef] {
match *self { match self {
VariantData::Struct(ref fields, ..) | VariantData::Tuple(ref fields, _) => fields, VariantData::Struct(fields, ..) | VariantData::Tuple(fields, _) => fields,
_ => &[], _ => &[],
} }
} }

View file

@ -44,16 +44,16 @@ impl MarkedAttrs {
impl NestedMetaItem { impl NestedMetaItem {
/// Returns the `MetaItem` if `self` is a `NestedMetaItem::MetaItem`. /// Returns the `MetaItem` if `self` is a `NestedMetaItem::MetaItem`.
pub fn meta_item(&self) -> Option<&MetaItem> { pub fn meta_item(&self) -> Option<&MetaItem> {
match *self { match self {
NestedMetaItem::MetaItem(ref item) => Some(item), NestedMetaItem::MetaItem(item) => Some(item),
_ => None, _ => None,
} }
} }
/// Returns the `Lit` if `self` is a `NestedMetaItem::Literal`s. /// Returns the `Lit` if `self` is a `NestedMetaItem::Literal`s.
pub fn literal(&self) -> Option<&Lit> { pub fn literal(&self) -> Option<&Lit> {
match *self { match self {
NestedMetaItem::Literal(ref lit) => Some(lit), NestedMetaItem::Literal(lit) => Some(lit),
_ => None, _ => None,
} }
} }
@ -116,18 +116,18 @@ impl NestedMetaItem {
impl Attribute { impl Attribute {
#[inline] #[inline]
pub fn has_name(&self, name: Symbol) -> bool { pub fn has_name(&self, name: Symbol) -> bool {
match self.kind { match &self.kind {
AttrKind::Normal(ref normal) => normal.item.path == name, AttrKind::Normal(normal) => normal.item.path == name,
AttrKind::DocComment(..) => false, AttrKind::DocComment(..) => false,
} }
} }
/// For a single-segment attribute, returns its name; otherwise, returns `None`. /// For a single-segment attribute, returns its name; otherwise, returns `None`.
pub fn ident(&self) -> Option<Ident> { pub fn ident(&self) -> Option<Ident> {
match self.kind { match &self.kind {
AttrKind::Normal(ref normal) => { AttrKind::Normal(normal) => {
if normal.item.path.segments.len() == 1 { if let [ident] = &*normal.item.path.segments {
Some(normal.item.path.segments[0].ident) Some(ident.ident)
} else { } else {
None None
} }
@ -140,17 +140,15 @@ impl Attribute {
} }
pub fn value_str(&self) -> Option<Symbol> { pub fn value_str(&self) -> Option<Symbol> {
match self.kind { match &self.kind {
AttrKind::Normal(ref normal) => { AttrKind::Normal(normal) => normal.item.meta_kind().and_then(|kind| kind.value_str()),
normal.item.meta_kind().and_then(|kind| kind.value_str())
}
AttrKind::DocComment(..) => None, AttrKind::DocComment(..) => None,
} }
} }
pub fn meta_item_list(&self) -> Option<Vec<NestedMetaItem>> { pub fn meta_item_list(&self) -> Option<Vec<NestedMetaItem>> {
match self.kind { match &self.kind {
AttrKind::Normal(ref normal) => match normal.item.meta_kind() { AttrKind::Normal(normal) => match normal.item.meta_kind() {
Some(MetaItemKind::List(list)) => Some(list), Some(MetaItemKind::List(list)) => Some(list),
_ => None, _ => None,
}, },
@ -191,8 +189,8 @@ impl MetaItem {
} }
pub fn meta_item_list(&self) -> Option<&[NestedMetaItem]> { pub fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
match self.kind { match &self.kind {
MetaItemKind::List(ref l) => Some(&l[..]), MetaItemKind::List(l) => Some(&**l),
_ => None, _ => None,
} }
} }
@ -268,9 +266,9 @@ impl Attribute {
/// * `#[doc = "doc"]` returns `Some("doc")`. /// * `#[doc = "doc"]` returns `Some("doc")`.
/// * `#[doc(...)]` returns `None`. /// * `#[doc(...)]` returns `None`.
pub fn doc_str(&self) -> Option<Symbol> { pub fn doc_str(&self) -> Option<Symbol> {
match self.kind { match &self.kind {
AttrKind::DocComment(.., data) => Some(data), AttrKind::DocComment(.., data) => Some(*data),
AttrKind::Normal(ref normal) if normal.item.path == sym::doc => { AttrKind::Normal(normal) if normal.item.path == sym::doc => {
normal.item.meta_kind().and_then(|kind| kind.value_str()) normal.item.meta_kind().and_then(|kind| kind.value_str())
} }
_ => None, _ => None,
@ -282,8 +280,8 @@ impl Attribute {
} }
pub fn get_normal_item(&self) -> &AttrItem { pub fn get_normal_item(&self) -> &AttrItem {
match self.kind { match &self.kind {
AttrKind::Normal(ref normal) => &normal.item, AttrKind::Normal(normal) => &normal.item,
AttrKind::DocComment(..) => panic!("unexpected doc comment"), AttrKind::DocComment(..) => panic!("unexpected doc comment"),
} }
} }
@ -297,28 +295,28 @@ impl Attribute {
/// Extracts the MetaItem from inside this Attribute. /// Extracts the MetaItem from inside this Attribute.
pub fn meta(&self) -> Option<MetaItem> { pub fn meta(&self) -> Option<MetaItem> {
match self.kind { match &self.kind {
AttrKind::Normal(ref normal) => normal.item.meta(self.span), AttrKind::Normal(normal) => normal.item.meta(self.span),
AttrKind::DocComment(..) => None, AttrKind::DocComment(..) => None,
} }
} }
pub fn meta_kind(&self) -> Option<MetaItemKind> { pub fn meta_kind(&self) -> Option<MetaItemKind> {
match self.kind { match &self.kind {
AttrKind::Normal(ref normal) => normal.item.meta_kind(), AttrKind::Normal(normal) => normal.item.meta_kind(),
AttrKind::DocComment(..) => None, AttrKind::DocComment(..) => None,
} }
} }
pub fn tokens(&self) -> TokenStream { pub fn tokens(&self) -> TokenStream {
match self.kind { match &self.kind {
AttrKind::Normal(ref normal) => normal AttrKind::Normal(normal) => normal
.tokens .tokens
.as_ref() .as_ref()
.unwrap_or_else(|| panic!("attribute is missing tokens: {:?}", self)) .unwrap_or_else(|| panic!("attribute is missing tokens: {:?}", self))
.to_attr_token_stream() .to_attr_token_stream()
.to_tokenstream(), .to_tokenstream(),
AttrKind::DocComment(comment_kind, data) => TokenStream::new(vec![TokenTree::Token( &AttrKind::DocComment(comment_kind, data) => TokenStream::new(vec![TokenTree::Token(
Token::new(token::DocComment(comment_kind, self.style, data), self.span), Token::new(token::DocComment(comment_kind, self.style, data), self.span),
Spacing::Alone, Spacing::Alone,
)]), )]),
@ -496,17 +494,17 @@ impl MetaItem {
let span = span.with_hi(segments.last().unwrap().ident.span.hi()); let span = span.with_hi(segments.last().unwrap().ident.span.hi());
Path { span, segments, tokens: None } Path { span, segments, tokens: None }
} }
Some(TokenTree::Token(Token { kind: token::Interpolated(nt), .. }, _)) => match *nt { Some(TokenTree::Token(Token { kind: token::Interpolated(nt), .. }, _)) => match &*nt {
token::Nonterminal::NtMeta(ref item) => return item.meta(item.path.span), token::Nonterminal::NtMeta(item) => return item.meta(item.path.span),
token::Nonterminal::NtPath(ref path) => (**path).clone(), token::Nonterminal::NtPath(path) => (**path).clone(),
_ => return None, _ => return None,
}, },
_ => return None, _ => return None,
}; };
let list_closing_paren_pos = tokens.peek().map(|tt| tt.span().hi()); let list_closing_paren_pos = tokens.peek().map(|tt| tt.span().hi());
let kind = MetaItemKind::from_tokens(tokens)?; let kind = MetaItemKind::from_tokens(tokens)?;
let hi = match kind { let hi = match &kind {
MetaItemKind::NameValue(ref lit) => lit.span.hi(), MetaItemKind::NameValue(lit) => lit.span.hi(),
MetaItemKind::List(..) => list_closing_paren_pos.unwrap_or(path.span.hi()), MetaItemKind::List(..) => list_closing_paren_pos.unwrap_or(path.span.hi()),
_ => path.span.hi(), _ => path.span.hi(),
}; };
@ -518,8 +516,8 @@ impl MetaItem {
impl MetaItemKind { impl MetaItemKind {
pub fn value_str(&self) -> Option<Symbol> { pub fn value_str(&self) -> Option<Symbol> {
match self { match self {
MetaItemKind::NameValue(ref v) => match v.kind { MetaItemKind::NameValue(v) => match v.kind {
LitKind::Str(ref s, _) => Some(*s), LitKind::Str(s, _) => Some(s),
_ => None, _ => None,
}, },
_ => None, _ => None,
@ -557,15 +555,15 @@ impl MetaItemKind {
} }
fn token_trees(&self, span: Span) -> Vec<TokenTree> { fn token_trees(&self, span: Span) -> Vec<TokenTree> {
match *self { match self {
MetaItemKind::Word => vec![], MetaItemKind::Word => vec![],
MetaItemKind::NameValue(ref lit) => { MetaItemKind::NameValue(lit) => {
vec![ vec![
TokenTree::token_alone(token::Eq, span), TokenTree::token_alone(token::Eq, span),
TokenTree::Token(lit.to_token(), Spacing::Alone), TokenTree::Token(lit.to_token(), Spacing::Alone),
] ]
} }
MetaItemKind::List(ref list) => { MetaItemKind::List(list) => {
let mut tokens = Vec::new(); let mut tokens = Vec::new();
for (i, item) in list.iter().enumerate() { for (i, item) in list.iter().enumerate() {
if i > 0 { if i > 0 {
@ -648,16 +646,16 @@ impl MetaItemKind {
impl NestedMetaItem { impl NestedMetaItem {
pub fn span(&self) -> Span { pub fn span(&self) -> Span {
match *self { match self {
NestedMetaItem::MetaItem(ref item) => item.span, NestedMetaItem::MetaItem(item) => item.span,
NestedMetaItem::Literal(ref lit) => lit.span, NestedMetaItem::Literal(lit) => lit.span,
} }
} }
fn token_trees(&self) -> Vec<TokenTree> { fn token_trees(&self) -> Vec<TokenTree> {
match *self { match self {
NestedMetaItem::MetaItem(ref item) => item.token_trees(), NestedMetaItem::MetaItem(item) => item.token_trees(),
NestedMetaItem::Literal(ref lit) => { NestedMetaItem::Literal(lit) => {
vec![TokenTree::Token(lit.to_token(), Spacing::Alone)] vec![TokenTree::Token(lit.to_token(), Spacing::Alone)]
} }
} }

View file

@ -439,15 +439,15 @@ pub fn noop_visit_constraint<T: MutVisitor>(
) { ) {
vis.visit_id(id); vis.visit_id(id);
vis.visit_ident(ident); vis.visit_ident(ident);
if let Some(ref mut gen_args) = gen_args { if let Some(gen_args) = gen_args {
vis.visit_generic_args(gen_args); vis.visit_generic_args(gen_args);
} }
match kind { match kind {
AssocConstraintKind::Equality { ref mut term } => match term { AssocConstraintKind::Equality { term } => match term {
Term::Ty(ty) => vis.visit_ty(ty), Term::Ty(ty) => vis.visit_ty(ty),
Term::Const(c) => vis.visit_anon_const(c), Term::Const(c) => vis.visit_anon_const(c),
}, },
AssocConstraintKind::Bound { ref mut bounds } => visit_bounds(bounds, vis), AssocConstraintKind::Bound { bounds } => visit_bounds(bounds, vis),
} }
vis.visit_span(span); vis.visit_span(span);
} }
@ -880,7 +880,7 @@ pub fn noop_flat_map_generic_param<T: MutVisitor>(
let GenericParam { id, ident, attrs, bounds, kind, colon_span, is_placeholder: _ } = &mut param; let GenericParam { id, ident, attrs, bounds, kind, colon_span, is_placeholder: _ } = &mut param;
vis.visit_id(id); vis.visit_id(id);
vis.visit_ident(ident); vis.visit_ident(ident);
if let Some(ref mut colon_span) = colon_span { if let Some(colon_span) = colon_span {
vis.visit_span(colon_span); vis.visit_span(colon_span);
} }
visit_attrs(attrs, vis); visit_attrs(attrs, vis);

View file

@ -601,9 +601,10 @@ impl Token {
/// Returns `true` if the token is an interpolated path. /// Returns `true` if the token is an interpolated path.
fn is_path(&self) -> bool { fn is_path(&self) -> bool {
if let Interpolated(ref nt) = self.kind && let NtPath(..) = **nt { if let Interpolated(nt) = &self.kind && let NtPath(..) = **nt {
return true; return true;
} }
false false
} }
@ -611,7 +612,7 @@ impl Token {
/// That is, is this a pre-parsed expression dropped into the token stream /// That is, is this a pre-parsed expression dropped into the token stream
/// (which happens while parsing the result of macro expansion)? /// (which happens while parsing the result of macro expansion)?
pub fn is_whole_expr(&self) -> bool { pub fn is_whole_expr(&self) -> bool {
if let Interpolated(ref nt) = self.kind if let Interpolated(nt) = &self.kind
&& let NtExpr(_) | NtLiteral(_) | NtPath(_) | NtBlock(_) = **nt && let NtExpr(_) | NtLiteral(_) | NtPath(_) | NtBlock(_) = **nt
{ {
return true; return true;
@ -622,9 +623,10 @@ impl Token {
// Is the token an interpolated block (`$b:block`)? // Is the token an interpolated block (`$b:block`)?
pub fn is_whole_block(&self) -> bool { pub fn is_whole_block(&self) -> bool {
if let Interpolated(ref nt) = self.kind && let NtBlock(..) = **nt { if let Interpolated(nt) = &self.kind && let NtBlock(..) = **nt {
return true; return true;
} }
false false
} }

View file

@ -377,26 +377,26 @@ pub fn needs_par_as_let_scrutinee(order: i8) -> bool {
/// parens or other delimiters, e.g., `X { y: 1 }`, `X { y: 1 }.method()`, `foo == X { y: 1 }` and /// parens or other delimiters, e.g., `X { y: 1 }`, `X { y: 1 }.method()`, `foo == X { y: 1 }` and
/// `X { y: 1 } == foo` all do, but `(X { y: 1 }) == foo` does not. /// `X { y: 1 } == foo` all do, but `(X { y: 1 }) == foo` does not.
pub fn contains_exterior_struct_lit(value: &ast::Expr) -> bool { pub fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
match value.kind { match &value.kind {
ast::ExprKind::Struct(..) => true, ast::ExprKind::Struct(..) => true,
ast::ExprKind::Assign(ref lhs, ref rhs, _) ast::ExprKind::Assign(lhs, rhs, _)
| ast::ExprKind::AssignOp(_, ref lhs, ref rhs) | ast::ExprKind::AssignOp(_, lhs, rhs)
| ast::ExprKind::Binary(_, ref lhs, ref rhs) => { | ast::ExprKind::Binary(_, lhs, rhs) => {
// X { y: 1 } + X { y: 2 } // X { y: 1 } + X { y: 2 }
contains_exterior_struct_lit(&lhs) || contains_exterior_struct_lit(&rhs) contains_exterior_struct_lit(&lhs) || contains_exterior_struct_lit(&rhs)
} }
ast::ExprKind::Await(ref x) ast::ExprKind::Await(x)
| ast::ExprKind::Unary(_, ref x) | ast::ExprKind::Unary(_, x)
| ast::ExprKind::Cast(ref x, _) | ast::ExprKind::Cast(x, _)
| ast::ExprKind::Type(ref x, _) | ast::ExprKind::Type(x, _)
| ast::ExprKind::Field(ref x, _) | ast::ExprKind::Field(x, _)
| ast::ExprKind::Index(ref x, _) => { | ast::ExprKind::Index(x, _) => {
// &X { y: 1 }, X { y: 1 }.y // &X { y: 1 }, X { y: 1 }.y
contains_exterior_struct_lit(&x) contains_exterior_struct_lit(&x)
} }
ast::ExprKind::MethodCall(box ast::MethodCall { ref receiver, .. }) => { ast::ExprKind::MethodCall(box ast::MethodCall { receiver, .. }) => {
// X { y: 1 }.bar(...) // X { y: 1 }.bar(...)
contains_exterior_struct_lit(&receiver) contains_exterior_struct_lit(&receiver)
} }

View file

@ -299,74 +299,68 @@ pub fn walk_trait_ref<'a, V: Visitor<'a>>(visitor: &mut V, trait_ref: &'a TraitR
pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
visitor.visit_vis(&item.vis); visitor.visit_vis(&item.vis);
visitor.visit_ident(item.ident); visitor.visit_ident(item.ident);
match item.kind { match &item.kind {
ItemKind::ExternCrate(_) => {} ItemKind::ExternCrate(_) => {}
ItemKind::Use(ref use_tree) => visitor.visit_use_tree(use_tree, item.id, false), ItemKind::Use(use_tree) => visitor.visit_use_tree(use_tree, item.id, false),
ItemKind::Static(ref typ, _, ref expr) | ItemKind::Const(_, ref typ, ref expr) => { ItemKind::Static(typ, _, expr) | ItemKind::Const(_, typ, expr) => {
visitor.visit_ty(typ); visitor.visit_ty(typ);
walk_list!(visitor, visit_expr, expr); walk_list!(visitor, visit_expr, expr);
} }
ItemKind::Fn(box Fn { defaultness: _, ref generics, ref sig, ref body }) => { ItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
let kind = let kind =
FnKind::Fn(FnCtxt::Free, item.ident, sig, &item.vis, generics, body.as_deref()); FnKind::Fn(FnCtxt::Free, item.ident, sig, &item.vis, generics, body.as_deref());
visitor.visit_fn(kind, item.span, item.id) visitor.visit_fn(kind, item.span, item.id)
} }
ItemKind::Mod(_unsafety, ref mod_kind) => match mod_kind { ItemKind::Mod(_unsafety, mod_kind) => match mod_kind {
ModKind::Loaded(items, _inline, _inner_span) => { ModKind::Loaded(items, _inline, _inner_span) => {
walk_list!(visitor, visit_item, items) walk_list!(visitor, visit_item, items)
} }
ModKind::Unloaded => {} ModKind::Unloaded => {}
}, },
ItemKind::ForeignMod(ref foreign_module) => { ItemKind::ForeignMod(foreign_module) => {
walk_list!(visitor, visit_foreign_item, &foreign_module.items); walk_list!(visitor, visit_foreign_item, &foreign_module.items);
} }
ItemKind::GlobalAsm(ref asm) => visitor.visit_inline_asm(asm), ItemKind::GlobalAsm(asm) => visitor.visit_inline_asm(asm),
ItemKind::TyAlias(box TyAlias { ref generics, ref bounds, ref ty, .. }) => { ItemKind::TyAlias(box TyAlias { generics, bounds, ty, .. }) => {
visitor.visit_generics(generics); visitor.visit_generics(generics);
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound); walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
walk_list!(visitor, visit_ty, ty); walk_list!(visitor, visit_ty, ty);
} }
ItemKind::Enum(ref enum_definition, ref generics) => { ItemKind::Enum(enum_definition, generics) => {
visitor.visit_generics(generics); visitor.visit_generics(generics);
visitor.visit_enum_def(enum_definition) visitor.visit_enum_def(enum_definition)
} }
ItemKind::Impl(box Impl { ItemKind::Impl(box Impl {
defaultness: _, defaultness: _,
unsafety: _, unsafety: _,
ref generics, generics,
constness: _, constness: _,
polarity: _, polarity: _,
ref of_trait, of_trait,
ref self_ty, self_ty,
ref items, items,
}) => { }) => {
visitor.visit_generics(generics); visitor.visit_generics(generics);
walk_list!(visitor, visit_trait_ref, of_trait); walk_list!(visitor, visit_trait_ref, of_trait);
visitor.visit_ty(self_ty); visitor.visit_ty(self_ty);
walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Impl); walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Impl);
} }
ItemKind::Struct(ref struct_definition, ref generics) ItemKind::Struct(struct_definition, generics)
| ItemKind::Union(ref struct_definition, ref generics) => { | ItemKind::Union(struct_definition, generics) => {
visitor.visit_generics(generics); visitor.visit_generics(generics);
visitor.visit_variant_data(struct_definition); visitor.visit_variant_data(struct_definition);
} }
ItemKind::Trait(box Trait { ItemKind::Trait(box Trait { unsafety: _, is_auto: _, generics, bounds, items }) => {
unsafety: _,
is_auto: _,
ref generics,
ref bounds,
ref items,
}) => {
visitor.visit_generics(generics); visitor.visit_generics(generics);
walk_list!(visitor, visit_param_bound, bounds, BoundKind::SuperTraits); walk_list!(visitor, visit_param_bound, bounds, BoundKind::SuperTraits);
walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Trait); walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Trait);
} }
ItemKind::TraitAlias(ref generics, ref bounds) => { ItemKind::TraitAlias(generics, bounds) => {
visitor.visit_generics(generics); visitor.visit_generics(generics);
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound); walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
} }
ItemKind::MacCall(ref mac) => visitor.visit_mac_call(mac), ItemKind::MacCall(mac) => visitor.visit_mac_call(mac),
ItemKind::MacroDef(ref ts) => visitor.visit_mac_def(ts, item.id), ItemKind::MacroDef(ts) => visitor.visit_mac_def(ts, item.id),
} }
walk_list!(visitor, visit_attribute, &item.attrs); walk_list!(visitor, visit_attribute, &item.attrs);
} }
@ -399,39 +393,39 @@ pub fn walk_pat_field<'a, V: Visitor<'a>>(visitor: &mut V, fp: &'a PatField) {
} }
pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) { pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
match typ.kind { match &typ.kind {
TyKind::Slice(ref ty) | TyKind::Paren(ref ty) => visitor.visit_ty(ty), TyKind::Slice(ty) | TyKind::Paren(ty) => visitor.visit_ty(ty),
TyKind::Ptr(ref mutable_type) => visitor.visit_ty(&mutable_type.ty), TyKind::Ptr(mutable_type) => visitor.visit_ty(&mutable_type.ty),
TyKind::Rptr(ref opt_lifetime, ref mutable_type) => { TyKind::Rptr(opt_lifetime, mutable_type) => {
walk_list!(visitor, visit_lifetime, opt_lifetime, LifetimeCtxt::Rptr); walk_list!(visitor, visit_lifetime, opt_lifetime, LifetimeCtxt::Rptr);
visitor.visit_ty(&mutable_type.ty) visitor.visit_ty(&mutable_type.ty)
} }
TyKind::Tup(ref tuple_element_types) => { TyKind::Tup(tuple_element_types) => {
walk_list!(visitor, visit_ty, tuple_element_types); walk_list!(visitor, visit_ty, tuple_element_types);
} }
TyKind::BareFn(ref function_declaration) => { TyKind::BareFn(function_declaration) => {
walk_list!(visitor, visit_generic_param, &function_declaration.generic_params); walk_list!(visitor, visit_generic_param, &function_declaration.generic_params);
walk_fn_decl(visitor, &function_declaration.decl); walk_fn_decl(visitor, &function_declaration.decl);
} }
TyKind::Path(ref maybe_qself, ref path) => { TyKind::Path(maybe_qself, path) => {
if let Some(ref qself) = *maybe_qself { if let Some(qself) = maybe_qself {
visitor.visit_ty(&qself.ty); visitor.visit_ty(&qself.ty);
} }
visitor.visit_path(path, typ.id); visitor.visit_path(path, typ.id);
} }
TyKind::Array(ref ty, ref length) => { TyKind::Array(ty, length) => {
visitor.visit_ty(ty); visitor.visit_ty(ty);
visitor.visit_anon_const(length) visitor.visit_anon_const(length)
} }
TyKind::TraitObject(ref bounds, ..) => { TyKind::TraitObject(bounds, ..) => {
walk_list!(visitor, visit_param_bound, bounds, BoundKind::TraitObject); walk_list!(visitor, visit_param_bound, bounds, BoundKind::TraitObject);
} }
TyKind::ImplTrait(_, ref bounds) => { TyKind::ImplTrait(_, bounds) => {
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Impl); walk_list!(visitor, visit_param_bound, bounds, BoundKind::Impl);
} }
TyKind::Typeof(ref expression) => visitor.visit_anon_const(expression), TyKind::Typeof(expression) => visitor.visit_anon_const(expression),
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {} TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {}
TyKind::MacCall(ref mac) => visitor.visit_mac_call(mac), TyKind::MacCall(mac) => visitor.visit_mac_call(mac),
TyKind::Never | TyKind::CVarArgs => {} TyKind::Never | TyKind::CVarArgs => {}
} }
} }
@ -444,15 +438,15 @@ pub fn walk_path<'a, V: Visitor<'a>>(visitor: &mut V, path: &'a Path) {
pub fn walk_use_tree<'a, V: Visitor<'a>>(visitor: &mut V, use_tree: &'a UseTree, id: NodeId) { pub fn walk_use_tree<'a, V: Visitor<'a>>(visitor: &mut V, use_tree: &'a UseTree, id: NodeId) {
visitor.visit_path(&use_tree.prefix, id); visitor.visit_path(&use_tree.prefix, id);
match use_tree.kind { match &use_tree.kind {
UseTreeKind::Simple(rename, ..) => { UseTreeKind::Simple(rename, ..) => {
// The extra IDs are handled during HIR lowering. // The extra IDs are handled during HIR lowering.
if let Some(rename) = rename { if let &Some(rename) = rename {
visitor.visit_ident(rename); visitor.visit_ident(rename);
} }
} }
UseTreeKind::Glob => {} UseTreeKind::Glob => {}
UseTreeKind::Nested(ref use_trees) => { UseTreeKind::Nested(use_trees) => {
for &(ref nested_tree, nested_id) in use_trees { for &(ref nested_tree, nested_id) in use_trees {
visitor.visit_use_tree(nested_tree, nested_id, true); visitor.visit_use_tree(nested_tree, nested_id, true);
} }
@ -462,7 +456,7 @@ pub fn walk_use_tree<'a, V: Visitor<'a>>(visitor: &mut V, use_tree: &'a UseTree,
pub fn walk_path_segment<'a, V: Visitor<'a>>(visitor: &mut V, segment: &'a PathSegment) { pub fn walk_path_segment<'a, V: Visitor<'a>>(visitor: &mut V, segment: &'a PathSegment) {
visitor.visit_ident(segment.ident); visitor.visit_ident(segment.ident);
if let Some(ref args) = segment.args { if let Some(args) = &segment.args {
visitor.visit_generic_args(args); visitor.visit_generic_args(args);
} }
} }
@ -471,8 +465,8 @@ pub fn walk_generic_args<'a, V>(visitor: &mut V, generic_args: &'a GenericArgs)
where where
V: Visitor<'a>, V: Visitor<'a>,
{ {
match *generic_args { match generic_args {
GenericArgs::AngleBracketed(ref data) => { GenericArgs::AngleBracketed(data) => {
for arg in &data.args { for arg in &data.args {
match arg { match arg {
AngleBracketedArg::Arg(a) => visitor.visit_generic_arg(a), AngleBracketedArg::Arg(a) => visitor.visit_generic_arg(a),
@ -480,7 +474,7 @@ where
} }
} }
} }
GenericArgs::Parenthesized(ref data) => { GenericArgs::Parenthesized(data) => {
walk_list!(visitor, visit_ty, &data.inputs); walk_list!(visitor, visit_ty, &data.inputs);
walk_fn_ret_ty(visitor, &data.output); walk_fn_ret_ty(visitor, &data.output);
} }
@ -500,64 +494,64 @@ where
pub fn walk_assoc_constraint<'a, V: Visitor<'a>>(visitor: &mut V, constraint: &'a AssocConstraint) { pub fn walk_assoc_constraint<'a, V: Visitor<'a>>(visitor: &mut V, constraint: &'a AssocConstraint) {
visitor.visit_ident(constraint.ident); visitor.visit_ident(constraint.ident);
if let Some(ref gen_args) = constraint.gen_args { if let Some(gen_args) = &constraint.gen_args {
visitor.visit_generic_args(gen_args); visitor.visit_generic_args(gen_args);
} }
match constraint.kind { match &constraint.kind {
AssocConstraintKind::Equality { ref term } => match term { AssocConstraintKind::Equality { term } => match term {
Term::Ty(ty) => visitor.visit_ty(ty), Term::Ty(ty) => visitor.visit_ty(ty),
Term::Const(c) => visitor.visit_anon_const(c), Term::Const(c) => visitor.visit_anon_const(c),
}, },
AssocConstraintKind::Bound { ref bounds } => { AssocConstraintKind::Bound { bounds } => {
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound); walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
} }
} }
} }
pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) { pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) {
match pattern.kind { match &pattern.kind {
PatKind::TupleStruct(ref opt_qself, ref path, ref elems) => { PatKind::TupleStruct(opt_qself, path, elems) => {
if let Some(ref qself) = *opt_qself { if let Some(qself) = opt_qself {
visitor.visit_ty(&qself.ty); visitor.visit_ty(&qself.ty);
} }
visitor.visit_path(path, pattern.id); visitor.visit_path(path, pattern.id);
walk_list!(visitor, visit_pat, elems); walk_list!(visitor, visit_pat, elems);
} }
PatKind::Path(ref opt_qself, ref path) => { PatKind::Path(opt_qself, path) => {
if let Some(ref qself) = *opt_qself { if let Some(qself) = opt_qself {
visitor.visit_ty(&qself.ty); visitor.visit_ty(&qself.ty);
} }
visitor.visit_path(path, pattern.id) visitor.visit_path(path, pattern.id)
} }
PatKind::Struct(ref opt_qself, ref path, ref fields, _) => { PatKind::Struct(opt_qself, path, fields, _) => {
if let Some(ref qself) = *opt_qself { if let Some(qself) = opt_qself {
visitor.visit_ty(&qself.ty); visitor.visit_ty(&qself.ty);
} }
visitor.visit_path(path, pattern.id); visitor.visit_path(path, pattern.id);
walk_list!(visitor, visit_pat_field, fields); walk_list!(visitor, visit_pat_field, fields);
} }
PatKind::Box(ref subpattern) PatKind::Box(subpattern) | PatKind::Ref(subpattern, _) | PatKind::Paren(subpattern) => {
| PatKind::Ref(ref subpattern, _) visitor.visit_pat(subpattern)
| PatKind::Paren(ref subpattern) => visitor.visit_pat(subpattern), }
PatKind::Ident(_, ident, ref optional_subpattern) => { PatKind::Ident(_, ident, optional_subpattern) => {
visitor.visit_ident(ident); visitor.visit_ident(*ident);
walk_list!(visitor, visit_pat, optional_subpattern); walk_list!(visitor, visit_pat, optional_subpattern);
} }
PatKind::Lit(ref expression) => visitor.visit_expr(expression), PatKind::Lit(expression) => visitor.visit_expr(expression),
PatKind::Range(ref lower_bound, ref upper_bound, _) => { PatKind::Range(lower_bound, upper_bound, _) => {
walk_list!(visitor, visit_expr, lower_bound); walk_list!(visitor, visit_expr, lower_bound);
walk_list!(visitor, visit_expr, upper_bound); walk_list!(visitor, visit_expr, upper_bound);
} }
PatKind::Wild | PatKind::Rest => {} PatKind::Wild | PatKind::Rest => {}
PatKind::Tuple(ref elems) | PatKind::Slice(ref elems) | PatKind::Or(ref elems) => { PatKind::Tuple(elems) | PatKind::Slice(elems) | PatKind::Or(elems) => {
walk_list!(visitor, visit_pat, elems); walk_list!(visitor, visit_pat, elems);
} }
PatKind::MacCall(ref mac) => visitor.visit_mac_call(mac), PatKind::MacCall(mac) => visitor.visit_mac_call(mac),
} }
} }
pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignItem) { pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignItem) {
let Item { id, span, ident, ref vis, ref attrs, ref kind, tokens: _ } = *item; let &Item { id, span, ident, ref vis, ref attrs, ref kind, tokens: _ } = item;
visitor.visit_vis(vis); visitor.visit_vis(vis);
visitor.visit_ident(ident); visitor.visit_ident(ident);
walk_list!(visitor, visit_attribute, attrs); walk_list!(visitor, visit_attribute, attrs);
@ -566,7 +560,7 @@ pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignI
visitor.visit_ty(ty); visitor.visit_ty(ty);
walk_list!(visitor, visit_expr, expr); walk_list!(visitor, visit_expr, expr);
} }
ForeignItemKind::Fn(box Fn { defaultness: _, ref generics, ref sig, ref body }) => { ForeignItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
let kind = FnKind::Fn(FnCtxt::Foreign, ident, sig, vis, generics, body.as_deref()); let kind = FnKind::Fn(FnCtxt::Foreign, ident, sig, vis, generics, body.as_deref());
visitor.visit_fn(kind, span, id); visitor.visit_fn(kind, span, id);
} }
@ -582,11 +576,9 @@ pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignI
} }
pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a GenericBound) { pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a GenericBound) {
match *bound { match bound {
GenericBound::Trait(ref typ, ref _modifier) => visitor.visit_poly_trait_ref(typ), GenericBound::Trait(typ, _modifier) => visitor.visit_poly_trait_ref(typ),
GenericBound::Outlives(ref lifetime) => { GenericBound::Outlives(lifetime) => visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound),
visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound)
}
} }
} }
@ -594,10 +586,10 @@ pub fn walk_generic_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a Generi
visitor.visit_ident(param.ident); visitor.visit_ident(param.ident);
walk_list!(visitor, visit_attribute, param.attrs.iter()); walk_list!(visitor, visit_attribute, param.attrs.iter());
walk_list!(visitor, visit_param_bound, &param.bounds, BoundKind::Bound); walk_list!(visitor, visit_param_bound, &param.bounds, BoundKind::Bound);
match param.kind { match &param.kind {
GenericParamKind::Lifetime => (), GenericParamKind::Lifetime => (),
GenericParamKind::Type { ref default } => walk_list!(visitor, visit_ty, default), GenericParamKind::Type { default } => walk_list!(visitor, visit_ty, default),
GenericParamKind::Const { ref ty, ref default, .. } => { GenericParamKind::Const { ty, default, .. } => {
visitor.visit_ty(ty); visitor.visit_ty(ty);
if let Some(default) = default { if let Some(default) = default {
visitor.visit_anon_const(default); visitor.visit_anon_const(default);
@ -621,24 +613,22 @@ pub fn walk_closure_binder<'a, V: Visitor<'a>>(visitor: &mut V, binder: &'a Clos
} }
pub fn walk_where_predicate<'a, V: Visitor<'a>>(visitor: &mut V, predicate: &'a WherePredicate) { pub fn walk_where_predicate<'a, V: Visitor<'a>>(visitor: &mut V, predicate: &'a WherePredicate) {
match *predicate { match predicate {
WherePredicate::BoundPredicate(WhereBoundPredicate { WherePredicate::BoundPredicate(WhereBoundPredicate {
ref bounded_ty, bounded_ty,
ref bounds, bounds,
ref bound_generic_params, bound_generic_params,
.. ..
}) => { }) => {
visitor.visit_ty(bounded_ty); visitor.visit_ty(bounded_ty);
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound); walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
walk_list!(visitor, visit_generic_param, bound_generic_params); walk_list!(visitor, visit_generic_param, bound_generic_params);
} }
WherePredicate::RegionPredicate(WhereRegionPredicate { WherePredicate::RegionPredicate(WhereRegionPredicate { lifetime, bounds, .. }) => {
ref lifetime, ref bounds, ..
}) => {
visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound); visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound);
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound); walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
} }
WherePredicate::EqPredicate(WhereEqPredicate { ref lhs_ty, ref rhs_ty, .. }) => { WherePredicate::EqPredicate(WhereEqPredicate { lhs_ty, rhs_ty, .. }) => {
visitor.visit_ty(lhs_ty); visitor.visit_ty(lhs_ty);
visitor.visit_ty(rhs_ty); visitor.visit_ty(rhs_ty);
} }
@ -646,7 +636,7 @@ pub fn walk_where_predicate<'a, V: Visitor<'a>>(visitor: &mut V, predicate: &'a
} }
pub fn walk_fn_ret_ty<'a, V: Visitor<'a>>(visitor: &mut V, ret_ty: &'a FnRetTy) { pub fn walk_fn_ret_ty<'a, V: Visitor<'a>>(visitor: &mut V, ret_ty: &'a FnRetTy) {
if let FnRetTy::Ty(ref output_ty) = *ret_ty { if let FnRetTy::Ty(output_ty) = ret_ty {
visitor.visit_ty(output_ty) visitor.visit_ty(output_ty)
} }
} }
@ -675,7 +665,7 @@ pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) {
} }
pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem, ctxt: AssocCtxt) { pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem, ctxt: AssocCtxt) {
let Item { id, span, ident, ref vis, ref attrs, ref kind, tokens: _ } = *item; let &Item { id, span, ident, ref vis, ref attrs, ref kind, tokens: _ } = item;
visitor.visit_vis(vis); visitor.visit_vis(vis);
visitor.visit_ident(ident); visitor.visit_ident(ident);
walk_list!(visitor, visit_attribute, attrs); walk_list!(visitor, visit_attribute, attrs);
@ -684,7 +674,7 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem,
visitor.visit_ty(ty); visitor.visit_ty(ty);
walk_list!(visitor, visit_expr, expr); walk_list!(visitor, visit_expr, expr);
} }
AssocItemKind::Fn(box Fn { defaultness: _, ref generics, ref sig, ref body }) => { AssocItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), ident, sig, vis, generics, body.as_deref()); let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), ident, sig, vis, generics, body.as_deref());
visitor.visit_fn(kind, span, id); visitor.visit_fn(kind, span, id);
} }
@ -717,13 +707,13 @@ pub fn walk_block<'a, V: Visitor<'a>>(visitor: &mut V, block: &'a Block) {
} }
pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) { pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) {
match statement.kind { match &statement.kind {
StmtKind::Local(ref local) => visitor.visit_local(local), StmtKind::Local(local) => visitor.visit_local(local),
StmtKind::Item(ref item) => visitor.visit_item(item), StmtKind::Item(item) => visitor.visit_item(item),
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => visitor.visit_expr(expr), StmtKind::Expr(expr) | StmtKind::Semi(expr) => visitor.visit_expr(expr),
StmtKind::Empty => {} StmtKind::Empty => {}
StmtKind::MacCall(ref mac) => { StmtKind::MacCall(mac) => {
let MacCallStmt { ref mac, style: _, ref attrs, tokens: _ } = **mac; let MacCallStmt { mac, attrs, style: _, tokens: _ } = &**mac;
visitor.visit_mac_call(mac); visitor.visit_mac_call(mac);
for attr in attrs.iter() { for attr in attrs.iter() {
visitor.visit_attribute(attr); visitor.visit_attribute(attr);
@ -760,7 +750,7 @@ pub fn walk_inline_asm<'a, V: Visitor<'a>>(visitor: &mut V, asm: &'a InlineAsm)
} }
pub fn walk_inline_asm_sym<'a, V: Visitor<'a>>(visitor: &mut V, sym: &'a InlineAsmSym) { pub fn walk_inline_asm_sym<'a, V: Visitor<'a>>(visitor: &mut V, sym: &'a InlineAsmSym) {
if let Some(ref qself) = sym.qself { if let Some(qself) = &sym.qself {
visitor.visit_ty(&qself.ty); visitor.visit_ty(&qself.ty);
} }
visitor.visit_path(&sym.path, sym.id); visitor.visit_path(&sym.path, sym.id);
@ -769,18 +759,18 @@ pub fn walk_inline_asm_sym<'a, V: Visitor<'a>>(visitor: &mut V, sym: &'a InlineA
pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) { pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
walk_list!(visitor, visit_attribute, expression.attrs.iter()); walk_list!(visitor, visit_attribute, expression.attrs.iter());
match expression.kind { match &expression.kind {
ExprKind::Box(ref subexpression) => visitor.visit_expr(subexpression), ExprKind::Box(subexpression) => visitor.visit_expr(subexpression),
ExprKind::Array(ref subexpressions) => { ExprKind::Array(subexpressions) => {
walk_list!(visitor, visit_expr, subexpressions); walk_list!(visitor, visit_expr, subexpressions);
} }
ExprKind::ConstBlock(ref anon_const) => visitor.visit_anon_const(anon_const), ExprKind::ConstBlock(anon_const) => visitor.visit_anon_const(anon_const),
ExprKind::Repeat(ref element, ref count) => { ExprKind::Repeat(element, count) => {
visitor.visit_expr(element); visitor.visit_expr(element);
visitor.visit_anon_const(count) visitor.visit_anon_const(count)
} }
ExprKind::Struct(ref se) => { ExprKind::Struct(se) => {
if let Some(ref qself) = se.qself { if let Some(qself) = &se.qself {
visitor.visit_ty(&qself.ty); visitor.visit_ty(&qself.ty);
} }
visitor.visit_path(&se.path, expression.id); visitor.visit_path(&se.path, expression.id);
@ -791,124 +781,124 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
StructRest::None => {} StructRest::None => {}
} }
} }
ExprKind::Tup(ref subexpressions) => { ExprKind::Tup(subexpressions) => {
walk_list!(visitor, visit_expr, subexpressions); walk_list!(visitor, visit_expr, subexpressions);
} }
ExprKind::Call(ref callee_expression, ref arguments) => { ExprKind::Call(callee_expression, arguments) => {
visitor.visit_expr(callee_expression); visitor.visit_expr(callee_expression);
walk_list!(visitor, visit_expr, arguments); walk_list!(visitor, visit_expr, arguments);
} }
ExprKind::MethodCall(box MethodCall { ref seg, ref receiver, ref args, span: _ }) => { ExprKind::MethodCall(box MethodCall { seg, receiver, args, span: _ }) => {
visitor.visit_path_segment(seg); visitor.visit_path_segment(seg);
visitor.visit_expr(receiver); visitor.visit_expr(receiver);
walk_list!(visitor, visit_expr, args); walk_list!(visitor, visit_expr, args);
} }
ExprKind::Binary(_, ref left_expression, ref right_expression) => { ExprKind::Binary(_, left_expression, right_expression) => {
visitor.visit_expr(left_expression); visitor.visit_expr(left_expression);
visitor.visit_expr(right_expression) visitor.visit_expr(right_expression)
} }
ExprKind::AddrOf(_, _, ref subexpression) | ExprKind::Unary(_, ref subexpression) => { ExprKind::AddrOf(_, _, subexpression) | ExprKind::Unary(_, subexpression) => {
visitor.visit_expr(subexpression) visitor.visit_expr(subexpression)
} }
ExprKind::Cast(ref subexpression, ref typ) | ExprKind::Type(ref subexpression, ref typ) => { ExprKind::Cast(subexpression, typ) | ExprKind::Type(subexpression, typ) => {
visitor.visit_expr(subexpression); visitor.visit_expr(subexpression);
visitor.visit_ty(typ) visitor.visit_ty(typ)
} }
ExprKind::Let(ref pat, ref expr, _) => { ExprKind::Let(pat, expr, _) => {
visitor.visit_pat(pat); visitor.visit_pat(pat);
visitor.visit_expr(expr); visitor.visit_expr(expr);
} }
ExprKind::If(ref head_expression, ref if_block, ref optional_else) => { ExprKind::If(head_expression, if_block, optional_else) => {
visitor.visit_expr(head_expression); visitor.visit_expr(head_expression);
visitor.visit_block(if_block); visitor.visit_block(if_block);
walk_list!(visitor, visit_expr, optional_else); walk_list!(visitor, visit_expr, optional_else);
} }
ExprKind::While(ref subexpression, ref block, ref opt_label) => { ExprKind::While(subexpression, block, opt_label) => {
walk_list!(visitor, visit_label, opt_label); walk_list!(visitor, visit_label, opt_label);
visitor.visit_expr(subexpression); visitor.visit_expr(subexpression);
visitor.visit_block(block); visitor.visit_block(block);
} }
ExprKind::ForLoop(ref pattern, ref subexpression, ref block, ref opt_label) => { ExprKind::ForLoop(pattern, subexpression, block, opt_label) => {
walk_list!(visitor, visit_label, opt_label); walk_list!(visitor, visit_label, opt_label);
visitor.visit_pat(pattern); visitor.visit_pat(pattern);
visitor.visit_expr(subexpression); visitor.visit_expr(subexpression);
visitor.visit_block(block); visitor.visit_block(block);
} }
ExprKind::Loop(ref block, ref opt_label) => { ExprKind::Loop(block, opt_label) => {
walk_list!(visitor, visit_label, opt_label); walk_list!(visitor, visit_label, opt_label);
visitor.visit_block(block); visitor.visit_block(block);
} }
ExprKind::Match(ref subexpression, ref arms) => { ExprKind::Match(subexpression, arms) => {
visitor.visit_expr(subexpression); visitor.visit_expr(subexpression);
walk_list!(visitor, visit_arm, arms); walk_list!(visitor, visit_arm, arms);
} }
ExprKind::Closure(box Closure { ExprKind::Closure(box Closure {
ref binder, binder,
capture_clause: _, capture_clause: _,
asyncness: _, asyncness: _,
movability: _, movability: _,
ref fn_decl, fn_decl,
ref body, body,
fn_decl_span: _, fn_decl_span: _,
}) => { }) => {
visitor.visit_fn(FnKind::Closure(binder, fn_decl, body), expression.span, expression.id) visitor.visit_fn(FnKind::Closure(binder, fn_decl, body), expression.span, expression.id)
} }
ExprKind::Block(ref block, ref opt_label) => { ExprKind::Block(block, opt_label) => {
walk_list!(visitor, visit_label, opt_label); walk_list!(visitor, visit_label, opt_label);
visitor.visit_block(block); visitor.visit_block(block);
} }
ExprKind::Async(_, _, ref body) => { ExprKind::Async(_, _, body) => {
visitor.visit_block(body); visitor.visit_block(body);
} }
ExprKind::Await(ref expr) => visitor.visit_expr(expr), ExprKind::Await(expr) => visitor.visit_expr(expr),
ExprKind::Assign(ref lhs, ref rhs, _) => { ExprKind::Assign(lhs, rhs, _) => {
visitor.visit_expr(lhs); visitor.visit_expr(lhs);
visitor.visit_expr(rhs); visitor.visit_expr(rhs);
} }
ExprKind::AssignOp(_, ref left_expression, ref right_expression) => { ExprKind::AssignOp(_, left_expression, right_expression) => {
visitor.visit_expr(left_expression); visitor.visit_expr(left_expression);
visitor.visit_expr(right_expression); visitor.visit_expr(right_expression);
} }
ExprKind::Field(ref subexpression, ident) => { ExprKind::Field(subexpression, ident) => {
visitor.visit_expr(subexpression); visitor.visit_expr(subexpression);
visitor.visit_ident(ident); visitor.visit_ident(*ident);
} }
ExprKind::Index(ref main_expression, ref index_expression) => { ExprKind::Index(main_expression, index_expression) => {
visitor.visit_expr(main_expression); visitor.visit_expr(main_expression);
visitor.visit_expr(index_expression) visitor.visit_expr(index_expression)
} }
ExprKind::Range(ref start, ref end, _) => { ExprKind::Range(start, end, _) => {
walk_list!(visitor, visit_expr, start); walk_list!(visitor, visit_expr, start);
walk_list!(visitor, visit_expr, end); walk_list!(visitor, visit_expr, end);
} }
ExprKind::Underscore => {} ExprKind::Underscore => {}
ExprKind::Path(ref maybe_qself, ref path) => { ExprKind::Path(maybe_qself, path) => {
if let Some(ref qself) = *maybe_qself { if let Some(qself) = maybe_qself {
visitor.visit_ty(&qself.ty); visitor.visit_ty(&qself.ty);
} }
visitor.visit_path(path, expression.id) visitor.visit_path(path, expression.id)
} }
ExprKind::Break(ref opt_label, ref opt_expr) => { ExprKind::Break(opt_label, opt_expr) => {
walk_list!(visitor, visit_label, opt_label); walk_list!(visitor, visit_label, opt_label);
walk_list!(visitor, visit_expr, opt_expr); walk_list!(visitor, visit_expr, opt_expr);
} }
ExprKind::Continue(ref opt_label) => { ExprKind::Continue(opt_label) => {
walk_list!(visitor, visit_label, opt_label); walk_list!(visitor, visit_label, opt_label);
} }
ExprKind::Ret(ref optional_expression) => { ExprKind::Ret(optional_expression) => {
walk_list!(visitor, visit_expr, optional_expression); walk_list!(visitor, visit_expr, optional_expression);
} }
ExprKind::Yeet(ref optional_expression) => { ExprKind::Yeet(optional_expression) => {
walk_list!(visitor, visit_expr, optional_expression); walk_list!(visitor, visit_expr, optional_expression);
} }
ExprKind::MacCall(ref mac) => visitor.visit_mac_call(mac), ExprKind::MacCall(mac) => visitor.visit_mac_call(mac),
ExprKind::Paren(ref subexpression) => visitor.visit_expr(subexpression), ExprKind::Paren(subexpression) => visitor.visit_expr(subexpression),
ExprKind::InlineAsm(ref asm) => visitor.visit_inline_asm(asm), ExprKind::InlineAsm(asm) => visitor.visit_inline_asm(asm),
ExprKind::Yield(ref optional_expression) => { ExprKind::Yield(optional_expression) => {
walk_list!(visitor, visit_expr, optional_expression); walk_list!(visitor, visit_expr, optional_expression);
} }
ExprKind::Try(ref subexpression) => visitor.visit_expr(subexpression), ExprKind::Try(subexpression) => visitor.visit_expr(subexpression),
ExprKind::TryBlock(ref body) => visitor.visit_block(body), ExprKind::TryBlock(body) => visitor.visit_block(body),
ExprKind::Lit(_) | ExprKind::IncludedBytes(..) | ExprKind::Err => {} ExprKind::Lit(_) | ExprKind::IncludedBytes(..) | ExprKind::Err => {}
} }
@ -935,8 +925,8 @@ pub fn walk_vis<'a, V: Visitor<'a>>(visitor: &mut V, vis: &'a Visibility) {
} }
pub fn walk_attribute<'a, V: Visitor<'a>>(visitor: &mut V, attr: &'a Attribute) { pub fn walk_attribute<'a, V: Visitor<'a>>(visitor: &mut V, attr: &'a Attribute) {
match attr.kind { match &attr.kind {
AttrKind::Normal(ref normal) => walk_mac_args(visitor, &normal.item.args), AttrKind::Normal(normal) => walk_mac_args(visitor, &normal.item.args),
AttrKind::DocComment(..) => {} AttrKind::DocComment(..) => {}
} }
} }

View file

@ -448,7 +448,8 @@ impl<'a> TraitDef<'a> {
_ => unreachable!(), _ => unreachable!(),
}; };
let container_id = cx.current_expansion.id.expn_data().parent.expect_local(); let container_id = cx.current_expansion.id.expn_data().parent.expect_local();
let always_copy = has_no_type_params && cx.resolver.has_derive_copy(container_id); let copy_fields =
is_packed && has_no_type_params && cx.resolver.has_derive_copy(container_id);
let newitem = match item.kind { let newitem = match item.kind {
ast::ItemKind::Struct(ref struct_def, ref generics) => self.expand_struct_def( ast::ItemKind::Struct(ref struct_def, ref generics) => self.expand_struct_def(
@ -457,16 +458,14 @@ impl<'a> TraitDef<'a> {
item.ident, item.ident,
generics, generics,
from_scratch, from_scratch,
is_packed, copy_fields,
always_copy,
), ),
ast::ItemKind::Enum(ref enum_def, ref generics) => { ast::ItemKind::Enum(ref enum_def, ref generics) => {
// We ignore `is_packed`/`always_copy` here, because // We ignore `is_packed` here, because `repr(packed)`
// `repr(packed)` enums cause an error later on. // enums cause an error later on.
// //
// This can only cause further compilation errors // This can only cause further compilation errors
// downstream in blatantly illegal code, so it // downstream in blatantly illegal code, so it is fine.
// is fine.
self.expand_enum_def(cx, enum_def, item.ident, generics, from_scratch) self.expand_enum_def(cx, enum_def, item.ident, generics, from_scratch)
} }
ast::ItemKind::Union(ref struct_def, ref generics) => { ast::ItemKind::Union(ref struct_def, ref generics) => {
@ -477,8 +476,7 @@ impl<'a> TraitDef<'a> {
item.ident, item.ident,
generics, generics,
from_scratch, from_scratch,
is_packed, copy_fields,
always_copy,
) )
} else { } else {
cx.span_err(mitem.span, "this trait cannot be derived for unions"); cx.span_err(mitem.span, "this trait cannot be derived for unions");
@ -748,8 +746,7 @@ impl<'a> TraitDef<'a> {
type_ident: Ident, type_ident: Ident,
generics: &Generics, generics: &Generics,
from_scratch: bool, from_scratch: bool,
is_packed: bool, copy_fields: bool,
always_copy: bool,
) -> P<ast::Item> { ) -> P<ast::Item> {
let field_tys: Vec<P<ast::Ty>> = let field_tys: Vec<P<ast::Ty>> =
struct_def.fields().iter().map(|field| field.ty.clone()).collect(); struct_def.fields().iter().map(|field| field.ty.clone()).collect();
@ -777,8 +774,7 @@ impl<'a> TraitDef<'a> {
type_ident, type_ident,
&selflike_args, &selflike_args,
&nonselflike_args, &nonselflike_args,
is_packed, copy_fields,
always_copy,
) )
}; };
@ -1016,19 +1012,9 @@ impl<'a> MethodDef<'a> {
/// } /// }
/// } /// }
/// ``` /// ```
/// If the struct doesn't impl `Copy`, we use let-destructuring with `ref`: /// If the struct doesn't impl `Copy`, we use the normal `&self.x`. This
/// ``` /// only works if the fields match the alignment required by the
/// # struct A { x: u8, y: u8 } /// `packed(N)` attribute. (We'll get errors later on if not.)
/// impl PartialEq for A {
/// fn eq(&self, other: &A) -> bool {
/// let Self { x: ref __self_0_0, y: ref __self_0_1 } = *self;
/// let Self { x: ref __self_1_0, y: ref __self_1_1 } = *other;
/// *__self_0_0 == *__self_1_0 && *__self_0_1 == *__self_1_1
/// }
/// }
/// ```
/// This latter case only works if the fields match the alignment required
/// by the `packed(N)` attribute. (We'll get errors later on if not.)
fn expand_struct_method_body<'b>( fn expand_struct_method_body<'b>(
&self, &self,
cx: &mut ExtCtxt<'_>, cx: &mut ExtCtxt<'_>,
@ -1037,51 +1023,19 @@ impl<'a> MethodDef<'a> {
type_ident: Ident, type_ident: Ident,
selflike_args: &[P<Expr>], selflike_args: &[P<Expr>],
nonselflike_args: &[P<Expr>], nonselflike_args: &[P<Expr>],
is_packed: bool, copy_fields: bool,
always_copy: bool,
) -> BlockOrExpr { ) -> BlockOrExpr {
let span = trait_.span;
assert!(selflike_args.len() == 1 || selflike_args.len() == 2); assert!(selflike_args.len() == 1 || selflike_args.len() == 2);
let mk_body = |cx, selflike_fields| { let selflike_fields =
self.call_substructure_method( trait_.create_struct_field_access_fields(cx, selflike_args, struct_def, copy_fields);
cx, self.call_substructure_method(
trait_, cx,
type_ident, trait_,
nonselflike_args, type_ident,
&Struct(struct_def, selflike_fields), nonselflike_args,
) &Struct(struct_def, selflike_fields),
}; )
if !is_packed {
let selflike_fields =
trait_.create_struct_field_access_fields(cx, selflike_args, struct_def, false);
mk_body(cx, selflike_fields)
} else if always_copy {
let selflike_fields =
trait_.create_struct_field_access_fields(cx, selflike_args, struct_def, true);
mk_body(cx, selflike_fields)
} else {
// Packed and not copy. Need to use ref patterns.
let prefixes: Vec<_> =
(0..selflike_args.len()).map(|i| format!("__self_{}", i)).collect();
let selflike_fields = trait_.create_struct_pattern_fields(cx, struct_def, &prefixes);
let mut body = mk_body(cx, selflike_fields);
let struct_path = cx.path(span, vec![Ident::new(kw::SelfUpper, type_ident.span)]);
let patterns =
trait_.create_struct_patterns(cx, struct_path, struct_def, &prefixes, ByRef::Yes);
// Do the let-destructuring.
let mut stmts: Vec<_> = iter::zip(selflike_args, patterns)
.map(|(selflike_arg_expr, pat)| {
let selflike_arg_expr = cx.expr_deref(span, selflike_arg_expr.clone());
cx.stmt_let_pat(span, pat, selflike_arg_expr)
})
.collect();
stmts.extend(std::mem::take(&mut body.0));
BlockOrExpr(stmts, body.1)
}
} }
fn expand_static_struct_method_body( fn expand_static_struct_method_body(
@ -1531,7 +1485,7 @@ impl<'a> TraitDef<'a> {
cx: &mut ExtCtxt<'_>, cx: &mut ExtCtxt<'_>,
selflike_args: &[P<Expr>], selflike_args: &[P<Expr>],
struct_def: &'a VariantData, struct_def: &'a VariantData,
copy: bool, copy_fields: bool,
) -> Vec<FieldInfo> { ) -> Vec<FieldInfo> {
self.create_fields(struct_def, |i, struct_field, sp| { self.create_fields(struct_def, |i, struct_field, sp| {
selflike_args selflike_args
@ -1550,7 +1504,7 @@ impl<'a> TraitDef<'a> {
}), }),
), ),
); );
if copy { if copy_fields {
field_expr = cx.expr_block( field_expr = cx.expr_block(
cx.block(struct_field.span, vec![cx.stmt_expr(field_expr)]), cx.block(struct_field.span, vec![cx.stmt_expr(field_expr)]),
); );

View file

@ -38,22 +38,8 @@ impl ConstantCx {
pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool { pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool {
let mut all_constants_ok = true; let mut all_constants_ok = true;
for constant in &fx.mir.required_consts { for constant in &fx.mir.required_consts {
let unevaluated = match fx.monomorphize(constant.literal) { if eval_mir_constant(fx, constant).is_none() {
ConstantKind::Ty(_) => unreachable!(),
ConstantKind::Unevaluated(uv, _) => uv,
ConstantKind::Val(..) => continue,
};
if let Err(err) = fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None) {
all_constants_ok = false; all_constants_ok = false;
match err {
ErrorHandled::Reported(_) => {
fx.tcx.sess.span_err(constant.span, "erroneous constant encountered");
}
ErrorHandled::TooGeneric => {
span_bug!(constant.span, "codegen encountered polymorphic constant: {:?}", err);
}
}
} }
} }
all_constants_ok all_constants_ok
@ -80,15 +66,15 @@ pub(crate) fn codegen_tls_ref<'tcx>(
} }
pub(crate) fn eval_mir_constant<'tcx>( pub(crate) fn eval_mir_constant<'tcx>(
fx: &mut FunctionCx<'_, '_, 'tcx>, fx: &FunctionCx<'_, '_, 'tcx>,
constant: &Constant<'tcx>, constant: &Constant<'tcx>,
) -> (ConstValue<'tcx>, Ty<'tcx>) { ) -> Option<(ConstValue<'tcx>, Ty<'tcx>)> {
let constant_kind = fx.monomorphize(constant.literal); let constant_kind = fx.monomorphize(constant.literal);
let uv = match constant_kind { let uv = match constant_kind {
ConstantKind::Ty(const_) => match const_.kind() { ConstantKind::Ty(const_) => match const_.kind() {
ty::ConstKind::Unevaluated(uv) => uv.expand(), ty::ConstKind::Unevaluated(uv) => uv.expand(),
ty::ConstKind::Value(val) => { ty::ConstKind::Value(val) => {
return (fx.tcx.valtree_to_const_val((const_.ty(), val)), const_.ty()); return Some((fx.tcx.valtree_to_const_val((const_.ty(), val)), const_.ty()));
} }
err => span_bug!( err => span_bug!(
constant.span, constant.span,
@ -102,22 +88,31 @@ pub(crate) fn eval_mir_constant<'tcx>(
span_bug!(constant.span, "MIR constant refers to static"); span_bug!(constant.span, "MIR constant refers to static");
} }
ConstantKind::Unevaluated(uv, _) => uv, ConstantKind::Unevaluated(uv, _) => uv,
ConstantKind::Val(val, _) => return (val, constant_kind.ty()), ConstantKind::Val(val, _) => return Some((val, constant_kind.ty())),
}; };
( let val = fx
fx.tcx.const_eval_resolve(ty::ParamEnv::reveal_all(), uv, None).unwrap_or_else(|_err| { .tcx
span_bug!(constant.span, "erroneous constant not captured by required_consts"); .const_eval_resolve(ty::ParamEnv::reveal_all(), uv, None)
}), .map_err(|err| match err {
constant_kind.ty(), ErrorHandled::Reported(_) => {
) fx.tcx.sess.span_err(constant.span, "erroneous constant encountered");
}
ErrorHandled::TooGeneric => {
span_bug!(constant.span, "codegen encountered polymorphic constant: {:?}", err);
}
})
.ok();
val.map(|val| (val, constant_kind.ty()))
} }
pub(crate) fn codegen_constant_operand<'tcx>( pub(crate) fn codegen_constant_operand<'tcx>(
fx: &mut FunctionCx<'_, '_, 'tcx>, fx: &mut FunctionCx<'_, '_, 'tcx>,
constant: &Constant<'tcx>, constant: &Constant<'tcx>,
) -> CValue<'tcx> { ) -> CValue<'tcx> {
let (const_val, ty) = eval_mir_constant(fx, constant); let (const_val, ty) = eval_mir_constant(fx, constant).unwrap_or_else(|| {
span_bug!(constant.span, "erroneous constant not captured by required_consts")
});
codegen_const_value(fx, const_val, ty) codegen_const_value(fx, const_val, ty)
} }
@ -453,20 +448,13 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
assert!(cx.todo.is_empty(), "{:?}", cx.todo); assert!(cx.todo.is_empty(), "{:?}", cx.todo);
} }
/// Used only for intrinsic implementations that need a compile-time constant
pub(crate) fn mir_operand_get_const_val<'tcx>( pub(crate) fn mir_operand_get_const_val<'tcx>(
fx: &FunctionCx<'_, '_, 'tcx>, fx: &FunctionCx<'_, '_, 'tcx>,
operand: &Operand<'tcx>, operand: &Operand<'tcx>,
) -> Option<ConstValue<'tcx>> { ) -> Option<ConstValue<'tcx>> {
match operand { match operand {
Operand::Constant(const_) => match fx.monomorphize(const_.literal) { Operand::Constant(const_) => Some(eval_mir_constant(fx, const_).unwrap().0),
ConstantKind::Ty(const_) => Some(
const_.eval_for_mir(fx.tcx, ParamEnv::reveal_all()).try_to_value(fx.tcx).unwrap(),
),
ConstantKind::Val(val, _) => Some(val),
ConstantKind::Unevaluated(uv, _) => {
Some(fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), uv, None).unwrap())
}
},
// FIXME(rust-lang/rust#85105): Casts like `IMM8 as u32` result in the const being stored // FIXME(rust-lang/rust#85105): Casts like `IMM8 as u32` result in the const being stored
// inside a temporary before being passed to the intrinsic requiring the const argument. // inside a temporary before being passed to the intrinsic requiring the const argument.
// This code tries to find a single constant defining definition of the referenced local. // This code tries to find a single constant defining definition of the referenced local.

View file

@ -83,7 +83,20 @@ pub fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) ->
let llfn = if tcx.sess.target.arch == "x86" && let llfn = if tcx.sess.target.arch == "x86" &&
let Some(dllimport) = common::get_dllimport(tcx, instance_def_id, sym) let Some(dllimport) = common::get_dllimport(tcx, instance_def_id, sym)
{ {
cx.declare_fn(&common::i686_decorated_name(&dllimport, common::is_mingw_gnu_toolchain(&tcx.sess.target), true), fn_abi) // Fix for https://github.com/rust-lang/rust/issues/104453
// On x86 Windows, LLVM uses 'L' as the prefix for any private
// global symbols, so when we create an undecorated function symbol
// that begins with an 'L' LLVM misinterprets that as a private
// global symbol that it created and so fails the compilation at a
// later stage since such a symbol must have a definition.
//
// To avoid this, we set the Storage Class to "DllImport" so that
// LLVM will prefix the name with `__imp_`. Ideally, we'd like the
// existing logic below to set the Storage Class, but it has an
// exemption for MinGW for backwards compatability.
let llfn = cx.declare_fn(&common::i686_decorated_name(&dllimport, common::is_mingw_gnu_toolchain(&tcx.sess.target), true), fn_abi);
unsafe { llvm::LLVMSetDLLStorageClass(llfn, llvm::DLLStorageClass::DllImport); }
llfn
} else { } else {
cx.declare_fn(sym, fn_abi) cx.declare_fn(sym, fn_abi)
}; };

View file

@ -42,7 +42,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}; };
self.cx.tcx().const_eval_resolve(ty::ParamEnv::reveal_all(), uv, None).map_err(|err| { self.cx.tcx().const_eval_resolve(ty::ParamEnv::reveal_all(), uv, None).map_err(|err| {
self.cx.tcx().sess.span_err(constant.span, "erroneous constant encountered"); match err {
ErrorHandled::Reported(_) => {
self.cx.tcx().sess.span_err(constant.span, "erroneous constant encountered");
}
ErrorHandled::TooGeneric => {
span_bug!(constant.span, "codegen encountered polymorphic constant: {:?}", err);
}
}
err err
}) })
} }

View file

@ -74,7 +74,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
fn print_dyn_existential( fn print_dyn_existential(
self, self,
predicates: &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>, predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
) -> Result<Self::DynExistential, Self::Error> { ) -> Result<Self::DynExistential, Self::Error> {
self.pretty_print_dyn_existential(predicates) self.pretty_print_dyn_existential(predicates)
} }

View file

@ -3000,7 +3000,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
fn compute_object_lifetime_bound( fn compute_object_lifetime_bound(
&self, &self,
span: Span, span: Span,
existential_predicates: &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>, existential_predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
) -> Option<ty::Region<'tcx>> // if None, use the default ) -> Option<ty::Region<'tcx>> // if None, use the default
{ {
let tcx = self.tcx(); let tcx = self.tcx();

View file

@ -748,7 +748,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
&self, &self,
a: Ty<'tcx>, a: Ty<'tcx>,
b: Ty<'tcx>, b: Ty<'tcx>,
predicates: &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>, predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
b_region: ty::Region<'tcx>, b_region: ty::Region<'tcx>,
) -> CoerceResult<'tcx> { ) -> CoerceResult<'tcx> {
if !self.tcx.features().dyn_star { if !self.tcx.features().dyn_star {

View file

@ -543,7 +543,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
fn print_dyn_existential( fn print_dyn_existential(
self, self,
_predicates: &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>, _predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
) -> Result<Self::DynExistential, Self::Error> { ) -> Result<Self::DynExistential, Self::Error> {
Err(NonTrivialPath) Err(NonTrivialPath)
} }

View file

@ -1159,7 +1159,7 @@ impl<'tcx> LateContext<'tcx> {
fn print_dyn_existential( fn print_dyn_existential(
self, self,
_predicates: &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>, _predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
) -> Result<Self::DynExistential, Self::Error> { ) -> Result<Self::DynExistential, Self::Error> {
Ok(()) Ok(())
} }

View file

@ -298,7 +298,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for ty::List<Ty
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D>
for ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>> for ty::List<ty::PolyExistentialPredicate<'tcx>>
{ {
fn decode(decoder: &mut D) -> &'tcx Self { fn decode(decoder: &mut D) -> &'tcx Self {
let len = decoder.read_usize(); let len = decoder.read_usize();
@ -379,7 +379,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D>
impl_decodable_via_ref! { impl_decodable_via_ref! {
&'tcx ty::TypeckResults<'tcx>, &'tcx ty::TypeckResults<'tcx>,
&'tcx ty::List<Ty<'tcx>>, &'tcx ty::List<Ty<'tcx>>,
&'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>, &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
&'tcx traits::ImplSource<'tcx, ()>, &'tcx traits::ImplSource<'tcx, ()>,
&'tcx mir::Body<'tcx>, &'tcx mir::Body<'tcx>,
&'tcx mir::UnsafetyCheckResult, &'tcx mir::UnsafetyCheckResult,

View file

@ -1,5 +1,4 @@
use crate::mir::interpret::LitToConstInput; use crate::mir::interpret::LitToConstInput;
use crate::mir::ConstantKind;
use crate::ty::{self, DefIdTree, InternalSubsts, ParamEnv, ParamEnvAnd, Ty, TyCtxt}; use crate::ty::{self, DefIdTree, InternalSubsts, ParamEnv, ParamEnvAnd, Ty, TyCtxt};
use rustc_data_structures::intern::Interned; use rustc_data_structures::intern::Interned;
use rustc_hir as hir; use rustc_hir as hir;
@ -230,20 +229,6 @@ impl<'tcx> Const<'tcx> {
} }
} }
#[inline]
/// Tries to evaluate the constant if it is `Unevaluated` and creates a ConstValue if the
/// evaluation succeeds. If it doesn't succeed, returns the unevaluated constant.
pub fn eval_for_mir(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> ConstantKind<'tcx> {
if let Some(val) = self.kind().try_eval_for_mir(tcx, param_env) {
match val {
Ok(const_val) => ConstantKind::from_value(const_val, self.ty()),
Err(guar) => ConstantKind::Ty(tcx.const_error_with_guaranteed(self.ty(), guar)),
}
} else {
ConstantKind::Ty(self)
}
}
#[inline] #[inline]
/// Panics if the value cannot be evaluated or doesn't contain a valid integer of the given type. /// Panics if the value cannot be evaluated or doesn't contain a valid integer of the given type.
pub fn eval_bits(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: Ty<'tcx>) -> u128 { pub fn eval_bits(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: Ty<'tcx>) -> u128 {

View file

@ -17,11 +17,11 @@ use crate::traits;
use crate::ty::query::{self, TyCtxtAt}; use crate::ty::query::{self, TyCtxtAt};
use crate::ty::{ use crate::ty::{
self, AdtDef, AdtDefData, AdtKind, Binder, BindingMode, BoundVar, CanonicalPolyFnSig, self, AdtDef, AdtDefData, AdtKind, Binder, BindingMode, BoundVar, CanonicalPolyFnSig,
ClosureSizeProfileData, Const, ConstS, ConstVid, DefIdTree, ExistentialPredicate, FloatTy, ClosureSizeProfileData, Const, ConstS, ConstVid, DefIdTree, FloatTy, FloatVar, FloatVid,
FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy, IntTy, IntVar, IntVid, List, GenericParamDefKind, InferConst, InferTy, IntTy, IntVar, IntVid, List, ParamConst, ParamTy,
ParamConst, ParamTy, PolyFnSig, Predicate, PredicateKind, PredicateS, ProjectionTy, Region, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind, PredicateS, ProjectionTy,
RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut, UintTy, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut,
Visibility, UintTy, Visibility,
}; };
use crate::ty::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef, UserSubsts}; use crate::ty::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef, UserSubsts};
use rustc_ast as ast; use rustc_ast as ast;
@ -109,7 +109,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
type Mutability = hir::Mutability; type Mutability = hir::Mutability;
type Movability = hir::Movability; type Movability = hir::Movability;
type PolyFnSig = PolyFnSig<'tcx>; type PolyFnSig = PolyFnSig<'tcx>;
type ListBinderExistentialPredicate = &'tcx List<Binder<'tcx, ExistentialPredicate<'tcx>>>; type ListBinderExistentialPredicate = &'tcx List<PolyExistentialPredicate<'tcx>>;
type BinderListTy = Binder<'tcx, &'tcx List<Ty<'tcx>>>; type BinderListTy = Binder<'tcx, &'tcx List<Ty<'tcx>>>;
type ListTy = &'tcx List<Ty<'tcx>>; type ListTy = &'tcx List<Ty<'tcx>>;
type ProjectionTy = ty::ProjectionTy<'tcx>; type ProjectionTy = ty::ProjectionTy<'tcx>;
@ -140,8 +140,7 @@ pub struct CtxtInterners<'tcx> {
substs: InternedSet<'tcx, InternalSubsts<'tcx>>, substs: InternedSet<'tcx, InternalSubsts<'tcx>>,
canonical_var_infos: InternedSet<'tcx, List<CanonicalVarInfo<'tcx>>>, canonical_var_infos: InternedSet<'tcx, List<CanonicalVarInfo<'tcx>>>,
region: InternedSet<'tcx, RegionKind<'tcx>>, region: InternedSet<'tcx, RegionKind<'tcx>>,
poly_existential_predicates: poly_existential_predicates: InternedSet<'tcx, List<PolyExistentialPredicate<'tcx>>>,
InternedSet<'tcx, List<ty::Binder<'tcx, ExistentialPredicate<'tcx>>>>,
predicate: InternedSet<'tcx, PredicateS<'tcx>>, predicate: InternedSet<'tcx, PredicateS<'tcx>>,
predicates: InternedSet<'tcx, List<Predicate<'tcx>>>, predicates: InternedSet<'tcx, List<Predicate<'tcx>>>,
projs: InternedSet<'tcx, List<ProjectionKind>>, projs: InternedSet<'tcx, List<ProjectionKind>>,
@ -1810,7 +1809,7 @@ nop_lift! {const_; Const<'a> => Const<'tcx>}
nop_lift! {const_allocation; ConstAllocation<'a> => ConstAllocation<'tcx>} nop_lift! {const_allocation; ConstAllocation<'a> => ConstAllocation<'tcx>}
nop_lift! {predicate; Predicate<'a> => Predicate<'tcx>} nop_lift! {predicate; Predicate<'a> => Predicate<'tcx>}
nop_list_lift! {poly_existential_predicates; ty::Binder<'a, ExistentialPredicate<'a>> => ty::Binder<'tcx, ExistentialPredicate<'tcx>>} nop_list_lift! {poly_existential_predicates; PolyExistentialPredicate<'a> => PolyExistentialPredicate<'tcx>}
nop_list_lift! {predicates; Predicate<'a> => Predicate<'tcx>} nop_list_lift! {predicates; Predicate<'a> => Predicate<'tcx>}
nop_list_lift! {canonical_var_infos; CanonicalVarInfo<'a> => CanonicalVarInfo<'tcx>} nop_list_lift! {canonical_var_infos; CanonicalVarInfo<'a> => CanonicalVarInfo<'tcx>}
nop_list_lift! {projs; ProjectionKind => ProjectionKind} nop_list_lift! {projs; ProjectionKind => ProjectionKind}
@ -2265,7 +2264,7 @@ slice_interners!(
substs: _intern_substs(GenericArg<'tcx>), substs: _intern_substs(GenericArg<'tcx>),
canonical_var_infos: _intern_canonical_var_infos(CanonicalVarInfo<'tcx>), canonical_var_infos: _intern_canonical_var_infos(CanonicalVarInfo<'tcx>),
poly_existential_predicates: poly_existential_predicates:
_intern_poly_existential_predicates(ty::Binder<'tcx, ExistentialPredicate<'tcx>>), _intern_poly_existential_predicates(PolyExistentialPredicate<'tcx>),
predicates: _intern_predicates(Predicate<'tcx>), predicates: _intern_predicates(Predicate<'tcx>),
projs: _intern_projs(ProjectionKind), projs: _intern_projs(ProjectionKind),
place_elems: _intern_place_elems(PlaceElem<'tcx>), place_elems: _intern_place_elems(PlaceElem<'tcx>),
@ -2544,7 +2543,7 @@ impl<'tcx> TyCtxt<'tcx> {
#[inline] #[inline]
pub fn mk_dynamic( pub fn mk_dynamic(
self, self,
obj: &'tcx List<ty::Binder<'tcx, ExistentialPredicate<'tcx>>>, obj: &'tcx List<PolyExistentialPredicate<'tcx>>,
reg: ty::Region<'tcx>, reg: ty::Region<'tcx>,
repr: DynKind, repr: DynKind,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
@ -2682,8 +2681,8 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn intern_poly_existential_predicates( pub fn intern_poly_existential_predicates(
self, self,
eps: &[ty::Binder<'tcx, ExistentialPredicate<'tcx>>], eps: &[PolyExistentialPredicate<'tcx>],
) -> &'tcx List<ty::Binder<'tcx, ExistentialPredicate<'tcx>>> { ) -> &'tcx List<PolyExistentialPredicate<'tcx>> {
assert!(!eps.is_empty()); assert!(!eps.is_empty());
assert!( assert!(
eps.array_windows() eps.array_windows()
@ -2767,10 +2766,7 @@ impl<'tcx> TyCtxt<'tcx> {
} }
pub fn mk_poly_existential_predicates< pub fn mk_poly_existential_predicates<
I: InternAs< I: InternAs<[PolyExistentialPredicate<'tcx>], &'tcx List<PolyExistentialPredicate<'tcx>>>,
[ty::Binder<'tcx, ExistentialPredicate<'tcx>>],
&'tcx List<ty::Binder<'tcx, ExistentialPredicate<'tcx>>>,
>,
>( >(
self, self,
iter: I, iter: I,

View file

@ -69,9 +69,7 @@ pub enum TypeError<'tcx> {
CyclicTy(Ty<'tcx>), CyclicTy(Ty<'tcx>),
CyclicConst(ty::Const<'tcx>), CyclicConst(ty::Const<'tcx>),
ProjectionMismatched(ExpectedFound<DefId>), ProjectionMismatched(ExpectedFound<DefId>),
ExistentialMismatch( ExistentialMismatch(ExpectedFound<&'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>>),
ExpectedFound<&'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>>,
),
ObjectUnsafeCoercion(DefId), ObjectUnsafeCoercion(DefId),
ConstMismatch(ExpectedFound<ty::Const<'tcx>>), ConstMismatch(ExpectedFound<ty::Const<'tcx>>),

View file

@ -94,9 +94,10 @@ pub use self::sty::{
BoundVariableKind, CanonicalPolyFnSig, ClosureSubsts, ClosureSubstsParts, ConstVid, BoundVariableKind, CanonicalPolyFnSig, ClosureSubsts, ClosureSubstsParts, ConstVid,
EarlyBoundRegion, ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FnSig, EarlyBoundRegion, ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FnSig,
FreeRegion, GenSig, GeneratorSubsts, GeneratorSubstsParts, InlineConstSubsts, FreeRegion, GenSig, GeneratorSubsts, GeneratorSubstsParts, InlineConstSubsts,
InlineConstSubstsParts, ParamConst, ParamTy, PolyExistentialProjection, InlineConstSubstsParts, ParamConst, ParamTy, PolyExistentialPredicate,
PolyExistentialTraitRef, PolyFnSig, PolyGenSig, PolyTraitRef, ProjectionTy, Region, RegionKind, PolyExistentialProjection, PolyExistentialTraitRef, PolyFnSig, PolyGenSig, PolyTraitRef,
RegionVid, TraitRef, TyKind, TypeAndMut, UpvarSubsts, VarianceDiagInfo, ProjectionTy, Region, RegionKind, RegionVid, TraitRef, TyKind, TypeAndMut, UpvarSubsts,
VarianceDiagInfo,
}; };
pub use self::trait_def::TraitDef; pub use self::trait_def::TraitDef;

View file

@ -63,7 +63,7 @@ pub trait Printer<'tcx>: Sized {
fn print_dyn_existential( fn print_dyn_existential(
self, self,
predicates: &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>, predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
) -> Result<Self::DynExistential, Self::Error>; ) -> Result<Self::DynExistential, Self::Error>;
fn print_const(self, ct: ty::Const<'tcx>) -> Result<Self::Const, Self::Error>; fn print_const(self, ct: ty::Const<'tcx>) -> Result<Self::Const, Self::Error>;
@ -308,9 +308,7 @@ impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for Ty<'tcx> {
} }
} }
impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>> {
for &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>
{
type Output = P::DynExistential; type Output = P::DynExistential;
type Error = P::Error; type Error = P::Error;
fn print(&self, cx: P) -> Result<Self::Output, Self::Error> { fn print(&self, cx: P) -> Result<Self::Output, Self::Error> {

View file

@ -1060,7 +1060,7 @@ pub trait PrettyPrinter<'tcx>:
fn pretty_print_dyn_existential( fn pretty_print_dyn_existential(
mut self, mut self,
predicates: &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>, predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
) -> Result<Self::DynExistential, Self::Error> { ) -> Result<Self::DynExistential, Self::Error> {
// Generate the main trait ref, including associated types. // Generate the main trait ref, including associated types.
let mut first = true; let mut first = true;
@ -1772,7 +1772,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
fn print_dyn_existential( fn print_dyn_existential(
self, self,
predicates: &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>, predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
) -> Result<Self::DynExistential, Self::Error> { ) -> Result<Self::DynExistential, Self::Error> {
self.pretty_print_dyn_existential(predicates) self.pretty_print_dyn_existential(predicates)
} }
@ -2530,12 +2530,12 @@ pub struct PrintClosureAsImpl<'tcx> {
forward_display_to_print! { forward_display_to_print! {
ty::Region<'tcx>, ty::Region<'tcx>,
Ty<'tcx>, Ty<'tcx>,
&'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>, &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
ty::Const<'tcx>, ty::Const<'tcx>,
// HACK(eddyb) these are exhaustive instead of generic, // HACK(eddyb) these are exhaustive instead of generic,
// because `for<'tcx>` isn't possible yet. // because `for<'tcx>` isn't possible yet.
ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>, ty::PolyExistentialPredicate<'tcx>,
ty::Binder<'tcx, ty::TraitRef<'tcx>>, ty::Binder<'tcx, ty::TraitRef<'tcx>>,
ty::Binder<'tcx, ty::ExistentialTraitRef<'tcx>>, ty::Binder<'tcx, ty::ExistentialTraitRef<'tcx>>,
ty::Binder<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>, ty::Binder<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,

View file

@ -658,7 +658,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
if is_match { Ok(a) } else { Err(TypeError::ConstMismatch(expected_found(relation, a, b))) } if is_match { Ok(a) } else { Err(TypeError::ConstMismatch(expected_found(relation, a, b))) }
} }
impl<'tcx> Relate<'tcx> for &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>> { impl<'tcx> Relate<'tcx> for &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>> {
fn relate<R: TypeRelation<'tcx>>( fn relate<R: TypeRelation<'tcx>>(
relation: &mut R, relation: &mut R,
a: Self, a: Self,

View file

@ -586,7 +586,7 @@ impl<'tcx, T: TypeVisitable<'tcx>> TypeSuperVisitable<'tcx> for ty::Binder<'tcx,
} }
} }
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>> { impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> { fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_poly_existential_predicates(v)) ty::util::fold_list(self, folder, |tcx, v| tcx.intern_poly_existential_predicates(v))
} }

View file

@ -703,7 +703,9 @@ impl<'tcx> ExistentialPredicate<'tcx> {
} }
} }
impl<'tcx> Binder<'tcx, ExistentialPredicate<'tcx>> { pub type PolyExistentialPredicate<'tcx> = Binder<'tcx, ExistentialPredicate<'tcx>>;
impl<'tcx> PolyExistentialPredicate<'tcx> {
/// Given an existential predicate like `?Self: PartialEq<u32>` (e.g., derived from `dyn PartialEq<u32>`), /// Given an existential predicate like `?Self: PartialEq<u32>` (e.g., derived from `dyn PartialEq<u32>`),
/// and a concrete type `self_ty`, returns a full predicate where the existentially quantified variable `?Self` /// and a concrete type `self_ty`, returns a full predicate where the existentially quantified variable `?Self`
/// has been replaced with `self_ty` (e.g., `self_ty: PartialEq<u32>`, in our example). /// has been replaced with `self_ty` (e.g., `self_ty: PartialEq<u32>`, in our example).
@ -727,7 +729,7 @@ impl<'tcx> Binder<'tcx, ExistentialPredicate<'tcx>> {
} }
} }
impl<'tcx> List<ty::Binder<'tcx, ExistentialPredicate<'tcx>>> { impl<'tcx> List<ty::PolyExistentialPredicate<'tcx>> {
/// Returns the "principal `DefId`" of this set of existential predicates. /// Returns the "principal `DefId`" of this set of existential predicates.
/// ///
/// A Rust trait object type consists (in addition to a lifetime bound) /// A Rust trait object type consists (in addition to a lifetime bound)

View file

@ -244,7 +244,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
fn print_dyn_existential( fn print_dyn_existential(
mut self, mut self,
predicates: &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>, predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
) -> Result<Self::DynExistential, Self::Error> { ) -> Result<Self::DynExistential, Self::Error> {
let mut first = true; let mut first = true;
for p in predicates { for p in predicates {

View file

@ -12,8 +12,8 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef};
use rustc_middle::ty::{ use rustc_middle::ty::{
self, Binder, Const, ExistentialPredicate, FloatTy, FnSig, IntTy, List, Region, RegionKind, self, Const, ExistentialPredicate, FloatTy, FnSig, IntTy, List, Region, RegionKind, TermKind,
TermKind, Ty, TyCtxt, UintTy, Ty, TyCtxt, UintTy,
}; };
use rustc_span::def_id::DefId; use rustc_span::def_id::DefId;
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
@ -226,7 +226,7 @@ fn encode_fnsig<'tcx>(
/// Rust types that are not used at the FFI boundary. /// Rust types that are not used at the FFI boundary.
fn encode_predicate<'tcx>( fn encode_predicate<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
predicate: Binder<'tcx, ExistentialPredicate<'tcx>>, predicate: ty::PolyExistentialPredicate<'tcx>,
dict: &mut FxHashMap<DictKey<'tcx>, usize>, dict: &mut FxHashMap<DictKey<'tcx>, usize>,
options: EncodeTyOptions, options: EncodeTyOptions,
) -> String { ) -> String {
@ -261,13 +261,13 @@ fn encode_predicate<'tcx>(
/// Rust types that are not used at the FFI boundary. /// Rust types that are not used at the FFI boundary.
fn encode_predicates<'tcx>( fn encode_predicates<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
predicates: &List<Binder<'tcx, ExistentialPredicate<'tcx>>>, predicates: &List<ty::PolyExistentialPredicate<'tcx>>,
dict: &mut FxHashMap<DictKey<'tcx>, usize>, dict: &mut FxHashMap<DictKey<'tcx>, usize>,
options: EncodeTyOptions, options: EncodeTyOptions,
) -> String { ) -> String {
// <predicate1[..predicateN]>E as part of vendor extended type // <predicate1[..predicateN]>E as part of vendor extended type
let mut s = String::new(); let mut s = String::new();
let predicates: Vec<Binder<'tcx, ExistentialPredicate<'tcx>>> = let predicates: Vec<ty::PolyExistentialPredicate<'tcx>> =
predicates.iter().map(|predicate| predicate).collect(); predicates.iter().map(|predicate| predicate).collect();
for predicate in predicates { for predicate in predicates {
s.push_str(&encode_predicate(tcx, predicate, dict, options)); s.push_str(&encode_predicate(tcx, predicate, dict, options));

View file

@ -502,7 +502,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
fn print_dyn_existential( fn print_dyn_existential(
mut self, mut self,
predicates: &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>, predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
) -> Result<Self::DynExistential, Self::Error> { ) -> Result<Self::DynExistential, Self::Error> {
// Okay, so this is a bit tricky. Imagine we have a trait object like // Okay, so this is a bit tricky. Imagine we have a trait object like
// `dyn for<'a> Foo<'a, Bar = &'a ()>`. When we mangle this, the // `dyn for<'a> Foo<'a, Bar = &'a ()>`. When we mangle this, the

View file

@ -758,7 +758,7 @@ impl<'tcx> WfPredicates<'tcx> {
fn from_object_ty( fn from_object_ty(
&mut self, &mut self,
ty: Ty<'tcx>, ty: Ty<'tcx>,
data: &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>, data: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
region: ty::Region<'tcx>, region: ty::Region<'tcx>,
) { ) {
// Imagine a type like this: // Imagine a type like this:
@ -822,7 +822,7 @@ impl<'tcx> WfPredicates<'tcx> {
/// `infer::required_region_bounds`, see that for more information. /// `infer::required_region_bounds`, see that for more information.
pub fn object_region_bounds<'tcx>( pub fn object_region_bounds<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
existential_predicates: &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>, existential_predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
) -> Vec<ty::Region<'tcx>> { ) -> Vec<ty::Region<'tcx>> {
// Since we don't actually *know* the self type for an object, // Since we don't actually *know* the self type for an object,
// this "open(err)" serves as a kind of dummy standin -- basically // this "open(err)" serves as a kind of dummy standin -- basically

View file

@ -634,7 +634,7 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
} }
impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<RustInterner<'tcx>>>> impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<RustInterner<'tcx>>>>
for &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>> for &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>
{ {
fn lower_into( fn lower_into(
self, self,

View file

@ -659,7 +659,7 @@ macro_rules! nonzero_signed_operations {
#[doc = concat!("let neg = ", stringify!($Ty), "::new(-1)?;")] #[doc = concat!("let neg = ", stringify!($Ty), "::new(-1)?;")]
#[doc = concat!("let min = ", stringify!($Ty), "::new(", #[doc = concat!("let min = ", stringify!($Ty), "::new(",
stringify!($Int), "::MIN)?;")] stringify!($Int), "::MIN)?;")]
#[doc = concat!("let max = ", stringify!($Ty), "::new(", #[doc = concat!("# let max = ", stringify!($Ty), "::new(",
stringify!($Int), "::MAX)?;")] stringify!($Int), "::MAX)?;")]
/// ///
/// assert_eq!(pos, pos.wrapping_abs()); /// assert_eq!(pos, pos.wrapping_abs());

View file

@ -47,8 +47,6 @@ fn cc2ar(cc: &Path, target: TargetSelection) -> Option<PathBuf> {
Some(PathBuf::from("ar")) Some(PathBuf::from("ar"))
} else if target.contains("vxworks") { } else if target.contains("vxworks") {
Some(PathBuf::from("wr-ar")) Some(PathBuf::from("wr-ar"))
} else if target.contains("android") {
Some(cc.parent().unwrap().join(PathBuf::from("llvm-ar")))
} else { } else {
let parent = cc.parent().unwrap(); let parent = cc.parent().unwrap();
let file = cc.file_name().unwrap().to_str().unwrap(); let file = cc.file_name().unwrap().to_str().unwrap();
@ -221,22 +219,12 @@ fn set_compiler(
} }
pub(crate) fn ndk_compiler(compiler: Language, triple: &str, ndk: &Path) -> PathBuf { pub(crate) fn ndk_compiler(compiler: Language, triple: &str, ndk: &Path) -> PathBuf {
let mut triple_iter = triple.split("-"); let triple_translated = triple
let triple_translated = if let Some(arch) = triple_iter.next() { .replace("armv7neon", "arm")
let arch_new = match arch { .replace("armv7", "arm")
"arm" | "armv7" | "armv7neon" | "thumbv7" | "thumbv7neon" => "armv7a", .replace("thumbv7neon", "arm")
other => other, .replace("thumbv7", "arm");
}; let compiler = format!("{}-{}", triple_translated, compiler.clang());
std::iter::once(arch_new).chain(triple_iter).collect::<Vec<&str>>().join("-")
} else {
triple.to_string()
};
// API 19 is the earliest API level supported by NDK r25b but AArch64 and x86_64 support
// begins at API level 21.
let api_level =
if triple.contains("aarch64") || triple.contains("x86_64") { "21" } else { "19" };
let compiler = format!("{}{}-{}", triple_translated, api_level, compiler.clang());
ndk.join("bin").join(compiler) ndk.join("bin").join(compiler)
} }

View file

@ -6,7 +6,7 @@ RUN sh /scripts/android-base-apt-get.sh
COPY scripts/android-ndk.sh /scripts/ COPY scripts/android-ndk.sh /scripts/
RUN . /scripts/android-ndk.sh && \ RUN . /scripts/android-ndk.sh && \
download_ndk android-ndk-r25b-linux.zip download_and_make_toolchain android-ndk-r15c-linux-x86_64.zip arm 14
RUN dpkg --add-architecture i386 && \ RUN dpkg --add-architecture i386 && \
apt-get update && \ apt-get update && \
@ -30,7 +30,7 @@ ENV PATH=$PATH:/android/sdk/platform-tools
ENV TARGETS=arm-linux-androideabi ENV TARGETS=arm-linux-androideabi
ENV RUST_CONFIGURE_ARGS --arm-linux-androideabi-ndk=/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/ ENV RUST_CONFIGURE_ARGS --arm-linux-androideabi-ndk=/android/ndk/arm-14
ENV SCRIPT python3 ../x.py --stage 2 test --host='' --target $TARGETS ENV SCRIPT python3 ../x.py --stage 2 test --host='' --target $TARGETS

View file

@ -6,7 +6,14 @@ RUN sh /scripts/android-base-apt-get.sh
# ndk # ndk
COPY scripts/android-ndk.sh /scripts/ COPY scripts/android-ndk.sh /scripts/
RUN . /scripts/android-ndk.sh && \ RUN . /scripts/android-ndk.sh && \
download_ndk android-ndk-r25b-linux.zip download_ndk android-ndk-r15c-linux-x86_64.zip && \
make_standalone_toolchain arm 14 && \
make_standalone_toolchain x86 14 && \
make_standalone_toolchain arm 21 && \
make_standalone_toolchain x86 21 && \
make_standalone_toolchain arm64 21 && \
make_standalone_toolchain x86_64 21 && \
remove_ndk
# env # env
ENV TARGETS=arm-linux-androideabi ENV TARGETS=arm-linux-androideabi
@ -19,12 +26,12 @@ ENV TARGETS=$TARGETS,x86_64-linux-android
ENV RUST_CONFIGURE_ARGS \ ENV RUST_CONFIGURE_ARGS \
--enable-extended \ --enable-extended \
--enable-profiler \ --enable-profiler \
--arm-linux-androideabi-ndk=/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/ \ --arm-linux-androideabi-ndk=/android/ndk/arm-14 \
--armv7-linux-androideabi-ndk=/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/ \ --armv7-linux-androideabi-ndk=/android/ndk/arm-14 \
--thumbv7neon-linux-androideabi-ndk=/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/ \ --thumbv7neon-linux-androideabi-ndk=/android/ndk/arm-14 \
--i686-linux-android-ndk=/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/ \ --i686-linux-android-ndk=/android/ndk/x86-14 \
--aarch64-linux-android-ndk=/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/ \ --aarch64-linux-android-ndk=/android/ndk/arm64-21 \
--x86_64-linux-android-ndk=/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/ \ --x86_64-linux-android-ndk=/android/ndk/x86_64-21 \
--disable-docs --disable-docs
ENV SCRIPT python3 ../x.py dist --host='' --target $TARGETS ENV SCRIPT python3 ../x.py dist --host='' --target $TARGETS

View file

@ -4,10 +4,28 @@ set -ex
URL=https://dl.google.com/android/repository URL=https://dl.google.com/android/repository
download_ndk() { download_ndk() {
mkdir /android/ mkdir -p /android/ndk
cd /android cd /android/ndk
curl -fO $URL/$1 curl -fO $URL/$1
unzip -q $1 unzip -q $1
rm $1 rm $1
mv android-ndk-* ndk mv android-ndk-* ndk
} }
make_standalone_toolchain() {
# See https://developer.android.com/ndk/guides/standalone_toolchain.htm
python3 /android/ndk/ndk/build/tools/make_standalone_toolchain.py \
--install-dir /android/ndk/$1-$2 \
--arch $1 \
--api $2
}
remove_ndk() {
rm -rf /android/ndk/ndk
}
download_and_make_toolchain() {
download_ndk $1 && \
make_standalone_toolchain $2 $3 && \
remove_ndk
}

View file

@ -257,12 +257,12 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
StructFieldItem(f) => ItemEnum::StructField(f.into_tcx(tcx)), StructFieldItem(f) => ItemEnum::StructField(f.into_tcx(tcx)),
EnumItem(e) => ItemEnum::Enum(e.into_tcx(tcx)), EnumItem(e) => ItemEnum::Enum(e.into_tcx(tcx)),
VariantItem(v) => ItemEnum::Variant(v.into_tcx(tcx)), VariantItem(v) => ItemEnum::Variant(v.into_tcx(tcx)),
FunctionItem(f) => ItemEnum::Function(from_function(f, header.unwrap(), tcx)), FunctionItem(f) => ItemEnum::Function(from_function(f, true, header.unwrap(), tcx)),
ForeignFunctionItem(f) => ItemEnum::Function(from_function(f, header.unwrap(), tcx)), ForeignFunctionItem(f) => ItemEnum::Function(from_function(f, false, header.unwrap(), tcx)),
TraitItem(t) => ItemEnum::Trait((*t).into_tcx(tcx)), TraitItem(t) => ItemEnum::Trait((*t).into_tcx(tcx)),
TraitAliasItem(t) => ItemEnum::TraitAlias(t.into_tcx(tcx)), TraitAliasItem(t) => ItemEnum::TraitAlias(t.into_tcx(tcx)),
MethodItem(m, _) => ItemEnum::Method(from_function_method(m, true, header.unwrap(), tcx)), MethodItem(m, _) => ItemEnum::Function(from_function(m, true, header.unwrap(), tcx)),
TyMethodItem(m) => ItemEnum::Method(from_function_method(m, false, header.unwrap(), tcx)), TyMethodItem(m) => ItemEnum::Function(from_function(m, false, header.unwrap(), tcx)),
ImplItem(i) => ItemEnum::Impl((*i).into_tcx(tcx)), ImplItem(i) => ItemEnum::Impl((*i).into_tcx(tcx)),
StaticItem(s) => ItemEnum::Static(s.into_tcx(tcx)), StaticItem(s) => ItemEnum::Static(s.into_tcx(tcx)),
ForeignStaticItem(s) => ItemEnum::Static(s.into_tcx(tcx)), ForeignStaticItem(s) => ItemEnum::Static(s.into_tcx(tcx)),
@ -618,6 +618,7 @@ impl FromWithTcx<clean::Impl> for Impl {
pub(crate) fn from_function( pub(crate) fn from_function(
function: Box<clean::Function>, function: Box<clean::Function>,
has_body: bool,
header: rustc_hir::FnHeader, header: rustc_hir::FnHeader,
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
) -> Function { ) -> Function {
@ -626,20 +627,6 @@ pub(crate) fn from_function(
decl: decl.into_tcx(tcx), decl: decl.into_tcx(tcx),
generics: generics.into_tcx(tcx), generics: generics.into_tcx(tcx),
header: from_fn_header(&header), header: from_fn_header(&header),
}
}
pub(crate) fn from_function_method(
function: Box<clean::Function>,
has_body: bool,
header: rustc_hir::FnHeader,
tcx: TyCtxt<'_>,
) -> Method {
let clean::Function { decl, generics } = *function;
Method {
decl: decl.into_tcx(tcx),
generics: generics.into_tcx(tcx),
header: from_fn_header(&header),
has_body, has_body,
} }
} }
@ -759,14 +746,13 @@ impl FromWithTcx<ItemType> for ItemKind {
Struct => ItemKind::Struct, Struct => ItemKind::Struct,
Union => ItemKind::Union, Union => ItemKind::Union,
Enum => ItemKind::Enum, Enum => ItemKind::Enum,
Function => ItemKind::Function, Function | TyMethod | Method => ItemKind::Function,
Typedef => ItemKind::Typedef, Typedef => ItemKind::Typedef,
OpaqueTy => ItemKind::OpaqueTy, OpaqueTy => ItemKind::OpaqueTy,
Static => ItemKind::Static, Static => ItemKind::Static,
Constant => ItemKind::Constant, Constant => ItemKind::Constant,
Trait => ItemKind::Trait, Trait => ItemKind::Trait,
Impl => ItemKind::Impl, Impl => ItemKind::Impl,
TyMethod | Method => ItemKind::Method,
StructField => ItemKind::StructField, StructField => ItemKind::StructField,
Variant => ItemKind::Variant, Variant => ItemKind::Variant,
Macro => ItemKind::Macro, Macro => ItemKind::Macro,

View file

@ -223,7 +223,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
false false
} }
types::ItemEnum::Method(_) types::ItemEnum::Function(_)
| types::ItemEnum::Module(_) | types::ItemEnum::Module(_)
| types::ItemEnum::AssocConst { .. } | types::ItemEnum::AssocConst { .. }
| types::ItemEnum::AssocType { .. } => true, | types::ItemEnum::AssocType { .. } => true,
@ -231,7 +231,6 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
| types::ItemEnum::Import(_) | types::ItemEnum::Import(_)
| types::ItemEnum::StructField(_) | types::ItemEnum::StructField(_)
| types::ItemEnum::Variant(_) | types::ItemEnum::Variant(_)
| types::ItemEnum::Function(_)
| types::ItemEnum::TraitAlias(_) | types::ItemEnum::TraitAlias(_)
| types::ItemEnum::Impl(_) | types::ItemEnum::Impl(_)
| types::ItemEnum::Typedef(_) | types::ItemEnum::Typedef(_)

View file

@ -9,7 +9,7 @@ use std::path::PathBuf;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
/// rustdoc format-version. /// rustdoc format-version.
pub const FORMAT_VERSION: u32 = 22; pub const FORMAT_VERSION: u32 = 23;
/// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information /// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information
/// about the language items in the local crate, as well as info about external items to allow /// about the language items in the local crate, as well as info about external items to allow
@ -210,7 +210,6 @@ pub enum ItemKind {
Constant, Constant,
Trait, Trait,
TraitAlias, TraitAlias,
Method,
Impl, Impl,
Static, Static,
ForeignType, ForeignType,
@ -243,7 +242,6 @@ pub enum ItemEnum {
Trait(Trait), Trait(Trait),
TraitAlias(TraitAlias), TraitAlias(TraitAlias),
Method(Method),
Impl(Impl), Impl(Impl),
Typedef(Typedef), Typedef(Typedef),
@ -415,18 +413,12 @@ pub enum Abi {
Other(String), Other(String),
} }
/// Represents a function (including methods and other associated functions)
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Function { pub struct Function {
pub decl: FnDecl, pub decl: FnDecl,
pub generics: Generics, pub generics: Generics,
pub header: Header, pub header: Header,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Method {
pub decl: FnDecl,
pub generics: Generics,
pub header: Header,
pub has_body: bool, pub has_body: bool,
} }

View file

@ -3,6 +3,7 @@
#[link(name = "extern", kind = "raw-dylib", import_name_type = "undecorated")] #[link(name = "extern", kind = "raw-dylib", import_name_type = "undecorated")]
extern "C" { extern "C" {
fn LooksLikeAPrivateGlobal(i: i32);
fn cdecl_fn_undecorated(i: i32); fn cdecl_fn_undecorated(i: i32);
#[link_name = "cdecl_fn_undecorated2"] #[link_name = "cdecl_fn_undecorated2"]
fn cdecl_fn_undecorated_renamed(i: i32); fn cdecl_fn_undecorated_renamed(i: i32);
@ -84,6 +85,13 @@ extern {
pub fn main() { pub fn main() {
unsafe { unsafe {
// Regression test for #104453
// On x86 LLVM uses 'L' as the prefix for private globals (PrivateGlobalPrefix), which
// causes it to believe that undecorated functions starting with 'L' are actually temporary
// symbols that it generated, which causes a later check to fail as the symbols we are
// creating don't have definitions (whereas all temporary symbols do).
LooksLikeAPrivateGlobal(13);
cdecl_fn_undecorated(1); cdecl_fn_undecorated(1);
cdecl_fn_undecorated_renamed(10); cdecl_fn_undecorated_renamed(10);
cdecl_fn_noprefix(2); cdecl_fn_noprefix(2);

View file

@ -1,6 +1,11 @@
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
void _cdecl LooksLikeAPrivateGlobal(int i) {
printf("LooksLikeAPrivateGlobal(%d)\n", i);
fflush(stdout);
}
void _cdecl cdecl_fn_undecorated(int i) { void _cdecl cdecl_fn_undecorated(int i) {
printf("cdecl_fn_undecorated(%d)\n", i); printf("cdecl_fn_undecorated(%d)\n", i);
fflush(stdout); fflush(stdout);

View file

@ -1,5 +1,6 @@
LIBRARY extern LIBRARY extern
EXPORTS EXPORTS
LooksLikeAPrivateGlobal
cdecl_fn_undecorated cdecl_fn_undecorated
cdecl_fn_undecorated2 cdecl_fn_undecorated2
cdecl_fn_noprefix cdecl_fn_noprefix

View file

@ -1,5 +1,6 @@
LIBRARY extern LIBRARY extern
EXPORTS EXPORTS
LooksLikeAPrivateGlobal
cdecl_fn_undecorated cdecl_fn_undecorated
cdecl_fn_undecorated2 cdecl_fn_undecorated2
cdecl_fn_noprefix cdecl_fn_noprefix

View file

@ -1,3 +1,4 @@
LooksLikeAPrivateGlobal(13)
cdecl_fn_undecorated(1) cdecl_fn_undecorated(1)
cdecl_fn_undecorated2(10) cdecl_fn_undecorated2(10)
cdecl_fn_noprefix(2) cdecl_fn_noprefix(2)

View file

@ -8,7 +8,7 @@ mod bar {
pub struct Baz; pub struct Baz;
// @set impl = "$.index[*][?(@.kind=='impl')].id" // @set impl = "$.index[*][?(@.kind=='impl')].id"
impl Baz { impl Baz {
// @set doit = "$.index[*][?(@.kind=='method')].id" // @set doit = "$.index[*][?(@.kind=='function')].id"
pub fn doit() {} pub fn doit() {}
} }
} }

View file

@ -463,16 +463,14 @@ struct PackedNonCopy(u8);
impl ::core::clone::Clone for PackedNonCopy { impl ::core::clone::Clone for PackedNonCopy {
#[inline] #[inline]
fn clone(&self) -> PackedNonCopy { fn clone(&self) -> PackedNonCopy {
let Self(ref __self_0_0) = *self; PackedNonCopy(::core::clone::Clone::clone(&self.0))
PackedNonCopy(::core::clone::Clone::clone(__self_0_0))
} }
} }
#[automatically_derived] #[automatically_derived]
impl ::core::fmt::Debug for PackedNonCopy { impl ::core::fmt::Debug for PackedNonCopy {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let Self(ref __self_0_0) = *self;
::core::fmt::Formatter::debug_tuple_field1_finish(f, "PackedNonCopy", ::core::fmt::Formatter::debug_tuple_field1_finish(f, "PackedNonCopy",
&__self_0_0) &&self.0)
} }
} }
#[automatically_derived] #[automatically_derived]
@ -485,8 +483,7 @@ impl ::core::default::Default for PackedNonCopy {
#[automatically_derived] #[automatically_derived]
impl ::core::hash::Hash for PackedNonCopy { impl ::core::hash::Hash for PackedNonCopy {
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
let Self(ref __self_0_0) = *self; ::core::hash::Hash::hash(&self.0, state)
::core::hash::Hash::hash(__self_0_0, state)
} }
} }
#[automatically_derived] #[automatically_derived]
@ -494,11 +491,7 @@ impl ::core::marker::StructuralPartialEq for PackedNonCopy { }
#[automatically_derived] #[automatically_derived]
impl ::core::cmp::PartialEq for PackedNonCopy { impl ::core::cmp::PartialEq for PackedNonCopy {
#[inline] #[inline]
fn eq(&self, other: &PackedNonCopy) -> bool { fn eq(&self, other: &PackedNonCopy) -> bool { self.0 == other.0 }
let Self(ref __self_0_0) = *self;
let Self(ref __self_1_0) = *other;
*__self_0_0 == *__self_1_0
}
} }
#[automatically_derived] #[automatically_derived]
impl ::core::marker::StructuralEq for PackedNonCopy { } impl ::core::marker::StructuralEq for PackedNonCopy { }
@ -516,18 +509,14 @@ impl ::core::cmp::PartialOrd for PackedNonCopy {
#[inline] #[inline]
fn partial_cmp(&self, other: &PackedNonCopy) fn partial_cmp(&self, other: &PackedNonCopy)
-> ::core::option::Option<::core::cmp::Ordering> { -> ::core::option::Option<::core::cmp::Ordering> {
let Self(ref __self_0_0) = *self; ::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0)
let Self(ref __self_1_0) = *other;
::core::cmp::PartialOrd::partial_cmp(__self_0_0, __self_1_0)
} }
} }
#[automatically_derived] #[automatically_derived]
impl ::core::cmp::Ord for PackedNonCopy { impl ::core::cmp::Ord for PackedNonCopy {
#[inline] #[inline]
fn cmp(&self, other: &PackedNonCopy) -> ::core::cmp::Ordering { fn cmp(&self, other: &PackedNonCopy) -> ::core::cmp::Ordering {
let Self(ref __self_0_0) = *self; ::core::cmp::Ord::cmp(&self.0, &other.0)
let Self(ref __self_1_0) = *other;
::core::cmp::Ord::cmp(__self_0_0, __self_1_0)
} }
} }

View file

@ -21,27 +21,27 @@ accept_pat!([p | q]);
#[cfg(FALSE)] #[cfg(FALSE)]
fn or_patterns() { fn or_patterns() {
// Top level of `let`: // Top level of `let`:
let (A | B); let (| A | B);
let (A | B); let (A | B);
let (A | B): u8; let (A | B): u8;
let (A | B) = 0; let (A | B) = 0;
let (A | B): u8 = 0; let (A | B): u8 = 0;
// Top level of `for`: // Top level of `for`:
for A | B in 0 {} for | A | B in 0 {}
for A | B in 0 {} for A | B in 0 {}
// Top level of `while`: // Top level of `while`:
while let A | B = 0 {} while let | A | B = 0 {}
while let A | B = 0 {} while let A | B = 0 {}
// Top level of `if`: // Top level of `if`:
if let A | B = 0 {} if let | A | B = 0 {}
if let A | B = 0 {} if let A | B = 0 {}
// Top level of `match` arms: // Top level of `match` arms:
match 0 { match 0 {
A | B => {} | A | B => {}
A | B => {} A | B => {}
} }

View file

@ -687,7 +687,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args:
fn matches_preds<'tcx>( fn matches_preds<'tcx>(
cx: &LateContext<'tcx>, cx: &LateContext<'tcx>,
ty: Ty<'tcx>, ty: Ty<'tcx>,
preds: &'tcx [Binder<'tcx, ExistentialPredicate<'tcx>>], preds: &'tcx [ty::PolyExistentialPredicate<'tcx>],
) -> bool { ) -> bool {
let infcx = cx.tcx.infer_ctxt().build(); let infcx = cx.tcx.infer_ctxt().build();
preds.iter().all(|&p| match cx.tcx.erase_late_bound_regions(p) { preds.iter().all(|&p| match cx.tcx.erase_late_bound_regions(p) {

View file

@ -17,7 +17,6 @@ pub(crate) enum Kind {
Constant, Constant,
Trait, Trait,
TraitAlias, TraitAlias,
Method,
Impl, Impl,
Static, Static,
ForeignType, ForeignType,
@ -63,7 +62,6 @@ impl Kind {
// Only in traits // Only in traits
AssocConst => false, AssocConst => false,
AssocType => false, AssocType => false,
Method => false,
StructField => false, // Only in structs or variants StructField => false, // Only in structs or variants
Variant => false, // Only in enums Variant => false, // Only in enums
@ -74,7 +72,7 @@ impl Kind {
match self { match self {
Kind::AssocConst => true, Kind::AssocConst => true,
Kind::AssocType => true, Kind::AssocType => true,
Kind::Method => true, Kind::Function => true,
Kind::Module => false, Kind::Module => false,
Kind::ExternCrate => false, Kind::ExternCrate => false,
@ -84,7 +82,6 @@ impl Kind {
Kind::Union => false, Kind::Union => false,
Kind::Enum => false, Kind::Enum => false,
Kind::Variant => false, Kind::Variant => false,
Kind::Function => false,
Kind::Typedef => false, Kind::Typedef => false,
Kind::OpaqueTy => false, Kind::OpaqueTy => false,
Kind::Constant => false, Kind::Constant => false,
@ -134,7 +131,6 @@ impl Kind {
ItemEnum::Function(_) => Function, ItemEnum::Function(_) => Function,
ItemEnum::Trait(_) => Trait, ItemEnum::Trait(_) => Trait,
ItemEnum::TraitAlias(_) => TraitAlias, ItemEnum::TraitAlias(_) => TraitAlias,
ItemEnum::Method(_) => Method,
ItemEnum::Impl(_) => Impl, ItemEnum::Impl(_) => Impl,
ItemEnum::Typedef(_) => Typedef, ItemEnum::Typedef(_) => Typedef,
ItemEnum::OpaqueTy(_) => OpaqueTy, ItemEnum::OpaqueTy(_) => OpaqueTy,
@ -164,7 +160,6 @@ impl Kind {
ItemKind::Import => Import, ItemKind::Import => Import,
ItemKind::Keyword => Keyword, ItemKind::Keyword => Keyword,
ItemKind::Macro => Macro, ItemKind::Macro => Macro,
ItemKind::Method => Method,
ItemKind::Module => Module, ItemKind::Module => Module,
ItemKind::OpaqueTy => OpaqueTy, ItemKind::OpaqueTy => OpaqueTy,
ItemKind::Primitive => Primitive, ItemKind::Primitive => Primitive,

View file

@ -3,9 +3,9 @@ use std::hash::Hash;
use rustdoc_json_types::{ use rustdoc_json_types::{
Constant, Crate, DynTrait, Enum, FnDecl, Function, FunctionPointer, GenericArg, GenericArgs, Constant, Crate, DynTrait, Enum, FnDecl, Function, FunctionPointer, GenericArg, GenericArgs,
GenericBound, GenericParamDef, Generics, Id, Impl, Import, ItemEnum, Method, Module, OpaqueTy, GenericBound, GenericParamDef, Generics, Id, Impl, Import, ItemEnum, Module, OpaqueTy, Path,
Path, Primitive, ProcMacro, Static, Struct, StructKind, Term, Trait, TraitAlias, Type, Primitive, ProcMacro, Static, Struct, StructKind, Term, Trait, TraitAlias, Type, TypeBinding,
TypeBinding, TypeBindingKind, Typedef, Union, Variant, WherePredicate, TypeBindingKind, Typedef, Union, Variant, WherePredicate,
}; };
use crate::{item_kind::Kind, Error, ErrorKind}; use crate::{item_kind::Kind, Error, ErrorKind};
@ -67,7 +67,6 @@ impl<'a> Validator<'a> {
ItemEnum::Function(x) => self.check_function(x), ItemEnum::Function(x) => self.check_function(x),
ItemEnum::Trait(x) => self.check_trait(x), ItemEnum::Trait(x) => self.check_trait(x),
ItemEnum::TraitAlias(x) => self.check_trait_alias(x), ItemEnum::TraitAlias(x) => self.check_trait_alias(x),
ItemEnum::Method(x) => self.check_method(x),
ItemEnum::Impl(x) => self.check_impl(x), ItemEnum::Impl(x) => self.check_impl(x),
ItemEnum::Typedef(x) => self.check_typedef(x), ItemEnum::Typedef(x) => self.check_typedef(x),
ItemEnum::OpaqueTy(x) => self.check_opaque_ty(x), ItemEnum::OpaqueTy(x) => self.check_opaque_ty(x),
@ -176,11 +175,6 @@ impl<'a> Validator<'a> {
x.params.iter().for_each(|i| self.check_generic_bound(i)); x.params.iter().for_each(|i| self.check_generic_bound(i));
} }
fn check_method(&mut self, x: &'a Method) {
self.check_fn_decl(&x.decl);
self.check_generics(&x.generics);
}
fn check_impl(&mut self, x: &'a Impl) { fn check_impl(&mut self, x: &'a Impl) {
self.check_generics(&x.generics); self.check_generics(&x.generics);
if let Some(path) = &x.trait_ { if let Some(path) = &x.trait_ {