Skip to content

Commit d0f23b4

Browse files
committed
Auto merge of #3857 - rust-lang:rustup-2024-09-02, r=RalfJung
Automatic Rustup
2 parents 3c0996b + 9fe4539 commit d0f23b4

File tree

136 files changed

+1185
-1177
lines changed

Some content is hidden

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

136 files changed

+1185
-1177
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4978,15 +4978,15 @@ dependencies = [
49784978

49794979
[[package]]
49804980
name = "stacker"
4981-
version = "0.1.15"
4981+
version = "0.1.17"
49824982
source = "registry+https://github.com/rust-lang/crates.io-index"
4983-
checksum = "c886bd4480155fd3ef527d45e9ac8dd7118a898a46530b7b94c3e21866259fce"
4983+
checksum = "799c883d55abdb5e98af1a7b3f23b9b6de8ecada0ecac058672d7635eb48ca7b"
49844984
dependencies = [
49854985
"cc",
49864986
"cfg-if",
49874987
"libc",
49884988
"psm",
4989-
"winapi",
4989+
"windows-sys 0.59.0",
49904990
]
49914991

49924992
[[package]]

compiler/rustc_ast/src/visit.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ pub enum FnKind<'a> {
6969
Fn(FnCtxt, Ident, &'a FnSig, &'a Visibility, &'a Generics, Option<&'a Block>),
7070

7171
/// E.g., `|x, y| body`.
72-
Closure(&'a ClosureBinder, &'a FnDecl, &'a Expr),
72+
Closure(&'a ClosureBinder, &'a Option<CoroutineKind>, &'a FnDecl, &'a Expr),
7373
}
7474

7575
impl<'a> FnKind<'a> {
7676
pub fn header(&self) -> Option<&'a FnHeader> {
7777
match *self {
7878
FnKind::Fn(_, _, sig, _, _, _) => Some(&sig.header),
79-
FnKind::Closure(_, _, _) => None,
79+
FnKind::Closure(..) => None,
8080
}
8181
}
8282

@@ -90,7 +90,7 @@ impl<'a> FnKind<'a> {
9090
pub fn decl(&self) -> &'a FnDecl {
9191
match self {
9292
FnKind::Fn(_, _, sig, _, _, _) => &sig.decl,
93-
FnKind::Closure(_, decl, _) => decl,
93+
FnKind::Closure(_, _, decl, _) => decl,
9494
}
9595
}
9696

@@ -839,7 +839,7 @@ pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Resu
839839
try_visit!(walk_fn_decl(visitor, decl));
840840
visit_opt!(visitor, visit_block, body);
841841
}
842-
FnKind::Closure(binder, decl, body) => {
842+
FnKind::Closure(binder, _coroutine_kind, decl, body) => {
843843
try_visit!(visitor.visit_closure_binder(binder));
844844
try_visit!(walk_fn_decl(visitor, decl));
845845
try_visit!(visitor.visit_expr(body));
@@ -1107,7 +1107,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V
11071107
ExprKind::Closure(box Closure {
11081108
binder,
11091109
capture_clause,
1110-
coroutine_kind: _,
1110+
coroutine_kind,
11111111
constness: _,
11121112
movability: _,
11131113
fn_decl,
@@ -1116,7 +1116,11 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V
11161116
fn_arg_span: _,
11171117
}) => {
11181118
try_visit!(visitor.visit_capture_by(capture_clause));
1119-
try_visit!(visitor.visit_fn(FnKind::Closure(binder, fn_decl, body), *span, *id))
1119+
try_visit!(visitor.visit_fn(
1120+
FnKind::Closure(binder, coroutine_kind, fn_decl, body),
1121+
*span,
1122+
*id
1123+
))
11201124
}
11211125
ExprKind::Block(block, opt_label) => {
11221126
visit_opt!(visitor, visit_label, opt_label);

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ use std::collections::hash_map::Entry;
4545
use rustc_ast::node_id::NodeMap;
4646
use rustc_ast::ptr::P;
4747
use rustc_ast::{self as ast, *};
48-
use rustc_ast_pretty::pprust;
4948
use rustc_data_structures::captures::Captures;
5049
use rustc_data_structures::fingerprint::Fingerprint;
5150
use rustc_data_structures::fx::FxIndexSet;
@@ -837,7 +836,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
837836

838837
(hir::ParamName::Fresh, hir::LifetimeParamKind::Elided(kind))
839838
}
840-
LifetimeRes::Static | LifetimeRes::Error => return None,
839+
LifetimeRes::Static { .. } | LifetimeRes::Error => return None,
841840
res => panic!(
842841
"Unexpected lifetime resolution {:?} for {:?} at {:?}",
843842
res, ident, ident.span
@@ -1399,24 +1398,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13991398
self.tcx.dcx().emit_err(errors::NoPreciseCapturesOnApit { span });
14001399
}
14011400

1402-
let span = t.span;
1403-
1404-
// HACK: pprust breaks strings with newlines when the type
1405-
// gets too long. We don't want these to show up in compiler
1406-
// output or built artifacts, so replace them here...
1407-
// Perhaps we should instead format APITs more robustly.
1408-
let ident = Ident::from_str_and_span(
1409-
&pprust::ty_to_string(t).replace('\n', " "),
1410-
span,
1411-
);
1412-
1413-
self.create_def(
1414-
self.current_hir_id_owner.def_id, // FIXME: should this use self.current_def_id_parent?
1415-
*def_node_id,
1416-
ident.name,
1417-
DefKind::TyParam,
1418-
span,
1419-
);
1401+
let def_id = self.local_def_id(*def_node_id);
1402+
let name = self.tcx.item_name(def_id.to_def_id());
1403+
let ident = Ident::new(name, span);
14201404
let (param, bounds, path) = self.lower_universal_param_and_bounds(
14211405
*def_node_id,
14221406
span,
@@ -1618,13 +1602,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16181602
opaque_ty_span: Span,
16191603
lower_item_bounds: impl FnOnce(&mut Self) -> &'hir [hir::GenericBound<'hir>],
16201604
) -> hir::TyKind<'hir> {
1621-
let opaque_ty_def_id = self.create_def(
1622-
self.current_hir_id_owner.def_id, // FIXME: should this use self.current_def_id_parent?
1623-
opaque_ty_node_id,
1624-
kw::Empty,
1625-
DefKind::OpaqueTy,
1626-
opaque_ty_span,
1627-
);
1605+
let opaque_ty_def_id = self.local_def_id(opaque_ty_node_id);
16281606
debug!(?opaque_ty_def_id);
16291607

16301608
// Map from captured (old) lifetime to synthetic (new) lifetime.
@@ -1656,7 +1634,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16561634
}
16571635

16581636
// Opaques do not capture `'static`
1659-
LifetimeRes::Static | LifetimeRes::Error => {
1637+
LifetimeRes::Static { .. } | LifetimeRes::Error => {
16601638
continue;
16611639
}
16621640

@@ -2069,7 +2047,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20692047
hir::LifetimeName::Param(param)
20702048
}
20712049
LifetimeRes::Infer => hir::LifetimeName::Infer,
2072-
LifetimeRes::Static => hir::LifetimeName::Static,
2050+
LifetimeRes::Static { .. } => hir::LifetimeName::Static,
20732051
LifetimeRes::Error => hir::LifetimeName::Error,
20742052
res => panic!(
20752053
"Unexpected lifetime resolution {:?} for {:?} at {:?}",

compiler/rustc_ast_lowering/src/lifetime_collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl<'ast> LifetimeCollectVisitor<'ast> {
2727
self.collected_lifetimes.insert(lifetime);
2828
}
2929
}
30-
LifetimeRes::Static | LifetimeRes::Error => {
30+
LifetimeRes::Static { .. } | LifetimeRes::Error => {
3131
self.collected_lifetimes.insert(lifetime);
3232
}
3333
LifetimeRes::Infer => {}

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
14851485

14861486
let disallowed = (!tilde_const_allowed).then(|| match fk {
14871487
FnKind::Fn(_, ident, _, _, _, _) => TildeConstReason::Function { ident: ident.span },
1488-
FnKind::Closure(_, _, _) => TildeConstReason::Closure,
1488+
FnKind::Closure(..) => TildeConstReason::Closure,
14891489
});
14901490
self.with_tilde_const(disallowed, |this| visit::walk_fn(this, fk));
14911491
}

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 10 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use rustc_ast::{ast, attr, MetaItemKind, NestedMetaItem};
22
use rustc_attr::{list_contains_name, InlineAttr, InstructionSetAttr, OptimizeAttr};
3-
use rustc_data_structures::fx::FxHashSet;
43
use rustc_errors::codes::*;
54
use rustc_errors::{struct_span_code_err, DiagMessage, SubdiagMessage};
65
use rustc_hir as hir;
@@ -9,7 +8,7 @@ use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
98
use rustc_hir::weak_lang_items::WEAK_LANG_ITEMS;
109
use rustc_hir::{lang_items, LangItem};
1110
use rustc_middle::middle::codegen_fn_attrs::{
12-
CodegenFnAttrFlags, CodegenFnAttrs, PatchableFunctionEntry, TargetFeature,
11+
CodegenFnAttrFlags, CodegenFnAttrs, PatchableFunctionEntry,
1312
};
1413
use rustc_middle::mir::mono::Linkage;
1514
use rustc_middle::query::Providers;
@@ -18,7 +17,6 @@ use rustc_session::lint;
1817
use rustc_session::parse::feature_err;
1918
use rustc_span::symbol::Ident;
2019
use rustc_span::{sym, Span};
21-
use rustc_target::abi::VariantIdx;
2220
use rustc_target::spec::{abi, SanitizerSet};
2321

2422
use crate::errors;
@@ -80,26 +78,23 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
8078
let mut link_ordinal_span = None;
8179
let mut no_sanitize_span = None;
8280

83-
let fn_sig_outer = || {
84-
use DefKind::*;
85-
86-
let def_kind = tcx.def_kind(did);
87-
if let Fn | AssocFn | Variant | Ctor(..) = def_kind { Some(tcx.fn_sig(did)) } else { None }
88-
};
89-
9081
for attr in attrs.iter() {
9182
// In some cases, attribute are only valid on functions, but it's the `check_attr`
9283
// pass that check that they aren't used anywhere else, rather this module.
9384
// In these cases, we bail from performing further checks that are only meaningful for
9485
// functions (such as calling `fn_sig`, which ICEs if given a non-function). We also
9586
// report a delayed bug, just in case `check_attr` isn't doing its job.
9687
let fn_sig = || {
97-
let sig = fn_sig_outer();
98-
if sig.is_none() {
88+
use DefKind::*;
89+
90+
let def_kind = tcx.def_kind(did);
91+
if let Fn | AssocFn | Variant | Ctor(..) = def_kind {
92+
Some(tcx.fn_sig(did))
93+
} else {
9994
tcx.dcx()
10095
.span_delayed_bug(attr.span, "this attribute can only be applied to functions");
96+
None
10197
}
102-
sig
10398
};
10499

105100
let Some(Ident { name, .. }) = attr.ident() else {
@@ -618,93 +613,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
618613
}
619614
}
620615

621-
if let Some(sig) = fn_sig_outer() {
622-
// Collect target features from types reachable from arguments.
623-
// We define a type as "reachable" if:
624-
// - it is a function argument
625-
// - it is a field of a reachable struct
626-
// - there is a reachable reference to it
627-
// FIXME(struct_target_features): we may want to cache the result of this computation.
628-
let mut visited_types = FxHashSet::default();
629-
let mut reachable_types: Vec<_> = sig.skip_binder().inputs().skip_binder().to_owned();
630-
let mut additional_tf = vec![];
631-
632-
while let Some(ty) = reachable_types.pop() {
633-
if visited_types.contains(&ty) {
634-
continue;
635-
}
636-
visited_types.insert(ty);
637-
match ty.kind() {
638-
ty::Alias(..) => {
639-
if let Ok(t) =
640-
tcx.try_normalize_erasing_regions(tcx.param_env(did.to_def_id()), ty)
641-
{
642-
reachable_types.push(t)
643-
}
644-
}
645-
646-
ty::Ref(_, inner, _) => reachable_types.push(*inner),
647-
ty::Tuple(tys) => reachable_types.extend(tys.iter()),
648-
ty::Adt(adt_def, args) => {
649-
additional_tf.extend_from_slice(tcx.struct_target_features(adt_def.did()));
650-
// This only recurses into structs as i.e. an Option<TargetFeature> is an ADT
651-
// that doesn't actually always contain a TargetFeature.
652-
if adt_def.is_struct() {
653-
reachable_types.extend(
654-
adt_def
655-
.variant(VariantIdx::from_usize(0))
656-
.fields
657-
.iter()
658-
.map(|field| field.ty(tcx, args)),
659-
);
660-
}
661-
}
662-
ty::Bool
663-
| ty::Char
664-
| ty::Int(..)
665-
| ty::Uint(..)
666-
| ty::Float(..)
667-
| ty::Foreign(..)
668-
| ty::Str
669-
| ty::Array(..)
670-
| ty::Pat(..)
671-
| ty::Slice(..)
672-
| ty::RawPtr(..)
673-
| ty::FnDef(..)
674-
| ty::FnPtr(..)
675-
| ty::Dynamic(..)
676-
| ty::Closure(..)
677-
| ty::CoroutineClosure(..)
678-
| ty::Coroutine(..)
679-
| ty::CoroutineWitness(..)
680-
| ty::Never
681-
| ty::Param(..)
682-
| ty::Bound(..)
683-
| ty::Placeholder(..)
684-
| ty::Infer(..)
685-
| ty::Error(..) => (),
686-
}
687-
}
688-
689-
// FIXME(struct_target_features): is this really necessary?
690-
if !additional_tf.is_empty() && sig.skip_binder().abi() != abi::Abi::Rust {
691-
tcx.dcx().span_err(
692-
tcx.hir().span(tcx.local_def_id_to_hir_id(did)),
693-
"cannot use a struct with target features in a function with non-Rust ABI",
694-
);
695-
}
696-
if !additional_tf.is_empty() && codegen_fn_attrs.inline == InlineAttr::Always {
697-
tcx.dcx().span_err(
698-
tcx.hir().span(tcx.local_def_id_to_hir_id(did)),
699-
"cannot use a struct with target features in a #[inline(always)] function",
700-
);
701-
}
702-
codegen_fn_attrs
703-
.target_features
704-
.extend(additional_tf.iter().map(|tf| TargetFeature { implied: true, ..*tf }));
705-
}
706-
707-
// If a function uses non-default target_features it can't be inlined into general
616+
// If a function uses #[target_feature] it can't be inlined into general
708617
// purpose functions as they wouldn't have the right target features
709618
// enabled. For that reason we also forbid #[inline(always)] as it can't be
710619
// respected.
@@ -849,20 +758,6 @@ fn check_link_name_xor_ordinal(
849758
}
850759
}
851760

852-
fn struct_target_features(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &[TargetFeature] {
853-
let mut features = vec![];
854-
let supported_features = tcx.supported_target_features(LOCAL_CRATE);
855-
for attr in tcx.get_attrs(def_id, sym::target_feature) {
856-
from_target_feature(tcx, attr, supported_features, &mut features);
857-
}
858-
tcx.arena.alloc_slice(&features)
859-
}
860-
861761
pub fn provide(providers: &mut Providers) {
862-
*providers = Providers {
863-
codegen_fn_attrs,
864-
should_inherit_track_caller,
865-
struct_target_features,
866-
..*providers
867-
};
762+
*providers = Providers { codegen_fn_attrs, should_inherit_track_caller, ..*providers };
868763
}

compiler/rustc_data_structures/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ rustc_index = { path = "../rustc_index", package = "rustc_index" }
2222
rustc_macros = { path = "../rustc_macros" }
2323
rustc_serialize = { path = "../rustc_serialize" }
2424
smallvec = { version = "1.8.1", features = ["const_generics", "union", "may_dangle"] }
25-
stacker = "0.1.15"
25+
stacker = "0.1.17"
2626
tempfile = "3.2"
2727
thin-vec = "0.2.12"
2828
tracing = "0.1"

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_lint_defs::{Applicability, LintExpectationId};
1212
use rustc_macros::{Decodable, Encodable};
1313
use rustc_span::source_map::Spanned;
1414
use rustc_span::symbol::Symbol;
15-
use rustc_span::{Span, DUMMY_SP};
15+
use rustc_span::{AttrId, Span, DUMMY_SP};
1616
use tracing::debug;
1717

1818
use crate::snippet::Style;
@@ -356,24 +356,19 @@ impl DiagInner {
356356

357357
pub(crate) fn update_unstable_expectation_id(
358358
&mut self,
359-
unstable_to_stable: &FxIndexMap<LintExpectationId, LintExpectationId>,
359+
unstable_to_stable: &FxIndexMap<AttrId, LintExpectationId>,
360360
) {
361361
if let Level::Expect(expectation_id) | Level::ForceWarning(Some(expectation_id)) =
362362
&mut self.level
363+
&& let LintExpectationId::Unstable { attr_id, lint_index } = *expectation_id
363364
{
364-
if expectation_id.is_stable() {
365-
return;
366-
}
367-
368365
// The unstable to stable map only maps the unstable `AttrId` to a stable `HirId` with an attribute index.
369366
// The lint index inside the attribute is manually transferred here.
370-
let lint_index = expectation_id.get_lint_index();
371-
expectation_id.set_lint_index(None);
372-
let mut stable_id = unstable_to_stable
373-
.get(expectation_id)
374-
.expect("each unstable `LintExpectationId` must have a matching stable id")
375-
.normalize();
367+
let Some(stable_id) = unstable_to_stable.get(&attr_id) else {
368+
panic!("{expectation_id:?} must have a matching stable id")
369+
};
376370

371+
let mut stable_id = *stable_id;
377372
stable_id.set_lint_index(lint_index);
378373
*expectation_id = stable_id;
379374
}

0 commit comments

Comments
 (0)