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 126dbdc

Browse files
committed
Auto merge of #103629 - matthiaskrgr:rollup-r94tqfa, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #103110 (remove redundant Send impl for references) - #103255 (Clean up hidden type registration) - #103394 (Clarify documentation about the memory layout of `UnsafeCell`) - #103408 (Clean return-position `impl Trait` in traits correctly in rustdoc) - #103505 (rustdoc: parse self-closing tags and attributes in `invalid_html_tags`) - #103524 (rustc_metadata: Add struct and variant constructors to module children at encoding time) - #103544 (Add flag to forbid recovery in the parser) - #103616 (rustdoc: remove CSS workaround for Firefox 29) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0da281b + ae4dc12 commit 126dbdc

File tree

21 files changed

+467
-217
lines changed

21 files changed

+467
-217
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,11 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
263263

264264
// Require that the hidden type actually fulfills all the bounds of the opaque type, even without
265265
// the bounds that the function supplies.
266-
match infcx.register_hidden_type(
267-
OpaqueTypeKey { def_id, substs: id_substs },
268-
ObligationCause::misc(instantiated_ty.span, body_id),
269-
param_env,
270-
definition_ty,
271-
origin,
272-
) {
266+
let opaque_ty = self.tcx.mk_opaque(def_id.to_def_id(), id_substs);
267+
match infcx
268+
.at(&ObligationCause::misc(instantiated_ty.span, body_id), param_env)
269+
.eq(opaque_ty, definition_ty)
270+
{
273271
Ok(infer_ok) => {
274272
for obligation in infer_ok.obligations {
275273
fulfillment_cx.register_predicate_obligation(&infcx, obligation);
@@ -280,7 +278,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
280278
.err_ctxt()
281279
.report_mismatched_types(
282280
&ObligationCause::misc(instantiated_ty.span, body_id),
283-
self.tcx.mk_opaque(def_id.to_def_id(), id_substs),
281+
opaque_ty,
284282
definition_ty,
285283
err,
286284
)

‎compiler/rustc_borrowck/src/type_check/relate_tys.rs‎

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_infer::infer::nll_relate::{NormalizationStrategy, TypeRelating, TypeRelatingDelegate};
22
use rustc_infer::infer::NllRegionVariableOrigin;
3-
use rustc_infer::traits::ObligationCause;
3+
use rustc_infer::traits::PredicateObligations;
44
use rustc_middle::mir::ConstraintCategory;
55
use rustc_middle::ty::error::TypeError;
66
use rustc_middle::ty::relate::TypeRelation;
@@ -155,27 +155,16 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
155155
true
156156
}
157157

158-
fn register_opaque_type(
158+
fn register_opaque_type_obligations(
159159
&mut self,
160-
a: Ty<'tcx>,
161-
b: Ty<'tcx>,
162-
a_is_expected: bool,
160+
obligations: PredicateObligations<'tcx>,
163161
) -> Result<(), TypeError<'tcx>> {
164-
let param_env = self.param_env();
165-
let span = self.span();
166-
let def_id = self.type_checker.body.source.def_id().expect_local();
167-
let body_id = self.type_checker.tcx().hir().local_def_id_to_hir_id(def_id);
168-
let cause = ObligationCause::misc(span, body_id);
169162
self.type_checker
170163
.fully_perform_op(
171164
self.locations,
172165
self.category,
173166
InstantiateOpaqueType {
174-
obligations: self
175-
.type_checker
176-
.infcx
177-
.handle_opaque_type(a, b, a_is_expected, &cause, param_env)?
178-
.obligations,
167+
obligations,
179168
// These fields are filled in during execution of the operation
180169
base_universe: None,
181170
region_constraints: None,

‎compiler/rustc_expand/src/mbe/macro_rules.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ fn expand_macro<'cx>(
250250
// hacky, but speeds up the `html5ever` benchmark significantly. (Issue
251251
// 68836 suggests a more comprehensive but more complex change to deal with
252252
// this situation.)
253+
// FIXME(Nilstrieb): Stop recovery from happening on this parser and retry later with recovery if the macro failed to match.
253254
let parser = parser_from_cx(sess, arg.clone());
254255

255256
// Try each arm's matchers.

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use crate::infer::nll_relate::{NormalizationStrategy, TypeRelating, TypeRelating
1616
use crate::infer::region_constraints::{Constraint, RegionConstraintData};
1717
use crate::infer::{InferCtxt, InferOk, InferResult, NllRegionVariableOrigin};
1818
use crate::traits::query::{Fallible, NoSolution};
19-
use crate::traits::TraitEngine;
2019
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
20+
use crate::traits::{PredicateObligations, TraitEngine};
2121
use rustc_data_structures::captures::Captures;
2222
use rustc_index::vec::Idx;
2323
use rustc_index::vec::IndexVec;
@@ -509,7 +509,7 @@ impl<'tcx> InferCtxt<'tcx> {
509509
for &(a, b) in &query_response.value.opaque_types {
510510
let a = substitute_value(self.tcx, &result_subst, a);
511511
let b = substitute_value(self.tcx, &result_subst, b);
512-
obligations.extend(self.handle_opaque_type(a, b,true,cause, param_env)?.obligations);
512+
obligations.extend(self.at(cause, param_env).eq(a, b)?.obligations);
513513
}
514514

515515
Ok(InferOk { value: result_subst, obligations })
@@ -741,17 +741,11 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
741741
true
742742
}
743743

744-
fn register_opaque_type(
744+
fn register_opaque_type_obligations(
745745
&mut self,
746-
a: Ty<'tcx>,
747-
b: Ty<'tcx>,
748-
a_is_expected: bool,
746+
obligations: PredicateObligations<'tcx>,
749747
) -> Result<(), TypeError<'tcx>> {
750-
self.obligations.extend(
751-
self.infcx
752-
.handle_opaque_type(a, b, a_is_expected, &self.cause, self.param_env)?
753-
.obligations,
754-
);
748+
self.obligations.extend(obligations);
755749
Ok(())
756750
}
757751
}

‎compiler/rustc_infer/src/infer/nll_relate/mod.rs‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ use crate::infer::combine::ConstEquateRelation;
2525
use crate::infer::InferCtxt;
2626
use crate::infer::{ConstVarValue, ConstVariableValue};
2727
use crate::infer::{TypeVariableOrigin, TypeVariableOriginKind};
28+
use crate::traits::PredicateObligation;
2829
use rustc_data_structures::fx::FxHashMap;
30+
use rustc_middle::traits::ObligationCause;
2931
use rustc_middle::ty::error::TypeError;
3032
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
3133
use rustc_middle::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor};
@@ -91,11 +93,9 @@ pub trait TypeRelatingDelegate<'tcx> {
9193
);
9294

9395
fn const_equate(&mut self, a: ty::Const<'tcx>, b: ty::Const<'tcx>);
94-
fn register_opaque_type(
96+
fn register_opaque_type_obligations(
9597
&mut self,
96-
a: Ty<'tcx>,
97-
b: Ty<'tcx>,
98-
a_is_expected: bool,
98+
obligations: Vec<PredicateObligation<'tcx>>,
9999
) -> Result<(), TypeError<'tcx>>;
100100

101101
/// Creates a new universe index. Used when instantiating placeholders.
@@ -414,7 +414,12 @@ where
414414
(_, &ty::Opaque(..)) => (generalize(a, true)?, b),
415415
_ => unreachable!(),
416416
};
417-
self.delegate.register_opaque_type(a, b, true)?;
417+
let cause = ObligationCause::dummy_with_span(self.delegate.span());
418+
let obligations = self
419+
.infcx
420+
.handle_opaque_type(a, b, true, &cause, self.delegate.param_env())?
421+
.obligations;
422+
self.delegate.register_opaque_type_obligations(obligations)?;
418423
trace!(a = ?a.kind(), b = ?b.kind(), "opaque type instantiated");
419424
Ok(a)
420425
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl<'tcx> InferCtxt<'tcx> {
103103
return Ok(InferOk { value: (), obligations: vec![] });
104104
}
105105
let (a, b) = if a_is_expected { (a, b) } else { (b, a) };
106-
let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
106+
let process = |a: Ty<'tcx>, b: Ty<'tcx>, a_is_expected| match *a.kind() {
107107
ty::Opaque(def_id, substs) if def_id.is_local() => {
108108
let def_id = def_id.expect_local();
109109
let origin = match self.defining_use_anchor {
@@ -169,13 +169,14 @@ impl<'tcx> InferCtxt<'tcx> {
169169
param_env,
170170
b,
171171
origin,
172+
a_is_expected,
172173
))
173174
}
174175
_ => None,
175176
};
176-
if let Some(res) = process(a, b) {
177+
if let Some(res) = process(a, b,true) {
177178
res
178-
} else if let Some(res) = process(b, a) {
179+
} else if let Some(res) = process(b, a,false) {
179180
res
180181
} else {
181182
let (a, b) = self.resolve_vars_if_possible((a, b));
@@ -514,13 +515,14 @@ impl UseKind {
514515

515516
impl<'tcx> InferCtxt<'tcx> {
516517
#[instrument(skip(self), level = "debug")]
517-
pubfn register_hidden_type(
518+
fn register_hidden_type(
518519
&self,
519520
opaque_type_key: OpaqueTypeKey<'tcx>,
520521
cause: ObligationCause<'tcx>,
521522
param_env: ty::ParamEnv<'tcx>,
522523
hidden_ty: Ty<'tcx>,
523524
origin: hir::OpaqueTyOrigin,
525+
a_is_expected: bool,
524526
) -> InferResult<'tcx, ()> {
525527
let tcx = self.tcx;
526528
let OpaqueTypeKey { def_id, substs } = opaque_type_key;
@@ -539,7 +541,8 @@ impl<'tcx> InferCtxt<'tcx> {
539541
origin,
540542
);
541543
if let Some(prev) = prev {
542-
obligations = self.at(&cause, param_env).eq(prev, hidden_ty)?.obligations;
544+
obligations =
545+
self.at(&cause, param_env).eq_exp(a_is_expected, prev, hidden_ty)?.obligations;
543546
}
544547

545548
let item_bounds = tcx.bound_explicit_item_bounds(def_id.to_def_id());

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

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use super::combine::{CombineFields, RelationDir};
22
use super::SubregionOrigin;
33

44
use crate::infer::combine::ConstEquateRelation;
5-
use crate::infer::{TypeVariableOrigin, TypeVariableOriginKind};
65
use crate::traits::Obligation;
7-
use rustc_middle::ty::error::{ExpectedFound, TypeError};
86
use rustc_middle::ty::relate::{Cause, Relate, RelateResult, TypeRelation};
97
use rustc_middle::ty::visit::TypeVisitable;
108
use rustc_middle::ty::TyVar;
@@ -130,39 +128,18 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
130128
(&ty::Opaque(did, ..), _) | (_, &ty::Opaque(did, ..))
131129
if self.fields.define_opaque_types && did.is_local() =>
132130
{
133-
let mut generalize = |ty, ty_is_expected| {
134-
let var = infcx.next_ty_var_id_in_universe(
135-
TypeVariableOrigin {
136-
kind: TypeVariableOriginKind::MiscVariable,
137-
span: self.fields.trace.cause.span,
138-
},
139-
ty::UniverseIndex::ROOT,
140-
);
141-
self.fields.instantiate(ty, RelationDir::SubtypeOf, var, ty_is_expected)?;
142-
Ok(infcx.tcx.mk_ty_var(var))
143-
};
144-
let (a, b) = if self.a_is_expected { (a, b) } else { (b, a) };
145-
let (ga, gb) = match (a.kind(), b.kind()) {
146-
(&ty::Opaque(..), _) => (a, generalize(b, true)?),
147-
(_, &ty::Opaque(..)) => (generalize(a, false)?, b),
148-
_ => unreachable!(),
149-
};
150131
self.fields.obligations.extend(
151132
infcx
152-
.handle_opaque_type(ga, gb, true, &self.fields.trace.cause, self.param_env())
153-
// Don't leak any generalized type variables out of this
154-
// subtyping relation in the case of a type error.
155-
.map_err(|err| {
156-
let (ga, gb) = self.fields.infcx.resolve_vars_if_possible((ga, gb));
157-
if let TypeError::Sorts(sorts) = err && sorts.expected == ga && sorts.found == gb {
158-
TypeError::Sorts(ExpectedFound { expected: a, found: b })
159-
} else {
160-
err
161-
}
162-
})?
133+
.handle_opaque_type(
134+
a,
135+
b,
136+
self.a_is_expected,
137+
&self.fields.trace.cause,
138+
self.param_env(),
139+
)?
163140
.obligations,
164141
);
165-
Ok(ga)
142+
Ok(a)
166143
}
167144
// Optimization of GeneratorWitness relation since we know that all
168145
// free regions are replaced with bound regions during construction.

‎compiler/rustc_metadata/src/rmeta/decoder.rs‎

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,15 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
773773
}
774774

775775
fn opt_item_name(self, item_index: DefIndex) -> Option<Symbol> {
776-
self.def_key(item_index).disambiguated_data.data.get_opt_name()
776+
let def_key = self.def_key(item_index);
777+
def_key.disambiguated_data.data.get_opt_name().or_else(|| {
778+
if def_key.disambiguated_data.data == DefPathData::Ctor {
779+
let parent_index = def_key.parent.expect("no parent for a constructor");
780+
self.def_key(parent_index).disambiguated_data.data.get_opt_name()
781+
} else {
782+
None
783+
}
784+
})
777785
}
778786

779787
fn item_name(self, item_index: DefIndex) -> Symbol {
@@ -905,7 +913,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
905913
.get(self, item_id)
906914
.unwrap_or_else(LazyArray::empty)
907915
.decode(self)
908-
.map(|index| self.get_variant(&self.def_kind(index), index, did))
916+
.filter_map(|index| {
917+
let kind = self.def_kind(index);
918+
match kind {
919+
DefKind::Ctor(..) => None,
920+
_ => Some(self.get_variant(&kind, index, did)),
921+
}
922+
})
909923
.collect()
910924
} else {
911925
std::iter::once(self.get_variant(&kind, item_id, did)).collect()
@@ -1029,50 +1043,27 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10291043

10301044
callback(ModChild { ident, res, vis, span, macro_rules });
10311045

1032-
// For non-re-export structs and variants add their constructors to children.
1033-
// Re-export lists automatically contain constructors when necessary.
1034-
match kind {
1035-
DefKind::Struct => {
1036-
if let Some((ctor_def_id, ctor_kind)) =
1037-
self.get_ctor_def_id_and_kind(child_index)
1038-
{
1039-
let ctor_res =
1040-
Res::Def(DefKind::Ctor(CtorOf::Struct, ctor_kind), ctor_def_id);
1041-
let vis = self.get_visibility(ctor_def_id.index);
1042-
callback(ModChild {
1043-
ident,
1044-
res: ctor_res,
1045-
vis,
1046-
span,
1047-
macro_rules: false,
1048-
});
1049-
}
1050-
}
1051-
DefKind::Variant => {
1052-
// Braced variants, unlike structs, generate unusable names in
1053-
// value namespace, they are reserved for possible future use.
1054-
// It's ok to use the variant's id as a ctor id since an
1055-
// error will be reported on any use of such resolution anyway.
1056-
let (ctor_def_id, ctor_kind) = self
1057-
.get_ctor_def_id_and_kind(child_index)
1058-
.unwrap_or((def_id, CtorKind::Fictive));
1059-
let ctor_res =
1060-
Res::Def(DefKind::Ctor(CtorOf::Variant, ctor_kind), ctor_def_id);
1061-
let mut vis = self.get_visibility(ctor_def_id.index);
1062-
if ctor_def_id == def_id && vis.is_public() {
1063-
// For non-exhaustive variants lower the constructor visibility to
1064-
// within the crate. We only need this for fictive constructors,
1065-
// for other constructors correct visibilities
1066-
// were already encoded in metadata.
1067-
let mut attrs = self.get_item_attrs(def_id.index, sess);
1068-
if attrs.any(|item| item.has_name(sym::non_exhaustive)) {
1069-
let crate_def_id = self.local_def_id(CRATE_DEF_INDEX);
1070-
vis = ty::Visibility::Restricted(crate_def_id);
1071-
}
1046+
// For non-reexport variants add their fictive constructors to children.
1047+
// Braced variants, unlike structs, generate unusable names in value namespace,
1048+
// they are reserved for possible future use. It's ok to use the variant's id as
1049+
// a ctor id since an error will be reported on any use of such resolution anyway.
1050+
// Reexport lists automatically contain such constructors when necessary.
1051+
if kind == DefKind::Variant && self.get_ctor_def_id_and_kind(child_index).is_none()
1052+
{
1053+
let ctor_res =
1054+
Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Fictive), def_id);
1055+
let mut vis = vis;
1056+
if vis.is_public() {
1057+
// For non-exhaustive variants lower the constructor visibility to
1058+
// within the crate. We only need this for fictive constructors,
1059+
// for other constructors correct visibilities
1060+
// were already encoded in metadata.
1061+
let mut attrs = self.get_item_attrs(def_id.index, sess);
1062+
if attrs.any(|item| item.has_name(sym::non_exhaustive)) {
1063+
vis = ty::Visibility::Restricted(self.local_def_id(CRATE_DEF_INDEX));
10721064
}
1073-
callback(ModChild { ident, res: ctor_res, vis, span, macro_rules: false });
10741065
}
1075-
_ => {}
1066+
callback(ModChild{ ident,res: ctor_res, vis, span,macro_rules:false});
10761067
}
10771068
}
10781069
}

0 commit comments

Comments
(0)

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