Skip to content

Commit 8c0b1fc

Browse files
committed
Auto merge of #121591 - matthiaskrgr:rollup-8wfhh3v, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #119590 (Stabilize `cfg_target_abi`) - #120805 (make non-PartialEq-typed consts as patterns a hard error) - #121060 (Add newtypes for bool fields/params/return types) - #121284 (Add test cases for inlining compiler-private items) - #121324 (pattern_analysis: factor out unspecialization) - #121409 (Prevent cycle in implied predicates computation) - #121513 (Fix sgx unit test compilation) - #121570 (Make most bootstrap step types !Copy) - #121586 (Don't use `unwrap()` in `ArrayIntoIter` lint when typeck fails) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 34aab62 + a442388 commit 8c0b1fc

File tree

80 files changed

+615
-544
lines changed

Some content is hidden

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

80 files changed

+615
-544
lines changed

compiler/rustc_ast/src/token.rs

+28-10
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl Lit {
107107
/// Keep this in sync with `Token::can_begin_literal_or_bool` excluding unary negation.
108108
pub fn from_token(token: &Token) -> Option<Lit> {
109109
match token.uninterpolate().kind {
110-
Ident(name, false) if name.is_bool_lit() => Some(Lit::new(Bool, name, None)),
110+
Ident(name, IdentIsRaw::No) if name.is_bool_lit() => Some(Lit::new(Bool, name, None)),
111111
Literal(token_lit) => Some(token_lit),
112112
Interpolated(ref nt)
113113
if let NtExpr(expr) | NtLiteral(expr) = &nt.0
@@ -183,7 +183,7 @@ impl LitKind {
183183
}
184184
}
185185

186-
pub fn ident_can_begin_expr(name: Symbol, span: Span, is_raw: bool) -> bool {
186+
pub fn ident_can_begin_expr(name: Symbol, span: Span, is_raw: IdentIsRaw) -> bool {
187187
let ident_token = Token::new(Ident(name, is_raw), span);
188188

189189
!ident_token.is_reserved_ident()
@@ -214,7 +214,7 @@ pub fn ident_can_begin_expr(name: Symbol, span: Span, is_raw: bool) -> bool {
214214
.contains(&name)
215215
}
216216

217-
fn ident_can_begin_type(name: Symbol, span: Span, is_raw: bool) -> bool {
217+
fn ident_can_begin_type(name: Symbol, span: Span, is_raw: IdentIsRaw) -> bool {
218218
let ident_token = Token::new(Ident(name, is_raw), span);
219219

220220
!ident_token.is_reserved_ident()
@@ -223,6 +223,24 @@ fn ident_can_begin_type(name: Symbol, span: Span, is_raw: bool) -> bool {
223223
.contains(&name)
224224
}
225225

226+
#[derive(PartialEq, Encodable, Decodable, Debug, Copy, Clone, HashStable_Generic)]
227+
pub enum IdentIsRaw {
228+
No,
229+
Yes,
230+
}
231+
232+
impl From<bool> for IdentIsRaw {
233+
fn from(b: bool) -> Self {
234+
if b { Self::Yes } else { Self::No }
235+
}
236+
}
237+
238+
impl From<IdentIsRaw> for bool {
239+
fn from(is_raw: IdentIsRaw) -> bool {
240+
matches!(is_raw, IdentIsRaw::Yes)
241+
}
242+
}
243+
226244
// SAFETY: due to the `Clone` impl below, all fields of all variants other than
227245
// `Interpolated` must impl `Copy`.
228246
#[derive(PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
@@ -298,7 +316,7 @@ pub enum TokenKind {
298316
/// Do not forget about `NtIdent` when you want to match on identifiers.
299317
/// It's recommended to use `Token::(ident,uninterpolate,uninterpolated_span)` to
300318
/// treat regular and interpolated identifiers in the same way.
301-
Ident(Symbol, /* is_raw */ bool),
319+
Ident(Symbol, IdentIsRaw),
302320
/// Lifetime identifier token.
303321
/// Do not forget about `NtLifetime` when you want to match on lifetime identifiers.
304322
/// It's recommended to use `Token::(lifetime,uninterpolate,uninterpolated_span)` to
@@ -411,7 +429,7 @@ impl Token {
411429

412430
/// Recovers a `Token` from an `Ident`. This creates a raw identifier if necessary.
413431
pub fn from_ast_ident(ident: Ident) -> Self {
414-
Token::new(Ident(ident.name, ident.is_raw_guess()), ident.span)
432+
Token::new(Ident(ident.name, ident.is_raw_guess().into()), ident.span)
415433
}
416434

417435
/// For interpolated tokens, returns a span of the fragment to which the interpolated
@@ -567,7 +585,7 @@ impl Token {
567585
pub fn can_begin_literal_maybe_minus(&self) -> bool {
568586
match self.uninterpolate().kind {
569587
Literal(..) | BinOp(Minus) => true,
570-
Ident(name, false) if name.is_bool_lit() => true,
588+
Ident(name, IdentIsRaw::No) if name.is_bool_lit() => true,
571589
Interpolated(ref nt) => match &nt.0 {
572590
NtLiteral(_) => true,
573591
NtExpr(e) => match &e.kind {
@@ -602,7 +620,7 @@ impl Token {
602620

603621
/// Returns an identifier if this token is an identifier.
604622
#[inline]
605-
pub fn ident(&self) -> Option<(Ident, /* is_raw */ bool)> {
623+
pub fn ident(&self) -> Option<(Ident, IdentIsRaw)> {
606624
// We avoid using `Token::uninterpolate` here because it's slow.
607625
match &self.kind {
608626
&Ident(name, is_raw) => Some((Ident::new(name, self.span), is_raw)),
@@ -755,7 +773,7 @@ impl Token {
755773
/// Returns `true` if the token is a non-raw identifier for which `pred` holds.
756774
pub fn is_non_raw_ident_where(&self, pred: impl FnOnce(Ident) -> bool) -> bool {
757775
match self.ident() {
758-
Some((id, false)) => pred(id),
776+
Some((id, IdentIsRaw::No)) => pred(id),
759777
_ => false,
760778
}
761779
}
@@ -806,7 +824,7 @@ impl Token {
806824
_ => return None,
807825
},
808826
SingleQuote => match joint.kind {
809-
Ident(name, false) => Lifetime(Symbol::intern(&format!("'{name}"))),
827+
Ident(name, IdentIsRaw::No) => Lifetime(Symbol::intern(&format!("'{name}"))),
810828
_ => return None,
811829
},
812830

@@ -836,7 +854,7 @@ pub enum Nonterminal {
836854
NtPat(P<ast::Pat>),
837855
NtExpr(P<ast::Expr>),
838856
NtTy(P<ast::Ty>),
839-
NtIdent(Ident, /* is_raw */ bool),
857+
NtIdent(Ident, IdentIsRaw),
840858
NtLifetime(Ident),
841859
NtLiteral(P<ast::Expr>),
842860
/// Stuff inside brackets for attributes

compiler/rustc_ast/src/tokenstream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ impl TokenStream {
656656
DelimSpacing::new(Spacing::JointHidden, Spacing::Alone),
657657
Delimiter::Bracket,
658658
[
659-
TokenTree::token_alone(token::Ident(sym::doc, false), span),
659+
TokenTree::token_alone(token::Ident(sym::doc, token::IdentIsRaw::No), span),
660660
TokenTree::token_alone(token::Eq, span),
661661
TokenTree::token_alone(
662662
TokenKind::lit(token::StrRaw(num_of_hashes), data, None),

compiler/rustc_ast_pretty/src/pprust/state.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ fn space_between(tt1: &TokenTree, tt2: &TokenTree) -> bool {
185185

186186
// IDENT + `!`: `println!()`, but `if !x { ... }` needs a space after the `if`
187187
(Tok(Token { kind: Ident(sym, is_raw), span }, _), Tok(Token { kind: Not, .. }, _))
188-
if !Ident::new(*sym, *span).is_reserved() || *is_raw =>
188+
if !Ident::new(*sym, *span).is_reserved() || matches!(is_raw, IdentIsRaw::Yes) =>
189189
{
190190
false
191191
}
@@ -197,7 +197,7 @@ fn space_between(tt1: &TokenTree, tt2: &TokenTree) -> bool {
197197
|| *sym == kw::Fn
198198
|| *sym == kw::SelfUpper
199199
|| *sym == kw::Pub
200-
|| *is_raw =>
200+
|| matches!(is_raw, IdentIsRaw::Yes) =>
201201
{
202202
false
203203
}
@@ -731,7 +731,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
731731
token::NtBlock(e) => self.block_to_string(e),
732732
token::NtStmt(e) => self.stmt_to_string(e),
733733
token::NtPat(e) => self.pat_to_string(e),
734-
token::NtIdent(e, is_raw) => IdentPrinter::for_ast_ident(*e, *is_raw).to_string(),
734+
&token::NtIdent(e, is_raw) => IdentPrinter::for_ast_ident(e, is_raw.into()).to_string(),
735735
token::NtLifetime(e) => e.to_string(),
736736
token::NtLiteral(e) => self.expr_to_string(e),
737737
token::NtVis(e) => self.vis_to_string(e),
@@ -795,7 +795,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
795795

796796
/* Name components */
797797
token::Ident(s, is_raw) => {
798-
IdentPrinter::new(s, is_raw, convert_dollar_crate).to_string().into()
798+
IdentPrinter::new(s, is_raw.into(), convert_dollar_crate).to_string().into()
799799
}
800800
token::Lifetime(s) => s.to_string().into(),
801801

compiler/rustc_builtin_macros/src/asm.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use ast::token::IdentIsRaw;
12
use rustc_ast as ast;
23
use rustc_ast::ptr::P;
34
use rustc_ast::token::{self, Delimiter};
@@ -416,7 +417,7 @@ fn parse_reg<'a>(
416417
) -> PResult<'a, ast::InlineAsmRegOrRegClass> {
417418
p.expect(&token::OpenDelim(Delimiter::Parenthesis))?;
418419
let result = match p.token.uninterpolate().kind {
419-
token::Ident(name, false) => ast::InlineAsmRegOrRegClass::RegClass(name),
420+
token::Ident(name, IdentIsRaw::No) => ast::InlineAsmRegOrRegClass::RegClass(name),
420421
token::Literal(token::Lit { kind: token::LitKind::Str, symbol, suffix: _ }) => {
421422
*explicit_reg = true;
422423
ast::InlineAsmRegOrRegClass::Reg(symbol)

compiler/rustc_builtin_macros/src/assert/context.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use rustc_ast::{
22
ptr::P,
3-
token,
4-
token::Delimiter,
3+
token::{self, Delimiter, IdentIsRaw},
54
tokenstream::{DelimSpan, TokenStream, TokenTree},
65
BinOpKind, BorrowKind, DelimArgs, Expr, ExprKind, ItemKind, MacCall, MethodCall, Mutability,
76
Path, PathSegment, Stmt, StructRest, UnOp, UseTree, UseTreeKind, DUMMY_NODE_ID,
@@ -170,7 +169,10 @@ impl<'cx, 'a> Context<'cx, 'a> {
170169
];
171170
let captures = self.capture_decls.iter().flat_map(|cap| {
172171
[
173-
TokenTree::token_joint_hidden(token::Ident(cap.ident.name, false), cap.ident.span),
172+
TokenTree::token_joint_hidden(
173+
token::Ident(cap.ident.name, IdentIsRaw::No),
174+
cap.ident.span,
175+
),
174176
TokenTree::token_alone(token::Comma, self.span),
175177
]
176178
});

compiler/rustc_builtin_macros/src/deriving/decodable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ where
198198
match fields {
199199
Unnamed(fields, is_tuple) => {
200200
let path_expr = cx.expr_path(outer_pat_path);
201-
if !*is_tuple {
201+
if matches!(is_tuple, IsTuple::No) {
202202
path_expr
203203
} else {
204204
let fields = fields

compiler/rustc_builtin_macros/src/deriving/default.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ fn default_struct_substructure(
6262
let default_call = |span| cx.expr_call_global(span, default_ident.clone(), ThinVec::new());
6363

6464
let expr = match summary {
65-
Unnamed(_, false) => cx.expr_ident(trait_span, substr.type_ident),
66-
Unnamed(fields, true) => {
65+
Unnamed(_, IsTuple::No) => cx.expr_ident(trait_span, substr.type_ident),
66+
Unnamed(fields, IsTuple::Yes) => {
6767
let exprs = fields.iter().map(|sp| default_call(*sp)).collect();
6868
cx.expr_call_ident(trait_span, substr.type_ident, exprs)
6969
}

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,16 @@ pub struct FieldInfo {
286286
pub other_selflike_exprs: Vec<P<Expr>>,
287287
}
288288

289+
#[derive(Copy, Clone)]
290+
pub enum IsTuple {
291+
No,
292+
Yes,
293+
}
294+
289295
/// Fields for a static method
290296
pub enum StaticFields {
291297
/// Tuple and unit structs/enum variants like this.
292-
Unnamed(Vec<Span>, bool /*is tuple*/),
298+
Unnamed(Vec<Span>, IsTuple),
293299
/// Normal structs/struct variants.
294300
Named(Vec<(Ident, Span)>),
295301
}
@@ -1439,7 +1445,10 @@ impl<'a> TraitDef<'a> {
14391445
}
14401446
}
14411447

1442-
let is_tuple = matches!(struct_def, ast::VariantData::Tuple(..));
1448+
let is_tuple = match struct_def {
1449+
ast::VariantData::Tuple(..) => IsTuple::Yes,
1450+
_ => IsTuple::No,
1451+
};
14431452
match (just_spans.is_empty(), named_idents.is_empty()) {
14441453
(false, false) => cx
14451454
.dcx()

compiler/rustc_builtin_macros/src/format.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_ast::{
1010
use rustc_data_structures::fx::FxHashSet;
1111
use rustc_errors::{Applicability, DiagnosticBuilder, MultiSpan, PResult, SingleLabelManySpans};
1212
use rustc_expand::base::{self, *};
13+
use rustc_parse::parser::Recovered;
1314
use rustc_parse_format as parse;
1415
use rustc_span::symbol::{Ident, Symbol};
1516
use rustc_span::{BytePos, InnerSpan, Span};
@@ -111,9 +112,8 @@ fn parse_args<'a>(ecx: &mut ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<
111112
_ => return Err(err),
112113
}
113114
}
114-
Ok(recovered) => {
115-
assert!(recovered);
116-
}
115+
Ok(Recovered::Yes) => (),
116+
Ok(Recovered::No) => unreachable!(),
117117
}
118118
}
119119
first = false;

compiler/rustc_codegen_llvm/src/intrinsic.rs

+31-24
Original file line numberDiff line numberDiff line change
@@ -2106,65 +2106,72 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
21062106
return Ok(args[0].immediate());
21072107
}
21082108

2109+
#[derive(Copy, Clone)]
2110+
enum Sign {
2111+
Unsigned,
2112+
Signed,
2113+
}
2114+
use Sign::*;
2115+
21092116
enum Style {
21102117
Float,
2111-
Int(/* is signed? */ bool),
2118+
Int(Sign),
21122119
Unsupported,
21132120
}
21142121

21152122
let (in_style, in_width) = match in_elem.kind() {
21162123
// vectors of pointer-sized integers should've been
21172124
// disallowed before here, so this unwrap is safe.
21182125
ty::Int(i) => (
2119-
Style::Int(true),
2126+
Style::Int(Signed),
21202127
i.normalize(bx.tcx().sess.target.pointer_width).bit_width().unwrap(),
21212128
),
21222129
ty::Uint(u) => (
2123-
Style::Int(false),
2130+
Style::Int(Unsigned),
21242131
u.normalize(bx.tcx().sess.target.pointer_width).bit_width().unwrap(),
21252132
),
21262133
ty::Float(f) => (Style::Float, f.bit_width()),
21272134
_ => (Style::Unsupported, 0),
21282135
};
21292136
let (out_style, out_width) = match out_elem.kind() {
21302137
ty::Int(i) => (
2131-
Style::Int(true),
2138+
Style::Int(Signed),
21322139
i.normalize(bx.tcx().sess.target.pointer_width).bit_width().unwrap(),
21332140
),
21342141
ty::Uint(u) => (
2135-
Style::Int(false),
2142+
Style::Int(Unsigned),
21362143
u.normalize(bx.tcx().sess.target.pointer_width).bit_width().unwrap(),
21372144
),
21382145
ty::Float(f) => (Style::Float, f.bit_width()),
21392146
_ => (Style::Unsupported, 0),
21402147
};
21412148

21422149
match (in_style, out_style) {
2143-
(Style::Int(in_is_signed), Style::Int(_)) => {
2150+
(Style::Int(sign), Style::Int(_)) => {
21442151
return Ok(match in_width.cmp(&out_width) {
21452152
Ordering::Greater => bx.trunc(args[0].immediate(), llret_ty),
21462153
Ordering::Equal => args[0].immediate(),
2147-
Ordering::Less => {
2148-
if in_is_signed {
2149-
bx.sext(args[0].immediate(), llret_ty)
2150-
} else {
2151-
bx.zext(args[0].immediate(), llret_ty)
2152-
}
2153-
}
2154+
Ordering::Less => match sign {
2155+
Sign::Signed => bx.sext(args[0].immediate(), llret_ty),
2156+
Sign::Unsigned => bx.zext(args[0].immediate(), llret_ty),
2157+
},
21542158
});
21552159
}
2156-
(Style::Int(in_is_signed), Style::Float) => {
2157-
return Ok(if in_is_signed {
2158-
bx.sitofp(args[0].immediate(), llret_ty)
2159-
} else {
2160-
bx.uitofp(args[0].immediate(), llret_ty)
2161-
});
2160+
(Style::Int(Sign::Signed), Style::Float) => {
2161+
return Ok(bx.sitofp(args[0].immediate(), llret_ty));
21622162
}
2163-
(Style::Float, Style::Int(out_is_signed)) => {
2164-
return Ok(match (out_is_signed, name == sym::simd_as) {
2165-
(false, false) => bx.fptoui(args[0].immediate(), llret_ty),
2166-
(true, false) => bx.fptosi(args[0].immediate(), llret_ty),
2167-
(_, true) => bx.cast_float_to_int(out_is_signed, args[0].immediate(), llret_ty),
2163+
(Style::Int(Sign::Unsigned), Style::Float) => {
2164+
return Ok(bx.uitofp(args[0].immediate(), llret_ty));
2165+
}
2166+
(Style::Float, Style::Int(sign)) => {
2167+
return Ok(match (sign, name == sym::simd_as) {
2168+
(Sign::Unsigned, false) => bx.fptoui(args[0].immediate(), llret_ty),
2169+
(Sign::Signed, false) => bx.fptosi(args[0].immediate(), llret_ty),
2170+
(_, true) => bx.cast_float_to_int(
2171+
matches!(sign, Sign::Signed),
2172+
args[0].immediate(),
2173+
llret_ty,
2174+
),
21682175
});
21692176
}
21702177
(Style::Float, Style::Float) => {

compiler/rustc_expand/src/mbe/macro_check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
use crate::errors;
108108
use crate::mbe::{KleeneToken, TokenTree};
109109

110-
use rustc_ast::token::{Delimiter, Token, TokenKind};
110+
use rustc_ast::token::{Delimiter, IdentIsRaw, Token, TokenKind};
111111
use rustc_ast::{NodeId, DUMMY_NODE_ID};
112112
use rustc_data_structures::fx::FxHashMap;
113113
use rustc_errors::{DiagnosticMessage, MultiSpan};
@@ -409,7 +409,7 @@ fn check_nested_occurrences(
409409
match (state, tt) {
410410
(
411411
NestedMacroState::Empty,
412-
&TokenTree::Token(Token { kind: TokenKind::Ident(name, false), .. }),
412+
&TokenTree::Token(Token { kind: TokenKind::Ident(name, IdentIsRaw::No), .. }),
413413
) => {
414414
if name == kw::MacroRules {
415415
state = NestedMacroState::MacroRules;

0 commit comments

Comments
 (0)