Skip to content

Commit 3ead112

Browse files
committed
Auto merge of #159046 - jhpratt:rollup-mqQhHMX, r=jhpratt
Rollup of 24 pull requests Successful merges: - #150946 (intrinsics: Add a fallback for non-const libm float functions) - #158541 (Move `std::io::Write` to `core::io`) - #156027 (Consider captured regions for opaque type region liveness.) - #156370 (Reject linked dylib EII default overrides) - #156508 (Infer all anonymous lifetimes in assoc consts as `'static`) - #157561 (rustdoc: do not include extra stuff in span) - #158617 (allow mGCA const arguments to fall back to anon consts) - #158645 (Fix splat ICEs and ban it in closures) - #158859 (Improve `-Zls` diagnostic message on `.rs` files) - #158988 (Redo `TokenStreamIter`) - #158347 (Improve generic parameters handling for #[diagnostic::on_const]) - #158384 (Allow BackwardIncompatibleDropHint in polonius legacy) - #158722 (delegation: do not always inherit `ConstArgHasType` predicates) - #158739 (view-types: HIR lowering) - #158877 (borrowck: Keep returned `path` from `best_blame_constraint()` consistent) - #158883 (tests: fix enum-match.rs to handle LLVM 23) - #158886 (Add documentation for the `no_std` attribute) - #158940 (Implement feature `char_to_u32`) - #158951 (Merge three `MaxUniverse`s into one) - #158960 (Fix bootstrap submodule path prefix matching) - #158961 (Reapply "LLVM 23: Run AssignGUIDPass in some places") - #158995 (Use REST API in linkchecker script) - #158996 ([compiler] Implement `PartialOrd` via `Ord` for `Span` and newtype_indexes) - #159036 (bootstrap: expand '@argfile' arguments to rustc shim)
2 parents d465559 + 589dd84 commit 3ead112

283 files changed

Lines changed: 6347 additions & 2871 deletions

File tree

Some content is hidden

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

compiler/rustc_ast/src/ast.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,15 +1378,6 @@ pub enum UnsafeSource {
13781378
UserProvided,
13791379
}
13801380

1381-
/// Track whether under `feature(min_generic_const_args)` this anon const
1382-
/// was explicitly disambiguated as an anon const or not through the use of
1383-
/// `const { ... }` syntax.
1384-
#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy, Walkable)]
1385-
pub enum MgcaDisambiguation {
1386-
AnonConst,
1387-
Direct,
1388-
}
1389-
13901381
/// A constant (expression) that's not an item or associated item,
13911382
/// but needs its own `DefId` for type-checking, const-eval, etc.
13921383
/// These are usually found nested inside types (e.g., array lengths)
@@ -1396,7 +1387,6 @@ pub enum MgcaDisambiguation {
13961387
pub struct AnonConst {
13971388
pub id: NodeId,
13981389
pub value: Box<Expr>,
1399-
pub mgca_disambiguation: MgcaDisambiguation,
14001390
}
14011391

14021392
/// An expression.
@@ -1627,6 +1617,7 @@ impl Expr {
16271617
| ExprKind::UnsafeBinderCast(..)
16281618
| ExprKind::While(..)
16291619
| ExprKind::Yield(YieldKind::Postfix(..))
1620+
| ExprKind::DirectConstArg(..)
16301621
| ExprKind::Err(_)
16311622
| ExprKind::Dummy => prefix_attrs_precedence(&self.attrs),
16321623
}
@@ -1920,6 +1911,9 @@ pub enum ExprKind {
19201911

19211912
UnsafeBinderCast(UnsafeBinderCastKind, Box<Expr>, Option<Box<Ty>>),
19221913

1914+
/// An mGCA `direct_const_arg!()` expression.
1915+
DirectConstArg(Box<Expr>),
1916+
19231917
/// Placeholder for an expression that wasn't syntactically well formed in some way.
19241918
Err(ErrorGuaranteed),
19251919

@@ -2566,6 +2560,8 @@ pub enum TyKind {
25662560
FieldOf(Box<Ty>, Option<Ident>, Ident),
25672561
/// A view of a type. `T.{ field_1, field_2 }`.
25682562
View(Box<Ty>, #[visitable(ignore)] ThinVec<Ident>),
2563+
/// An mGCA `direct_const_arg!()` expression.
2564+
DirectConstArg(Box<Expr>),
25692565
/// Sometimes we need a dummy value when no error has occurred.
25702566
Dummy,
25712567
/// Placeholder for a kind that has failed to be defined.
@@ -3066,6 +3062,9 @@ impl FnDecl {
30663062
/// Must have the same value as `FnSigKind::NO_SPLATTED_ARG_INDEX` and `FnDeclFlags::NO_SPLATTED_ARG_INDEX`.
30673063
pub const NO_SPLATTED_ARG_INDEX: u8 = u8::MAX;
30683064

3065+
/// The maximum valid splatted argument index.
3066+
pub const MAX_VALID_SPLATTED_ARG_INDEX: u8 = Self::NO_SPLATTED_ARG_INDEX - 1;
3067+
30693068
/// Returns a splatted argument index, if any are present.
30703069
pub fn splatted(&self) -> Option<u8> {
30713070
self.inputs.iter().enumerate().find_map(|(index, arg)| {

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ use crate::ast_traits::{HasAttrs, HasTokens};
2222
use crate::token::{self, Delimiter, Token, TokenKind};
2323
use crate::{AttrVec, Attribute};
2424

25+
#[cfg(test)]
26+
mod tests;
27+
2528
/// Part of a `TokenStream`.
2629
#[derive(Debug, Clone, PartialEq, Eq, Hash, Encodable, Decodable, StableHash)]
2730
pub enum TokenTree {
@@ -833,32 +836,30 @@ impl StableHash for TokenStream {
833836
}
834837

835838
#[derive(Clone)]
836-
pub struct TokenStreamIter<'t> {
837-
stream: &'t TokenStream,
838-
index: usize,
839-
}
839+
pub struct TokenStreamIter<'t>(std::slice::Iter<'t, TokenTree>);
840840

841841
impl<'t> TokenStreamIter<'t> {
842842
fn new(stream: &'t TokenStream) -> Self {
843-
TokenStreamIter { stream, index: 0 }
843+
TokenStreamIter(stream.0.as_slice().iter())
844844
}
845845

846846
// Peeking could be done via `Peekable`, but most iterators need peeking,
847847
// and this is simple and avoids the need to use `peekable` and `Peekable`
848848
// at all the use sites.
849849
pub fn peek(&self) -> Option<&'t TokenTree> {
850-
self.stream.0.get(self.index)
850+
self.0.as_slice().first()
851851
}
852852
}
853853

854854
impl<'t> Iterator for TokenStreamIter<'t> {
855855
type Item = &'t TokenTree;
856856

857857
fn next(&mut self) -> Option<&'t TokenTree> {
858-
self.stream.0.get(self.index).map(|tree| {
859-
self.index += 1;
860-
tree
861-
})
858+
self.0.next()
859+
}
860+
861+
fn size_hint(&self) -> (usize, Option<usize>) {
862+
self.0.size_hint()
862863
}
863864
}
864865

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use rustc_span::DUMMY_SP;
2+
3+
use crate::token::TokenKind;
4+
use crate::tokenstream::TokenStream;
5+
6+
#[test]
7+
fn test_token_stream_iter() {
8+
let ts = TokenStream::token_alone(TokenKind::Eq, DUMMY_SP);
9+
assert_eq!(ts.len(), 1);
10+
11+
let iter = ts.iter();
12+
assert_eq!(iter.size_hint(), (1, Some(1)));
13+
}

compiler/rustc_ast/src/util/classify.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ pub fn leading_labeled_expr(mut expr: &ast::Expr) -> bool {
155155
| Yeet(..)
156156
| Yield(..)
157157
| UnsafeBinderCast(..)
158+
| DirectConstArg(..)
158159
| Err(..)
159160
| Dummy => return false,
160161
}
@@ -240,6 +241,7 @@ pub fn expr_trailing_brace(mut expr: &ast::Expr) -> Option<TrailingBrace<'_>> {
240241
| Try(_)
241242
| Yeet(None)
242243
| UnsafeBinderCast(..)
244+
| DirectConstArg(..)
243245
| Err(_)
244246
| Dummy => {
245247
break None;
@@ -301,9 +303,10 @@ fn type_trailing_braced_mac_call(mut ty: &ast::Ty) -> Option<&ast::MacCall> {
301303
| ast::TyKind::CVarArgs
302304
| ast::TyKind::Pat(..)
303305
| ast::TyKind::FieldOf(..)
306+
| ast::TyKind::View(..)
307+
| ast::TyKind::DirectConstArg(..)
304308
| ast::TyKind::Dummy
305-
| ast::TyKind::Err(..)
306-
| ast::TyKind::View(..) => break None,
309+
| ast::TyKind::Err(..) => break None,
307310
}
308311
}
309312
}

compiler/rustc_ast/src/visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ macro_rules! common_visitor_and_walkers {
418418
UnsafeBinderCastKind,
419419
BinOpKind,
420420
BlockCheckMode,
421-
MgcaDisambiguation,
422421
BorrowKind,
423422
BoundAsyncness,
424423
BoundConstness,
@@ -1074,6 +1073,8 @@ macro_rules! common_visitor_and_walkers {
10741073
visit_visitable!($($mut)? vis, bytes),
10751074
ExprKind::UnsafeBinderCast(kind, expr, ty) =>
10761075
visit_visitable!($($mut)? vis, kind, expr, ty),
1076+
ExprKind::DirectConstArg(expr) =>
1077+
visit_visitable!($($mut)? vis, expr),
10771078
ExprKind::Err(_guar) => {}
10781079
ExprKind::Dummy => {}
10791080
}

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
498498
}
499499

500500
ExprKind::MacCall(_) => panic!("{:?} shouldn't exist here", e.span),
501+
502+
ExprKind::DirectConstArg(_) => {
503+
let e = self
504+
.tcx
505+
.dcx()
506+
.struct_span_err(
507+
e.span,
508+
"expected expression, found `direct_const_arg!()` constant",
509+
)
510+
.emit();
511+
hir::ExprKind::Err(e)
512+
}
501513
};
502514

503515
hir::Expr { hir_id: expr_hir_id, kind, span }
@@ -599,11 +611,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
599611
arg
600612
};
601613

602-
let anon_const = AnonConst {
603-
id: node_id,
604-
value: const_value,
605-
mgca_disambiguation: MgcaDisambiguation::AnonConst,
606-
};
614+
let anon_const = AnonConst { id: node_id, value: const_value };
607615
generic_args.push(AngleBracketedArg::Arg(GenericArg::Const(anon_const)));
608616
} else {
609617
real_args.push(arg);

0 commit comments

Comments
 (0)