From 7e5f6c7f83d4092a216248ed64068befdb25e99c Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 19 Jun 2019 20:10:37 +0300 Subject: [PATCH 1/3] rustc: always keep `hir::Path` behind a `P<...>`. --- src/librustc/hir/lowering.rs | 6 +++--- src/librustc/hir/mod.rs | 2 +- src/librustc_typeck/collect.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 9c4a208f0f9fc..78670b2eb402e 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -2725,7 +2725,7 @@ impl<'a> LoweringContext<'a> { // ::std::future::Future let future_path = - self.std_path(span, &[sym::future, sym::Future], Some(future_params), false); + P(self.std_path(span, &[sym::future, sym::Future], Some(future_params), false)); hir::GenericBound::Trait( hir::PolyTraitRef { @@ -3094,7 +3094,7 @@ impl<'a> LoweringContext<'a> { fn lower_trait_ref(&mut self, p: &TraitRef, itctx: ImplTraitContext<'_>) -> hir::TraitRef { let path = match self.lower_qpath(p.ref_id, &None, &p.path, ParamMode::Explicit, itctx) { - hir::QPath::Resolved(None, path) => path.and_then(|path| path), + hir::QPath::Resolved(None, path) => path, qpath => bug!("lower_trait_ref: unexpected QPath `{:?}`", qpath), }; hir::TraitRef { @@ -5577,7 +5577,7 @@ impl<'a> LoweringContext<'a> { let principal = hir::PolyTraitRef { bound_generic_params: hir::HirVec::new(), trait_ref: hir::TraitRef { - path: path.and_then(|path| path), + path, hir_ref_id: hir_id, }, span, diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 6df1c2d8c77e5..9f655202e7968 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -2217,7 +2217,7 @@ pub enum UseKind { /// within the resolution map. #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct TraitRef { - pub path: Path, + pub path: P, // Don't hash the ref_id. It is tracked via the thing it is used to access #[stable_hasher(ignore)] pub hir_ref_id: HirId, diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 87e1166b7c041..8464a710a4ae3 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1353,7 +1353,7 @@ pub fn checked_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fail: bool) -> Op None } } - Node::TraitRef(&hir::TraitRef { ref path, .. }) => Some(path), + Node::TraitRef(&hir::TraitRef { ref path, .. }) => Some(&**path), _ => None, }; From 25a920648a3b616469422ea0a9689297f108e8e3 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 12 Jun 2019 09:36:12 +0300 Subject: [PATCH 2/3] syntax: use `box` instead of `Box::new` in `ptr::P`. --- src/libsyntax/lib.rs | 1 + src/libsyntax/ptr.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 337b84247361d..1fe3dfa40ee6e 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -12,6 +12,7 @@ #![deny(unused_lifetimes)] #![feature(bind_by_move_pattern_guards)] +#![feature(box_syntax)] #![feature(const_fn)] #![feature(const_transmute)] #![feature(crate_visibility_modifier)] diff --git a/src/libsyntax/ptr.rs b/src/libsyntax/ptr.rs index f0cfa5a84a827..2e282327fea1f 100644 --- a/src/libsyntax/ptr.rs +++ b/src/libsyntax/ptr.rs @@ -45,7 +45,7 @@ pub struct P { /// Construct a `P` from a `T` value. pub fn P(value: T) -> P { P { - ptr: Box::new(value) + ptr: box value } } From c6374cfbe2de22e46b4e7687fa733549114bf070 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 12 Jun 2019 09:41:00 +0300 Subject: [PATCH 3/3] rustc: use a separate copy of P for HIR than for AST. --- src/librustc/cfg/construct.rs | 2 +- src/librustc/hir/lowering.rs | 18 +-- src/librustc/hir/mod.rs | 11 +- src/librustc/hir/print.rs | 2 +- src/librustc/hir/ptr.rs | 141 +++++++++++++++++++ src/librustc/lib.rs | 2 + src/librustc/middle/expr_use_visitor.rs | 2 +- src/librustc/middle/liveness.rs | 2 +- src/librustc/middle/resolve_lifetime.rs | 2 +- src/librustc_mir/hair/cx/to_ref.rs | 2 +- src/librustc_mir/hair/pattern/check_match.rs | 2 +- src/librustc_mir/hair/pattern/mod.rs | 2 +- src/librustc_typeck/astconv.rs | 2 +- src/librustc_typeck/check/_match.rs | 2 +- src/librustc_typeck/check/coercion.rs | 2 +- src/librustc_typeck/check/expr.rs | 2 +- src/librustc_typeck/check/mod.rs | 2 +- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/doctree.rs | 2 +- src/libsyntax/ptr.rs | 2 +- 20 files changed, 176 insertions(+), 28 deletions(-) create mode 100644 src/librustc/hir/ptr.rs diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index a7750edbb6f48..403e2f02f0545 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -1,11 +1,11 @@ use crate::cfg::*; use crate::middle::region; use rustc_data_structures::graph::implementation as graph; -use syntax::ptr::P; use crate::ty::{self, TyCtxt}; use crate::hir::{self, PatKind}; use crate::hir::def_id::DefId; +use crate::hir::ptr::P; struct CFGBuilder<'a, 'tcx> { tcx: TyCtxt<'tcx>, diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 78670b2eb402e..49a832948f17c 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -39,6 +39,7 @@ use crate::hir::map::{DefKey, DefPathData, Definitions}; use crate::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX}; use crate::hir::def::{Res, DefKind, PartialRes, PerNS}; use crate::hir::{GenericArg, ConstArg}; +use crate::hir::ptr::P; use crate::lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES, ELIDED_LIFETIMES_IN_PATHS}; use crate::middle::cstore::CrateStore; @@ -61,7 +62,6 @@ use syntax::ast::*; use syntax::errors; use syntax::ext::hygiene::{Mark, SyntaxContext}; use syntax::print::pprust; -use syntax::ptr::P; use syntax::source_map::{self, respan, ExpnInfo, CompilerDesugaringKind, Spanned}; use syntax::source_map::CompilerDesugaringKind::IfTemporary; use syntax::std_inject; @@ -1111,7 +1111,7 @@ impl<'a> LoweringContext<'a> { }, ); - lowered_generics.params = lowered_generics + let mut lowered_params: Vec<_> = lowered_generics .params .into_iter() .chain(in_band_defs) @@ -1121,7 +1121,7 @@ impl<'a> LoweringContext<'a> { // unsorted generic parameters at the moment, so we make sure // that they're ordered correctly here for now. (When we chain // the `in_band_defs`, we might make the order unsorted.) - lowered_generics.params.sort_by_key(|param| { + lowered_params.sort_by_key(|param| { match param.kind { hir::GenericParamKind::Lifetime { .. } => ParamKindOrd::Lifetime, hir::GenericParamKind::Type { .. } => ParamKindOrd::Type, @@ -1129,6 +1129,8 @@ impl<'a> LoweringContext<'a> { } }); + lowered_generics.params = lowered_params.into(); + (lowered_generics, res) } @@ -1155,13 +1157,13 @@ impl<'a> LoweringContext<'a> { &mut self, capture_clause: CaptureBy, closure_node_id: NodeId, - ret_ty: Option<&Ty>, + ret_ty: Option>, span: Span, body: impl FnOnce(&mut LoweringContext<'_>) -> hir::Expr, ) -> hir::ExprKind { let capture_clause = self.lower_capture_clause(capture_clause); let output = match ret_ty { - Some(ty) => FunctionRetTy::Ty(P(ty.clone())), + Some(ty) => FunctionRetTy::Ty(ty), None => FunctionRetTy::Default(span), }; let ast_decl = FnDecl { @@ -3620,7 +3622,7 @@ impl<'a> LoweringContext<'a> { hir::Item { hir_id: new_id, ident, - attrs: attrs.clone(), + attrs: attrs.into_iter().cloned().collect(), node: item, vis, span, @@ -3705,7 +3707,7 @@ impl<'a> LoweringContext<'a> { hir::Item { hir_id: new_hir_id, ident, - attrs: attrs.clone(), + attrs: attrs.into_iter().cloned().collect(), node: item, vis, span: use_tree.span, @@ -4567,7 +4569,7 @@ impl<'a> LoweringContext<'a> { // `|x: u8| future_from_generator(|| -> X { ... })`. let body_id = this.lower_fn_body(&outer_decl, |this| { let async_ret_ty = if let FunctionRetTy::Ty(ty) = &decl.output { - Some(&**ty) + Some(ty.clone()) } else { None }; let async_body = this.make_async_expr( capture_clause, closure_id, async_ret_ty, body.span, diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 9f655202e7968..bfbd8398f99f3 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -12,6 +12,7 @@ pub use self::UnsafeSource::*; use crate::hir::def::{Res, DefKind}; use crate::hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX}; +use crate::hir::ptr::P; use crate::util::nodemap::{NodeMap, FxHashSet}; use crate::mir::mono::Linkage; @@ -23,7 +24,6 @@ use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect}; use syntax::ast::{Attribute, Label, LitKind, StrStyle, FloatTy, IntTy, UintTy}; use syntax::attr::{InlineAttr, OptimizeAttr}; use syntax::ext::hygiene::SyntaxContext; -use syntax::ptr::P; use syntax::symbol::{Symbol, kw}; use syntax::tokenstream::TokenStream; use syntax::util::parser::ExprPrecedence; @@ -63,6 +63,7 @@ pub mod lowering; pub mod map; pub mod pat_util; pub mod print; +pub mod ptr; pub mod upvars; /// Uniquely identifies a node in the HIR of the current crate. It is @@ -1979,13 +1980,15 @@ pub struct InlineAsmOutput { pub span: Span, } +// NOTE(eddyb) This is used within MIR as well, so unlike the rest of the HIR, +// it needs to be `Clone` and use plain `Vec` instead of `HirVec`. #[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct InlineAsm { pub asm: Symbol, pub asm_str_style: StrStyle, - pub outputs: HirVec, - pub inputs: HirVec, - pub clobbers: HirVec, + pub outputs: Vec, + pub inputs: Vec, + pub clobbers: Vec, pub volatile: bool, pub alignstack: bool, pub dialect: AsmDialect, diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 8b1984e04f55b..3b33de1a17926 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -6,7 +6,6 @@ use syntax::parse::lexer::comments; use syntax::print::pp::{self, Breaks}; use syntax::print::pp::Breaks::{Consistent, Inconsistent}; use syntax::print::pprust::{self, PrintState}; -use syntax::ptr::P; use syntax::symbol::kw; use syntax::util::parser::{self, AssocOp, Fixity}; use syntax_pos::{self, BytePos, FileName}; @@ -14,6 +13,7 @@ use syntax_pos::{self, BytePos, FileName}; use crate::hir; use crate::hir::{PatKind, GenericBound, TraitBoundModifier, RangeEnd}; use crate::hir::{GenericParam, GenericParamKind, GenericArg}; +use crate::hir::ptr::P; use std::borrow::Cow; use std::cell::Cell; diff --git a/src/librustc/hir/ptr.rs b/src/librustc/hir/ptr.rs new file mode 100644 index 0000000000000..3a87b36a1b434 --- /dev/null +++ b/src/librustc/hir/ptr.rs @@ -0,0 +1,141 @@ +// HACK(eddyb) this is a copy of `syntax::ptr`, minus the mutation (the HIR is +// frozen anyway). The only reason for doing this instead of replacing `P` +// with `Box` in HIR, is that `&Box<[T]>` doesn't implement `IntoIterator`. + +use std::fmt::{self, Display, Debug}; +use std::iter::FromIterator; +use std::ops::Deref; +use std::{slice, vec}; + +use serialize::{Encodable, Decodable, Encoder, Decoder}; + +use rustc_data_structures::stable_hasher::{StableHasher, StableHasherResult, + HashStable}; +/// An owned smart pointer. +#[derive(Hash, PartialEq, Eq)] +pub struct P { + ptr: Box +} + +/// Construct a `P` from a `T` value. +#[allow(non_snake_case)] +pub fn P(value: T) -> P { + P { + ptr: box value + } +} + +impl P { + // HACK(eddyb) used by HIR lowering in a few places still. + // NOTE: do not make this more public than `pub(super)`. + pub(super) fn into_inner(self) -> T { + *self.ptr + } +} + +impl Deref for P { + type Target = T; + + fn deref(&self) -> &T { + &self.ptr + } +} + +impl Debug for P { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + Debug::fmt(&self.ptr, f) + } +} + +impl Display for P { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + Display::fmt(&**self, f) + } +} + +impl Decodable for P { + fn decode(d: &mut D) -> Result, D::Error> { + Decodable::decode(d).map(P) + } +} + +impl Encodable for P { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { + (**self).encode(s) + } +} + +impl P<[T]> { + pub const fn new() -> P<[T]> { + // HACK(eddyb) bypass the lack of a `const fn` to create an empty `Box<[T]>` + // (as trait methods, `default` in this case, can't be `const fn` yet). + P { + ptr: unsafe { + use std::ptr::NonNull; + std::mem::transmute(NonNull::<[T; 0]>::dangling() as NonNull<[T]>) + }, + } + } + + #[inline(never)] + pub fn from_vec(v: Vec) -> P<[T]> { + P { ptr: v.into_boxed_slice() } + } + + // HACK(eddyb) used by HIR lowering in a few places still. + // NOTE: do not make this more public than `pub(super)`, + // and do not make this into an `IntoIterator` impl. + pub(super) fn into_iter(self) -> vec::IntoIter { + self.ptr.into_vec().into_iter() + } +} + + +impl Default for P<[T]> { + /// Creates an empty `P<[T]>`. + fn default() -> P<[T]> { + P::new() + } +} + +impl From> for P<[T]> { + fn from(v: Vec) -> Self { + P::from_vec(v) + } +} + +impl FromIterator for P<[T]> { + fn from_iter>(iter: I) -> P<[T]> { + P::from_vec(iter.into_iter().collect()) + } +} + +impl<'a, T> IntoIterator for &'a P<[T]> { + type Item = &'a T; + type IntoIter = slice::Iter<'a, T>; + fn into_iter(self) -> Self::IntoIter { + self.ptr.into_iter() + } +} + +impl Encodable for P<[T]> { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { + Encodable::encode(&**self, s) + } +} + +impl Decodable for P<[T]> { + fn decode(d: &mut D) -> Result, D::Error> { + Ok(P::from_vec(Decodable::decode(d)?)) + } +} + +impl HashStable for P + where T: ?Sized + HashStable +{ + fn hash_stable(&self, + hcx: &mut CTX, + hasher: &mut StableHasher) { + (**self).hash_stable(hcx, hasher); + } +} diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 257d5159f1131..21c1a8d28d4c5 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -35,6 +35,8 @@ #![feature(arbitrary_self_types)] #![feature(box_patterns)] #![feature(box_syntax)] +#![feature(const_fn)] +#![feature(const_transmute)] #![feature(core_intrinsics)] #![feature(drain_filter)] #![feature(inner_deref)] diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 086ddfd7e33bf..c93cc847adff2 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -11,6 +11,7 @@ use self::OverloadedCallType::*; use crate::hir::def::{CtorOf, Res, DefKind}; use crate::hir::def_id::DefId; +use crate::hir::ptr::P; use crate::infer::InferCtxt; use crate::middle::mem_categorization as mc; use crate::middle::region; @@ -18,7 +19,6 @@ use crate::ty::{self, DefIdTree, TyCtxt, adjustment}; use crate::hir::{self, PatKind}; use std::rc::Rc; -use syntax::ptr::P; use syntax_pos::Span; use crate::util::nodemap::ItemLocalSet; diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 7b69fe394fb2c..464bc4fd6dfd7 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -99,6 +99,7 @@ use self::VarKind::*; use crate::hir::def::*; use crate::hir::Node; +use crate::hir::ptr::P; use crate::ty::{self, TyCtxt}; use crate::ty::query::Providers; use crate::lint; @@ -111,7 +112,6 @@ use std::io::prelude::*; use std::io; use std::rc::Rc; use syntax::ast; -use syntax::ptr::P; use syntax::symbol::{kw, sym}; use syntax_pos::Span; diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 412346bab257e..c94893d8b7575 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -8,6 +8,7 @@ use crate::hir::def::{Res, DefKind}; use crate::hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; use crate::hir::map::Map; +use crate::hir::ptr::P; use crate::hir::{GenericArg, GenericParam, ItemLocalId, LifetimeName, Node, ParamName}; use crate::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt}; @@ -21,7 +22,6 @@ use std::cell::Cell; use std::mem::replace; use syntax::ast; use syntax::attr; -use syntax::ptr::P; use syntax::symbol::{kw, sym}; use syntax_pos::Span; diff --git a/src/librustc_mir/hair/cx/to_ref.rs b/src/librustc_mir/hair/cx/to_ref.rs index 946d66fc91d7d..c365cc2ad8544 100644 --- a/src/librustc_mir/hair/cx/to_ref.rs +++ b/src/librustc_mir/hair/cx/to_ref.rs @@ -1,7 +1,7 @@ use crate::hair::*; use rustc::hir; -use syntax::ptr::P; +use rustc::hir::ptr::P; pub trait ToRef { type Output; diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index ed850379af60b..f8baf457e9d2c 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -18,12 +18,12 @@ use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc::hir::def::*; use rustc::hir::def_id::DefId; use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap}; +use rustc::hir::ptr::P; use rustc::hir::{self, Pat, PatKind}; use smallvec::smallvec; use std::slice; -use syntax::ptr::P; use syntax_pos::{Span, DUMMY_SP, MultiSpan}; pub(crate) fn check_match<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) { diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index cf597ce0b6319..6ba2f58776849 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -20,13 +20,13 @@ use rustc::ty::layout::{VariantIdx, Size}; use rustc::hir::{self, PatKind, RangeEnd}; use rustc::hir::def::{CtorOf, Res, DefKind, CtorKind}; use rustc::hir::pat_util::EnumerateAndAdjustIterator; +use rustc::hir::ptr::P; use rustc_data_structures::indexed_vec::Idx; use std::cmp::Ordering; use std::fmt; use syntax::ast; -use syntax::ptr::P; use syntax::symbol::sym; use syntax_pos::Span; diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 9b8f6a556bf88..1792716d1fb35 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -7,6 +7,7 @@ use crate::hir::{self, GenericArg, GenericArgs, ExprKind}; use crate::hir::def::{CtorOf, Res, DefKind}; use crate::hir::def_id::DefId; use crate::hir::HirVec; +use crate::hir::ptr::P; use crate::lint; use crate::middle::lang_items::SizedTraitLangItem; use crate::middle::resolve_lifetime as rl; @@ -23,7 +24,6 @@ use crate::require_c_abi_if_c_variadic; use smallvec::SmallVec; use syntax::ast; use syntax::feature_gate::{GateIssue, emit_feature_err}; -use syntax::ptr::P; use syntax::util::lev_distance::find_best_match_for_name; use syntax::symbol::sym; use syntax_pos::{DUMMY_SP, Span, MultiSpan}; diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index b435c99ad01f5..841e73adb0b68 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -5,6 +5,7 @@ use errors::{Applicability, DiagnosticBuilder}; use rustc::hir::{self, PatKind, Pat, ExprKind}; use rustc::hir::def::{Res, DefKind, CtorKind}; use rustc::hir::pat_util::EnumerateAndAdjustIterator; +use rustc::hir::ptr::P; use rustc::infer; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc::traits::{ObligationCause, ObligationCauseCode}; @@ -12,7 +13,6 @@ use rustc::ty::{self, Ty, TypeFoldable}; use rustc::ty::subst::Kind; use syntax::ast; use syntax::source_map::Spanned; -use syntax::ptr::P; use syntax::util::lev_distance::find_best_match_for_name; use syntax_pos::Span; use syntax_pos::hygiene::CompilerDesugaringKind; diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 4bd2f216224a5..94c76deade279 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -54,6 +54,7 @@ use crate::check::{FnCtxt, Needs}; use errors::DiagnosticBuilder; use rustc::hir; use rustc::hir::def_id::DefId; +use rustc::hir::ptr::P; use rustc::infer::{Coercion, InferResult, InferOk}; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc::traits::{self, ObligationCause, ObligationCauseCode}; @@ -67,7 +68,6 @@ use rustc::ty::relate::RelateResult; use smallvec::{smallvec, SmallVec}; use std::ops::Deref; use syntax::feature_gate; -use syntax::ptr::P; use syntax::symbol::sym; use syntax_pos; diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 21fa219a1cab2..ccc20bd9585c9 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -20,13 +20,13 @@ use crate::astconv::AstConv as _; use errors::{Applicability, DiagnosticBuilder}; use syntax::ast; -use syntax::ptr::P; use syntax::symbol::{Symbol, LocalInternedString, kw, sym}; use syntax::source_map::Span; use syntax::util::lev_distance::find_best_match_for_name; use rustc::hir; use rustc::hir::{ExprKind, QPath}; use rustc::hir::def::{CtorKind, Res, DefKind}; +use rustc::hir::ptr::P; use rustc::infer; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc::mir::interpret::GlobalId; diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 37866bab9009d..04364874c1037 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -93,6 +93,7 @@ use rustc::hir::def::{CtorOf, Res, DefKind}; use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap}; use rustc::hir::itemlikevisit::ItemLikeVisitor; +use rustc::hir::ptr::P; use crate::middle::lang_items; use crate::namespace::Namespace; use rustc::infer::{self, InferCtxt, InferOk, InferResult}; @@ -122,7 +123,6 @@ use syntax_pos::hygiene::CompilerDesugaringKind; use syntax::ast; use syntax::attr; use syntax::feature_gate::{GateIssue, emit_feature_err}; -use syntax::ptr::P; use syntax::source_map::{DUMMY_SP, original_sp}; use syntax::symbol::{kw, sym}; diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 3fe048a6986bb..7353c3ec2e557 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -20,6 +20,7 @@ use rustc::mir::interpret::{GlobalId, ConstValue}; use rustc::hir; use rustc::hir::def::{CtorKind, DefKind, Res}; use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc::hir::ptr::P; use rustc::ty::subst::{InternalSubsts, SubstsRef, UnpackedKind}; use rustc::ty::{self, DefIdTree, TyCtxt, Region, RegionVid, Ty, AdtKind}; use rustc::ty::fold::TypeFolder; @@ -29,7 +30,6 @@ use syntax::ast::{self, AttrStyle, Ident}; use syntax::attr; use syntax::ext::base::MacroKind; use syntax::source_map::{dummy_spanned, Spanned}; -use syntax::ptr::P; use syntax::symbol::{Symbol, kw, sym}; use syntax::symbol::InternedString; use syntax_pos::{self, Pos, FileName}; diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 2557b8d1627c0..45a3c8a3c2256 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -6,11 +6,11 @@ use syntax::ast; use syntax::ast::{Name, NodeId}; use syntax::attr; use syntax::ext::base::MacroKind; -use syntax::ptr::P; use syntax_pos::{self, Span}; use rustc::hir; use rustc::hir::def_id::CrateNum; +use rustc::hir::ptr::P; pub struct Module<'hir> { pub name: Option, diff --git a/src/libsyntax/ptr.rs b/src/libsyntax/ptr.rs index 2e282327fea1f..be580dc2e6a7e 100644 --- a/src/libsyntax/ptr.rs +++ b/src/libsyntax/ptr.rs @@ -41,8 +41,8 @@ pub struct P { ptr: Box } -#[allow(non_snake_case)] /// Construct a `P` from a `T` value. +#[allow(non_snake_case)] pub fn P(value: T) -> P { P { ptr: box value