Skip to content

Commit b2b34bd

Browse files
committed
Auto merge of #112344 - matthiaskrgr:rollup-tswr83e, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #111058 (Correct fortanix LVI test print function) - #111369 (Added custom risc32-imac for esp-espidf target) - #111962 (Make GDB Python Pretty Printers loadable after spawning GDB, avoiding required `rust-gdb`) - #112019 (Don't suggest changing `&self` and `&mut self` in function signature to be mutable when taking `&mut self` in closure) - #112199 (Fix suggestion for matching struct with `..` on both ends) - #112220 (Cleanup some `EarlyBinder::skip_binder()` -> `EarlyBinder::subst_identity()`) - #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

Lines changed: 22 additions & 6 deletions
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

Lines changed: 13 additions & 1 deletion
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

Lines changed: 11 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 45 additions & 12 deletions
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

Lines changed: 1 addition & 0 deletions
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),
Lines changed: 31 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions
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)

0 commit comments

Comments
 (0)