Skip to content

Commit fb4aebd

Browse files
committedSep 30, 2024
Auto merge of rust-lang#131069 - matthiaskrgr:rollup-jg1icf9, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#131023 (Copy correct path to clipboard for modules/keywords/primitives) - rust-lang#131035 (Preserve brackets around if-lets and skip while-lets) - rust-lang#131038 (Fix `adt_const_params` leaking `{type error}` in error msg) - rust-lang#131053 (Improve `--print=check-cfg` documentation) - rust-lang#131056 (enable compiler fingerprint logs in verbose mode) r? `@ghost` `@rustbot` modify labels: rollup

File tree

75 files changed

+322
-347
lines changed

Some content is hidden

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

75 files changed

+322
-347
lines changed
 

‎compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -961,13 +961,20 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
961961
hir_ty.span,
962962
"using raw pointers as const generic parameters is forbidden",
963963
),
964-
_ => tcx.dcx().struct_span_err(
965-
hir_ty.span,
966-
format!("`{}` is forbidden as the type of a const generic parameter", ty),
967-
),
964+
_ => {
965+
// Avoid showing "{type error}" to users. See #118179.
966+
ty.error_reported()?;
967+
968+
tcx.dcx().struct_span_err(
969+
hir_ty.span,
970+
format!(
971+
"`{ty}` is forbidden as the type of a const generic parameter",
972+
),
973+
)
974+
}
968975
};
969976

970-
diag.note("the only supported types are integers, `bool` and `char`");
977+
diag.note("the only supported types are integers, `bool`, and `char`");
971978

972979
let cause = ObligationCause::misc(hir_ty.span, param.def_id);
973980
let adt_const_params_feature_string =

‎compiler/rustc_lint/src/if_let_rescope.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ impl IfLetRescope {
122122
}
123123
let tcx = cx.tcx;
124124
let source_map = tcx.sess.source_map();
125-
let expr_end = expr.span.shrink_to_hi();
125+
let expr_end = match expr.kind {
126+
hir::ExprKind::If(_cond, conseq, None) => conseq.span.shrink_to_hi(),
127+
hir::ExprKind::If(_cond, _conseq, Some(alt)) => alt.span.shrink_to_hi(),
128+
_ => return,
129+
};
126130
let mut add_bracket_to_match_head = match_head_needs_bracket(tcx, expr);
127131
let mut significant_droppers = vec![];
128132
let mut lifetime_ends = vec![];
@@ -145,7 +149,10 @@ impl IfLetRescope {
145149
recovered: Recovered::No,
146150
}) = cond.kind
147151
{
148-
let if_let_pat = expr.span.shrink_to_lo().between(init.span);
152+
// Peel off round braces
153+
let if_let_pat = source_map
154+
.span_take_while(expr.span, |&ch| ch == '(' || ch.is_whitespace())
155+
.between(init.span);
149156
// The consequent fragment is always a block.
150157
let before_conseq = conseq.span.shrink_to_lo();
151158
let lifetime_end = source_map.end_point(conseq.span);
@@ -159,6 +166,8 @@ impl IfLetRescope {
159166
if ty_ascription.is_some()
160167
|| !expr.span.can_be_used_for_suggestions()
161168
|| !pat.span.can_be_used_for_suggestions()
169+
|| !if_let_pat.can_be_used_for_suggestions()
170+
|| !before_conseq.can_be_used_for_suggestions()
162171
{
163172
// Our `match` rewrites does not support type ascription,
164173
// so we just bail.
@@ -240,6 +249,23 @@ impl<'tcx> LateLintPass<'tcx> for IfLetRescope {
240249
if let (Level::Allow, _) = cx.tcx.lint_level_at_node(IF_LET_RESCOPE, expr.hir_id) {
241250
return;
242251
}
252+
if let hir::ExprKind::Loop(block, _label, hir::LoopSource::While, _span) = expr.kind
253+
&& let Some(value) = block.expr
254+
&& let hir::ExprKind::If(cond, _conseq, _alt) = value.kind
255+
&& let hir::ExprKind::Let(..) = cond.kind
256+
{
257+
// Recall that `while let` is lowered into this:
258+
// ```
259+
// loop {
260+
// if let .. { body } else { break; }
261+
// }
262+
// ```
263+
// There is no observable change in drop order on the overall `if let` expression
264+
// given that the `{ break; }` block is trivial so the edition change
265+
// means nothing substantial to this `while` statement.
266+
self.skip.insert(value.hir_id);
267+
return;
268+
}
243269
if expr_parent_is_stmt(cx.tcx, expr.hir_id)
244270
&& matches!(expr.kind, hir::ExprKind::If(_cond, _conseq, None))
245271
{

0 commit comments

Comments
 (0)
Please sign in to comment.