Skip to content

Commit c80dde4

Browse files
committed
Auto merge of rust-lang#99210 - Dylan-DPC:rollup-879cp1t, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#98574 (Lower let-else in MIR) - rust-lang#99011 (`UnsafeCell` blocks niches inside its nested type from being available outside) - rust-lang#99030 (diagnostics: error messages when struct literals fail to parse) - rust-lang#99155 (Keep unstable target features for asm feature checking) - rust-lang#99199 (Refactor: remove an unnecessary `span_to_snippet`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 42bd138 + 3933b2b commit c80dde4

File tree

72 files changed

+830
-830
lines changed

Some content is hidden

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

72 files changed

+830
-830
lines changed
+22-73
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::{ImplTraitContext, ImplTraitPosition, LoweringContext};
2-
use rustc_ast::{AttrVec, Block, BlockCheckMode, Expr, Local, LocalKind, Stmt, StmtKind};
2+
use rustc_ast::{Block, BlockCheckMode, Local, LocalKind, Stmt, StmtKind};
33
use rustc_hir as hir;
44
use rustc_session::parse::feature_err;
5-
use rustc_span::{sym, DesugaringKind};
5+
use rustc_span::sym;
66

77
use smallvec::SmallVec;
88

@@ -36,21 +36,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
3636
match s.kind {
3737
StmtKind::Local(ref local) => {
3838
let hir_id = self.lower_node_id(s.id);
39-
match &local.kind {
40-
LocalKind::InitElse(init, els) => {
41-
let e = self.lower_let_else(hir_id, local, init, els, tail);
42-
expr = Some(e);
43-
// remaining statements are in let-else expression
44-
break;
45-
}
46-
_ => {
47-
let local = self.lower_local(local);
48-
self.alias_attrs(hir_id, local.hir_id);
49-
let kind = hir::StmtKind::Local(local);
50-
let span = self.lower_span(s.span);
51-
stmts.push(hir::Stmt { hir_id, kind, span });
52-
}
53-
}
39+
let local = self.lower_local(local);
40+
self.alias_attrs(hir_id, local.hir_id);
41+
let kind = hir::StmtKind::Local(local);
42+
let span = self.lower_span(s.span);
43+
stmts.push(hir::Stmt { hir_id, kind, span });
5444
}
5545
StmtKind::Item(ref it) => {
5646
stmts.extend(self.lower_item_ref(it).into_iter().enumerate().map(
@@ -101,10 +91,24 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10191
let init = l.kind.init().map(|init| self.lower_expr(init));
10292
let hir_id = self.lower_node_id(l.id);
10393
let pat = self.lower_pat(&l.pat);
94+
let els = if let LocalKind::InitElse(_, els) = &l.kind {
95+
if !self.tcx.features().let_else {
96+
feature_err(
97+
&self.tcx.sess.parse_sess,
98+
sym::let_else,
99+
l.span,
100+
"`let...else` statements are unstable",
101+
)
102+
.emit();
103+
}
104+
Some(self.lower_block(els, false))
105+
} else {
106+
None
107+
};
104108
let span = self.lower_span(l.span);
105109
let source = hir::LocalSource::Normal;
106110
self.lower_attrs(hir_id, &l.attrs);
107-
self.arena.alloc(hir::Local { hir_id, ty, pat, init, span, source })
111+
self.arena.alloc(hir::Local { hir_id, ty, pat, init, els, span, source })
108112
}
109113

110114
fn lower_block_check_mode(&mut self, b: &BlockCheckMode) -> hir::BlockCheckMode {
@@ -115,59 +119,4 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
115119
}
116120
}
117121
}
118-
119-
fn lower_let_else(
120-
&mut self,
121-
stmt_hir_id: hir::HirId,
122-
local: &Local,
123-
init: &Expr,
124-
els: &Block,
125-
tail: &[Stmt],
126-
) -> &'hir hir::Expr<'hir> {
127-
let ty = local
128-
.ty
129-
.as_ref()
130-
.map(|t| self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Variable)));
131-
let span = self.lower_span(local.span);
132-
let span = self.mark_span_with_reason(DesugaringKind::LetElse, span, None);
133-
let init = self.lower_expr(init);
134-
let local_hir_id = self.lower_node_id(local.id);
135-
self.lower_attrs(local_hir_id, &local.attrs);
136-
let let_expr = {
137-
let lex = self.arena.alloc(hir::Let {
138-
hir_id: local_hir_id,
139-
pat: self.lower_pat(&local.pat),
140-
ty,
141-
init,
142-
span,
143-
});
144-
self.arena.alloc(self.expr(span, hir::ExprKind::Let(lex), AttrVec::new()))
145-
};
146-
let then_expr = {
147-
let (stmts, expr) = self.lower_stmts(tail);
148-
let block = self.block_all(span, stmts, expr);
149-
self.arena.alloc(self.expr_block(block, AttrVec::new()))
150-
};
151-
let else_expr = {
152-
let block = self.lower_block(els, false);
153-
self.arena.alloc(self.expr_block(block, AttrVec::new()))
154-
};
155-
self.alias_attrs(let_expr.hir_id, local_hir_id);
156-
self.alias_attrs(else_expr.hir_id, local_hir_id);
157-
let if_expr = self.arena.alloc(hir::Expr {
158-
hir_id: stmt_hir_id,
159-
span,
160-
kind: hir::ExprKind::If(let_expr, then_expr, Some(else_expr)),
161-
});
162-
if !self.tcx.features().let_else {
163-
feature_err(
164-
&self.tcx.sess.parse_sess,
165-
sym::let_else,
166-
local.span,
167-
"`let...else` statements are unstable",
168-
)
169-
.emit();
170-
}
171-
if_expr
172-
}
173122
}

compiler/rustc_ast_lowering/src/lib.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -2146,7 +2146,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21462146
debug_assert!(!a.is_empty());
21472147
self.attrs.insert(hir_id.local_id, a);
21482148
}
2149-
let local = hir::Local { hir_id, init, pat, source, span: self.lower_span(span), ty: None };
2149+
let local = hir::Local {
2150+
hir_id,
2151+
init,
2152+
pat,
2153+
els: None,
2154+
source,
2155+
span: self.lower_span(span),
2156+
ty: None,
2157+
};
21502158
self.stmt(span, hir::StmtKind::Local(self.arena.alloc(local)))
21512159
}
21522160

compiler/rustc_attr/src/builtin.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,6 @@ pub enum ReprAttr {
856856
ReprSimd,
857857
ReprTransparent,
858858
ReprAlign(u32),
859-
ReprNoNiche,
860859
}
861860

862861
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
@@ -904,7 +903,6 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
904903
sym::packed => Some(ReprPacked(1)),
905904
sym::simd => Some(ReprSimd),
906905
sym::transparent => Some(ReprTransparent),
907-
sym::no_niche => Some(ReprNoNiche),
908906
sym::align => {
909907
let mut err = struct_span_err!(
910908
diagnostic,
@@ -943,7 +941,7 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
943941
Ok(literal) => acc.push(ReprPacked(literal)),
944942
Err(message) => literal_error = Some(message),
945943
};
946-
} else if matches!(name, sym::C | sym::simd | sym::transparent | sym::no_niche)
944+
} else if matches!(name, sym::C | sym::simd | sym::transparent)
947945
|| int_type_of_word(name).is_some()
948946
{
949947
recognised = true;
@@ -1001,7 +999,7 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
1001999
} else {
10021000
if matches!(
10031001
meta_item.name_or_empty(),
1004-
sym::C | sym::simd | sym::transparent | sym::no_niche
1002+
sym::C | sym::simd | sym::transparent
10051003
) || int_type_of_word(meta_item.name_or_empty()).is_some()
10061004
{
10071005
recognised = true;
@@ -1039,7 +1037,7 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
10391037
.emit();
10401038
} else if matches!(
10411039
meta_item.name_or_empty(),
1042-
sym::C | sym::simd | sym::transparent | sym::no_niche
1040+
sym::C | sym::simd | sym::transparent
10431041
) || int_type_of_word(meta_item.name_or_empty()).is_some()
10441042
{
10451043
recognised = true;

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -1598,21 +1598,18 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15981598
let return_ty = tcx.erase_regions(return_ty);
15991599

16001600
// to avoid panics
1601-
if let Some(iter_trait) = tcx.get_diagnostic_item(sym::Iterator) {
1602-
if self
1601+
if let Some(iter_trait) = tcx.get_diagnostic_item(sym::Iterator)
1602+
&& self
16031603
.infcx
16041604
.type_implements_trait(iter_trait, return_ty, ty_params, self.param_env)
16051605
.must_apply_modulo_regions()
1606-
{
1607-
if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(return_span) {
1608-
err.span_suggestion_hidden(
1609-
return_span,
1610-
"use `.collect()` to allocate the iterator",
1611-
format!("{snippet}.collect::<Vec<_>>()"),
1612-
Applicability::MaybeIncorrect,
1613-
);
1614-
}
1615-
}
1606+
{
1607+
err.span_suggestion_hidden(
1608+
return_span.shrink_to_hi(),
1609+
"use `.collect()` to allocate the iterator",
1610+
".collect::<Vec<_>>()",
1611+
Applicability::MaybeIncorrect,
1612+
);
16161613
}
16171614
}
16181615

compiler/rustc_codegen_cranelift/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
167167
}
168168
}
169169

170-
fn target_features(&self, _sess: &Session) -> Vec<rustc_span::Symbol> {
170+
fn target_features(&self, _sess: &Session, _allow_unstable: bool) -> Vec<rustc_span::Symbol> {
171171
vec![]
172172
}
173173

compiler/rustc_codegen_gcc/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ impl CodegenBackend for GccCodegenBackend {
140140
)
141141
}
142142

143-
fn target_features(&self, sess: &Session) -> Vec<Symbol> {
144-
target_features(sess)
143+
fn target_features(&self, sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
144+
target_features(sess, allow_unstable)
145145
}
146146
}
147147

@@ -298,12 +298,12 @@ pub fn target_cpu(sess: &Session) -> &str {
298298
}
299299
}
300300

301-
pub fn target_features(sess: &Session) -> Vec<Symbol> {
301+
pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
302302
supported_target_features(sess)
303303
.iter()
304304
.filter_map(
305305
|&(feature, gate)| {
306-
if sess.is_nightly_build() || gate.is_none() { Some(feature) } else { None }
306+
if sess.is_nightly_build() || allow_unstable || gate.is_none() { Some(feature) } else { None }
307307
},
308308
)
309309
.filter(|_feature| {

compiler/rustc_codegen_llvm/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ impl CodegenBackend for LlvmCodegenBackend {
324324
llvm_util::print_version();
325325
}
326326

327-
fn target_features(&self, sess: &Session) -> Vec<Symbol> {
328-
target_features(sess)
327+
fn target_features(&self, sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
328+
target_features(sess, allow_unstable)
329329
}
330330

331331
fn codegen_crate<'tcx>(

compiler/rustc_codegen_llvm/src/llvm_util.rs

+21-18
Original file line numberDiff line numberDiff line change
@@ -233,26 +233,29 @@ pub fn check_tied_features(
233233

234234
// Used to generate cfg variables and apply features
235235
// Must express features in the way Rust understands them
236-
pub fn target_features(sess: &Session) -> Vec<Symbol> {
236+
pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
237237
let target_machine = create_informational_target_machine(sess);
238-
let mut features: Vec<Symbol> =
239-
supported_target_features(sess)
240-
.iter()
241-
.filter_map(|&(feature, gate)| {
242-
if sess.is_nightly_build() || gate.is_none() { Some(feature) } else { None }
243-
})
244-
.filter(|feature| {
245-
// check that all features in a given smallvec are enabled
246-
for llvm_feature in to_llvm_features(sess, feature) {
247-
let cstr = SmallCStr::new(llvm_feature);
248-
if !unsafe { llvm::LLVMRustHasFeature(target_machine, cstr.as_ptr()) } {
249-
return false;
250-
}
238+
let mut features: Vec<Symbol> = supported_target_features(sess)
239+
.iter()
240+
.filter_map(|&(feature, gate)| {
241+
if sess.is_nightly_build() || allow_unstable || gate.is_none() {
242+
Some(feature)
243+
} else {
244+
None
245+
}
246+
})
247+
.filter(|feature| {
248+
// check that all features in a given smallvec are enabled
249+
for llvm_feature in to_llvm_features(sess, feature) {
250+
let cstr = SmallCStr::new(llvm_feature);
251+
if !unsafe { llvm::LLVMRustHasFeature(target_machine, cstr.as_ptr()) } {
252+
return false;
251253
}
252-
true
253-
})
254-
.map(|feature| Symbol::intern(feature))
255-
.collect();
254+
}
255+
true
256+
})
257+
.map(|feature| Symbol::intern(feature))
258+
.collect();
256259

257260
// LLVM 14 changed the ABI for i128 arguments to __float/__fix builtins on Win64
258261
// (see https://reviews.llvm.org/D110413). This unstable target feature is intended for use

compiler/rustc_codegen_ssa/src/traits/backend.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<'tcx, T> Backend<'tcx> for T where
5959
pub trait CodegenBackend {
6060
fn init(&self, _sess: &Session) {}
6161
fn print(&self, _req: PrintRequest, _sess: &Session) {}
62-
fn target_features(&self, _sess: &Session) -> Vec<Symbol> {
62+
fn target_features(&self, _sess: &Session, _allow_unstable: bool) -> Vec<Symbol> {
6363
vec![]
6464
}
6565
fn print_passes(&self) {}

compiler/rustc_const_eval/src/interpret/intern.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx, const_eval::Memory
217217
}
218218

219219
if let Some(def) = mplace.layout.ty.ty_adt_def() {
220-
if Some(def.did()) == self.ecx.tcx.lang_items().unsafe_cell_type() {
220+
if def.is_unsafe_cell() {
221221
// We are crossing over an `UnsafeCell`, we can mutate again. This means that
222222
// References we encounter inside here are interned as pointing to mutable
223223
// allocations.

compiler/rustc_const_eval/src/interpret/validity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
821821
// Special check preventing `UnsafeCell` in the inner part of constants
822822
if let Some(def) = op.layout.ty.ty_adt_def() {
823823
if matches!(self.ctfe_mode, Some(CtfeValidationMode::Const { inner: true, .. }))
824-
&& Some(def.did()) == self.ecx.tcx.lang_items().unsafe_cell_type()
824+
&& def.is_unsafe_cell()
825825
{
826826
throw_validation_failure!(self.path, { "`UnsafeCell` in a `const`" });
827827
}

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ impl Qualif for HasMutInterior {
9696
}
9797

9898
fn in_adt_inherently<'tcx>(
99-
cx: &ConstCx<'_, 'tcx>,
99+
_cx: &ConstCx<'_, 'tcx>,
100100
adt: AdtDef<'tcx>,
101101
_: SubstsRef<'tcx>,
102102
) -> bool {
103103
// Exactly one type, `UnsafeCell`, has the `HasMutInterior` qualif inherently.
104104
// It arises structurally for all other types.
105-
Some(adt.did()) == cx.tcx.lang_items().unsafe_cell_type()
105+
adt.is_unsafe_cell()
106106
}
107107
}
108108

compiler/rustc_feature/src/active.rs

-3
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,6 @@ declare_features! (
156156
(active, intrinsics, "1.0.0", None, None),
157157
/// Allows using `#[lang = ".."]` attribute for linking items to special compiler logic.
158158
(active, lang_items, "1.0.0", None, None),
159-
/// Allows `#[repr(no_niche)]` (an implementation detail of `rustc`,
160-
/// it is not on path for eventual stabilization).
161-
(active, no_niche, "1.42.0", None, None),
162159
/// Allows using `#[omit_gdb_pretty_printer_section]`.
163160
(active, omit_gdb_pretty_printer_section, "1.5.0", None, None),
164161
/// Allows using `#[prelude_import]` on glob `use` items.

compiler/rustc_hir/src/hir.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,8 @@ pub struct Local<'hir> {
13161316
pub ty: Option<&'hir Ty<'hir>>,
13171317
/// Initializer expression to set the value, if any.
13181318
pub init: Option<&'hir Expr<'hir>>,
1319+
/// Else block for a `let...else` binding.
1320+
pub els: Option<&'hir Block<'hir>>,
13191321
pub hir_id: HirId,
13201322
pub span: Span,
13211323
/// Can be `ForLoopDesugar` if the `let` statement is part of a `for` loop

compiler/rustc_hir/src/intravisit.rs

+3
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,9 @@ pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local<'v>) {
472472
walk_list!(visitor, visit_expr, &local.init);
473473
visitor.visit_id(local.hir_id);
474474
visitor.visit_pat(&local.pat);
475+
if let Some(els) = local.els {
476+
visitor.visit_block(els);
477+
}
475478
walk_list!(visitor, visit_ty, &local.ty);
476479
}
477480

0 commit comments

Comments
 (0)