Skip to content

Commit 01af504

Browse files
committed
Auto merge of rust-lang#102666 - matthiaskrgr:rollup-tuge18t, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#102241 (Package `rust-docs-json` into nightly components (take 3)) - rust-lang#102488 (Check generic argument compatibility when projecting assoc ty) - rust-lang#102647 (Only allow ~const bounds for traits with #[const_trait]) - rust-lang#102648 (Add test for rust-lang#102605) - rust-lang#102651 (It's not about types or consts, but the lack of regions) - rust-lang#102653 (resolve instance: missing value to `delay_span_bug`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 02cd79a + db94aed commit 01af504

File tree

73 files changed

+434
-201
lines changed

Some content is hidden

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

73 files changed

+434
-201
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
236236
.unwrap();
237237
let mut hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
238238
trace!("finalized opaque type {:?} to {:#?}", opaque_type_key, hidden_type.ty.kind());
239-
if hidden_type.has_infer_types_or_consts() {
239+
if hidden_type.has_non_region_infer() {
240240
infcx.tcx.sess.delay_span_bug(
241241
decl.hidden_type.span,
242242
&format!("could not resolve {:#?}", hidden_type.ty.kind()),

compiler/rustc_hir_analysis/src/check/fn_ctxt/_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9191
mutate_fulfillment_errors: impl Fn(&mut Vec<traits::FulfillmentError<'tcx>>),
9292
) -> Ty<'tcx> {
9393
// No Infer()? Nothing needs doing.
94-
if !ty.has_infer_types_or_consts() {
94+
if !ty.has_non_region_infer() {
9595
debug!("no inference var, nothing needs doing");
9696
return ty;
9797
}
9898

9999
// If `ty` is a type variable, see whether we already know what it is.
100100
ty = self.resolve_vars_if_possible(ty);
101-
if !ty.has_infer_types_or_consts() {
101+
if !ty.has_non_region_infer() {
102102
debug!(?ty);
103103
return ty;
104104
}

compiler/rustc_hir_analysis/src/check/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
6363
let get_operand_ty = |expr| {
6464
let ty = self.typeck_results.borrow().expr_ty_adjusted(expr);
6565
let ty = self.resolve_vars_if_possible(ty);
66-
if ty.has_infer_types_or_consts() {
66+
if ty.has_non_region_infer() {
6767
assert!(self.is_tainted_by_errors());
6868
self.tcx.ty_error()
6969
} else {

compiler/rustc_hir_analysis/src/check/intrinsicck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
149149
target_features: &FxHashSet<Symbol>,
150150
) -> Option<InlineAsmType> {
151151
let ty = (self.get_operand_ty)(expr);
152-
if ty.has_infer_types_or_consts() {
152+
if ty.has_non_region_infer() {
153153
bug!("inference variable in asm operand ty: {:?} {:?}", expr, ty);
154154
}
155155
let asm_ty_isize = match self.tcx.sess.target.pointer_width {

compiler/rustc_hir_analysis/src/check/op.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
471471
// This has nothing here because it means we did string
472472
// concatenation (e.g., "Hello " + "World!"). This means
473473
// we don't want the note in the else clause to be emitted
474-
} else if lhs_ty.has_param_types_or_consts() {
474+
} else if lhs_ty.has_non_region_param() {
475475
// Look for a TraitPredicate in the Fulfillment errors,
476476
// and use it to generate a suggestion.
477477
//
@@ -657,7 +657,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
657657
format!("cannot apply unary operator `{}`", op.as_str()),
658658
);
659659

660-
if operand_ty.has_param_types_or_consts() {
660+
if operand_ty.has_non_region_param() {
661661
let predicates = errors.iter().filter_map(|error| {
662662
error.obligation.predicate.to_opt_poly_trait_pred()
663663
});

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1428,9 +1428,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
14281428
let substituted_pred = predicates.rebind(pred).subst(tcx, substs);
14291429
// Don't check non-defaulted params, dependent defaults (including lifetimes)
14301430
// or preds with multiple params.
1431-
if substituted_pred.has_param_types_or_consts()
1432-
|| param_count.params.len() > 1
1433-
|| has_region
1431+
if substituted_pred.has_non_region_param() || param_count.params.len() > 1 || has_region
14341432
{
14351433
None
14361434
} else if predicates.0.predicates.iter().any(|&(p, _)| p == substituted_pred) {

compiler/rustc_infer/src/infer/mod.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
712712
) -> bool {
713713
// Reject any attempt to unify two unevaluated constants that contain inference
714714
// variables, since inference variables in queries lead to ICEs.
715-
if a.substs.has_infer_types_or_consts()
716-
|| b.substs.has_infer_types_or_consts()
717-
|| param_env.has_infer_types_or_consts()
715+
if a.substs.has_non_region_infer()
716+
|| b.substs.has_non_region_infer()
717+
|| param_env.has_non_region_infer()
718718
{
719719
debug!("a or b or param_env contain infer vars in its substs -> cannot unify");
720720
return false;
@@ -1734,7 +1734,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17341734

17351735
// Postpone the evaluation of constants whose substs depend on inference
17361736
// variables
1737-
if substs.has_infer_types_or_consts() {
1737+
if substs.has_non_region_infer() {
17381738
let ac = AbstractConst::new(self.tcx, unevaluated);
17391739
match ac {
17401740
Ok(None) => {
@@ -2072,21 +2072,17 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>(
20722072
) -> SubstsRef<'tcx> {
20732073
tcx.mk_substs(substs.iter().enumerate().map(|(idx, arg)| {
20742074
match arg.unpack() {
2075-
GenericArgKind::Type(_)
2076-
if arg.has_param_types_or_consts() || arg.has_infer_types_or_consts() =>
2077-
{
2075+
GenericArgKind::Type(_) if arg.has_non_region_param() || arg.has_non_region_infer() => {
20782076
tcx.mk_ty(ty::Placeholder(ty::PlaceholderType {
20792077
universe: ty::UniverseIndex::ROOT,
20802078
name: ty::BoundVar::from_usize(idx),
20812079
}))
20822080
.into()
20832081
}
2084-
GenericArgKind::Const(ct)
2085-
if ct.has_infer_types_or_consts() || ct.has_param_types_or_consts() =>
2086-
{
2082+
GenericArgKind::Const(ct) if ct.has_non_region_infer() || ct.has_non_region_param() => {
20872083
let ty = ct.ty();
20882084
// If the type references param or infer, replace that too...
2089-
if ty.has_param_types_or_consts() || ty.has_infer_types_or_consts() {
2085+
if ty.has_non_region_param() || ty.has_non_region_infer() {
20902086
bug!("const `{ct}`'s type should not reference params or types");
20912087
}
20922088
tcx.mk_const(ty::ConstS {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ where
357357
// In NLL, we don't have type inference variables
358358
// floating around, so we can do this rather imprecise
359359
// variant of the occurs-check.
360-
assert!(!generalized_ty.has_infer_types_or_consts());
360+
assert!(!generalized_ty.has_non_region_infer());
361361
}
362362

363363
self.infcx.inner.borrow_mut().type_variables().instantiate(vid, generalized_ty);

compiler/rustc_infer/src/infer/resolve.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticVarResolver<'a, 'tcx> {
3232
}
3333

3434
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
35-
if !t.has_infer_types_or_consts() {
35+
if !t.has_non_region_infer() {
3636
t // micro-optimize -- if there is nothing in this type that this fold affects...
3737
} else {
3838
let t = self.infcx.shallow_resolve(t);
@@ -41,7 +41,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticVarResolver<'a, 'tcx> {
4141
}
4242

4343
fn fold_const(&mut self, ct: Const<'tcx>) -> Const<'tcx> {
44-
if !ct.has_infer_types_or_consts() {
44+
if !ct.has_non_region_infer() {
4545
ct // micro-optimize -- if there is nothing in this const that this fold affects...
4646
} else {
4747
let ct = self.infcx.shallow_resolve(ct);

compiler/rustc_middle/src/mir/interpret/queries.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'tcx> TyCtxt<'tcx> {
4545
//
4646
// When trying to evaluate constants containing inference variables,
4747
// use `Infcx::const_eval_resolve` instead.
48-
if ct.substs.has_infer_types_or_consts() {
48+
if ct.substs.has_non_region_infer() {
4949
bug!("did not expect inference variables here");
5050
}
5151

@@ -76,7 +76,7 @@ impl<'tcx> TyCtxt<'tcx> {
7676
//
7777
// When trying to evaluate constants containing inference variables,
7878
// use `Infcx::const_eval_resolve` instead.
79-
if ct.substs.has_infer_types_or_consts() {
79+
if ct.substs.has_non_region_infer() {
8080
bug!("did not expect inference variables here");
8181
}
8282

compiler/rustc_middle/src/mir/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl<'tcx> Body<'tcx> {
313313
is_polymorphic: false,
314314
tainted_by_errors,
315315
};
316-
body.is_polymorphic = body.has_param_types_or_consts();
316+
body.is_polymorphic = body.has_non_region_param();
317317
body
318318
}
319319

@@ -339,7 +339,7 @@ impl<'tcx> Body<'tcx> {
339339
is_polymorphic: false,
340340
tainted_by_errors: None,
341341
};
342-
body.is_polymorphic = body.has_param_types_or_consts();
342+
body.is_polymorphic = body.has_non_region_param();
343343
body
344344
}
345345

@@ -2760,15 +2760,15 @@ fn pretty_print_const_value<'tcx>(
27602760
}
27612761
// Aggregates, printed as array/tuple/struct/variant construction syntax.
27622762
//
2763-
// NB: the `has_param_types_or_consts` check ensures that we can use
2763+
// NB: the `has_non_region_param` check ensures that we can use
27642764
// the `destructure_const` query with an empty `ty::ParamEnv` without
27652765
// introducing ICEs (e.g. via `layout_of`) from missing bounds.
27662766
// E.g. `transmute([0usize; 2]): (u8, *mut T)` needs to know `T: Sized`
27672767
// to be able to destructure the tuple into `(0u8, *mut T)
27682768
//
27692769
// FIXME(eddyb) for `--emit=mir`/`-Z dump-mir`, we should provide the
27702770
// correct `ty::ParamEnv` to allow printing *all* constant values.
2771-
(_, ty::Array(..) | ty::Tuple(..) | ty::Adt(..)) if !ty.has_param_types_or_consts() => {
2771+
(_, ty::Array(..) | ty::Tuple(..) | ty::Adt(..)) if !ty.has_non_region_param() => {
27722772
let ct = tcx.lift(ct).unwrap();
27732773
let ty = tcx.lift(ty).unwrap();
27742774
if let Some(contents) = tcx.try_destructure_mir_constant(

compiler/rustc_middle/src/ty/abstract_const.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ impl<'tcx> AbstractConst<'tcx> {
7171
walk_abstract_const::<!, _>(tcx, self, |node| {
7272
match node.root(tcx) {
7373
Node::Leaf(leaf) => {
74-
if leaf.has_infer_types_or_consts() {
74+
if leaf.has_non_region_infer() {
7575
failure_kind = FailureKind::MentionsInfer;
76-
} else if leaf.has_param_types_or_consts() {
76+
} else if leaf.has_non_region_param() {
7777
failure_kind = cmp::min(failure_kind, FailureKind::MentionsParam);
7878
}
7979
}
8080
Node::Cast(_, _, ty) => {
81-
if ty.has_infer_types_or_consts() {
81+
if ty.has_non_region_infer() {
8282
failure_kind = FailureKind::MentionsInfer;
83-
} else if ty.has_param_types_or_consts() {
83+
} else if ty.has_non_region_param() {
8484
failure_kind = cmp::min(failure_kind, FailureKind::MentionsParam);
8585
}
8686
}

compiler/rustc_middle/src/ty/fast_reject.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub fn simplify_type<'tcx>(
132132
// don't unify with anything else as long as they are fully normalized.
133133
//
134134
// We will have to be careful with lazy normalization here.
135-
TreatParams::AsPlaceholder if !ty.has_infer_types_or_consts() => {
135+
TreatParams::AsPlaceholder if !ty.has_non_region_infer() => {
136136
debug!("treating `{}` as a placeholder", ty);
137137
Some(PlaceholderSimplifiedType)
138138
}

compiler/rustc_middle/src/ty/layout.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
244244
tcx: TyCtxt<'tcx>,
245245
param_env: ty::ParamEnv<'tcx>,
246246
) -> Result<SizeSkeleton<'tcx>, LayoutError<'tcx>> {
247-
debug_assert!(!ty.has_infer_types_or_consts());
247+
debug_assert!(!ty.has_non_region_infer());
248248

249249
// First try computing a static layout.
250250
let err = match tcx.layout_of(param_env.and(ty)) {
@@ -260,7 +260,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
260260
let tail = tcx.struct_tail_erasing_lifetimes(pointee, param_env);
261261
match tail.kind() {
262262
ty::Param(_) | ty::Projection(_) => {
263-
debug_assert!(tail.has_param_types_or_consts());
263+
debug_assert!(tail.has_non_region_param());
264264
Ok(SizeSkeleton::Pointer { non_zero, tail: tcx.erase_regions(tail) })
265265
}
266266
_ => bug!(

compiler/rustc_middle/src/ty/visit.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,17 @@ pub trait TypeVisitable<'tcx>: fmt::Debug + Clone {
104104
None
105105
}
106106
}
107-
fn has_param_types_or_consts(&self) -> bool {
108-
self.has_type_flags(TypeFlags::HAS_TY_PARAM | TypeFlags::HAS_CT_PARAM)
107+
fn has_non_region_param(&self) -> bool {
108+
self.has_type_flags(TypeFlags::NEEDS_SUBST - TypeFlags::HAS_RE_PARAM)
109109
}
110110
fn has_infer_regions(&self) -> bool {
111111
self.has_type_flags(TypeFlags::HAS_RE_INFER)
112112
}
113113
fn has_infer_types(&self) -> bool {
114114
self.has_type_flags(TypeFlags::HAS_TY_INFER)
115115
}
116-
fn has_infer_types_or_consts(&self) -> bool {
117-
self.has_type_flags(TypeFlags::HAS_TY_INFER | TypeFlags::HAS_CT_INFER)
116+
fn has_non_region_infer(&self) -> bool {
117+
self.has_type_flags(TypeFlags::NEEDS_INFER - TypeFlags::HAS_RE_INFER)
118118
}
119119
fn needs_infer(&self) -> bool {
120120
self.has_type_flags(TypeFlags::NEEDS_INFER)

compiler/rustc_monomorphize/src/polymorphize.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
290290
impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
291291
#[instrument(level = "debug", skip(self))]
292292
fn visit_const(&mut self, c: Const<'tcx>) -> ControlFlow<Self::BreakTy> {
293-
if !c.has_param_types_or_consts() {
293+
if !c.has_non_region_param() {
294294
return ControlFlow::CONTINUE;
295295
}
296296

@@ -311,7 +311,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
311311
}
312312

313313
fn visit_mir_const(&mut self, constant: ConstantKind<'tcx>) -> ControlFlow<Self::BreakTy> {
314-
if !constant.has_param_types_or_consts() {
314+
if !constant.has_non_region_param() {
315315
return ControlFlow::CONTINUE;
316316
}
317317

@@ -336,7 +336,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
336336

337337
#[instrument(level = "debug", skip(self))]
338338
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
339-
if !ty.has_param_types_or_consts() {
339+
if !ty.has_non_region_param() {
340340
return ControlFlow::CONTINUE;
341341
}
342342

@@ -373,7 +373,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a> {
373373

374374
#[instrument(level = "debug", skip(self))]
375375
fn visit_const(&mut self, c: Const<'tcx>) -> ControlFlow<Self::BreakTy> {
376-
if !c.has_param_types_or_consts() {
376+
if !c.has_non_region_param() {
377377
return ControlFlow::CONTINUE;
378378
}
379379

@@ -391,7 +391,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a> {
391391

392392
#[instrument(level = "debug", skip(self))]
393393
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
394-
if !ty.has_param_types_or_consts() {
394+
if !ty.has_non_region_param() {
395395
return ControlFlow::CONTINUE;
396396
}
397397

compiler/rustc_passes/src/check_const.rs

-26
Original file line numberDiff line numberDiff line change
@@ -191,32 +191,6 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> {
191191
self.tcx.hir()
192192
}
193193

194-
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
195-
let tcx = self.tcx;
196-
if let hir::ItemKind::Impl(hir::Impl {
197-
constness: hir::Constness::Const,
198-
of_trait: Some(trait_ref),
199-
..
200-
}) = item.kind
201-
&& let Some(def_id) = trait_ref.trait_def_id()
202-
{
203-
let source_map = tcx.sess.source_map();
204-
if !tcx.has_attr(def_id, sym::const_trait) {
205-
tcx.sess
206-
.struct_span_err(
207-
source_map.guess_head_span(item.span),
208-
"const `impl`s must be for traits marked with `#[const_trait]`",
209-
)
210-
.span_note(
211-
source_map.guess_head_span(tcx.def_span(def_id)),
212-
"this trait must be annotated with `#[const_trait]`",
213-
)
214-
.emit();
215-
}
216-
}
217-
intravisit::walk_item(self, item);
218-
}
219-
220194
fn visit_anon_const(&mut self, anon: &'tcx hir::AnonConst) {
221195
let kind = Some(hir::ConstContext::Const);
222196
self.recurse_into(kind, None, |this| intravisit::walk_anon_const(this, anon));

compiler/rustc_symbol_mangling/src/v0.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
301301

302302
// Encode impl generic params if the substitutions contain parameters (implying
303303
// polymorphization is enabled) and this isn't an inherent impl.
304-
if impl_trait_ref.is_some() && substs.iter().any(|a| a.has_param_types_or_consts()) {
304+
if impl_trait_ref.is_some() && substs.iter().any(|a| a.has_non_region_param()) {
305305
self = self.path_generic_args(
306306
|this| {
307307
this.path_append_ns(

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
236236
}
237237

238238
Err(ErrorHandled::TooGeneric) => {
239-
let err = if uv.has_infer_types_or_consts() {
239+
let err = if uv.has_non_region_infer() {
240240
NotConstEvaluatable::MentionsInfer
241-
} else if uv.has_param_types_or_consts() {
241+
} else if uv.has_non_region_param() {
242242
NotConstEvaluatable::MentionsParam
243243
} else {
244244
let guar = infcx.tcx.sess.delay_span_bug(span, format!("Missing value for constant, but no error reported?"));
@@ -254,7 +254,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
254254
}
255255
Err(ErrorHandled::Reported(e)) => Err(NotConstEvaluatable::Error(e)),
256256
Ok(_) => {
257-
if uv.substs.has_param_types_or_consts() {
257+
if uv.substs.has_non_region_param() {
258258
assert!(matches!(infcx.tcx.def_kind(uv.def.did), DefKind::AnonConst));
259259
let mir_body = infcx.tcx.mir_for_ctfe_opt_const_arg(uv.def);
260260

0 commit comments

Comments
 (0)