Skip to content

Commit

Permalink
Auto merge of #70742 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
[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.
  • Loading branch information
bors committed Apr 3, 2020
2 parents 4c587bb + 223e1b5 commit 4331852
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 113 deletions.
27 changes: 15 additions & 12 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,24 +554,26 @@ bitflags! {
/// Does this have [ConstKind::Placeholder]?
const HAS_CT_PLACEHOLDER = 1 << 8;

/// `true` if there are "names" of regions and so forth
/// that are local to a particular fn/inferctxt
const HAS_FREE_LOCAL_REGIONS = 1 << 9;

/// `true` if there are "names" of types and regions and so forth
/// that are local to a particular fn
const HAS_FREE_LOCAL_NAMES = TypeFlags::HAS_TY_PARAM.bits
| TypeFlags::HAS_RE_PARAM.bits
| TypeFlags::HAS_CT_PARAM.bits
| TypeFlags::HAS_TY_INFER.bits
| TypeFlags::HAS_RE_INFER.bits
| TypeFlags::HAS_CT_INFER.bits
| TypeFlags::HAS_TY_PLACEHOLDER.bits
| TypeFlags::HAS_RE_PLACEHOLDER.bits
| TypeFlags::HAS_CT_PLACEHOLDER.bits;
| TypeFlags::HAS_CT_PLACEHOLDER.bits
| TypeFlags::HAS_FREE_LOCAL_REGIONS.bits;

/// Does this have [Projection] or [UnnormalizedProjection]?
const HAS_TY_PROJECTION = 1 << 9;
const HAS_TY_PROJECTION = 1 << 10;
/// Does this have [Opaque]?
const HAS_TY_OPAQUE = 1 << 10;
const HAS_TY_OPAQUE = 1 << 11;
/// Does this have [ConstKind::Unevaluated]?
const HAS_CT_PROJECTION = 1 << 11;
const HAS_CT_PROJECTION = 1 << 12;

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

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

/// Is an error type reachable?
const HAS_TY_ERR = 1 << 13;
const HAS_TY_ERR = 1 << 14;

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

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

/// Does this have any [ReErased] regions?
const HAS_RE_ERASED = 1 << 16;
const HAS_RE_ERASED = 1 << 17;

/// Flags representing the nominal content of a type,
/// computed by FlagsComputation. If you add a new nominal
Expand All @@ -608,6 +610,7 @@ bitflags! {
| TypeFlags::HAS_TY_PLACEHOLDER.bits
| TypeFlags::HAS_RE_PLACEHOLDER.bits
| TypeFlags::HAS_CT_PLACEHOLDER.bits
| TypeFlags::HAS_FREE_LOCAL_REGIONS.bits
| TypeFlags::HAS_TY_PROJECTION.bits
| TypeFlags::HAS_TY_OPAQUE.bits
| TypeFlags::HAS_CT_PROJECTION.bits
Expand Down
28 changes: 14 additions & 14 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1743,42 +1743,42 @@ impl RegionKind {
}
}

pub fn keep_in_local_tcx(&self) -> bool {
if let ty::ReVar(..) = self { true } else { false }
}

pub fn type_flags(&self) -> TypeFlags {
let mut flags = TypeFlags::empty();

if self.keep_in_local_tcx() {
flags = flags | TypeFlags::KEEP_IN_LOCAL_TCX;
}

match *self {
ty::ReVar(..) => {
flags = flags | TypeFlags::HAS_FREE_REGIONS;
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
flags = flags | TypeFlags::HAS_RE_INFER;
flags = flags | TypeFlags::KEEP_IN_LOCAL_TCX;
}
ty::RePlaceholder(..) => {
flags = flags | TypeFlags::HAS_FREE_REGIONS;
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
flags = flags | TypeFlags::HAS_RE_PLACEHOLDER;
}
ty::ReLateBound(..) => {
flags = flags | TypeFlags::HAS_RE_LATE_BOUND;
}
ty::ReEarlyBound(..) => {
flags = flags | TypeFlags::HAS_FREE_REGIONS;
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
flags = flags | TypeFlags::HAS_RE_PARAM;
}
ty::ReEmpty(_) | ty::ReStatic | ty::ReFree { .. } | ty::ReScope { .. } => {
ty::ReFree { .. } | ty::ReScope { .. } => {
flags = flags | TypeFlags::HAS_FREE_REGIONS;
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
}
ty::ReErased => {
flags = flags | TypeFlags::HAS_RE_ERASED;
ty::ReEmpty(_) | ty::ReStatic => {
flags = flags | TypeFlags::HAS_FREE_REGIONS;
}
ty::ReClosureBound(..) => {
flags = flags | TypeFlags::HAS_FREE_REGIONS;
}
ty::ReLateBound(..) => {
flags = flags | TypeFlags::HAS_RE_LATE_BOUND;
}
ty::ReErased => {
flags = flags | TypeFlags::HAS_RE_ERASED;
}
}

debug!("type_flags({:?}) = {:?}", self, flags);
Expand Down
1 change: 1 addition & 0 deletions src/librustc_parse/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ impl<'a> Parser<'a> {
ExprKind::MethodCall(_, _) => "a method call",
ExprKind::Call(_, _) => "a function call",
ExprKind::Await(_) => "`.await`",
ExprKind::Err => return Ok(with_postfix),
_ => unreachable!("parse_dot_or_call_expr_with_ shouldn't produce this"),
}
);
Expand Down
34 changes: 14 additions & 20 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId};
use rustc_hir as hir;
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::Visitor;
use rustc_hir::intravisit::{walk_generics, Visitor};
use rustc_hir::print;
use rustc_hir::{Constness, ExprKind, GenericArg, GenericArgs};
use rustc_infer::traits;
Expand Down Expand Up @@ -838,18 +838,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
},
);
if !inferred_params.is_empty() {
// We always collect the spans for placeholder types when evaluating `fn`s, but we
// only want to emit an error complaining about them if infer types (`_`) are not
// allowed. `allow_ty_infer` gates this behavior.
crate::collect::placeholder_type_error(
tcx,
inferred_params[0],
&[],
inferred_params,
false,
);
}

self.complain_about_missing_type_params(
missing_type_params,
Expand Down Expand Up @@ -2734,7 +2722,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
hir::TyKind::BareFn(ref bf) => {
require_c_abi_if_c_variadic(tcx, &bf.decl, bf.abi, ast_ty.span);
tcx.mk_fn_ptr(self.ty_of_fn(bf.unsafety, bf.abi, &bf.decl, &[], None))
tcx.mk_fn_ptr(self.ty_of_fn(
bf.unsafety,
bf.abi,
&bf.decl,
&hir::Generics::empty(),
None,
))
}
hir::TyKind::TraitObject(ref bounds, ref lifetime) => {
self.conv_object_ty_poly_trait_ref(ast_ty.span, bounds, lifetime)
Expand Down Expand Up @@ -2917,7 +2911,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
unsafety: hir::Unsafety,
abi: abi::Abi,
decl: &hir::FnDecl<'_>,
generic_params: &[hir::GenericParam<'_>],
generics: &hir::Generics<'_>,
ident_span: Option<Span>,
) -> ty::PolyFnSig<'tcx> {
debug!("ty_of_fn");
Expand All @@ -2929,6 +2923,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
for ty in decl.inputs {
visitor.visit_ty(ty);
}
walk_generics(&mut visitor, generics);

let input_tys = decl.inputs.iter().map(|a| self.ty_of_arg(a, None));
let output_ty = match decl.output {
hir::FnRetTy::Return(ref output) => {
Expand All @@ -2950,7 +2946,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
crate::collect::placeholder_type_error(
tcx,
ident_span.map(|sp| sp.shrink_to_hi()).unwrap_or(DUMMY_SP),
generic_params,
&generics.params[..],
visitor.0,
ident_span.is_some(),
);
Expand All @@ -2976,8 +2972,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
tcx.sess,
decl.output.span(),
E0581,
"return type references {} \
which is not constrained by the fn input types",
"return type references {} which is not constrained by the fn input types",
lifetime_name
);
if let ty::BrAnon(_) = *br {
Expand All @@ -2988,8 +2983,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// though we can easily give a hint that ought to be
// relevant.
err.note(
"lifetimes appearing in an associated type \
are not considered constrained",
"lifetimes appearing in an associated type are not considered constrained",
);
}
err.emit();
Expand Down
9 changes: 8 additions & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,14 @@ fn typeck_tables_of_with_fallback<'tcx>(
let fcx = if let (Some(header), Some(decl)) = (fn_header, fn_decl) {
let fn_sig = if crate::collect::get_infer_ret_ty(&decl.output).is_some() {
let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id);
AstConv::ty_of_fn(&fcx, header.unsafety, header.abi, decl, &[], None)
AstConv::ty_of_fn(
&fcx,
header.unsafety,
header.abi,
decl,
&hir::Generics::empty(),
None,
)
} else {
tcx.fn_sig(def_id)
};
Expand Down
22 changes: 12 additions & 10 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
sig.header.unsafety,
sig.header.abi,
&sig.decl,
&generics.params[..],
&generics,
Some(ident.span),
),
}
Expand All @@ -1478,14 +1478,9 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
ident,
generics,
..
}) => AstConv::ty_of_fn(
&icx,
header.unsafety,
header.abi,
decl,
&generics.params[..],
Some(ident.span),
),
}) => {
AstConv::ty_of_fn(&icx, header.unsafety, header.abi, decl, &generics, Some(ident.span))
}

ForeignItem(&hir::ForeignItem { kind: ForeignItemKind::Fn(ref fn_decl, _, _), .. }) => {
let abi = tcx.hir().get_foreign_abi(hir_id);
Expand Down Expand Up @@ -2110,7 +2105,14 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
} else {
hir::Unsafety::Unsafe
};
let fty = AstConv::ty_of_fn(&ItemCtxt::new(tcx, def_id), unsafety, abi, decl, &[], None);
let fty = AstConv::ty_of_fn(
&ItemCtxt::new(tcx, def_id),
unsafety,
abi,
decl,
&hir::Generics::empty(),
None,
);

// Feature gate SIMD types in FFI, since I am not sure that the
// ABIs are handled at all correctly. -huonw
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sync/once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ impl Once {
/// assert!(handle.join().is_err());
/// assert_eq!(INIT.is_completed(), false);
/// ```
#[stable(feature = "once_is_completed", since = "1.44.0")]
#[stable(feature = "once_is_completed", since = "1.43.0")]
#[inline]
pub fn is_completed(&self) -> bool {
// An `Acquire` load is enough because that makes all the initialization
Expand Down
32 changes: 32 additions & 0 deletions src/test/ui/did_you_mean/bad-assoc-ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,36 @@ trait K<A, B> {}
fn foo<X: K<_, _>>(x: X) {}
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures

fn bar<F>(_: F) where F: Fn() -> _ {}
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures

fn baz<F: Fn() -> _>(_: F) {}
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures

struct L<F>(F) where F: Fn() -> _;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
struct M<F> where F: Fn() -> _ {
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
a: F,
}
enum N<F> where F: Fn() -> _ {
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
Foo(F),
}

union O<F> where F: Fn() -> _ {
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR unions with non-`Copy` fields are unstable
foo: F,
}

trait P<F> where F: Fn() -> _ {
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
}

trait Q {
fn foo<F>(_: F) where F: Fn() -> _ {}
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
}

fn main() {}
Loading

0 comments on commit 4331852

Please sign in to comment.