Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 204a1dd

Browse files
committed
Auto merge of rust-lang#121158 - GuillaumeGomez:rollup-l38pzjw, r=GuillaumeGomez
Rollup of 13 pull requests Successful merges: - rust-lang#118264 (Optimize `VecDeque::drain` for (half-)open ranges) - rust-lang#120741 (Make `io::BorrowedCursor::advance` safe) - rust-lang#120777 (Bump Unicode to version 15.1.0, regenerate tables) - rust-lang#120971 (Fix comment in core/src/str/validations.rs) - rust-lang#121034 (Improve wording of `static_mut_ref`) - rust-lang#121095 (Add extra indent spaces for rust-playground link) - rust-lang#121109 (Add an ErrorGuaranteed to ast::TyKind::Err (attempt 2)) - rust-lang#121119 (Make `async Fn` trait kind errors better) - rust-lang#121141 (Fix closure kind docs) - rust-lang#121145 (Update aarch64 target feature docs to match LLVM) - rust-lang#121146 (Only point out non-diverging arms for match suggestions) - rust-lang#121147 (Avoid debug logging entire MIR body) - rust-lang#121155 (doc: add note about panicking examples for strict_overflow_ops) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b656f51 + 35f8b3d commit 204a1dd

File tree

130 files changed

+1288
-825
lines changed

Some content is hidden

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

130 files changed

+1288
-825
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,10 +2136,12 @@ pub enum TyKind {
21362136
ImplicitSelf,
21372137
/// A macro in the type position.
21382138
MacCall(P<MacCall>),
2139-
/// Placeholder for a kind that has failed to be defined.
2140-
Err,
21412139
/// Placeholder for a `va_list`.
21422140
CVarArgs,
2141+
/// Sometimes we need a dummy value when no error has occurred.
2142+
Dummy,
2143+
/// Placeholder for a kind that has failed to be defined.
2144+
Err(ErrorGuaranteed),
21432145
}
21442146

21452147
impl TyKind {

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,12 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
481481
let Ty { id, kind, span, tokens } = ty.deref_mut();
482482
vis.visit_id(id);
483483
match kind {
484-
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err | TyKind::Never | TyKind::CVarArgs => {}
484+
TyKind::Infer
485+
| TyKind::ImplicitSelf
486+
| TyKind::Err(_)
487+
| TyKind::Dummy
488+
| TyKind::Never
489+
| TyKind::CVarArgs => {}
485490
TyKind::Slice(ty) => vis.visit_ty(ty),
486491
TyKind::Ptr(mt) => vis.visit_mt(mt),
487492
TyKind::Ref(lt, mt) => {
@@ -1649,7 +1654,7 @@ impl DummyAstNode for Ty {
16491654
fn dummy() -> Self {
16501655
Ty {
16511656
id: DUMMY_NODE_ID,
1652-
kind: TyKind::Err,
1657+
kind: TyKind::Dummy,
16531658
span: Default::default(),
16541659
tokens: Default::default(),
16551660
}

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
447447
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Impl);
448448
}
449449
TyKind::Typeof(expression) => visitor.visit_anon_const(expression),
450-
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {}
450+
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Dummy | TyKind::Err(_) => {}
451451
TyKind::MacCall(mac) => visitor.visit_mac_call(mac),
452452
TyKind::Never | TyKind::CVarArgs => {}
453453
TyKind::AnonStruct(_, ref fields) | TyKind::AnonUnion(_, ref fields) => {

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12861286
fn lower_ty_direct(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
12871287
let kind = match &t.kind {
12881288
TyKind::Infer => hir::TyKind::Infer,
1289-
TyKind::Err => hir::TyKind::Err(self.dcx().has_errors().unwrap()),
1289+
TyKind::Err(guar) => hir::TyKind::Err(*guar),
12901290
// Lower the anonymous structs or unions in a nested lowering context.
12911291
//
12921292
// ```
@@ -1504,6 +1504,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15041504
);
15051505
hir::TyKind::Err(guar)
15061506
}
1507+
TyKind::Dummy => panic!("`TyKind::Dummy` should never be lowered"),
15071508
};
15081509

15091510
hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.lower_node_id(t.id) }

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
881881
&item.vis,
882882
errors::VisibilityNotPermittedNote::TraitImpl,
883883
);
884-
if let TyKind::Err = self_ty.kind {
884+
// njn: use Dummy here
885+
if let TyKind::Err(_) = self_ty.kind {
885886
this.dcx().emit_err(errors::ObsoleteAuto { span: item.span });
886887
}
887888
if let (&Unsafe::Yes(span), &ImplPolarity::Negative(sp)) = (unsafety, polarity)

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,11 +1048,16 @@ impl<'a> State<'a> {
10481048
ast::TyKind::Infer => {
10491049
self.word("_");
10501050
}
1051-
ast::TyKind::Err => {
1051+
ast::TyKind::Err(_) => {
10521052
self.popen();
10531053
self.word("/*ERROR*/");
10541054
self.pclose();
10551055
}
1056+
ast::TyKind::Dummy => {
1057+
self.popen();
1058+
self.word("/*DUMMY*/");
1059+
self.pclose();
1060+
}
10561061
ast::TyKind::ImplicitSelf => {
10571062
self.word("Self");
10581063
}

compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ fn start<T: Termination + 'static>(
112112

113113
static mut NUM: u8 = 6 * 7;
114114

115-
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
116-
#[allow(static_mut_ref)]
115+
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
116+
#[allow(static_mut_refs)]
117117
static NUM_REF: &'static u8 = unsafe { &NUM };
118118

119119
unsafe fn zeroed<T>() -> T {

compiler/rustc_codegen_gcc/example/mini_core_hello_world.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ fn start<T: Termination + 'static>(
9999

100100
static mut NUM: u8 = 6 * 7;
101101

102-
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
103-
#[allow(static_mut_ref)]
102+
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
103+
#[allow(static_mut_refs)]
104104
static NUM_REF: &'static u8 = unsafe { &NUM };
105105

106106
macro_rules! assert {
Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
Reference of mutable static.
1+
You have created a reference to a mutable static.
22

33
Erroneous code example:
44

55
```compile_fail,edition2024,E0796
66
static mut X: i32 = 23;
7-
static mut Y: i32 = 24;
87
9-
unsafe {
10-
let y = &X;
11-
let ref x = X;
12-
let (x, y) = (&X, &Y);
13-
foo(&X);
8+
fn work() {
9+
let _val = unsafe { X };
1410
}
1511
16-
fn foo<'a>(_x: &'a i32) {}
12+
let x_ref = unsafe { &mut X };
13+
work();
14+
// The next line has Undefined Behavior!
15+
// `x_ref` is a mutable reference and allows no aliases,
16+
// but `work` has been reading the reference between
17+
// the moment `x_ref` was created and when it was used.
18+
// This violates the uniqueness of `x_ref`.
19+
*x_ref = 42;
1720
```
1821

19-
Mutable statics can be written to by multiple threads: aliasing violations or
20-
data races will cause undefined behavior.
22+
A reference to a mutable static has lifetime `'static`. This is very dangerous
23+
as it is easy to accidentally overlap the lifetime of that reference with
24+
other, conflicting accesses to the same static.
2125

22-
Reference of mutable static is a hard error from 2024 edition.
26+
References to mutable statics are a hard error in the 2024 edition.

compiler/rustc_expand/src/base.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,13 @@ impl DummyResult {
567567
}
568568

569569
/// A plain dummy type.
570-
pub fn raw_ty(sp: Span, is_error: bool) -> P<ast::Ty> {
570+
pub fn raw_ty(sp: Span) -> P<ast::Ty> {
571+
// FIXME(nnethercote): you might expect `ast::TyKind::Dummy` to be used here, but some
572+
// values produced here end up being lowered to HIR, which `ast::TyKind::Dummy` does not
573+
// support, so we use an empty tuple instead.
571574
P(ast::Ty {
572575
id: ast::DUMMY_NODE_ID,
573-
kind: if is_error { ast::TyKind::Err } else { ast::TyKind::Tup(ThinVec::new()) },
576+
kind: ast::TyKind::Tup(ThinVec::new()),
574577
span: sp,
575578
tokens: None,
576579
})
@@ -611,7 +614,7 @@ impl MacResult for DummyResult {
611614
}
612615

613616
fn make_ty(self: Box<DummyResult>) -> Option<P<ast::Ty>> {
614-
Some(DummyResult::raw_ty(self.span, self.is_error))
617+
Some(DummyResult::raw_ty(self.span))
615618
}
616619

617620
fn make_arms(self: Box<DummyResult>) -> Option<SmallVec<[ast::Arm; 1]>> {

0 commit comments

Comments
 (0)