Skip to content

Commit 7d85104

Browse files
committed
Auto merge of rust-lang#104289 - Dylan-DPC:rollup-v7wei2t, r=Dylan-DPC
Rollup of 9 pull requests Successful merges: - rust-lang#100633 (Consider `#[must_use]` annotation on `async fn` as also affecting the `Future::Output`) - rust-lang#103445 (`#[test]`: Point at return type if `Termination` bound is unsatisfied) - rust-lang#103924 (Fix broken link in description of error code E0706) - rust-lang#104146 (Retry binding TCP Socket in remote-test-server) - rust-lang#104169 (Migrate `:target` rules to use CSS variables) - rust-lang#104202 (Fix ICE rust-lang#103748) - rust-lang#104216 (Don't ICE on operator trait methods with generic methods) - rust-lang#104217 (Display help message when fluent arg was referenced incorrectly) - rust-lang#104245 (Reduce default configuration's dependency upon static libstdcpp library (rust-lang#103606)) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 742d3f0 + 3781120 commit 7d85104

Some content is hidden

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

50 files changed

+384
-151
lines changed

compiler/rustc_builtin_macros/src/test.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub fn expand_test_or_bench(
112112
};
113113

114114
// Note: non-associated fn items are already handled by `expand_test_or_bench`
115-
if !matches!(item.kind, ast::ItemKind::Fn(_)) {
115+
let ast::ItemKind::Fn(fn_) = &item.kind else {
116116
let diag = &cx.sess.parse_sess.span_diagnostic;
117117
let msg = "the `#[test]` attribute may only be used on a non-associated function";
118118
let mut err = match item.kind {
@@ -130,7 +130,7 @@ pub fn expand_test_or_bench(
130130
.emit();
131131

132132
return vec![Annotatable::Item(item)];
133-
}
133+
};
134134

135135
// has_*_signature will report any errors in the type so compilation
136136
// will fail. We shouldn't try to expand in this case because the errors
@@ -141,12 +141,14 @@ pub fn expand_test_or_bench(
141141
return vec![Annotatable::Item(item)];
142142
}
143143

144-
let (sp, attr_sp) = (cx.with_def_site_ctxt(item.span), cx.with_def_site_ctxt(attr_sp));
144+
let sp = cx.with_def_site_ctxt(item.span);
145+
let ret_ty_sp = cx.with_def_site_ctxt(fn_.sig.decl.output.span());
146+
let attr_sp = cx.with_def_site_ctxt(attr_sp);
145147

146148
let test_id = Ident::new(sym::test, attr_sp);
147149

148150
// creates test::$name
149-
let test_path = |name| cx.path(sp, vec![test_id, Ident::from_str_and_span(name, sp)]);
151+
let test_path = |name| cx.path(ret_ty_sp, vec![test_id, Ident::from_str_and_span(name, sp)]);
150152

151153
// creates test::ShouldPanic::$name
152154
let should_panic_path = |name| {
@@ -192,7 +194,7 @@ pub fn expand_test_or_bench(
192194
vec![
193195
// super::$test_fn(b)
194196
cx.expr_call(
195-
sp,
197+
ret_ty_sp,
196198
cx.expr_path(cx.path(sp, vec![item.ident])),
197199
vec![cx.expr_ident(sp, b)],
198200
),
@@ -216,7 +218,11 @@ pub fn expand_test_or_bench(
216218
cx.expr_path(test_path("assert_test_result")),
217219
vec![
218220
// $test_fn()
219-
cx.expr_call(sp, cx.expr_path(cx.path(sp, vec![item.ident])), vec![]), // )
221+
cx.expr_call(
222+
ret_ty_sp,
223+
cx.expr_path(cx.path(sp, vec![item.ident])),
224+
vec![],
225+
), // )
220226
],
221227
), // }
222228
), // )

compiler/rustc_error_codes/src/error_codes/E0706.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ You might be interested in visiting the [async book] for further information.
5656
[`async-trait` crate]: https://crates.io/crates/async-trait
5757
[async-is-hard]: https://smallcultfollowing.com/babysteps/blog/2019/10/26/async-fn-in-traits-are-hard/
5858
[Generic Associated Types]: https://github.com/rust-lang/rust/issues/44265
59-
[async book]: https://rust-lang.github.io/async-book/07_workarounds/06_async_in_traits.html
59+
[async book]: https://rust-lang.github.io/async-book/07_workarounds/05_async_in_traits.html

compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,6 @@ hir_analysis_const_bound_for_non_const_trait =
150150
hir_analysis_self_in_impl_self =
151151
`Self` is not valid in the self type of an impl block
152152
.note = replace `Self` with a different type
153+
154+
hir_analysis_op_trait_generic_params =
155+
`{$method_name}` must not have any generic parameters

compiler/rustc_error_messages/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ use intl_memoizer::concurrent::IntlLangMemoizer;
3030
#[cfg(not(parallel_compiler))]
3131
use intl_memoizer::IntlLangMemoizer;
3232

33-
pub use fluent_bundle::{FluentArgs, FluentError, FluentValue};
33+
pub use fluent_bundle::{self, FluentArgs, FluentError, FluentValue};
34+
3435
pub use unic_langid::{langid, LanguageIdentifier};
3536

3637
// Generates `DEFAULT_LOCALE_RESOURCES` static and `fluent_generated` module.

compiler/rustc_errors/src/translation.rs

+29-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use crate::snippet::Style;
22
use crate::{DiagnosticArg, DiagnosticMessage, FluentBundle};
33
use rustc_data_structures::sync::Lrc;
4-
use rustc_error_messages::FluentArgs;
4+
use rustc_error_messages::{
5+
fluent_bundle::resolver::errors::{ReferenceKind, ResolverError},
6+
FluentArgs, FluentError,
7+
};
58
use std::borrow::Cow;
69

710
/// Convert diagnostic arguments (a rustc internal type that exists to implement
@@ -102,14 +105,31 @@ pub trait Translate {
102105
.or_else(|| translate_with_bundle(self.fallback_fluent_bundle()))
103106
.map(|(translated, errs)| {
104107
// Always bail out for errors with the fallback bundle.
105-
assert!(
106-
errs.is_empty(),
107-
"identifier: {:?}, attr: {:?}, args: {:?}, errors: {:?}",
108-
identifier,
109-
attr,
110-
args,
111-
errs
112-
);
108+
109+
let mut help_messages = vec![];
110+
111+
if !errs.is_empty() {
112+
for error in &errs {
113+
match error {
114+
FluentError::ResolverError(ResolverError::Reference(
115+
ReferenceKind::Message { id, .. },
116+
)) if args.iter().any(|(arg_id, _)| arg_id == id) => {
117+
help_messages.push(format!("Argument `{id}` exists but was not referenced correctly. Try using `{{${id}}}` instead"));
118+
}
119+
_ => {}
120+
}
121+
}
122+
123+
panic!(
124+
"Encountered errors while formatting message for `{identifier}`\n\
125+
help: {}\n\
126+
attr: `{attr:?}`\n\
127+
args: `{args:?}`\n\
128+
errors: `{errs:?}`",
129+
help_messages.join("\nhelp: ")
130+
);
131+
}
132+
113133
translated
114134
})
115135
.expect("failed to find message in primary or fallback fluent bundles")

compiler/rustc_hir_typeck/src/errors.rs

+8
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,11 @@ pub struct AddMissingParenthesesInRange {
125125
#[suggestion_part(code = ")")]
126126
pub right: Span,
127127
}
128+
129+
#[derive(Diagnostic)]
130+
#[diag(hir_analysis_op_trait_generic_params)]
131+
pub struct OpMethodGenericParams {
132+
#[primary_span]
133+
pub span: Span,
134+
pub method_name: String,
135+
}

compiler/rustc_hir_typeck/src/method/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod suggest;
1010
pub use self::suggest::SelfSource;
1111
pub use self::MethodError::*;
1212

13+
use crate::errors::OpMethodGenericParams;
1314
use crate::{Expectation, FnCtxt};
1415
use rustc_data_structures::sync::Lrc;
1516
use rustc_errors::{Applicability, Diagnostic};
@@ -443,7 +444,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
443444
};
444445
let def_id = method_item.def_id;
445446
let generics = tcx.generics_of(def_id);
446-
assert_eq!(generics.params.len(), 0);
447+
448+
if generics.params.len() != 0 {
449+
tcx.sess.emit_fatal(OpMethodGenericParams {
450+
span: tcx.def_span(method_item.def_id),
451+
method_name: m_name.to_string(),
452+
});
453+
}
447454

448455
debug!("lookup_in_trait_adjusted: method_item={:?}", method_item);
449456
let mut obligations = vec![];

compiler/rustc_lint/src/unused.rs

+23-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::def::{DefKind, Res};
99
use rustc_hir::def_id::DefId;
1010
use rustc_infer::traits::util::elaborate_predicates_with_span;
1111
use rustc_middle::ty::adjustment;
12-
use rustc_middle::ty::{self, Ty};
12+
use rustc_middle::ty::{self, DefIdTree, Ty};
1313
use rustc_span::symbol::Symbol;
1414
use rustc_span::symbol::{kw, sym};
1515
use rustc_span::{BytePos, Span};
@@ -87,17 +87,33 @@ declare_lint_pass!(UnusedResults => [UNUSED_MUST_USE, UNUSED_RESULTS]);
8787

8888
impl<'tcx> LateLintPass<'tcx> for UnusedResults {
8989
fn check_stmt(&mut self, cx: &LateContext<'_>, s: &hir::Stmt<'_>) {
90-
let expr = match s.kind {
91-
hir::StmtKind::Semi(ref expr) => &**expr,
92-
_ => return,
93-
};
90+
let hir::StmtKind::Semi(expr) = s.kind else { return; };
9491

9592
if let hir::ExprKind::Ret(..) = expr.kind {
9693
return;
9794
}
9895

96+
if let hir::ExprKind::Match(await_expr, _arms, hir::MatchSource::AwaitDesugar) = expr.kind
97+
&& let ty = cx.typeck_results().expr_ty(&await_expr)
98+
&& let ty::Opaque(future_def_id, _) = ty.kind()
99+
&& cx.tcx.ty_is_opaque_future(ty)
100+
// FIXME: This also includes non-async fns that return `impl Future`.
101+
&& let async_fn_def_id = cx.tcx.parent(*future_def_id)
102+
&& check_must_use_def(
103+
cx,
104+
async_fn_def_id,
105+
expr.span,
106+
"output of future returned by ",
107+
"",
108+
)
109+
{
110+
// We have a bare `foo().await;` on an opaque type from an async function that was
111+
// annotated with `#[must_use]`.
112+
return;
113+
}
114+
99115
let ty = cx.typeck_results().expr_ty(&expr);
100-
let type_permits_lack_of_use = check_must_use_ty(cx, ty, &expr, s.span, "", "", 1);
116+
let type_permits_lack_of_use = check_must_use_ty(cx, ty, &expr, expr.span, "", "", 1);
101117

102118
let mut fn_warned = false;
103119
let mut op_warned = false;
@@ -119,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
119135
_ => None,
120136
};
121137
if let Some(def_id) = maybe_def_id {
122-
fn_warned = check_must_use_def(cx, def_id, s.span, "return value of ", "");
138+
fn_warned = check_must_use_def(cx, def_id, expr.span, "return value of ", "");
123139
} else if type_permits_lack_of_use {
124140
// We don't warn about unused unit or uninhabited types.
125141
// (See https://github.com/rust-lang/rust/issues/43806 for details.)

compiler/rustc_middle/src/values.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ fn find_item_ty_spans(
185185
});
186186
if check_params && let Some(args) = path.segments.last().unwrap().args {
187187
let params_in_repr = tcx.params_in_repr(def_id);
188-
for (i, arg) in args.args.iter().enumerate() {
188+
// the domain size check is needed because the HIR may not be well-formed at this point
189+
for (i, arg) in args.args.iter().enumerate().take(params_in_repr.domain_size()) {
189190
if let hir::GenericArg::Type(ty) = arg && params_in_repr.contains(i as u32) {
190191
find_item_ty_spans(tcx, ty, needle, spans, seen_representable);
191192
}

compiler/rustc_passes/src/check_attr.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl CheckAttrVisitor<'_> {
139139
sym::collapse_debuginfo => self.check_collapse_debuginfo(attr, span, target),
140140
sym::const_trait => self.check_const_trait(attr, span, target),
141141
sym::must_not_suspend => self.check_must_not_suspend(&attr, span, target),
142-
sym::must_use => self.check_must_use(hir_id, &attr, span, target),
142+
sym::must_use => self.check_must_use(hir_id, &attr, target),
143143
sym::rustc_pass_by_value => self.check_pass_by_value(&attr, span, target),
144144
sym::rustc_allow_incoherent_impl => {
145145
self.check_allow_incoherent_impl(&attr, span, target)
@@ -1163,17 +1163,7 @@ impl CheckAttrVisitor<'_> {
11631163
}
11641164

11651165
/// Warns against some misuses of `#[must_use]`
1166-
fn check_must_use(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) -> bool {
1167-
let node = self.tcx.hir().get(hir_id);
1168-
if let Some(kind) = node.fn_kind() && let rustc_hir::IsAsync::Async = kind.asyncness() {
1169-
self.tcx.emit_spanned_lint(
1170-
UNUSED_ATTRIBUTES,
1171-
hir_id,
1172-
attr.span,
1173-
errors::MustUseAsync { span }
1174-
);
1175-
}
1176-
1166+
fn check_must_use(&self, hir_id: HirId, attr: &Attribute, target: Target) -> bool {
11771167
if !matches!(
11781168
target,
11791169
Target::Fn

config.toml.example

+4-3
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ changelog-seen = 2
8787
# this flag will indicate that this version check should not be done.
8888
#version-check = true
8989

90-
# Link libstdc++ statically into the rustc_llvm instead of relying on a
91-
# dynamic version to be available.
92-
#static-libstdcpp = true
90+
# When true, link libstdc++ statically into the rustc_llvm.
91+
# This is useful if you don't want to use the dynamic version of that
92+
# library provided by LLVM.
93+
#static-libstdcpp = false
9394

9495
# Whether to use Ninja to build LLVM. This runs much faster than make.
9596
#ninja = true

src/bootstrap/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ impl Config {
781781
config.llvm_optimize = true;
782782
config.ninja_in_file = true;
783783
config.llvm_version_check = true;
784-
config.llvm_static_stdcpp = true;
784+
config.llvm_static_stdcpp = false;
785785
config.backtrace = true;
786786
config.rust_optimize = true;
787787
config.rust_optimize_tests = true;

src/ci/run.sh

+4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ else
123123
# (And PGO is its own can of worms).
124124
if [ "$NO_DOWNLOAD_CI_LLVM" = "" ]; then
125125
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set llvm.download-ci-llvm=if-available"
126+
else
127+
# When building for CI we want to use the static C++ Standard library
128+
# included with LLVM, since a dynamic libstdcpp may not be available.
129+
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set llvm.static-libstdcpp"
126130
fi
127131
fi
128132

src/librustdoc/html/static/css/rustdoc.css

+2
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,8 @@ h3.variant {
12691269

12701270
:target {
12711271
padding-right: 3px;
1272+
background-color: var(--target-background-color);
1273+
border-right: 3px solid var(--target-border-color);
12721274
}
12731275

12741276
.notable-traits-tooltip {

src/librustdoc/html/static/css/themes/ayu.css

+2-5
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ Original by Dempfi (https://github.com/dempfi/ayu)
6363
--test-arrow-background-color: rgba(57, 175, 215, 0.09);
6464
--test-arrow-hover-color: #c5c5c5;
6565
--test-arrow-hover-background-color: rgba(57, 175, 215, 0.368);
66+
--target-background-color: rgba(255, 236, 164, 0.06);
67+
--target-border-color: rgba(255, 180, 76, 0.85);
6668
--rust-logo-filter: drop-shadow(1px 0 0px #fff)
6769
drop-shadow(0 1px 0 #fff)
6870
drop-shadow(-1px 0 0 #fff)
@@ -168,11 +170,6 @@ details.rustdoc-toggle > summary::before {
168170
color: #788797;
169171
}
170172

171-
:target {
172-
background: rgba(255, 236, 164, 0.06);
173-
border-right: 3px solid rgba(255, 180, 76, 0.85);
174-
}
175-
176173
.search-failed a {
177174
color: #39AFD7;
178175
}

src/librustdoc/html/static/css/themes/dark.css

+2-5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
--test-arrow-background-color: rgba(78, 139, 202, 0.2);
5959
--test-arrow-hover-color: #dedede;
6060
--test-arrow-hover-background-color: #4e8bca;
61+
--target-background-color: #494a3d;
62+
--target-border-color: #bb7410;
6163
--rust-logo-filter: drop-shadow(1px 0 0px #fff)
6264
drop-shadow(0 1px 0 #fff)
6365
drop-shadow(-1px 0 0 #fff)
@@ -90,11 +92,6 @@ details.rustdoc-toggle > summary::before {
9092
filter: invert(100%);
9193
}
9294

93-
:target {
94-
background-color: #494a3d;
95-
border-right: 3px solid #bb7410;
96-
}
97-
9895
.search-failed a {
9996
color: #0089ff;
10097
}

src/librustdoc/html/static/css/themes/light.css

+2-5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
--test-arrow-background-color: rgba(78, 139, 202, 0.2);
5959
--test-arrow-hover-color: #f5f5f5;
6060
--test-arrow-hover-background-color: #4e8bca;
61+
--target-background-color: #fdFfd3;
62+
--target-border-color: #ad7c37;
6163
--rust-logo-filter: initial;
6264
/* match border-color; uses https://codepen.io/sosuke/pen/Pjoqqp */
6365
--crate-search-div-filter: invert(100%) sepia(0%) saturate(4223%) hue-rotate(289deg)
@@ -83,11 +85,6 @@ body.source .example-wrap pre.rust a {
8385
background: #eee;
8486
}
8587

86-
:target {
87-
background: #FDFFD3;
88-
border-right: 3px solid #AD7C37;
89-
}
90-
9188
.search-failed a {
9289
color: #3873AD;
9390
}

0 commit comments

Comments
 (0)