Skip to content

Commit 4e21162

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

33 files changed

+193
-39
lines changed

Diff for: Cargo.lock

+1-1
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

Diff for: compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+37-13
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
}

Diff for: compiler/rustc_lint/src/traits.rs

+1-1
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
}

Diff for: compiler/rustc_lint_defs/src/builtin.rs

+1-1
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
///

Diff for: compiler/rustc_middle/src/ty/sty.rs

+1-1
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(),

Diff for: compiler/rustc_mir_transform/src/check_unsafety.rs

+1-1
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(),

Diff for: compiler/rustc_parse/src/parser/attr_wrapper.rs

+1-1
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
}))

Diff for: compiler/rustc_parse/src/parser/item.rs

+8-4
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
}

Diff for: compiler/rustc_parse_format/Cargo.toml

+1-1
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 }

Diff for: compiler/rustc_parse_format/src/lib.rs

+1-1
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;

Diff for: compiler/rustc_smir/src/stable_mir/ty.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ use super::{
44
with, AllocId, DefId,
55
};
66
use crate::rustc_internal::Opaque;
7+
use std::fmt::{self, Debug, Formatter};
78

8-
#[derive(Copy, Clone, Debug)]
9+
#[derive(Copy, Clone)]
910
pub struct Ty(pub usize);
1011

12+
impl Debug for Ty {
13+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
14+
f.debug_struct("Ty").field("id", &self.0).field("kind", &self.kind()).finish()
15+
}
16+
}
17+
1118
impl Ty {
1219
pub fn kind(&self) -> TyKind {
1320
with(|context| context.ty_kind(*self))

Diff for: library/core/src/error.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ responsibilities they cover:
3737
The panic and error systems are not entirely distinct. Often times errors
3838
that are anticipated runtime failures in an API might instead represent bugs
3939
to a caller. For these situations the standard library provides APIs for
40-
constructing panics with an `Error` as it's source.
40+
constructing panics with an `Error` as its source.
4141

4242
* [`Result::unwrap`]
4343
* [`Result::expect`]

Diff for: src/bootstrap/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ impl Build {
10191019

10201020
fn info(&self, msg: &str) {
10211021
match self.config.dry_run {
1022-
DryRun::SelfCheck => return,
1022+
DryRun::SelfCheck => (),
10231023
DryRun::Disabled | DryRun::UserSelected => {
10241024
println!("{msg}");
10251025
}

Diff for: src/bootstrap/llvm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,9 @@ fn configure_cmake(
598598
} else if target.contains("linux") {
599599
cfg.define("CMAKE_SYSTEM_NAME", "Linux");
600600
} else {
601-
builder.info(
601+
builder.info(&format!(
602602
"could not determine CMAKE_SYSTEM_NAME from the target `{target}`, build may fail",
603-
);
603+
));
604604
}
605605

606606
// When cross-compiling we should also set CMAKE_SYSTEM_VERSION, but in
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![allow(dead_code)]
2+
3+
fn bar<'a>(_: std::fmt::Arguments<'a>) {}
4+
fn main() {
5+
let x = format_args!("a {} {} {}.", 1, format_args!("b{}!", 2), 3);
6+
//~^ ERROR temporary value dropped while borrowed
7+
8+
bar(x);
9+
10+
let foo = format_args!("{}", "hi");
11+
//~^ ERROR temporary value dropped while borrowed
12+
bar(foo);
13+
14+
let foo = format_args!("hi"); // no placeholder in arguments, so no error
15+
bar(foo);
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error[E0716]: temporary value dropped while borrowed
2+
--> $DIR/issue-114374-invalid-help-fmt-args.rs:5:13
3+
|
4+
LL | let x = format_args!("a {} {} {}.", 1, format_args!("b{}!", 2), 3);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
6+
| |
7+
| creates a temporary value which is freed while still in use
8+
...
9+
LL | bar(x);
10+
| - borrow later used here
11+
|
12+
= note: the result of `format_args!` can only be assigned directly if no placeholders in it's arguments are used
13+
= note: to learn more, visit <https://doc.rust-lang.org/std/macro.format_args.html>
14+
= note: this error originates in the macro `format_args` (in Nightly builds, run with -Z macro-backtrace for more info)
15+
16+
error[E0716]: temporary value dropped while borrowed
17+
--> $DIR/issue-114374-invalid-help-fmt-args.rs:10:15
18+
|
19+
LL | let foo = format_args!("{}", "hi");
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
21+
| |
22+
| creates a temporary value which is freed while still in use
23+
LL |
24+
LL | bar(foo);
25+
| --- borrow later used here
26+
|
27+
= note: the result of `format_args!` can only be assigned directly if no placeholders in it's arguments are used
28+
= note: to learn more, visit <https://doc.rust-lang.org/std/macro.format_args.html>
29+
= note: this error originates in the macro `format_args` (in Nightly builds, run with -Z macro-backtrace for more info)
30+
31+
error: aborting due to 2 previous errors
32+
33+
For more information about this error, try `rustc --explain E0716`.

Diff for: tests/ui/drop-bounds/drop-bounds-impl-drop.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
#![deny(drop_bounds)]
33
// As a special exemption, `impl Drop` in the return position raises no error.
44
// This allows a convenient way to return an unnamed drop guard.
5-
fn voldemort_type() -> impl Drop {
6-
struct Voldemort;
7-
impl Drop for Voldemort {
5+
fn unnameable_type() -> impl Drop {
6+
struct Unnameable;
7+
impl Drop for Unnameable {
88
fn drop(&mut self) {}
99
}
10-
Voldemort
10+
Unnameable
1111
}
1212
fn main() {
13-
let _ = voldemort_type();
13+
let _ = unnameable_type();
1414
}

Diff for: tests/ui/fn/keyword-order.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ error: expected item, found keyword `pub`
1111
|
1212
LL | default pub const async unsafe extern fn err() {}
1313
| ^^^ expected item
14+
|
15+
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
1416

1517
error: aborting due to 2 previous errors
1618

Diff for: tests/ui/parser/default-unmatched.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ error: expected item, found reserved keyword `do`
1111
|
1212
LL | default do
1313
| ^^ expected item
14+
|
15+
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
1416

1517
error: aborting due to 2 previous errors
1618

Diff for: tests/ui/parser/impl-parsing.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ error: expected item, found keyword `unsafe`
3535
|
3636
LL | default unsafe FAIL
3737
| ^^^^^^ expected item
38+
|
39+
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
3840

3941
error: aborting due to 6 previous errors
4042

Diff for: tests/ui/parser/issue-101477-enum.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ error: expected item, found `==`
1111
|
1212
LL | B == 2
1313
| ^^ expected item
14+
|
15+
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
1416

1517
error: aborting due to 2 previous errors
1618

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5 //~ ERROR expected item, found `5`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: expected item, found `5`
2+
--> $DIR/issue-113110-non-item-at-module-root.rs:1:2
3+
|
4+
LL | 5
5+
| ^ expected item
6+
|
7+
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
8+
9+
error: aborting due to previous error
10+

Diff for: tests/ui/parser/issues/issue-17904-2.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: expected item, found keyword `where`
33
|
44
LL | struct Bar<T> { x: T } where T: Copy
55
| ^^^^^ expected item
6+
|
7+
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
68

79
error: aborting due to previous error
810

Diff for: tests/ui/parser/issues/issue-43196.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ error: expected item, found `|`
1111
|
1212
LL | |
1313
| ^ expected item
14+
|
15+
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
1416

1517
error: aborting due to 2 previous errors
1618

Diff for: tests/ui/parser/issues/issue-62913.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ error: expected item, found `"\u\"`
1717
|
1818
LL | "\u\"
1919
| ^^^^^^ expected item
20+
|
21+
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
2022

2123
error: aborting due to 3 previous errors
2224

Diff for: tests/ui/parser/issues/issue-68890.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ error: expected item, found `)`
1515
|
1616
LL | enum e{A((?'a a+?+l))}
1717
| ^ expected item
18+
|
19+
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
1820

1921
error: aborting due to 3 previous errors
2022

Diff for: tests/ui/parser/shebang/shebang-doc-comment.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: expected item, found `[`
33
|
44
LL | [allow(unused_variables)]
55
| ^ expected item
6+
|
7+
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
68

79
error: aborting due to previous error
810

Diff for: tests/ui/parser/virtual-structs.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: expected item, found reserved keyword `virtual`
33
|
44
LL | virtual struct SuperStruct {
55
| ^^^^^^^ expected item
6+
|
7+
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
68

79
error: aborting due to previous error
810

0 commit comments

Comments
 (0)