Skip to content

Commit 3f2b2ee

Browse files
committed
Auto merge of #104758 - Manishearth:rollup-rh1tfum, r=Manishearth
Rollup of 6 pull requests Successful merges: - #103488 (Allow opaque types in trait impl headers and rely on coherence to reject unsound cases) - #104359 (Refactor must_use lint into two parts) - #104612 (Lower return type outside async block creation) - #104621 (Fix --extern library finding errors) - #104647 (enable fuzzy_provenance_casts lint in liballoc and libstd) - #104750 (Bump `fd-lock` in `bootstrap` again) Failed merges: - #104732 (Refactor `ty::ClosureKind` related stuff) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 008bc1d + 42afb70 commit 3f2b2ee

File tree

98 files changed

+902
-540
lines changed

Some content is hidden

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

98 files changed

+902
-540
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -588,17 +588,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
588588
&mut self,
589589
capture_clause: CaptureBy,
590590
closure_node_id: NodeId,
591-
ret_ty: Option<AstP<Ty>>,
591+
ret_ty: Option<hir::FnRetTy<'hir>>,
592592
span: Span,
593593
async_gen_kind: hir::AsyncGeneratorKind,
594594
body: impl FnOnce(&mut Self) -> hir::Expr<'hir>,
595595
) -> hir::ExprKind<'hir> {
596-
let output = match ret_ty {
597-
Some(ty) => hir::FnRetTy::Return(
598-
self.lower_ty(&ty, &ImplTraitContext::Disallowed(ImplTraitPosition::AsyncBlock)),
599-
),
600-
None => hir::FnRetTy::DefaultReturn(self.lower_span(span)),
601-
};
596+
let output = ret_ty.unwrap_or_else(|| hir::FnRetTy::DefaultReturn(self.lower_span(span)));
602597

603598
// Resume argument type. We let the compiler infer this to simplify the lowering. It is
604599
// fully constrained by `future::from_generator`.
@@ -1003,8 +998,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
1003998
// Transform `async |x: u8| -> X { ... }` into
1004999
// `|x: u8| future_from_generator(|| -> X { ... })`.
10051000
let body_id = this.lower_fn_body(&outer_decl, |this| {
1006-
let async_ret_ty =
1007-
if let FnRetTy::Ty(ty) = &decl.output { Some(ty.clone()) } else { None };
1001+
let async_ret_ty = if let FnRetTy::Ty(ty) = &decl.output {
1002+
let itctx = ImplTraitContext::Disallowed(ImplTraitPosition::AsyncBlock);
1003+
Some(hir::FnRetTy::Return(this.lower_ty(&ty, &itctx)))
1004+
} else {
1005+
None
1006+
};
1007+
10081008
let async_body = this.make_async_expr(
10091009
capture_clause,
10101010
inner_closure_id,

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ use rustc_infer::infer::nll_relate::{NormalizationStrategy, TypeRelating, TypeRe
22
use rustc_infer::infer::NllRegionVariableOrigin;
33
use rustc_infer::traits::PredicateObligations;
44
use rustc_middle::mir::ConstraintCategory;
5-
use rustc_middle::ty::error::TypeError;
65
use rustc_middle::ty::relate::TypeRelation;
7-
use rustc_middle::ty::{self, Const, Ty};
6+
use rustc_middle::ty::{self, Ty};
87
use rustc_span::Span;
98
use rustc_trait_selection::traits::query::Fallible;
109

@@ -141,13 +140,6 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
141140
);
142141
}
143142

144-
// We don't have to worry about the equality of consts during borrow checking
145-
// as consts always have a static lifetime.
146-
// FIXME(oli-obk): is this really true? We can at least have HKL and with
147-
// inline consts we may have further lifetimes that may be unsound to treat as
148-
// 'static.
149-
fn const_equate(&mut self, _a: Const<'tcx>, _b: Const<'tcx>) {}
150-
151143
fn normalization() -> NormalizationStrategy {
152144
NormalizationStrategy::Eager
153145
}
@@ -156,10 +148,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
156148
true
157149
}
158150

159-
fn register_opaque_type_obligations(
160-
&mut self,
161-
obligations: PredicateObligations<'tcx>,
162-
) -> Result<(), TypeError<'tcx>> {
151+
fn register_obligations(&mut self, obligations: PredicateObligations<'tcx>) {
163152
self.type_checker
164153
.fully_perform_op(
165154
self.locations,
@@ -172,6 +161,5 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
172161
},
173162
)
174163
.unwrap();
175-
Ok(())
176164
}
177165
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ metadata_crate_location_unknown_type =
275275
extern location for {$crate_name} is of an unknown type: {$path}
276276
277277
metadata_lib_filename_form =
278-
file name should be lib*.rlib or {dll_prefix}*.{dll_suffix}
278+
file name should be lib*.rlib or {$dll_prefix}*{$dll_suffix}
279279
280280
metadata_multiple_import_name_type =
281281
multiple `import_name_type` arguments in a single `#[link]` attribute

compiler/rustc_hir_analysis/src/check/dropck.rs

+8
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ impl<'tcx> TypeRelation<'tcx> for SimpleEqRelation<'tcx> {
244244
self.tcx
245245
}
246246

247+
fn intercrate(&self) -> bool {
248+
false
249+
}
250+
247251
fn param_env(&self) -> ty::ParamEnv<'tcx> {
248252
self.param_env
249253
}
@@ -256,6 +260,10 @@ impl<'tcx> TypeRelation<'tcx> for SimpleEqRelation<'tcx> {
256260
true
257261
}
258262

263+
fn mark_ambiguous(&mut self) {
264+
bug!()
265+
}
266+
259267
fn relate_with_variance<T: Relate<'tcx>>(
260268
&mut self,
261269
_: ty::Variance,

compiler/rustc_hir_analysis/src/coherence/orphan.rs

-53
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc_data_structures::fx::FxHashSet;
55
use rustc_errors::{struct_span_err, DelayDm};
66
use rustc_errors::{Diagnostic, ErrorGuaranteed};
77
use rustc_hir as hir;
8-
use rustc_middle::ty::subst::GenericArgKind;
98
use rustc_middle::ty::subst::InternalSubsts;
109
use rustc_middle::ty::util::IgnoreRegions;
1110
use rustc_middle::ty::{
@@ -47,58 +46,6 @@ fn do_orphan_check_impl<'tcx>(
4746
let sp = tcx.def_span(def_id);
4847
let tr = impl_.of_trait.as_ref().unwrap();
4948

50-
// Ensure no opaque types are present in this impl header. See issues #76202 and #86411 for examples,
51-
// and #84660 where it would otherwise allow unsoundness.
52-
if trait_ref.has_opaque_types() {
53-
trace!("{:#?}", item);
54-
// First we find the opaque type in question.
55-
for ty in trait_ref.substs {
56-
for ty in ty.walk() {
57-
let ty::subst::GenericArgKind::Type(ty) = ty.unpack() else { continue };
58-
let ty::Opaque(def_id, _) = *ty.kind() else { continue };
59-
trace!(?def_id);
60-
61-
// Then we search for mentions of the opaque type's type alias in the HIR
62-
struct SpanFinder<'tcx> {
63-
sp: Span,
64-
def_id: DefId,
65-
tcx: TyCtxt<'tcx>,
66-
}
67-
impl<'v, 'tcx> hir::intravisit::Visitor<'v> for SpanFinder<'tcx> {
68-
#[instrument(level = "trace", skip(self, _id))]
69-
fn visit_path(&mut self, path: &'v hir::Path<'v>, _id: hir::HirId) {
70-
// You can't mention an opaque type directly, so we look for type aliases
71-
if let hir::def::Res::Def(hir::def::DefKind::TyAlias, def_id) = path.res {
72-
// And check if that type alias's type contains the opaque type we're looking for
73-
for arg in self.tcx.type_of(def_id).walk() {
74-
if let GenericArgKind::Type(ty) = arg.unpack() {
75-
if let ty::Opaque(def_id, _) = *ty.kind() {
76-
if def_id == self.def_id {
77-
// Finally we update the span to the mention of the type alias
78-
self.sp = path.span;
79-
return;
80-
}
81-
}
82-
}
83-
}
84-
}
85-
hir::intravisit::walk_path(self, path)
86-
}
87-
}
88-
89-
let mut visitor = SpanFinder { sp, def_id, tcx };
90-
hir::intravisit::walk_item(&mut visitor, item);
91-
let reported = tcx
92-
.sess
93-
.struct_span_err(visitor.sp, "cannot implement trait on type alias impl trait")
94-
.span_note(tcx.def_span(def_id), "type alias impl trait defined here")
95-
.emit();
96-
return Err(reported);
97-
}
98-
}
99-
span_bug!(sp, "opaque type not found, but `has_opaque_types` is set")
100-
}
101-
10249
match traits::orphan_check(tcx, item.owner_id.to_def_id()) {
10350
Ok(()) => {}
10451
Err(err) => emit_orphan_check_error(

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

+1
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ fn trait_predicate_kind<'tcx>(
517517
| ty::PredicateKind::ClosureKind(..)
518518
| ty::PredicateKind::ConstEvaluatable(..)
519519
| ty::PredicateKind::ConstEquate(..)
520+
| ty::PredicateKind::Ambiguous
520521
| ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
521522
}
522523
}

compiler/rustc_hir_analysis/src/outlives/explicit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> {
5959
| ty::PredicateKind::Coerce(..)
6060
| ty::PredicateKind::ConstEvaluatable(..)
6161
| ty::PredicateKind::ConstEquate(..)
62+
| ty::PredicateKind::Ambiguous
6263
| ty::PredicateKind::TypeWellFormedFromEnv(..) => (),
6364
}
6465
}

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
702702
// code is looking for a self type of an unresolved
703703
// inference variable.
704704
| ty::PredicateKind::ClosureKind(..)
705+
| ty::PredicateKind::Ambiguous
705706
| ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
706707
},
707708
)

compiler/rustc_hir_typeck/src/method/probe.rs

+1
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
803803
| ty::PredicateKind::TypeOutlives(..)
804804
| ty::PredicateKind::ConstEvaluatable(..)
805805
| ty::PredicateKind::ConstEquate(..)
806+
| ty::PredicateKind::Ambiguous
806807
| ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
807808
}
808809
});

compiler/rustc_infer/src/infer/at.rs

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ impl<'tcx> InferCtxt<'tcx> {
8181
.normalize_fn_sig_for_diagnostic
8282
.as_ref()
8383
.map(|f| f.clone()),
84+
intercrate: self.intercrate,
8485
}
8586
}
8687
}

compiler/rustc_infer/src/infer/canonical/query_response.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ use rustc_index::vec::Idx;
2323
use rustc_index::vec::IndexVec;
2424
use rustc_middle::arena::ArenaAllocatable;
2525
use rustc_middle::mir::ConstraintCategory;
26-
use rustc_middle::ty::error::TypeError;
2726
use rustc_middle::ty::fold::TypeFoldable;
2827
use rustc_middle::ty::relate::TypeRelation;
2928
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
30-
use rustc_middle::ty::{self, BoundVar, Const, ToPredicate, Ty, TyCtxt};
29+
use rustc_middle::ty::{self, BoundVar, ToPredicate, Ty, TyCtxt};
3130
use rustc_span::Span;
3231
use std::fmt::Debug;
3332
use std::iter;
@@ -729,10 +728,6 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
729728
});
730729
}
731730

732-
fn const_equate(&mut self, _a: Const<'tcx>, _b: Const<'tcx>) {
733-
span_bug!(self.cause.span(), "generic_const_exprs: unreachable `const_equate`");
734-
}
735-
736731
fn normalization() -> NormalizationStrategy {
737732
NormalizationStrategy::Eager
738733
}
@@ -741,11 +736,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
741736
true
742737
}
743738

744-
fn register_opaque_type_obligations(
745-
&mut self,
746-
obligations: PredicateObligations<'tcx>,
747-
) -> Result<(), TypeError<'tcx>> {
739+
fn register_obligations(&mut self, obligations: PredicateObligations<'tcx>) {
748740
self.obligations.extend(obligations);
749-
Ok(())
750741
}
751742
}

compiler/rustc_infer/src/infer/combine.rs

+31
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,15 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
450450
ty::Binder::dummy(predicate),
451451
));
452452
}
453+
454+
pub fn mark_ambiguous(&mut self) {
455+
self.obligations.push(Obligation::new(
456+
self.tcx(),
457+
self.trace.cause.clone(),
458+
self.param_env,
459+
ty::Binder::dummy(ty::PredicateKind::Ambiguous),
460+
));
461+
}
453462
}
454463

455464
struct Generalizer<'cx, 'tcx> {
@@ -521,6 +530,11 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
521530
fn tcx(&self) -> TyCtxt<'tcx> {
522531
self.infcx.tcx
523532
}
533+
534+
fn intercrate(&self) -> bool {
535+
self.infcx.intercrate
536+
}
537+
524538
fn param_env(&self) -> ty::ParamEnv<'tcx> {
525539
self.param_env
526540
}
@@ -533,6 +547,10 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
533547
true
534548
}
535549

550+
fn mark_ambiguous(&mut self) {
551+
span_bug!(self.cause.span, "opaque types are handled in `tys`");
552+
}
553+
536554
fn binders<T>(
537555
&mut self,
538556
a: ty::Binder<'tcx, T>,
@@ -657,6 +675,10 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
657675
// relatable.
658676
Ok(t)
659677
}
678+
ty::Opaque(def_id, substs) => {
679+
let s = self.relate(substs, substs)?;
680+
Ok(if s == substs { t } else { self.infcx.tcx.mk_opaque(def_id, s) })
681+
}
660682
_ => relate::super_relate_tys(self, t, t),
661683
}?;
662684

@@ -799,6 +821,11 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
799821
self.infcx.tcx
800822
}
801823

824+
fn intercrate(&self) -> bool {
825+
assert!(!self.infcx.intercrate);
826+
false
827+
}
828+
802829
fn param_env(&self) -> ty::ParamEnv<'tcx> {
803830
self.param_env
804831
}
@@ -811,6 +838,10 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
811838
true
812839
}
813840

841+
fn mark_ambiguous(&mut self) {
842+
bug!()
843+
}
844+
814845
fn relate_with_variance<T: Relate<'tcx>>(
815846
&mut self,
816847
_variance: ty::Variance,

compiler/rustc_infer/src/infer/equate.rs

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
3232
self.fields.tcx()
3333
}
3434

35+
fn intercrate(&self) -> bool {
36+
self.fields.infcx.intercrate
37+
}
38+
3539
fn param_env(&self) -> ty::ParamEnv<'tcx> {
3640
self.fields.param_env
3741
}
@@ -40,6 +44,10 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
4044
self.a_is_expected
4145
}
4246

47+
fn mark_ambiguous(&mut self) {
48+
self.fields.mark_ambiguous();
49+
}
50+
4351
fn relate_item_substs(
4452
&mut self,
4553
_item_def_id: DefId,

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -2937,6 +2937,11 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> {
29372937
self.0.tcx
29382938
}
29392939

2940+
fn intercrate(&self) -> bool {
2941+
assert!(!self.0.intercrate);
2942+
false
2943+
}
2944+
29402945
fn param_env(&self) -> ty::ParamEnv<'tcx> {
29412946
// Unused, only for consts which we treat as always equal
29422947
ty::ParamEnv::empty()
@@ -2950,6 +2955,10 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> {
29502955
true
29512956
}
29522957

2958+
fn mark_ambiguous(&mut self) {
2959+
bug!()
2960+
}
2961+
29532962
fn relate_with_variance<T: relate::Relate<'tcx>>(
29542963
&mut self,
29552964
_variance: ty::Variance,

compiler/rustc_infer/src/infer/glb.rs

+9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ impl<'tcx> TypeRelation<'tcx> for Glb<'_, '_, 'tcx> {
3030
"Glb"
3131
}
3232

33+
fn intercrate(&self) -> bool {
34+
assert!(!self.fields.infcx.intercrate);
35+
false
36+
}
37+
3338
fn tcx(&self) -> TyCtxt<'tcx> {
3439
self.fields.tcx()
3540
}
@@ -42,6 +47,10 @@ impl<'tcx> TypeRelation<'tcx> for Glb<'_, '_, 'tcx> {
4247
self.a_is_expected
4348
}
4449

50+
fn mark_ambiguous(&mut self) {
51+
bug!("mark_ambiguous used outside of coherence");
52+
}
53+
4554
fn relate_with_variance<T: Relate<'tcx>>(
4655
&mut self,
4756
variance: ty::Variance,

0 commit comments

Comments
 (0)