Skip to content

Commit fc8a3e3

Browse files
committed
Auto merge of rust-lang#114024 - matthiaskrgr:rollup-uhdbq64, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#113969 (add dynamic for smir) - rust-lang#113985 (Use erased self type when autoderefing for trait error suggestion) - rust-lang#113987 (Comment stuff in the new solver) - rust-lang#113992 (arm-none fixups) - rust-lang#113993 (Optimize format usage) - rust-lang#113994 (Optimize format usage) - rust-lang#114006 (Update sparc-unknown-none-elf platform README) - rust-lang#114021 (Add missing documentation for `Session::time`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents cb6ab95 + a516425 commit fc8a3e3

30 files changed

+315
-76
lines changed

compiler/rustc_errors/src/diagnostic.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -420,13 +420,13 @@ impl Diagnostic {
420420
let expected_label = if expected_label.is_empty() {
421421
"expected".to_string()
422422
} else {
423-
format!("expected {}", expected_label)
423+
format!("expected {expected_label}")
424424
};
425425
let found_label = found_label.to_string();
426426
let found_label = if found_label.is_empty() {
427427
"found".to_string()
428428
} else {
429-
format!("found {}", found_label)
429+
format!("found {found_label}")
430430
};
431431
let (found_padding, expected_padding) = if expected_label.len() > found_label.len() {
432432
(expected_label.len() - found_label.len(), 0)
@@ -439,13 +439,13 @@ impl Diagnostic {
439439
StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
440440
StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
441441
}));
442-
msg.push((format!("`{}\n", expected_extra), Style::NoStyle));
442+
msg.push((format!("`{expected_extra}\n"), Style::NoStyle));
443443
msg.push((format!("{}{} `", " ".repeat(found_padding), found_label), Style::NoStyle));
444444
msg.extend(found.0.iter().map(|x| match *x {
445445
StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
446446
StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
447447
}));
448-
msg.push((format!("`{}", found_extra), Style::NoStyle));
448+
msg.push((format!("`{found_extra}"), Style::NoStyle));
449449

450450
// For now, just attach these as notes.
451451
self.highlighted_note(msg);
@@ -454,7 +454,7 @@ impl Diagnostic {
454454

455455
pub fn note_trait_signature(&mut self, name: Symbol, signature: String) -> &mut Self {
456456
self.highlighted_note(vec![
457-
(format!("`{}` from trait: `", name), Style::NoStyle),
457+
(format!("`{name}` from trait: `"), Style::NoStyle),
458458
(signature, Style::Highlight),
459459
("`".to_string(), Style::NoStyle),
460460
]);

compiler/rustc_errors/src/diagnostic_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl IntoDiagnosticArg for bool {
102102

103103
impl IntoDiagnosticArg for char {
104104
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
105-
DiagnosticArgValue::Str(Cow::Owned(format!("{:?}", self)))
105+
DiagnosticArgValue::Str(Cow::Owned(format!("{self:?}")))
106106
}
107107
}
108108

compiler/rustc_errors/src/emitter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,12 @@ pub trait Emitter: Translate {
279279
let msg = if substitution.is_empty() || sugg.style.hide_inline() {
280280
// This substitution is only removal OR we explicitly don't want to show the
281281
// code inline (`hide_inline`). Therefore, we don't show the substitution.
282-
format!("help: {}", &msg)
282+
format!("help: {msg}")
283283
} else {
284284
// Show the default suggestion text with the substitution
285285
format!(
286286
"help: {}{}: `{}`",
287-
&msg,
287+
msg,
288288
if self.source_map().is_some_and(|sm| is_case_difference(
289289
sm,
290290
substitution,

compiler/rustc_errors/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ impl HandlerInner {
14851485
let _ = self.fatal(errors);
14861486
}
14871487
(_, _) => {
1488-
let _ = self.fatal(format!("{}; {}", &errors, &warnings));
1488+
let _ = self.fatal(format!("{errors}; {warnings}"));
14891489
}
14901490
}
14911491

compiler/rustc_parse/src/parser/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl<'a> Parser<'a> {
238238
_ => unreachable!(),
239239
}
240240
.into();
241-
let invalid = format!("{}=", &sugg);
241+
let invalid = format!("{sugg}=");
242242
self.sess.emit_err(errors::InvalidComparisonOperator {
243243
span: sp,
244244
invalid: invalid.clone(),

compiler/rustc_parse/src/validate_attr.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -157,32 +157,32 @@ fn emit_malformed_attribute(
157157
matches!(name, sym::doc | sym::ignore | sym::inline | sym::link | sym::test | sym::bench)
158158
};
159159

160-
let error_msg = format!("malformed `{}` attribute input", name);
160+
let error_msg = format!("malformed `{name}` attribute input");
161161
let mut msg = "attribute must be of the form ".to_owned();
162162
let mut suggestions = vec![];
163163
let mut first = true;
164164
let inner = if style == ast::AttrStyle::Inner { "!" } else { "" };
165165
if template.word {
166166
first = false;
167-
let code = format!("#{}[{}]", inner, name);
168-
msg.push_str(&format!("`{}`", &code));
167+
let code = format!("#{inner}[{name}]");
168+
msg.push_str(&format!("`{code}`"));
169169
suggestions.push(code);
170170
}
171171
if let Some(descr) = template.list {
172172
if !first {
173173
msg.push_str(" or ");
174174
}
175175
first = false;
176-
let code = format!("#{}[{}({})]", inner, name, descr);
177-
msg.push_str(&format!("`{}`", &code));
176+
let code = format!("#{inner}[{name}({descr})]");
177+
msg.push_str(&format!("`{code}`"));
178178
suggestions.push(code);
179179
}
180180
if let Some(descr) = template.name_value_str {
181181
if !first {
182182
msg.push_str(" or ");
183183
}
184-
let code = format!("#{}[{} = \"{}\"]", inner, name, descr);
185-
msg.push_str(&format!("`{}`", &code));
184+
let code = format!("#{inner}[{name} = \"{descr}\"]");
185+
msg.push_str(&format!("`{code}`"));
186186
suggestions.push(code);
187187
}
188188
if should_warn(name) {

compiler/rustc_session/src/utils.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ impl Session {
77
pub fn timer(&self, what: &'static str) -> VerboseTimingGuard<'_> {
88
self.prof.verbose_generic_activity(what)
99
}
10+
/// Used by `-Z self-profile`.
1011
pub fn time<R>(&self, what: &'static str, f: impl FnOnce() -> R) -> R {
1112
self.prof.verbose_generic_activity(what).run(f)
1213
}

compiler/rustc_smir/src/rustc_internal/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ pub fn br_named_def(did: DefId) -> stable_mir::ty::BrNamedDef {
5959
with_tables(|t| t.br_named_def(did))
6060
}
6161

62+
pub fn trait_def(did: DefId) -> stable_mir::ty::TraitDef {
63+
with_tables(|t| t.trait_def(did))
64+
}
65+
6266
impl<'tcx> Tables<'tcx> {
6367
pub fn item_def_id(&self, item: &stable_mir::CrateItem) -> DefId {
6468
self.def_ids[item.0]
@@ -100,6 +104,10 @@ impl<'tcx> Tables<'tcx> {
100104
stable_mir::ty::BrNamedDef(self.create_def_id(did))
101105
}
102106

107+
pub fn trait_def(&mut self, did: DefId) -> stable_mir::ty::TraitDef {
108+
stable_mir::ty::TraitDef(self.create_def_id(did))
109+
}
110+
103111
fn create_def_id(&mut self, did: DefId) -> stable_mir::DefId {
104112
// FIXME: this becomes inefficient when we have too many ids
105113
for (i, &d) in self.def_ids.iter().enumerate() {

compiler/rustc_smir/src/rustc_smir/mod.rs

+83-4
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,72 @@ impl<'tcx> Stable<'tcx> for ty::AliasTy<'tcx> {
258258
}
259259
}
260260

261+
impl<'tcx> Stable<'tcx> for ty::DynKind {
262+
type T = stable_mir::ty::DynKind;
263+
264+
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
265+
use ty::DynKind;
266+
match self {
267+
DynKind::Dyn => stable_mir::ty::DynKind::Dyn,
268+
DynKind::DynStar => stable_mir::ty::DynKind::DynStar,
269+
}
270+
}
271+
}
272+
273+
impl<'tcx> Stable<'tcx> for ty::ExistentialPredicate<'tcx> {
274+
type T = stable_mir::ty::ExistentialPredicate;
275+
276+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
277+
use stable_mir::ty::ExistentialPredicate::*;
278+
match self {
279+
ty::ExistentialPredicate::Trait(existential_trait_ref) => {
280+
Trait(existential_trait_ref.stable(tables))
281+
}
282+
ty::ExistentialPredicate::Projection(existential_projection) => {
283+
Projection(existential_projection.stable(tables))
284+
}
285+
ty::ExistentialPredicate::AutoTrait(def_id) => AutoTrait(tables.trait_def(*def_id)),
286+
}
287+
}
288+
}
289+
290+
impl<'tcx> Stable<'tcx> for ty::ExistentialTraitRef<'tcx> {
291+
type T = stable_mir::ty::ExistentialTraitRef;
292+
293+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
294+
let ty::ExistentialTraitRef { def_id, args } = self;
295+
stable_mir::ty::ExistentialTraitRef {
296+
def_id: tables.trait_def(*def_id),
297+
generic_args: args.stable(tables),
298+
}
299+
}
300+
}
301+
302+
impl<'tcx> Stable<'tcx> for ty::TermKind<'tcx> {
303+
type T = stable_mir::ty::TermKind;
304+
305+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
306+
use stable_mir::ty::TermKind;
307+
match self {
308+
ty::TermKind::Ty(ty) => TermKind::Type(tables.intern_ty(*ty)),
309+
ty::TermKind::Const(const_) => TermKind::Const(opaque(const_)),
310+
}
311+
}
312+
}
313+
314+
impl<'tcx> Stable<'tcx> for ty::ExistentialProjection<'tcx> {
315+
type T = stable_mir::ty::ExistentialProjection;
316+
317+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
318+
let ty::ExistentialProjection { def_id, args, term } = self;
319+
stable_mir::ty::ExistentialProjection {
320+
def_id: tables.trait_def(*def_id),
321+
generic_args: args.stable(tables),
322+
term: term.unpack().stable(tables),
323+
}
324+
}
325+
}
326+
261327
impl<'tcx> Stable<'tcx> for ty::adjustment::PointerCoercion {
262328
type T = stable_mir::mir::PointerCoercion;
263329
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
@@ -525,13 +591,17 @@ impl<'tcx> Stable<'tcx> for ty::GenericArgs<'tcx> {
525591
}
526592
}
527593

528-
impl<'tcx> Stable<'tcx> for ty::PolyFnSig<'tcx> {
529-
type T = stable_mir::ty::PolyFnSig;
594+
impl<'tcx, S, V> Stable<'tcx> for ty::Binder<'tcx, S>
595+
where
596+
S: Stable<'tcx, T = V>,
597+
{
598+
type T = stable_mir::ty::Binder<V>;
599+
530600
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
531601
use stable_mir::ty::Binder;
532602

533603
Binder {
534-
value: self.skip_binder().stable(tables),
604+
value: self.as_ref().skip_binder().stable(tables),
535605
bound_vars: self
536606
.bound_vars()
537607
.iter()
@@ -671,7 +741,16 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> {
671741
generic_args.stable(tables),
672742
)),
673743
ty::FnPtr(poly_fn_sig) => TyKind::RigidTy(RigidTy::FnPtr(poly_fn_sig.stable(tables))),
674-
ty::Dynamic(_, _, _) => todo!(),
744+
ty::Dynamic(existential_predicates, region, dyn_kind) => {
745+
TyKind::RigidTy(RigidTy::Dynamic(
746+
existential_predicates
747+
.iter()
748+
.map(|existential_predicate| existential_predicate.stable(tables))
749+
.collect(),
750+
opaque(region),
751+
dyn_kind.stable(tables),
752+
))
753+
}
675754
ty::Closure(def_id, generic_args) => TyKind::RigidTy(RigidTy::Closure(
676755
rustc_internal::closure_def(*def_id),
677756
generic_args.stable(tables),

compiler/rustc_smir/src/stable_mir/ty.rs

+36
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub enum RigidTy {
3838
FnPtr(PolyFnSig),
3939
Closure(ClosureDef, GenericArgs),
4040
Generator(GeneratorDef, GenericArgs, Movability),
41+
Dynamic(Vec<Binder<ExistentialPredicate>>, Region, DynKind),
4142
Never,
4243
Tuple(Vec<Ty>),
4344
}
@@ -98,6 +99,9 @@ pub struct AdtDef(pub(crate) DefId);
9899
#[derive(Clone, PartialEq, Eq, Debug)]
99100
pub struct AliasDef(pub(crate) DefId);
100101

102+
#[derive(Clone, PartialEq, Eq, Debug)]
103+
pub struct TraitDef(pub(crate) DefId);
104+
101105
#[derive(Clone, Debug)]
102106
pub struct GenericArgs(pub Vec<GenericArgKind>);
103107

@@ -108,6 +112,12 @@ pub enum GenericArgKind {
108112
Const(Const),
109113
}
110114

115+
#[derive(Clone, Debug)]
116+
pub enum TermKind {
117+
Type(Ty),
118+
Const(Const),
119+
}
120+
111121
#[derive(Clone, Debug)]
112122
pub enum AliasKind {
113123
Projection,
@@ -192,3 +202,29 @@ pub enum BoundRegionKind {
192202
BrNamed(BrNamedDef, String),
193203
BrEnv,
194204
}
205+
206+
#[derive(Clone, Debug)]
207+
pub enum DynKind {
208+
Dyn,
209+
DynStar,
210+
}
211+
212+
#[derive(Clone, Debug)]
213+
pub enum ExistentialPredicate {
214+
Trait(ExistentialTraitRef),
215+
Projection(ExistentialProjection),
216+
AutoTrait(TraitDef),
217+
}
218+
219+
#[derive(Clone, Debug)]
220+
pub struct ExistentialTraitRef {
221+
pub def_id: TraitDef,
222+
pub generic_args: GenericArgs,
223+
}
224+
225+
#[derive(Clone, Debug)]
226+
pub struct ExistentialProjection {
227+
pub def_id: TraitDef,
228+
pub generic_args: GenericArgs,
229+
pub term: TermKind,
230+
}

compiler/rustc_target/src/spec/armebv7r_none_eabi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, Targ
55

66
pub fn target() -> Target {
77
Target {
8-
llvm_target: "armebv7r-unknown-none-eabi".into(),
8+
llvm_target: "armebv7r-none-eabi".into(),
99
pointer_width: 32,
1010
data_layout: "E-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
1111
arch: "arm".into(),
@@ -18,7 +18,7 @@ pub fn target() -> Target {
1818
panic_strategy: PanicStrategy::Abort,
1919
max_atomic_width: Some(64),
2020
emit_debug_gdb_scripts: false,
21-
// GCC and Clang default to 8 for arm-none here
21+
// GCC defaults to 8 for arm-none here.
2222
c_enum_min_bits: Some(8),
2323
..Default::default()
2424
},

compiler/rustc_target/src/spec/armebv7r_none_eabihf.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, Targ
55

66
pub fn target() -> Target {
77
Target {
8-
llvm_target: "armebv7r-unknown-none-eabihf".into(),
8+
llvm_target: "armebv7r-none-eabihf".into(),
99
pointer_width: 32,
1010
data_layout: "E-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
1111
arch: "arm".into(),
@@ -19,7 +19,7 @@ pub fn target() -> Target {
1919
features: "+vfp3,-d32,-fp16".into(),
2020
max_atomic_width: Some(64),
2121
emit_debug_gdb_scripts: false,
22-
// GCC and Clang default to 8 for arm-none here
22+
// GCC defaults to 8 for arm-none here.
2323
c_enum_min_bits: Some(8),
2424
..Default::default()
2525
},

compiler/rustc_target/src/spec/armv4t_none_eabi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ pub fn target() -> Target {
3939
has_thumb_interworking: true,
4040
relocation_model: RelocModel::Static,
4141
panic_strategy: PanicStrategy::Abort,
42-
// from thumb_base, rust-lang/rust#44993.
42+
// From thumb_base, rust-lang/rust#44993.
4343
emit_debug_gdb_scripts: false,
44-
// from thumb_base, apparently gcc/clang give enums a minimum of 8 bits on no-os targets
44+
// From thumb_base, GCC gives enums a minimum of 8 bits on no-os targets.
4545
c_enum_min_bits: Some(8),
4646
..Default::default()
4747
},

compiler/rustc_target/src/spec/armv7a_none_eabihf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn target() -> Target {
1818
max_atomic_width: Some(64),
1919
panic_strategy: PanicStrategy::Abort,
2020
emit_debug_gdb_scripts: false,
21-
// GCC and Clang default to 8 for arm-none here
21+
// GCC defaults to 8 for arm-none here.
2222
c_enum_min_bits: Some(8),
2323
..Default::default()
2424
};

0 commit comments

Comments
 (0)