Skip to content

Commit f7534b5

Browse files
committed
Auto merge of rust-lang#81952 - JohnTitor:rollup-i28kgfb, r=JohnTitor
Rollup of 11 pull requests Successful merges: - rust-lang#79849 (Clarify docs regarding sleep of zero duration) - rust-lang#80438 (Add `Box::into_inner`.) - rust-lang#81466 (Add suggest mut method for loop) - rust-lang#81687 (Make Vec::split_at_spare_mut public) - rust-lang#81904 (Bump stabilization version for const int methods) - rust-lang#81909 ([compiler/rustc_typeck/src/check/expr.rs] Remove unnecessary refs in pattern matching) - rust-lang#81910 (Use format string in bootstrap panic instead of a string directly) - rust-lang#81913 (Rename HIR UnOp variants) - rust-lang#81925 (Add long explanation for E0547) - rust-lang#81926 (add suggestion to use the `async_recursion` crate) - rust-lang#81951 (Update cargo) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents ca98712 + 77114af commit f7534b5

Some content is hidden

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

58 files changed

+387
-160
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
260260

261261
fn lower_unop(&mut self, u: UnOp) -> hir::UnOp {
262262
match u {
263-
UnOp::Deref => hir::UnOp::UnDeref,
264-
UnOp::Not => hir::UnOp::UnNot,
265-
UnOp::Neg => hir::UnOp::UnNeg,
263+
UnOp::Deref => hir::UnOp::Deref,
264+
UnOp::Not => hir::UnOp::Not,
265+
UnOp::Neg => hir::UnOp::Neg,
266266
}
267267
}
268268

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ E0539: include_str!("./error_codes/E0539.md"),
287287
E0541: include_str!("./error_codes/E0541.md"),
288288
E0542: include_str!("./error_codes/E0542.md"),
289289
E0546: include_str!("./error_codes/E0546.md"),
290+
E0547: include_str!("./error_codes/E0547.md"),
290291
E0550: include_str!("./error_codes/E0550.md"),
291292
E0551: include_str!("./error_codes/E0551.md"),
292293
E0552: include_str!("./error_codes/E0552.md"),
@@ -606,7 +607,6 @@ E0781: include_str!("./error_codes/E0781.md"),
606607
E0543, // missing 'reason'
607608
E0544, // multiple stability levels
608609
E0545, // incorrect 'issue'
609-
E0547, // missing 'issue'
610610
// E0548, // replaced with a generic attribute input check
611611
// rustc_deprecated attribute must be paired with either stable or unstable
612612
// attribute
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
The `issue` value is missing in a stability attribute.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0547
6+
#![feature(staged_api)]
7+
#![stable(since = "1.0.0", feature = "test")]
8+
9+
#[unstable(feature = "_unstable_fn")] // invalid
10+
fn _unstable_fn() {}
11+
12+
#[rustc_const_unstable(feature = "_unstable_const_fn")] // invalid
13+
fn _unstable_const_fn() {}
14+
```
15+
16+
To fix this issue, you need to provide the `issue` field. Example:
17+
18+
```
19+
#![feature(staged_api)]
20+
#![stable(since = "1.0.0", feature = "test")]
21+
22+
#[unstable(feature = "_unstable_fn", issue = "none")] // ok!
23+
fn _unstable_fn() {}
24+
25+
#[rustc_const_unstable(
26+
feature = "_unstable_const_fn",
27+
issue = "none"
28+
)] // ok!
29+
fn _unstable_const_fn() {}
30+
```
31+
32+
See the [How Rust is Made and “Nightly Rust”][how-rust-made-nightly] appendix
33+
of the Book and the [Stability attributes][stability-attributes] section of the
34+
Rustc Dev Guide for more details.
35+
36+
[how-rust-made-nightly]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
37+
[stability-attributes]: https://rustc-dev-guide.rust-lang.org/stability.html

compiler/rustc_hir/src/hir.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1112,25 +1112,25 @@ pub type BinOp = Spanned<BinOpKind>;
11121112
#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)]
11131113
pub enum UnOp {
11141114
/// The `*` operator (deferencing).
1115-
UnDeref,
1115+
Deref,
11161116
/// The `!` operator (logical negation).
1117-
UnNot,
1117+
Not,
11181118
/// The `-` operator (negation).
1119-
UnNeg,
1119+
Neg,
11201120
}
11211121

11221122
impl UnOp {
11231123
pub fn as_str(self) -> &'static str {
11241124
match self {
1125-
Self::UnDeref => "*",
1126-
Self::UnNot => "!",
1127-
Self::UnNeg => "-",
1125+
Self::Deref => "*",
1126+
Self::Not => "!",
1127+
Self::Neg => "-",
11281128
}
11291129
}
11301130

11311131
/// Returns `true` if the unary operator takes its argument by value.
11321132
pub fn is_by_value(self) -> bool {
1133-
matches!(self, Self::UnNeg | Self::UnNot)
1133+
matches!(self, Self::Neg | Self::Not)
11341134
}
11351135
}
11361136

@@ -1477,7 +1477,7 @@ impl Expr<'_> {
14771477
// https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md#type-ascription-and-temporaries
14781478
ExprKind::Type(ref e, _) => e.is_place_expr(allow_projections_from),
14791479

1480-
ExprKind::Unary(UnOp::UnDeref, _) => true,
1480+
ExprKind::Unary(UnOp::Deref, _) => true,
14811481

14821482
ExprKind::Field(ref base, _) | ExprKind::Index(ref base, _) => {
14831483
allow_projections_from(base) || base.is_place_expr(allow_projections_from)

compiler/rustc_lint/src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ fn lint_literal<'tcx>(
472472
impl<'tcx> LateLintPass<'tcx> for TypeLimits {
473473
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx hir::Expr<'tcx>) {
474474
match e.kind {
475-
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref expr) => {
475+
hir::ExprKind::Unary(hir::UnOp::Neg, ref expr) => {
476476
// propagate negation, if the negation itself isn't negated
477477
if self.negated_expr_id != Some(e.hir_id) {
478478
self.negated_expr_id = Some(expr.hir_id);

compiler/rustc_middle/src/ty/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<'tcx> Const<'tcx> {
5555

5656
let lit_input = match expr.kind {
5757
hir::ExprKind::Lit(ref lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: false }),
58-
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref expr) => match expr.kind {
58+
hir::ExprKind::Unary(hir::UnOp::Neg, ref expr) => match expr.kind {
5959
hir::ExprKind::Lit(ref lit) => {
6060
Some(LitToConstInput { lit: &lit.node, ty, neg: true })
6161
}

compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs

+85-9
Original file line numberDiff line numberDiff line change
@@ -376,15 +376,18 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
376376
opt_assignment_rhs_span.and_then(|span| span.desugaring_kind());
377377
match opt_desugaring_kind {
378378
// on for loops, RHS points to the iterator part
379-
Some(DesugaringKind::ForLoop(_)) => Some((
380-
false,
381-
opt_assignment_rhs_span.unwrap(),
382-
format!(
383-
"this iterator yields `{SIGIL}` {DESC}s",
384-
SIGIL = pointer_sigil,
385-
DESC = pointer_desc
386-
),
387-
)),
379+
Some(DesugaringKind::ForLoop(_)) => {
380+
self.suggest_similar_mut_method_for_for_loop(&mut err);
381+
Some((
382+
false,
383+
opt_assignment_rhs_span.unwrap(),
384+
format!(
385+
"this iterator yields `{SIGIL}` {DESC}s",
386+
SIGIL = pointer_sigil,
387+
DESC = pointer_desc
388+
),
389+
))
390+
}
388391
// don't create labels for compiler-generated spans
389392
Some(_) => None,
390393
None => {
@@ -537,6 +540,79 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
537540
);
538541
}
539542

543+
// Attempt to search similar mutable assosiated items for suggestion.
544+
// In the future, attempt in all path but initially for RHS of for_loop
545+
fn suggest_similar_mut_method_for_for_loop(&self, err: &mut DiagnosticBuilder<'_>) {
546+
let hir = self.infcx.tcx.hir();
547+
let node = hir.item(self.mir_hir_id());
548+
use hir::{
549+
Expr,
550+
ExprKind::{Block, Call, DropTemps, Match, MethodCall},
551+
};
552+
if let hir::ItemKind::Fn(_, _, body_id) = node.kind {
553+
if let Block(
554+
hir::Block {
555+
expr:
556+
Some(Expr {
557+
kind:
558+
DropTemps(Expr {
559+
kind:
560+
Match(
561+
Expr {
562+
kind:
563+
Call(
564+
_,
565+
[Expr {
566+
kind: MethodCall(path_segment, ..),
567+
hir_id,
568+
..
569+
}, ..],
570+
),
571+
..
572+
},
573+
..,
574+
),
575+
..
576+
}),
577+
..
578+
}),
579+
..
580+
},
581+
_,
582+
) = hir.body(body_id).value.kind
583+
{
584+
let opt_suggestions = path_segment
585+
.hir_id
586+
.map(|path_hir_id| self.infcx.tcx.typeck(path_hir_id.owner))
587+
.and_then(|typeck| typeck.type_dependent_def_id(*hir_id))
588+
.and_then(|def_id| self.infcx.tcx.impl_of_method(def_id))
589+
.map(|def_id| self.infcx.tcx.associated_items(def_id))
590+
.map(|assoc_items| {
591+
assoc_items
592+
.in_definition_order()
593+
.map(|assoc_item_def| assoc_item_def.ident)
594+
.filter(|&ident| {
595+
let original_method_ident = path_segment.ident;
596+
original_method_ident != ident
597+
&& ident
598+
.as_str()
599+
.starts_with(&original_method_ident.name.to_string())
600+
})
601+
.map(|ident| format!("{}()", ident))
602+
});
603+
604+
if let Some(suggestions) = opt_suggestions {
605+
err.span_suggestions(
606+
path_segment.ident.span,
607+
&format!("use mutable method"),
608+
suggestions,
609+
Applicability::MaybeIncorrect,
610+
);
611+
}
612+
}
613+
};
614+
}
615+
540616
/// Targeted error when encountering an `FnMut` closure where an `Fn` closure was expected.
541617
fn expected_fn_found_fn_mut_call(&self, err: &mut DiagnosticBuilder<'_>, sp: Span, act: &str) {
542618
err.span_label(sp, format!("cannot {}", act));

compiler/rustc_mir_build/src/thir/cx/expr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -299,23 +299,23 @@ fn make_mirror_unadjusted<'a, 'tcx>(
299299
}
300300
}
301301

302-
hir::ExprKind::Unary(hir::UnOp::UnDeref, ref arg) => {
302+
hir::ExprKind::Unary(hir::UnOp::Deref, ref arg) => {
303303
if cx.typeck_results().is_method_call(expr) {
304304
overloaded_place(cx, expr, expr_ty, None, vec![arg.to_ref()], expr.span)
305305
} else {
306306
ExprKind::Deref { arg: arg.to_ref() }
307307
}
308308
}
309309

310-
hir::ExprKind::Unary(hir::UnOp::UnNot, ref arg) => {
310+
hir::ExprKind::Unary(hir::UnOp::Not, ref arg) => {
311311
if cx.typeck_results().is_method_call(expr) {
312312
overloaded_operator(cx, expr, vec![arg.to_ref()])
313313
} else {
314314
ExprKind::Unary { op: UnOp::Not, arg: arg.to_ref() }
315315
}
316316
}
317317

318-
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref arg) => {
318+
hir::ExprKind::Unary(hir::UnOp::Neg, ref arg) => {
319319
if cx.typeck_results().is_method_call(expr) {
320320
overloaded_operator(cx, expr, vec![arg.to_ref()])
321321
} else if let hir::ExprKind::Lit(ref lit) = arg.kind {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
866866
return *self.const_to_pat(value, expr.hir_id, expr.span, false).kind;
867867
}
868868
hir::ExprKind::Lit(ref lit) => (lit, false),
869-
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref expr) => {
869+
hir::ExprKind::Unary(hir::UnOp::Neg, ref expr) => {
870870
let lit = match expr.kind {
871871
hir::ExprKind::Lit(ref lit) => lit,
872872
_ => span_bug!(expr.span, "not a literal: {:?}", expr),

compiler/rustc_passes/src/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ fn resolve_local<'tcx>(
664664

665665
match expr.kind {
666666
hir::ExprKind::AddrOf(_, _, ref subexpr)
667-
| hir::ExprKind::Unary(hir::UnOp::UnDeref, ref subexpr)
667+
| hir::ExprKind::Unary(hir::UnOp::Deref, ref subexpr)
668668
| hir::ExprKind::Field(ref subexpr, _)
669669
| hir::ExprKind::Index(ref subexpr, _) => {
670670
expr = &subexpr;

compiler/rustc_typeck/src/check/check.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,9 @@ fn async_opaque_type_cycle_error(tcx: TyCtxt<'tcx>, span: Span) {
15051505
struct_span_err!(tcx.sess, span, E0733, "recursion in an `async fn` requires boxing")
15061506
.span_label(span, "recursive `async fn`")
15071507
.note("a recursive `async fn` must be rewritten to return a boxed `dyn Future`")
1508+
.note(
1509+
"consider using the `async_recursion` crate: https://crates.io/crates/async_recursion",
1510+
)
15081511
.emit();
15091512
}
15101513

compiler/rustc_typeck/src/check/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
773773
if let hir::ExprKind::Lit(lit) = &expr.kind { lit.node.is_suffixed() } else { false }
774774
};
775775
let is_negative_int =
776-
|expr: &hir::Expr<'_>| matches!(expr.kind, hir::ExprKind::Unary(hir::UnOp::UnNeg, ..));
776+
|expr: &hir::Expr<'_>| matches!(expr.kind, hir::ExprKind::Unary(hir::UnOp::Neg, ..));
777777
let is_uint = |ty: Ty<'_>| matches!(ty.kind(), ty::Uint(..));
778778

779779
let in_const_context = self.tcx.hir().is_inside_const_context(expr.hir_id);

0 commit comments

Comments
 (0)