Skip to content

Commit 16b5690

Browse files
committed
Auto merge of #127819 - matthiaskrgr:rollup-djdffkl, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #127669 (Fix the issue of invalid suggestion for a reference of iterator) - #127707 (match lowering: Use an iterator to find `expand_until`) - #127730 (Fix and enforce `unsafe_op_in_unsafe_fn` in compiler) - #127789 (delete #![allow(unsafe_op_in_unsafe_fn)] in teeos) - #127805 (run-make-support: update gimli to 0.31.0) - #127808 (Make ErrorGuaranteed discoverable outside types, consts, and lifetimes) - #127817 (Fix a bunch of sites that were walking instead of visiting, making it impossible for visitor impls to look at these values) - #127818 (Various ast validation simplifications) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a91f7d7 + ab4cc44 commit 16b5690

File tree

30 files changed

+643
-500
lines changed

30 files changed

+643
-500
lines changed

Diff for: Cargo.lock

+12-1
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,17 @@ dependencies = [
16181618
"rustc-std-workspace-core",
16191619
]
16201620

1621+
[[package]]
1622+
name = "gimli"
1623+
version = "0.31.0"
1624+
source = "registry+https://github.com/rust-lang/crates.io-index"
1625+
checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64"
1626+
dependencies = [
1627+
"fallible-iterator",
1628+
"indexmap",
1629+
"stable_deref_trait",
1630+
]
1631+
16211632
[[package]]
16221633
name = "glob"
16231634
version = "0.3.1"
@@ -3421,7 +3432,7 @@ dependencies = [
34213432
"ar",
34223433
"bstr",
34233434
"build_helper",
3424-
"gimli 0.28.1",
3435+
"gimli 0.31.0",
34253436
"object 0.34.0",
34263437
"regex",
34273438
"similar",

Diff for: compiler/rustc_abi/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ impl Step for Size {
627627

628628
#[inline]
629629
unsafe fn forward_unchecked(start: Self, count: usize) -> Self {
630-
Self::from_bytes(u64::forward_unchecked(start.bytes(), count))
630+
Self::from_bytes(unsafe { u64::forward_unchecked(start.bytes(), count) })
631631
}
632632

633633
#[inline]
@@ -642,7 +642,7 @@ impl Step for Size {
642642

643643
#[inline]
644644
unsafe fn backward_unchecked(start: Self, count: usize) -> Self {
645-
Self::from_bytes(u64::backward_unchecked(start.bytes(), count))
645+
Self::from_bytes(unsafe { u64::backward_unchecked(start.bytes(), count) })
646646
}
647647
}
648648

Diff for: compiler/rustc_ast/src/mut_visit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
482482
TyKind::Slice(ty) => vis.visit_ty(ty),
483483
TyKind::Ptr(mt) => vis.visit_mt(mt),
484484
TyKind::Ref(lt, mt) => {
485-
visit_opt(lt, |lt| noop_visit_lifetime(lt, vis));
485+
visit_opt(lt, |lt| vis.visit_lifetime(lt));
486486
vis.visit_mt(mt);
487487
}
488488
TyKind::BareFn(bft) => {
@@ -925,7 +925,7 @@ pub fn noop_flat_map_generic_param<T: MutVisitor>(
925925
vis.visit_id(id);
926926
visit_attrs(attrs, vis);
927927
vis.visit_ident(ident);
928-
visit_vec(bounds, |bound| noop_visit_param_bound(bound, vis));
928+
visit_vec(bounds, |bound| vis.visit_param_bound(bound));
929929
match kind {
930930
GenericParamKind::Lifetime => {}
931931
GenericParamKind::Type { default } => {
@@ -983,7 +983,7 @@ fn noop_visit_where_predicate<T: MutVisitor>(pred: &mut WherePredicate, vis: &mu
983983
}
984984
WherePredicate::RegionPredicate(rp) => {
985985
let WhereRegionPredicate { span, lifetime, bounds } = rp;
986-
noop_visit_lifetime(lifetime, vis);
986+
vis.visit_lifetime(lifetime);
987987
visit_vec(bounds, |bound| noop_visit_param_bound(bound, vis));
988988
vis.visit_span(span);
989989
}

Diff for: compiler/rustc_ast_passes/src/ast_validation.rs

+26-70
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,20 @@ use std::mem;
3838
use std::ops::{Deref, DerefMut};
3939
use thin_vec::thin_vec;
4040

41-
use crate::errors;
41+
use crate::errors::{self, TildeConstReason};
4242

4343
/// Is `self` allowed semantically as the first parameter in an `FnDecl`?
4444
enum SelfSemantic {
4545
Yes,
4646
No,
4747
}
4848

49-
/// What is the context that prevents using `~const`?
50-
// FIXME(effects): Consider getting rid of this in favor of `errors::TildeConstReason`, they're
51-
// almost identical. This gets rid of an abstraction layer which might be considered bad.
52-
enum DisallowTildeConstContext<'a> {
53-
TraitObject,
54-
Fn(FnKind<'a>),
55-
Trait(Span),
56-
TraitImpl(Span),
57-
Impl(Span),
58-
TraitAssocTy(Span),
59-
TraitImplAssocTy(Span),
60-
InherentAssocTy(Span),
61-
Item,
62-
}
63-
64-
enum TraitOrTraitImpl<'a> {
49+
enum TraitOrTraitImpl {
6550
Trait { span: Span, constness: Option<Span> },
66-
TraitImpl { constness: Const, polarity: ImplPolarity, trait_ref: &'a TraitRef },
51+
TraitImpl { constness: Const, polarity: ImplPolarity, trait_ref: Span },
6752
}
6853

69-
impl<'a> TraitOrTraitImpl<'a> {
54+
impl TraitOrTraitImpl {
7055
fn constness(&self) -> Option<Span> {
7156
match self {
7257
Self::Trait { constness: Some(span), .. }
@@ -81,9 +66,9 @@ struct AstValidator<'a> {
8166
features: &'a Features,
8267

8368
/// The span of the `extern` in an `extern { ... }` block, if any.
84-
extern_mod: Option<&'a Item>,
69+
extern_mod: Option<Span>,
8570

86-
outer_trait_or_trait_impl: Option<TraitOrTraitImpl<'a>>,
71+
outer_trait_or_trait_impl: Option<TraitOrTraitImpl>,
8772

8873
has_proc_macro_decls: bool,
8974

@@ -92,7 +77,7 @@ struct AstValidator<'a> {
9277
/// e.g., `impl Iterator<Item = impl Debug>`.
9378
outer_impl_trait: Option<Span>,
9479

95-
disallow_tilde_const: Option<DisallowTildeConstContext<'a>>,
80+
disallow_tilde_const: Option<TildeConstReason>,
9681

9782
/// Used to ban `impl Trait` in path projections like `<impl Iterator>::Item`
9883
/// or `Foo::Bar<impl Trait>`
@@ -115,7 +100,7 @@ impl<'a> AstValidator<'a> {
115100
trait_.map(|(constness, polarity, trait_ref)| TraitOrTraitImpl::TraitImpl {
116101
constness,
117102
polarity,
118-
trait_ref,
103+
trait_ref: trait_ref.path.span,
119104
}),
120105
);
121106
f(self);
@@ -145,7 +130,7 @@ impl<'a> AstValidator<'a> {
145130

146131
fn with_tilde_const(
147132
&mut self,
148-
disallowed: Option<DisallowTildeConstContext<'a>>,
133+
disallowed: Option<TildeConstReason>,
149134
f: impl FnOnce(&mut Self),
150135
) {
151136
let old = mem::replace(&mut self.disallow_tilde_const, disallowed);
@@ -224,7 +209,7 @@ impl<'a> AstValidator<'a> {
224209
}
225210
}
226211
TyKind::TraitObject(..) => self
227-
.with_tilde_const(Some(DisallowTildeConstContext::TraitObject), |this| {
212+
.with_tilde_const(Some(TildeConstReason::TraitObject), |this| {
228213
visit::walk_ty(this, t)
229214
}),
230215
TyKind::Path(qself, path) => {
@@ -354,7 +339,7 @@ impl<'a> AstValidator<'a> {
354339
}
355340
}
356341

357-
fn check_trait_fn_not_const(&self, constness: Const, parent: &TraitOrTraitImpl<'a>) {
342+
fn check_trait_fn_not_const(&self, constness: Const, parent: &TraitOrTraitImpl) {
358343
let Const::Yes(span) = constness else {
359344
return;
360345
};
@@ -367,7 +352,7 @@ impl<'a> AstValidator<'a> {
367352
..
368353
} = parent
369354
{
370-
Some(trait_ref.path.span.shrink_to_lo())
355+
Some(trait_ref.shrink_to_lo())
371356
} else {
372357
None
373358
};
@@ -579,7 +564,7 @@ impl<'a> AstValidator<'a> {
579564
}
580565

581566
fn current_extern_span(&self) -> Span {
582-
self.session.source_map().guess_head_span(self.extern_mod.unwrap().span)
567+
self.session.source_map().guess_head_span(self.extern_mod.unwrap())
583568
}
584569

585570
/// An `fn` in `extern { ... }` cannot have qualifiers, e.g. `async fn`.
@@ -980,7 +965,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
980965
this.visit_vis(&item.vis);
981966
this.visit_ident(item.ident);
982967
let disallowed = matches!(constness, Const::No)
983-
.then(|| DisallowTildeConstContext::TraitImpl(item.span));
968+
.then(|| TildeConstReason::TraitImpl { span: item.span });
984969
this.with_tilde_const(disallowed, |this| this.visit_generics(generics));
985970
this.visit_trait_ref(t);
986971
this.visit_ty(self_ty);
@@ -1035,7 +1020,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10351020
this.visit_vis(&item.vis);
10361021
this.visit_ident(item.ident);
10371022
this.with_tilde_const(
1038-
Some(DisallowTildeConstContext::Impl(item.span)),
1023+
Some(TildeConstReason::Impl { span: item.span }),
10391024
|this| this.visit_generics(generics),
10401025
);
10411026
this.visit_ty(self_ty);
@@ -1080,7 +1065,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10801065
}
10811066
ItemKind::ForeignMod(ForeignMod { abi, safety, .. }) => {
10821067
self.with_in_extern_mod(*safety, |this| {
1083-
let old_item = mem::replace(&mut this.extern_mod, Some(item));
1068+
let old_item = mem::replace(&mut this.extern_mod, Some(item.span));
10841069
this.visibility_not_permitted(
10851070
&item.vis,
10861071
errors::VisibilityNotPermittedNote::IndividualForeignItems,
@@ -1154,7 +1139,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11541139
this.visit_ident(item.ident);
11551140
let disallowed = is_const_trait
11561141
.is_none()
1157-
.then(|| DisallowTildeConstContext::Trait(item.span));
1142+
.then(|| TildeConstReason::Trait { span: item.span });
11581143
this.with_tilde_const(disallowed, |this| {
11591144
this.visit_generics(generics);
11601145
walk_list!(this, visit_param_bound, bounds, BoundKind::SuperTraits)
@@ -1399,40 +1384,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13991384
self.dcx().emit_err(errors::ConstBoundTraitObject { span: trait_ref.span });
14001385
}
14011386
(_, BoundConstness::Maybe(span), BoundPolarity::Positive)
1402-
if let Some(reason) = &self.disallow_tilde_const =>
1387+
if let Some(reason) = self.disallow_tilde_const =>
14031388
{
1404-
let reason = match reason {
1405-
DisallowTildeConstContext::Fn(FnKind::Closure(..)) => {
1406-
errors::TildeConstReason::Closure
1407-
}
1408-
DisallowTildeConstContext::Fn(FnKind::Fn(_, ident, ..)) => {
1409-
errors::TildeConstReason::Function { ident: ident.span }
1410-
}
1411-
&DisallowTildeConstContext::Trait(span) => {
1412-
errors::TildeConstReason::Trait { span }
1413-
}
1414-
&DisallowTildeConstContext::TraitImpl(span) => {
1415-
errors::TildeConstReason::TraitImpl { span }
1416-
}
1417-
&DisallowTildeConstContext::Impl(span) => {
1418-
// FIXME(effects): Consider providing a help message or even a structured
1419-
// suggestion for moving such bounds to the assoc const fns if available.
1420-
errors::TildeConstReason::Impl { span }
1421-
}
1422-
&DisallowTildeConstContext::TraitAssocTy(span) => {
1423-
errors::TildeConstReason::TraitAssocTy { span }
1424-
}
1425-
&DisallowTildeConstContext::TraitImplAssocTy(span) => {
1426-
errors::TildeConstReason::TraitImplAssocTy { span }
1427-
}
1428-
&DisallowTildeConstContext::InherentAssocTy(span) => {
1429-
errors::TildeConstReason::InherentAssocTy { span }
1430-
}
1431-
DisallowTildeConstContext::TraitObject => {
1432-
errors::TildeConstReason::TraitObject
1433-
}
1434-
DisallowTildeConstContext::Item => errors::TildeConstReason::Item,
1435-
};
14361389
self.dcx().emit_err(errors::TildeConstDisallowed { span, reason });
14371390
}
14381391
(
@@ -1569,7 +1522,10 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
15691522
.and_then(TraitOrTraitImpl::constness)
15701523
.is_some();
15711524

1572-
let disallowed = (!tilde_const_allowed).then(|| DisallowTildeConstContext::Fn(fk));
1525+
let disallowed = (!tilde_const_allowed).then(|| match fk {
1526+
FnKind::Fn(_, ident, _, _, _, _) => TildeConstReason::Function { ident: ident.span },
1527+
FnKind::Closure(_, _, _) => TildeConstReason::Closure,
1528+
});
15731529
self.with_tilde_const(disallowed, |this| visit::walk_fn(this, fk));
15741530
}
15751531

@@ -1664,12 +1620,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
16641620
AssocItemKind::Type(_) => {
16651621
let disallowed = (!parent_is_const).then(|| match self.outer_trait_or_trait_impl {
16661622
Some(TraitOrTraitImpl::Trait { .. }) => {
1667-
DisallowTildeConstContext::TraitAssocTy(item.span)
1623+
TildeConstReason::TraitAssocTy { span: item.span }
16681624
}
16691625
Some(TraitOrTraitImpl::TraitImpl { .. }) => {
1670-
DisallowTildeConstContext::TraitImplAssocTy(item.span)
1626+
TildeConstReason::TraitImplAssocTy { span: item.span }
16711627
}
1672-
None => DisallowTildeConstContext::InherentAssocTy(item.span),
1628+
None => TildeConstReason::InherentAssocTy { span: item.span },
16731629
});
16741630
self.with_tilde_const(disallowed, |this| {
16751631
this.with_in_trait_impl(None, |this| visit::walk_assoc_item(this, item, ctxt))
@@ -1852,7 +1808,7 @@ pub fn check_crate(
18521808
outer_trait_or_trait_impl: None,
18531809
has_proc_macro_decls: false,
18541810
outer_impl_trait: None,
1855-
disallow_tilde_const: Some(DisallowTildeConstContext::Item),
1811+
disallow_tilde_const: Some(TildeConstReason::Item),
18561812
is_impl_trait_banned: false,
18571813
extern_mod_safety: None,
18581814
lint_buffer: lints,

Diff for: compiler/rustc_ast_passes/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ pub struct TildeConstDisallowed {
612612
pub reason: TildeConstReason,
613613
}
614614

615-
#[derive(Subdiagnostic)]
615+
#[derive(Subdiagnostic, Copy, Clone)]
616616
pub enum TildeConstReason {
617617
#[note(ast_passes_closure)]
618618
Closure,

Diff for: compiler/rustc_codegen_llvm/src/allocator.rs

+27-23
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ pub(crate) unsafe fn codegen(
2121
) {
2222
let llcx = &*module_llvm.llcx;
2323
let llmod = module_llvm.llmod();
24-
let usize = match tcx.sess.target.pointer_width {
25-
16 => llvm::LLVMInt16TypeInContext(llcx),
26-
32 => llvm::LLVMInt32TypeInContext(llcx),
27-
64 => llvm::LLVMInt64TypeInContext(llcx),
28-
tws => bug!("Unsupported target word size for int: {}", tws),
24+
let usize = unsafe {
25+
match tcx.sess.target.pointer_width {
26+
16 => llvm::LLVMInt16TypeInContext(llcx),
27+
32 => llvm::LLVMInt32TypeInContext(llcx),
28+
64 => llvm::LLVMInt64TypeInContext(llcx),
29+
tws => bug!("Unsupported target word size for int: {}", tws),
30+
}
2931
};
30-
let i8 = llvm::LLVMInt8TypeInContext(llcx);
31-
let i8p = llvm::LLVMPointerTypeInContext(llcx, 0);
32+
let i8 = unsafe { llvm::LLVMInt8TypeInContext(llcx) };
33+
let i8p = unsafe { llvm::LLVMPointerTypeInContext(llcx, 0) };
3234

3335
if kind == AllocatorKind::Default {
3436
for method in ALLOCATOR_METHODS {
@@ -73,23 +75,25 @@ pub(crate) unsafe fn codegen(
7375
true,
7476
);
7577

76-
// __rust_alloc_error_handler_should_panic
77-
let name = OomStrategy::SYMBOL;
78-
let ll_g = llvm::LLVMRustGetOrInsertGlobal(llmod, name.as_ptr().cast(), name.len(), i8);
79-
if tcx.sess.default_hidden_visibility() {
80-
llvm::LLVMRustSetVisibility(ll_g, llvm::Visibility::Hidden);
81-
}
82-
let val = tcx.sess.opts.unstable_opts.oom.should_panic();
83-
let llval = llvm::LLVMConstInt(i8, val as u64, False);
84-
llvm::LLVMSetInitializer(ll_g, llval);
85-
86-
let name = NO_ALLOC_SHIM_IS_UNSTABLE;
87-
let ll_g = llvm::LLVMRustGetOrInsertGlobal(llmod, name.as_ptr().cast(), name.len(), i8);
88-
if tcx.sess.default_hidden_visibility() {
89-
llvm::LLVMRustSetVisibility(ll_g, llvm::Visibility::Hidden);
78+
unsafe {
79+
// __rust_alloc_error_handler_should_panic
80+
let name = OomStrategy::SYMBOL;
81+
let ll_g = llvm::LLVMRustGetOrInsertGlobal(llmod, name.as_ptr().cast(), name.len(), i8);
82+
if tcx.sess.default_hidden_visibility() {
83+
llvm::LLVMRustSetVisibility(ll_g, llvm::Visibility::Hidden);
84+
}
85+
let val = tcx.sess.opts.unstable_opts.oom.should_panic();
86+
let llval = llvm::LLVMConstInt(i8, val as u64, False);
87+
llvm::LLVMSetInitializer(ll_g, llval);
88+
89+
let name = NO_ALLOC_SHIM_IS_UNSTABLE;
90+
let ll_g = llvm::LLVMRustGetOrInsertGlobal(llmod, name.as_ptr().cast(), name.len(), i8);
91+
if tcx.sess.default_hidden_visibility() {
92+
llvm::LLVMRustSetVisibility(ll_g, llvm::Visibility::Hidden);
93+
}
94+
let llval = llvm::LLVMConstInt(i8, 0, False);
95+
llvm::LLVMSetInitializer(ll_g, llval);
9096
}
91-
let llval = llvm::LLVMConstInt(i8, 0, False);
92-
llvm::LLVMSetInitializer(ll_g, llval);
9397

9498
if tcx.sess.opts.debuginfo != DebugInfo::None {
9599
let dbg_cx = debuginfo::CodegenUnitDebugContext::new(llmod);

0 commit comments

Comments
 (0)