Skip to content

Commit

Permalink
Auto merge of rust-lang#81952 - JohnTitor:rollup-i28kgfb, r=JohnTitor
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Feb 10, 2021
2 parents ca98712 + 77114af commit f7534b5
Show file tree
Hide file tree
Showing 58 changed files with 387 additions and 160 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ impl<'hir> LoweringContext<'_, 'hir> {

fn lower_unop(&mut self, u: UnOp) -> hir::UnOp {
match u {
UnOp::Deref => hir::UnOp::UnDeref,
UnOp::Not => hir::UnOp::UnNot,
UnOp::Neg => hir::UnOp::UnNeg,
UnOp::Deref => hir::UnOp::Deref,
UnOp::Not => hir::UnOp::Not,
UnOp::Neg => hir::UnOp::Neg,
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ E0539: include_str!("./error_codes/E0539.md"),
E0541: include_str!("./error_codes/E0541.md"),
E0542: include_str!("./error_codes/E0542.md"),
E0546: include_str!("./error_codes/E0546.md"),
E0547: include_str!("./error_codes/E0547.md"),
E0550: include_str!("./error_codes/E0550.md"),
E0551: include_str!("./error_codes/E0551.md"),
E0552: include_str!("./error_codes/E0552.md"),
Expand Down Expand Up @@ -606,7 +607,6 @@ E0781: include_str!("./error_codes/E0781.md"),
E0543, // missing 'reason'
E0544, // multiple stability levels
E0545, // incorrect 'issue'
E0547, // missing 'issue'
// E0548, // replaced with a generic attribute input check
// rustc_deprecated attribute must be paired with either stable or unstable
// attribute
Expand Down
37 changes: 37 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0547.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
The `issue` value is missing in a stability attribute.

Erroneous code example:

```compile_fail,E0547
#![feature(staged_api)]
#![stable(since = "1.0.0", feature = "test")]
#[unstable(feature = "_unstable_fn")] // invalid
fn _unstable_fn() {}
#[rustc_const_unstable(feature = "_unstable_const_fn")] // invalid
fn _unstable_const_fn() {}
```

To fix this issue, you need to provide the `issue` field. Example:

```
#![feature(staged_api)]
#![stable(since = "1.0.0", feature = "test")]
#[unstable(feature = "_unstable_fn", issue = "none")] // ok!
fn _unstable_fn() {}
#[rustc_const_unstable(
feature = "_unstable_const_fn",
issue = "none"
)] // ok!
fn _unstable_const_fn() {}
```

See the [How Rust is Made and “Nightly Rust”][how-rust-made-nightly] appendix
of the Book and the [Stability attributes][stability-attributes] section of the
Rustc Dev Guide for more details.

[how-rust-made-nightly]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
[stability-attributes]: https://rustc-dev-guide.rust-lang.org/stability.html
16 changes: 8 additions & 8 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,25 +1112,25 @@ pub type BinOp = Spanned<BinOpKind>;
#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)]
pub enum UnOp {
/// The `*` operator (deferencing).
UnDeref,
Deref,
/// The `!` operator (logical negation).
UnNot,
Not,
/// The `-` operator (negation).
UnNeg,
Neg,
}

impl UnOp {
pub fn as_str(self) -> &'static str {
match self {
Self::UnDeref => "*",
Self::UnNot => "!",
Self::UnNeg => "-",
Self::Deref => "*",
Self::Not => "!",
Self::Neg => "-",
}
}

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

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

ExprKind::Unary(UnOp::UnDeref, _) => true,
ExprKind::Unary(UnOp::Deref, _) => true,

ExprKind::Field(ref base, _) | ExprKind::Index(ref base, _) => {
allow_projections_from(base) || base.is_place_expr(allow_projections_from)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ fn lint_literal<'tcx>(
impl<'tcx> LateLintPass<'tcx> for TypeLimits {
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx hir::Expr<'tcx>) {
match e.kind {
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref expr) => {
hir::ExprKind::Unary(hir::UnOp::Neg, ref expr) => {
// propagate negation, if the negation itself isn't negated
if self.negated_expr_id != Some(e.hir_id) {
self.negated_expr_id = Some(expr.hir_id);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<'tcx> Const<'tcx> {

let lit_input = match expr.kind {
hir::ExprKind::Lit(ref lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: false }),
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref expr) => match expr.kind {
hir::ExprKind::Unary(hir::UnOp::Neg, ref expr) => match expr.kind {
hir::ExprKind::Lit(ref lit) => {
Some(LitToConstInput { lit: &lit.node, ty, neg: true })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,18 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
opt_assignment_rhs_span.and_then(|span| span.desugaring_kind());
match opt_desugaring_kind {
// on for loops, RHS points to the iterator part
Some(DesugaringKind::ForLoop(_)) => Some((
false,
opt_assignment_rhs_span.unwrap(),
format!(
"this iterator yields `{SIGIL}` {DESC}s",
SIGIL = pointer_sigil,
DESC = pointer_desc
),
)),
Some(DesugaringKind::ForLoop(_)) => {
self.suggest_similar_mut_method_for_for_loop(&mut err);
Some((
false,
opt_assignment_rhs_span.unwrap(),
format!(
"this iterator yields `{SIGIL}` {DESC}s",
SIGIL = pointer_sigil,
DESC = pointer_desc
),
))
}
// don't create labels for compiler-generated spans
Some(_) => None,
None => {
Expand Down Expand Up @@ -537,6 +540,79 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
);
}

// Attempt to search similar mutable assosiated items for suggestion.
// In the future, attempt in all path but initially for RHS of for_loop
fn suggest_similar_mut_method_for_for_loop(&self, err: &mut DiagnosticBuilder<'_>) {
let hir = self.infcx.tcx.hir();
let node = hir.item(self.mir_hir_id());
use hir::{
Expr,
ExprKind::{Block, Call, DropTemps, Match, MethodCall},
};
if let hir::ItemKind::Fn(_, _, body_id) = node.kind {
if let Block(
hir::Block {
expr:
Some(Expr {
kind:
DropTemps(Expr {
kind:
Match(
Expr {
kind:
Call(
_,
[Expr {
kind: MethodCall(path_segment, ..),
hir_id,
..
}, ..],
),
..
},
..,
),
..
}),
..
}),
..
},
_,
) = hir.body(body_id).value.kind
{
let opt_suggestions = path_segment
.hir_id
.map(|path_hir_id| self.infcx.tcx.typeck(path_hir_id.owner))
.and_then(|typeck| typeck.type_dependent_def_id(*hir_id))
.and_then(|def_id| self.infcx.tcx.impl_of_method(def_id))
.map(|def_id| self.infcx.tcx.associated_items(def_id))
.map(|assoc_items| {
assoc_items
.in_definition_order()
.map(|assoc_item_def| assoc_item_def.ident)
.filter(|&ident| {
let original_method_ident = path_segment.ident;
original_method_ident != ident
&& ident
.as_str()
.starts_with(&original_method_ident.name.to_string())
})
.map(|ident| format!("{}()", ident))
});

if let Some(suggestions) = opt_suggestions {
err.span_suggestions(
path_segment.ident.span,
&format!("use mutable method"),
suggestions,
Applicability::MaybeIncorrect,
);
}
}
};
}

/// Targeted error when encountering an `FnMut` closure where an `Fn` closure was expected.
fn expected_fn_found_fn_mut_call(&self, err: &mut DiagnosticBuilder<'_>, sp: Span, act: &str) {
err.span_label(sp, format!("cannot {}", act));
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_mir_build/src/thir/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,23 +299,23 @@ fn make_mirror_unadjusted<'a, 'tcx>(
}
}

hir::ExprKind::Unary(hir::UnOp::UnDeref, ref arg) => {
hir::ExprKind::Unary(hir::UnOp::Deref, ref arg) => {
if cx.typeck_results().is_method_call(expr) {
overloaded_place(cx, expr, expr_ty, None, vec![arg.to_ref()], expr.span)
} else {
ExprKind::Deref { arg: arg.to_ref() }
}
}

hir::ExprKind::Unary(hir::UnOp::UnNot, ref arg) => {
hir::ExprKind::Unary(hir::UnOp::Not, ref arg) => {
if cx.typeck_results().is_method_call(expr) {
overloaded_operator(cx, expr, vec![arg.to_ref()])
} else {
ExprKind::Unary { op: UnOp::Not, arg: arg.to_ref() }
}
}

hir::ExprKind::Unary(hir::UnOp::UnNeg, ref arg) => {
hir::ExprKind::Unary(hir::UnOp::Neg, ref arg) => {
if cx.typeck_results().is_method_call(expr) {
overloaded_operator(cx, expr, vec![arg.to_ref()])
} else if let hir::ExprKind::Lit(ref lit) = arg.kind {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/thir/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
return *self.const_to_pat(value, expr.hir_id, expr.span, false).kind;
}
hir::ExprKind::Lit(ref lit) => (lit, false),
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref expr) => {
hir::ExprKind::Unary(hir::UnOp::Neg, ref expr) => {
let lit = match expr.kind {
hir::ExprKind::Lit(ref lit) => lit,
_ => span_bug!(expr.span, "not a literal: {:?}", expr),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ fn resolve_local<'tcx>(

match expr.kind {
hir::ExprKind::AddrOf(_, _, ref subexpr)
| hir::ExprKind::Unary(hir::UnOp::UnDeref, ref subexpr)
| hir::ExprKind::Unary(hir::UnOp::Deref, ref subexpr)
| hir::ExprKind::Field(ref subexpr, _)
| hir::ExprKind::Index(ref subexpr, _) => {
expr = &subexpr;
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_typeck/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,9 @@ fn async_opaque_type_cycle_error(tcx: TyCtxt<'tcx>, span: Span) {
struct_span_err!(tcx.sess, span, E0733, "recursion in an `async fn` requires boxing")
.span_label(span, "recursive `async fn`")
.note("a recursive `async fn` must be rewritten to return a boxed `dyn Future`")
.note(
"consider using the `async_recursion` crate: https://crates.io/crates/async_recursion",
)
.emit();
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let hir::ExprKind::Lit(lit) = &expr.kind { lit.node.is_suffixed() } else { false }
};
let is_negative_int =
|expr: &hir::Expr<'_>| matches!(expr.kind, hir::ExprKind::Unary(hir::UnOp::UnNeg, ..));
|expr: &hir::Expr<'_>| matches!(expr.kind, hir::ExprKind::Unary(hir::UnOp::Neg, ..));
let is_uint = |ty: Ty<'_>| matches!(ty.kind(), ty::Uint(..));

let in_const_context = self.tcx.hir().is_inside_const_context(expr.hir_id);
Expand Down
Loading

0 comments on commit f7534b5

Please sign in to comment.