Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e1de04a

Browse files
committed
Auto merge of #116885 - aliemjay:rollup-plbeppt, r=aliemjay
Rollup of 5 pull requests Successful merges: - #116812 (Disable missing_copy_implementations lint on non_exhaustive types) - #116856 (Disable effects in libcore again) - #116865 (Suggest constraining assoc types in more cases) - #116870 (Don't compare host param by name) - #116879 (revert #114586) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e8b8c78 + 8489bce commit e1de04a

File tree

21 files changed

+272
-140
lines changed

21 files changed

+272
-140
lines changed

‎compiler/rustc_borrowck/src/region_infer/opaque_types.rs‎

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -328,26 +328,19 @@ fn check_opaque_type_well_formed<'tcx>(
328328

329329
// Require that the hidden type actually fulfills all the bounds of the opaque type, even without
330330
// the bounds that the function supplies.
331-
let mut obligations = vec![];
332-
infcx
333-
.insert_hidden_type(
334-
OpaqueTypeKey { def_id, args: identity_args },
335-
&ObligationCause::misc(definition_span, def_id),
336-
param_env,
337-
definition_ty,
338-
true,
339-
&mut obligations,
340-
)
341-
.unwrap();
342-
infcx.add_item_bounds_for_hidden_type(
343-
def_id.to_def_id(),
344-
identity_args,
345-
ObligationCause::misc(definition_span, def_id),
346-
param_env,
347-
definition_ty,
348-
&mut obligations,
349-
);
350-
ocx.register_obligations(obligations);
331+
let opaque_ty = Ty::new_opaque(tcx, def_id.to_def_id(), identity_args);
332+
ocx.eq(&ObligationCause::misc(definition_span, def_id), param_env, opaque_ty, definition_ty)
333+
.map_err(|err| {
334+
infcx
335+
.err_ctxt()
336+
.report_mismatched_types(
337+
&ObligationCause::misc(definition_span, def_id),
338+
opaque_ty,
339+
definition_ty,
340+
err,
341+
)
342+
.emit()
343+
})?;
351344

352345
// Require the hidden type to be well-formed with only the generics of the opaque type.
353346
// Defining use functions may have more bounds than the opaque type, which is ok, as long as the

‎compiler/rustc_hir_analysis/src/bounds.rs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ impl<'tcx> Bounds<'tcx> {
4646
) {
4747
self.push_trait_bound_inner(tcx, trait_ref, span, polarity);
4848

49-
// if we have a host param, we push an unconst trait bound in addition
50-
// to the const one.
51-
// FIXME(effects) we should find a better way than name matching
52-
if tcx.features().effects && trait_ref.skip_binder().args.host_effect_param().is_some() {
49+
// push a non-const (`host = true`) version of the bound if it is `~const`.
50+
if tcx.features().effects
51+
&& let Some(host_effect_idx) = tcx.generics_of(trait_ref.def_id()).host_effect_index
52+
&& trait_ref.skip_binder().args.const_at(host_effect_idx) != tcx.consts.true_
53+
{
5354
let generics = tcx.generics_of(trait_ref.def_id());
5455
let Some(host_index) = generics.host_effect_index else { return };
5556
let trait_ref = trait_ref.map_bound(|mut trait_ref| {

‎compiler/rustc_hir_typeck/src/callee.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,8 +786,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
786786
tcx.consts.false_
787787
}
788788
Some(hir::ConstContext::ConstFn) => {
789-
let args = ty::GenericArgs::identity_for_item(tcx, context);
790-
args.host_effect_param().expect("ConstContext::Maybe must have host effect param")
789+
let host_idx = tcx
790+
.generics_of(context)
791+
.host_effect_index
792+
.expect("ConstContext::Maybe must have host effect param");
793+
ty::GenericArgs::identity_for_item(tcx, context).const_at(host_idx)
791794
}
792795
None => tcx.consts.true_,
793796
};

‎compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs‎

Lines changed: 58 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -341,39 +341,48 @@ impl<T> Trait<T> for X {
341341
let tcx = self.tcx;
342342
let assoc = tcx.associated_item(proj_ty.def_id);
343343
let (trait_ref, assoc_args) = proj_ty.trait_ref_and_own_args(tcx);
344-
if let Some(item) = tcx.hir().get_if_local(body_owner_def_id) {
345-
if let Some(hir_generics) = item.generics() {
346-
// Get the `DefId` for the type parameter corresponding to `A` in `<A as T>::Foo`.
347-
// This will also work for `impl Trait`.
348-
let def_id = if let ty::Param(param_ty) = proj_ty.self_ty().kind() {
349-
let generics = tcx.generics_of(body_owner_def_id);
350-
generics.type_param(param_ty, tcx).def_id
351-
} else {
352-
return false;
353-
};
354-
let Some(def_id) = def_id.as_local() else {
355-
return false;
356-
};
357-
358-
// First look in the `where` clause, as this might be
359-
// `fn foo<T>(x: T) where T: Trait`.
360-
for pred in hir_generics.bounds_for_param(def_id) {
361-
if self.constrain_generic_bound_associated_type_structured_suggestion(
362-
diag,
363-
&trait_ref,
364-
pred.bounds,
365-
assoc,
366-
assoc_args,
367-
ty,
368-
&msg,
369-
false,
370-
) {
371-
return true;
372-
}
373-
}
344+
let Some(item) = tcx.hir().get_if_local(body_owner_def_id) else {
345+
return false;
346+
};
347+
let Some(hir_generics) = item.generics() else {
348+
return false;
349+
};
350+
// Get the `DefId` for the type parameter corresponding to `A` in `<A as T>::Foo`.
351+
// This will also work for `impl Trait`.
352+
let def_id = if let ty::Param(param_ty) = proj_ty.self_ty().kind() {
353+
let generics = tcx.generics_of(body_owner_def_id);
354+
generics.type_param(param_ty, tcx).def_id
355+
} else {
356+
return false;
357+
};
358+
let Some(def_id) = def_id.as_local() else {
359+
return false;
360+
};
361+
362+
// First look in the `where` clause, as this might be
363+
// `fn foo<T>(x: T) where T: Trait`.
364+
for pred in hir_generics.bounds_for_param(def_id) {
365+
if self.constrain_generic_bound_associated_type_structured_suggestion(
366+
diag,
367+
&trait_ref,
368+
pred.bounds,
369+
assoc,
370+
assoc_args,
371+
ty,
372+
&msg,
373+
false,
374+
) {
375+
return true;
374376
}
375377
}
376-
false
378+
// If associated item, look to constrain the params of the trait/impl.
379+
let hir_id = match item {
380+
hir::Node::ImplItem(item) => item.hir_id(),
381+
hir::Node::TraitItem(item) => item.hir_id(),
382+
_ => return false,
383+
};
384+
let parent = tcx.hir().get_parent_item(hir_id).def_id;
385+
self.suggest_constraint(diag, msg, parent.into(), proj_ty, ty)
377386
}
378387

379388
/// An associated type was expected and a different type was found.
@@ -426,21 +435,26 @@ impl<T> Trait<T> for X {
426435
let impl_comparison =
427436
matches!(cause_code, ObligationCauseCode::CompareImplItemObligation { .. });
428437
let assoc = tcx.associated_item(proj_ty.def_id);
429-
if !callable_scope || impl_comparison {
438+
if impl_comparison {
430439
// We do not want to suggest calling functions when the reason of the
431-
// type error is a comparison of an `impl` with its `trait` or when the
432-
// scope is outside of a `Body`.
440+
// type error is a comparison of an `impl` with its `trait`.
433441
} else {
434-
// If we find a suitable associated function that returns the expected type, we don't
435-
// want the more general suggestion later in this method about "consider constraining
436-
// the associated type or calling a method that returns the associated type".
437-
let point_at_assoc_fn = self.point_at_methods_that_satisfy_associated_type(
438-
diag,
439-
assoc.container_id(tcx),
440-
current_method_ident,
441-
proj_ty.def_id,
442-
values.expected,
443-
);
442+
let point_at_assoc_fn = if callable_scope
443+
&& self.point_at_methods_that_satisfy_associated_type(
444+
diag,
445+
assoc.container_id(tcx),
446+
current_method_ident,
447+
proj_ty.def_id,
448+
values.expected,
449+
) {
450+
// If we find a suitable associated function that returns the expected type, we
451+
// don't want the more general suggestion later in this method about "consider
452+
// constraining the associated type or calling a method that returns the associated
453+
// type".
454+
true
455+
} else {
456+
false
457+
};
444458
// Possibly suggest constraining the associated type to conform to the
445459
// found type.
446460
if self.suggest_constraint(diag, &msg, body_owner_def_id, proj_ty, values.found)

‎compiler/rustc_infer/src/infer/opaque_types.rs‎

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -145,25 +145,7 @@ impl<'tcx> InferCtxt<'tcx> {
145145
return None;
146146
}
147147
}
148-
DefiningAnchor::Bubble => {
149-
if let ty::Alias(ty::Opaque, _) = b.kind() {
150-
// In bubble mode we don't know which of the two opaque types is supposed to have the other
151-
// as a hidden type (both, none or either one of them could be in its defining scope).
152-
let predicate = ty::PredicateKind::AliasRelate(
153-
a.into(),
154-
b.into(),
155-
ty::AliasRelationDirection::Equate,
156-
);
157-
let obligation = traits::Obligation::new(
158-
self.tcx,
159-
cause.clone(),
160-
param_env,
161-
predicate,
162-
);
163-
let obligations = vec![obligation];
164-
return Some(Ok(InferOk { value: (), obligations }));
165-
}
166-
}
148+
DefiningAnchor::Bubble => {}
167149
DefiningAnchor::Error => return None,
168150
};
169151
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }) = *b.kind() {

‎compiler/rustc_lint/src/builtin.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
677677
if type_implements_negative_copy_modulo_regions(cx.tcx, ty, param_env) {
678678
return;
679679
}
680+
if def.is_variant_list_non_exhaustive()
681+
|| def.variants().iter().any(|variant| variant.is_field_list_non_exhaustive())
682+
{
683+
return;
684+
}
680685

681686
// We shouldn't recommend implementing `Copy` on stateful things,
682687
// such as iterators.

‎compiler/rustc_middle/src/ty/generic_args.rs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
1111
use rustc_hir::def_id::DefId;
1212
use rustc_macros::HashStable;
1313
use rustc_serialize::{self, Decodable, Encodable};
14-
use rustc_span::sym;
1514
use rustc_type_ir::WithCachedTypeInfo;
1615
use smallvec::SmallVec;
1716

@@ -452,10 +451,6 @@ impl<'tcx> GenericArgs<'tcx> {
452451
tcx.mk_args_from_iter(self.iter().take(generics.count()))
453452
}
454453

455-
pub fn host_effect_param(&'tcx self) -> Option<ty::Const<'tcx>> {
456-
self.consts().rfind(|x| matches!(x.kind(), ty::ConstKind::Param(p) if p.name == sym::host))
457-
}
458-
459454
pub fn print_as_list(&self) -> String {
460455
let v = self.iter().map(|arg| arg.to_string()).collect::<Vec<_>>();
461456
format!("[{}]", v.join(", "))

‎compiler/rustc_trait_selection/src/traits/fulfill.rs‎

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc_infer::infer::DefineOpaqueTypes;
66
use rustc_infer::traits::ProjectionCacheKey;
77
use rustc_infer::traits::{PolyTraitObligation, SelectionError, TraitEngine};
88
use rustc_middle::mir::interpret::ErrorHandled;
9-
use rustc_middle::traits::DefiningAnchor;
109
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
1110
use rustc_middle::ty::error::{ExpectedFound, TypeError};
1211
use rustc_middle::ty::GenericArgsRef;
@@ -626,27 +625,9 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
626625
}
627626
}
628627
ty::PredicateKind::Ambiguous => ProcessResult::Unchanged,
629-
ty::PredicateKind::AliasRelate(..)
630-
if matches!(self.selcx.infcx.defining_use_anchor, DefiningAnchor::Bubble) =>
631-
{
632-
ProcessResult::Unchanged
628+
ty::PredicateKind::AliasRelate(..) => {
629+
bug!("AliasRelate is only used for new solver")
633630
}
634-
ty::PredicateKind::AliasRelate(a, b, relate) => match relate {
635-
ty::AliasRelationDirection::Equate => match self
636-
.selcx
637-
.infcx
638-
.at(&obligation.cause, obligation.param_env)
639-
.eq(DefineOpaqueTypes::Yes, a, b)
640-
{
641-
Ok(inf_ok) => ProcessResult::Changed(mk_pending(inf_ok.into_obligations())),
642-
Err(_) => ProcessResult::Error(FulfillmentErrorCode::CodeSelectionError(
643-
SelectionError::Unimplemented,
644-
)),
645-
},
646-
ty::AliasRelationDirection::Subtype => {
647-
bug!("AliasRelate with subtyping is only used for new solver")
648-
}
649-
},
650631
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
651632
match self.selcx.infcx.at(&obligation.cause, obligation.param_env).eq(
652633
DefineOpaqueTypes::No,

‎compiler/rustc_trait_selection/src/traits/select/mod.rs‎

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use rustc_infer::traits::TraitObligation;
3838
use rustc_middle::dep_graph::dep_kinds;
3939
use rustc_middle::dep_graph::DepNodeIndex;
4040
use rustc_middle::mir::interpret::ErrorHandled;
41-
use rustc_middle::traits::DefiningAnchor;
4241
use rustc_middle::ty::_match::MatchAgainstFreshVars;
4342
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
4443
use rustc_middle::ty::fold::BottomUpFolder;
@@ -1005,27 +1004,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10051004
}
10061005
}
10071006
}
1008-
ty::PredicateKind::AliasRelate(..)
1009-
if matches!(self.infcx.defining_use_anchor, DefiningAnchor::Bubble) =>
1010-
{
1011-
Ok(EvaluatedToAmbig)
1007+
ty::PredicateKind::AliasRelate(..) => {
1008+
bug!("AliasRelate is only used for new solver")
10121009
}
1013-
ty::PredicateKind::AliasRelate(a, b, relate) => match relate {
1014-
ty::AliasRelationDirection::Equate => match self
1015-
.infcx
1016-
.at(&obligation.cause, obligation.param_env)
1017-
.eq(DefineOpaqueTypes::Yes, a, b)
1018-
{
1019-
Ok(inf_ok) => self.evaluate_predicates_recursively(
1020-
previous_stack,
1021-
inf_ok.into_obligations(),
1022-
),
1023-
Err(_) => Ok(EvaluatedToErr),
1024-
},
1025-
ty::AliasRelationDirection::Subtype => {
1026-
bug!("AliasRelate subtyping is only used for new solver")
1027-
}
1028-
},
10291010
ty::PredicateKind::Ambiguous => Ok(EvaluatedToAmbig),
10301011
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
10311012
match self.infcx.at(&obligation.cause, obligation.param_env).eq(

‎library/core/src/lib.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@
219219
#![feature(doc_cfg)]
220220
#![feature(doc_cfg_hide)]
221221
#![feature(doc_notable_trait)]
222-
#![feature(effects)]
223222
#![feature(exhaustive_patterns)]
224223
#![feature(extern_types)]
225224
#![feature(fundamental)]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /