Skip to content

Commit 6343edf

Browse files
committed
Auto merge of rust-lang#94469 - Dylan-DPC:rollup-2tcq6s5, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - rust-lang#91545 (Generalize "remove `&`" and "add `*`" suggestions to more than one deref) - rust-lang#93385 (Rustdoc ty consistency fixes) - rust-lang#93926 (Lint against more useless `#[must_use]` attributes) - rust-lang#94094 (use BOOL for TCP_NODELAY setsockopt value on Windows) - rust-lang#94384 (Add Atomic*::from_mut_slice) - rust-lang#94448 (5 - Make more use of `let_chains`) - rust-lang#94452 (Sync portable-simd for bitmasks &c.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8d6f527 + 4001d98 commit 6343edf

Some content is hidden

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

44 files changed

+1402
-468
lines changed

compiler/rustc_macros/src/session_diagnostic.rs

-1
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,6 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
587587
// next call to `it.next()` retrieves the next character.
588588
while let Some(c) = it.next() {
589589
if c == '{' && *it.peek().unwrap_or(&'\0') != '{' {
590-
#[must_use]
591590
let mut eat_argument = || -> Option<String> {
592591
let mut result = String::new();
593592
// Format specifiers look like

compiler/rustc_passes/src/check_attr.rs

+48-17
Original file line numberDiff line numberDiff line change
@@ -1111,24 +1111,55 @@ impl CheckAttrVisitor<'_> {
11111111
}
11121112

11131113
/// Warns against some misuses of `#[must_use]`
1114-
fn check_must_use(&self, hir_id: HirId, attr: &Attribute, span: Span, _target: Target) -> bool {
1114+
fn check_must_use(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) -> bool {
11151115
let node = self.tcx.hir().get(hir_id);
1116-
if let Some(fn_node) = node.fn_kind() {
1117-
if let rustc_hir::IsAsync::Async = fn_node.asyncness() {
1118-
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
1119-
lint.build(
1120-
"`must_use` attribute on `async` functions \
1121-
applies to the anonymous `Future` returned by the \
1122-
function, not the value within",
1123-
)
1124-
.span_label(
1125-
span,
1126-
"this attribute does nothing, the `Future`s \
1127-
returned by async functions are already `must_use`",
1128-
)
1129-
.emit();
1130-
});
1131-
}
1116+
if let Some(kind) = node.fn_kind() && let rustc_hir::IsAsync::Async = kind.asyncness() {
1117+
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
1118+
lint.build(
1119+
"`must_use` attribute on `async` functions \
1120+
applies to the anonymous `Future` returned by the \
1121+
function, not the value within",
1122+
)
1123+
.span_label(
1124+
span,
1125+
"this attribute does nothing, the `Future`s \
1126+
returned by async functions are already `must_use`",
1127+
)
1128+
.emit();
1129+
});
1130+
}
1131+
1132+
if !matches!(
1133+
target,
1134+
Target::Fn
1135+
| Target::Enum
1136+
| Target::Struct
1137+
| Target::Union
1138+
| Target::Method(_)
1139+
| Target::ForeignFn
1140+
// `impl Trait` in return position can trip
1141+
// `unused_must_use` if `Trait` is marked as
1142+
// `#[must_use]`
1143+
| Target::Trait
1144+
) {
1145+
let article = match target {
1146+
Target::ExternCrate
1147+
| Target::OpaqueTy
1148+
| Target::Enum
1149+
| Target::Impl
1150+
| Target::Expression
1151+
| Target::Arm
1152+
| Target::AssocConst
1153+
| Target::AssocTy => "an",
1154+
_ => "a",
1155+
};
1156+
1157+
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
1158+
lint.build(&format!(
1159+
"`#[must_use]` has no effect when applied to {article} {target}"
1160+
))
1161+
.emit();
1162+
});
11321163
}
11331164

11341165
// For now, its always valid

compiler/rustc_passes/src/dead.rs

+27-28
Original file line numberDiff line numberDiff line change
@@ -683,34 +683,33 @@ impl<'tcx> DeadVisitor<'tcx> {
683683
let descr = self.tcx.def_kind(def_id).descr(def_id.to_def_id());
684684
let mut err = lint.build(&format!("{} is never {}: `{}`", descr, participle, name));
685685
let hir = self.tcx.hir();
686-
if let Some(encl_scope) = hir.get_enclosing_scope(id) {
687-
if let Some(encl_def_id) = hir.opt_local_def_id(encl_scope) {
688-
if let Some(ign_traits) = self.ignored_derived_traits.get(&encl_def_id) {
689-
let traits_str = ign_traits
690-
.iter()
691-
.map(|(trait_id, _)| format!("`{}`", self.tcx.item_name(*trait_id)))
692-
.collect::<Vec<_>>()
693-
.join(" and ");
694-
let plural_s = pluralize!(ign_traits.len());
695-
let article = if ign_traits.len() > 1 { "" } else { "a " };
696-
let is_are = if ign_traits.len() > 1 { "these are" } else { "this is" };
697-
let msg = format!(
698-
"`{}` has {}derived impl{} for the trait{} {}, but {} \
699-
intentionally ignored during dead code analysis",
700-
self.tcx.item_name(encl_def_id.to_def_id()),
701-
article,
702-
plural_s,
703-
plural_s,
704-
traits_str,
705-
is_are
706-
);
707-
let multispan = ign_traits
708-
.iter()
709-
.map(|(_, impl_id)| self.tcx.def_span(*impl_id))
710-
.collect::<Vec<_>>();
711-
err.span_note(multispan, &msg);
712-
}
713-
}
686+
if let Some(encl_scope) = hir.get_enclosing_scope(id)
687+
&& let Some(encl_def_id) = hir.opt_local_def_id(encl_scope)
688+
&& let Some(ign_traits) = self.ignored_derived_traits.get(&encl_def_id)
689+
{
690+
let traits_str = ign_traits
691+
.iter()
692+
.map(|(trait_id, _)| format!("`{}`", self.tcx.item_name(*trait_id)))
693+
.collect::<Vec<_>>()
694+
.join(" and ");
695+
let plural_s = pluralize!(ign_traits.len());
696+
let article = if ign_traits.len() > 1 { "" } else { "a " };
697+
let is_are = if ign_traits.len() > 1 { "these are" } else { "this is" };
698+
let msg = format!(
699+
"`{}` has {}derived impl{} for the trait{} {}, but {} \
700+
intentionally ignored during dead code analysis",
701+
self.tcx.item_name(encl_def_id.to_def_id()),
702+
article,
703+
plural_s,
704+
plural_s,
705+
traits_str,
706+
is_are
707+
);
708+
let multispan = ign_traits
709+
.iter()
710+
.map(|(_, impl_id)| self.tcx.def_span(*impl_id))
711+
.collect::<Vec<_>>();
712+
err.span_note(multispan, &msg);
714713
}
715714
err.emit();
716715
});

compiler/rustc_passes/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
//!
55
//! This API is completely unstable and subject to change.
66
7+
#![allow(rustc::potential_query_instability)]
78
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
89
#![feature(crate_visibility_modifier)]
910
#![feature(iter_intersperse)]
1011
#![feature(let_else)]
12+
#![feature(let_chains)]
1113
#![feature(map_try_insert)]
1214
#![feature(min_specialization)]
1315
#![feature(nll)]
1416
#![feature(try_blocks)]
1517
#![recursion_limit = "256"]
16-
#![allow(rustc::potential_query_instability)]
1718

1819
#[macro_use]
1920
extern crate rustc_middle;

compiler/rustc_passes/src/liveness.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,11 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
332332
let def_id = local_def_id.to_def_id();
333333

334334
// Don't run unused pass for #[derive()]
335-
if let Some(parent) = self.tcx.parent(def_id) {
336-
if let DefKind::Impl = self.tcx.def_kind(parent.expect_local()) {
337-
if self.tcx.has_attr(parent, sym::automatically_derived) {
338-
return;
339-
}
340-
}
335+
if let Some(parent) = self.tcx.parent(def_id)
336+
&& let DefKind::Impl = self.tcx.def_kind(parent.expect_local())
337+
&& self.tcx.has_attr(parent, sym::automatically_derived)
338+
{
339+
return;
341340
}
342341

343342
// Don't run unused pass for #[naked]

compiler/rustc_passes/src/reachable.rs

+15-17
Original file line numberDiff line numberDiff line change
@@ -94,24 +94,22 @@ impl<'tcx> Visitor<'tcx> for ReachableContext<'tcx> {
9494
_ => None,
9595
};
9696

97-
if let Some(res) = res {
98-
if let Some(def_id) = res.opt_def_id().and_then(|def_id| def_id.as_local()) {
99-
if self.def_id_represents_local_inlined_item(def_id.to_def_id()) {
100-
self.worklist.push(def_id);
101-
} else {
102-
match res {
103-
// If this path leads to a constant, then we need to
104-
// recurse into the constant to continue finding
105-
// items that are reachable.
106-
Res::Def(DefKind::Const | DefKind::AssocConst, _) => {
107-
self.worklist.push(def_id);
108-
}
97+
if let Some(res) = res && let Some(def_id) = res.opt_def_id().and_then(|el| el.as_local()) {
98+
if self.def_id_represents_local_inlined_item(def_id.to_def_id()) {
99+
self.worklist.push(def_id);
100+
} else {
101+
match res {
102+
// If this path leads to a constant, then we need to
103+
// recurse into the constant to continue finding
104+
// items that are reachable.
105+
Res::Def(DefKind::Const | DefKind::AssocConst, _) => {
106+
self.worklist.push(def_id);
107+
}
109108

110-
// If this wasn't a static, then the destination is
111-
// surely reachable.
112-
_ => {
113-
self.reachable_symbols.insert(def_id);
114-
}
109+
// If this wasn't a static, then the destination is
110+
// surely reachable.
111+
_ => {
112+
self.reachable_symbols.insert(def_id);
115113
}
116114
}
117115
}

0 commit comments

Comments
 (0)