Skip to content

Commit 2585bce

Browse files
committed
Auto merge of rust-lang#105017 - matthiaskrgr:rollup-j0x550l, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#104804 (Rename `ast::Lit` as `ast::MetaItemLit`.) - rust-lang#104891 (Add documentation for `has_escaping_bound_vars`) - rust-lang#104933 (interpret: remove PartialOrd from a bunch of types that do not have or need a sensible order) - rust-lang#104936 (Ignore bivariant parameters in test_type_match.) - rust-lang#104954 (make simple check of prinf function) - rust-lang#104956 (Avoid ICE if the Clone trait is not found while building error suggestions) - rust-lang#104982 (interpret: get rid of run() function) - rust-lang#104998 (Update my mailmap) - rust-lang#105006 (stricter alignment enforcement for ScalarPair) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8a09420 + 3dfb6ca commit 2585bce

File tree

47 files changed

+567
-415
lines changed

Some content is hidden

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

47 files changed

+567
-415
lines changed

.mailmap

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ Jacob <[email protected]>
229229
Jacob Greenfield <[email protected]>
230230
231231
Jake Vossen <[email protected]>
232-
Jakob Degen <[email protected]>
232+
Jakob Degen <jakob[email protected]> <jakob@degen.com>
233233
Jakob Lautrup Nysom <[email protected]>
234234
Jakub Adam Wieczorek <[email protected]>
235235
Jakub Adam Wieczorek <[email protected]> <[email protected]>

compiler/rustc_ast/src/ast.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//! - [`FnDecl`], [`FnHeader`] and [`Param`]: Metadata associated with a function declaration.
1414
//! - [`Generics`], [`GenericParam`], [`WhereClause`]: Metadata associated with generic parameters.
1515
//! - [`EnumDef`] and [`Variant`]: Enum declaration.
16-
//! - [`Lit`] and [`LitKind`]: Literal expressions.
16+
//! - [`MetaItemLit`] and [`LitKind`]: Literal expressions.
1717
//! - [`MacroDef`], [`MacStmtStyle`], [`MacCall`], [`MacDelimiter`]: Macro definition and invocation.
1818
//! - [`Attribute`]: Metadata associated with item.
1919
//! - [`UnOp`], [`BinOp`], and [`BinOpKind`]: Unary and binary operators.
@@ -489,7 +489,7 @@ pub enum NestedMetaItem {
489489
/// A literal.
490490
///
491491
/// E.g., `"foo"`, `64`, `true`.
492-
Literal(Lit),
492+
Lit(MetaItemLit),
493493
}
494494

495495
/// A spanned compile-time attribute item.
@@ -518,7 +518,7 @@ pub enum MetaItemKind {
518518
/// Name value meta item.
519519
///
520520
/// E.g., `feature = "foo"` as in `#[feature = "foo"]`.
521-
NameValue(Lit),
521+
NameValue(MetaItemLit),
522522
}
523523

524524
/// A block (`{ .. }`).
@@ -1599,12 +1599,12 @@ pub enum AttrArgs {
15991599
}
16001600

16011601
// The RHS of an `AttrArgs::Eq` starts out as an expression. Once macro
1602-
// expansion is completed, all cases end up either as a literal, which is the
1603-
// form used after lowering to HIR, or as an error.
1602+
// expansion is completed, all cases end up either as a meta item literal,
1603+
// which is the form used after lowering to HIR, or as an error.
16041604
#[derive(Clone, Encodable, Decodable, Debug)]
16051605
pub enum AttrArgsEq {
16061606
Ast(P<Expr>),
1607-
Hir(Lit),
1607+
Hir(MetaItemLit),
16081608
}
16091609

16101610
impl AttrArgs {
@@ -1726,19 +1726,18 @@ pub enum StrStyle {
17261726
Raw(u8),
17271727
}
17281728

1729-
/// An AST literal.
1729+
/// A literal in a meta item.
17301730
#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)]
1731-
pub struct Lit {
1731+
pub struct MetaItemLit {
17321732
/// The original literal token as written in source code.
17331733
pub token_lit: token::Lit,
17341734
/// The "semantic" representation of the literal lowered from the original tokens.
17351735
/// Strings are unescaped, hexadecimal forms are eliminated, etc.
1736-
/// FIXME: Remove this and only create the semantic representation during lowering to HIR.
17371736
pub kind: LitKind,
17381737
pub span: Span,
17391738
}
17401739

1741-
/// Same as `Lit`, but restricted to string literals.
1740+
/// Similar to `MetaItemLit`, but restricted to string literals.
17421741
#[derive(Clone, Copy, Encodable, Decodable, Debug)]
17431742
pub struct StrLit {
17441743
/// The original literal token as written in source code.
@@ -1747,7 +1746,6 @@ pub struct StrLit {
17471746
pub suffix: Option<Symbol>,
17481747
pub span: Span,
17491748
/// The unescaped "semantic" representation of the literal lowered from the original token.
1750-
/// FIXME: Remove this and only create the semantic representation during lowering to HIR.
17511749
pub symbol_unescaped: Symbol,
17521750
}
17531751

@@ -1783,6 +1781,8 @@ pub enum LitFloatType {
17831781
Unsuffixed,
17841782
}
17851783

1784+
/// This type is used within both `ast::MetaItemLit` and `hir::Lit`.
1785+
///
17861786
/// Note that the entire literal (including the suffix) is considered when
17871787
/// deciding the `LitKind`. This means that float literals like `1f32` are
17881788
/// classified by this type as `Float`. This is different to `token::LitKind`
@@ -3096,9 +3096,9 @@ mod size_asserts {
30963096
static_assert_size!(Impl, 184);
30973097
static_assert_size!(Item, 184);
30983098
static_assert_size!(ItemKind, 112);
3099-
static_assert_size!(Lit, 48);
31003099
static_assert_size!(LitKind, 24);
31013100
static_assert_size!(Local, 72);
3101+
static_assert_size!(MetaItemLit, 48);
31023102
static_assert_size!(Param, 40);
31033103
static_assert_size!(Pat, 88);
31043104
static_assert_size!(Path, 24);

compiler/rustc_ast/src/attr/mod.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::ast;
44
use crate::ast::{AttrArgs, AttrArgsEq, AttrId, AttrItem, AttrKind, AttrStyle, Attribute};
5-
use crate::ast::{DelimArgs, Lit, LitKind};
5+
use crate::ast::{DelimArgs, LitKind, MetaItemLit};
66
use crate::ast::{MacDelimiter, MetaItem, MetaItemKind, NestedMetaItem};
77
use crate::ast::{Path, PathSegment};
88
use crate::ptr::P;
@@ -50,10 +50,10 @@ impl NestedMetaItem {
5050
}
5151
}
5252

53-
/// Returns the `Lit` if `self` is a `NestedMetaItem::Literal`s.
54-
pub fn literal(&self) -> Option<&Lit> {
53+
/// Returns the `MetaItemLit` if `self` is a `NestedMetaItem::Literal`s.
54+
pub fn lit(&self) -> Option<&MetaItemLit> {
5555
match self {
56-
NestedMetaItem::Literal(lit) => Some(lit),
56+
NestedMetaItem::Lit(lit) => Some(lit),
5757
_ => None,
5858
}
5959
}
@@ -78,12 +78,12 @@ impl NestedMetaItem {
7878
}
7979

8080
/// Returns a name and single literal value tuple of the `MetaItem`.
81-
pub fn name_value_literal(&self) -> Option<(Symbol, &Lit)> {
81+
pub fn name_value_literal(&self) -> Option<(Symbol, &MetaItemLit)> {
8282
self.meta_item().and_then(|meta_item| {
8383
meta_item.meta_item_list().and_then(|meta_item_list| {
8484
if meta_item_list.len() == 1
8585
&& let Some(ident) = meta_item.ident()
86-
&& let Some(lit) = meta_item_list[0].literal()
86+
&& let Some(lit) = meta_item_list[0].lit()
8787
{
8888
return Some((ident.name, lit));
8989
}
@@ -179,7 +179,7 @@ impl MetaItem {
179179
/// #[attribute(name = "value")]
180180
/// ^^^^^^^^^^^^^^
181181
/// ```
182-
pub fn name_value_literal(&self) -> Option<&Lit> {
182+
pub fn name_value_literal(&self) -> Option<&MetaItemLit> {
183183
match &self.kind {
184184
MetaItemKind::NameValue(v) => Some(v),
185185
_ => None,
@@ -334,7 +334,7 @@ pub fn mk_name_value_item_str(ident: Ident, str: Symbol, str_span: Span) -> Meta
334334
}
335335

336336
pub fn mk_name_value_item(ident: Ident, lit_kind: LitKind, lit_span: Span) -> MetaItem {
337-
let lit = Lit::from_lit_kind(lit_kind, lit_span);
337+
let lit = MetaItemLit::from_lit_kind(lit_kind, lit_span);
338338
let span = ident.span.to(lit_span);
339339
MetaItem { path: Path::from_ident(ident), span, kind: MetaItemKind::NameValue(lit) }
340340
}
@@ -604,7 +604,7 @@ impl MetaItemKind {
604604
MetaItemKind::name_value_from_tokens(&mut inner_tokens.into_trees())
605605
}
606606
Some(TokenTree::Token(token, _)) => {
607-
Lit::from_token(&token).map(MetaItemKind::NameValue)
607+
MetaItemLit::from_token(&token).map(MetaItemKind::NameValue)
608608
}
609609
_ => None,
610610
}
@@ -622,7 +622,7 @@ impl MetaItemKind {
622622
AttrArgs::Eq(_, AttrArgsEq::Ast(expr)) => match expr.kind {
623623
ast::ExprKind::Lit(token_lit) => {
624624
// Turn failures to `None`, we'll get parse errors elsewhere.
625-
Lit::from_token_lit(token_lit, expr.span)
625+
MetaItemLit::from_token_lit(token_lit, expr.span)
626626
.ok()
627627
.map(|lit| MetaItemKind::NameValue(lit))
628628
}
@@ -655,14 +655,14 @@ impl NestedMetaItem {
655655
pub fn span(&self) -> Span {
656656
match self {
657657
NestedMetaItem::MetaItem(item) => item.span,
658-
NestedMetaItem::Literal(lit) => lit.span,
658+
NestedMetaItem::Lit(lit) => lit.span,
659659
}
660660
}
661661

662662
fn token_trees(&self) -> Vec<TokenTree> {
663663
match self {
664664
NestedMetaItem::MetaItem(item) => item.token_trees(),
665-
NestedMetaItem::Literal(lit) => {
665+
NestedMetaItem::Lit(lit) => {
666666
vec![TokenTree::Token(lit.to_token(), Spacing::Alone)]
667667
}
668668
}
@@ -674,10 +674,10 @@ impl NestedMetaItem {
674674
{
675675
match tokens.peek() {
676676
Some(TokenTree::Token(token, _))
677-
if let Some(lit) = Lit::from_token(token) =>
677+
if let Some(lit) = MetaItemLit::from_token(token) =>
678678
{
679679
tokens.next();
680-
return Some(NestedMetaItem::Literal(lit));
680+
return Some(NestedMetaItem::Lit(lit));
681681
}
682682
Some(TokenTree::Delimited(_, Delimiter::Invisible, inner_tokens)) => {
683683
let inner_tokens = inner_tokens.clone();

compiler/rustc_ast/src/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ pub fn noop_visit_macro_def<T: MutVisitor>(macro_def: &mut MacroDef, vis: &mut T
628628
pub fn noop_visit_meta_list_item<T: MutVisitor>(li: &mut NestedMetaItem, vis: &mut T) {
629629
match li {
630630
NestedMetaItem::MetaItem(mi) => vis.visit_meta_item(mi),
631-
NestedMetaItem::Literal(_lit) => {}
631+
NestedMetaItem::Lit(_lit) => {}
632632
}
633633
}
634634

compiler/rustc_ast/src/util/literal.rs

+12-20
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Code related to parsing literals.
22
3-
use crate::ast::{self, Lit, LitKind};
3+
use crate::ast::{self, LitKind, MetaItemLit};
44
use crate::token::{self, Token};
5-
use rustc_data_structures::sync::Lrc;
65
use rustc_lexer::unescape::{byte_from_char, unescape_byte, unescape_char, unescape_literal, Mode};
76
use rustc_span::symbol::{kw, sym, Symbol};
87
use rustc_span::Span;
@@ -196,33 +195,26 @@ impl LitKind {
196195
}
197196
}
198197

199-
impl Lit {
200-
/// Converts literal token into an AST literal.
201-
pub fn from_token_lit(token_lit: token::Lit, span: Span) -> Result<Lit, LitError> {
202-
Ok(Lit { token_lit, kind: LitKind::from_token_lit(token_lit)?, span })
198+
impl MetaItemLit {
199+
/// Converts token literal into a meta item literal.
200+
pub fn from_token_lit(token_lit: token::Lit, span: Span) -> Result<MetaItemLit, LitError> {
201+
Ok(MetaItemLit { token_lit, kind: LitKind::from_token_lit(token_lit)?, span })
203202
}
204203

205-
/// Converts an arbitrary token into an AST literal.
206-
pub fn from_token(token: &Token) -> Option<Lit> {
204+
/// Converts an arbitrary token into meta item literal.
205+
pub fn from_token(token: &Token) -> Option<MetaItemLit> {
207206
token::Lit::from_token(token)
208-
.and_then(|token_lit| Lit::from_token_lit(token_lit, token.span).ok())
207+
.and_then(|token_lit| MetaItemLit::from_token_lit(token_lit, token.span).ok())
209208
}
210209

211-
/// Attempts to recover an AST literal from semantic literal.
210+
/// Attempts to create a meta item literal from a `LitKind`.
212211
/// This function is used when the original token doesn't exist (e.g. the literal is created
213212
/// by an AST-based macro) or unavailable (e.g. from HIR pretty-printing).
214-
pub fn from_lit_kind(kind: LitKind, span: Span) -> Lit {
215-
Lit { token_lit: kind.to_token_lit(), kind, span }
213+
pub fn from_lit_kind(kind: LitKind, span: Span) -> MetaItemLit {
214+
MetaItemLit { token_lit: kind.to_token_lit(), kind, span }
216215
}
217216

218-
/// Recovers an AST literal from a string of bytes produced by `include_bytes!`.
219-
/// This requires ASCII-escaping the string, which can result in poor performance
220-
/// for very large strings of bytes.
221-
pub fn from_included_bytes(bytes: &Lrc<[u8]>, span: Span) -> Lit {
222-
Self::from_lit_kind(LitKind::ByteStr(bytes.clone()), span)
223-
}
224-
225-
/// Losslessly convert an AST literal into a token.
217+
/// Losslessly convert a meta item literal into a token.
226218
pub fn to_token(&self) -> Token {
227219
let kind = match self.token_lit.kind {
228220
token::Bool => token::Ident(self.token_lit.symbol, false),

compiler/rustc_ast_lowering/src/lib.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -948,17 +948,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
948948
AttrArgs::Eq(eq_span, AttrArgsEq::Ast(expr)) => {
949949
// In valid code the value always ends up as a single literal. Otherwise, a dummy
950950
// literal suffices because the error is handled elsewhere.
951-
let lit = if let ExprKind::Lit(token_lit) = expr.kind {
952-
match Lit::from_token_lit(token_lit, expr.span) {
953-
Ok(lit) => lit,
954-
Err(_err) => Lit {
955-
token_lit: token::Lit::new(token::LitKind::Err, kw::Empty, None),
956-
kind: LitKind::Err,
957-
span: DUMMY_SP,
958-
},
959-
}
951+
let lit = if let ExprKind::Lit(token_lit) = expr.kind
952+
&& let Ok(lit) = MetaItemLit::from_token_lit(token_lit, expr.span)
953+
{
954+
lit
960955
} else {
961-
Lit {
956+
MetaItemLit {
962957
token_lit: token::Lit::new(token::LitKind::Err, kw::Empty, None),
963958
kind: LitKind::Err,
964959
span: DUMMY_SP,

compiler/rustc_ast_pretty/src/pprust/state.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
371371
}
372372
}
373373

374-
fn print_literal(&mut self, lit: &ast::Lit) {
374+
fn print_meta_item_lit(&mut self, lit: &ast::MetaItemLit) {
375375
self.print_token_literal(lit.token_lit, lit.span)
376376
}
377377

@@ -488,7 +488,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
488488
self.print_path(&item.path, false, 0);
489489
self.space();
490490
self.word_space("=");
491-
let token_str = self.literal_to_string(lit);
491+
let token_str = self.meta_item_lit_to_string(lit);
492492
self.word(token_str);
493493
}
494494
}
@@ -498,7 +498,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
498498
fn print_meta_list_item(&mut self, item: &ast::NestedMetaItem) {
499499
match item {
500500
ast::NestedMetaItem::MetaItem(ref mi) => self.print_meta_item(mi),
501-
ast::NestedMetaItem::Literal(ref lit) => self.print_literal(lit),
501+
ast::NestedMetaItem::Lit(ref lit) => self.print_meta_item_lit(lit),
502502
}
503503
}
504504

@@ -510,7 +510,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
510510
self.print_path(&item.path, false, 0);
511511
self.space();
512512
self.word_space("=");
513-
self.print_literal(value);
513+
self.print_meta_item_lit(value);
514514
}
515515
ast::MetaItemKind::List(ref items) => {
516516
self.print_path(&item.path, false, 0);
@@ -825,8 +825,8 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
825825
Self::to_string(|s| s.print_expr(e))
826826
}
827827

828-
fn literal_to_string(&self, lit: &ast::Lit) -> String {
829-
Self::to_string(|s| s.print_literal(lit))
828+
fn meta_item_lit_to_string(&self, lit: &ast::MetaItemLit) -> String {
829+
Self::to_string(|s| s.print_meta_item_lit(lit))
830830
}
831831

832832
fn tt_to_string(&self, tt: &TokenTree) -> String {

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ impl<'a> State<'a> {
328328
self.print_token_literal(token_lit, expr.span);
329329
}
330330
ast::ExprKind::IncludedBytes(ref bytes) => {
331-
let lit = ast::Lit::from_included_bytes(bytes, expr.span);
332-
self.print_literal(&lit)
331+
let lit = ast::LitKind::ByteStr(bytes.clone()).to_token_lit();
332+
self.print_token_literal(lit, expr.span)
333333
}
334334
ast::ExprKind::Cast(ref expr, ref ty) => {
335335
let prec = AssocOp::As.precedence() as i8;

compiler/rustc_attr/src/builtin.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Parsing and validation of builtin attributes
22
33
use rustc_ast as ast;
4-
use rustc_ast::{Attribute, Lit, LitKind, MetaItem, MetaItemKind, NestedMetaItem, NodeId};
4+
use rustc_ast::{Attribute, LitKind, MetaItem, MetaItemKind, MetaItemLit, NestedMetaItem, NodeId};
55
use rustc_ast_pretty::pprust;
66
use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg};
77
use rustc_macros::HashStable_Generic;
@@ -486,7 +486,7 @@ where
486486
continue 'outer;
487487
}
488488
},
489-
NestedMetaItem::Literal(lit) => {
489+
NestedMetaItem::Lit(lit) => {
490490
handle_errors(
491491
&sess.parse_sess,
492492
lit.span,
@@ -658,11 +658,11 @@ pub fn eval_condition(
658658
ast::MetaItemKind::List(ref mis) if cfg.name_or_empty() == sym::version => {
659659
try_gate_cfg(sym::version, cfg.span, sess, features);
660660
let (min_version, span) = match &mis[..] {
661-
[NestedMetaItem::Literal(Lit { kind: LitKind::Str(sym, ..), span, .. })] => {
661+
[NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Str(sym, ..), span, .. })] => {
662662
(sym, span)
663663
}
664664
[
665-
NestedMetaItem::Literal(Lit { span, .. })
665+
NestedMetaItem::Lit(MetaItemLit { span, .. })
666666
| NestedMetaItem::MetaItem(MetaItem { span, .. }),
667667
] => {
668668
sess.emit_err(session_diagnostics::ExpectedVersionLiteral { span: *span });
@@ -899,7 +899,7 @@ where
899899
continue 'outer;
900900
}
901901
},
902-
NestedMetaItem::Literal(lit) => {
902+
NestedMetaItem::Lit(lit) => {
903903
handle_errors(
904904
&sess.parse_sess,
905905
lit.span,

0 commit comments

Comments
 (0)