Skip to content

Commit 297273c

Browse files
committed
Auto merge of #94692 - matthiaskrgr:rollup-64p7ya7, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #94636 (Check extra function arg exprs even if the fn is not C-variadic) - #94676 (Remove unnecessary `..` patterns) - #94681 (CTFE engine: expose misc_cast to Miri) - #94684 (Fix rustdoc for GATs with with anonymous bound regions) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2631aee + a1119fd commit 297273c

File tree

13 files changed

+93
-64
lines changed

13 files changed

+93
-64
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -2064,17 +2064,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20642064
)),
20652065
_ => None,
20662066
});
2067-
if let ImplTraitContext::TypeAliasesOpaqueTy { ref mut capturable_lifetimes, .. } =
2068-
itctx
2069-
{
2067+
if let ImplTraitContext::TypeAliasesOpaqueTy { ref mut capturable_lifetimes } = itctx {
20702068
capturable_lifetimes.extend(lt_def_names.clone());
20712069
}
20722070

20732071
let res = this.lower_trait_ref(&p.trait_ref, itctx.reborrow());
20742072

2075-
if let ImplTraitContext::TypeAliasesOpaqueTy { ref mut capturable_lifetimes, .. } =
2076-
itctx
2077-
{
2073+
if let ImplTraitContext::TypeAliasesOpaqueTy { ref mut capturable_lifetimes } = itctx {
20782074
for param in lt_def_names {
20792075
capturable_lifetimes.remove(&param);
20802076
}

compiler/rustc_const_eval/src/interpret/cast.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
9797
Ok(())
9898
}
9999

100-
fn misc_cast(
100+
pub fn misc_cast(
101101
&self,
102102
src: &ImmTy<'tcx, M::PointerTag>,
103103
cast_ty: Ty<'tcx>,
@@ -139,7 +139,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
139139
if let Some(discr) = src.layout.ty.discriminant_for_variant(*self.tcx, index) {
140140
assert!(src.layout.is_zst());
141141
let discr_layout = self.layout_of(discr.ty)?;
142-
return Ok(self.cast_from_scalar(discr.val, discr_layout, cast_ty).into());
142+
return Ok(self.cast_from_int_like(discr.val, discr_layout, cast_ty).into());
143143
}
144144
}
145145
Variants::Multiple { .. } => {}
@@ -169,17 +169,17 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
169169
}
170170
}
171171

172-
// # The remaining source values are scalar.
172+
// # The remaining source values are scalar and "int-like".
173173

174174
// For all remaining casts, we either
175175
// (a) cast a raw ptr to usize, or
176176
// (b) cast from an integer-like (including bool, char, enums).
177177
// In both cases we want the bits.
178178
let bits = src.to_scalar()?.to_bits(src.layout.size)?;
179-
Ok(self.cast_from_scalar(bits, src.layout, cast_ty).into())
179+
Ok(self.cast_from_int_like(bits, src.layout, cast_ty).into())
180180
}
181181

182-
pub(super) fn cast_from_scalar(
182+
fn cast_from_int_like(
183183
&self,
184184
v: u128, // raw bits (there is no ScalarTy so we separate data+layout)
185185
src_layout: TyAndLayout<'tcx>,

compiler/rustc_const_eval/src/interpret/operand.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -681,18 +681,22 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
681681
let tag_val = self.read_immediate(&self.operand_field(op, tag_field)?)?;
682682
assert_eq!(tag_layout.size, tag_val.layout.size);
683683
assert_eq!(tag_layout.abi.is_signed(), tag_val.layout.abi.is_signed());
684-
let tag_val = tag_val.to_scalar()?;
685-
trace!("tag value: {:?}", tag_val);
684+
trace!("tag value: {}", tag_val);
686685

687686
// Figure out which discriminant and variant this corresponds to.
688687
Ok(match *tag_encoding {
689688
TagEncoding::Direct => {
689+
// Generate a specific error if `tag_val` is not an integer.
690+
// (`tag_bits` itself is only used for error messages below.)
690691
let tag_bits = tag_val
692+
.to_scalar()?
691693
.try_to_int()
692694
.map_err(|dbg_val| err_ub!(InvalidTag(dbg_val)))?
693695
.assert_bits(tag_layout.size);
694696
// Cast bits from tag layout to discriminant layout.
695-
let discr_val = self.cast_from_scalar(tag_bits, tag_layout, discr_layout.ty);
697+
// After the checks we did above, this cannot fail.
698+
let discr_val =
699+
self.misc_cast(&tag_val, discr_layout.ty).unwrap().to_scalar().unwrap();
696700
let discr_bits = discr_val.assert_bits(discr_layout.size);
697701
// Convert discriminant to variant index, and catch invalid discriminants.
698702
let index = match *op.layout.ty.kind() {
@@ -712,6 +716,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
712716
(discr_val, index.0)
713717
}
714718
TagEncoding::Niche { dataful_variant, ref niche_variants, niche_start } => {
719+
let tag_val = tag_val.to_scalar()?;
715720
// Compute the variant this niche value/"tag" corresponds to. With niche layout,
716721
// discriminant (encoded in niche/tag) and variant index are the same.
717722
let variants_start = niche_variants.start().as_u32();

compiler/rustc_middle/src/mir/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ pub fn write_allocations<'tcx>(
660660
}
661661
fn alloc_ids_from_const(val: ConstValue<'_>) -> impl Iterator<Item = AllocId> + '_ {
662662
match val {
663-
ConstValue::Scalar(interpret::Scalar::Ptr(ptr, _size)) => {
663+
ConstValue::Scalar(interpret::Scalar::Ptr(ptr, _)) => {
664664
Either::Left(Either::Left(std::iter::once(ptr.provenance)))
665665
}
666666
ConstValue::Scalar(interpret::Scalar::Int { .. }) => {

compiler/rustc_privacy/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> {
852852
self.visit(self.ev.tcx.type_of(param.def_id));
853853
}
854854
}
855-
GenericParamDefKind::Const { has_default, .. } => {
855+
GenericParamDefKind::Const { has_default } => {
856856
self.visit(self.ev.tcx.type_of(param.def_id));
857857
if has_default {
858858
self.visit(self.ev.tcx.const_param_default(param.def_id));

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
405405
}
406406
hir::Node::Item(hir::Item {
407407
kind:
408-
hir::ItemKind::Trait(_, _, generics, _, _)
408+
hir::ItemKind::Trait(_, _, generics, ..)
409409
| hir::ItemKind::Impl(hir::Impl { generics, .. }),
410410
..
411411
}) if projection.is_some() => {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14031403
self.fcx.var_for_def(self.span, param)
14041404
}
14051405
}
1406-
GenericParamDefKind::Const { has_default, .. } => {
1406+
GenericParamDefKind::Const { has_default } => {
14071407
if !infer_args && has_default {
14081408
tcx.const_param_default(param.def_id)
14091409
.subst_spanned(tcx, substs.unwrap(), Some(self.span))

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

+12-10
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
281281
self.demand_suptype(provided_arg.span, formal_input_ty, coerced_ty);
282282
};
283283

284+
let minimum_input_count = formal_input_tys.len();
285+
284286
// Check the arguments.
285287
// We do this in a pretty awful way: first we type-check any arguments
286288
// that are not closures, then we type-check the closures. This is so
@@ -303,7 +305,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
303305
})
304306
}
305307

306-
let minimum_input_count = formal_input_tys.len();
307308
for (idx, arg) in provided_args.iter().enumerate() {
308309
// Warn only for the first loop (the "no closures" one).
309310
// Closure arguments themselves can't be diverging, but
@@ -456,17 +457,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
456457
err.emit();
457458
}
458459

459-
// We also need to make sure we at least write the ty of the other
460-
// arguments which we skipped above.
461-
if c_variadic {
462-
fn variadic_error<'tcx>(sess: &Session, span: Span, ty: Ty<'tcx>, cast_ty: &str) {
463-
use crate::structured_errors::MissingCastForVariadicArg;
460+
for arg in provided_args.iter().skip(minimum_input_count) {
461+
let arg_ty = self.check_expr(&arg);
464462

465-
MissingCastForVariadicArg { sess, span, ty, cast_ty }.diagnostic().emit();
466-
}
463+
if c_variadic {
464+
// We also need to make sure we at least write the ty of the other
465+
// arguments which we skipped above, either because they were additional
466+
// c_variadic args, or because we had an argument count mismatch.
467+
fn variadic_error<'tcx>(sess: &Session, span: Span, ty: Ty<'tcx>, cast_ty: &str) {
468+
use crate::structured_errors::MissingCastForVariadicArg;
467469

468-
for arg in provided_args.iter().skip(expected_arg_count) {
469-
let arg_ty = self.check_expr(&arg);
470+
MissingCastForVariadicArg { sess, span, ty, cast_ty }.diagnostic().emit();
471+
}
470472

471473
// There are a few types which get autopromoted when passed via varargs
472474
// in C but we just error out instead and require explicit casts.

src/librustdoc/clean/mod.rs

+3-16
Original file line numberDiff line numberDiff line change
@@ -402,16 +402,7 @@ fn projection_to_path_segment(ty: ty::ProjectionTy<'_>, cx: &mut DocContext<'_>)
402402
PathSegment {
403403
name: item.name,
404404
args: GenericArgs::AngleBracketed {
405-
args: ty.substs[generics.parent_count..]
406-
.iter()
407-
.map(|ty| match ty.unpack() {
408-
ty::subst::GenericArgKind::Lifetime(lt) => {
409-
GenericArg::Lifetime(lt.clean(cx).unwrap())
410-
}
411-
ty::subst::GenericArgKind::Type(ty) => GenericArg::Type(ty.clean(cx)),
412-
ty::subst::GenericArgKind::Const(c) => GenericArg::Const(Box::new(c.clean(cx))),
413-
})
414-
.collect(),
405+
args: substs_to_args(cx, &ty.substs[generics.parent_count..], false),
415406
bindings: Default::default(),
416407
},
417408
}
@@ -451,7 +442,7 @@ impl Clean<GenericParamDef> for ty::GenericParamDef {
451442
},
452443
)
453444
}
454-
ty::GenericParamDefKind::Const { has_default, .. } => (
445+
ty::GenericParamDefKind::Const { has_default } => (
455446
self.name,
456447
GenericParamDefKind::Const {
457448
did: self.def_id,
@@ -1379,11 +1370,7 @@ fn maybe_expand_private_type_alias(cx: &mut DocContext<'_>, path: &hir::Path<'_>
13791370
});
13801371
if let Some(lt) = lifetime.cloned() {
13811372
let lt_def_id = cx.tcx.hir().local_def_id(param.hir_id);
1382-
let cleaned = if !lt.is_elided() {
1383-
lt.clean(cx)
1384-
} else {
1385-
self::types::Lifetime::elided()
1386-
};
1373+
let cleaned = if !lt.is_elided() { lt.clean(cx) } else { Lifetime::elided() };
13871374
substs.insert(lt_def_id.to_def_id(), SubstParam::Lifetime(cleaned));
13881375
}
13891376
indices.lifetimes += 1;

src/librustdoc/clean/utils.rs

+25-20
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,12 @@ crate fn krate(cx: &mut DocContext<'_>) -> Crate {
7777
Crate { module, primitives, external_traits: cx.external_traits.clone() }
7878
}
7979

80-
fn external_generic_args(
80+
crate fn substs_to_args(
8181
cx: &mut DocContext<'_>,
82-
did: DefId,
83-
has_self: bool,
84-
bindings: Vec<TypeBinding>,
85-
substs: SubstsRef<'_>,
86-
) -> GenericArgs {
87-
let mut skip_self = has_self;
88-
let mut ty_kind = None;
89-
let args: Vec<_> = substs
82+
substs: &[ty::subst::GenericArg<'_>],
83+
mut skip_first: bool,
84+
) -> Vec<GenericArg> {
85+
substs
9086
.iter()
9187
.filter_map(|kind| match kind.unpack() {
9288
GenericArgKind::Lifetime(lt) => match *lt {
@@ -95,23 +91,32 @@ fn external_generic_args(
9591
}
9692
_ => lt.clean(cx).map(GenericArg::Lifetime),
9793
},
98-
GenericArgKind::Type(_) if skip_self => {
99-
skip_self = false;
94+
GenericArgKind::Type(_) if skip_first => {
95+
skip_first = false;
10096
None
10197
}
102-
GenericArgKind::Type(ty) => {
103-
ty_kind = Some(ty.kind());
104-
Some(GenericArg::Type(ty.clean(cx)))
105-
}
98+
GenericArgKind::Type(ty) => Some(GenericArg::Type(ty.clean(cx))),
10699
GenericArgKind::Const(ct) => Some(GenericArg::Const(Box::new(ct.clean(cx)))),
107100
})
108-
.collect();
101+
.collect()
102+
}
103+
104+
fn external_generic_args(
105+
cx: &mut DocContext<'_>,
106+
did: DefId,
107+
has_self: bool,
108+
bindings: Vec<TypeBinding>,
109+
substs: SubstsRef<'_>,
110+
) -> GenericArgs {
111+
let args = substs_to_args(cx, &substs, has_self);
109112

110113
if cx.tcx.fn_trait_kind_from_lang_item(did).is_some() {
111-
let inputs = match ty_kind.unwrap() {
112-
ty::Tuple(tys) => tys.iter().map(|t| t.clean(cx)).collect(),
113-
_ => return GenericArgs::AngleBracketed { args, bindings: bindings.into() },
114-
};
114+
let inputs =
115+
// The trait's first substitution is the one after self, if there is one.
116+
match substs.iter().nth(if has_self { 1 } else { 0 }).unwrap().expect_ty().kind() {
117+
ty::Tuple(tys) => tys.iter().map(|t| t.clean(cx)).collect(),
118+
_ => return GenericArgs::AngleBracketed { args, bindings: bindings.into() },
119+
};
115120
let output = None;
116121
// FIXME(#20299) return type comes from a projection now
117122
// match types[1].kind {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![crate_name = "foo"]
2+
#![feature(generic_associated_types)]
3+
4+
pub trait Trait {
5+
type Gat<'a>;
6+
}
7+
8+
// Make sure that the elided lifetime shows up
9+
10+
// @has foo/type.T.html
11+
// @has - "pub type T = "
12+
// @has - "&lt;'_&gt;"
13+
pub type T = fn(&<() as Trait>::Gat<'_>);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
(|| {})(|| {
3+
//~^ ERROR this function takes 0 arguments but 1 argument was supplied
4+
let b = 1;
5+
});
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0057]: this function takes 0 arguments but 1 argument was supplied
2+
--> $DIR/wrong_argument_ice-4.rs:2:5
3+
|
4+
LL | (|| {})(|| {
5+
| _____^^^^^^^_-
6+
| | |
7+
| | expected 0 arguments
8+
LL | |
9+
LL | | let b = 1;
10+
LL | | });
11+
| |_____- supplied 1 argument
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0057`.

0 commit comments

Comments
 (0)