Skip to content

Commit a227c70

Browse files
committed
Use lang items instead of hard-coded paths in HIR lowering
1 parent 80a65bc commit a227c70

File tree

44 files changed

+987
-732
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+987
-732
lines changed

src/libcore/convert/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ pub trait Into<T>: Sized {
381381
pub trait From<T>: Sized {
382382
/// Performs the conversion.
383383
#[stable(feature = "rust1", since = "1.0.0")]
384+
#[cfg_attr(not(bootstrap), lang = "from_method")]
384385
fn from(_: T) -> Self;
385386
}
386387

src/libcore/iter/traits/collect.rs

+1
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ pub trait IntoIterator {
236236
/// assert_eq!(None, iter.next());
237237
/// ```
238238
#[stable(feature = "rust1", since = "1.0.0")]
239+
#[cfg_attr(not(bootstrap), lang = "into_iter")]
239240
fn into_iter(self) -> Self::IntoIter;
240241
}
241242

src/libcore/iter/traits/iterator.rs

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ pub trait Iterator {
127127
/// assert_eq!(None, iter.next());
128128
/// ```
129129
#[stable(feature = "rust1", since = "1.0.0")]
130+
#[cfg_attr(not(bootstrap), lang = "iter_next")]
130131
fn next(&mut self) -> Option<Self::Item>;
131132

132133
/// Returns the bounds on the remaining length of the iterator.

src/libcore/ops/range.rs

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use crate::hash::{Hash, Hasher};
4141
#[doc(alias = "..")]
4242
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
4343
#[stable(feature = "rust1", since = "1.0.0")]
44+
#[cfg_attr(not(bootstrap), lang = "range_full")]
4445
pub struct RangeFull;
4546

4647
#[stable(feature = "rust1", since = "1.0.0")]
@@ -73,6 +74,7 @@ impl fmt::Debug for RangeFull {
7374
#[doc(alias = "..")]
7475
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
7576
#[stable(feature = "rust1", since = "1.0.0")]
77+
#[cfg_attr(not(bootstrap), lang = "range")]
7678
pub struct Range<Idx> {
7779
/// The lower bound of the range (inclusive).
7880
#[stable(feature = "rust1", since = "1.0.0")]
@@ -178,6 +180,7 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
178180
#[doc(alias = "..")]
179181
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
180182
#[stable(feature = "rust1", since = "1.0.0")]
183+
#[cfg_attr(not(bootstrap), lang = "range_from")]
181184
pub struct RangeFrom<Idx> {
182185
/// The lower bound of the range (inclusive).
183186
#[stable(feature = "rust1", since = "1.0.0")]
@@ -262,6 +265,7 @@ impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
262265
#[doc(alias = "..")]
263266
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
264267
#[stable(feature = "rust1", since = "1.0.0")]
268+
#[cfg_attr(not(bootstrap), lang = "range_to")]
265269
pub struct RangeTo<Idx> {
266270
/// The upper bound of the range (exclusive).
267271
#[stable(feature = "rust1", since = "1.0.0")]
@@ -404,6 +408,7 @@ impl<Idx> RangeInclusive<Idx> {
404408
#[inline]
405409
#[rustc_promotable]
406410
#[rustc_const_stable(feature = "const_range_new", since = "1.32.0")]
411+
#[cfg_attr(not(bootstrap), lang = "range_inclusive")]
407412
pub const fn new(start: Idx, end: Idx) -> Self {
408413
Self { start, end, is_empty: None }
409414
}
@@ -607,6 +612,7 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
607612
#[doc(alias = "..=")]
608613
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
609614
#[stable(feature = "inclusive_range", since = "1.26.0")]
615+
#[cfg_attr(not(bootstrap), lang = "range_to_inclusive")]
610616
pub struct RangeToInclusive<Idx> {
611617
/// The upper bound of the range (inclusive)
612618
#[stable(feature = "inclusive_range", since = "1.26.0")]

src/libcore/ops/try.rs

+3
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,18 @@ pub trait Try {
4343
/// `Try`). Specifically, the value `X::from_error(From::from(e))`
4444
/// is returned, where `X` is the return type of the enclosing function.
4545
#[unstable(feature = "try_trait", issue = "42327")]
46+
#[cfg_attr(not(bootstrap), lang = "try_into_result")]
4647
fn into_result(self) -> Result<Self::Ok, Self::Error>;
4748

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

5355
/// Wrap an OK value to construct the composite result. For example,
5456
/// `Result::Ok(x)` and `Result::from_ok(x)` are equivalent.
5557
#[unstable(feature = "try_trait", issue = "42327")]
58+
#[cfg_attr(not(bootstrap), lang = "try_from_ok")]
5659
fn from_ok(v: Self::Ok) -> Self;
5760
}

src/libcore/option.rs

+2
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,11 @@ use crate::{
156156
pub enum Option<T> {
157157
/// No value
158158
#[stable(feature = "rust1", since = "1.0.0")]
159+
#[cfg_attr(not(bootstrap), lang = "option_none")]
159160
None,
160161
/// Some value `T`
161162
#[stable(feature = "rust1", since = "1.0.0")]
163+
#[cfg_attr(not(bootstrap), lang = "option_some")]
162164
Some(#[stable(feature = "rust1", since = "1.0.0")] T),
163165
}
164166

src/libcore/pin.rs

+1
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ impl<P: Deref> Pin<P> {
562562
/// [`mem::swap`]: ../../std/mem/fn.swap.html
563563
#[stable(feature = "pin", since = "1.33.0")]
564564
#[inline(always)]
565+
#[cfg_attr(not(bootstrap), lang = "pin_new_unchecked")]
565566
pub unsafe fn new_unchecked(pointer: P) -> Pin<P> {
566567
Pin { pointer }
567568
}

src/libcore/result.rs

+2
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,12 @@ use crate::ops::{self, Deref, DerefMut};
247247
pub enum Result<T, E> {
248248
/// Contains the success value
249249
#[stable(feature = "rust1", since = "1.0.0")]
250+
#[cfg_attr(not(bootstrap), lang = "result_ok")]
250251
Ok(#[stable(feature = "rust1", since = "1.0.0")] T),
251252

252253
/// Contains the error value
253254
#[stable(feature = "rust1", since = "1.0.0")]
255+
#[cfg_attr(not(bootstrap), lang = "result_err")]
254256
Err(#[stable(feature = "rust1", since = "1.0.0")] E),
255257
}
256258

src/libcore/task/poll.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::result::Result;
1111
pub enum Poll<T> {
1212
/// Represents that a value is immediately ready.
1313
#[stable(feature = "futures_api", since = "1.36.0")]
14+
#[cfg_attr(not(bootstrap), lang = "poll_ready")]
1415
Ready(#[stable(feature = "futures_api", since = "1.36.0")] T),
1516

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

src/librustc/hir/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,20 @@ pub mod map;
88
pub mod upvars;
99

1010
use crate::ty::query::Providers;
11+
use crate::ty::TyCtxt;
12+
use rustc_hir as hir;
13+
use rustc_hir::def_id::DefId;
14+
use rustc_hir::lang_item::LangItem;
15+
use rustc_span::Span;
1116

1217
pub fn provide(providers: &mut Providers<'_>) {
1318
check_attr::provide(providers);
1419
map::provide(providers);
1520
upvars::provide(providers);
1621
}
22+
23+
impl hir::RequireLangItem for TyCtxt<'_> {
24+
fn require_lang_item(self, lang_item: LangItem, span: Span) -> DefId {
25+
self.require_lang_item(lang_item, Some(span))
26+
}
27+
}

src/librustc/ich/impls_hir.rs

-6
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,6 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::def_id::DefIndex {
283283
}
284284
}
285285

286-
impl<'a> HashStable<StableHashingContext<'a>> for crate::middle::lang_items::LangItem {
287-
fn hash_stable(&self, _: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
288-
::std::hash::Hash::hash(self, hasher);
289-
}
290-
}
291-
292286
impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitCandidate {
293287
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
294288
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {

src/librustc/macros.rs

-37
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,3 @@
1-
macro_rules! enum_from_u32 {
2-
($(#[$attr:meta])* pub enum $name:ident {
3-
$($variant:ident = $e:expr,)*
4-
}) => {
5-
$(#[$attr])*
6-
pub enum $name {
7-
$($variant = $e),*
8-
}
9-
10-
impl $name {
11-
pub fn from_u32(u: u32) -> Option<$name> {
12-
$(if u == $name::$variant as u32 {
13-
return Some($name::$variant)
14-
})*
15-
None
16-
}
17-
}
18-
};
19-
($(#[$attr:meta])* pub enum $name:ident {
20-
$($variant:ident,)*
21-
}) => {
22-
$(#[$attr])*
23-
pub enum $name {
24-
$($variant,)*
25-
}
26-
27-
impl $name {
28-
pub fn from_u32(u: u32) -> Option<$name> {
29-
$(if u == $name::$variant as u32 {
30-
return Some($name::$variant)
31-
})*
32-
None
33-
}
34-
}
35-
}
36-
}
37-
381
#[macro_export]
392
macro_rules! bug {
403
() => ( bug!("impossible case reached") );

0 commit comments

Comments
 (0)