Skip to content

Commit 7a125f7

Browse files
committed
Auto merge of rust-lang#129660 - compiler-errors:crater-rollup, r=<try>
[CRATER] Crater Rollup This is a " crater rollup" of: * rust-lang#126452 * rust-lang#128784 * rust-lang#129392 * rust-lang#129422 * rust-lang#129543 **What is a crater rollup?** It's simply a crater job that is run on all of the containing PRs *together*, and then we can set the crates list for each of these jobs to just the failures after it's done. It should cut out on the bulk of "normal" crates that do nothing and simply just take time to build. r? `@ghost`
2 parents ae9f501 + cee59b8 commit 7a125f7

File tree

66 files changed

+1374
-198
lines changed

Some content is hidden

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

66 files changed

+1374
-198
lines changed

compiler/rustc_ast/src/mut_visit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ fn visit_lazy_tts<T: MutVisitor>(vis: &mut T, lazy_tts: &mut Option<LazyAttrToke
752752
pub fn visit_token<T: MutVisitor>(vis: &mut T, t: &mut Token) {
753753
let Token { kind, span } = t;
754754
match kind {
755-
token::Ident(name, _ /*raw*/) | token::Lifetime(name) => {
755+
token::Ident(name, _ /* raw */) | token::Lifetime(name, _ /* raw */) => {
756756
let mut ident = Ident::new(*name, *span);
757757
vis.visit_ident(&mut ident);
758758
*name = ident.name;
@@ -762,7 +762,7 @@ pub fn visit_token<T: MutVisitor>(vis: &mut T, t: &mut Token) {
762762
token::NtIdent(ident, _is_raw) => {
763763
vis.visit_ident(ident);
764764
}
765-
token::NtLifetime(ident) => {
765+
token::NtLifetime(ident, _is_raw) => {
766766
vis.visit_ident(ident);
767767
}
768768
token::Interpolated(nt) => {

compiler/rustc_ast/src/token.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,11 @@ pub enum TokenKind {
331331
/// Do not forget about `NtLifetime` when you want to match on lifetime identifiers.
332332
/// It's recommended to use `Token::(lifetime,uninterpolate,uninterpolated_span)` to
333333
/// treat regular and interpolated lifetime identifiers in the same way.
334-
Lifetime(Symbol),
334+
Lifetime(Symbol, IdentIsRaw),
335335
/// This identifier (and its span) is the lifetime passed to the
336336
/// declarative macro. The span in the surrounding `Token` is the span of
337337
/// the `lifetime` metavariable in the macro's RHS.
338-
NtLifetime(Ident),
338+
NtLifetime(Ident, IdentIsRaw),
339339

340340
/// An embedded AST node, as produced by a macro. This only exists for
341341
/// historical reasons. We'd like to get rid of it, for multiple reasons.
@@ -458,7 +458,7 @@ impl Token {
458458
/// if they keep spans or perform edition checks.
459459
pub fn uninterpolated_span(&self) -> Span {
460460
match self.kind {
461-
NtIdent(ident, _) | NtLifetime(ident) => ident.span,
461+
NtIdent(ident, _) | NtLifetime(ident, _) => ident.span,
462462
Interpolated(ref nt) => nt.use_span(),
463463
_ => self.span,
464464
}
@@ -646,7 +646,9 @@ impl Token {
646646
pub fn uninterpolate(&self) -> Cow<'_, Token> {
647647
match self.kind {
648648
NtIdent(ident, is_raw) => Cow::Owned(Token::new(Ident(ident.name, is_raw), ident.span)),
649-
NtLifetime(ident) => Cow::Owned(Token::new(Lifetime(ident.name), ident.span)),
649+
NtLifetime(ident, is_raw) => {
650+
Cow::Owned(Token::new(Lifetime(ident.name, is_raw), ident.span))
651+
}
650652
_ => Cow::Borrowed(self),
651653
}
652654
}
@@ -664,11 +666,11 @@ impl Token {
664666

665667
/// Returns a lifetime identifier if this token is a lifetime.
666668
#[inline]
667-
pub fn lifetime(&self) -> Option<Ident> {
669+
pub fn lifetime(&self) -> Option<(Ident, IdentIsRaw)> {
668670
// We avoid using `Token::uninterpolate` here because it's slow.
669671
match self.kind {
670-
Lifetime(name) => Some(Ident::new(name, self.span)),
671-
NtLifetime(ident) => Some(ident),
672+
Lifetime(name, is_raw) => Some((Ident::new(name, self.span), is_raw)),
673+
NtLifetime(ident, is_raw) => Some((ident, is_raw)),
672674
_ => None,
673675
}
674676
}
@@ -850,7 +852,7 @@ impl Token {
850852
_ => return None,
851853
},
852854
SingleQuote => match joint.kind {
853-
Ident(name, IdentIsRaw::No) => Lifetime(Symbol::intern(&format!("'{name}"))),
855+
Ident(name, is_raw) => Lifetime(Symbol::intern(&format!("'{name}")), is_raw),
854856
_ => return None,
855857
},
856858

compiler/rustc_ast/src/tokenstream.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,11 @@ impl TokenStream {
482482
token::NtIdent(ident, is_raw) => {
483483
TokenTree::Token(Token::new(token::Ident(ident.name, is_raw), ident.span), spacing)
484484
}
485-
token::NtLifetime(ident) => TokenTree::Delimited(
485+
token::NtLifetime(ident, is_raw) => TokenTree::Delimited(
486486
DelimSpan::from_single(token.span),
487487
DelimSpacing::new(Spacing::JointHidden, spacing),
488488
Delimiter::Invisible,
489-
TokenStream::token_alone(token::Lifetime(ident.name), ident.span),
489+
TokenStream::token_alone(token::Lifetime(ident.name, is_raw), ident.span),
490490
),
491491
token::Interpolated(ref nt) => TokenTree::Delimited(
492492
DelimSpan::from_single(token.span),

compiler/rustc_ast_pretty/src/pprust/state.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ use std::borrow::Cow;
1111
use ast::TraitBoundModifiers;
1212
use rustc_ast::attr::AttrIdGenerator;
1313
use rustc_ast::ptr::P;
14-
use rustc_ast::token::{self, BinOpToken, CommentKind, Delimiter, Nonterminal, Token, TokenKind};
14+
use rustc_ast::token::{
15+
self, BinOpToken, CommentKind, Delimiter, IdentIsRaw, Nonterminal, Token, TokenKind,
16+
};
1517
use rustc_ast::tokenstream::{Spacing, TokenStream, TokenTree};
1618
use rustc_ast::util::classify;
1719
use rustc_ast::util::comments::{Comment, CommentStyle};
@@ -947,8 +949,13 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
947949
token::NtIdent(ident, is_raw) => {
948950
IdentPrinter::for_ast_ident(ident, is_raw.into()).to_string().into()
949951
}
950-
token::Lifetime(name) => name.to_string().into(),
951-
token::NtLifetime(ident) => ident.name.to_string().into(),
952+
953+
token::Lifetime(name, IdentIsRaw::No)
954+
| token::NtLifetime(Ident { name, .. }, IdentIsRaw::No) => name.to_string().into(),
955+
token::Lifetime(name, IdentIsRaw::Yes)
956+
| token::NtLifetime(Ident { name, .. }, IdentIsRaw::Yes) => {
957+
format!("'r#{}", &name.as_str()[1..]).into()
958+
}
952959

953960
/* Other */
954961
token::DocComment(comment_kind, attr_style, data) => {

compiler/rustc_expand/src/mbe/macro_parser.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,10 @@ pub(crate) enum NamedMatch {
398398
fn token_name_eq(t1: &Token, t2: &Token) -> bool {
399399
if let (Some((ident1, is_raw1)), Some((ident2, is_raw2))) = (t1.ident(), t2.ident()) {
400400
ident1.name == ident2.name && is_raw1 == is_raw2
401-
} else if let (Some(ident1), Some(ident2)) = (t1.lifetime(), t2.lifetime()) {
402-
ident1.name == ident2.name
401+
} else if let (Some((ident1, is_raw1)), Some((ident2, is_raw2))) =
402+
(t1.lifetime(), t2.lifetime())
403+
{
404+
ident1.name == ident2.name && is_raw1 == is_raw2
403405
} else {
404406
t1.kind == t2.kind
405407
}

compiler/rustc_expand/src/mbe/transcribe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ pub(super) fn transcribe<'a>(
283283
let kind = token::NtIdent(*ident, *is_raw);
284284
TokenTree::token_alone(kind, sp)
285285
}
286-
MatchedSingle(ParseNtResult::Lifetime(ident)) => {
286+
MatchedSingle(ParseNtResult::Lifetime(ident, is_raw)) => {
287287
marker.visit_span(&mut sp);
288-
let kind = token::NtLifetime(*ident);
288+
let kind = token::NtLifetime(*ident, *is_raw);
289289
TokenTree::token_alone(kind, sp)
290290
}
291291
MatchedSingle(ParseNtResult::Nt(nt)) => {

compiler/rustc_expand/src/proc_macro_server.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,16 @@ impl FromInternal<(TokenStream, &mut Rustc<'_, '_>)> for Vec<TokenTree<TokenStre
229229
span: ident.span,
230230
})),
231231

232-
Lifetime(name) => {
232+
Lifetime(name, is_raw) => {
233233
let ident = symbol::Ident::new(name, span).without_first_quote();
234234
trees.extend([
235235
TokenTree::Punct(Punct { ch: b'\'', joint: true, span }),
236-
TokenTree::Ident(Ident { sym: ident.name, is_raw: false, span }),
236+
TokenTree::Ident(Ident { sym: ident.name, is_raw: is_raw.into(), span }),
237237
]);
238238
}
239-
NtLifetime(ident) => {
240-
let stream = TokenStream::token_alone(token::Lifetime(ident.name), ident.span);
239+
NtLifetime(ident, is_raw) => {
240+
let stream =
241+
TokenStream::token_alone(token::Lifetime(ident.name, is_raw), ident.span);
241242
trees.push(TokenTree::Group(Group {
242243
delimiter: pm::Delimiter::None,
243244
stream: Some(stream),

compiler/rustc_hir_analysis/src/check/check.rs

-11
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,6 @@ pub fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Abi) {
5151
});
5252
}
5353
}
54-
55-
// This ABI is only allowed on function pointers
56-
if abi == Abi::CCmseNonSecureCall {
57-
struct_span_code_err!(
58-
tcx.dcx(),
59-
span,
60-
E0781,
61-
"the `\"C-cmse-nonsecure-call\"` ABI is only allowed on function pointers"
62-
)
63-
.emit();
64-
}
6554
}
6655

6756
fn check_struct(tcx: TyCtxt<'_>, def_id: LocalDefId) {

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+16-15
Original file line numberDiff line numberDiff line change
@@ -1481,17 +1481,21 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
14811481

14821482
// Figure out if this is a type/trait segment,
14831483
// which requires object lifetime defaults.
1484-
let type_def_id = match res {
1485-
Res::Def(DefKind::AssocTy, def_id) if depth == 1 => Some(self.tcx.parent(def_id)),
1486-
Res::Def(DefKind::Variant, def_id) if depth == 0 => Some(self.tcx.parent(def_id)),
1487-
Res::Def(
1488-
DefKind::Struct
1489-
| DefKind::Union
1490-
| DefKind::Enum
1491-
| DefKind::TyAlias
1492-
| DefKind::Trait,
1493-
def_id,
1494-
) if depth == 0 => Some(def_id),
1484+
let type_def_id = match (res, depth) {
1485+
(Res::Def(DefKind::AssocTy, def_id), 1) => Some(self.tcx.parent(def_id)),
1486+
(Res::Def(DefKind::Variant, def_id), 0) => Some(self.tcx.parent(def_id)),
1487+
(
1488+
Res::Def(
1489+
DefKind::Struct
1490+
| DefKind::Union
1491+
| DefKind::Enum
1492+
| DefKind::TyAlias
1493+
| DefKind::Trait
1494+
| DefKind::AssocTy,
1495+
def_id,
1496+
),
1497+
0,
1498+
) => Some(def_id),
14951499
_ => None,
14961500
};
14971501

@@ -1535,9 +1539,6 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
15351539
let map = &self.map;
15361540
let generics = self.tcx.generics_of(def_id);
15371541

1538-
// `type_def_id` points to an item, so there is nothing to inherit generics from.
1539-
debug_assert_eq!(generics.parent_count, 0);
1540-
15411542
let set_to_region = |set: ObjectLifetimeDefault| match set {
15421543
ObjectLifetimeDefault::Empty => {
15431544
if in_body {
@@ -1548,8 +1549,8 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
15481549
}
15491550
ObjectLifetimeDefault::Static => Some(ResolvedArg::StaticLifetime),
15501551
ObjectLifetimeDefault::Param(param_def_id) => {
1551-
// This index can be used with `generic_args` since `parent_count == 0`.
15521552
let index = generics.param_def_id_to_index[&param_def_id] as usize;
1553+
let index = index - generics.parent_count;
15531554
generic_args.args.get(index).and_then(|arg| match arg {
15541555
GenericArg::Lifetime(lt) => map.defs.get(&lt.hir_id).copied(),
15551556
_ => None,

compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use rustc_errors::DiagCtxtHandle;
2-
use rustc_hir as hir;
3-
use rustc_hir::HirId;
1+
use rustc_errors::{struct_span_code_err, DiagCtxtHandle, E0781};
2+
use rustc_hir::{self as hir, HirId};
43
use rustc_middle::ty::layout::LayoutError;
54
use rustc_middle::ty::{self, ParamEnv, TyCtxt};
65
use rustc_span::Span;
@@ -26,7 +25,19 @@ pub fn validate_cmse_abi<'tcx>(
2625
..
2726
}) = hir_node
2827
else {
29-
// might happen when this ABI is used incorrectly. That will be handled elsewhere
28+
let span = match tcx.parent_hir_node(hir_id) {
29+
hir::Node::Item(hir::Item {
30+
kind: hir::ItemKind::ForeignMod { .. }, span, ..
31+
}) => *span,
32+
_ => tcx.hir().span(hir_id),
33+
};
34+
struct_span_code_err!(
35+
tcx.dcx(),
36+
span,
37+
E0781,
38+
"the `\"C-cmse-nonsecure-call\"` ABI is only allowed on function pointers"
39+
)
40+
.emit();
3041
return;
3142
};
3243

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
22932293
let fn_ty = tcx.mk_fn_sig(input_tys, output_ty, decl.c_variadic, safety, abi);
22942294
let bare_fn_ty = ty::Binder::bind_with_vars(fn_ty, bound_vars);
22952295

2296+
if let hir::Node::Ty(hir::Ty { kind: hir::TyKind::BareFn(bare_fn_ty), span, .. }) =
2297+
tcx.hir_node(hir_id)
2298+
{
2299+
crate::check::check_abi(tcx, hir_id, *span, bare_fn_ty.abi);
2300+
}
2301+
22962302
// reject function types that violate cmse ABI requirements
22972303
cmse::validate_cmse_abi(self.tcx(), self.dcx(), hir_id, abi, bare_fn_ty);
22982304

compiler/rustc_hir_typeck/src/coercion.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ struct Coerce<'a, 'tcx> {
8181
/// See #47489 and #48598
8282
/// See docs on the "AllowTwoPhase" type for a more detailed discussion
8383
allow_two_phase: AllowTwoPhase,
84+
coerce_never: bool,
8485
}
8586

8687
impl<'a, 'tcx> Deref for Coerce<'a, 'tcx> {
@@ -124,8 +125,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
124125
fcx: &'f FnCtxt<'f, 'tcx>,
125126
cause: ObligationCause<'tcx>,
126127
allow_two_phase: AllowTwoPhase,
128+
coerce_never: bool,
127129
) -> Self {
128-
Coerce { fcx, cause, allow_two_phase, use_lub: false }
130+
Coerce { fcx, cause, allow_two_phase, use_lub: false, coerce_never }
129131
}
130132

131133
fn unify(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> InferResult<'tcx, Ty<'tcx>> {
@@ -176,7 +178,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
176178

177179
// Coercing from `!` to any type is allowed:
178180
if a.is_never() {
179-
return success(simple(Adjust::NeverToAny)(b), b, vec![]);
181+
if self.coerce_never {
182+
return success(simple(Adjust::NeverToAny)(b), b, vec![]);
183+
} else {
184+
return self.unify_and(a, b, identity);
185+
}
180186
}
181187

182188
// Coercing *from* an unresolved inference variable means that
@@ -978,7 +984,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
978984
/// The expressions *must not* have any preexisting adjustments.
979985
pub fn coerce(
980986
&self,
981-
expr: &hir::Expr<'_>,
987+
expr: &'tcx hir::Expr<'tcx>,
982988
expr_ty: Ty<'tcx>,
983989
mut target: Ty<'tcx>,
984990
allow_two_phase: AllowTwoPhase,
@@ -995,7 +1001,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9951001

9961002
let cause =
9971003
cause.unwrap_or_else(|| self.cause(expr.span, ObligationCauseCode::ExprAssignable));
998-
let coerce = Coerce::new(self, cause, allow_two_phase);
1004+
let coerce =
1005+
Coerce::new(self, cause, allow_two_phase, self.expr_is_rvalue_for_divergence(expr));
9991006
let ok = self.commit_if_ok(|_| coerce.coerce(source, target))?;
10001007

10011008
let (adjustments, _) = self.register_infer_ok_obligations(ok);
@@ -1018,7 +1025,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10181025

10191026
let cause = self.cause(DUMMY_SP, ObligationCauseCode::ExprAssignable);
10201027
// We don't ever need two-phase here since we throw out the result of the coercion
1021-
let coerce = Coerce::new(self, cause, AllowTwoPhase::No);
1028+
let coerce = Coerce::new(self, cause, AllowTwoPhase::No, true);
10221029
self.probe(|_| {
10231030
let Ok(ok) = coerce.coerce(source, target) else {
10241031
return false;
@@ -1035,7 +1042,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10351042
pub fn deref_steps(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> Option<usize> {
10361043
let cause = self.cause(DUMMY_SP, ObligationCauseCode::ExprAssignable);
10371044
// We don't ever need two-phase here since we throw out the result of the coercion
1038-
let coerce = Coerce::new(self, cause, AllowTwoPhase::No);
1045+
let coerce = Coerce::new(self, cause, AllowTwoPhase::No, true);
10391046
coerce
10401047
.autoderef(DUMMY_SP, expr_ty)
10411048
.find_map(|(ty, steps)| self.probe(|_| coerce.unify(ty, target)).ok().map(|_| steps))
@@ -1192,7 +1199,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11921199
// probably aren't processing function arguments here and even if we were,
11931200
// they're going to get autorefed again anyway and we can apply 2-phase borrows
11941201
// at that time.
1195-
let mut coerce = Coerce::new(self, cause.clone(), AllowTwoPhase::No);
1202+
let mut coerce = Coerce::new(self, cause.clone(), AllowTwoPhase::No, true);
11961203
coerce.use_lub = true;
11971204

11981205
// First try to coerce the new expression to the type of the previous ones,

0 commit comments

Comments
 (0)