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 22 pull requests #91756

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
5907a8c
Fix incorrect feature flags
jhpratt Nov 14, 2021
64cca29
Fix method name reference in stream documentation
jplatte Nov 21, 2021
15a4ed6
adjust const_eval_select documentation
RalfJung Nov 28, 2021
85558ad
adjust some const_eval_select safety comments
RalfJung Nov 28, 2021
80a308d
Use `HashMap::from()` instead of using `HashMap::new()` with `HashMap…
JosephTLyons Dec 2, 2021
440cffd
Use `BTreeMap::from()` instead of using `BTreeMap::new()` with `BTree…
JosephTLyons Dec 2, 2021
72a6974
Make `HashMap`s mutable again
JosephTLyons Dec 3, 2021
d5f6b9c
code-cov: generate dead functions with private/default linkage
wesleywiser Dec 2, 2021
8bfc76d
Fix Vec::extend_from_slice docs
rukai Dec 4, 2021
41f7692
Document all public items in `rustc_incremental`
pierwill Oct 29, 2021
d9e4502
fix documentation for `core::ready::Ready`
ibraheemdev Dec 8, 2021
913996b
Remove the match on `ErrorKind::Other`
ChrisDenton Dec 8, 2021
c7f80fc
add tests
b-naber Dec 8, 2021
c025a5d
move core/stream/stream/mod.rs to core/stream/stream.rs
ibraheemdev Dec 8, 2021
15de4cb
Remove redundant [..]s
est31 Dec 3, 2021
9f6da95
fix typo in `intrinsics::raw_eq` docs
WaffleLapkin Dec 8, 2021
42f9104
Fix `Vec::reserve_exact` documentation
dalcde Dec 9, 2021
4b0a9c9
Delete Utf8Lossy::from_str
dtolnay Dec 9, 2021
e18518b
Add unstable book entries for parts of asm that are not being stabilized
Amanieu Dec 9, 2021
caed83d
Add reminder to match the error kind once ` DirectoryNotEmpty` is sta…
ChrisDenton Dec 9, 2021
cebd949
Replace iterator-based set construction by *Set::From<[T; N]>
juniorbassani Dec 9, 2021
99bd24e
Fix span calculation on secondary_label as well
compiler-errors Dec 5, 2021
8a6f54f
Use more accurate wording in `bootstrap.py` logging
jyn514 Dec 9, 2021
ae6f5fb
If --verbose is passed, print a warning in `bootstrap.py` when downlo…
jyn514 Dec 9, 2021
dfcaac5
Don't print bootstrap caching/ensure info unless `-vv` is passed
jyn514 Dec 9, 2021
6840030
Default to `doc-stage = 2` for the tools profile
jyn514 Dec 9, 2021
777c041
Add pierwill to .mailmap
pierwill Dec 10, 2021
305dd69
Fix since attribute for const_linked_list_new feature
not-my-profile Dec 10, 2021
381b275
Suggest using a temporary variable to fix borrowck errors
camelid Mar 15, 2021
c80c1f0
Rollup merge of #83174 - camelid:borrow-help, r=oli-obk
matthiaskrgr Dec 10, 2021
743344b
Rollup merge of #90407 - pierwill:edit-rustc-incremental-docs, r=cjgi…
matthiaskrgr Dec 10, 2021
08c58bf
Rollup merge of #90897 - jhpratt:fix-incorrect-feature-flags, r=dtolnay
matthiaskrgr Dec 10, 2021
48ab293
Rollup merge of #91105 - jplatte:stream-docs, r=dtolnay
matthiaskrgr Dec 10, 2021
4ca565b
Rollup merge of #91325 - RalfJung:const_eval_select, r=dtolnay
matthiaskrgr Dec 10, 2021
efa9cce
Rollup merge of #91470 - wesleywiser:code_coverage_link_error, r=tmandry
matthiaskrgr Dec 10, 2021
f510acc
Rollup merge of #91482 - JosephTLyons:update-HashMap-and-BTreeMap-doc…
matthiaskrgr Dec 10, 2021
f758c82
Rollup merge of #91524 - rukai:fix_extend_from_slice_docs, r=dtolnay
matthiaskrgr Dec 10, 2021
6ec2bcb
Rollup merge of #91575 - compiler-errors:issue-91556, r=cjgillot
matthiaskrgr Dec 10, 2021
4174648
Rollup merge of #91625 - est31:remove_indexes, r=oli-obk
matthiaskrgr Dec 10, 2021
b3c957f
Rollup merge of #91646 - ibraheemdev:patch-9, r=dtolnay
matthiaskrgr Dec 10, 2021
0614348
Rollup merge of #91668 - ChrisDenton:bootstrap-clean-error, r=Mark-Si…
matthiaskrgr Dec 10, 2021
eadfd89
Rollup merge of #91678 - b-naber:tests-for-postpone-const-eval, r=jac…
matthiaskrgr Dec 10, 2021
e609f20
Rollup merge of #91679 - ibraheemdev:stream-mod, r=Mark-Simulacrum
matthiaskrgr Dec 10, 2021
7208476
Rollup merge of #91681 - WaffleLapkin:patch-3, r=scottmcm
matthiaskrgr Dec 10, 2021
51fb3cb
Rollup merge of #91686 - dalcde:patch-1, r=dtolnay
matthiaskrgr Dec 10, 2021
5934aa8
Rollup merge of #91697 - dtolnay:lossyfromstr, r=Mark-Simulacrum
matthiaskrgr Dec 10, 2021
899412e
Rollup merge of #91706 - Amanieu:asm_unstable_book2, r=joshtriplett
matthiaskrgr Dec 10, 2021
1abaaf1
Rollup merge of #91709 - juniorbassani:use-from-array-in-set-examples…
matthiaskrgr Dec 10, 2021
be75849
Rollup merge of #91716 - jyn514:x.py-defaults, r=Mark-Simulacrum
matthiaskrgr Dec 10, 2021
f47131f
Rollup merge of #91747 - pierwill:patch-1, r=Mark-Simulacrum
matthiaskrgr Dec 10, 2021
8d5ce4a
Rollup merge of #91755 - not-my-profile:fix-const_linked_list_new-sin…
matthiaskrgr Dec 10, 2021
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
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ Philipp Brüschweiler <[email protected]> <[email protected]>
Philipp Krones <[email protected]> flip1995 <[email protected]>
Philipp Krones <[email protected]> <[email protected]>
Philipp Matthias Schäfer <[email protected]>
pierwill <[email protected]> <[email protected]>
Przemysław Wesołek <[email protected]> Przemek Wesołek <[email protected]>
Rafael Ávila de Espíndola <[email protected]> Rafael Avila de Espindola <espindola@dream.(none)>
Ralph Giles <[email protected]> Ralph Giles <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/util/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl LitKind {
// string in the token.
let s = symbol.as_str();
let symbol =
if s.contains(&['\\', '\r'][..]) {
if s.contains(&['\\', '\r']) {
let mut buf = String::with_capacity(s.len());
let mut error = Ok(());
unescape_literal(&s, Mode::Str, &mut |_, unescaped_char| {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {

if let Some(modifiers) = nested_meta.value_str() {
for modifier in modifiers.as_str().split(',') {
if let Some(modifier) = modifier.strip_prefix(&['+', '-'][..]) {
if let Some(modifier) = modifier.strip_prefix(&['+', '-']) {
macro_rules! gate_modifier { ($($name:literal => $feature:ident)*) => {
$(if modifier == $name {
let msg = concat!("`#[link(modifiers=\"", $name, "\")]` is unstable");
Expand Down Expand Up @@ -383,7 +383,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}

ast::ItemKind::Fn(..) => {
if self.sess.contains_name(&i.attrs[..], sym::start) {
if self.sess.contains_name(&i.attrs, sym::start) {
gate_feature_post!(
&self,
start,
Expand All @@ -396,7 +396,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}

ast::ItemKind::Struct(..) => {
for attr in self.sess.filter_by_name(&i.attrs[..], sym::repr) {
for attr in self.sess.filter_by_name(&i.attrs, sym::repr) {
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
if item.has_name(sym::simd) {
gate_feature_post!(
Expand Down
28 changes: 14 additions & 14 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
ast::MetaItemKind::List(ref items) => {
self.print_path(&item.path, false, 0);
self.popen();
self.commasep(Consistent, &items[..], |s, i| s.print_meta_list_item(i));
self.commasep(Consistent, &items, |s, i| s.print_meta_list_item(i));
self.pclose();
}
}
Expand Down Expand Up @@ -997,7 +997,7 @@ impl<'a> State<'a> {
}
ast::TyKind::Tup(ref elts) => {
self.popen();
self.commasep(Inconsistent, &elts[..], |s, ty| s.print_type(ty));
self.commasep(Inconsistent, &elts, |s, ty| s.print_type(ty));
if elts.len() == 1 {
self.word(",");
}
Expand All @@ -1017,10 +1017,10 @@ impl<'a> State<'a> {
ast::TyKind::Path(Some(ref qself), ref path) => self.print_qpath(path, qself, false),
ast::TyKind::TraitObject(ref bounds, syntax) => {
let prefix = if syntax == ast::TraitObjectSyntax::Dyn { "dyn" } else { "" };
self.print_type_bounds(prefix, &bounds[..]);
self.print_type_bounds(prefix, &bounds);
}
ast::TyKind::ImplTrait(_, ref bounds) => {
self.print_type_bounds("impl", &bounds[..]);
self.print_type_bounds("impl", &bounds);
}
ast::TyKind::Array(ref ty, ref length) => {
self.word("[");
Expand Down Expand Up @@ -1339,7 +1339,7 @@ impl<'a> State<'a> {
real_bounds.push(b.clone());
}
}
self.print_type_bounds(":", &real_bounds[..]);
self.print_type_bounds(":", &real_bounds);
self.print_where_clause(&generics.where_clause);
self.word(" ");
self.bopen();
Expand Down Expand Up @@ -1368,7 +1368,7 @@ impl<'a> State<'a> {
}
}
self.nbsp();
self.print_type_bounds("=", &real_bounds[..]);
self.print_type_bounds("=", &real_bounds);
self.print_where_clause(&generics.where_clause);
self.word(";");
}
Expand Down Expand Up @@ -1960,10 +1960,10 @@ impl<'a> State<'a> {
self.print_expr_tup(exprs);
}
ast::ExprKind::Call(ref func, ref args) => {
self.print_expr_call(func, &args[..]);
self.print_expr_call(func, &args);
}
ast::ExprKind::MethodCall(ref segment, ref args, _) => {
self.print_expr_method_call(segment, &args[..]);
self.print_expr_method_call(segment, &args);
}
ast::ExprKind::Binary(op, ref lhs, ref rhs) => {
self.print_expr_binary(op, lhs, rhs);
Expand Down Expand Up @@ -2440,11 +2440,11 @@ impl<'a> State<'a> {
self.print_path(path, true, 0);
}
self.popen();
self.commasep(Inconsistent, &elts[..], |s, p| s.print_pat(p));
self.commasep(Inconsistent, &elts, |s, p| s.print_pat(p));
self.pclose();
}
PatKind::Or(ref pats) => {
self.strsep("|", true, Inconsistent, &pats[..], |s, p| s.print_pat(p));
self.strsep("|", true, Inconsistent, &pats, |s, p| s.print_pat(p));
}
PatKind::Path(None, ref path) => {
self.print_path(path, true, 0);
Expand All @@ -2462,7 +2462,7 @@ impl<'a> State<'a> {
self.word_space("{");
self.commasep_cmnt(
Consistent,
&fields[..],
&fields,
|s, f| {
s.cbox(INDENT_UNIT);
if !f.is_shorthand {
Expand All @@ -2485,7 +2485,7 @@ impl<'a> State<'a> {
}
PatKind::Tuple(ref elts) => {
self.popen();
self.commasep(Inconsistent, &elts[..], |s, p| s.print_pat(p));
self.commasep(Inconsistent, &elts, |s, p| s.print_pat(p));
if elts.len() == 1 {
self.word(",");
}
Expand Down Expand Up @@ -2527,7 +2527,7 @@ impl<'a> State<'a> {
}
PatKind::Slice(ref elts) => {
self.word("[");
self.commasep(Inconsistent, &elts[..], |s, p| s.print_pat(p));
self.commasep(Inconsistent, &elts, |s, p| s.print_pat(p));
self.word("]");
}
PatKind::Rest => self.word(".."),
Expand Down Expand Up @@ -2836,7 +2836,7 @@ impl<'a> State<'a> {
self.print_path(&tree.prefix, false, 0);
self.word("::{");
}
self.commasep(Inconsistent, &items[..], |this, &(ref tree, _)| {
self.commasep(Inconsistent, &items, |this, &(ref tree, _)| {
this.print_use_tree(tree)
});
self.word("}");
Expand Down
89 changes: 87 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ use rustc_span::symbol::sym;
use rustc_span::{BytePos, MultiSpan, Span, DUMMY_SP};
use rustc_trait_selection::infer::InferCtxtExt;

use crate::borrow_set::TwoPhaseActivation;
use crate::borrowck_errors;

use crate::diagnostics::find_all_local_uses;
use crate::{
borrow_set::BorrowData, diagnostics::Instance, prefixes::IsPrefixOf,
InitializationRequiringAction, MirBorrowckCtxt, PrefixSet, WriteKind,
};

use super::{
explain_borrow::BorrowExplanation, FnSelfUseKind, IncludingDowncast, RegionName,
RegionNameSource, UseSpans,
explain_borrow::{BorrowExplanation, LaterUseKind},
FnSelfUseKind, IncludingDowncast, RegionName, RegionNameSource, UseSpans,
};

#[derive(Debug)]
Expand Down Expand Up @@ -768,9 +770,92 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
Some((issued_span, span)),
);

self.suggest_using_local_if_applicable(
&mut err,
location,
(place, span),
gen_borrow_kind,
issued_borrow,
explanation,
);

err
}

#[instrument(level = "debug", skip(self, err))]
fn suggest_using_local_if_applicable(
&self,
err: &mut DiagnosticBuilder<'_>,
location: Location,
(place, span): (Place<'tcx>, Span),
gen_borrow_kind: BorrowKind,
issued_borrow: &BorrowData<'tcx>,
explanation: BorrowExplanation,
) {
let used_in_call =
matches!(explanation, BorrowExplanation::UsedLater(LaterUseKind::Call, _call_span, _));
if !used_in_call {
debug!("not later used in call");
return;
}

let outer_call_loc =
if let TwoPhaseActivation::ActivatedAt(loc) = issued_borrow.activation_location {
loc
} else {
issued_borrow.reserve_location
};
let outer_call_stmt = self.body.stmt_at(outer_call_loc);

let inner_param_location = location;
let Some(inner_param_stmt) = self.body.stmt_at(inner_param_location).left() else {
debug!("`inner_param_location` {:?} is not for a statement", inner_param_location);
return;
};
let Some(&inner_param) = inner_param_stmt.kind.as_assign().map(|(p, _)| p) else {
debug!(
"`inner_param_location` {:?} is not for an assignment: {:?}",
inner_param_location, inner_param_stmt
);
return;
};
let inner_param_uses = find_all_local_uses::find(self.body, inner_param.local);
let Some((inner_call_loc,inner_call_term)) = inner_param_uses.into_iter().find_map(|loc| {
let Either::Right(term) = self.body.stmt_at(loc) else {
debug!("{:?} is a statement, so it can't be a call", loc);
return None;
};
let TerminatorKind::Call { args, .. } = &term.kind else {
debug!("not a call: {:?}", term);
return None;
};
debug!("checking call args for uses of inner_param: {:?}", args);
if args.contains(&Operand::Move(inner_param)) {
Some((loc,term))
} else {
None
}
}) else {
debug!("no uses of inner_param found as a by-move call arg");
return;
};
debug!("===> outer_call_loc = {:?}, inner_call_loc = {:?}", outer_call_loc, inner_call_loc);

let inner_call_span = inner_call_term.source_info.span;
let outer_call_span = outer_call_stmt.either(|s| s.source_info, |t| t.source_info).span;
if outer_call_span == inner_call_span || !outer_call_span.contains(inner_call_span) {
// FIXME: This stops the suggestion in some cases where it should be emitted.
// Fix the spans for those cases so it's emitted correctly.
debug!(
"outer span {:?} does not strictly contain inner span {:?}",
outer_call_span, inner_call_span
);
return;
}
err.span_help(inner_call_span, "try adding a local storing this argument...");
err.span_help(outer_call_span, "...and then using that local as the argument to this call");
}

fn suggest_split_at_mut_if_applicable(
&self,
err: &mut DiagnosticBuilder<'_>,
Expand Down
26 changes: 26 additions & 0 deletions compiler/rustc_borrowck/src/diagnostics/find_all_local_uses.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::collections::BTreeSet;

use rustc_middle::mir::visit::{PlaceContext, Visitor};
use rustc_middle::mir::{Body, Local, Location};

/// Find all uses of (including assignments to) a [`Local`].
///
/// Uses `BTreeSet` so output is deterministic.
pub(super) fn find<'tcx>(body: &Body<'tcx>, local: Local) -> BTreeSet<Location> {
let mut visitor = AllLocalUsesVisitor { for_local: local, uses: BTreeSet::default() };
visitor.visit_body(body);
visitor.uses
}

struct AllLocalUsesVisitor {
for_local: Local,
uses: BTreeSet<Location>,
}

impl<'tcx> Visitor<'tcx> for AllLocalUsesVisitor {
fn visit_local(&mut self, local: &Local, _context: PlaceContext, location: Location) {
if *local == self.for_local {
self.uses.insert(location);
}
}
}
1 change: 1 addition & 0 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use rustc_target::abi::VariantIdx;
use super::borrow_set::BorrowData;
use super::MirBorrowckCtxt;

mod find_all_local_uses;
mod find_use;
mod outlives_suggestion;
mod region_name;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
Some(&idx) => Some(idx),
None => {
let msg = format!("there is no argument named `{}`", name);
ecx.struct_span_err(span, &msg[..]).emit();
ecx.struct_span_err(span, &msg).emit();
None
}
},
Expand Down
20 changes: 10 additions & 10 deletions compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,17 +766,17 @@ impl<'a> TraitDef<'a> {
self,
struct_def,
type_ident,
&self_args[..],
&nonself_args[..],
&self_args,
&nonself_args,
)
} else {
method_def.expand_struct_method_body(
cx,
self,
struct_def,
type_ident,
&self_args[..],
&nonself_args[..],
&self_args,
&nonself_args,
use_temporaries,
)
};
Expand Down Expand Up @@ -815,8 +815,8 @@ impl<'a> TraitDef<'a> {
self,
enum_def,
type_ident,
&self_args[..],
&nonself_args[..],
&self_args,
&nonself_args,
)
} else {
method_def.expand_enum_method_body(
Expand All @@ -825,7 +825,7 @@ impl<'a> TraitDef<'a> {
enum_def,
type_ident,
self_args,
&nonself_args[..],
&nonself_args,
)
};

Expand Down Expand Up @@ -1217,7 +1217,7 @@ impl<'a> MethodDef<'a> {
let vi_idents = self_arg_names
.iter()
.map(|name| {
let vi_suffix = format!("{}_vi", &name[..]);
let vi_suffix = format!("{}_vi", name);
Ident::from_str_and_span(&vi_suffix, span)
})
.collect::<Vec<Ident>>();
Expand All @@ -1226,7 +1226,7 @@ impl<'a> MethodDef<'a> {
// delegated expression that handles the catch-all case,
// using `__variants_tuple` to drive logic if necessary.
let catch_all_substructure =
EnumNonMatchingCollapsed(self_arg_idents, &variants[..], &vi_idents[..]);
EnumNonMatchingCollapsed(self_arg_idents, &variants, &vi_idents);

let first_fieldless = variants.iter().find(|v| v.data.fields().is_empty());

Expand Down Expand Up @@ -1261,7 +1261,7 @@ impl<'a> MethodDef<'a> {
idents
};
for self_arg_name in &self_arg_names[1..] {
let (p, idents) = mk_self_pat(cx, &self_arg_name[..]);
let (p, idents) = mk_self_pat(cx, &self_arg_name);
subpats.push(p);
self_pats_idents.push(idents);
}
Expand Down
Loading