Skip to content
/ rust Public
forked from rust-lang/rust

Commit 97c966b

Browse files
committed
Auto merge of rust-lang#139552 - matthiaskrgr:rollup-b194mk8, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - rust-lang#139494 (Restrict some queries by def-kind more) - rust-lang#139496 (Revert r-a changes of rust-lang#139455) - rust-lang#139506 (add missing word in doc comment (part 2)) - rust-lang#139515 (Improve presentation of closure signature mismatch from `Fn` trait goal) - rust-lang#139520 (compiletest maintenance: sort deps and drop dep on `anyhow`) - rust-lang#139523 (Rustc dev guide subtree update) - rust-lang#139526 (Fix deprecation note for std::intrinsics) - rust-lang#139528 (compiletest: Remove the `--logfile` flag) - rust-lang#139541 (Instantiate higher-ranked transmute goal w/ placeholders before emitting sub-obligations) - rust-lang#139547 (Update library tracking issue template to set S-tracking-unimplemented) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c1b8b7e + f2fd24d commit 97c966b

File tree

37 files changed

+207
-113
lines changed

37 files changed

+207
-113
lines changed

.github/ISSUE_TEMPLATE/library_tracking_issue.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: Library Tracking Issue
33
about: A tracking issue for an unstable library feature.
44
title: Tracking Issue for XXX
5-
labels: C-tracking-issue, T-libs-api
5+
labels: C-tracking-issue, T-libs-api, S-tracking-unimplemented
66
---
77
<!--
88
Thank you for creating a tracking issue!
@@ -49,6 +49,8 @@ For larger features, more steps might be involved.
4949
If the feature is changed later, please add those PRs here as well.
5050
-->
5151

52+
(Remember to update the `S-tracking-*` label when checking boxes.)
53+
5254
- [ ] Implementation: #...
5355
- [ ] Final comment period (FCP)[^1]
5456
- [ ] Stabilization PR

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,6 @@ name = "compiletest"
718718
version = "0.0.0"
719719
dependencies = [
720720
"anstyle-svg",
721-
"anyhow",
722721
"build_helper",
723722
"colored",
724723
"diff",

compiler/rustc_errors/src/diagnostic.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -647,9 +647,9 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
647647
#[rustc_lint_diagnostics]
648648
pub fn note_expected_found(
649649
&mut self,
650-
expected_label: &dyn fmt::Display,
650+
expected_label: &str,
651651
expected: DiagStyledString,
652-
found_label: &dyn fmt::Display,
652+
found_label: &str,
653653
found: DiagStyledString,
654654
) -> &mut Self {
655655
self.note_expected_found_extra(
@@ -665,9 +665,9 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
665665
#[rustc_lint_diagnostics]
666666
pub fn note_expected_found_extra(
667667
&mut self,
668-
expected_label: &dyn fmt::Display,
668+
expected_label: &str,
669669
expected: DiagStyledString,
670-
found_label: &dyn fmt::Display,
670+
found_label: &str,
671671
found: DiagStyledString,
672672
expected_extra: DiagStyledString,
673673
found_extra: DiagStyledString,

compiler/rustc_hir_analysis/src/collect.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
//! At present, however, we do run collection across all items in the
1515
//! crate as a kind of pass. This should eventually be factored away.
1616
17+
use std::assert_matches::assert_matches;
1718
use std::cell::Cell;
1819
use std::iter;
1920
use std::ops::Bound;
@@ -1344,7 +1345,8 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn
13441345
compute_sig_of_foreign_fn_decl(tcx, def_id, sig.decl, abi, sig.header.safety())
13451346
}
13461347

1347-
Ctor(data) | Variant(hir::Variant { data, .. }) if data.ctor().is_some() => {
1348+
Ctor(data) => {
1349+
assert_matches!(data.ctor(), Some(_));
13481350
let adt_def_id = tcx.hir_get_parent_item(hir_id).def_id.to_def_id();
13491351
let ty = tcx.type_of(adt_def_id).instantiate_identity();
13501352
let inputs = data.fields().iter().map(|f| tcx.type_of(f.def_id).instantiate_identity());

compiler/rustc_hir_analysis/src/variance/mod.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ fn variances_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Variance] {
4444
return &[];
4545
}
4646

47-
match tcx.def_kind(item_def_id) {
47+
let kind = tcx.def_kind(item_def_id);
48+
match kind {
4849
DefKind::Fn
4950
| DefKind::AssocFn
5051
| DefKind::Enum
5152
| DefKind::Struct
5253
| DefKind::Union
53-
| DefKind::Variant
5454
| DefKind::Ctor(..) => {
5555
// These are inferred.
5656
let crate_map = tcx.crate_variances(());
@@ -89,7 +89,11 @@ fn variances_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Variance] {
8989
}
9090

9191
// Variance not relevant.
92-
span_bug!(tcx.def_span(item_def_id), "asked to compute variance for wrong kind of item");
92+
span_bug!(
93+
tcx.def_span(item_def_id),
94+
"asked to compute variance for {}",
95+
kind.descr(item_def_id.to_def_id())
96+
);
9397
}
9498

9599
#[derive(Debug, Copy, Clone)]

compiler/rustc_lint/src/lints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ impl Subdiagnostic for BuiltinClashingExternSub<'_> {
513513
expected_str.push(self.expected.fn_sig(self.tcx).to_string(), false);
514514
let mut found_str = DiagStyledString::new();
515515
found_str.push(self.found.fn_sig(self.tcx).to_string(), true);
516-
diag.note_expected_found(&"", expected_str, &"", found_str);
516+
diag.note_expected_found("", expected_str, "", found_str);
517517
}
518518
}
519519

compiler/rustc_metadata/src/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,6 @@ fn should_encode_variances<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: Def
10991099
DefKind::Struct
11001100
| DefKind::Union
11011101
| DefKind::Enum
1102-
| DefKind::Variant
11031102
| DefKind::OpaqueTy
11041103
| DefKind::Fn
11051104
| DefKind::Ctor(..)
@@ -1109,6 +1108,7 @@ fn should_encode_variances<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: Def
11091108
matches!(tcx.opt_rpitit_info(def_id), Some(ty::ImplTraitInTraitData::Trait { .. }))
11101109
}
11111110
DefKind::Mod
1111+
| DefKind::Variant
11121112
| DefKind::Field
11131113
| DefKind::AssocConst
11141114
| DefKind::TyParam

compiler/rustc_trait_selection/src/error_reporting/infer/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
967967
format!("...so that the {}", sup_trace.cause.as_requirement_str()),
968968
);
969969

970-
err.note_expected_found(&"", sup_expected, &"", sup_found);
970+
err.note_expected_found("", sup_expected, "", sup_found);
971971
return if sub_region.is_error() | sup_region.is_error() {
972972
err.delay_as_bug()
973973
} else {

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

+51-25
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use core::ops::ControlFlow;
22
use std::borrow::Cow;
33
use std::path::PathBuf;
44

5+
use rustc_abi::ExternAbi;
56
use rustc_ast::TraitObjectSyntax;
67
use rustc_data_structures::fx::FxHashMap;
78
use rustc_data_structures::unord::UnordSet;
@@ -2799,32 +2800,57 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
27992800
}
28002801

28012802
// Note any argument mismatches
2802-
let given_ty = params.skip_binder();
2803+
let ty::Tuple(given) = *params.skip_binder().kind() else {
2804+
return;
2805+
};
2806+
28032807
let expected_ty = trait_pred.skip_binder().trait_ref.args.type_at(1);
2804-
if let ty::Tuple(given) = given_ty.kind()
2805-
&& let ty::Tuple(expected) = expected_ty.kind()
2806-
{
2807-
if expected.len() != given.len() {
2808-
// Note number of types that were expected and given
2809-
err.note(
2810-
format!(
2811-
"expected a closure taking {} argument{}, but one taking {} argument{} was given",
2812-
given.len(),
2813-
pluralize!(given.len()),
2814-
expected.len(),
2815-
pluralize!(expected.len()),
2816-
)
2817-
);
2818-
} else if !self.same_type_modulo_infer(given_ty, expected_ty) {
2819-
// Print type mismatch
2820-
let (expected_args, given_args) = self.cmp(given_ty, expected_ty);
2821-
err.note_expected_found(
2822-
&"a closure with arguments",
2823-
expected_args,
2824-
&"a closure with arguments",
2825-
given_args,
2826-
);
2827-
}
2808+
let ty::Tuple(expected) = *expected_ty.kind() else {
2809+
return;
2810+
};
2811+
2812+
if expected.len() != given.len() {
2813+
// Note number of types that were expected and given
2814+
err.note(format!(
2815+
"expected a closure taking {} argument{}, but one taking {} argument{} was given",
2816+
given.len(),
2817+
pluralize!(given.len()),
2818+
expected.len(),
2819+
pluralize!(expected.len()),
2820+
));
2821+
return;
2822+
}
2823+
2824+
let given_ty = Ty::new_fn_ptr(
2825+
self.tcx,
2826+
params.rebind(self.tcx.mk_fn_sig(
2827+
given,
2828+
self.tcx.types.unit,
2829+
false,
2830+
hir::Safety::Safe,
2831+
ExternAbi::Rust,
2832+
)),
2833+
);
2834+
let expected_ty = Ty::new_fn_ptr(
2835+
self.tcx,
2836+
trait_pred.rebind(self.tcx.mk_fn_sig(
2837+
expected,
2838+
self.tcx.types.unit,
2839+
false,
2840+
hir::Safety::Safe,
2841+
ExternAbi::Rust,
2842+
)),
2843+
);
2844+
2845+
if !self.same_type_modulo_infer(given_ty, expected_ty) {
2846+
// Print type mismatch
2847+
let (expected_args, given_args) = self.cmp(expected_ty, given_ty);
2848+
err.note_expected_found(
2849+
"a closure with signature",
2850+
expected_args,
2851+
"a closure with signature",
2852+
given_args,
2853+
);
28282854
}
28292855
}
28302856

compiler/rustc_trait_selection/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ impl Subdiagnostic for RegionOriginNote<'_> {
415415
label_or_note(span, fluent::trait_selection_subtype);
416416
diag.arg("requirement", requirement);
417417

418-
diag.note_expected_found(&"", expected, &"", found);
418+
diag.note_expected_found("", expected, "", found);
419419
}
420420
RegionOriginNote::WithRequirement { span, requirement, expected_found: None } => {
421421
// FIXME: this really should be handled at some earlier stage. Our

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
317317
obligation.cause.clone(),
318318
obligation.recursion_depth + 1,
319319
obligation.param_env,
320-
obligation.predicate.rebind(trait_ref),
320+
trait_ref,
321321
)
322322
};
323323

@@ -343,7 +343,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
343343
obligation.cause.clone(),
344344
obligation.recursion_depth + 1,
345345
obligation.param_env,
346-
obligation.predicate.rebind(outlives),
346+
outlives,
347347
)
348348
};
349349

@@ -404,7 +404,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
404404
}
405405
}
406406

407-
let predicate = obligation.predicate.skip_binder();
407+
let predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
408408

409409
let mut assume = predicate.trait_ref.args.const_at(2);
410410
// FIXME(mgca): We should shallowly normalize this.

compiler/rustc_ty_utils/src/implied_bounds.rs

+19-12
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use rustc_data_structures::fx::FxHashMap;
44
use rustc_hir as hir;
55
use rustc_hir::def::DefKind;
66
use rustc_hir::def_id::LocalDefId;
7-
use rustc_middle::bug;
87
use rustc_middle::query::Providers;
98
use rustc_middle::ty::{self, Ty, TyCtxt, fold_regions};
9+
use rustc_middle::{bug, span_bug};
1010
use rustc_span::Span;
1111

1212
pub(crate) fn provide(providers: &mut Providers) {
@@ -21,7 +21,8 @@ pub(crate) fn provide(providers: &mut Providers) {
2121
}
2222

2323
fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<'tcx>, Span)] {
24-
match tcx.def_kind(def_id) {
24+
let kind = tcx.def_kind(def_id);
25+
match kind {
2526
DefKind::Fn => {
2627
let sig = tcx.fn_sig(def_id).instantiate_identity();
2728
let liberated_sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), sig);
@@ -121,32 +122,38 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<'
121122
}
122123
}
123124
DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.local_parent(def_id)),
124-
DefKind::OpaqueTy => bug!("implied bounds are not defined for opaques"),
125-
DefKind::Mod
125+
DefKind::Static { .. }
126+
| DefKind::Const
127+
| DefKind::AnonConst
128+
| DefKind::InlineConst
126129
| DefKind::Struct
127130
| DefKind::Union
128131
| DefKind::Enum
129-
| DefKind::Variant
130132
| DefKind::Trait
131-
| DefKind::TyAlias
132-
| DefKind::ForeignTy
133133
| DefKind::TraitAlias
134+
| DefKind::TyAlias => ty::List::empty(),
135+
DefKind::OpaqueTy
136+
| DefKind::Mod
137+
| DefKind::Variant
138+
| DefKind::ForeignTy
134139
| DefKind::TyParam
135-
| DefKind::Const
136140
| DefKind::ConstParam
137-
| DefKind::Static { .. }
138141
| DefKind::Ctor(_, _)
139142
| DefKind::Macro(_)
140143
| DefKind::ExternCrate
141144
| DefKind::Use
142145
| DefKind::ForeignMod
143-
| DefKind::AnonConst
144-
| DefKind::InlineConst
145146
| DefKind::Field
146147
| DefKind::LifetimeParam
147148
| DefKind::GlobalAsm
148149
| DefKind::Closure
149-
| DefKind::SyntheticCoroutineBody => ty::List::empty(),
150+
| DefKind::SyntheticCoroutineBody => {
151+
span_bug!(
152+
tcx.def_span(def_id),
153+
"`assumed_wf_types` not defined for {} `{def_id:?}`",
154+
kind.descr(def_id.to_def_id())
155+
);
156+
}
150157
}
151158
}
152159

compiler/rustc_ty_utils/src/opaque_types.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use rustc_hir::def::DefKind;
33
use rustc_hir::def_id::LocalDefId;
44
use rustc_hir::intravisit;
55
use rustc_hir::intravisit::Visitor;
6-
use rustc_middle::bug;
76
use rustc_middle::query::Providers;
87
use rustc_middle::ty::util::{CheckRegions, NotUniqueParam};
98
use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor};
9+
use rustc_middle::{bug, span_bug};
1010
use rustc_span::Span;
1111
use tracing::{instrument, trace};
1212

@@ -320,9 +320,12 @@ fn opaque_types_defined_by<'tcx>(
320320
| DefKind::AnonConst => {
321321
collector.collect_taits_declared_in_body();
322322
}
323+
// Closures and coroutines are type checked with their parent
324+
DefKind::Closure | DefKind::InlineConst => {
325+
collector.opaques.extend(tcx.opaque_types_defined_by(tcx.local_parent(item)));
326+
}
327+
DefKind::AssocTy | DefKind::TyAlias | DefKind::GlobalAsm => {}
323328
DefKind::OpaqueTy
324-
| DefKind::TyAlias
325-
| DefKind::AssocTy
326329
| DefKind::Mod
327330
| DefKind::Struct
328331
| DefKind::Union
@@ -340,12 +343,13 @@ fn opaque_types_defined_by<'tcx>(
340343
| DefKind::ForeignMod
341344
| DefKind::Field
342345
| DefKind::LifetimeParam
343-
| DefKind::GlobalAsm
344346
| DefKind::Impl { .. }
345-
| DefKind::SyntheticCoroutineBody => {}
346-
// Closures and coroutines are type checked with their parent
347-
DefKind::Closure | DefKind::InlineConst => {
348-
collector.opaques.extend(tcx.opaque_types_defined_by(tcx.local_parent(item)));
347+
| DefKind::SyntheticCoroutineBody => {
348+
span_bug!(
349+
tcx.def_span(item),
350+
"`opaque_types_defined_by` not defined for {} `{item:?}`",
351+
kind.descr(item.to_def_id())
352+
);
349353
}
350354
}
351355
tcx.mk_local_def_ids(&collector.opaques)

compiler/rustc_ty_utils/src/sig_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
116116
"{kind:?} has not seen any uses of `walk_types` yet, ping oli-obk if you'd like any help"
117117
)
118118
}
119-
// These don't have any types.
119+
// These don't have any types, but are visited during privacy checking.
120120
| DefKind::ExternCrate
121121
| DefKind::ForeignMod
122122
| DefKind::ForeignTy

0 commit comments

Comments
 (0)