Skip to content

Commit

Permalink
Use lang items instead of hard-coded paths in HIR lowering
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed Jan 27, 2020
1 parent 80a65bc commit a227c70
Show file tree
Hide file tree
Showing 44 changed files with 987 additions and 732 deletions.
1 change: 1 addition & 0 deletions src/libcore/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ pub trait Into<T>: Sized {
pub trait From<T>: Sized {
/// Performs the conversion.
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(bootstrap), lang = "from_method")]
fn from(_: T) -> Self;
}

Expand Down
1 change: 1 addition & 0 deletions src/libcore/iter/traits/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ pub trait IntoIterator {
/// assert_eq!(None, iter.next());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(bootstrap), lang = "into_iter")]
fn into_iter(self) -> Self::IntoIter;
}

Expand Down
1 change: 1 addition & 0 deletions src/libcore/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pub trait Iterator {
/// assert_eq!(None, iter.next());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(bootstrap), lang = "iter_next")]
fn next(&mut self) -> Option<Self::Item>;

/// Returns the bounds on the remaining length of the iterator.
Expand Down
6 changes: 6 additions & 0 deletions src/libcore/ops/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use crate::hash::{Hash, Hasher};
#[doc(alias = "..")]
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(bootstrap), lang = "range_full")]
pub struct RangeFull;

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -73,6 +74,7 @@ impl fmt::Debug for RangeFull {
#[doc(alias = "..")]
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(bootstrap), lang = "range")]
pub struct Range<Idx> {
/// The lower bound of the range (inclusive).
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -178,6 +180,7 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
#[doc(alias = "..")]
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(bootstrap), lang = "range_from")]
pub struct RangeFrom<Idx> {
/// The lower bound of the range (inclusive).
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -262,6 +265,7 @@ impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
#[doc(alias = "..")]
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(bootstrap), lang = "range_to")]
pub struct RangeTo<Idx> {
/// The upper bound of the range (exclusive).
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -404,6 +408,7 @@ impl<Idx> RangeInclusive<Idx> {
#[inline]
#[rustc_promotable]
#[rustc_const_stable(feature = "const_range_new", since = "1.32.0")]
#[cfg_attr(not(bootstrap), lang = "range_inclusive")]
pub const fn new(start: Idx, end: Idx) -> Self {
Self { start, end, is_empty: None }
}
Expand Down Expand Up @@ -607,6 +612,7 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
#[doc(alias = "..=")]
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[stable(feature = "inclusive_range", since = "1.26.0")]
#[cfg_attr(not(bootstrap), lang = "range_to_inclusive")]
pub struct RangeToInclusive<Idx> {
/// The upper bound of the range (inclusive)
#[stable(feature = "inclusive_range", since = "1.26.0")]
Expand Down
3 changes: 3 additions & 0 deletions src/libcore/ops/try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@ pub trait Try {
/// `Try`). Specifically, the value `X::from_error(From::from(e))`
/// is returned, where `X` is the return type of the enclosing function.
#[unstable(feature = "try_trait", issue = "42327")]
#[cfg_attr(not(bootstrap), lang = "try_into_result")]
fn into_result(self) -> Result<Self::Ok, Self::Error>;

/// Wrap an error value to construct the composite result. For example,
/// `Result::Err(x)` and `Result::from_error(x)` are equivalent.
#[unstable(feature = "try_trait", issue = "42327")]
#[cfg_attr(not(bootstrap), lang = "try_from_error")]
fn from_error(v: Self::Error) -> Self;

/// Wrap an OK value to construct the composite result. For example,
/// `Result::Ok(x)` and `Result::from_ok(x)` are equivalent.
#[unstable(feature = "try_trait", issue = "42327")]
#[cfg_attr(not(bootstrap), lang = "try_from_ok")]
fn from_ok(v: Self::Ok) -> Self;
}
2 changes: 2 additions & 0 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,11 @@ use crate::{
pub enum Option<T> {
/// No value
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(bootstrap), lang = "option_none")]
None,
/// Some value `T`
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(bootstrap), lang = "option_some")]
Some(#[stable(feature = "rust1", since = "1.0.0")] T),
}

Expand Down
1 change: 1 addition & 0 deletions src/libcore/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ impl<P: Deref> Pin<P> {
/// [`mem::swap`]: ../../std/mem/fn.swap.html
#[stable(feature = "pin", since = "1.33.0")]
#[inline(always)]
#[cfg_attr(not(bootstrap), lang = "pin_new_unchecked")]
pub unsafe fn new_unchecked(pointer: P) -> Pin<P> {
Pin { pointer }
}
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,12 @@ use crate::ops::{self, Deref, DerefMut};
pub enum Result<T, E> {
/// Contains the success value
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(bootstrap), lang = "result_ok")]
Ok(#[stable(feature = "rust1", since = "1.0.0")] T),

/// Contains the error value
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(bootstrap), lang = "result_err")]
Err(#[stable(feature = "rust1", since = "1.0.0")] E),
}

Expand Down
2 changes: 2 additions & 0 deletions src/libcore/task/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::result::Result;
pub enum Poll<T> {
/// Represents that a value is immediately ready.
#[stable(feature = "futures_api", since = "1.36.0")]
#[cfg_attr(not(bootstrap), lang = "poll_ready")]
Ready(#[stable(feature = "futures_api", since = "1.36.0")] T),

/// Represents that a value is not ready yet.
Expand All @@ -19,6 +20,7 @@ pub enum Poll<T> {
/// ensure that the current task is scheduled to be awoken when
/// progress can be made.
#[stable(feature = "futures_api", since = "1.36.0")]
#[cfg_attr(not(bootstrap), lang = "poll_pending")]
Pending,
}

Expand Down
11 changes: 11 additions & 0 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@ pub mod map;
pub mod upvars;

use crate::ty::query::Providers;
use crate::ty::TyCtxt;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::lang_item::LangItem;
use rustc_span::Span;

pub fn provide(providers: &mut Providers<'_>) {
check_attr::provide(providers);
map::provide(providers);
upvars::provide(providers);
}

impl hir::RequireLangItem for TyCtxt<'_> {
fn require_lang_item(self, lang_item: LangItem, span: Span) -> DefId {
self.require_lang_item(lang_item, Some(span))
}
}
6 changes: 0 additions & 6 deletions src/librustc/ich/impls_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,6 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::def_id::DefIndex {
}
}

impl<'a> HashStable<StableHashingContext<'a>> for crate::middle::lang_items::LangItem {
fn hash_stable(&self, _: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
::std::hash::Hash::hash(self, hasher);
}
}

impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitCandidate {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
Expand Down
37 changes: 0 additions & 37 deletions src/librustc/macros.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,3 @@
macro_rules! enum_from_u32 {
($(#[$attr:meta])* pub enum $name:ident {
$($variant:ident = $e:expr,)*
}) => {
$(#[$attr])*
pub enum $name {
$($variant = $e),*
}

impl $name {
pub fn from_u32(u: u32) -> Option<$name> {
$(if u == $name::$variant as u32 {
return Some($name::$variant)
})*
None
}
}
};
($(#[$attr:meta])* pub enum $name:ident {
$($variant:ident,)*
}) => {
$(#[$attr])*
pub enum $name {
$($variant,)*
}

impl $name {
pub fn from_u32(u: u32) -> Option<$name> {
$(if u == $name::$variant as u32 {
return Some($name::$variant)
})*
None
}
}
}
}

#[macro_export]
macro_rules! bug {
() => ( bug!("impossible case reached") );
Expand Down
Loading

0 comments on commit a227c70

Please sign in to comment.