Skip to content

Commit ddcbba0

Browse files
committed
Auto merge of rust-lang#98680 - matthiaskrgr:rollup-1bkrrn9, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - rust-lang#98434 (Ensure that `static_crt` is set in the bootstrapper whenever using `cc-rs` to get a compiler command line.) - rust-lang#98636 (Triagebot: Fix mentions word wrapping.) - rust-lang#98642 (Fix rust-lang#98260) - rust-lang#98643 (Improve pretty printing of valtrees for references) - rust-lang#98646 (rustdoc: fix bugs in main.js popover help and settings) - rust-lang#98647 (Update cargo) - rust-lang#98652 (`alloc`: clean and ensure `no_global_oom_handling` builds are warning-free) - rust-lang#98660 (Unbreak stage1 tests via ignore-stage1 in `proc-macro/invalid-punct-ident-1.rs`.) - rust-lang#98665 (Use verbose help for deprecation suggestion) - rust-lang#98668 (Avoid some `&str` to `String` conversions with `MultiSpan::push_span_label`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3fcf43b + d34c4ca commit ddcbba0

File tree

46 files changed

+311
-238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+311
-238
lines changed

compiler/rustc_const_eval/src/const_eval/mod.rs

-78
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc_middle::mir;
55
use rustc_middle::mir::interpret::{EvalToValTreeResult, GlobalId};
66
use rustc_middle::ty::{self, TyCtxt};
77
use rustc_span::{source_map::DUMMY_SP, symbol::Symbol};
8-
use rustc_target::abi::VariantIdx;
98

109
use crate::interpret::{
1110
intern_const_alloc_recursive, ConstValue, InternKind, InterpCx, InterpResult, MemPlaceMeta,
@@ -91,83 +90,6 @@ pub(crate) fn eval_to_valtree<'tcx>(
9190
}
9291
}
9392

94-
/// Tries to destructure constants of type Array or Adt into the constants
95-
/// of its fields.
96-
pub(crate) fn try_destructure_const<'tcx>(
97-
tcx: TyCtxt<'tcx>,
98-
const_: ty::Const<'tcx>,
99-
) -> Option<ty::DestructuredConst<'tcx>> {
100-
if let ty::ConstKind::Value(valtree) = const_.kind() {
101-
let branches = match valtree {
102-
ty::ValTree::Branch(b) => b,
103-
_ => return None,
104-
};
105-
106-
let (fields, variant) = match const_.ty().kind() {
107-
ty::Array(inner_ty, _) | ty::Slice(inner_ty) => {
108-
// construct the consts for the elements of the array/slice
109-
let field_consts = branches
110-
.iter()
111-
.map(|b| {
112-
tcx.mk_const(ty::ConstS { kind: ty::ConstKind::Value(*b), ty: *inner_ty })
113-
})
114-
.collect::<Vec<_>>();
115-
debug!(?field_consts);
116-
117-
(field_consts, None)
118-
}
119-
ty::Adt(def, _) if def.variants().is_empty() => bug!("unreachable"),
120-
ty::Adt(def, substs) => {
121-
let variant_idx = if def.is_enum() {
122-
VariantIdx::from_u32(branches[0].unwrap_leaf().try_to_u32().ok()?)
123-
} else {
124-
VariantIdx::from_u32(0)
125-
};
126-
let fields = &def.variant(variant_idx).fields;
127-
let mut field_consts = Vec::with_capacity(fields.len());
128-
129-
// Note: First element inValTree corresponds to variant of enum
130-
let mut valtree_idx = if def.is_enum() { 1 } else { 0 };
131-
for field in fields {
132-
let field_ty = field.ty(tcx, substs);
133-
let field_valtree = branches[valtree_idx]; // first element of branches is variant
134-
let field_const = tcx.mk_const(ty::ConstS {
135-
kind: ty::ConstKind::Value(field_valtree),
136-
ty: field_ty,
137-
});
138-
field_consts.push(field_const);
139-
valtree_idx += 1;
140-
}
141-
debug!(?field_consts);
142-
143-
(field_consts, Some(variant_idx))
144-
}
145-
ty::Tuple(elem_tys) => {
146-
let fields = elem_tys
147-
.iter()
148-
.enumerate()
149-
.map(|(i, elem_ty)| {
150-
let elem_valtree = branches[i];
151-
tcx.mk_const(ty::ConstS {
152-
kind: ty::ConstKind::Value(elem_valtree),
153-
ty: elem_ty,
154-
})
155-
})
156-
.collect::<Vec<_>>();
157-
158-
(fields, None)
159-
}
160-
_ => bug!("cannot destructure constant {:?}", const_),
161-
};
162-
163-
let fields = tcx.arena.alloc_from_iter(fields.into_iter());
164-
165-
Some(ty::DestructuredConst { variant, fields })
166-
} else {
167-
None
168-
}
169-
}
170-
17193
#[instrument(skip(tcx), level = "debug")]
17294
pub(crate) fn try_destructure_mir_constant<'tcx>(
17395
tcx: TyCtxt<'tcx>,

compiler/rustc_const_eval/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ pub fn provide(providers: &mut Providers) {
4242
providers.eval_to_const_value_raw = const_eval::eval_to_const_value_raw_provider;
4343
providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
4444
providers.const_caller_location = const_eval::const_caller_location;
45-
providers.try_destructure_const = |tcx, val| const_eval::try_destructure_const(tcx, val);
4645
providers.eval_to_valtree = |tcx, param_env_and_value| {
4746
let (param_env, raw) = param_env_and_value.into_parts();
4847
const_eval::eval_to_valtree(tcx, param_env, raw)

compiler/rustc_expand/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &
136136
let mut msp = MultiSpan::from_span(primary_span);
137137
for span_label in span_labels {
138138
let span = make_span(&file_text, &span_label.start, &span_label.end);
139-
msp.push_span_label(span, span_label.label.to_string());
139+
msp.push_span_label(span, span_label.label);
140140
println!("span: {:?} label: {:?}", span, span_label.label);
141141
println!("text: {:?}", source_map.span_to_snippet(span));
142142
}

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -194,24 +194,18 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
194194
if !v.0.is_empty() {
195195
span = v.0.clone().into();
196196
for sp in v.0 {
197-
span.push_span_label(
198-
sp,
199-
"`'static` requirement introduced here".to_string(),
200-
);
197+
span.push_span_label(sp, "`'static` requirement introduced here");
201198
}
202199
add_label = false;
203200
}
204201
}
205202
if add_label {
206203
span.push_span_label(
207204
fn_decl.output.span(),
208-
"requirement introduced by this return type".to_string(),
205+
"requirement introduced by this return type",
209206
);
210207
}
211-
span.push_span_label(
212-
cause.span,
213-
"because of this returned expression".to_string(),
214-
);
208+
span.push_span_label(cause.span, "because of this returned expression");
215209
err.span_note(
216210
span,
217211
"`'static` lifetime requirement introduced by the return type",
@@ -523,13 +517,11 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
523517
hir_v.visit_ty(&self_ty);
524518
for span in &traits {
525519
let mut multi_span: MultiSpan = vec![*span].into();
526-
multi_span.push_span_label(
527-
*span,
528-
"this has an implicit `'static` lifetime requirement".to_string(),
529-
);
520+
multi_span
521+
.push_span_label(*span, "this has an implicit `'static` lifetime requirement");
530522
multi_span.push_span_label(
531523
ident.span,
532-
"calling this method introduces the `impl`'s 'static` requirement".to_string(),
524+
"calling this method introduces the `impl`'s 'static` requirement",
533525
);
534526
err.span_note(multi_span, "the used `impl` has a `'static` requirement");
535527
err.span_suggestion_verbose(

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
128128
}
129129
let mut type_param_span: MultiSpan = visitor.types.to_vec().into();
130130
for &span in &visitor.types {
131-
type_param_span.push_span_label(
132-
span,
133-
"consider borrowing this type parameter in the trait".to_string(),
134-
);
131+
type_param_span
132+
.push_span_label(span, "consider borrowing this type parameter in the trait");
135133
}
136134

137135
err.note(&format!("expected `{}`\n found `{}`", expected, found));

compiler/rustc_infer/src/traits/error_reporting/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ pub fn report_object_safety_error<'tcx>(
8585
let has_multi_span = !multi_span.is_empty();
8686
let mut note_span = MultiSpan::from_spans(multi_span.clone());
8787
if let (Some(trait_span), true) = (trait_span, has_multi_span) {
88-
note_span
89-
.push_span_label(trait_span, "this trait cannot be made into an object...".to_string());
88+
note_span.push_span_label(trait_span, "this trait cannot be made into an object...");
9089
}
9190
for (span, msg) in iter::zip(multi_span, messages) {
9291
note_span.push_span_label(span, msg);

compiler/rustc_middle/src/middle/stability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ pub fn deprecation_suggestion(
150150
span: Span,
151151
) {
152152
if let Some(suggestion) = suggestion {
153-
diag.span_suggestion(
153+
diag.span_suggestion_verbose(
154154
span,
155155
&format!("replace the use of the deprecated {}", kind),
156156
suggestion,

compiler/rustc_middle/src/mir/interpret/queries.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,8 @@ impl<'tcx> TyCtxtEnsure<'tcx> {
205205
}
206206

207207
impl<'tcx> TyCtxt<'tcx> {
208-
/// Destructure a type-level constant ADT or array into its variant index and its field values.
209-
/// Panics if the destructuring fails, use `try_destructure_const` for fallible version.
210-
pub fn destructure_const(self, const_: ty::Const<'tcx>) -> ty::DestructuredConst<'tcx> {
211-
self.try_destructure_const(const_).unwrap()
212-
}
213-
214208
/// Destructure a mir constant ADT or array into its variant index and its field values.
215-
/// Panics if the destructuring fails, use `try_destructure_const` for fallible version.
209+
/// Panics if the destructuring fails, use `try_destructure_mir_constant` for fallible version.
216210
pub fn destructure_mir_constant(
217211
self,
218212
param_env: ty::ParamEnv<'tcx>,

compiler/rustc_middle/src/query/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -978,11 +978,9 @@ rustc_queries! {
978978
desc { "converting type-level constant value to mir constant value"}
979979
}
980980

981-
/// Destructure a constant ADT or array into its variant index and its
982-
/// field values or return `None` if constant is invalid.
983-
///
984-
/// Use infallible `TyCtxt::destructure_const` when you know that constant is valid.
985-
query try_destructure_const(key: ty::Const<'tcx>) -> Option<ty::DestructuredConst<'tcx>> {
981+
/// Destructures array, ADT or tuple constants into the constants
982+
/// of their fields.
983+
query destructure_const(key: ty::Const<'tcx>) -> ty::DestructuredConst<'tcx> {
986984
desc { "destructuring type level constant"}
987985
}
988986

compiler/rustc_middle/src/ty/print/pretty.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,11 @@ pub trait PrettyPrinter<'tcx>:
14471447
p!(write("{:?}", String::from_utf8_lossy(bytes)));
14481448
return Ok(self);
14491449
}
1450-
_ => {}
1450+
_ => {
1451+
p!("&");
1452+
p!(pretty_print_const_valtree(valtree, *inner_ty, print_ty));
1453+
return Ok(self);
1454+
}
14511455
},
14521456
(ty::ValTree::Branch(_), ty::Array(t, _)) if *t == u8_type => {
14531457
let bytes = valtree.try_to_raw_bytes(self.tcx(), *t).unwrap_or_else(|| {
@@ -1459,16 +1463,8 @@ pub trait PrettyPrinter<'tcx>:
14591463
}
14601464
// Aggregates, printed as array/tuple/struct/variant construction syntax.
14611465
(ty::ValTree::Branch(_), ty::Array(..) | ty::Tuple(..) | ty::Adt(..)) => {
1462-
let Some(contents) = self.tcx().try_destructure_const(
1463-
ty::Const::from_value(self.tcx(), valtree, ty)
1464-
) else {
1465-
// Fall back to debug pretty printing for invalid constants.
1466-
p!(write("{:?}", valtree));
1467-
if print_ty {
1468-
p!(": ", print(ty));
1469-
}
1470-
return Ok(self);
1471-
};
1466+
let contents =
1467+
self.tcx().destructure_const(ty::Const::from_value(self.tcx(), valtree, ty));
14721468
let fields = contents.fields.iter().copied();
14731469
match *ty.kind() {
14741470
ty::Array(..) => {

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ fn adt_defined_here<'p, 'tcx>(
947947

948948
span.push_span_label(def_span, String::new());
949949
for pat in spans {
950-
span.push_span_label(pat, "not covered".to_string());
950+
span.push_span_label(pat, "not covered");
951951
}
952952
err.span_note(span, &format!("`{}` defined here", ty));
953953
}

compiler/rustc_parse/src/parser/mod.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -891,22 +891,19 @@ impl<'a> Parser<'a> {
891891
let mut first_note = MultiSpan::from(vec![initial_semicolon]);
892892
first_note.push_span_label(
893893
initial_semicolon,
894-
"this `;` turns the preceding closure into a statement".to_string(),
894+
"this `;` turns the preceding closure into a statement",
895895
);
896896
first_note.push_span_label(
897897
closure_spans.body,
898-
"this expression is a statement because of the trailing semicolon".to_string(),
898+
"this expression is a statement because of the trailing semicolon",
899899
);
900900
expect_err.span_note(first_note, "statement found outside of a block");
901901

902902
let mut second_note = MultiSpan::from(vec![closure_spans.whole_closure]);
903-
second_note.push_span_label(
904-
closure_spans.whole_closure,
905-
"this is the parsed closure...".to_string(),
906-
);
903+
second_note.push_span_label(closure_spans.whole_closure, "this is the parsed closure...");
907904
second_note.push_span_label(
908905
following_token_span,
909-
"...but likely you meant the closure to end here".to_string(),
906+
"...but likely you meant the closure to end here",
910907
);
911908
expect_err.span_note(second_note, "the closure body may be incorrectly delimited");
912909

compiler/rustc_passes/src/check_attr.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -857,11 +857,8 @@ impl CheckAttrVisitor<'_> {
857857
if let Some((prev_inline, prev_span)) = *specified_inline {
858858
if do_inline != prev_inline {
859859
let mut spans = MultiSpan::from_spans(vec![prev_span, meta.span()]);
860-
spans.push_span_label(prev_span, String::from("this attribute..."));
861-
spans.push_span_label(
862-
meta.span(),
863-
String::from("...conflicts with this attribute"),
864-
);
860+
spans.push_span_label(prev_span, "this attribute...");
861+
spans.push_span_label(meta.span(), "...conflicts with this attribute");
865862
self.tcx
866863
.sess
867864
.struct_span_err(spans, "conflicting doc inlining attributes")

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2561,7 +2561,7 @@ fn show_candidates(
25612561
let span = source_span[local_def_id];
25622562
let span = session.source_map().guess_head_span(span);
25632563
let mut multi_span = MultiSpan::from_span(span);
2564-
multi_span.push_span_label(span, "not accessible".to_string());
2564+
multi_span.push_span_label(span, "not accessible");
25652565
err.span_note(multi_span, &msg);
25662566
} else {
25672567
err.note(&msg);

compiler/rustc_resolve/src/late/diagnostics.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,8 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
601601
};
602602
multi_span.push_span_label(sp, msg);
603603
}
604-
multi_span.push_span_label(
605-
base_error.span,
606-
"expected this type to be a trait...".to_string(),
607-
);
604+
multi_span
605+
.push_span_label(base_error.span, "expected this type to be a trait...");
608606
err.span_help(
609607
multi_span,
610608
"`+` is used to constrain a \"trait object\" type with lifetimes or \
@@ -1227,17 +1225,14 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
12271225
let mut m: MultiSpan = non_visible_spans.clone().into();
12281226
non_visible_spans
12291227
.into_iter()
1230-
.for_each(|s| m.push_span_label(s, "private field".to_string()));
1228+
.for_each(|s| m.push_span_label(s, "private field"));
12311229
err.span_note(m, "constructor is not visible here due to private fields");
12321230
}
12331231

12341232
return true;
12351233
}
12361234

1237-
err.span_label(
1238-
span,
1239-
"constructor is not visible here due to private fields".to_string(),
1240-
);
1235+
err.span_label(span, "constructor is not visible here due to private fields");
12411236
}
12421237
(
12431238
Res::Def(

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -2204,8 +2204,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
22042204
_ => true,
22052205
};
22062206
if !ident.span.overlaps(span) && !same_line {
2207-
multispan
2208-
.push_span_label(ident.span, "required by a bound in this".to_string());
2207+
multispan.push_span_label(ident.span, "required by a bound in this");
22092208
}
22102209
}
22112210
let descr = format!("required by a bound in `{}`", item_name);

0 commit comments

Comments
 (0)