Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #106637

Merged
merged 28 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9c8bf51
Remove invalid case for mutable borrow suggestion
RedDocMD Dec 13, 2022
afefbb6
Clean up mut keyword check
RedDocMD Dec 14, 2022
73e7207
Fix ui constant tests for big-endian platforms
uweigand Dec 22, 2022
cc1dee1
Fix incorrect suggestion for extra `&` in pattern
obeis Dec 30, 2022
a74a488
Add ui test for #106182
obeis Dec 30, 2022
50ab306
Simplify some canonical type alias names
compiler-errors Jan 3, 2023
c104ee9
Move check_region_obligations_and_report_errors to TypeErrCtxt
compiler-errors Dec 26, 2022
21b078a
Use FxIndexSet when updating obligation causes in adjust_fulfillment_…
compiler-errors Jan 4, 2023
c5bde06
Enable Shadow Call Stack for Fuchsia on AArch64
ilovepi Dec 22, 2022
d0cf7e3
Use fmt named parameters in rustc_borrowck
wcampbell0x2a Jan 7, 2023
ecc0507
docs/test: add empty error-docs for `E0208`, `E0640` and `E0717`
Ezrashaw Jan 8, 2023
24ce65c
docs/test: add error-docs and UI test for `E0711`
Ezrashaw Jan 8, 2023
2c92c72
fix: fix CI errors
Ezrashaw Jan 9, 2023
abe040d
Change commit_if_ok to probe
JulianKnodt Dec 4, 2022
77b6137
Change based on comments
JulianKnodt Dec 13, 2022
b79a9a0
Set !const_evaluatable if ambig. and not inferred
JulianKnodt Dec 20, 2022
7c5cb73
Check for duplicates
JulianKnodt Dec 20, 2022
21c5ffe
Clean up
JulianKnodt Dec 21, 2022
b7587f1
Rollup merge of #105292 - JulianKnodt:no_eager_commit, r=BoxyUwU
fee1-dead Jan 9, 2023
c1f8a3f
Rollup merge of #105655 - RedDocMD:bug-105645, r=oli-obk
fee1-dead Jan 9, 2023
63f2a13
Rollup merge of #106047 - uweigand:s390x-test-bigendian-ui, r=oli-obk
fee1-dead Jan 9, 2023
fd75cfe
Rollup merge of #106061 - ilovepi:fuchsia-scs, r=oli-obk
fee1-dead Jan 9, 2023
7779386
Rollup merge of #106164 - compiler-errors:check-region-tweak, r=oli-obk
fee1-dead Jan 9, 2023
37c1d6d
Rollup merge of #106291 - obeis:issue-106182, r=oli-obk
fee1-dead Jan 9, 2023
f8319bb
Rollup merge of #106389 - compiler-errors:no-canonicalized, r=lcnr
fee1-dead Jan 9, 2023
357128a
Rollup merge of #106468 - compiler-errors:err-instability, r=lcnr
fee1-dead Jan 9, 2023
99529b0
Rollup merge of #106549 - wcampbell0x2a:use-fmt-named-parameters-borr…
fee1-dead Jan 9, 2023
77f529b
Rollup merge of #106614 - Ezrashaw:ui-test-fixups-2, r=GuillaumeGomez
fee1-dead Jan 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
err.span_note(
MultiSpan::from_spans(reinit_spans),
&if reinits <= 3 {
format!("these {} reinitializations might get skipped", reinits)
format!("these {reinits} reinitializations might get skipped")
} else {
format!(
"these 3 reinitializations and {} other{} might get skipped",
Expand Down Expand Up @@ -225,9 +225,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
err.span_label(
span,
format!(
"value {} here after {}move",
"value {} here after {partial_str}move",
desired_action.as_verb_in_past_tense(),
partial_str
),
);
}
Expand Down Expand Up @@ -257,7 +256,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&format!(
"consider creating a fresh reborrow of {} here",
self.describe_place(moved_place)
.map(|n| format!("`{}`", n))
.map(|n| format!("`{n}`"))
.unwrap_or_else(|| "the mutable reference".to_string()),
),
"&mut *",
Expand All @@ -271,7 +270,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
DescribePlaceOpt { including_downcast: true, including_tuple_field: true },
);
let note_msg = match opt_name {
Some(name) => format!("`{}`", name),
Some(name) => format!("`{name}`"),
None => "value".to_owned(),
};
if self.suggest_borrow_fn_like(&mut err, ty, &move_site_vec, &note_msg) {
Expand All @@ -297,9 +296,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
} = use_spans
{
err.note(&format!(
"{} occurs due to deref coercion to `{}`",
"{} occurs due to deref coercion to `{deref_target_ty}`",
desired_action.as_noun(),
deref_target_ty
));

// Check first whether the source is accessible (issue #87060)
Expand Down
39 changes: 13 additions & 26 deletions compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
if borrow_span.map(|sp| !sp.overlaps(var_or_use_span)).unwrap_or(true) {
err.span_label(
var_or_use_span,
format!("{}borrow later {}", borrow_desc, message),
format!("{borrow_desc}borrow later {message}"),
);
}
} else {
Expand All @@ -90,7 +90,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
let capture_kind_label = message;
err.span_label(
var_or_use_span,
format!("{}borrow later {}", borrow_desc, capture_kind_label),
format!("{borrow_desc}borrow later {capture_kind_label}"),
);
err.span_label(path_span, path_label);
}
Expand All @@ -110,7 +110,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
};
// We can use `var_or_use_span` if either `path_span` is not present, or both spans are the same
if path_span.map(|path_span| path_span == var_or_use_span).unwrap_or(true) {
err.span_label(var_or_use_span, format!("{}{}", borrow_desc, message));
err.span_label(var_or_use_span, format!("{borrow_desc}{message}"));
} else {
// path_span must be `Some` as otherwise the if condition is true
let path_span = path_span.unwrap();
Expand All @@ -121,7 +121,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
let capture_kind_label = message;
err.span_label(
var_or_use_span,
format!("{}borrow later {}", borrow_desc, capture_kind_label),
format!("{borrow_desc}borrow later {capture_kind_label}"),
);
err.span_label(path_span, path_label);
}
Expand Down Expand Up @@ -160,12 +160,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
match local_names[dropped_local] {
Some(local_name) if !local_decl.from_compiler_desugaring() => {
let message = format!(
"{B}borrow might be used here, when `{LOC}` is dropped \
and runs the {DTOR} for {TYPE}",
B = borrow_desc,
LOC = local_name,
TYPE = type_desc,
DTOR = dtor_desc
"{borrow_desc}borrow might be used here, when `{local_name}` is dropped \
and runs the {dtor_desc} for {type_desc}",
);
err.span_label(body.source_info(drop_loc).span, message);

Expand All @@ -180,18 +176,14 @@ impl<'tcx> BorrowExplanation<'tcx> {
err.span_label(
local_decl.source_info.span,
format!(
"a temporary with access to the {B}borrow \
"a temporary with access to the {borrow_desc}borrow \
is created here ...",
B = borrow_desc
),
);
let message = format!(
"... and the {B}borrow might be used here, \
"... and the {borrow_desc}borrow might be used here, \
when that temporary is dropped \
and runs the {DTOR} for {TYPE}",
B = borrow_desc,
TYPE = type_desc,
DTOR = dtor_desc
and runs the {dtor_desc} for {type_desc}",
);
err.span_label(body.source_info(drop_loc).span, message);

Expand Down Expand Up @@ -249,20 +241,16 @@ impl<'tcx> BorrowExplanation<'tcx> {
err.span_label(
span,
format!(
"{}requires that `{}` is borrowed for `{}`",
"{}requires that `{desc}` is borrowed for `{region_name}`",
category.description(),
desc,
region_name,
),
);
} else {
err.span_label(
span,
format!(
"{}requires that {}borrow lasts for `{}`",
"{}requires that {borrow_desc}borrow lasts for `{region_name}`",
category.description(),
borrow_desc,
region_name,
),
);
};
Expand Down Expand Up @@ -296,15 +284,14 @@ impl<'tcx> BorrowExplanation<'tcx> {
if region_name.was_named() { region_name.name } else { kw::UnderscoreLifetime };

let msg = format!(
"you can add a bound to the {}to make it last less than `'static` and match `{}`",
"you can add a bound to the {}to make it last less than `'static` and match `{region_name}`",
category.description(),
region_name,
);

err.span_suggestion_verbose(
span.shrink_to_hi(),
&msg,
format!(" + {}", suggestable_name),
format!(" + {suggestable_name}"),
Applicability::Unspecified,
);
}
Expand Down
38 changes: 16 additions & 22 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
move_prefix: &str,
) {
let message = format!(
"{}move occurs because {} has type `{}`, which does not implement the `Copy` trait",
move_prefix, place_desc, ty,
"{move_prefix}move occurs because {place_desc} has type `{ty}`, which does not implement the `Copy` trait",
);
if let Some(span) = span {
err.span_label(span, message);
Expand Down Expand Up @@ -739,11 +738,11 @@ impl<'tcx> BorrowedContentSource<'tcx> {
BorrowedContentSource::OverloadedDeref(ty) => ty
.ty_adt_def()
.and_then(|adt| match tcx.get_diagnostic_name(adt.did())? {
name @ (sym::Rc | sym::Arc) => Some(format!("an `{}`", name)),
name @ (sym::Rc | sym::Arc) => Some(format!("an `{name}`")),
_ => None,
})
.unwrap_or_else(|| format!("dereference of `{}`", ty)),
BorrowedContentSource::OverloadedIndex(ty) => format!("index of `{}`", ty),
.unwrap_or_else(|| format!("dereference of `{ty}`")),
BorrowedContentSource::OverloadedIndex(ty) => format!("index of `{ty}`"),
}
}

Expand All @@ -769,11 +768,11 @@ impl<'tcx> BorrowedContentSource<'tcx> {
BorrowedContentSource::OverloadedDeref(ty) => ty
.ty_adt_def()
.and_then(|adt| match tcx.get_diagnostic_name(adt.did())? {
name @ (sym::Rc | sym::Arc) => Some(format!("an `{}`", name)),
name @ (sym::Rc | sym::Arc) => Some(format!("an `{name}`")),
_ => None,
})
.unwrap_or_else(|| format!("dereference of `{}`", ty)),
BorrowedContentSource::OverloadedIndex(ty) => format!("an index of `{}`", ty),
.unwrap_or_else(|| format!("dereference of `{ty}`")),
BorrowedContentSource::OverloadedIndex(ty) => format!("an index of `{ty}`"),
}
}

Expand Down Expand Up @@ -1033,7 +1032,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
if let UseSpans::FnSelfUse { var_span, fn_call_span, fn_span, kind } = move_spans {
let place_name = self
.describe_place(moved_place.as_ref())
.map(|n| format!("`{}`", n))
.map(|n| format!("`{n}`"))
.unwrap_or_else(|| "value".to_owned());
match kind {
CallKind::FnCall { fn_trait_id, .. }
Expand All @@ -1042,8 +1041,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
err.span_label(
fn_call_span,
&format!(
"{} {}moved due to this call{}",
place_name, partially_str, loop_message
"{place_name} {partially_str}moved due to this call{loop_message}",
),
);
err.span_note(
Expand All @@ -1056,8 +1054,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
err.span_label(
fn_call_span,
&format!(
"{} {}moved due to usage in operator{}",
place_name, partially_str, loop_message
"{place_name} {partially_str}moved due to usage in operator{loop_message}",
),
);
if self.fn_self_span_reported.insert(fn_span) {
Expand Down Expand Up @@ -1089,9 +1086,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
err.span_suggestion_verbose(
move_span.shrink_to_lo(),
&format!(
"consider iterating over a slice of the `{}`'s content to \
"consider iterating over a slice of the `{ty}`'s content to \
avoid moving into the `for` loop",
ty,
),
"&",
Applicability::MaybeIncorrect,
Expand All @@ -1101,8 +1097,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
err.span_label(
fn_call_span,
&format!(
"{} {}moved due to this implicit call to `.into_iter()`{}",
place_name, partially_str, loop_message
"{place_name} {partially_str}moved due to this implicit call to `.into_iter()`{loop_message}",
),
);
// If the moved place was a `&mut` ref, then we can
Expand All @@ -1118,7 +1113,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&format!(
"consider creating a fresh reborrow of {} here",
self.describe_place(moved_place.as_ref())
.map(|n| format!("`{}`", n))
.map(|n| format!("`{n}`"))
.unwrap_or_else(|| "the mutable reference".to_string()),
),
"&mut *",
Expand All @@ -1130,8 +1125,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
err.span_label(
fn_call_span,
&format!(
"{} {}moved due to this method call{}",
place_name, partially_str, loop_message
"{place_name} {partially_str}moved due to this method call{loop_message}",
),
);
let infcx = tcx.infer_ctxt().build();
Expand Down Expand Up @@ -1206,15 +1200,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
if move_span != span || !loop_message.is_empty() {
err.span_label(
move_span,
format!("value {}moved{} here{}", partially_str, move_msg, loop_message),
format!("value {partially_str}moved{move_msg} here{loop_message}"),
);
}
// If the move error occurs due to a loop, don't show
// another message for the same span
if loop_message.is_empty() {
move_spans.var_span_label(
err,
format!("variable {}moved due to use{}", partially_str, move_spans.describe()),
format!("variable {partially_str}moved due to use{}", move_spans.describe()),
"moved",
);
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
ProjectionElem::Deref,
],
} => {
err.span_label(span, format!("cannot {ACT}", ACT = act));
err.span_label(span, format!("cannot {act}"));

if let Some(span) = get_mut_span_in_struct_field(
self.infcx.tcx,
Expand All @@ -290,7 +290,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
.unwrap_or(false) =>
{
let decl = &self.body.local_decls[local];
err.span_label(span, format!("cannot {ACT}", ACT = act));
err.span_label(span, format!("cannot {act}"));
if let Some(mir::Statement {
source_info,
kind:
Expand Down Expand Up @@ -639,7 +639,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}

PlaceRef { local: _, projection: [.., ProjectionElem::Deref] } => {
err.span_label(span, format!("cannot {ACT}", ACT = act));
err.span_label(span, format!("cannot {act}"));

match opt_source {
Some(BorrowedContentSource::OverloadedDeref(ty)) => {
Expand Down Expand Up @@ -1212,7 +1212,7 @@ fn suggest_ampmut<'tcx>(
{
let lt_name = &src[1..ws_pos];
let ty = &src[ws_pos..];
return (true, highlight_span, format!("&{} mut{}", lt_name, ty));
return (true, highlight_span, format!("&{lt_name} mut{ty}"));
}

let ty_mut = local_decl.ty.builtin_deref(true).unwrap();
Expand Down
18 changes: 8 additions & 10 deletions compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ impl OutlivesSuggestionBuilder {
let mut diag = if suggested.len() == 1 {
mbcx.infcx.tcx.sess.diagnostic().struct_help(&match suggested.last().unwrap() {
SuggestedConstraint::Outlives(a, bs) => {
let bs: SmallVec<[String; 2]> = bs.iter().map(|r| format!("{}", r)).collect();
format!("add bound `{}: {}`", a, bs.join(" + "))
let bs: SmallVec<[String; 2]> = bs.iter().map(|r| r.to_string()).collect();
format!("add bound `{a}: {}`", bs.join(" + "))
}

SuggestedConstraint::Equal(a, b) => {
format!("`{}` and `{}` must be the same: replace one with the other", a, b)
format!("`{a}` and `{b}` must be the same: replace one with the other")
}
SuggestedConstraint::Static(a) => format!("replace `{}` with `'static`", a),
SuggestedConstraint::Static(a) => format!("replace `{a}` with `'static`"),
})
} else {
// Create a new diagnostic.
Expand All @@ -231,18 +231,16 @@ impl OutlivesSuggestionBuilder {
for constraint in suggested {
match constraint {
SuggestedConstraint::Outlives(a, bs) => {
let bs: SmallVec<[String; 2]> =
bs.iter().map(|r| format!("{}", r)).collect();
diag.help(&format!("add bound `{}: {}`", a, bs.join(" + ")));
let bs: SmallVec<[String; 2]> = bs.iter().map(|r| r.to_string()).collect();
diag.help(&format!("add bound `{a}: {}`", bs.join(" + ")));
}
SuggestedConstraint::Equal(a, b) => {
diag.help(&format!(
"`{}` and `{}` must be the same: replace one with the other",
a, b
"`{a}` and `{b}` must be the same: replace one with the other",
));
}
SuggestedConstraint::Static(a) => {
diag.help(&format!("replace `{}` with `'static`", a));
diag.help(&format!("replace `{a}` with `'static`"));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
);
(desc, note)
}
_ => panic!("Unexpected type {:?}", ty),
_ => panic!("Unexpected type {ty:?}"),
};
diag.note(&format!("requirement occurs because of {desc}",));
diag.note(&note);
Expand Down Expand Up @@ -725,10 +725,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let lifetime = if f.has_name() { fr_name.name } else { kw::UnderscoreLifetime };

let arg = match param.param.pat.simple_ident() {
Some(simple_ident) => format!("argument `{}`", simple_ident),
Some(simple_ident) => format!("argument `{simple_ident}`"),
None => "the argument".to_string(),
};
let captures = format!("captures data from {}", arg);
let captures = format!("captures data from {arg}");

return nice_region_error::suggest_new_region_bound(
self.infcx.tcx,
Expand Down
Loading