Skip to content

Commit 4e21162

Browse files
committed
Auto merge of #115615 - matthiaskrgr:rollup-49fosdf, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #114511 (Remove the unhelpful let binding diag comes from FormatArguments) - #115473 (Add explanatory note to 'expected item' error) - #115574 (Replace `rustc_data_structures` dependency with `rustc_index` in `rustc_parse_format`) - #115578 (Clarify cryptic comments) - #115587 (fix #115348) - #115596 (A small change) - #115598 (Fix log formatting in bootstrap) - #115605 (Better Debug for `Ty` in smir) - #115614 (Fix minor grammar typo) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a5b2ac6 + 1d3451d commit 4e21162

33 files changed

+193
-39
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4175,7 +4175,7 @@ dependencies = [
41754175
name = "rustc_parse_format"
41764176
version = "0.0.0"
41774177
dependencies = [
4178-
"rustc_data_structures",
4178+
"rustc_index",
41794179
"rustc_lexer",
41804180
]
41814181

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,21 +2130,27 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21302130
/// misleading users in cases like `tests/ui/nll/borrowed-temporary-error.rs`.
21312131
/// We could expand the analysis to suggest hoising all of the relevant parts of
21322132
/// the users' code to make the code compile, but that could be too much.
2133-
struct NestedStatementVisitor {
2133+
/// We found the `prop_expr` by the way to check whether the expression is a `FormatArguments`,
2134+
/// which is a special case since it's generated by the compiler.
2135+
struct NestedStatementVisitor<'tcx> {
21342136
span: Span,
21352137
current: usize,
21362138
found: usize,
2139+
prop_expr: Option<&'tcx hir::Expr<'tcx>>,
21372140
}
21382141

2139-
impl<'tcx> Visitor<'tcx> for NestedStatementVisitor {
2140-
fn visit_block(&mut self, block: &hir::Block<'tcx>) {
2142+
impl<'tcx> Visitor<'tcx> for NestedStatementVisitor<'tcx> {
2143+
fn visit_block(&mut self, block: &'tcx hir::Block<'tcx>) {
21412144
self.current += 1;
21422145
walk_block(self, block);
21432146
self.current -= 1;
21442147
}
2145-
fn visit_expr(&mut self, expr: &hir::Expr<'tcx>) {
2148+
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
21462149
if self.span == expr.span.source_callsite() {
21472150
self.found = self.current;
2151+
if self.prop_expr.is_none() {
2152+
self.prop_expr = Some(expr);
2153+
}
21482154
}
21492155
walk_expr(self, expr);
21502156
}
@@ -2162,22 +2168,40 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21622168
span: proper_span,
21632169
current: 0,
21642170
found: 0,
2171+
prop_expr: None,
21652172
};
21662173
visitor.visit_stmt(stmt);
2174+
2175+
let typeck_results = self.infcx.tcx.typeck(self.mir_def_id());
2176+
let expr_ty: Option<Ty<'_>> = visitor.prop_expr.map(|expr| typeck_results.expr_ty(expr).peel_refs());
2177+
2178+
let is_format_arguments_item =
2179+
if let Some(expr_ty) = expr_ty
2180+
&& let ty::Adt(adt, _) = expr_ty.kind() {
2181+
self.infcx.tcx.lang_items().get(LangItem::FormatArguments) == Some(adt.did())
2182+
} else {
2183+
false
2184+
};
2185+
21672186
if visitor.found == 0
21682187
&& stmt.span.contains(proper_span)
21692188
&& let Some(p) = sm.span_to_margin(stmt.span)
21702189
&& let Ok(s) = sm.span_to_snippet(proper_span)
21712190
{
2172-
let addition = format!("let binding = {};\n{}", s, " ".repeat(p));
2173-
err.multipart_suggestion_verbose(
2174-
msg,
2175-
vec![
2176-
(stmt.span.shrink_to_lo(), addition),
2177-
(proper_span, "binding".to_string()),
2178-
],
2179-
Applicability::MaybeIncorrect,
2180-
);
2191+
if !is_format_arguments_item {
2192+
let addition = format!("let binding = {};\n{}", s, " ".repeat(p));
2193+
err.multipart_suggestion_verbose(
2194+
msg,
2195+
vec![
2196+
(stmt.span.shrink_to_lo(), addition),
2197+
(proper_span, "binding".to_string()),
2198+
],
2199+
Applicability::MaybeIncorrect,
2200+
);
2201+
} else {
2202+
err.note("the result of `format_args!` can only be assigned directly if no placeholders in it's arguments are used");
2203+
err.note("to learn more, visit <https://doc.rust-lang.org/std/macro.format_args.html>");
2204+
}
21812205
suggested = true;
21822206
break;
21832207
}

compiler/rustc_lint/src/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
9696
};
9797
let def_id = trait_predicate.trait_ref.def_id;
9898
if cx.tcx.lang_items().drop_trait() == Some(def_id) {
99-
// Explicitly allow `impl Drop`, a drop-guards-as-Voldemort-type pattern.
99+
// Explicitly allow `impl Drop`, a drop-guards-as-unnameable-type pattern.
100100
if trait_predicate.trait_ref.self_ty().is_impl_trait() {
101101
continue;
102102
}

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4363,7 +4363,7 @@ declare_lint! {
43634363
/// pub struct S;
43644364
/// }
43654365
///
4366-
/// pub fn get_voldemort() -> m::S { m::S }
4366+
/// pub fn get_unnameable() -> m::S { m::S }
43674367
/// # fn main() {}
43684368
/// ```
43694369
///

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2857,7 +2857,7 @@ impl<'tcx> Ty<'tcx> {
28572857
| ty::Uint(..)
28582858
| ty::Float(..) => true,
28592859

2860-
// The voldemort ZSTs are fine.
2860+
// ZST which can't be named are fine.
28612861
ty::FnDef(..) => true,
28622862

28632863
ty::Array(element_ty, _len) => element_ty.is_trivially_pure_clone_copy(),

compiler/rustc_mir_transform/src/check_unsafety.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def: LocalDefId) -> &UnsafetyCheckResu
483483
// `mir_built` force this.
484484
let body = &tcx.mir_built(def).borrow();
485485

486-
if body.is_custom_mir() {
486+
if body.is_custom_mir() || body.tainted_by_errors.is_some() {
487487
return tcx.arena.alloc(UnsafetyCheckResult {
488488
violations: Vec::new(),
489489
used_unsafe_blocks: Default::default(),

compiler/rustc_parse/src/parser/attr_wrapper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl ToAttrTokenStream for LazyAttrTokenStreamImpl {
106106
let mut cursor_snapshot = self.cursor_snapshot.clone();
107107
let tokens =
108108
std::iter::once((FlatToken::Token(self.start_token.0.clone()), self.start_token.1))
109-
.chain((0..self.num_calls).map(|_| {
109+
.chain(std::iter::repeat_with(|| {
110110
let token = cursor_snapshot.next();
111111
(FlatToken::Token(token.0), token.1)
112112
}))

compiler/rustc_parse/src/parser/item.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,16 @@ impl<'a> Parser<'a> {
7373
if !self.maybe_consume_incorrect_semicolon(&items) {
7474
let msg = format!("expected item, found {token_str}");
7575
let mut err = self.struct_span_err(self.token.span, msg);
76-
let label = if self.is_kw_followed_by_ident(kw::Let) {
77-
"consider using `const` or `static` instead of `let` for global variables"
76+
let span = self.token.span;
77+
if self.is_kw_followed_by_ident(kw::Let) {
78+
err.span_label(
79+
span,
80+
"consider using `const` or `static` instead of `let` for global variables",
81+
);
7882
} else {
79-
"expected item"
83+
err.span_label(span, "expected item")
84+
.note("for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>");
8085
};
81-
err.span_label(self.token.span, label);
8286
return Err(err);
8387
}
8488
}

compiler/rustc_parse_format/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ edition = "2021"
55

66
[dependencies]
77
rustc_lexer = { path = "../rustc_lexer" }
8-
rustc_data_structures = { path = "../rustc_data_structures" }
8+
rustc_index = { path = "../rustc_index", default-features = false }

compiler/rustc_parse_format/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ fn unescape_string(string: &str) -> Option<string::String> {
10111011

10121012
// Assert a reasonable size for `Piece`
10131013
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
1014-
rustc_data_structures::static_assert_size!(Piece<'_>, 16);
1014+
rustc_index::static_assert_size!(Piece<'_>, 16);
10151015

10161016
#[cfg(test)]
10171017
mod tests;

0 commit comments

Comments
 (0)