Skip to content

Update mod.rs #141935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
4d56e88
Update mod.rs
kiseitai3 Jun 2, 2025
95ff1e4
docs: Small clarification on the usage of `read_to_string` and `read_…
kiseitai3 Jun 2, 2025
ffabd27
docs: Amended usage notes sections in read_to_end/read_to_string. Add…
Jun 4, 2025
28d3682
Merge remote-tracking branch 'origin/141714_stdin_read_to_string_docs…
Jun 4, 2025
f9499d9
Merge branch 'rust-lang:master' into 141714_stdin_read_to_string_docs
kiseitai3 Jun 4, 2025
ac993c4
Merge remote-tracking branch 'origin/141714_stdin_read_to_string_docs…
Jun 4, 2025
a0350b2
Add `iter` macro
oli-obk Feb 27, 2025
c3567c1
std: abort the process on failure to allocate a TLS key
joboet May 23, 2025
10a81ef
compiler: add CanonAbi
workingjubilee Mar 6, 2025
20e554b
compiler: add AbiMap
workingjubilee Mar 6, 2025
80767ea
compiler: use CanonAbi for entry_abi
workingjubilee May 21, 2025
d76aaea
compiler: change Conv to CanonAbi
workingjubilee May 21, 2025
608fe82
cg_llvm: convert to CanonAbi
workingjubilee May 21, 2025
bf29712
cg_clif: convert to CanonAbi
workingjubilee May 21, 2025
3b9480d
cg_gcc: convert to CanonAbi
workingjubilee May 21, 2025
0f617e3
miri: sed to CanonAbi
workingjubilee May 21, 2025
bc91070
bless test for CanonAbi::X86(SysV64) change
workingjubilee May 22, 2025
af990ac
compiler: simplify TargetOptions ABI functions
workingjubilee May 26, 2025
06f3050
compiler: actually remove Conv now that it is irrelevant
workingjubilee May 30, 2025
1830c9b
Use the informative error as the main const eval error message
oli-obk May 28, 2025
cfdc10b
Clarify why we are talking about a failed const eval at a random place
oli-obk May 30, 2025
b4be056
Remove bootstrap cfgs from library/
cuviper Jun 2, 2025
a73ec8a
Remove more library bootstrap
cuviper Jun 2, 2025
7563815
Remove pre-expansion AST stats.
nnethercote Jun 3, 2025
b4308fc
Remove `Path::is_ident`.
nnethercote Jun 3, 2025
0b3d6f5
Add missing `dyn` keywords to tests that do not test for them Part 2
Veykril Jun 3, 2025
3878b69
Rework collect_and_apply to not rely on size hint for optimization
compiler-errors Jun 3, 2025
1fd08c7
Improve the documentation of `Display` and `FromStr`, and their inter…
joshtriplett Feb 7, 2025
f70d304
Add some more description of interactions between `Display` and `From…
joshtriplett Feb 7, 2025
689a2a6
`FromStr`: Rework explanation of `FromStr`/`Display` round-tripping
joshtriplett Jun 3, 2025
58f3c5e
`Display`: Rework explanation of `FromStr`/`Display` round-tripping
joshtriplett Jun 3, 2025
be0705c
Remove `i128` and `u128` from `improper_ctypes_definitions`
tgross35 Feb 20, 2025
9b42771
build dist for x86_64-pc-solaris and sparcv9-sun-solaris
psumbera Mar 4, 2025
88f3ba1
add s390x z17 target features
folkertdev May 19, 2025
49f146c
make `OsString::new` and `PathBuf::new` unstably const
cyrgani May 24, 2025
e620131
index: add method for checking range on DenseBitSet
nia-e May 31, 2025
7cb7542
Use non-2015 edition paths in tests that do not test for their resolu…
Veykril Jun 2, 2025
c5f1c58
bootstrap: don't symlink source dir into stage0 sysroot
lambdageek Jun 4, 2025
fd20ff9
run `check::Std` as the final step
onur-ozkan Jun 4, 2025
c901623
make it possible to request stage 0 std with `Builder::ensure`
onur-ozkan Jun 4, 2025
6d8856e
remove outdated RUSTC_SYSROOT handling for ci-rustc
onur-ozkan Jun 4, 2025
f8e301c
Remove `MetaItemListParser::all_{word,path}_list`, which are unused.
nnethercote May 20, 2025
ecffede
Remove an unnecessary lifetime.
nnethercote May 20, 2025
f42ebfa
Remove `MetaItemParser::{word,word_without_args,path_is}`.
nnethercote May 20, 2025
e3c9bd3
Remove `MetaItemParser::{path,deconstruct}`.
nnethercote May 20, 2025
84c36c4
Rename `MetaItemParser::path_without_args` as `MetaItemParser::path`.
nnethercote May 20, 2025
3135980
Fix incorrect eq_unspanned in TokenStream
chenyukang May 26, 2025
a50cf4d
remove eq_unspanned from TokenStream
chenyukang May 26, 2025
fecd610
remove f16: From<u16>
usamoi Jun 2, 2025
8ac2576
Lightly tweak docs for BTree{Map,Set}::extract_if
rs-sac Jun 2, 2025
72b2ce4
add tests
Qelxiros Jun 3, 2025
d3586db
add tests for negative numbers
Qelxiros Jun 4, 2025
eea5295
Add missing 2015 edition directives
Veykril Jun 3, 2025
374b9c9
Improve some `Visitor` comments.
nnethercote Jun 4, 2025
1454a0d
x86 (32/64): go back to passing SIMD vectors by-ptr
RalfJung May 20, 2025
7e2e608
abi_check: tweak some comments
RalfJung Jun 1, 2025
de794e4
Add link to correct documentation in htmldocck.py
Derukugis Jun 2, 2025
ddab0d8
Fix for async drop inside async gen fn
azhogin Jun 2, 2025
d386874
Use non-2015 edition paths in tests that do not test for their resolu…
Veykril Jun 3, 2025
156fab5
Run wfcheck in one big loop instead of per module
oli-obk Jun 3, 2025
3453e36
Triagebot: Remove `assign.users_on_vacation`
fmease Jun 3, 2025
5f6b5d9
Add a test to reproduce ICE
compiler-errors Jun 3, 2025
bbbd641
Ensure query keys are printed with reduced queries
compiler-errors May 31, 2025
a0c447f
Visit the ident in `PreciseCapturingNonLifetimeArg`.
nnethercote Jun 4, 2025
7100d28
Change `tag_field` to `FieldIdx` in `Variants::Multiple`
scottmcm Jun 4, 2025
e6fa498
Fix incorrect use of "recommend" over "recommended"
Rageking8 Jun 4, 2025
2161b80
Don't refer to 'this tail expression' in expansion.
m-ou-se Jun 4, 2025
22c04b8
Don't refer to 'local binding' in extern macro.
m-ou-se Jun 4, 2025
1ea8699
Move placeholder handling to a proper preprocessing step
amandasystems Apr 29, 2025
99dd99b
Use an enum for SCC representatives, plus other code review
amandasystems May 2, 2025
b497e61
Add Location::file_with_nul
cramertj Jan 3, 2025
2de3006
UnsafePinned: also include the effects of UnsafeCell
RalfJung May 4, 2025
2dfe379
add Miri tests
RalfJung May 4, 2025
b86a201
Do not run PGO/BOLT in x64 Linux alt builds
Kobzol May 30, 2025
fe7aaab
Use 4-core large disk runner for the alt job
Kobzol May 30, 2025
f883bef
update gpu offload build command
ZuseZ4 Jun 3, 2025
2fdb150
use a relative path, so that this also works offline
tshepang Jun 2, 2025
1232f32
distracting indirection
tshepang Jun 2, 2025
a308272
Trivial: dedup word
smanilov Jun 2, 2025
8853bfa
Add title and toc to Async chapter
smanilov Jun 2, 2025
48ca697
Fix some warning blocks that contain Markdown
fmease Jun 2, 2025
5127d48
Simplify long sentence
smanilov Jun 2, 2025
b72bcdd
Preparing for merge from rustc
jieyouxu Jun 3, 2025
b92f05a
cleaned up some tests
Kivooeo Jun 3, 2025
c15f1d8
implement new `x` flag: `--skip-std-check-if-no-download-rustc`
onur-ozkan Jun 3, 2025
cf0dd5d
bless tidy
onur-ozkan Jun 3, 2025
44f8bee
add change-entry
onur-ozkan Jun 3, 2025
b9f8abf
document `skip-std-check-if-no-download-rustc` in rustc-dev-guide
onur-ozkan Jun 4, 2025
1b75e1a
update `skip_std_check_if_no_download_rustc` doc-comments
onur-ozkan Jun 4, 2025
fedc840
jsondoclint: Extract `Command`/`CommandKind` into its own file
aDotInTheVoid May 28, 2025
beb00d4
jsondocck: command -> directive
aDotInTheVoid May 28, 2025
50a8292
jsondocck: Explain what `KNOWN_DIRECTIVE_NAMES` is doing
aDotInTheVoid Jun 5, 2025
376507b
cleaned up some tests
Kivooeo Jun 3, 2025
73325df
rustdoc-json-type: Depend on `serde` and `serde_derive` seperately
aDotInTheVoid Jun 3, 2025
badc578
Report the actual item that evaluation failed for
oli-obk Jun 4, 2025
e62aa1b
bootstrap: Fix file permissions when dereferencing symlinks
smpdt Jun 4, 2025
23b7206
Fix parsing of frontmatters with inner hyphens
matthewjasper Jun 4, 2025
433dc71
Enable `__powitf2` on MSVC
beetrees May 21, 2025
0e9accc
fixed typo in readme
Lorl0rd May 10, 2025
7f11e8f
libm: Clean up unused files
tgross35 Apr 22, 2025
f8d321d
Update `CmpResult` to use a pointer-sized return type
tgross35 May 23, 2025
ef9b35c
Typo in README.md
D-Dario0 May 28, 2025
517f12f
aarch64: Add a note saying why we use `frintx` rather than `frintn`
tgross35 May 28, 2025
36c4228
cleanup: Reuse `MinInt` and `Int` from `libm` in `compiler-builtins`
tgross35 Apr 21, 2025
ca73c15
Reuse `libm`'s `Caat` and `CastFrom` in `compiler-builtins`
tgross35 May 29, 2025
57bdcfa
Remove unneeded C symbols
tgross35 May 28, 2025
2f92d6d
Replace the `nm` symbol check with a Rust implementation
tgross35 Apr 19, 2025
2d2369f
Remove the now-unneeded llvm-tools-preview
tgross35 May 28, 2025
3be8875
Change `compiler-builtins` to edition 2024
tgross35 May 29, 2025
8c85829
symcheck: Print the command to make reproducing errors easier
tgross35 May 29, 2025
eab2c69
Add benchmarks for float parsing and printing
tgross35 May 29, 2025
0384ba3
Run `builtins-test-intrinsics` when possible
tgross35 Mar 19, 2025
9c6c62b
ci: Allow concurrency outside of pull requests
tgross35 May 29, 2025
aaece93
Increase the benchmark rustc version to 2025-05-28
tgross35 May 29, 2025
7f19764
libm-test: Make `extensive` an attribute rather than a test type
tgross35 May 29, 2025
7a1abae
ci: Allow for multiple icount benchmarks in the same run
tgross35 May 29, 2025
d6bc12c
chore: release
github-actions[bot] May 29, 2025
bc08052
Fix new `dead_code` warnings from recent nightlies
tgross35 Jun 1, 2025
d1a4e71
Upgrade all dependencies to the latest available version
tgross35 Jun 1, 2025
ab70932
cleanup: Use `x.biteq(y)` rather than `x.to_bits() == y.to_bits()`
tgross35 Jun 2, 2025
eeb2f6c
ci: Refactor benchmark regression checks
tgross35 Jun 1, 2025
76d8b35
libm-test: Fix unintentional skips in `binop_common`
tgross35 Jun 2, 2025
fb54651
Replace the musl submodule with a download script
tgross35 Jun 4, 2025
d84e222
Add an empty rust-version file
tgross35 May 28, 2025
f3ef1b0
Add tooling for `josh` syncs
tgross35 May 18, 2025
4993831
Update the upstream Rust version
tgross35 Jun 4, 2025
fb80bfd
`panic-handler`: Remove the `no_core` feature
tgross35 Jun 4, 2025
3432db9
Rename `LifetimeSyntax` variants to lang-team-approved names
shepmaster May 9, 2025
8563905
Introduce the `mismatched_lifetime_syntaxes` lint
shepmaster Mar 28, 2025
8587e1a
Replace `elided_named_lifetimes` with `mismatched_lifetime_syntaxes`
shepmaster Mar 17, 2025
7298055
docs: Small clarification on the usage of `read_to_string` and `read_…
kiseitai3 Jun 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4673,6 +4673,7 @@ dependencies = [
"bincode",
"rustc-hash 2.1.1",
"serde",
"serde_derive",
"serde_json",
]

Expand Down
136 changes: 136 additions & 0 deletions compiler/rustc_abi/src/canon_abi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
use std::fmt;

#[cfg(feature = "nightly")]
use rustc_macros::HashStable_Generic;

use crate::ExternAbi;

/// Calling convention to determine codegen
///
/// CanonAbi erases certain distinctions ExternAbi preserves, but remains target-dependent.
/// There are still both target-specific variants and aliasing variants, though much fewer.
/// The reason for this step is the frontend may wish to show an ExternAbi but implement that ABI
/// using a different ABI than the string per se, or describe irrelevant differences, e.g.
/// - extern "system"
/// - extern "cdecl"
/// - extern "C-unwind"
/// In that sense, this erases mere syntactic distinctions to create a canonical *directive*,
/// rather than picking the "actual" ABI.
#[derive(Copy, Clone, Debug)]
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
pub enum CanonAbi {
// NOTE: the use of nested variants for some ABIs is for many targets they don't matter,
// and this pushes the complexity of their reasoning to target-specific code,
// allowing a `match` to easily exhaustively ignore these subcategories of variants.
// Otherwise it is very tempting to avoid matching exhaustively!
C,
Rust,
RustCold,

/// ABIs relevant to 32-bit Arm targets
Arm(ArmCall),
/// ABI relevant to GPUs: the entry point for a GPU kernel
GpuKernel,

/// ABIs relevant to bare-metal interrupt targets
// FIXME(workingjubilee): a particular reason for this nesting is we might not need these?
// interrupt ABIs should have the same properties:
// - uncallable by Rust calls, as LLVM rejects it in most cases
// - uses a preserve-all-registers *callee* convention
// - should always return `-> !` (effectively... it can't use normal `ret`)
// what differs between targets is
// - allowed arguments: x86 differs slightly, having 2-3 arguments which are handled magically
// - may need special prologues/epilogues for some interrupts, without affecting "call ABI"
Interrupt(InterruptKind),

/// ABIs relevant to Windows or x86 targets
X86(X86Call),
}

impl fmt::Display for CanonAbi {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.to_erased_extern_abi().as_str().fmt(f)
}
}

impl CanonAbi {
/// convert to the ExternAbi that *shares a string* with this CanonAbi
///
/// A target-insensitive mapping of CanonAbi to ExternAbi, convenient for "forwarding" impls.
/// Importantly, the set of CanonAbi values is a logical *subset* of ExternAbi values,
/// so this is injective: if you take an ExternAbi to a CanonAbi and back, you have lost data.
const fn to_erased_extern_abi(self) -> ExternAbi {
match self {
CanonAbi::C => ExternAbi::C { unwind: false },
CanonAbi::Rust => ExternAbi::Rust,
CanonAbi::RustCold => ExternAbi::RustCold,
CanonAbi::Arm(arm_call) => match arm_call {
ArmCall::Aapcs => ExternAbi::Aapcs { unwind: false },
ArmCall::CCmseNonSecureCall => ExternAbi::CCmseNonSecureCall,
ArmCall::CCmseNonSecureEntry => ExternAbi::CCmseNonSecureEntry,
},
CanonAbi::GpuKernel => ExternAbi::GpuKernel,
CanonAbi::Interrupt(interrupt_kind) => match interrupt_kind {
InterruptKind::Avr => ExternAbi::AvrInterrupt,
InterruptKind::AvrNonBlocking => ExternAbi::AvrNonBlockingInterrupt,
InterruptKind::Msp430 => ExternAbi::Msp430Interrupt,
InterruptKind::RiscvMachine => ExternAbi::RiscvInterruptM,
InterruptKind::RiscvSupervisor => ExternAbi::RiscvInterruptS,
InterruptKind::X86 => ExternAbi::X86Interrupt,
},
CanonAbi::X86(x86_call) => match x86_call {
X86Call::Fastcall => ExternAbi::Fastcall { unwind: false },
X86Call::Stdcall => ExternAbi::Stdcall { unwind: false },
X86Call::SysV64 => ExternAbi::SysV64 { unwind: false },
X86Call::Thiscall => ExternAbi::Thiscall { unwind: false },
X86Call::Vectorcall => ExternAbi::Vectorcall { unwind: false },
X86Call::Win64 => ExternAbi::Win64 { unwind: false },
},
}
}
}

/// Callee codegen for interrupts
///
/// This is named differently from the "Call" enums because it is different:
/// these "ABI" differences are not relevant to callers, since there is "no caller".
/// These only affect callee codegen. making their categorization as distinct ABIs a bit peculiar.
#[derive(Copy, Clone, Debug)]
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
pub enum InterruptKind {
Avr,
AvrNonBlocking,
Msp430,
RiscvMachine,
RiscvSupervisor,
X86,
}

/// ABIs defined for x86-{32,64}
///
/// One of SysV64 or Win64 may alias the C ABI, and arguably Win64 is cross-platform now?
#[derive(Clone, Copy, Debug)]
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
pub enum X86Call {
/// "fastcall" has both GNU and Windows variants
Fastcall,
/// "stdcall" has both GNU and Windows variants
Stdcall,
SysV64,
Thiscall,
Vectorcall,
Win64,
}

/// ABIs defined for 32-bit Arm
#[derive(Copy, Clone, Debug)]
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
pub enum ArmCall {
Aapcs,
CCmseNonSecureCall,
CCmseNonSecureEntry,
}
7 changes: 2 additions & 5 deletions compiler/rustc_abi/src/extern_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd};
#[cfg(feature = "nightly")]
use rustc_macros::{Decodable, Encodable};

use crate::AbiFromStrErr;

#[cfg(test)]
mod tests;

Expand Down Expand Up @@ -99,11 +101,6 @@ macro_rules! abi_impls {
}
}

#[derive(Debug)]
pub enum AbiFromStrErr {
Unknown,
}

abi_impls! {
ExternAbi = {
C { unwind: false } =><= "C",
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_abi/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
niche_variants,
niche_start,
},
tag_field: 0,
tag_field: FieldIdx::new(0),
variants: IndexVec::new(),
},
fields: FieldsShape::Arbitrary {
Expand Down Expand Up @@ -1072,7 +1072,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
variants: Variants::Multiple {
tag,
tag_encoding: TagEncoding::Direct,
tag_field: 0,
tag_field: FieldIdx::new(0),
variants: IndexVec::new(),
},
fields: FieldsShape::Arbitrary {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_abi/src/layout/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub(super) fn layout<
// Build a prefix layout, including "promoting" all ineligible
// locals as part of the prefix. We compute the layout of all of
// these fields at once to get optimal packing.
let tag_index = prefix_layouts.len();
let tag_index = prefix_layouts.next_index();

// `variant_fields` already accounts for the reserved variants, so no need to add them.
let max_discr = (variant_fields.len() - 1) as u128;
Expand Down Expand Up @@ -187,7 +187,7 @@ pub(super) fn layout<

// "a" (`0..b_start`) and "b" (`b_start..`) correspond to
// "outer" and "promoted" fields respectively.
let b_start = FieldIdx::new(tag_index + 1);
let b_start = tag_index.plus(1);
let offsets_b = IndexVec::from_raw(offsets.raw.split_off(b_start.index()));
let offsets_a = offsets;

Expand Down
15 changes: 12 additions & 3 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_Generic};

mod callconv;
mod canon_abi;
mod extern_abi;
mod layout;
#[cfg(test)]
mod tests;

mod extern_abi;

pub use callconv::{Heterogeneous, HomogeneousAggregate, Reg, RegKind};
pub use canon_abi::{ArmCall, CanonAbi, InterruptKind, X86Call};
pub use extern_abi::{ExternAbi, all_names};
#[cfg(feature = "nightly")]
pub use layout::{FIRST_VARIANT, FieldIdx, Layout, TyAbiInterface, TyAndLayout, VariantIdx};
Expand Down Expand Up @@ -1572,7 +1573,7 @@ pub enum Variants<FieldIdx: Idx, VariantIdx: Idx> {
Multiple {
tag: Scalar,
tag_encoding: TagEncoding<VariantIdx>,
tag_field: usize,
tag_field: FieldIdx,
variants: IndexVec<VariantIdx, LayoutData<FieldIdx, VariantIdx>>,
},
}
Expand Down Expand Up @@ -1895,3 +1896,11 @@ pub enum StructKind {
/// A univariant, but with a prefix of an arbitrary size & alignment (e.g., enum tag).
Prefixed(Size, Align),
}

#[derive(Clone, Debug)]
pub enum AbiFromStrErr {
/// not a known ABI
Unknown,
/// no "-unwind" variant can be used here
NoExplicitUnwind,
}
22 changes: 9 additions & 13 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,15 @@ pub struct Path {

impl PartialEq<Symbol> for Path {
#[inline]
fn eq(&self, symbol: &Symbol) -> bool {
matches!(&self.segments[..], [segment] if segment.ident.name == *symbol)
fn eq(&self, name: &Symbol) -> bool {
if let [segment] = self.segments.as_ref()
&& segment.args.is_none()
&& segment.ident.name == *name
{
true
} else {
false
}
}
}

Expand All @@ -120,17 +127,6 @@ impl Path {
Path { segments: thin_vec![PathSegment::from_ident(ident)], span: ident.span, tokens: None }
}

pub fn is_ident(&self, name: Symbol) -> bool {
if let [segment] = self.segments.as_ref()
&& segment.args.is_none()
&& segment.ident.name == name
{
true
} else {
false
}
}

pub fn is_global(&self) -> bool {
self.segments.first().is_some_and(|segment| segment.ident.name == kw::PathRoot)
}
Expand Down
16 changes: 3 additions & 13 deletions compiler/rustc_ast/src/tokenstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ impl TokenTree {
match (self, other) {
(TokenTree::Token(token, _), TokenTree::Token(token2, _)) => token.kind == token2.kind,
(TokenTree::Delimited(.., delim, tts), TokenTree::Delimited(.., delim2, tts2)) => {
delim == delim2 && tts.eq_unspanned(tts2)
delim == delim2
&& tts.len() == tts2.len()
&& tts.iter().zip(tts2.iter()).all(|(a, b)| a.eq_unspanned(b))
}
_ => false,
}
Expand Down Expand Up @@ -694,18 +696,6 @@ impl TokenStream {
TokenStreamIter::new(self)
}

/// Compares two `TokenStream`s, checking equality without regarding span information.
pub fn eq_unspanned(&self, other: &TokenStream) -> bool {
let mut iter1 = self.iter();
let mut iter2 = other.iter();
for (tt1, tt2) in iter::zip(&mut iter1, &mut iter2) {
if !tt1.eq_unspanned(tt2) {
return false;
}
}
iter1.next().is_none() && iter2.next().is_none()
}

/// Create a token stream containing a single token with alone spacing. The
/// spacing used for the final token in a constructed stream doesn't matter
/// because it's never used. In practice we arbitrarily use
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ pub enum LifetimeCtxt {
/// explicitly, you need to override each method. (And you also need
/// to monitor future changes to `Visitor` in case a new method with a
/// new default implementation gets introduced.)
///
/// Every `walk_*` method uses deconstruction to access fields of structs and
/// enums. This will result in a compile error if a field is added, which makes
/// it more likely the appropriate visit call will be added for it.
pub trait Visitor<'ast>: Sized {
/// The result type of the `visit_*` methods. Can be either `()`,
/// or `ControlFlow<T>`.
Expand Down
15 changes: 8 additions & 7 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::assert_matches::assert_matches;
use std::ops::ControlFlow;
use std::sync::Arc;

Expand Down Expand Up @@ -1199,11 +1198,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
let closure_def_id = self.local_def_id(closure_id);
let (binder_clause, generic_params) = self.lower_closure_binder(binder);

assert_matches!(
coroutine_kind,
CoroutineKind::Async { .. },
"only async closures are supported currently"
);
let coroutine_desugaring = match coroutine_kind {
CoroutineKind::Async { .. } => hir::CoroutineDesugaring::Async,
CoroutineKind::Gen { .. } => hir::CoroutineDesugaring::Gen,
CoroutineKind::AsyncGen { span, .. } => {
span_bug!(span, "only async closures and `iter!` closures are supported currently")
}
};

let body = self.with_new_scopes(fn_decl_span, |this| {
let inner_decl =
Expand Down Expand Up @@ -1247,7 +1248,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// Lower this as a `CoroutineClosure`. That will ensure that HIR typeck
// knows that a `FnDecl` output type like `-> &str` actually means
// "coroutine that returns &str", rather than directly returning a `&str`.
kind: hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async),
kind: hir::ClosureKind::CoroutineClosure(coroutine_desugaring),
constness: hir::Constness::NotConst,
});
hir::ExprKind::Closure(c)
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
};
let span = self.tcx.sess.source_map().start_point(t.span).shrink_to_hi();
let region = Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id };
(region, LifetimeSyntax::Hidden)
(region, LifetimeSyntax::Implicit)
}
};
self.lower_lifetime(&region, LifetimeSource::Reference, syntax)
Expand Down Expand Up @@ -1790,7 +1790,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
id,
Ident::new(kw::UnderscoreLifetime, span),
LifetimeSource::Path { angle_brackets },
LifetimeSyntax::Hidden,
LifetimeSyntax::Implicit,
)
}

Expand Down Expand Up @@ -2422,7 +2422,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
Ident::new(kw::UnderscoreLifetime, self.lower_span(span)),
hir::LifetimeKind::ImplicitObjectLifetimeDefault,
LifetimeSource::Other,
LifetimeSyntax::Hidden,
LifetimeSyntax::Implicit,
);
debug!("elided_dyn_bound: r={:?}", r);
self.arena.alloc(r)
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,12 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
for span in spans {
if (!visitor.features.coroutines() && !span.allows_unstable(sym::coroutines))
&& (!visitor.features.gen_blocks() && !span.allows_unstable(sym::gen_blocks))
&& (!visitor.features.yield_expr() && !span.allows_unstable(sym::yield_expr))
{
#[allow(rustc::untranslatable_diagnostic)]
// Don't know which of the two features to include in the
// error message, so I am arbitrarily picking one.
feature_err(&visitor.sess, sym::coroutines, *span, "yield syntax is experimental")
// Emit yield_expr as the error, since that will be sufficient. You can think of it
// as coroutines and gen_blocks imply yield_expr.
feature_err(&visitor.sess, sym::yield_expr, *span, "yield syntax is experimental")
.emit();
}
}
Expand Down
Loading
Loading