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 14 pull requests #90161

Merged
merged 38 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
729ff2d
Give better error for `macro_rules name`
aDotInTheVoid Sep 25, 2021
1bb399c
Ensure that pushing empty path works as before
seanyoung Oct 8, 2021
bd1a1e4
Don't mark for loop head span with desugaring
camsteffen Oct 14, 2021
a697aa6
Use more lowered spans in for loop
camsteffen Oct 15, 2021
ffdd5a0
Fix clippy with for loop span change
camsteffen Oct 14, 2021
4333091
Update E0637 description to mention `&` w/o an explicit lifetime name
JohnTitor Oct 15, 2021
d2470e7
rustc_ast: Turn `MutVisitor::token_visiting_enabled` into a constant
petrochenkov Oct 17, 2021
7581bae
Fix const qualification when executed after promotion
tmiasko Oct 19, 2021
c97cf7f
Reject closures in patterns
tmiasko Oct 18, 2021
21d02bf
Add a regression test for issue-83479
JohnTitor Oct 20, 2021
396a4f4
Increase `ROOT_ENTRY_LIMIT` to 1331
JohnTitor Oct 20, 2021
fe060bf
Change `Duration::from_secs_*` underflow error
mbartlett21 Oct 16, 2021
6469fba
Trait objects
BoxyUwU Oct 20, 2021
a81e489
Return pos impl trait
BoxyUwU Oct 20, 2021
83a1834
Wfness
BoxyUwU Oct 20, 2021
8f23779
Inference
BoxyUwU Oct 20, 2021
7a8bd2d
add fixme
BoxyUwU Oct 20, 2021
c75d8cb
Ordering
BoxyUwU Oct 20, 2021
e7a9e82
*dust dust*
BoxyUwU Oct 20, 2021
74c6636
Verify that only NeedsNonConstDrop expects promoteds
tmiasko Oct 21, 2021
ab44e46
Add test for issue #78561
samlich Oct 20, 2021
d50832b
triagebot: Treat `I-*nominated` like `I-nominated`
joshtriplett Oct 21, 2021
04c1ec5
Clarify undefined behaviour for binary heap, btree and hashset
Wilfred Jul 28, 2021
0dba9d0
Stabilize feature saturating_div for rust 1.58
kellerkindt Oct 21, 2021
d91e9b7
Rollup merge of #87537 - Wilfred:improve-min-heap-docs, r=Mark-Simula…
JohnTitor Oct 22, 2021
918f9cc
Rollup merge of #88624 - kellerkindt:master, r=JohnTitor
JohnTitor Oct 22, 2021
8738d5d
Rollup merge of #89257 - aDotInTheVoid:macro-error-2, r=estebank
JohnTitor Oct 22, 2021
62da4ab
Rollup merge of #89665 - seanyoung:push-empty, r=m-ou-se
JohnTitor Oct 22, 2021
91fb223
Rollup merge of #89895 - camsteffen:for-loop-head-span, r=davidtwco
JohnTitor Oct 22, 2021
327d807
Rollup merge of #89922 - JohnTitor:update-e0637, r=jackh726
JohnTitor Oct 22, 2021
8b7adf6
Rollup merge of #89944 - mbartlett21:patch-2, r=Mark-Simulacrum
JohnTitor Oct 22, 2021
cbebdd8
Rollup merge of #89991 - petrochenkov:visitok2, r=jackh726
JohnTitor Oct 22, 2021
9ed9025
Rollup merge of #90028 - tmiasko:structural-match-closure, r=spastorino
JohnTitor Oct 22, 2021
a656bc5
Rollup merge of #90069 - tmiasko:promoted-const-qualif, r=oli-obk
JohnTitor Oct 22, 2021
de306d7
Rollup merge of #90078 - JohnTitor:test-83479, r=Mark-Simulacrum
JohnTitor Oct 22, 2021
49f2384
Rollup merge of #90114 - BoxyUwU:cg_defaults_tests, r=lcnr
JohnTitor Oct 22, 2021
a741f68
Rollup merge of #90115 - samlich:test-issue-78561, r=oli-obk
JohnTitor Oct 22, 2021
ea8a896
Rollup merge of #90129 - joshtriplett:triagebot-nominated, r=Mark-Sim…
JohnTitor Oct 22, 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
12 changes: 5 additions & 7 deletions compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ pub trait MutVisitor: Sized {
/// Mutable token visiting only exists for the `macro_rules` token marker and should not be
/// used otherwise. Token visitor would be entirely separate from the regular visitor if
/// the marker didn't have to visit AST fragments in nonterminal tokens.
fn token_visiting_enabled(&self) -> bool {
false
}
const VISIT_TOKENS: bool = false;

// Methods in this trait have one of three forms:
//
Expand Down Expand Up @@ -363,7 +361,7 @@ pub fn visit_mac_args<T: MutVisitor>(args: &mut MacArgs, vis: &mut T) {
}
MacArgs::Eq(eq_span, token) => {
vis.visit_span(eq_span);
if vis.token_visiting_enabled() {
if T::VISIT_TOKENS {
visit_token(token, vis);
} else {
// The value in `#[key = VALUE]` must be visited as an expression for backward
Expand Down Expand Up @@ -682,7 +680,7 @@ pub fn visit_tt<T: MutVisitor>(tt: &mut TokenTree, vis: &mut T) {

// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
pub fn visit_tts<T: MutVisitor>(TokenStream(tts): &mut TokenStream, vis: &mut T) {
if vis.token_visiting_enabled() && !tts.is_empty() {
if T::VISIT_TOKENS && !tts.is_empty() {
let tts = Lrc::make_mut(tts);
visit_vec(tts, |(tree, _is_joint)| visit_tt(tree, vis));
}
Expand All @@ -692,14 +690,14 @@ pub fn visit_attr_annotated_tts<T: MutVisitor>(
AttrAnnotatedTokenStream(tts): &mut AttrAnnotatedTokenStream,
vis: &mut T,
) {
if vis.token_visiting_enabled() && !tts.is_empty() {
if T::VISIT_TOKENS && !tts.is_empty() {
let tts = Lrc::make_mut(tts);
visit_vec(tts, |(tree, _is_joint)| visit_attr_annotated_tt(tree, vis));
}
}

pub fn visit_lazy_tts_opt_mut<T: MutVisitor>(lazy_tts: Option<&mut LazyTokenStream>, vis: &mut T) {
if vis.token_visiting_enabled() {
if T::VISIT_TOKENS {
if let Some(lazy_tts) = lazy_tts {
let mut tts = lazy_tts.create_token_stream();
visit_attr_annotated_tts(&mut tts, vis);
Expand Down
39 changes: 18 additions & 21 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1332,15 +1332,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
body: &Block,
opt_label: Option<Label>,
) -> hir::Expr<'hir> {
let orig_head_span = head.span;
// expand <head>
let mut head = self.lower_expr_mut(head);
let desugared_span = self.mark_span_with_reason(
DesugaringKind::ForLoop(ForLoopLoc::Head),
orig_head_span,
None,
);
head.span = self.lower_span(desugared_span);
let head = self.lower_expr_mut(head);
let desugared_span =
self.mark_span_with_reason(DesugaringKind::ForLoop(ForLoopLoc::Head), head.span, None);
let e_span = self.lower_span(e.span);

let iter = Ident::with_dummy_span(sym::iter);

Expand All @@ -1354,23 +1350,24 @@ impl<'hir> LoweringContext<'_, 'hir> {
// `::std::option::Option::Some(val) => __next = val`
let pat_arm = {
let val_ident = Ident::with_dummy_span(sym::val);
let (val_pat, val_pat_hid) = self.pat_ident(pat.span, val_ident);
let val_expr = self.expr_ident(pat.span, val_ident, val_pat_hid);
let next_expr = self.expr_ident(pat.span, next_ident, next_pat_hid);
let pat_span = self.lower_span(pat.span);
let (val_pat, val_pat_hid) = self.pat_ident(pat_span, val_ident);
let val_expr = self.expr_ident(pat_span, val_ident, val_pat_hid);
let next_expr = self.expr_ident(pat_span, next_ident, next_pat_hid);
let assign = self.arena.alloc(self.expr(
pat.span,
hir::ExprKind::Assign(next_expr, val_expr, self.lower_span(pat.span)),
pat_span,
hir::ExprKind::Assign(next_expr, val_expr, self.lower_span(pat_span)),
ThinVec::new(),
));
let some_pat = self.pat_some(pat.span, val_pat);
let some_pat = self.pat_some(pat_span, val_pat);
self.arm(some_pat, assign)
};

// `::std::option::Option::None => break`
let break_arm = {
let break_expr =
self.with_loop_scope(e.id, |this| this.expr_break_alloc(e.span, ThinVec::new()));
let pat = self.pat_none(e.span);
self.with_loop_scope(e.id, |this| this.expr_break_alloc(e_span, ThinVec::new()));
let pat = self.pat_none(e_span);
self.arm(pat, break_expr)
};

Expand Down Expand Up @@ -1416,10 +1413,10 @@ impl<'hir> LoweringContext<'_, 'hir> {

let body_block = self.with_loop_scope(e.id, |this| this.lower_block(body, false));
let body_expr = self.expr_block(body_block, ThinVec::new());
let body_stmt = self.stmt_expr(body.span, body_expr);
let body_stmt = self.stmt_expr(body_block.span, body_expr);

let loop_block = self.block_all(
e.span,
e_span,
arena_vec![self; next_let, match_stmt, pat_let, body_stmt],
None,
);
Expand All @@ -1429,7 +1426,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
loop_block,
self.lower_label(opt_label),
hir::LoopSource::ForLoop,
self.lower_span(e.span.with_hi(orig_head_span.hi())),
self.lower_span(e_span.with_hi(head.span.hi())),
);
let loop_expr = self.arena.alloc(hir::Expr {
hir_id: self.lower_node_id(e.id),
Expand All @@ -1442,7 +1439,7 @@ impl<'hir> LoweringContext<'_, 'hir> {

let into_iter_span = self.mark_span_with_reason(
DesugaringKind::ForLoop(ForLoopLoc::IntoIter),
orig_head_span,
head.span,
None,
);

Expand All @@ -1458,7 +1455,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// #82462: to correctly diagnose borrow errors, the block that contains
// the iter expr needs to have a span that covers the loop body.
let desugared_full_span =
self.mark_span_with_reason(DesugaringKind::ForLoop(ForLoopLoc::Head), e.span, None);
self.mark_span_with_reason(DesugaringKind::ForLoop(ForLoopLoc::Head), e_span, None);

let match_expr = self.arena.alloc(self.expr_match(
desugared_full_span,
Expand Down
60 changes: 30 additions & 30 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use rustc_middle::mir::{
};
use rustc_middle::ty::{self, suggest_constraining_type_param, Ty};
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
use rustc_span::source_map::DesugaringKind;
use rustc_span::symbol::sym;
use rustc_span::{BytePos, MultiSpan, Span, DUMMY_SP};
use rustc_trait_selection::infer::InferCtxtExt;
Expand Down Expand Up @@ -247,6 +246,36 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
place_name, partially_str, loop_message
),
);
let sess = self.infcx.tcx.sess;
let ty = used_place.ty(self.body, self.infcx.tcx).ty;
// If we have a `&mut` ref, we need to reborrow.
if let ty::Ref(_, _, hir::Mutability::Mut) = ty.kind() {
// If we are in a loop this will be suggested later.
if !is_loop_move {
err.span_suggestion_verbose(
move_span.shrink_to_lo(),
&format!(
"consider creating a fresh reborrow of {} here",
self.describe_place(moved_place.as_ref())
.map(|n| format!("`{}`", n))
.unwrap_or_else(
|| "the mutable reference".to_string()
),
),
"&mut *".to_string(),
Applicability::MachineApplicable,
);
}
} else if let Ok(snippet) =
sess.source_map().span_to_snippet(move_span)
{
err.span_suggestion(
move_span,
"consider borrowing to avoid moving into the for loop",
format!("&{}", snippet),
Applicability::MaybeIncorrect,
);
}
} else {
err.span_label(
fn_call_span,
Expand Down Expand Up @@ -315,35 +344,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
in_pattern = true;
}
}

if let Some(DesugaringKind::ForLoop(_)) = move_span.desugaring_kind() {
let sess = self.infcx.tcx.sess;
let ty = used_place.ty(self.body, self.infcx.tcx).ty;
// If we have a `&mut` ref, we need to reborrow.
if let ty::Ref(_, _, hir::Mutability::Mut) = ty.kind() {
// If we are in a loop this will be suggested later.
if !is_loop_move {
err.span_suggestion_verbose(
move_span.shrink_to_lo(),
&format!(
"consider creating a fresh reborrow of {} here",
self.describe_place(moved_place.as_ref())
.map(|n| format!("`{}`", n))
.unwrap_or_else(|| "the mutable reference".to_string()),
),
"&mut *".to_string(),
Applicability::MachineApplicable,
);
}
} else if let Ok(snippet) = sess.source_map().span_to_snippet(move_span) {
err.span_suggestion(
move_span,
"consider borrowing to avoid moving into the for loop",
format!("&{}", snippet),
Applicability::MaybeIncorrect,
);
}
}
}

use_spans.var_span_label_path_only(
Expand Down
21 changes: 11 additions & 10 deletions compiler/rustc_borrowck/src/diagnostics/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ use rustc_middle::ty;
use rustc_mir_dataflow::move_paths::{
IllegalMoveOrigin, IllegalMoveOriginKind, LookupResult, MoveError, MovePathIndex,
};
use rustc_span::source_map::DesugaringKind;
use rustc_span::{sym, Span, DUMMY_SP};
use rustc_trait_selection::traits::type_known_to_meet_bound_modulo_regions;

use crate::diagnostics::UseSpans;
use crate::diagnostics::{FnSelfUseKind, UseSpans};
use crate::prefixes::PrefixSet;
use crate::MirBorrowckCtxt;

Expand Down Expand Up @@ -400,19 +399,21 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
| ty::Opaque(def_id, _) => def_id,
_ => return err,
};
let is_option = self.infcx.tcx.is_diagnostic_item(sym::Option, def_id);
let is_result = self.infcx.tcx.is_diagnostic_item(sym::Result, def_id);
if (is_option || is_result) && use_spans.map_or(true, |v| !v.for_closure()) {
let diag_name = self.infcx.tcx.get_diagnostic_name(def_id);
if matches!(diag_name, Some(sym::Option | sym::Result))
&& use_spans.map_or(true, |v| !v.for_closure())
{
err.span_suggestion_verbose(
span.shrink_to_hi(),
&format!(
"consider borrowing the `{}`'s content",
if is_option { "Option" } else { "Result" }
),
&format!("consider borrowing the `{}`'s content", diag_name.unwrap()),
".as_ref()".to_string(),
Applicability::MaybeIncorrect,
);
} else if matches!(span.desugaring_kind(), Some(DesugaringKind::ForLoop(_))) {
} else if let Some(UseSpans::FnSelfUse {
kind: FnSelfUseKind::Normal { implicit_into_iter: true, .. },
..
}) = use_spans
{
let suggest = match self.infcx.tcx.get_diagnostic_item(sym::IntoIterator) {
Some(def_id) => self.infcx.tcx.infer_ctxt().enter(|infcx| {
type_known_to_meet_bound_modulo_regions(
Expand Down
11 changes: 9 additions & 2 deletions compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ pub trait Qualif {
/// Whether this `Qualif` is cleared when a local is moved from.
const IS_CLEARED_ON_MOVE: bool = false;

/// Whether this `Qualif` might be evaluated after the promotion and can encounter a promoted.
const ALLOW_PROMOTED: bool = false;

/// Extracts the field of `ConstQualifs` that corresponds to this `Qualif`.
fn in_qualifs(qualifs: &ConstQualifs) -> bool;

Expand Down Expand Up @@ -129,6 +132,7 @@ pub struct NeedsNonConstDrop;
impl Qualif for NeedsNonConstDrop {
const ANALYSIS_NAME: &'static str = "flow_needs_nonconst_drop";
const IS_CLEARED_ON_MOVE: bool = true;
const ALLOW_PROMOTED: bool = true;

fn in_qualifs(qualifs: &ConstQualifs) -> bool {
qualifs.needs_non_const_drop
Expand Down Expand Up @@ -310,9 +314,12 @@ where
// Check the qualifs of the value of `const` items.
if let Some(ct) = constant.literal.const_for_ty() {
if let ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs_: _, promoted }) = ct.val {
assert!(promoted.is_none());
// Use qualifs of the type for the promoted. Promoteds in MIR body should be possible
// only for `NeedsNonConstDrop` with precise drop checking. This is the only const
// check performed after the promotion. Verify that with an assertion.
assert!(promoted.is_none() || Q::ALLOW_PROMOTED);
// Don't peek inside trait associated constants.
if cx.tcx.trait_of_item(def.did).is_none() {
if promoted.is_none() && cx.tcx.trait_of_item(def.did).is_none() {
let qualifs = if let Some((did, param_did)) = def.as_const_arg() {
cx.tcx.at(constant.span).mir_const_qualif_const_arg((did, param_did))
} else {
Expand Down
36 changes: 26 additions & 10 deletions compiler/rustc_error_codes/src/error_codes/E0637.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,51 @@
An underscore `_` character has been used as the identifier for a lifetime.
`'_` lifetime name or `&T` without an explicit lifetime name has been used
on illegal place.

Erroneous code example:

```compile_fail,E0106,E0637
fn longest<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {
//^^ `'_` is a reserved lifetime name
fn underscore_lifetime<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {
//^^ `'_` is a reserved lifetime name
if str1.len() > str2.len() {
str1
} else {
str2
}
}
fn and_without_explicit_lifetime<T>()
where
T: Into<&u32>,
//^ `&` without an explicit lifetime name
{
}
```

`'_`, cannot be used as a lifetime identifier because it is a reserved for the
anonymous lifetime. To fix this, use a lowercase letter such as 'a, or a series
of lowercase letters such as `'foo`. For more information, see [the
book][bk-no]. For more information on using the anonymous lifetime in rust
nightly, see [the nightly book][bk-al].
First, `'_` cannot be used as a lifetime identifier in some places
because it is a reserved for the anonymous lifetime. Second, `&T`
without an explicit lifetime name cannot also be used in some places.
To fix them, use a lowercase letter such as `'a`, or a series
of lowercase letters such as `'foo`. For more information about lifetime
identifier, see [the book][bk-no]. For more information on using
the anonymous lifetime in Rust 2018, see [the Rust 2018 blog post][blog-al].

Corrected example:

```
fn longest<'a>(str1: &'a str, str2: &'a str) -> &'a str {
fn underscore_lifetime<'a>(str1: &'a str, str2: &'a str) -> &'a str {
if str1.len() > str2.len() {
str1
} else {
str2
}
}
fn and_without_explicit_lifetime<'foo, T>()
where
T: Into<&'foo u32>,
{
}
```

[bk-no]: https://doc.rust-lang.org/book/appendix-02-operators.html#non-operator-symbols
[bk-al]: https://doc.rust-lang.org/nightly/edition-guide/rust-2018/ownership-and-lifetimes/the-anonymous-lifetime.html
[blog-al]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html#more-lifetime-elision-rules
4 changes: 1 addition & 3 deletions compiler/rustc_expand/src/mbe/transcribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ use std::mem;
struct Marker(LocalExpnId, Transparency);

impl MutVisitor for Marker {
fn token_visiting_enabled(&self) -> bool {
true
}
const VISIT_TOKENS: bool = true;

fn visit_span(&mut self, span: &mut Span) {
*span = span.apply_mark(self.0.to_expn_id(), self.1)
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_expand/src/mut_visit/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ fn print_crate_items(krate: &ast::Crate) -> String {
struct ToZzIdentMutVisitor;

impl MutVisitor for ToZzIdentMutVisitor {
fn token_visiting_enabled(&self) -> bool {
true
}
const VISIT_TOKENS: bool = true;

fn visit_ident(&mut self, ident: &mut Ident) {
*ident = Ident::from_str("zz");
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_lint/src/array_into_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,8 @@ impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
Applicability::MachineApplicable,
);
if self.for_expr_span == expr.span {
let expr_span = expr.span.ctxt().outer_expn_data().call_site;
diag.span_suggestion(
receiver_arg.span.shrink_to_hi().to(expr_span.shrink_to_hi()),
receiver_arg.span.shrink_to_hi().to(expr.span.shrink_to_hi()),
"or remove `.into_iter()` to iterate by value",
String::new(),
Applicability::MaybeIncorrect,
Expand Down
Loading