From ed640c6a27aca3b2446ab8d6f00df0a2d78f1192 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 9 Nov 2019 17:44:11 +0100 Subject: Merge hir::Mutability into ast::Mutability. --- src/libsyntax/ast.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index b57d2238991..b0f83f03f62 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -733,6 +733,30 @@ pub enum Mutability { Immutable, } +impl Mutability { + /// Returns `MutMutable` only if both `self` and `other` are mutable. + pub fn and(self, other: Self) -> Self { + match self { + Mutability::Mutable => other, + Mutability::Immutable => Mutability::Immutable, + } + } + + pub fn invert(self) -> Self { + match self { + Mutability::Mutable => Mutability::Immutable, + Mutability::Immutable => Mutability::Mutable, + } + } + + pub fn prefix_str(&self) -> &'static str { + match self { + Mutability::Mutable => "mut ", + Mutability::Immutable => "", + } + } +} + #[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] pub enum BinOpKind { /// The `+` operator (addition) -- cgit 1.4.1-3-g733a5 From f03cbc313ddc16d7aba6c21c197a52ee4d2e85e9 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 9 Nov 2019 18:01:12 +0100 Subject: Merge hir::Unsafety into ast::Unsafety. --- src/librustc/hir/lowering.rs | 2 +- src/librustc/hir/lowering/item.rs | 13 +++---------- src/librustc/hir/mod.rs | 27 +-------------------------- src/libsyntax/ast.rs | 36 +++++++++++++++++++++++------------- 4 files changed, 28 insertions(+), 50 deletions(-) (limited to 'src/libsyntax') diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index a22db239d28..02afdc27acd 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1213,7 +1213,7 @@ impl<'a> LoweringContext<'a> { &NodeMap::default(), ImplTraitContext::disallowed(), ), - unsafety: this.lower_unsafety(f.unsafety), + unsafety: f.unsafety, abi: this.lower_abi(f.abi), decl: this.lower_fn_decl(&f.decl, None, false, None), param_names: this.lower_fn_params_to_names(&f.decl), diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index 2d03e92139e..bf288f271a6 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -433,7 +433,7 @@ impl LoweringContext<'_> { ); hir::ItemKind::Impl( - self.lower_unsafety(unsafety), + unsafety, self.lower_impl_polarity(polarity), self.lower_defaultness(defaultness, true /* [1] */), generics, @@ -450,7 +450,7 @@ impl LoweringContext<'_> { .collect(); hir::ItemKind::Trait( self.lower_is_auto(is_auto), - self.lower_unsafety(unsafety), + unsafety, self.lower_generics(generics, ImplTraitContext::disallowed()), bounds, items, @@ -1284,7 +1284,7 @@ impl LoweringContext<'_> { fn lower_fn_header(&mut self, h: FnHeader) -> hir::FnHeader { hir::FnHeader { - unsafety: self.lower_unsafety(h.unsafety), + unsafety: h.unsafety, asyncness: self.lower_asyncness(h.asyncness.node), constness: h.constness.node, abi: self.lower_abi(h.abi), @@ -1311,13 +1311,6 @@ impl LoweringContext<'_> { .emit(); } - pub(super) fn lower_unsafety(&mut self, u: Unsafety) -> hir::Unsafety { - match u { - Unsafety::Unsafe => hir::Unsafety::Unsafe, - Unsafety::Normal => hir::Unsafety::Normal, - } - } - fn lower_asyncness(&mut self, a: IsAsync) -> hir::IsAsync { match a { IsAsync::Async { .. } => hir::IsAsync::Async, diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 63d4ba6d8b7..645d7b5fdb0 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -22,7 +22,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan}; use syntax::source_map::Spanned; use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect}; use syntax::ast::{Attribute, Label, LitKind, StrStyle, FloatTy, IntTy, UintTy}; -pub use syntax::ast::{Mutability, Constness}; +pub use syntax::ast::{Mutability, Constness, Unsafety}; use syntax::attr::{InlineAttr, OptimizeAttr}; use syntax::symbol::{Symbol, kw}; use syntax::tokenstream::TokenStream; @@ -2154,22 +2154,6 @@ pub enum IsAsync { NotAsync, } -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, HashStable, - RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum Unsafety { - Unsafe, - Normal, -} - -impl Unsafety { - pub fn prefix_str(&self) -> &'static str { - match self { - Unsafety::Unsafe => "unsafe ", - Unsafety::Normal => "", - } - } -} - #[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum Defaultness { Default { has_value: bool }, @@ -2196,15 +2180,6 @@ impl Defaultness { } } -impl fmt::Display for Unsafety { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(match self { - Unsafety::Normal => "normal", - Unsafety::Unsafe => "unsafe", - }) - } -} - #[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, HashStable)] pub enum ImplPolarity { /// `impl Trait for Type` diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index b0f83f03f62..887d7beed6d 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1991,12 +1991,34 @@ pub enum IsAuto { No, } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, + RustcEncodable, RustcDecodable, Debug)] pub enum Unsafety { Unsafe, Normal, } +impl Unsafety { + pub fn prefix_str(&self) -> &'static str { + match self { + Unsafety::Unsafe => "unsafe ", + Unsafety::Normal => "", + } + } +} + +impl fmt::Display for Unsafety { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Display::fmt( + match *self { + Unsafety::Normal => "normal", + Unsafety::Unsafe => "unsafe", + }, + f, + ) + } +} + #[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug)] pub enum IsAsync { Async { @@ -2041,18 +2063,6 @@ pub enum Defaultness { Final, } -impl fmt::Display for Unsafety { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt( - match *self { - Unsafety::Normal => "normal", - Unsafety::Unsafe => "unsafe", - }, - f, - ) - } -} - #[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] pub enum ImplPolarity { /// `impl Trait for Type` -- cgit 1.4.1-3-g733a5 From 5b30da10b64cf9b3567554e651bb6a9d62ad554b Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 9 Nov 2019 18:06:57 +0100 Subject: Merge hir::GeneratorMovability into ast::Movability. --- src/librustc/hir/lowering/expr.rs | 9 +++------ src/librustc/hir/mod.rs | 17 +++-------------- src/librustc/ich/impls_syntax.rs | 1 + src/librustc/mir/mod.rs | 2 +- src/librustc/traits/select.rs | 4 ++-- src/librustc/ty/context.rs | 2 +- src/librustc/ty/print/pretty.rs | 7 +++---- src/librustc/ty/sty.rs | 2 +- src/librustc_mir/borrow_check/mod.rs | 2 +- src/librustc_mir/borrow_check/nll/universal_regions.rs | 2 +- src/librustc_mir/hair/mod.rs | 2 +- src/librustc_mir/transform/generator.rs | 2 +- src/librustc_passes/loops.rs | 4 ++-- src/librustc_traits/generic_types.rs | 2 +- src/librustc_typeck/check/closure.rs | 4 ++-- src/librustc_typeck/check/mod.rs | 4 ++-- src/libsyntax/ast.rs | 8 ++++++-- 17 files changed, 32 insertions(+), 42 deletions(-) (limited to 'src/libsyntax') diff --git a/src/librustc/hir/lowering/expr.rs b/src/librustc/hir/lowering/expr.rs index 74a2be8cf56..6c92a997b1f 100644 --- a/src/librustc/hir/lowering/expr.rs +++ b/src/librustc/hir/lowering/expr.rs @@ -494,7 +494,7 @@ impl LoweringContext<'_> { decl, body_id, span, - Some(hir::GeneratorMovability::Static) + Some(hir::Movability::Static) ); let generator = hir::Expr { hir_id: self.lower_node_id(closure_node_id), @@ -725,7 +725,7 @@ impl LoweringContext<'_> { fn_decl_span: Span, generator_kind: Option, movability: Movability, - ) -> Option { + ) -> Option { match generator_kind { Some(hir::GeneratorKind::Gen) => { if !decl.inputs.is_empty() { @@ -736,10 +736,7 @@ impl LoweringContext<'_> { "generators cannot have explicit parameters" ); } - Some(match movability { - Movability::Movable => hir::GeneratorMovability::Movable, - Movability::Static => hir::GeneratorMovability::Static, - }) + Some(movability) }, Some(hir::GeneratorKind::Async(_)) => { bug!("non-`async` closure body turned `async` during lowering"); diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 645d7b5fdb0..297022600f9 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -22,7 +22,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan}; use syntax::source_map::Spanned; use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect}; use syntax::ast::{Attribute, Label, LitKind, StrStyle, FloatTy, IntTy, UintTy}; -pub use syntax::ast::{Mutability, Constness, Unsafety}; +pub use syntax::ast::{Mutability, Constness, Unsafety, Movability}; use syntax::attr::{InlineAttr, OptimizeAttr}; use syntax::symbol::{Symbol, kw}; use syntax::tokenstream::TokenStream; @@ -1628,8 +1628,8 @@ pub enum ExprKind { /// The `Span` is the argument block `|...|`. /// /// This may also be a generator literal or an `async block` as indicated by the - /// `Option`. - Closure(CaptureClause, P, BodyId, Span, Option), + /// `Option`. + Closure(CaptureClause, P, BodyId, Span, Option), /// A block (e.g., `'label: { ... }`). Block(P, Option