Skip to content

Commit 4331852

Browse files
committed
Auto merge of #70742 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum
[beta] backport 4 PRs This backports the following PRs: * parse_and_disallow_postfix_after_cast: account for `ExprKind::Err`. #70556 * Account for bad placeholder types in where clauses #70294 * Fix "since" field for `Once::is_complete`'s `#[stable]` attribute #70018 * Ensure HAS_FREE_LOCAL_NAMES is set for ReFree #69956 All commits cherry picked cleanly.
2 parents 4c587bb + 223e1b5 commit 4331852

13 files changed

+234
-113
lines changed

src/librustc/ty/mod.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -554,24 +554,26 @@ bitflags! {
554554
/// Does this have [ConstKind::Placeholder]?
555555
const HAS_CT_PLACEHOLDER = 1 << 8;
556556

557+
/// `true` if there are "names" of regions and so forth
558+
/// that are local to a particular fn/inferctxt
559+
const HAS_FREE_LOCAL_REGIONS = 1 << 9;
560+
557561
/// `true` if there are "names" of types and regions and so forth
558562
/// that are local to a particular fn
559563
const HAS_FREE_LOCAL_NAMES = TypeFlags::HAS_TY_PARAM.bits
560-
| TypeFlags::HAS_RE_PARAM.bits
561564
| TypeFlags::HAS_CT_PARAM.bits
562565
| TypeFlags::HAS_TY_INFER.bits
563-
| TypeFlags::HAS_RE_INFER.bits
564566
| TypeFlags::HAS_CT_INFER.bits
565567
| TypeFlags::HAS_TY_PLACEHOLDER.bits
566-
| TypeFlags::HAS_RE_PLACEHOLDER.bits
567-
| TypeFlags::HAS_CT_PLACEHOLDER.bits;
568+
| TypeFlags::HAS_CT_PLACEHOLDER.bits
569+
| TypeFlags::HAS_FREE_LOCAL_REGIONS.bits;
568570

569571
/// Does this have [Projection] or [UnnormalizedProjection]?
570-
const HAS_TY_PROJECTION = 1 << 9;
572+
const HAS_TY_PROJECTION = 1 << 10;
571573
/// Does this have [Opaque]?
572-
const HAS_TY_OPAQUE = 1 << 10;
574+
const HAS_TY_OPAQUE = 1 << 11;
573575
/// Does this have [ConstKind::Unevaluated]?
574-
const HAS_CT_PROJECTION = 1 << 11;
576+
const HAS_CT_PROJECTION = 1 << 12;
575577

576578
/// Could this type be normalized further?
577579
const HAS_PROJECTION = TypeFlags::HAS_TY_PROJECTION.bits
@@ -580,21 +582,21 @@ bitflags! {
580582

581583
/// Present if the type belongs in a local type context.
582584
/// Set for placeholders and inference variables that are not "Fresh".
583-
const KEEP_IN_LOCAL_TCX = 1 << 12;
585+
const KEEP_IN_LOCAL_TCX = 1 << 13;
584586

585587
/// Is an error type reachable?
586-
const HAS_TY_ERR = 1 << 13;
588+
const HAS_TY_ERR = 1 << 14;
587589

588590
/// Does this have any region that "appears free" in the type?
589591
/// Basically anything but [ReLateBound] and [ReErased].
590-
const HAS_FREE_REGIONS = 1 << 14;
592+
const HAS_FREE_REGIONS = 1 << 15;
591593

592594
/// Does this have any [ReLateBound] regions? Used to check
593595
/// if a global bound is safe to evaluate.
594-
const HAS_RE_LATE_BOUND = 1 << 15;
596+
const HAS_RE_LATE_BOUND = 1 << 16;
595597

596598
/// Does this have any [ReErased] regions?
597-
const HAS_RE_ERASED = 1 << 16;
599+
const HAS_RE_ERASED = 1 << 17;
598600

599601
/// Flags representing the nominal content of a type,
600602
/// computed by FlagsComputation. If you add a new nominal
@@ -608,6 +610,7 @@ bitflags! {
608610
| TypeFlags::HAS_TY_PLACEHOLDER.bits
609611
| TypeFlags::HAS_RE_PLACEHOLDER.bits
610612
| TypeFlags::HAS_CT_PLACEHOLDER.bits
613+
| TypeFlags::HAS_FREE_LOCAL_REGIONS.bits
611614
| TypeFlags::HAS_TY_PROJECTION.bits
612615
| TypeFlags::HAS_TY_OPAQUE.bits
613616
| TypeFlags::HAS_CT_PROJECTION.bits

src/librustc/ty/sty.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -1743,42 +1743,42 @@ impl RegionKind {
17431743
}
17441744
}
17451745

1746-
pub fn keep_in_local_tcx(&self) -> bool {
1747-
if let ty::ReVar(..) = self { true } else { false }
1748-
}
1749-
17501746
pub fn type_flags(&self) -> TypeFlags {
17511747
let mut flags = TypeFlags::empty();
17521748

1753-
if self.keep_in_local_tcx() {
1754-
flags = flags | TypeFlags::KEEP_IN_LOCAL_TCX;
1755-
}
1756-
17571749
match *self {
17581750
ty::ReVar(..) => {
17591751
flags = flags | TypeFlags::HAS_FREE_REGIONS;
1752+
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
17601753
flags = flags | TypeFlags::HAS_RE_INFER;
1754+
flags = flags | TypeFlags::KEEP_IN_LOCAL_TCX;
17611755
}
17621756
ty::RePlaceholder(..) => {
17631757
flags = flags | TypeFlags::HAS_FREE_REGIONS;
1758+
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
17641759
flags = flags | TypeFlags::HAS_RE_PLACEHOLDER;
17651760
}
1766-
ty::ReLateBound(..) => {
1767-
flags = flags | TypeFlags::HAS_RE_LATE_BOUND;
1768-
}
17691761
ty::ReEarlyBound(..) => {
17701762
flags = flags | TypeFlags::HAS_FREE_REGIONS;
1763+
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
17711764
flags = flags | TypeFlags::HAS_RE_PARAM;
17721765
}
1773-
ty::ReEmpty(_) | ty::ReStatic | ty::ReFree { .. } | ty::ReScope { .. } => {
1766+
ty::ReFree { .. } | ty::ReScope { .. } => {
17741767
flags = flags | TypeFlags::HAS_FREE_REGIONS;
1768+
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
17751769
}
1776-
ty::ReErased => {
1777-
flags = flags | TypeFlags::HAS_RE_ERASED;
1770+
ty::ReEmpty(_) | ty::ReStatic => {
1771+
flags = flags | TypeFlags::HAS_FREE_REGIONS;
17781772
}
17791773
ty::ReClosureBound(..) => {
17801774
flags = flags | TypeFlags::HAS_FREE_REGIONS;
17811775
}
1776+
ty::ReLateBound(..) => {
1777+
flags = flags | TypeFlags::HAS_RE_LATE_BOUND;
1778+
}
1779+
ty::ReErased => {
1780+
flags = flags | TypeFlags::HAS_RE_ERASED;
1781+
}
17821782
}
17831783

17841784
debug!("type_flags({:?}) = {:?}", self, flags);

src/librustc_parse/parser/expr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ impl<'a> Parser<'a> {
638638
ExprKind::MethodCall(_, _) => "a method call",
639639
ExprKind::Call(_, _) => "a function call",
640640
ExprKind::Await(_) => "`.await`",
641+
ExprKind::Err => return Ok(with_postfix),
641642
_ => unreachable!("parse_dot_or_call_expr_with_ shouldn't produce this"),
642643
}
643644
);

src/librustc_typeck/astconv.rs

+14-20
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId};
2323
use rustc_hir as hir;
2424
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
2525
use rustc_hir::def_id::DefId;
26-
use rustc_hir::intravisit::Visitor;
26+
use rustc_hir::intravisit::{walk_generics, Visitor};
2727
use rustc_hir::print;
2828
use rustc_hir::{Constness, ExprKind, GenericArg, GenericArgs};
2929
use rustc_infer::traits;
@@ -838,18 +838,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
838838
}
839839
},
840840
);
841-
if !inferred_params.is_empty() {
842-
// We always collect the spans for placeholder types when evaluating `fn`s, but we
843-
// only want to emit an error complaining about them if infer types (`_`) are not
844-
// allowed. `allow_ty_infer` gates this behavior.
845-
crate::collect::placeholder_type_error(
846-
tcx,
847-
inferred_params[0],
848-
&[],
849-
inferred_params,
850-
false,
851-
);
852-
}
853841

854842
self.complain_about_missing_type_params(
855843
missing_type_params,
@@ -2734,7 +2722,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
27342722
}
27352723
hir::TyKind::BareFn(ref bf) => {
27362724
require_c_abi_if_c_variadic(tcx, &bf.decl, bf.abi, ast_ty.span);
2737-
tcx.mk_fn_ptr(self.ty_of_fn(bf.unsafety, bf.abi, &bf.decl, &[], None))
2725+
tcx.mk_fn_ptr(self.ty_of_fn(
2726+
bf.unsafety,
2727+
bf.abi,
2728+
&bf.decl,
2729+
&hir::Generics::empty(),
2730+
None,
2731+
))
27382732
}
27392733
hir::TyKind::TraitObject(ref bounds, ref lifetime) => {
27402734
self.conv_object_ty_poly_trait_ref(ast_ty.span, bounds, lifetime)
@@ -2917,7 +2911,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
29172911
unsafety: hir::Unsafety,
29182912
abi: abi::Abi,
29192913
decl: &hir::FnDecl<'_>,
2920-
generic_params: &[hir::GenericParam<'_>],
2914+
generics: &hir::Generics<'_>,
29212915
ident_span: Option<Span>,
29222916
) -> ty::PolyFnSig<'tcx> {
29232917
debug!("ty_of_fn");
@@ -2929,6 +2923,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
29292923
for ty in decl.inputs {
29302924
visitor.visit_ty(ty);
29312925
}
2926+
walk_generics(&mut visitor, generics);
2927+
29322928
let input_tys = decl.inputs.iter().map(|a| self.ty_of_arg(a, None));
29332929
let output_ty = match decl.output {
29342930
hir::FnRetTy::Return(ref output) => {
@@ -2950,7 +2946,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
29502946
crate::collect::placeholder_type_error(
29512947
tcx,
29522948
ident_span.map(|sp| sp.shrink_to_hi()).unwrap_or(DUMMY_SP),
2953-
generic_params,
2949+
&generics.params[..],
29542950
visitor.0,
29552951
ident_span.is_some(),
29562952
);
@@ -2976,8 +2972,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
29762972
tcx.sess,
29772973
decl.output.span(),
29782974
E0581,
2979-
"return type references {} \
2980-
which is not constrained by the fn input types",
2975+
"return type references {} which is not constrained by the fn input types",
29812976
lifetime_name
29822977
);
29832978
if let ty::BrAnon(_) = *br {
@@ -2988,8 +2983,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
29882983
// though we can easily give a hint that ought to be
29892984
// relevant.
29902985
err.note(
2991-
"lifetimes appearing in an associated type \
2992-
are not considered constrained",
2986+
"lifetimes appearing in an associated type are not considered constrained",
29932987
);
29942988
}
29952989
err.emit();

src/librustc_typeck/check/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,14 @@ fn typeck_tables_of_with_fallback<'tcx>(
10041004
let fcx = if let (Some(header), Some(decl)) = (fn_header, fn_decl) {
10051005
let fn_sig = if crate::collect::get_infer_ret_ty(&decl.output).is_some() {
10061006
let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id);
1007-
AstConv::ty_of_fn(&fcx, header.unsafety, header.abi, decl, &[], None)
1007+
AstConv::ty_of_fn(
1008+
&fcx,
1009+
header.unsafety,
1010+
header.abi,
1011+
decl,
1012+
&hir::Generics::empty(),
1013+
None,
1014+
)
10081015
} else {
10091016
tcx.fn_sig(def_id)
10101017
};

src/librustc_typeck/collect.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
14671467
sig.header.unsafety,
14681468
sig.header.abi,
14691469
&sig.decl,
1470-
&generics.params[..],
1470+
&generics,
14711471
Some(ident.span),
14721472
),
14731473
}
@@ -1478,14 +1478,9 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
14781478
ident,
14791479
generics,
14801480
..
1481-
}) => AstConv::ty_of_fn(
1482-
&icx,
1483-
header.unsafety,
1484-
header.abi,
1485-
decl,
1486-
&generics.params[..],
1487-
Some(ident.span),
1488-
),
1481+
}) => {
1482+
AstConv::ty_of_fn(&icx, header.unsafety, header.abi, decl, &generics, Some(ident.span))
1483+
}
14891484

14901485
ForeignItem(&hir::ForeignItem { kind: ForeignItemKind::Fn(ref fn_decl, _, _), .. }) => {
14911486
let abi = tcx.hir().get_foreign_abi(hir_id);
@@ -2110,7 +2105,14 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
21102105
} else {
21112106
hir::Unsafety::Unsafe
21122107
};
2113-
let fty = AstConv::ty_of_fn(&ItemCtxt::new(tcx, def_id), unsafety, abi, decl, &[], None);
2108+
let fty = AstConv::ty_of_fn(
2109+
&ItemCtxt::new(tcx, def_id),
2110+
unsafety,
2111+
abi,
2112+
decl,
2113+
&hir::Generics::empty(),
2114+
None,
2115+
);
21142116

21152117
// Feature gate SIMD types in FFI, since I am not sure that the
21162118
// ABIs are handled at all correctly. -huonw

src/libstd/sync/once.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl Once {
363363
/// assert!(handle.join().is_err());
364364
/// assert_eq!(INIT.is_completed(), false);
365365
/// ```
366-
#[stable(feature = "once_is_completed", since = "1.44.0")]
366+
#[stable(feature = "once_is_completed", since = "1.43.0")]
367367
#[inline]
368368
pub fn is_completed(&self) -> bool {
369369
// An `Acquire` load is enough because that makes all the initialization

src/test/ui/did_you_mean/bad-assoc-ty.rs

+32
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,36 @@ trait K<A, B> {}
4949
fn foo<X: K<_, _>>(x: X) {}
5050
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
5151

52+
fn bar<F>(_: F) where F: Fn() -> _ {}
53+
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
54+
55+
fn baz<F: Fn() -> _>(_: F) {}
56+
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
57+
58+
struct L<F>(F) where F: Fn() -> _;
59+
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
60+
struct M<F> where F: Fn() -> _ {
61+
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
62+
a: F,
63+
}
64+
enum N<F> where F: Fn() -> _ {
65+
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
66+
Foo(F),
67+
}
68+
69+
union O<F> where F: Fn() -> _ {
70+
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
71+
//~| ERROR unions with non-`Copy` fields are unstable
72+
foo: F,
73+
}
74+
75+
trait P<F> where F: Fn() -> _ {
76+
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
77+
}
78+
79+
trait Q {
80+
fn foo<F>(_: F) where F: Fn() -> _ {}
81+
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
82+
}
83+
5284
fn main() {}

0 commit comments

Comments
 (0)