Skip to content

Commit 8cf20db

Browse files
committed
Auto merge of rust-lang#120249 - matthiaskrgr:rollup-h646lvq, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#119433 (rc,sync: Do not create references to uninitialized values) - rust-lang#119460 (coverage: Never emit improperly-ordered coverage regions) - rust-lang#119766 (Split tait and impl trait in assoc items logic) - rust-lang#120160 (Manually implement derived `NonZero` traits.) - rust-lang#120177 (Remove duplicate dependencies for rustc) - rust-lang#120183 (Add `#[coverage(off)]` to closures introduced by `#[test]` and `#[bench]`) - rust-lang#120185 (coverage: Don't instrument `#[automatically_derived]` functions) - rust-lang#120201 (Bump some deps with syn 1.0 dependencies) - rust-lang#120246 (Re-add estebank to review rotation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d5fd099 + f341954 commit 8cf20db

Some content is hidden

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

47 files changed

+881
-266
lines changed

Cargo.lock

+31-46
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,12 @@ dependencies = [
310310

311311
[[package]]
312312
name = "bstr"
313-
version = "1.5.0"
313+
version = "1.9.0"
314314
source = "registry+https://github.com/rust-lang/crates.io-index"
315-
checksum = "a246e68bb43f6cd9db24bea052a53e40405417c5fb372e3d1a8a7f770a564ef5"
315+
checksum = "c48f0051a4b4c5e0b6d365cd04af53aeaa209e3cc15ec2cdb69e73cc87fbd0dc"
316316
dependencies = [
317317
"memchr",
318-
"once_cell",
319-
"regex-automata 0.1.10",
318+
"regex-automata 0.4.3",
320319
"serde",
321320
]
322321

@@ -373,9 +372,9 @@ dependencies = [
373372

374373
[[package]]
375374
name = "byteorder"
376-
version = "1.4.3"
375+
version = "1.5.0"
377376
source = "registry+https://github.com/rust-lang/crates.io-index"
378-
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
377+
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
379378

380379
[[package]]
381380
name = "bytes"
@@ -1589,11 +1588,11 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
15891588

15901589
[[package]]
15911590
name = "globset"
1592-
version = "0.4.10"
1591+
version = "0.4.13"
15931592
source = "registry+https://github.com/rust-lang/crates.io-index"
1594-
checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc"
1593+
checksum = "759c97c1e17c55525b57192c06a267cda0ac5210b222d6b82189a2338fa1c13d"
15951594
dependencies = [
1596-
"aho-corasick 0.7.20",
1595+
"aho-corasick 1.0.2",
15971596
"bstr",
15981597
"fnv",
15991598
"log",
@@ -2370,9 +2369,9 @@ dependencies = [
23702369

23712370
[[package]]
23722371
name = "memchr"
2373-
version = "2.5.0"
2372+
version = "2.7.1"
23742373
source = "registry+https://github.com/rust-lang/crates.io-index"
2375-
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
2374+
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
23762375
dependencies = [
23772376
"compiler_builtins",
23782377
"rustc-std-workspace-core",
@@ -2588,9 +2587,9 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
25882587

25892588
[[package]]
25902589
name = "object"
2591-
version = "0.32.1"
2590+
version = "0.32.2"
25922591
source = "registry+https://github.com/rust-lang/crates.io-index"
2593-
checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0"
2592+
checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
25942593
dependencies = [
25952594
"compiler_builtins",
25962595
"crc32fast",
@@ -3183,6 +3182,12 @@ dependencies = [
31833182
"memchr",
31843183
]
31853184

3185+
[[package]]
3186+
name = "regex-automata"
3187+
version = "0.4.3"
3188+
source = "registry+https://github.com/rust-lang/crates.io-index"
3189+
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
3190+
31863191
[[package]]
31873192
name = "regex-syntax"
31883193
version = "0.6.29"
@@ -4789,12 +4794,12 @@ checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06"
47894794

47904795
[[package]]
47914796
name = "ruzstd"
4792-
version = "0.4.0"
4797+
version = "0.5.0"
47934798
source = "registry+https://github.com/rust-lang/crates.io-index"
4794-
checksum = "ac3ffab8f9715a0d455df4bbb9d21e91135aab3cd3ca187af0cd0c3c3f868fdc"
4799+
checksum = "58c4eb8a81997cf040a091d1f7e1938aeab6749d3a0dfa73af43cdc32393483d"
47954800
dependencies = [
47964801
"byteorder",
4797-
"thiserror-core",
4802+
"derive_more",
47984803
"twox-hash",
47994804
]
48004805

@@ -5357,26 +5362,6 @@ dependencies = [
53575362
"thiserror-impl",
53585363
]
53595364

5360-
[[package]]
5361-
name = "thiserror-core"
5362-
version = "1.0.38"
5363-
source = "registry+https://github.com/rust-lang/crates.io-index"
5364-
checksum = "0d97345f6437bb2004cd58819d8a9ef8e36cdd7661c2abc4bbde0a7c40d9f497"
5365-
dependencies = [
5366-
"thiserror-core-impl",
5367-
]
5368-
5369-
[[package]]
5370-
name = "thiserror-core-impl"
5371-
version = "1.0.38"
5372-
source = "registry+https://github.com/rust-lang/crates.io-index"
5373-
checksum = "10ac1c5050e43014d16b2f94d0d2ce79e65ffdd8b38d8048f9c8f6a8a6da62ac"
5374-
dependencies = [
5375-
"proc-macro2",
5376-
"quote",
5377-
"syn 1.0.109",
5378-
]
5379-
53805365
[[package]]
53815366
name = "thiserror-impl"
53825367
version = "1.0.47"
@@ -5424,7 +5409,7 @@ name = "tidy"
54245409
version = "0.1.0"
54255410
dependencies = [
54265411
"cargo-platform",
5427-
"cargo_metadata 0.15.4",
5412+
"cargo_metadata 0.18.0",
54285413
"ignore",
54295414
"lazy_static",
54305415
"miropt-test-tools",
@@ -5749,28 +5734,28 @@ dependencies = [
57495734

57505735
[[package]]
57515736
name = "unic-langid"
5752-
version = "0.9.1"
5737+
version = "0.9.4"
57535738
source = "registry+https://github.com/rust-lang/crates.io-index"
5754-
checksum = "398f9ad7239db44fd0f80fe068d12ff22d78354080332a5077dc6f52f14dcf2f"
5739+
checksum = "238722e6d794ed130f91f4ea33e01fcff4f188d92337a21297892521c72df516"
57555740
dependencies = [
57565741
"unic-langid-impl",
57575742
"unic-langid-macros",
57585743
]
57595744

57605745
[[package]]
57615746
name = "unic-langid-impl"
5762-
version = "0.9.1"
5747+
version = "0.9.4"
57635748
source = "registry+https://github.com/rust-lang/crates.io-index"
5764-
checksum = "e35bfd2f2b8796545b55d7d3fd3e89a0613f68a0d1c8bc28cb7ff96b411a35ff"
5749+
checksum = "4bd55a2063fdea4ef1f8633243a7b0524cbeef1905ae04c31a1c9b9775c55bc6"
57655750
dependencies = [
57665751
"tinystr",
57675752
]
57685753

57695754
[[package]]
57705755
name = "unic-langid-macros"
5771-
version = "0.9.1"
5756+
version = "0.9.4"
57725757
source = "registry+https://github.com/rust-lang/crates.io-index"
5773-
checksum = "055e618bf694161ffff0466d95cef3e1a5edc59f6ba1888e97801f2b4ebdc4fe"
5758+
checksum = "5c854cefb82ff2816410ce606acbad1b3af065140907b29be9229040752b83ec"
57745759
dependencies = [
57755760
"proc-macro-hack",
57765761
"tinystr",
@@ -5780,13 +5765,13 @@ dependencies = [
57805765

57815766
[[package]]
57825767
name = "unic-langid-macros-impl"
5783-
version = "0.9.1"
5768+
version = "0.9.4"
57845769
source = "registry+https://github.com/rust-lang/crates.io-index"
5785-
checksum = "1f5cdec05b907f4e2f6843f4354f4ce6a5bebe1a56df320a49134944477ce4d8"
5770+
checksum = "fea2a4c80deb4fb3ca51f66b5e2dd91e3642bbce52234bcf22e41668281208e4"
57865771
dependencies = [
57875772
"proc-macro-hack",
57885773
"quote",
5789-
"syn 1.0.109",
5774+
"syn 2.0.32",
57905775
"unic-langid-impl",
57915776
]
57925777

compiler/rustc_builtin_macros/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![doc(rust_logo)]
77
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
88
#![feature(array_windows)]
9+
#![feature(assert_matches)]
910
#![feature(box_patterns)]
1011
#![feature(decl_macro)]
1112
#![feature(if_let_guard)]

compiler/rustc_builtin_macros/src/test.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_errors::{Applicability, DiagnosticBuilder, Level};
99
use rustc_expand::base::*;
1010
use rustc_span::symbol::{sym, Ident, Symbol};
1111
use rustc_span::{ErrorGuaranteed, FileNameDisplayPreference, Span};
12+
use std::assert_matches::assert_matches;
1213
use std::iter;
1314
use thin_vec::{thin_vec, ThinVec};
1415

@@ -182,6 +183,16 @@ pub fn expand_test_or_bench(
182183
// creates $name: $expr
183184
let field = |name, expr| cx.field_imm(sp, Ident::from_str_and_span(name, sp), expr);
184185

186+
// Adds `#[coverage(off)]` to a closure, so it won't be instrumented in
187+
// `-Cinstrument-coverage` builds.
188+
// This requires `#[allow_internal_unstable(coverage_attribute)]` on the
189+
// corresponding macro declaration in `core::macros`.
190+
let coverage_off = |mut expr: P<ast::Expr>| {
191+
assert_matches!(expr.kind, ast::ExprKind::Closure(_));
192+
expr.attrs.push(cx.attr_nested_word(sym::coverage, sym::off, sp));
193+
expr
194+
};
195+
185196
let test_fn = if is_bench {
186197
// A simple ident for a lambda
187198
let b = Ident::from_str_and_span("b", attr_sp);
@@ -190,8 +201,9 @@ pub fn expand_test_or_bench(
190201
sp,
191202
cx.expr_path(test_path("StaticBenchFn")),
192203
thin_vec![
204+
// #[coverage(off)]
193205
// |b| self::test::assert_test_result(
194-
cx.lambda1(
206+
coverage_off(cx.lambda1(
195207
sp,
196208
cx.expr_call(
197209
sp,
@@ -206,16 +218,17 @@ pub fn expand_test_or_bench(
206218
],
207219
),
208220
b,
209-
), // )
221+
)), // )
210222
],
211223
)
212224
} else {
213225
cx.expr_call(
214226
sp,
215227
cx.expr_path(test_path("StaticTestFn")),
216228
thin_vec![
229+
// #[coverage(off)]
217230
// || {
218-
cx.lambda0(
231+
coverage_off(cx.lambda0(
219232
sp,
220233
// test::assert_test_result(
221234
cx.expr_call(
@@ -230,7 +243,7 @@ pub fn expand_test_or_bench(
230243
), // )
231244
],
232245
), // }
233-
), // )
246+
)), // )
234247
],
235248
)
236249
};

compiler/rustc_hir_analysis/src/collect/type_of.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,13 @@ pub(super) fn type_of_opaque(
530530
Ok(ty::EarlyBinder::bind(match tcx.hir_node_by_def_id(def_id) {
531531
Node::Item(item) => match item.kind {
532532
ItemKind::OpaqueTy(OpaqueTy {
533-
origin: hir::OpaqueTyOrigin::TyAlias { .. },
533+
origin: hir::OpaqueTyOrigin::TyAlias { in_assoc_ty: false },
534534
..
535535
}) => opaque::find_opaque_ty_constraints_for_tait(tcx, def_id),
536+
ItemKind::OpaqueTy(OpaqueTy {
537+
origin: hir::OpaqueTyOrigin::TyAlias { in_assoc_ty: true },
538+
..
539+
}) => opaque::find_opaque_ty_constraints_for_impl_trait_in_assoc_type(tcx, def_id),
536540
// Opaque types desugared from `impl Trait`.
537541
ItemKind::OpaqueTy(&OpaqueTy {
538542
origin:

compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs

+72-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,60 @@ pub fn test_opaque_hidden_types(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed>
2323
res
2424
}
2525

26+
/// Checks "defining uses" of opaque `impl Trait` in associated types.
27+
/// These can only be defined by associated items of the same trait.
28+
#[instrument(skip(tcx), level = "debug")]
29+
pub(super) fn find_opaque_ty_constraints_for_impl_trait_in_assoc_type(
30+
tcx: TyCtxt<'_>,
31+
def_id: LocalDefId,
32+
) -> Ty<'_> {
33+
let mut parent_def_id = def_id;
34+
while tcx.def_kind(parent_def_id) == def::DefKind::OpaqueTy {
35+
// Account for `type Alias = impl Trait<Foo = impl Trait>;` (#116031)
36+
parent_def_id = tcx.local_parent(parent_def_id);
37+
}
38+
let impl_def_id = tcx.local_parent(parent_def_id);
39+
match tcx.def_kind(impl_def_id) {
40+
DefKind::Impl { .. } => {}
41+
other => bug!("invalid impl trait in assoc type parent: {other:?}"),
42+
}
43+
44+
let mut locator = TaitConstraintLocator { def_id, tcx, found: None, typeck_types: vec![] };
45+
46+
for &assoc_id in tcx.associated_item_def_ids(impl_def_id) {
47+
let assoc = tcx.associated_item(assoc_id);
48+
match assoc.kind {
49+
ty::AssocKind::Const | ty::AssocKind::Fn => {
50+
locator.check(assoc_id.expect_local(), ImplTraitSource::AssocTy)
51+
}
52+
// Associated types don't have bodies, so they can't constrain hidden types
53+
ty::AssocKind::Type => {}
54+
}
55+
}
56+
57+
if let Some(hidden) = locator.found {
58+
// Only check against typeck if we didn't already error
59+
if !hidden.ty.references_error() {
60+
for concrete_type in locator.typeck_types {
61+
if concrete_type.ty != tcx.erase_regions(hidden.ty)
62+
&& !(concrete_type, hidden).references_error()
63+
{
64+
hidden.report_mismatch(&concrete_type, def_id, tcx).emit();
65+
}
66+
}
67+
}
68+
69+
hidden.ty
70+
} else {
71+
let reported = tcx.dcx().emit_err(UnconstrainedOpaqueType {
72+
span: tcx.def_span(def_id),
73+
name: tcx.item_name(parent_def_id.to_def_id()),
74+
what: "impl",
75+
});
76+
Ty::new_error(tcx, reported)
77+
}
78+
}
79+
2680
/// Checks "defining uses" of opaque `impl Trait` types to ensure that they meet the restrictions
2781
/// laid for "higher-order pattern unification".
2882
/// This ensures that inference is tractable.
@@ -128,9 +182,15 @@ struct TaitConstraintLocator<'tcx> {
128182
typeck_types: Vec<ty::OpaqueHiddenType<'tcx>>,
129183
}
130184

185+
#[derive(Debug)]
186+
enum ImplTraitSource {
187+
AssocTy,
188+
TyAlias,
189+
}
190+
131191
impl TaitConstraintLocator<'_> {
132192
#[instrument(skip(self), level = "debug")]
133-
fn check(&mut self, item_def_id: LocalDefId) {
193+
fn check(&mut self, item_def_id: LocalDefId, source: ImplTraitSource) {
134194
// Don't try to check items that cannot possibly constrain the type.
135195
if !self.tcx.has_typeck_results(item_def_id) {
136196
debug!("no constraint: no typeck results");
@@ -182,7 +242,13 @@ impl TaitConstraintLocator<'_> {
182242
continue;
183243
}
184244
constrained = true;
185-
if !self.tcx.opaque_types_defined_by(item_def_id).contains(&self.def_id) {
245+
let opaque_types_defined_by = match source {
246+
ImplTraitSource::AssocTy => {
247+
self.tcx.impl_trait_in_assoc_types_defined_by(item_def_id)
248+
}
249+
ImplTraitSource::TyAlias => self.tcx.opaque_types_defined_by(item_def_id),
250+
};
251+
if !opaque_types_defined_by.contains(&self.def_id) {
186252
self.tcx.dcx().emit_err(TaitForwardCompat {
187253
span: hidden_type.span,
188254
item_span: self
@@ -240,29 +306,29 @@ impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> {
240306
}
241307
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
242308
if let hir::ExprKind::Closure(closure) = ex.kind {
243-
self.check(closure.def_id);
309+
self.check(closure.def_id, ImplTraitSource::TyAlias);
244310
}
245311
intravisit::walk_expr(self, ex);
246312
}
247313
fn visit_item(&mut self, it: &'tcx Item<'tcx>) {
248314
trace!(?it.owner_id);
249315
// The opaque type itself or its children are not within its reveal scope.
250316
if it.owner_id.def_id != self.def_id {
251-
self.check(it.owner_id.def_id);
317+
self.check(it.owner_id.def_id, ImplTraitSource::TyAlias);
252318
intravisit::walk_item(self, it);
253319
}
254320
}
255321
fn visit_impl_item(&mut self, it: &'tcx ImplItem<'tcx>) {
256322
trace!(?it.owner_id);
257323
// The opaque type itself or its children are not within its reveal scope.
258324
if it.owner_id.def_id != self.def_id {
259-
self.check(it.owner_id.def_id);
325+
self.check(it.owner_id.def_id, ImplTraitSource::TyAlias);
260326
intravisit::walk_impl_item(self, it);
261327
}
262328
}
263329
fn visit_trait_item(&mut self, it: &'tcx TraitItem<'tcx>) {
264330
trace!(?it.owner_id);
265-
self.check(it.owner_id.def_id);
331+
self.check(it.owner_id.def_id, ImplTraitSource::TyAlias);
266332
intravisit::walk_trait_item(self, it);
267333
}
268334
fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) {

0 commit comments

Comments
 (0)