Skip to content

Commit 7fdefb8

Browse files
committed
Auto merge of #127476 - jieyouxu:rollup-16wyb0b, r=jieyouxu
Rollup of 10 pull requests Successful merges: - #126841 ([`macro_metavar_expr_concat`] Add support for literals) - #126881 (Make `NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE` a deny-by-default lint in edition 2024) - #126921 (Give VaList its own home) - #127367 (Run alloc sync tests) - #127431 (Use field ident spans directly instead of the full field span in diagnostics on local fields) - #127437 (Uplift trait ref is knowable into `rustc_next_trait_solver`) - #127439 (Uplift elaboration into `rustc_type_ir`) - #127451 (Improve `run-make/output-type-permutations` code and improve `filename_not_in_denylist` API) - #127452 (Fix intrinsic const parameter counting with `effects`) - #127459 (rustdoc-json: add type/trait alias tests) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9af6fee + 76be8f1 commit 7fdefb8

File tree

79 files changed

+1989
-1570
lines changed

Some content is hidden

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

79 files changed

+1989
-1570
lines changed

compiler/rustc_expand/src/mbe/metavar_expr.rs

+53-21
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
use rustc_ast::token::{self, Delimiter, IdentIsRaw};
1+
use rustc_ast::token::{self, Delimiter, IdentIsRaw, Lit, Token, TokenKind};
22
use rustc_ast::tokenstream::{RefTokenTreeCursor, TokenStream, TokenTree};
33
use rustc_ast::{LitIntType, LitKind};
44
use rustc_ast_pretty::pprust;
55
use rustc_errors::{Applicability, PResult};
66
use rustc_macros::{Decodable, Encodable};
77
use rustc_session::parse::ParseSess;
88
use rustc_span::symbol::Ident;
9-
use rustc_span::Span;
9+
use rustc_span::{Span, Symbol};
1010

1111
pub(crate) const RAW_IDENT_ERR: &str = "`${concat(..)}` currently does not support raw identifiers";
12+
pub(crate) const UNSUPPORTED_CONCAT_ELEM_ERR: &str = "expected identifier or string literal";
1213

1314
/// A meta-variable expression, for expansions based on properties of meta-variables.
1415
#[derive(Debug, PartialEq, Encodable, Decodable)]
@@ -51,11 +52,26 @@ impl MetaVarExpr {
5152
let mut result = Vec::new();
5253
loop {
5354
let is_var = try_eat_dollar(&mut iter);
54-
let element_ident = parse_ident(&mut iter, psess, outer_span)?;
55+
let token = parse_token(&mut iter, psess, outer_span)?;
5556
let element = if is_var {
56-
MetaVarExprConcatElem::Var(element_ident)
57+
MetaVarExprConcatElem::Var(parse_ident_from_token(psess, token)?)
58+
} else if let TokenKind::Literal(Lit {
59+
kind: token::LitKind::Str,
60+
symbol,
61+
suffix: None,
62+
}) = token.kind
63+
{
64+
MetaVarExprConcatElem::Literal(symbol)
5765
} else {
58-
MetaVarExprConcatElem::Ident(element_ident)
66+
match parse_ident_from_token(psess, token) {
67+
Err(err) => {
68+
err.cancel();
69+
return Err(psess
70+
.dcx()
71+
.struct_span_err(token.span, UNSUPPORTED_CONCAT_ELEM_ERR));
72+
}
73+
Ok(elem) => MetaVarExprConcatElem::Ident(elem),
74+
}
5975
};
6076
result.push(element);
6177
if iter.look_ahead(0).is_none() {
@@ -105,11 +121,13 @@ impl MetaVarExpr {
105121

106122
#[derive(Debug, Decodable, Encodable, PartialEq)]
107123
pub(crate) enum MetaVarExprConcatElem {
108-
/// There is NO preceding dollar sign, which means that this identifier should be interpreted
109-
/// as a literal.
124+
/// Identifier WITHOUT a preceding dollar sign, which means that this identifier should be
125+
/// interpreted as a literal.
110126
Ident(Ident),
111-
/// There is a preceding dollar sign, which means that this identifier should be expanded
112-
/// and interpreted as a variable.
127+
/// For example, a number or a string.
128+
Literal(Symbol),
129+
/// Identifier WITH a preceding dollar sign, which means that this identifier should be
130+
/// expanded and interpreted as a variable.
113131
Var(Ident),
114132
}
115133

@@ -158,7 +176,7 @@ fn parse_depth<'psess>(
158176
span: Span,
159177
) -> PResult<'psess, usize> {
160178
let Some(tt) = iter.next() else { return Ok(0) };
161-
let TokenTree::Token(token::Token { kind: token::TokenKind::Literal(lit), .. }, _) = tt else {
179+
let TokenTree::Token(Token { kind: TokenKind::Literal(lit), .. }, _) = tt else {
162180
return Err(psess
163181
.dcx()
164182
.struct_span_err(span, "meta-variable expression depth must be a literal"));
@@ -180,12 +198,14 @@ fn parse_ident<'psess>(
180198
psess: &'psess ParseSess,
181199
fallback_span: Span,
182200
) -> PResult<'psess, Ident> {
183-
let Some(tt) = iter.next() else {
184-
return Err(psess.dcx().struct_span_err(fallback_span, "expected identifier"));
185-
};
186-
let TokenTree::Token(token, _) = tt else {
187-
return Err(psess.dcx().struct_span_err(tt.span(), "expected identifier"));
188-
};
201+
let token = parse_token(iter, psess, fallback_span)?;
202+
parse_ident_from_token(psess, token)
203+
}
204+
205+
fn parse_ident_from_token<'psess>(
206+
psess: &'psess ParseSess,
207+
token: &Token,
208+
) -> PResult<'psess, Ident> {
189209
if let Some((elem, is_raw)) = token.ident() {
190210
if let IdentIsRaw::Yes = is_raw {
191211
return Err(psess.dcx().struct_span_err(elem.span, RAW_IDENT_ERR));
@@ -205,10 +225,24 @@ fn parse_ident<'psess>(
205225
Err(err)
206226
}
207227

228+
fn parse_token<'psess, 't>(
229+
iter: &mut RefTokenTreeCursor<'t>,
230+
psess: &'psess ParseSess,
231+
fallback_span: Span,
232+
) -> PResult<'psess, &'t Token> {
233+
let Some(tt) = iter.next() else {
234+
return Err(psess.dcx().struct_span_err(fallback_span, UNSUPPORTED_CONCAT_ELEM_ERR));
235+
};
236+
let TokenTree::Token(token, _) = tt else {
237+
return Err(psess.dcx().struct_span_err(tt.span(), UNSUPPORTED_CONCAT_ELEM_ERR));
238+
};
239+
Ok(token)
240+
}
241+
208242
/// Tries to move the iterator forward returning `true` if there is a comma. If not, then the
209243
/// iterator is not modified and the result is `false`.
210244
fn try_eat_comma(iter: &mut RefTokenTreeCursor<'_>) -> bool {
211-
if let Some(TokenTree::Token(token::Token { kind: token::Comma, .. }, _)) = iter.look_ahead(0) {
245+
if let Some(TokenTree::Token(Token { kind: token::Comma, .. }, _)) = iter.look_ahead(0) {
212246
let _ = iter.next();
213247
return true;
214248
}
@@ -218,8 +252,7 @@ fn try_eat_comma(iter: &mut RefTokenTreeCursor<'_>) -> bool {
218252
/// Tries to move the iterator forward returning `true` if there is a dollar sign. If not, then the
219253
/// iterator is not modified and the result is `false`.
220254
fn try_eat_dollar(iter: &mut RefTokenTreeCursor<'_>) -> bool {
221-
if let Some(TokenTree::Token(token::Token { kind: token::Dollar, .. }, _)) = iter.look_ahead(0)
222-
{
255+
if let Some(TokenTree::Token(Token { kind: token::Dollar, .. }, _)) = iter.look_ahead(0) {
223256
let _ = iter.next();
224257
return true;
225258
}
@@ -232,8 +265,7 @@ fn eat_dollar<'psess>(
232265
psess: &'psess ParseSess,
233266
span: Span,
234267
) -> PResult<'psess, ()> {
235-
if let Some(TokenTree::Token(token::Token { kind: token::Dollar, .. }, _)) = iter.look_ahead(0)
236-
{
268+
if let Some(TokenTree::Token(Token { kind: token::Dollar, .. }, _)) = iter.look_ahead(0) {
237269
let _ = iter.next();
238270
return Ok(());
239271
}

compiler/rustc_expand/src/mbe/transcribe.rs

+27-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ use rustc_ast::token::{self, Delimiter, Token, TokenKind};
1111
use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree};
1212
use rustc_data_structures::fx::FxHashMap;
1313
use rustc_errors::{pluralize, Diag, DiagCtxtHandle, PResult};
14+
use rustc_parse::lexer::nfc_normalize;
1415
use rustc_parse::parser::ParseNtResult;
1516
use rustc_session::parse::ParseSess;
17+
use rustc_session::parse::SymbolGallery;
1618
use rustc_span::hygiene::{LocalExpnId, Transparency};
1719
use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent};
18-
use rustc_span::{with_metavar_spans, Span, Symbol, SyntaxContext};
20+
use rustc_span::{with_metavar_spans, Span, SyntaxContext};
1921
use smallvec::{smallvec, SmallVec};
2022
use std::mem;
2123

@@ -312,7 +314,16 @@ pub(super) fn transcribe<'a>(
312314

313315
// Replace meta-variable expressions with the result of their expansion.
314316
mbe::TokenTree::MetaVarExpr(sp, expr) => {
315-
transcribe_metavar_expr(dcx, expr, interp, &mut marker, &repeats, &mut result, sp)?;
317+
transcribe_metavar_expr(
318+
dcx,
319+
expr,
320+
interp,
321+
&mut marker,
322+
&repeats,
323+
&mut result,
324+
sp,
325+
&psess.symbol_gallery,
326+
)?;
316327
}
317328

318329
// If we are entering a new delimiter, we push its contents to the `stack` to be
@@ -669,6 +680,7 @@ fn transcribe_metavar_expr<'a>(
669680
repeats: &[(usize, usize)],
670681
result: &mut Vec<TokenTree>,
671682
sp: &DelimSpan,
683+
symbol_gallery: &SymbolGallery,
672684
) -> PResult<'a, ()> {
673685
let mut visited_span = || {
674686
let mut span = sp.entire();
@@ -680,16 +692,26 @@ fn transcribe_metavar_expr<'a>(
680692
let mut concatenated = String::new();
681693
for element in elements.into_iter() {
682694
let string = match element {
683-
MetaVarExprConcatElem::Ident(ident) => ident.to_string(),
684-
MetaVarExprConcatElem::Var(ident) => extract_ident(dcx, *ident, interp)?,
695+
MetaVarExprConcatElem::Ident(elem) => elem.to_string(),
696+
MetaVarExprConcatElem::Literal(elem) => elem.as_str().into(),
697+
MetaVarExprConcatElem::Var(elem) => extract_ident(dcx, *elem, interp)?,
685698
};
686699
concatenated.push_str(&string);
687700
}
701+
let symbol = nfc_normalize(&concatenated);
702+
let concatenated_span = visited_span();
703+
if !rustc_lexer::is_ident(symbol.as_str()) {
704+
return Err(dcx.struct_span_err(
705+
concatenated_span,
706+
"`${concat(..)}` is not generating a valid identifier",
707+
));
708+
}
709+
symbol_gallery.insert(symbol, concatenated_span);
688710
// The current implementation marks the span as coming from the macro regardless of
689711
// contexts of the concatenated identifiers but this behavior may change in the
690712
// future.
691713
result.push(TokenTree::Token(
692-
Token::from_ast_ident(Ident::new(Symbol::intern(&concatenated), visited_span())),
714+
Token::from_ast_ident(Ident::new(symbol, concatenated_span)),
693715
Spacing::Alone,
694716
));
695717
}

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,20 @@ fn equate_intrinsic_type<'tcx>(
2626
n_cts: usize,
2727
sig: ty::PolyFnSig<'tcx>,
2828
) {
29-
let (own_counts, span) = match tcx.hir_node_by_def_id(def_id) {
29+
let (generics, span) = match tcx.hir_node_by_def_id(def_id) {
3030
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, generics, _), .. })
3131
| hir::Node::ForeignItem(hir::ForeignItem {
3232
kind: hir::ForeignItemKind::Fn(.., generics, _),
3333
..
34-
}) => {
35-
let own_counts = tcx.generics_of(def_id).own_counts();
36-
(own_counts, generics.span)
37-
}
34+
}) => (tcx.generics_of(def_id), generics.span),
3835
_ => {
3936
struct_span_code_err!(tcx.dcx(), span, E0622, "intrinsic must be a function")
4037
.with_span_label(span, "expected a function")
4138
.emit();
4239
return;
4340
}
4441
};
42+
let own_counts = generics.own_counts();
4543

4644
let gen_count_ok = |found: usize, expected: usize, descr: &str| -> bool {
4745
if found != expected {
@@ -57,9 +55,17 @@ fn equate_intrinsic_type<'tcx>(
5755
}
5856
};
5957

58+
// the host effect param should be invisible as it shouldn't matter
59+
// whether effects is enabled for the intrinsic provider crate.
60+
let consts_count = if generics.host_effect_index.is_some() {
61+
own_counts.consts - 1
62+
} else {
63+
own_counts.consts
64+
};
65+
6066
if gen_count_ok(own_counts.lifetimes, n_lts, "lifetime")
6167
&& gen_count_ok(own_counts.types, n_tps, "type")
62-
&& gen_count_ok(own_counts.consts, n_cts, "const")
68+
&& gen_count_ok(consts_count, n_cts, "const")
6369
{
6470
let _ = check_function_signature(
6571
tcx,

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, trait_def_id: LocalDefId) {
478478
param_env,
479479
item_def_id,
480480
tcx.explicit_item_bounds(item_def_id)
481-
.instantiate_identity_iter_copied()
481+
.iter_identity_copied()
482482
.collect::<Vec<_>>(),
483483
&FxIndexSet::default(),
484484
gat_def_id,
@@ -1205,17 +1205,16 @@ fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: ty::AssocIt
12051205
let bounds = wfcx.tcx().explicit_item_bounds(item.def_id);
12061206

12071207
debug!("check_associated_type_bounds: bounds={:?}", bounds);
1208-
let wf_obligations =
1209-
bounds.instantiate_identity_iter_copied().flat_map(|(bound, bound_span)| {
1210-
let normalized_bound = wfcx.normalize(span, None, bound);
1211-
traits::wf::clause_obligations(
1212-
wfcx.infcx,
1213-
wfcx.param_env,
1214-
wfcx.body_def_id,
1215-
normalized_bound,
1216-
bound_span,
1217-
)
1218-
});
1208+
let wf_obligations = bounds.iter_identity_copied().flat_map(|(bound, bound_span)| {
1209+
let normalized_bound = wfcx.normalize(span, None, bound);
1210+
traits::wf::clause_obligations(
1211+
wfcx.infcx,
1212+
wfcx.param_env,
1213+
wfcx.body_def_id,
1214+
normalized_bound,
1215+
bound_span,
1216+
)
1217+
});
12191218

12201219
wfcx.register_obligations(wf_obligations);
12211220
}

compiler/rustc_hir_analysis/src/coherence/orphan.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ fn orphan_check<'tcx>(
286286
tcx: TyCtxt<'tcx>,
287287
impl_def_id: LocalDefId,
288288
mode: OrphanCheckMode,
289-
) -> Result<(), OrphanCheckErr<'tcx, FxIndexSet<DefId>>> {
289+
) -> Result<(), OrphanCheckErr<TyCtxt<'tcx>, FxIndexSet<DefId>>> {
290290
// We only accept this routine to be invoked on implementations
291291
// of a trait, not inherent implementations.
292292
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
@@ -326,17 +326,16 @@ fn orphan_check<'tcx>(
326326
ty
327327
};
328328

329-
Ok(ty)
329+
Ok::<_, !>(ty)
330330
};
331331

332-
let Ok(result) = traits::orphan_check_trait_ref::<!>(
332+
let result = traits::orphan_check_trait_ref(
333333
&infcx,
334334
trait_ref,
335335
traits::InCrate::Local { mode },
336336
lazily_normalize_ty,
337-
) else {
338-
unreachable!()
339-
};
337+
)
338+
.into_ok();
340339

341340
// (2) Try to map the remaining inference vars back to generic params.
342341
result.map_err(|err| match err {
@@ -369,7 +368,7 @@ fn emit_orphan_check_error<'tcx>(
369368
tcx: TyCtxt<'tcx>,
370369
trait_ref: ty::TraitRef<'tcx>,
371370
impl_def_id: LocalDefId,
372-
err: traits::OrphanCheckErr<'tcx, FxIndexSet<DefId>>,
371+
err: traits::OrphanCheckErr<TyCtxt<'tcx>, FxIndexSet<DefId>>,
373372
) -> ErrorGuaranteed {
374373
match err {
375374
traits::OrphanCheckErr::NonLocalInputType(tys) => {
@@ -482,7 +481,7 @@ fn emit_orphan_check_error<'tcx>(
482481

483482
fn lint_uncovered_ty_params<'tcx>(
484483
tcx: TyCtxt<'tcx>,
485-
UncoveredTyParams { uncovered, local_ty }: UncoveredTyParams<'tcx, FxIndexSet<DefId>>,
484+
UncoveredTyParams { uncovered, local_ty }: UncoveredTyParams<TyCtxt<'tcx>, FxIndexSet<DefId>>,
486485
impl_def_id: LocalDefId,
487486
) {
488487
let hir_id = tcx.local_def_id_to_hir_id(impl_def_id);

compiler/rustc_hir_analysis/src/collect.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
12011201

12021202
let is_marker = tcx.has_attr(def_id, sym::marker);
12031203
let rustc_coinductive = tcx.has_attr(def_id, sym::rustc_coinductive);
1204+
let is_fundamental = tcx.has_attr(def_id, sym::fundamental);
12041205

12051206
// FIXME: We could probably do way better attribute validation here.
12061207
let mut skip_array_during_method_dispatch = false;
@@ -1352,6 +1353,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
13521353
has_auto_impl: is_auto,
13531354
is_marker,
13541355
is_coinductive: rustc_coinductive || is_auto,
1356+
is_fundamental,
13551357
skip_array_during_method_dispatch,
13561358
skip_boxed_slice_during_method_dispatch,
13571359
specialization_kind,

compiler/rustc_hir_analysis/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ This API is completely unstable and subject to change.
7171
#![feature(rustdoc_internals)]
7272
#![feature(slice_partition_dedup)]
7373
#![feature(try_blocks)]
74+
#![feature(unwrap_infallible)]
7475
// tidy-alphabetical-end
7576

7677
#[macro_use]

compiler/rustc_hir_typeck/src/coercion.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1752,10 +1752,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
17521752
fcx.probe(|_| {
17531753
let ocx = ObligationCtxt::new(fcx);
17541754
ocx.register_obligations(
1755-
fcx.tcx
1756-
.item_super_predicates(rpit_def_id)
1757-
.instantiate_identity_iter()
1758-
.filter_map(|clause| {
1755+
fcx.tcx.item_super_predicates(rpit_def_id).iter_identity().filter_map(
1756+
|clause| {
17591757
let predicate = clause
17601758
.kind()
17611759
.map_bound(|clause| match clause {
@@ -1776,7 +1774,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
17761774
fcx.param_env,
17771775
predicate,
17781776
))
1779-
}),
1777+
},
1778+
),
17801779
);
17811780
ocx.select_where_possible().is_empty()
17821781
})

0 commit comments

Comments
 (0)