Skip to content

Commit 7a36a77

Browse files
authored
Unrolled build for rust-lang#137449
Rollup merge of rust-lang#137449 - compiler-errors:control-flow, r=Amanieu,lnicola Denote `ControlFlow` as `#[must_use]` I've repeatedly hit bugs in the compiler due to `ControlFlow` not being marked `#[must_use]`. There seems to be an accepted ACP to make the type `#[must_use]` (rust-lang/libs-team#444), so this PR implements that part of it. Most of the usages in the compiler that trigger this new warning are "root" usages (calling into an API that uses control-flow internally, but for which the callee doesn't really care) and have been suppressed by `let _ = ...`, but I did legitimately find one instance of a missing `?` and one for a never-used `ControlFlow` value in rust-lang#137448. Presumably this needs an FCP too, so I'm opening this and nominating it for T-libs-api. This PR also touches the tools (incl. rust-analyzer), but if this went into FCP, I'd split those out into separate PRs which can land before this one does. r? libs-api `@rustbot` label: T-libs-api I-libs-api-nominated
2 parents 8279176 + e250bd1 commit 7a36a77

File tree

24 files changed

+67
-62
lines changed

24 files changed

+67
-62
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,7 @@ fn add_library_search_dirs(
21362136
}
21372137

21382138
let fallback = Some(NativeLibSearchFallback { self_contained_components, apple_sdk_root });
2139-
walk_native_lib_search_dirs(sess, fallback, |dir, is_framework| {
2139+
let _ = walk_native_lib_search_dirs(sess, fallback, |dir, is_framework| {
21402140
if is_framework {
21412141
cmd.framework_path(dir);
21422142
} else {

compiler/rustc_hir_typeck/src/method/suggest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
533533
}
534534
}
535535
_ => {
536-
intravisit::walk_pat(self, p);
536+
let _ = intravisit::walk_pat(self, p);
537537
}
538538
}
539539
ControlFlow::Continue(())
@@ -556,7 +556,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
556556
method_name,
557557
sugg_let: None,
558558
};
559-
let_visitor.visit_body(&body);
559+
let _ = let_visitor.visit_body(&body);
560560
if let Some(sugg_let) = let_visitor.sugg_let
561561
&& let Some(self_ty) = self.node_ty_opt(sugg_let.init_hir_id)
562562
{

compiler/rustc_privacy/src/lib.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -1361,12 +1361,12 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
13611361
GenericParamDefKind::Lifetime => {}
13621362
GenericParamDefKind::Type { has_default, .. } => {
13631363
if has_default {
1364-
self.visit(self.tcx.type_of(param.def_id).instantiate_identity());
1364+
let _ = self.visit(self.tcx.type_of(param.def_id).instantiate_identity());
13651365
}
13661366
}
13671367
// FIXME(generic_const_exprs): May want to look inside const here
13681368
GenericParamDefKind::Const { .. } => {
1369-
self.visit(self.tcx.type_of(param.def_id).instantiate_identity());
1369+
let _ = self.visit(self.tcx.type_of(param.def_id).instantiate_identity());
13701370
}
13711371
}
13721372
}
@@ -1381,19 +1381,19 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
13811381
// consider the ones that the user wrote. This is important
13821382
// for the inferred outlives rules; see
13831383
// `tests/ui/rfc-2093-infer-outlives/privacy.rs`.
1384-
self.visit_predicates(self.tcx.explicit_predicates_of(self.item_def_id));
1384+
let _ = self.visit_predicates(self.tcx.explicit_predicates_of(self.item_def_id));
13851385
self
13861386
}
13871387

13881388
fn bounds(&mut self) -> &mut Self {
13891389
self.in_primary_interface = false;
1390-
self.visit_clauses(self.tcx.explicit_item_bounds(self.item_def_id).skip_binder());
1390+
let _ = self.visit_clauses(self.tcx.explicit_item_bounds(self.item_def_id).skip_binder());
13911391
self
13921392
}
13931393

13941394
fn ty(&mut self) -> &mut Self {
13951395
self.in_primary_interface = true;
1396-
self.visit(self.tcx.type_of(self.item_def_id).instantiate_identity());
1396+
let _ = self.visit(self.tcx.type_of(self.item_def_id).instantiate_identity());
13971397
self
13981398
}
13991399

@@ -1785,7 +1785,7 @@ fn check_mod_privacy(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
17851785

17861786
let module = tcx.hir_module_items(module_def_id);
17871787
for def_id in module.definitions() {
1788-
rustc_ty_utils::sig_types::walk_types(tcx, def_id, &mut visitor);
1788+
let _ = rustc_ty_utils::sig_types::walk_types(tcx, def_id, &mut visitor);
17891789

17901790
if let Some(body_id) = tcx.hir_maybe_body_owned_by(def_id) {
17911791
visitor.visit_nested_body(body_id.id());
@@ -1798,7 +1798,11 @@ fn check_mod_privacy(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
17981798
let trait_ref = tcx.impl_trait_ref(id.owner_id.def_id).unwrap();
17991799
let trait_ref = trait_ref.instantiate_identity();
18001800
visitor.span = item.path.span;
1801-
visitor.visit_def_id(trait_ref.def_id, "trait", &trait_ref.print_only_trait_path());
1801+
let _ = visitor.visit_def_id(
1802+
trait_ref.def_id,
1803+
"trait",
1804+
&trait_ref.print_only_trait_path(),
1805+
);
18021806
}
18031807
}
18041808
}

compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/find_anon_type.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
7777
match arg.kind {
7878
hir::TyKind::BareFn(_) => {
7979
self.current_index.shift_in(1);
80-
intravisit::walk_ty(self, arg);
80+
let _ = intravisit::walk_ty(self, arg);
8181
self.current_index.shift_out(1);
8282
return ControlFlow::Continue(());
8383
}
8484

8585
hir::TyKind::TraitObject(bounds, ..) => {
8686
for bound in bounds {
8787
self.current_index.shift_in(1);
88-
self.visit_poly_trait_ref(bound);
88+
let _ = self.visit_poly_trait_ref(bound);
8989
self.current_index.shift_out(1);
9090
}
9191
}

compiler/rustc_trait_selection/src/traits/project.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>(
743743
) {
744744
debug!("assemble_candidates_from_trait_def(..)");
745745
let mut ambiguous = false;
746-
selcx.for_each_item_bound(
746+
let _ = selcx.for_each_item_bound(
747747
obligation.predicate.self_ty(),
748748
|selcx, clause, _| {
749749
let Some(clause) = clause.as_projection_clause() else {

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
176176
// normalization, so try to deduplicate when possible to avoid
177177
// unnecessary ambiguity.
178178
let mut distinct_normalized_bounds = FxHashSet::default();
179-
self.for_each_item_bound::<!>(
179+
let _ = self.for_each_item_bound::<!>(
180180
placeholder_trait_predicate.self_ty(),
181181
|selcx, bound, idx| {
182182
let Some(bound) = bound.as_trait_clause() else {

compiler/rustc_type_ir/src/binder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ where
112112
pub fn bind_with_vars(value: T, bound_vars: I::BoundVarKinds) -> Binder<I, T> {
113113
if cfg!(debug_assertions) {
114114
let mut validator = ValidateBoundVars::new(bound_vars);
115-
value.visit_with(&mut validator);
115+
let _ = value.visit_with(&mut validator);
116116
}
117117
Binder { value, bound_vars }
118118
}
@@ -196,7 +196,7 @@ impl<I: Interner, T> Binder<I, T> {
196196
let value = f(value);
197197
if cfg!(debug_assertions) {
198198
let mut validator = ValidateBoundVars::new(bound_vars);
199-
value.visit_with(&mut validator);
199+
let _ = value.visit_with(&mut validator);
200200
}
201201
Binder { value, bound_vars }
202202
}
@@ -209,7 +209,7 @@ impl<I: Interner, T> Binder<I, T> {
209209
let value = f(value)?;
210210
if cfg!(debug_assertions) {
211211
let mut validator = ValidateBoundVars::new(bound_vars);
212-
value.visit_with(&mut validator);
212+
let _ = value.visit_with(&mut validator);
213213
}
214214
Ok(Binder { value, bound_vars })
215215
}

library/core/src/ops/control_flow.rs

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ use crate::{convert, ops};
8080
/// [`Continue`]: ControlFlow::Continue
8181
#[stable(feature = "control_flow_enum_type", since = "1.55.0")]
8282
#[rustc_diagnostic_item = "ControlFlow"]
83+
#[must_use]
8384
// ControlFlow should not implement PartialOrd or Ord, per RFC 3058:
8485
// https://rust-lang.github.io/rfcs/3058-try-trait-v2.html#traits-for-controlflow
8586
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

src/librustdoc/html/length_limit/tests.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,53 @@ fn empty() {
99
#[test]
1010
fn basic() {
1111
let mut buf = HtmlWithLimit::new(60);
12-
buf.push("Hello ");
12+
let _ = buf.push("Hello ");
1313
buf.open_tag("em");
14-
buf.push("world");
14+
let _ = buf.push("world");
1515
buf.close_tag();
16-
buf.push("!");
16+
let _ = buf.push("!");
1717
assert_eq!(buf.finish(), "Hello <em>world</em>!");
1818
}
1919

2020
#[test]
2121
fn no_tags() {
2222
let mut buf = HtmlWithLimit::new(60);
23-
buf.push("Hello");
24-
buf.push(" world!");
23+
let _ = buf.push("Hello");
24+
let _ = buf.push(" world!");
2525
assert_eq!(buf.finish(), "Hello world!");
2626
}
2727

2828
#[test]
2929
fn limit_0() {
3030
let mut buf = HtmlWithLimit::new(0);
31-
buf.push("Hello ");
31+
let _ = buf.push("Hello ");
3232
buf.open_tag("em");
33-
buf.push("world");
33+
let _ = buf.push("world");
3434
buf.close_tag();
35-
buf.push("!");
35+
let _ = buf.push("!");
3636
assert_eq!(buf.finish(), "");
3737
}
3838

3939
#[test]
4040
fn exactly_limit() {
4141
let mut buf = HtmlWithLimit::new(12);
42-
buf.push("Hello ");
42+
let _ = buf.push("Hello ");
4343
buf.open_tag("em");
44-
buf.push("world");
44+
let _ = buf.push("world");
4545
buf.close_tag();
46-
buf.push("!");
46+
let _ = buf.push("!");
4747
assert_eq!(buf.finish(), "Hello <em>world</em>!");
4848
}
4949

5050
#[test]
5151
fn multiple_nested_tags() {
5252
let mut buf = HtmlWithLimit::new(60);
5353
buf.open_tag("p");
54-
buf.push("This is a ");
54+
let _ = buf.push("This is a ");
5555
buf.open_tag("em");
56-
buf.push("paragraph");
56+
let _ = buf.push("paragraph");
5757
buf.open_tag("strong");
58-
buf.push("!");
58+
let _ = buf.push("!");
5959
buf.close_tag();
6060
buf.close_tag();
6161
buf.close_tag();
@@ -66,22 +66,22 @@ fn multiple_nested_tags() {
6666
fn forgot_to_close_tags() {
6767
let mut buf = HtmlWithLimit::new(60);
6868
buf.open_tag("p");
69-
buf.push("This is a ");
69+
let _ = buf.push("This is a ");
7070
buf.open_tag("em");
71-
buf.push("paragraph");
71+
let _ = buf.push("paragraph");
7272
buf.open_tag("strong");
73-
buf.push("!");
73+
let _ = buf.push("!");
7474
assert_eq!(buf.finish(), "<p>This is a <em>paragraph<strong>!</strong></em></p>");
7575
}
7676

7777
#[test]
7878
fn past_the_limit() {
7979
let mut buf = HtmlWithLimit::new(20);
8080
buf.open_tag("p");
81-
(0..10).try_for_each(|n| {
81+
let _ = (0..10).try_for_each(|n| {
8282
buf.open_tag("strong");
83-
buf.push("word#")?;
84-
buf.push(&n.to_string())?;
83+
let _ = buf.push("word#")?;
84+
let _ = buf.push(&n.to_string())?;
8585
buf.close_tag();
8686
ControlFlow::Continue(())
8787
});
@@ -100,8 +100,8 @@ fn past_the_limit() {
100100
fn quickly_past_the_limit() {
101101
let mut buf = HtmlWithLimit::new(6);
102102
buf.open_tag("p");
103-
buf.push("Hello");
104-
buf.push(" World");
103+
let _ = buf.push("Hello");
104+
let _ = buf.push(" World");
105105
// intentionally not closing <p> before finishing
106106
assert_eq!(buf.finish(), "<p>Hello</p>");
107107
}
@@ -110,7 +110,7 @@ fn quickly_past_the_limit() {
110110
fn close_too_many() {
111111
let mut buf = HtmlWithLimit::new(60);
112112
buf.open_tag("p");
113-
buf.push("Hello");
113+
let _ = buf.push("Hello");
114114
buf.close_tag();
115115
// This call does not panic because there are valid cases
116116
// where `close_tag()` is called with no tags left to close.

src/librustdoc/html/markdown.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ fn markdown_summary_with_limit(
15681568

15691569
let mut buf = HtmlWithLimit::new(length_limit);
15701570
let mut stopped_early = false;
1571-
p.try_for_each(|event| {
1571+
let _ = p.try_for_each(|event| {
15721572
match &event {
15731573
Event::Text(text) => {
15741574
let r =

src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl BreakAfterExprVisitor {
129129
};
130130

131131
get_enclosing_block(cx, hir_id).is_some_and(|block| {
132-
visitor.visit_block(block);
132+
let _ = visitor.visit_block(block);
133133
visitor.break_after_expr
134134
})
135135
}

src/tools/clippy/clippy_lints/src/methods/read_line_without_trim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn check(cx: &LateContext<'_>, call: &Expr<'_>, recv: &Expr<'_>, arg: &Expr<
4040
// We've checked that `call` is a call to `Stdin::read_line()` with the right receiver,
4141
// now let's check if the first use of the string passed to `::read_line()`
4242
// is used for operations that will always fail (e.g. parsing "6\n" into a number)
43-
for_each_local_use_after_expr(cx, local_id, call.hir_id, |expr| {
43+
let _ = for_each_local_use_after_expr(cx, local_id, call.hir_id, |expr| {
4444
if let Some(parent) = get_parent_expr(cx, expr) {
4545
let data = if let ExprKind::MethodCall(segment, recv, args, span) = parent.kind {
4646
if args.is_empty()

src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl PassByRefOrValue {
141141
// Gather all the lifetimes found in the output type which may affect whether
142142
// `TRIVIALLY_COPY_PASS_BY_REF` should be linted.
143143
let mut output_regions = FxHashSet::default();
144-
for_each_top_level_late_bound_region(fn_sig.skip_binder().output(), |region| -> ControlFlow<!> {
144+
let _ = for_each_top_level_late_bound_region(fn_sig.skip_binder().output(), |region| -> ControlFlow<!> {
145145
output_regions.insert(region);
146146
ControlFlow::Continue(())
147147
});

src/tools/clippy/clippy_lints/src/unconditional_recursion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ impl UnconditionalRecursion {
381381
implemented_ty_id,
382382
method_span,
383383
};
384-
walk_body(&mut c, body);
384+
let _ = walk_body(&mut c, body);
385385
}
386386
}
387387
}

src/tools/rust-analyzer/crates/hir-ty/src/chalk_db.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,19 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
145145
let mut result = vec![];
146146
if fps.is_empty() {
147147
debug!("Unrestricted search for {:?} impls...", trait_);
148-
self.for_trait_impls(trait_, self_ty_fp, |impls| {
148+
let _ = self.for_trait_impls(trait_, self_ty_fp, |impls| {
149149
result.extend(impls.for_trait(trait_).map(id_to_chalk));
150150
ControlFlow::Continue(())
151-
})
151+
});
152152
} else {
153-
self.for_trait_impls(trait_, self_ty_fp, |impls| {
153+
let _ = self.for_trait_impls(trait_, self_ty_fp, |impls| {
154154
result.extend(
155155
fps.iter().flat_map(move |fp| {
156156
impls.for_trait_and_self_ty(trait_, *fp).map(id_to_chalk)
157157
}),
158158
);
159159
ControlFlow::Continue(())
160-
})
160+
});
161161
};
162162

163163
debug!("impls_for_trait returned {} impls", result.len());

src/tools/rust-analyzer/crates/hir-ty/src/dyn_compatibility.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub fn dyn_compatibility_of_trait_query(
116116
trait_: TraitId,
117117
) -> Option<DynCompatibilityViolation> {
118118
let mut res = None;
119-
dyn_compatibility_of_trait_with_callback(db, trait_, &mut |osv| {
119+
let _ = dyn_compatibility_of_trait_with_callback(db, trait_, &mut |osv| {
120120
res = Some(osv);
121121
ControlFlow::Break(())
122122
});
@@ -597,7 +597,7 @@ fn contains_illegal_impl_trait_in_trait(
597597

598598
let ret = sig.skip_binders().ret();
599599
let mut visitor = OpaqueTypeCollector(FxHashSet::default());
600-
ret.visit_with(visitor.as_dyn(), DebruijnIndex::INNERMOST);
600+
let _ = ret.visit_with(visitor.as_dyn(), DebruijnIndex::INNERMOST);
601601

602602
// Since we haven't implemented RPITIT in proper way like rustc yet,
603603
// just check whether `ret` contains RPIT for now

src/tools/rust-analyzer/crates/hir-ty/src/dyn_compatibility/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn check_dyn_compatibility<'a>(
5353
continue;
5454
};
5555
let mut osvs = FxHashSet::default();
56-
dyn_compatibility_with_callback(&db, trait_id, &mut |osv| {
56+
let _ = dyn_compatibility_with_callback(&db, trait_id, &mut |osv| {
5757
osvs.insert(match osv {
5858
DynCompatibilityViolation::SizedSelf => SizedSelf,
5959
DynCompatibilityViolation::SelfReferential => SelfReferential,

src/tools/rust-analyzer/crates/hir-ty/src/infer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ impl<'a> InferenceContext<'a> {
11431143
non_assocs: FxHashMap::default(),
11441144
};
11451145
for ty in tait_candidates {
1146-
ty.visit_with(collector.as_dyn(), DebruijnIndex::INNERMOST);
1146+
let _ = ty.visit_with(collector.as_dyn(), DebruijnIndex::INNERMOST);
11471147
}
11481148

11491149
// Non-assoc TAITs can be define-used everywhere as long as they are

src/tools/rust-analyzer/crates/hir-ty/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ where
10331033
T: ?Sized + TypeVisitable<Interner>,
10341034
{
10351035
let mut collector = PlaceholderCollector { db, placeholders: FxHashSet::default() };
1036-
value.visit_with(&mut collector, DebruijnIndex::INNERMOST);
1036+
let _ = value.visit_with(&mut collector, DebruijnIndex::INNERMOST);
10371037
collector.placeholders.into_iter().collect()
10381038
}
10391039

src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ pub(crate) fn iterate_method_candidates<T>(
596596
mut callback: impl FnMut(ReceiverAdjustments, AssocItemId, bool) -> Option<T>,
597597
) -> Option<T> {
598598
let mut slot = None;
599-
iterate_method_candidates_dyn(
599+
let _ = iterate_method_candidates_dyn(
600600
ty,
601601
db,
602602
env,

0 commit comments

Comments
 (0)