diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index a22db239d282..02afdc27acdc 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 2d03e92139e4..bf288f271a69 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 63d4ba6d8b75..645d7b5fdb01 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 b0f83f03f626..887d7beed6de 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`