Skip to content

Commit 647aecc

Browse files
committed
Auto merge of #44807 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 4 pull requests - Successful merges: #44103, #44625, #44789, #44795 - Failed merges:
2 parents 6f90787 + a8a0ec2 commit 647aecc

File tree

7 files changed

+96
-32
lines changed

7 files changed

+96
-32
lines changed

src/librustc_lint/unused.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
153153
};
154154

155155
let mut fn_warned = false;
156+
let mut op_warned = false;
156157
if cx.tcx.sess.features.borrow().fn_must_use {
157158
let maybe_def = match expr.node {
158159
hir::ExprCall(ref callee, _) => {
@@ -172,9 +173,24 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
172173
let def_id = def.def_id();
173174
fn_warned = check_must_use(cx, def_id, s.span, "return value of ");
174175
}
176+
177+
if let hir::ExprBinary(bin_op, ..) = expr.node {
178+
match bin_op.node {
179+
// Hardcoding the comparison operators here seemed more
180+
// expedient than the refactoring that would be needed to
181+
// look up the `#[must_use]` attribute which does exist on
182+
// the comparison trait methods
183+
hir::BiEq | hir::BiLt | hir::BiLe | hir::BiNe | hir::BiGe | hir::BiGt => {
184+
let msg = "unused comparison which must be used";
185+
cx.span_lint(UNUSED_MUST_USE, expr.span, msg);
186+
op_warned = true;
187+
},
188+
_ => {},
189+
}
190+
}
175191
}
176192

177-
if !(ty_warned || fn_warned) {
193+
if !(ty_warned || fn_warned || op_warned) {
178194
cx.span_lint(UNUSED_RESULTS, s.span, "unused result");
179195
}
180196

src/librustc_mir/borrow_check.rs

+19-11
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
408408
self.each_borrow_involving_path(
409409
context, lvalue_span.0, flow_state, |this, _idx, borrow| {
410410
if !borrow.compatible_with(BorrowKind::Mut) {
411-
this.report_move_out_while_borrowed(context, lvalue_span);
411+
this.report_move_out_while_borrowed(context, lvalue_span, borrow);
412412
Control::Break
413413
} else {
414414
Control::Continue
@@ -896,20 +896,28 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
896896
fn report_use_of_moved(&mut self,
897897
_context: Context,
898898
(lvalue, span): (&Lvalue, Span)) {
899-
let mut err = self.tcx.cannot_act_on_uninitialized_variable(
900-
span, "use", &self.describe_lvalue(lvalue), Origin::Mir);
901-
// FIXME: add span_label for use of uninitialized variable
902-
err.emit();
899+
self.tcx.cannot_act_on_uninitialized_variable(span,
900+
"use",
901+
&self.describe_lvalue(lvalue),
902+
Origin::Mir)
903+
.span_label(span, format!("use of possibly uninitialized `{}`",
904+
self.describe_lvalue(lvalue)))
905+
.emit();
903906
}
904907

905908
fn report_move_out_while_borrowed(&mut self,
906909
_context: Context,
907-
(lvalue, span): (&Lvalue, Span)) {
908-
let mut err = self.tcx.cannot_move_when_borrowed(
909-
span, &self.describe_lvalue(lvalue), Origin::Mir);
910-
// FIXME 1: add span_label for "borrow of `()` occurs here"
911-
// FIXME 2: add span_label for "move out of `{}` occurs here"
912-
err.emit();
910+
(lvalue, span): (&Lvalue, Span),
911+
borrow: &BorrowData) {
912+
self.tcx.cannot_move_when_borrowed(span,
913+
&self.describe_lvalue(lvalue),
914+
Origin::Mir)
915+
.span_label(self.retrieve_borrow_span(borrow),
916+
format!("borrow of `{}` occurs here",
917+
self.describe_lvalue(&borrow.lvalue)))
918+
.span_label(span, format!("move out of `{}` occurs here",
919+
self.describe_lvalue(lvalue)))
920+
.emit();
913921
}
914922

915923
fn report_use_while_mutably_borrowed(&mut self,

src/librustdoc/html/static/rustdoc.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ span.since {
823823

824824
.information {
825825
position: absolute;
826-
left: -1px;
826+
left: -20px;
827827
margin-top: 7px;
828828
z-index: 1;
829829
}

src/libstd/process.rs

+24-8
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,18 @@ use sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
106106
pub struct Child {
107107
handle: imp::Process,
108108

109-
/// The handle for writing to the child's stdin, if it has been captured
109+
/// The handle for writing to the child's standard input (stdin), if it has
110+
/// been captured.
110111
#[stable(feature = "process", since = "1.0.0")]
111112
pub stdin: Option<ChildStdin>,
112113

113-
/// The handle for reading from the child's stdout, if it has been captured
114+
/// The handle for reading from the child's standard output (stdout), if it
115+
/// has been captured.
114116
#[stable(feature = "process", since = "1.0.0")]
115117
pub stdout: Option<ChildStdout>,
116118

117-
/// The handle for reading from the child's stderr, if it has been captured
119+
/// The handle for reading from the child's standard error (stderr), if it
120+
/// has been captured.
118121
#[stable(feature = "process", since = "1.0.0")]
119122
pub stderr: Option<ChildStderr>,
120123
}
@@ -149,12 +152,17 @@ impl fmt::Debug for Child {
149152
}
150153
}
151154

152-
/// A handle to a child process's stdin.
155+
/// A handle to a child process's standard input (stdin).
153156
///
154157
/// This struct is used in the [`stdin`] field on [`Child`].
155158
///
159+
/// When an instance of `ChildStdin` is [dropped], the `ChildStdin`'s underlying
160+
/// file handle will be closed. If the child process was blocked on input prior
161+
/// to being dropped, it will become unblocked after dropping.
162+
///
156163
/// [`Child`]: struct.Child.html
157164
/// [`stdin`]: struct.Child.html#structfield.stdin
165+
/// [dropped]: ../ops/trait.Drop.html
158166
#[stable(feature = "process", since = "1.0.0")]
159167
pub struct ChildStdin {
160168
inner: AnonPipe
@@ -192,12 +200,16 @@ impl fmt::Debug for ChildStdin {
192200
}
193201
}
194202

195-
/// A handle to a child process's stdout.
203+
/// A handle to a child process's standard output (stdout).
196204
///
197205
/// This struct is used in the [`stdout`] field on [`Child`].
198206
///
207+
/// When an instance of `ChildStdout` is [dropped], the `ChildStdout`'s
208+
/// underlying file handle will be closed.
209+
///
199210
/// [`Child`]: struct.Child.html
200211
/// [`stdout`]: struct.Child.html#structfield.stdout
212+
/// [dropped]: ../ops/trait.Drop.html
201213
#[stable(feature = "process", since = "1.0.0")]
202214
pub struct ChildStdout {
203215
inner: AnonPipe
@@ -239,8 +251,12 @@ impl fmt::Debug for ChildStdout {
239251
///
240252
/// This struct is used in the [`stderr`] field on [`Child`].
241253
///
254+
/// When an instance of `ChildStderr` is [dropped], the `ChildStderr`'s
255+
/// underlying file handle will be closed.
256+
///
242257
/// [`Child`]: struct.Child.html
243258
/// [`stderr`]: struct.Child.html#structfield.stderr
259+
/// [dropped]: ../ops/trait.Drop.html
244260
#[stable(feature = "process", since = "1.0.0")]
245261
pub struct ChildStderr {
246262
inner: AnonPipe
@@ -534,7 +550,7 @@ impl Command {
534550
self
535551
}
536552

537-
/// Configuration for the child process's stdin handle (file descriptor 0).
553+
/// Configuration for the child process's standard input (stdin) handle.
538554
///
539555
/// # Examples
540556
///
@@ -554,7 +570,7 @@ impl Command {
554570
self
555571
}
556572

557-
/// Configuration for the child process's stdout handle (file descriptor 1).
573+
/// Configuration for the child process's standard output (stdout) handle.
558574
///
559575
/// # Examples
560576
///
@@ -574,7 +590,7 @@ impl Command {
574590
self
575591
}
576592

577-
/// Configuration for the child process's stderr handle (file descriptor 2).
593+
/// Configuration for the child process's standard error (stderr) handle.
578594
///
579595
/// # Examples
580596
///

src/libsyntax/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ declare_features! (
380380
// #[doc(masked)]
381381
(active, doc_masked, "1.21.0", None),
382382

383-
// allow `#[must_use]` on functions (RFC 1940)
383+
// allow `#[must_use]` on functions and comparison operators (RFC 1940)
384384
(active, fn_must_use, "1.21.0", Some(43302)),
385385

386386
// allow '|' at beginning of match arms (RFC 1925)

src/test/ui/rfc_1940-must_use_on_functions/fn_must_use.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#![feature(fn_must_use)]
1212
#![warn(unused_must_use)]
1313

14+
#[derive(PartialEq, Eq)]
1415
struct MyStruct {
1516
n: usize,
1617
}
@@ -58,13 +59,18 @@ fn main() {
5859
need_to_use_this_value();
5960

6061
let mut m = MyStruct { n: 2 };
62+
let n = MyStruct { n: 3 };
63+
6164
m.need_to_use_this_method_value();
6265
m.is_even(); // trait method!
6366

64-
m.replace(3);
67+
m.replace(3); // won't warn (annotation needs to be in trait definition)
6568

69+
// comparison methods are `must_use`
6670
2.eq(&3);
71+
m.eq(&n);
6772

68-
// FIXME: operators should probably be `must_use` if underlying method is
73+
// lint includes comparison operators
6974
2 == 3;
75+
m == n;
7076
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
warning: unused return value of `need_to_use_this_value` which must be used: it's important
2-
--> $DIR/fn_must_use.rs:58:5
2+
--> $DIR/fn_must_use.rs:59:5
33
|
4-
58 | need_to_use_this_value();
4+
59 | need_to_use_this_value();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
note: lint level defined here
@@ -11,20 +11,38 @@ note: lint level defined here
1111
| ^^^^^^^^^^^^^^^
1212

1313
warning: unused return value of `MyStruct::need_to_use_this_method_value` which must be used
14-
--> $DIR/fn_must_use.rs:61:5
14+
--> $DIR/fn_must_use.rs:64:5
1515
|
16-
61 | m.need_to_use_this_method_value();
16+
64 | m.need_to_use_this_method_value();
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1818

1919
warning: unused return value of `EvenNature::is_even` which must be used: no side effects
20-
--> $DIR/fn_must_use.rs:62:5
20+
--> $DIR/fn_must_use.rs:65:5
2121
|
22-
62 | m.is_even(); // trait method!
22+
65 | m.is_even(); // trait method!
2323
| ^^^^^^^^^^^^
2424

2525
warning: unused return value of `std::cmp::PartialEq::eq` which must be used
26-
--> $DIR/fn_must_use.rs:66:5
26+
--> $DIR/fn_must_use.rs:70:5
2727
|
28-
66 | 2.eq(&3);
28+
70 | 2.eq(&3);
2929
| ^^^^^^^^^
3030

31+
warning: unused return value of `std::cmp::PartialEq::eq` which must be used
32+
--> $DIR/fn_must_use.rs:71:5
33+
|
34+
71 | m.eq(&n);
35+
| ^^^^^^^^^
36+
37+
warning: unused comparison which must be used
38+
--> $DIR/fn_must_use.rs:74:5
39+
|
40+
74 | 2 == 3;
41+
| ^^^^^^
42+
43+
warning: unused comparison which must be used
44+
--> $DIR/fn_must_use.rs:75:5
45+
|
46+
75 | m == n;
47+
| ^^^^^^
48+

0 commit comments

Comments
 (0)