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 11 pull requests #81952

Merged
merged 29 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8a85a85
Clarify difference between unix/windows behaviour
Digital-Chaos Dec 23, 2020
bb2a27b
Update library/std/src/thread/mod.rs
Digital-Chaos Jan 15, 2021
cd6dad6
Make Vec::split_at_spare_mut public
WaffleLapkin Feb 2, 2021
476a57a
fix typo in library/alloc/src/vec/mod.rs
WaffleLapkin Feb 3, 2021
76223fa
Add note to `Vec::split_at_spare_mut` docs that the method is low-level
WaffleLapkin Feb 3, 2021
d3c4dbd
Add suggest mu method for loop
sasurau4 Jan 28, 2021
90c9b57
Add test
sasurau4 Jan 28, 2021
4d33d41
Add long explanation for E0547
jesusprubio Feb 8, 2021
1b32a7a
Bump stabilization version for const int methods
jhpratt Feb 9, 2021
ce7de07
Add `Box::into_inner`.
crlf0710 Dec 28, 2020
7554c77
Remove unnecessary refs in pattern matching
wcampbell0x2a Feb 9, 2021
31c9339
Use format string in bootstrap panic instead of a string directly
jyn514 Feb 9, 2021
c4e3558
Rename HIR UnOp variants
osa1 Feb 9, 2021
7b84b62
Lost text re-added
jesusprubio Feb 9, 2021
4af417a
add suggestion to use the `async_recursion` crate
henryboisdequin Feb 9, 2021
8fbdd2d
Update compiler/rustc_error_codes/src/error_codes/E0547.md
jesusprubio Feb 9, 2021
8ff7b75
update tracking issue for vec_split_at_spare
KodrAus Feb 9, 2021
b53b79c
Update cargo
ehuss Feb 10, 2021
bb06b13
Rollup merge of #79849 - Digital-Chaos:sleep-zero, r=m-ou-se
JohnTitor Feb 10, 2021
a28f2af
Rollup merge of #80438 - crlf0710:box_into_inner, r=m-ou-se
JohnTitor Feb 10, 2021
3f09418
Rollup merge of #81466 - sasurau4:fix/enhance-sugget-mut-method-for-l…
JohnTitor Feb 10, 2021
e2765f8
Rollup merge of #81687 - WaffleLapkin:split_at_spare, r=KodrAus
JohnTitor Feb 10, 2021
bf0c2d5
Rollup merge of #81904 - jhpratt:const_int_fn-stabilization, r=jyn514
JohnTitor Feb 10, 2021
fff36f1
Rollup merge of #81909 - wcampbell0x2a:remove-unnecessary-refs, r=est…
JohnTitor Feb 10, 2021
8129108
Rollup merge of #81910 - jyn514:bootstrap-1.52, r=jackh726
JohnTitor Feb 10, 2021
a58feb9
Rollup merge of #81913 - osa1:rename_unop_variants, r=matthewjasper
JohnTitor Feb 10, 2021
40fa6fc
Rollup merge of #81925 - jesusprubio:add-long-explanation-e0547, r=Gu…
JohnTitor Feb 10, 2021
2e8e591
Rollup merge of #81926 - henryboisdequin:fix-81907, r=estebank
JohnTitor Feb 10, 2021
77114af
Rollup merge of #81951 - ehuss:update-cargo, r=ehuss
JohnTitor Feb 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
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