Skip to content

Commit b2b34bd

Browse files
committed
Auto merge of rust-lang#112344 - matthiaskrgr:rollup-tswr83e, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#111058 (Correct fortanix LVI test print function) - rust-lang#111369 (Added custom risc32-imac for esp-espidf target) - rust-lang#111962 (Make GDB Python Pretty Printers loadable after spawning GDB, avoiding required `rust-gdb`) - rust-lang#112019 (Don't suggest changing `&self` and `&mut self` in function signature to be mutable when taking `&mut self` in closure) - rust-lang#112199 (Fix suggestion for matching struct with `..` on both ends) - rust-lang#112220 (Cleanup some `EarlyBinder::skip_binder()` -> `EarlyBinder::subst_identity()`) - rust-lang#112325 (diagnostics: do not suggest type name tweaks on type-inferred closure args) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3572d74 + 38c92cc commit b2b34bd

File tree

24 files changed

+320
-41
lines changed

24 files changed

+320
-41
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+22-6
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,28 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
416416
_,
417417
) = pat.kind
418418
{
419-
err.span_suggestion(
420-
upvar_ident.span,
421-
"consider changing this to be mutable",
422-
format!("mut {}", upvar_ident.name),
423-
Applicability::MachineApplicable,
424-
);
419+
if upvar_ident.name == kw::SelfLower {
420+
for (_, node) in self.infcx.tcx.hir().parent_iter(upvar_hir_id) {
421+
if let Some(fn_decl) = node.fn_decl() {
422+
if !matches!(fn_decl.implicit_self, hir::ImplicitSelfKind::ImmRef | hir::ImplicitSelfKind::MutRef) {
423+
err.span_suggestion(
424+
upvar_ident.span,
425+
"consider changing this to be mutable",
426+
format!("mut {}", upvar_ident.name),
427+
Applicability::MachineApplicable,
428+
);
429+
break;
430+
}
431+
}
432+
}
433+
} else {
434+
err.span_suggestion(
435+
upvar_ident.span,
436+
"consider changing this to be mutable",
437+
format!("mut {}", upvar_ident.name),
438+
Applicability::MachineApplicable,
439+
);
440+
}
425441
}
426442

427443
let tcx = self.infcx.tcx;

compiler/rustc_hir_typeck/src/check.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,19 @@ pub(super) fn check_fn<'a, 'tcx>(
9696
// for simple cases like `fn foo(x: Trait)`,
9797
// where we would error once on the parameter as a whole, and once on the binding `x`.
9898
if param.pat.simple_ident().is_none() && !params_can_be_unsized {
99-
fcx.require_type_is_sized(param_ty, param.pat.span, traits::SizedArgumentType(ty_span));
99+
fcx.require_type_is_sized(
100+
param_ty,
101+
param.pat.span,
102+
// ty_span == binding_span iff this is a closure parameter with no type ascription,
103+
// or if it's an implicit `self` parameter
104+
traits::SizedArgumentType(
105+
if ty_span == Some(param.span) && tcx.is_closure(fn_def_id.into()) {
106+
None
107+
} else {
108+
ty_span
109+
},
110+
),
111+
);
100112
}
101113

102114
fcx.write_ty(param.hir_id, param_ty);

compiler/rustc_hir_typeck/src/gather_locals.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,17 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
129129
self.fcx.require_type_is_sized(
130130
var_ty,
131131
p.span,
132-
traits::SizedArgumentType(Some(ty_span)),
132+
// ty_span == ident.span iff this is a closure parameter with no type
133+
// ascription, or if it's an implicit `self` parameter
134+
traits::SizedArgumentType(
135+
if ty_span == ident.span
136+
&& self.fcx.tcx.is_closure(self.fcx.body_id.into())
137+
{
138+
None
139+
} else {
140+
Some(ty_span)
141+
},
142+
),
133143
);
134144
}
135145
} else {

compiler/rustc_middle/src/ty/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ impl<'tcx> Instance<'tcx> {
586586
if let Some(substs) = self.substs_for_mir_body() {
587587
v.subst(tcx, substs)
588588
} else {
589-
v.skip_binder()
589+
v.subst_identity()
590590
}
591591
}
592592

compiler/rustc_mir_transform/src/shim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ fn build_call_shim<'tcx>(
647647
let mut sig = if let Some(sig_substs) = sig_substs {
648648
sig.subst(tcx, &sig_substs)
649649
} else {
650-
sig.skip_binder()
650+
sig.subst_identity()
651651
};
652652

653653
if let CallKind::Indirect(fnty) = call_kind {

compiler/rustc_parse/src/parser/pat.rs

+45-12
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,8 @@ impl<'a> Parser<'a> {
938938
let mut etc = false;
939939
let mut ate_comma = true;
940940
let mut delayed_err: Option<DiagnosticBuilder<'a, ErrorGuaranteed>> = None;
941-
let mut etc_span = None;
941+
let mut first_etc_and_maybe_comma_span = None;
942+
let mut last_non_comma_dotdot_span = None;
942943

943944
while self.token != token::CloseDelim(Delimiter::Brace) {
944945
let attrs = match self.parse_outer_attributes() {
@@ -969,12 +970,27 @@ impl<'a> Parser<'a> {
969970
{
970971
etc = true;
971972
let mut etc_sp = self.token.span;
973+
if first_etc_and_maybe_comma_span.is_none() {
974+
if let Some(comma_tok) = self
975+
.look_ahead(1, |t| if *t == token::Comma { Some(t.clone()) } else { None })
976+
{
977+
let nw_span = self
978+
.sess
979+
.source_map()
980+
.span_extend_to_line(comma_tok.span)
981+
.trim_start(comma_tok.span.shrink_to_lo())
982+
.map(|s| self.sess.source_map().span_until_non_whitespace(s));
983+
first_etc_and_maybe_comma_span = nw_span.map(|s| etc_sp.to(s));
984+
} else {
985+
first_etc_and_maybe_comma_span =
986+
Some(self.sess.source_map().span_until_non_whitespace(etc_sp));
987+
}
988+
}
972989

973990
self.recover_bad_dot_dot();
974991
self.bump(); // `..` || `...` || `_`
975992

976993
if self.token == token::CloseDelim(Delimiter::Brace) {
977-
etc_span = Some(etc_sp);
978994
break;
979995
}
980996
let token_str = super::token_descr(&self.token);
@@ -996,7 +1012,6 @@ impl<'a> Parser<'a> {
9961012
ate_comma = true;
9971013
}
9981014

999-
etc_span = Some(etc_sp.until(self.token.span));
10001015
if self.token == token::CloseDelim(Delimiter::Brace) {
10011016
// If the struct looks otherwise well formed, recover and continue.
10021017
if let Some(sp) = comma_sp {
@@ -1040,6 +1055,9 @@ impl<'a> Parser<'a> {
10401055
}
10411056
}?;
10421057
ate_comma = this.eat(&token::Comma);
1058+
1059+
last_non_comma_dotdot_span = Some(this.prev_token.span);
1060+
10431061
// We just ate a comma, so there's no need to use
10441062
// `TrailingToken::Comma`
10451063
Ok((field, TrailingToken::None))
@@ -1049,15 +1067,30 @@ impl<'a> Parser<'a> {
10491067
}
10501068

10511069
if let Some(mut err) = delayed_err {
1052-
if let Some(etc_span) = etc_span {
1053-
err.multipart_suggestion(
1054-
"move the `..` to the end of the field list",
1055-
vec![
1056-
(etc_span, String::new()),
1057-
(self.token.span, format!("{}.. }}", if ate_comma { "" } else { ", " })),
1058-
],
1059-
Applicability::MachineApplicable,
1060-
);
1070+
if let Some(first_etc_span) = first_etc_and_maybe_comma_span {
1071+
if self.prev_token == token::DotDot {
1072+
// We have `.., x, ..`.
1073+
err.multipart_suggestion(
1074+
"remove the starting `..`",
1075+
vec![(first_etc_span, String::new())],
1076+
Applicability::MachineApplicable,
1077+
);
1078+
} else {
1079+
if let Some(last_non_comma_dotdot_span) = last_non_comma_dotdot_span {
1080+
// We have `.., x`.
1081+
err.multipart_suggestion(
1082+
"move the `..` to the end of the field list",
1083+
vec![
1084+
(first_etc_span, String::new()),
1085+
(
1086+
self.token.span.to(last_non_comma_dotdot_span.shrink_to_hi()),
1087+
format!("{} .. }}", if ate_comma { "" } else { "," }),
1088+
),
1089+
],
1090+
Applicability::MachineApplicable,
1091+
);
1092+
}
1093+
}
10611094
}
10621095
err.emit();
10631096
}

compiler/rustc_target/src/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,7 @@ supported_targets! {
12841284
("riscv32im-unknown-none-elf", riscv32im_unknown_none_elf),
12851285
("riscv32imc-unknown-none-elf", riscv32imc_unknown_none_elf),
12861286
("riscv32imc-esp-espidf", riscv32imc_esp_espidf),
1287+
("riscv32imac-esp-espidf", riscv32imac_esp_espidf),
12871288
("riscv32imac-unknown-none-elf", riscv32imac_unknown_none_elf),
12881289
("riscv32imac-unknown-xous-elf", riscv32imac_unknown_xous_elf),
12891290
("riscv32gc-unknown-linux-gnu", riscv32gc_unknown_linux_gnu),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use crate::spec::{cvs, PanicStrategy, RelocModel, Target, TargetOptions};
2+
3+
pub fn target() -> Target {
4+
Target {
5+
data_layout: "e-m:e-p:32:32-i64:64-n32-S128".into(),
6+
llvm_target: "riscv32".into(),
7+
pointer_width: 32,
8+
arch: "riscv32".into(),
9+
10+
options: TargetOptions {
11+
families: cvs!["unix"],
12+
os: "espidf".into(),
13+
env: "newlib".into(),
14+
vendor: "espressif".into(),
15+
linker: Some("riscv32-esp-elf-gcc".into()),
16+
cpu: "generic-rv32".into(),
17+
18+
// As RiscV32IMAC architecture does natively support atomics,
19+
// automatically enable the support for the Rust STD library.
20+
max_atomic_width: Some(64),
21+
atomic_cas: true,
22+
23+
features: "+m,+a,+c".into(),
24+
panic_strategy: PanicStrategy::Abort,
25+
relocation_model: RelocModel::Static,
26+
emit_debug_gdb_scripts: false,
27+
eh_frame_header: false,
28+
..Default::default()
29+
},
30+
}
31+
}

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2807,8 +2807,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
28072807
err.help("unsized locals are gated as an unstable feature");
28082808
}
28092809
}
2810-
ObligationCauseCode::SizedArgumentType(sp) => {
2811-
if let Some(span) = sp {
2810+
ObligationCauseCode::SizedArgumentType(ty_span) => {
2811+
if let Some(span) = ty_span {
28122812
if let ty::PredicateKind::Clause(clause) = predicate.kind().skip_binder()
28132813
&& let ty::Clause::Trait(trait_pred) = clause
28142814
&& let ty::Dynamic(..) = trait_pred.self_ty().kind()

src/doc/rustc/src/platform-support.md

+1
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ target | std | host | notes
298298
`riscv32im-unknown-none-elf` | * | | Bare RISC-V (RV32IM ISA)
299299
[`riscv32imac-unknown-xous-elf`](platform-support/riscv32imac-unknown-xous-elf.md) | ? | | RISC-V Xous (RV32IMAC ISA)
300300
[`riscv32imc-esp-espidf`](platform-support/esp-idf.md) | ✓ | | RISC-V ESP-IDF
301+
[`riscv32imac-esp-espidf`](platform-support/esp-idf.md) | ✓ | | RISC-V ESP-IDF
301302
`riscv64gc-unknown-freebsd` | | | RISC-V FreeBSD
302303
`riscv64gc-unknown-fuchsia` | | | RISC-V Fuchsia
303304
`riscv64gc-unknown-linux-musl` | | | RISC-V Linux (kernel 4.20, musl 1.2.0)

src/doc/rustc/src/platform-support/esp-idf.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ Targets for the [ESP-IDF](https://github.com/espressif/esp-idf) development fram
1313

1414
The target names follow this format: `$ARCH-esp-espidf`, where `$ARCH` specifies the target processor architecture. The following targets are currently defined:
1515

16-
| Target name | Target CPU(s) |
17-
|--------------------------------|-----------------------|
18-
| `riscv32imc-esp-espidf` | [ESP32-C3](https://www.espressif.com/en/products/socs/esp32-c3) |
16+
| Target name | Target CPU(s) | Minimum ESP-IDF version |
17+
|--------------------------------|-----------------------|-------------------------|
18+
| `riscv32imc-esp-espidf` | [ESP32-C3](https://www.espressif.com/en/products/socs/esp32-c3) | `v4.3` |
19+
| `riscv32imac-esp-espidf` | [ESP32-C6](https://www.espressif.com/en/products/socs/esp32-c6) | `v5.1` |
1920

20-
The minimum supported ESP-IDF version is `v4.3`, though it is recommended to use the latest stable release if possible.
21+
It is recommended to use the latest ESP-IDF stable release if possible.
2122

2223
## Building the target
2324

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# Add this folder to the python sys path; GDB Python-interpreter will now find modules in this path
2+
import sys
3+
from os import path
4+
self_dir = path.dirname(path.realpath(__file__))
5+
sys.path.append(self_dir)
6+
17
import gdb
28
import gdb_lookup
3-
gdb_lookup.register_printers(gdb.current_objfile())
9+
10+
# current_objfile can be none; even with `gdb foo-app`; sourcing this file after gdb init now works
11+
try:
12+
gdb_lookup.register_printers(gdb.current_objfile())
13+
except Exception:
14+
gdb_lookup.register_printers(gdb.selected_inferior().progspace)

src/librustdoc/clean/blanket_impl.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
104104
// the post-inference `trait_ref`, as it's more accurate.
105105
trait_: Some(clean_trait_ref_with_bindings(
106106
cx,
107-
ty::Binder::dummy(trait_ref.skip_binder()),
107+
ty::Binder::dummy(trait_ref.subst_identity()),
108108
ThinVec::new(),
109109
)),
110-
for_: clean_middle_ty(ty::Binder::dummy(ty.skip_binder()), cx, None),
110+
for_: clean_middle_ty(ty::Binder::dummy(ty.subst_identity()), cx, None),
111111
items: cx
112112
.tcx
113113
.associated_items(impl_def_id)
@@ -116,7 +116,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
116116
.collect::<Vec<_>>(),
117117
polarity: ty::ImplPolarity::Positive,
118118
kind: ImplKind::Blanket(Box::new(clean_middle_ty(
119-
ty::Binder::dummy(trait_ref.skip_binder().self_ty()),
119+
ty::Binder::dummy(trait_ref.subst_identity().self_ty()),
120120
cx,
121121
None,
122122
))),
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CHECK: print
22
CHECK: lfence
3-
CHECK: lfence
4-
CHECK: lfence
5-
CHECK: callq 0x{{[[:xdigit:]]*}} <_Unwind_Resume>
6-
CHECK-NEXT: ud2
3+
CHECK: popq
4+
CHECK-NEXT: popq [[REGISTER:%[a-z]+]]
5+
CHECK-NEXT: lfence
6+
CHECK-NEXT: jmpq *[[REGISTER]]

tests/run-make/x86_64-fortanix-unknown-sgx-lvi/script.sh

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ function check {
3333
${objdump} --disassemble-symbols="${func}" --demangle \
3434
${enclave} > ${asm}
3535
${filecheck} --input-file ${asm} ${checks}
36+
37+
if [ "${func_re}" != "rust_plus_one_global_asm" &&
38+
"${func_re}" != "cmake_plus_one_c_global_asm" ]; then
39+
# The assembler cannot avoid explicit `ret` instructions. Sequences
40+
# of `shlq $0x0, (%rsp); lfence; retq` are used instead.
41+
# https://www.intel.com/content/www/us/en/developer/articles/technical/
42+
# software-security-guidance/technical-documentation/load-value-injection.html
43+
${filecheck} --implicit-check-not ret --input-file ${asm} ${checks}
44+
fi
3645
}
3746

3847
build

tests/ui/borrowck/issue-111554.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
struct Foo {}
2+
3+
impl Foo {
4+
pub fn foo(&mut self) {
5+
|| bar(&mut self);
6+
//~^ ERROR cannot borrow `self` as mutable, as it is not declared as mutable
7+
}
8+
9+
pub fn baz(&self) {
10+
|| bar(&mut self);
11+
//~^ ERROR cannot borrow `self` as mutable, as it is not declared as mutable
12+
//~| ERROR cannot borrow data in a `&` reference as mutable
13+
}
14+
15+
pub fn qux(mut self) {
16+
|| bar(&mut self);
17+
// OK
18+
}
19+
20+
pub fn quux(self) {
21+
|| bar(&mut self);
22+
//~^ ERROR cannot borrow `self` as mutable, as it is not declared as mutable
23+
}
24+
}
25+
26+
fn bar(_: &mut Foo) {}
27+
28+
fn main() {}

tests/ui/borrowck/issue-111554.stderr

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
2+
--> $DIR/issue-111554.rs:5:16
3+
|
4+
LL | || bar(&mut self);
5+
| ^^^^^^^^^ cannot borrow as mutable
6+
7+
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
8+
--> $DIR/issue-111554.rs:10:16
9+
|
10+
LL | || bar(&mut self);
11+
| ^^^^^^^^^ cannot borrow as mutable
12+
13+
error[E0596]: cannot borrow data in a `&` reference as mutable
14+
--> $DIR/issue-111554.rs:10:16
15+
|
16+
LL | || bar(&mut self);
17+
| ^^^^^^^^^ cannot borrow as mutable
18+
19+
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
20+
--> $DIR/issue-111554.rs:21:16
21+
|
22+
LL | pub fn quux(self) {
23+
| ---- help: consider changing this to be mutable: `mut self`
24+
LL | || bar(&mut self);
25+
| ^^^^^^^^^ cannot borrow as mutable
26+
27+
error: aborting due to 4 previous errors
28+
29+
For more information about this error, try `rustc --explain E0596`.

tests/ui/closures/issue-111932.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait Foo: std::fmt::Debug {}
2+
3+
fn print_foos(foos: impl Iterator<Item = dyn Foo>) {
4+
foos.for_each(|foo| { //~ ERROR [E0277]
5+
println!("{:?}", foo); //~ ERROR [E0277]
6+
});
7+
}
8+
9+
fn main() {}

0 commit comments

Comments
 (0)