Skip to content

Commit 792c645

Browse files
committed
Auto merge of #75145 - davidtwco:issue-60607-preallocate-defid-for-lang-items, r=petrochenkov
Reference lang items during AST lowering Fixes #60607 and fixes #61019. This PR introduces `QPath::LangItem` to the HIR and uses it in AST lowering instead of constructing a `hir::Path` from a slice of symbols: - Credit for much of this work goes to @matthewjasper, I basically just [rebased their earlier work](matthewjasper@a227c70#diff-c0f791ead38d2d02916faaad0f56f41d). - ~~Changes to Clippy might not be correct, they compile but attempting to run tests through `./x.py` produced failures which appeared spurious, so I didn't run any clippy tests.~~ - Changes to save analysis might not be correct - tests pass but I don't have a lot of confidence in those changes being correct. - I've used `GenericBounds::LangItemTrait` rather than changing `PolyTraitRef`, as suggested by @matthewjasper [in this comment](matthewjasper@a227c70#r40107992) but I'd prefer that be left for a follow-up. - I've split things into smaller commits fairly arbitrarily to make the diff easier to review, each commit should compile but might not pass tests until the final commit. r? @oli-obk cc @matthewjasper
2 parents 33c96b4 + f1ce294 commit 792c645

Some content is hidden

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

61 files changed

+588
-458
lines changed

library/core/src/convert/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ pub trait Into<T>: Sized {
385385
))]
386386
pub trait From<T>: Sized {
387387
/// Performs the conversion.
388+
#[cfg_attr(not(bootstrap), lang = "from")]
388389
#[stable(feature = "rust1", since = "1.0.0")]
389390
fn from(_: T) -> Self;
390391
}

library/core/src/future/future.rs

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub trait Future {
9696
/// [`Context`]: ../task/struct.Context.html
9797
/// [`Waker`]: ../task/struct.Waker.html
9898
/// [`Waker::wake`]: ../task/struct.Waker.html#method.wake
99+
#[cfg_attr(not(bootstrap), lang = "poll")]
99100
#[stable(feature = "futures_api", since = "1.36.0")]
100101
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>;
101102
}

library/core/src/future/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ unsafe impl Sync for ResumeTy {}
5353
/// This function returns a `GenFuture` underneath, but hides it in `impl Trait` to give
5454
/// better error messages (`impl Future` rather than `GenFuture<[closure.....]>`).
5555
// This is `const` to avoid extra errors after we recover from `const async fn`
56+
#[cfg_attr(not(bootstrap), lang = "from_generator")]
5657
#[doc(hidden)]
5758
#[unstable(feature = "gen_future", issue = "50547")]
5859
#[inline]
@@ -85,6 +86,7 @@ where
8586
GenFuture(gen)
8687
}
8788

89+
#[cfg_attr(not(bootstrap), lang = "get_context")]
8890
#[doc(hidden)]
8991
#[unstable(feature = "gen_future", issue = "50547")]
9092
#[inline]

library/core/src/iter/traits/collect.rs

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

library/core/src/iter/traits/iterator.rs

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ pub trait Iterator {
129129
/// assert_eq!(None, iter.next());
130130
/// assert_eq!(None, iter.next());
131131
/// ```
132+
#[cfg_attr(not(bootstrap), lang = "next")]
132133
#[stable(feature = "rust1", since = "1.0.0")]
133134
fn next(&mut self) -> Option<Self::Item>;
134135

library/core/src/ops/range.rs

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use crate::hash::Hash;
3838
/// [`IntoIterator`]: ../iter/trait.Iterator.html
3939
/// [`Iterator`]: ../iter/trait.IntoIterator.html
4040
/// [slicing index]: ../slice/trait.SliceIndex.html
41+
#[cfg_attr(not(bootstrap), lang = "RangeFull")]
4142
#[doc(alias = "..")]
4243
#[derive(Copy, Clone, Default, PartialEq, Eq, Hash)]
4344
#[stable(feature = "rust1", since = "1.0.0")]
@@ -70,6 +71,7 @@ impl fmt::Debug for RangeFull {
7071
/// assert_eq!(arr[1.. 3], [ 1,2 ]); // Range
7172
/// assert_eq!(arr[1..=3], [ 1,2,3 ]);
7273
/// ```
74+
#[cfg_attr(not(bootstrap), lang = "Range")]
7375
#[doc(alias = "..")]
7476
#[derive(Clone, Default, PartialEq, Eq, Hash)] // not Copy -- see #27186
7577
#[stable(feature = "rust1", since = "1.0.0")]
@@ -178,6 +180,7 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
178180
/// ```
179181
///
180182
/// [`Iterator`]: ../iter/trait.IntoIterator.html
183+
#[cfg_attr(not(bootstrap), lang = "RangeFrom")]
181184
#[doc(alias = "..")]
182185
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
183186
#[stable(feature = "rust1", since = "1.0.0")]
@@ -260,6 +263,7 @@ impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
260263
/// [`IntoIterator`]: ../iter/trait.Iterator.html
261264
/// [`Iterator`]: ../iter/trait.IntoIterator.html
262265
/// [slicing index]: ../slice/trait.SliceIndex.html
266+
#[cfg_attr(not(bootstrap), lang = "RangeTo")]
263267
#[doc(alias = "..")]
264268
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
265269
#[stable(feature = "rust1", since = "1.0.0")]
@@ -328,6 +332,7 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
328332
/// assert_eq!(arr[1.. 3], [ 1,2 ]);
329333
/// assert_eq!(arr[1..=3], [ 1,2,3 ]); // RangeInclusive
330334
/// ```
335+
#[cfg_attr(not(bootstrap), lang = "RangeInclusive")]
331336
#[doc(alias = "..=")]
332337
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
333338
#[stable(feature = "inclusive_range", since = "1.26.0")]
@@ -359,6 +364,7 @@ impl<Idx> RangeInclusive<Idx> {
359364
///
360365
/// assert_eq!(3..=5, RangeInclusive::new(3, 5));
361366
/// ```
367+
#[cfg_attr(not(bootstrap), lang = "range_inclusive_new")]
362368
#[stable(feature = "inclusive_range_methods", since = "1.27.0")]
363369
#[inline]
364370
#[rustc_promotable]
@@ -555,6 +561,7 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
555561
/// [`IntoIterator`]: ../iter/trait.Iterator.html
556562
/// [`Iterator`]: ../iter/trait.IntoIterator.html
557563
/// [slicing index]: ../slice/trait.SliceIndex.html
564+
#[cfg_attr(not(bootstrap), lang = "RangeToInclusive")]
558565
#[doc(alias = "..=")]
559566
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
560567
#[stable(feature = "inclusive_range", since = "1.26.0")]

library/core/src/ops/try.rs

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

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

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

library/core/src/option.rs

+2
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,11 @@ use crate::{
144144
#[stable(feature = "rust1", since = "1.0.0")]
145145
pub enum Option<T> {
146146
/// No value
147+
#[cfg_attr(not(bootstrap), lang = "None")]
147148
#[stable(feature = "rust1", since = "1.0.0")]
148149
None,
149150
/// Some value `T`
151+
#[cfg_attr(not(bootstrap), lang = "Some")]
150152
#[stable(feature = "rust1", since = "1.0.0")]
151153
Some(#[stable(feature = "rust1", since = "1.0.0")] T),
152154
}

library/core/src/pin.rs

+1
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ impl<P: Deref> Pin<P> {
569569
/// ```
570570
///
571571
/// [`mem::swap`]: ../../std/mem/fn.swap.html
572+
#[cfg_attr(not(bootstrap), lang = "new_unchecked")]
572573
#[stable(feature = "pin", since = "1.33.0")]
573574
#[inline(always)]
574575
pub unsafe fn new_unchecked(pointer: P) -> Pin<P> {

library/core/src/result.rs

+2
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,12 @@ use crate::{convert, fmt};
246246
#[stable(feature = "rust1", since = "1.0.0")]
247247
pub enum Result<T, E> {
248248
/// Contains the success value
249+
#[cfg_attr(not(bootstrap), lang = "Ok")]
249250
#[stable(feature = "rust1", since = "1.0.0")]
250251
Ok(#[stable(feature = "rust1", since = "1.0.0")] T),
251252

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

library/core/src/task/poll.rs

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

@@ -18,6 +19,7 @@ pub enum Poll<T> {
1819
/// When a function returns `Pending`, the function *must* also
1920
/// ensure that the current task is scheduled to be awoken when
2021
/// progress can be made.
22+
#[cfg_attr(not(bootstrap), lang = "Pending")]
2123
#[stable(feature = "futures_api", since = "1.36.0")]
2224
Pending,
2325
}

0 commit comments

Comments
 (0)