Skip to content

Commit 4a43094

Browse files
committed
Auto merge of rust-lang#136448 - matthiaskrgr:rollup-pdim5di, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#134272 (Remove rustc_encodable_decodable feature) - rust-lang#136283 (Update encode_utf16 to mention it is native endian) - rust-lang#136394 (Clean up MonoItem::instantiation_mode) - rust-lang#136402 (diagnostics: fix borrowck suggestions for if/while let conditionals) - rust-lang#136415 (Highlight clarifying information in "expected/found" error) - rust-lang#136422 (Convert two `rustc_middle::lint` functions to `Span` methods.) - rust-lang#136434 (rustc_allowed_through_unstable_modules: require deprecation message) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6c0de7f + 961bf7f commit 4a43094

File tree

143 files changed

+775
-1180
lines changed

Some content is hidden

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

143 files changed

+775
-1180
lines changed

compiler/rustc_attr_data_structures/src/stability.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,6 @@ impl PartialConstStability {
101101
}
102102
}
103103

104-
#[derive(Encodable, Decodable, PartialEq, Copy, Clone, Debug, Eq, Hash)]
105-
#[derive(HashStable_Generic)]
106-
pub enum AllowedThroughUnstableModules {
107-
/// This does not get a deprecation warning. We still generally would prefer people to use the
108-
/// fully stable path, and a warning will likely be emitted in the future.
109-
WithoutDeprecation,
110-
/// Emit the given deprecation warning.
111-
WithDeprecation(Symbol),
112-
}
113-
114104
/// The available stability levels.
115105
#[derive(Encodable, Decodable, PartialEq, Copy, Clone, Debug, Eq, Hash)]
116106
#[derive(HashStable_Generic)]
@@ -147,8 +137,9 @@ pub enum StabilityLevel {
147137
Stable {
148138
/// Rust release which stabilized this feature.
149139
since: StableSince,
150-
/// This is `Some` if this item allowed to be referred to on stable via unstable modules.
151-
allowed_through_unstable_modules: Option<AllowedThroughUnstableModules>,
140+
/// This is `Some` if this item allowed to be referred to on stable via unstable modules;
141+
/// the `Symbol` is the deprecation message printed in that case.
142+
allowed_through_unstable_modules: Option<Symbol>,
152143
},
153144
}
154145

compiler/rustc_attr_parsing/src/attributes/stability.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use rustc_ast::MetaItem;
66
use rustc_ast::attr::AttributeExt;
77
use rustc_ast_pretty::pprust;
88
use rustc_attr_data_structures::{
9-
AllowedThroughUnstableModules, ConstStability, DefaultBodyStability, Stability, StabilityLevel,
10-
StableSince, UnstableReason, VERSION_PLACEHOLDER,
9+
ConstStability, DefaultBodyStability, Stability, StabilityLevel, StableSince, UnstableReason,
10+
VERSION_PLACEHOLDER,
1111
};
1212
use rustc_errors::ErrorGuaranteed;
1313
use rustc_session::Session;
14-
use rustc_span::{Span, Symbol, sym};
14+
use rustc_span::{Span, Symbol, kw, sym};
1515

1616
use crate::attributes::util::UnsupportedLiteralReason;
1717
use crate::{parse_version, session_diagnostics};
@@ -29,10 +29,14 @@ pub fn find_stability(
2929
for attr in attrs {
3030
match attr.name_or_empty() {
3131
sym::rustc_allowed_through_unstable_modules => {
32-
allowed_through_unstable_modules = Some(match attr.value_str() {
33-
Some(msg) => AllowedThroughUnstableModules::WithDeprecation(msg),
34-
None => AllowedThroughUnstableModules::WithoutDeprecation,
35-
})
32+
// The value is mandatory, but avoid ICEs in case such code reaches this function.
33+
allowed_through_unstable_modules = Some(attr.value_str().unwrap_or_else(|| {
34+
sess.dcx().span_delayed_bug(
35+
item_sp,
36+
"`#[rustc_allowed_through_unstable_modules]` without deprecation message",
37+
);
38+
kw::Empty
39+
}))
3640
}
3741
sym::unstable => {
3842
if stab.is_some() {

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+92-18
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,98 @@ impl<'tcx> BorrowExplanation<'tcx> {
248248
);
249249
err.span_label(body.source_info(drop_loc).span, message);
250250

251-
if let LocalInfo::BlockTailTemp(info) = local_decl.local_info() {
251+
struct FindLetExpr<'hir> {
252+
span: Span,
253+
result: Option<(Span, &'hir hir::Pat<'hir>, &'hir hir::Expr<'hir>)>,
254+
tcx: TyCtxt<'hir>,
255+
}
256+
257+
impl<'hir> rustc_hir::intravisit::Visitor<'hir> for FindLetExpr<'hir> {
258+
type NestedFilter = rustc_middle::hir::nested_filter::OnlyBodies;
259+
fn nested_visit_map(&mut self) -> Self::Map {
260+
self.tcx.hir()
261+
}
262+
fn visit_expr(&mut self, expr: &'hir hir::Expr<'hir>) {
263+
if let hir::ExprKind::If(cond, _conseq, _alt)
264+
| hir::ExprKind::Loop(
265+
hir::Block {
266+
expr:
267+
Some(&hir::Expr {
268+
kind: hir::ExprKind::If(cond, _conseq, _alt),
269+
..
270+
}),
271+
..
272+
},
273+
_,
274+
hir::LoopSource::While,
275+
_,
276+
) = expr.kind
277+
&& let hir::ExprKind::Let(hir::LetExpr {
278+
init: let_expr_init,
279+
span: let_expr_span,
280+
pat: let_expr_pat,
281+
..
282+
}) = cond.kind
283+
&& let_expr_init.span.contains(self.span)
284+
{
285+
self.result =
286+
Some((*let_expr_span, let_expr_pat, let_expr_init))
287+
} else {
288+
hir::intravisit::walk_expr(self, expr);
289+
}
290+
}
291+
}
292+
293+
if let &LocalInfo::IfThenRescopeTemp { if_then } = local_decl.local_info()
294+
&& let hir::Node::Expr(expr) = tcx.hir_node(if_then)
295+
&& let hir::ExprKind::If(cond, conseq, alt) = expr.kind
296+
&& let hir::ExprKind::Let(&hir::LetExpr {
297+
span: _,
298+
pat,
299+
init,
300+
// FIXME(#101728): enable rewrite when type ascription is
301+
// stabilized again.
302+
ty: None,
303+
recovered: _,
304+
}) = cond.kind
305+
&& pat.span.can_be_used_for_suggestions()
306+
&& let Ok(pat) = tcx.sess.source_map().span_to_snippet(pat.span)
307+
{
308+
suggest_rewrite_if_let(tcx, expr, &pat, init, conseq, alt, err);
309+
} else if let Some((old, new)) = multiple_borrow_span
310+
&& let def_id = body.source.def_id()
311+
&& let Some(node) = tcx.hir().get_if_local(def_id)
312+
&& let Some(body_id) = node.body_id()
313+
&& let hir_body = tcx.hir().body(body_id)
314+
&& let mut expr_finder = (FindLetExpr { span: old, result: None, tcx })
315+
&& let Some((let_expr_span, let_expr_pat, let_expr_init)) = {
316+
expr_finder.visit_expr(hir_body.value);
317+
expr_finder.result
318+
}
319+
&& !let_expr_span.contains(new)
320+
{
321+
// #133941: The `old` expression is at the conditional part of an
322+
// if/while let expression. Adding a semicolon won't work.
323+
// Instead, try suggesting the `matches!` macro or a temporary.
324+
if let_expr_pat
325+
.walk_short(|pat| !matches!(pat.kind, hir::PatKind::Binding(..)))
326+
{
327+
if let Ok(pat_snippet) =
328+
tcx.sess.source_map().span_to_snippet(let_expr_pat.span)
329+
&& let Ok(init_snippet) =
330+
tcx.sess.source_map().span_to_snippet(let_expr_init.span)
331+
{
332+
err.span_suggestion_verbose(
333+
let_expr_span,
334+
"consider using the `matches!` macro",
335+
format!("matches!({init_snippet}, {pat_snippet})"),
336+
Applicability::MaybeIncorrect,
337+
);
338+
} else {
339+
err.note("consider using the `matches!` macro");
340+
}
341+
}
342+
} else if let LocalInfo::BlockTailTemp(info) = local_decl.local_info() {
252343
if info.tail_result_is_ignored {
253344
// #85581: If the first mutable borrow's scope contains
254345
// the second borrow, this suggestion isn't helpful.
@@ -281,23 +372,6 @@ impl<'tcx> BorrowExplanation<'tcx> {
281372
Applicability::MaybeIncorrect,
282373
);
283374
};
284-
} else if let &LocalInfo::IfThenRescopeTemp { if_then } =
285-
local_decl.local_info()
286-
&& let hir::Node::Expr(expr) = tcx.hir_node(if_then)
287-
&& let hir::ExprKind::If(cond, conseq, alt) = expr.kind
288-
&& let hir::ExprKind::Let(&hir::LetExpr {
289-
span: _,
290-
pat,
291-
init,
292-
// FIXME(#101728): enable rewrite when type ascription is
293-
// stabilized again.
294-
ty: None,
295-
recovered: _,
296-
}) = cond.kind
297-
&& pat.span.can_be_used_for_suggestions()
298-
&& let Ok(pat) = tcx.sess.source_map().span_to_snippet(pat.span)
299-
{
300-
suggest_rewrite_if_let(tcx, expr, &pat, init, conseq, alt, err);
301375
}
302376
}
303377
}

compiler/rustc_builtin_macros/src/deriving/debug.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn show_substructure(cx: &ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) ->
5656

5757
let (ident, vdata, fields) = match substr.fields {
5858
Struct(vdata, fields) => (substr.type_ident, *vdata, fields),
59-
EnumMatching(_, v, fields) => (v.ident, &v.data, fields),
59+
EnumMatching(v, fields) => (v.ident, &v.data, fields),
6060
AllFieldlessEnum(enum_def) => return show_fieldless_enum(cx, span, enum_def, substr),
6161
EnumDiscr(..) | StaticStruct(..) | StaticEnum(..) => {
6262
cx.dcx().span_bug(span, "nonsensical .fields in `#[derive(Debug)]`")

0 commit comments

Comments
 (0)