Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #68078

Merged
merged 54 commits into from
Jan 10, 2020
Merged
Changes from 3 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
cc0fbdf
Automatically prefer integer addresses for zst MPlace
oli-obk Dec 21, 2019
5b770b0
Remove a ZST special casing that is not necessary anymore
oli-obk Dec 21, 2019
4a5c35b
Fix an ICE happening due code assuming that `MPlaceTy` cannot have in…
oli-obk Dec 21, 2019
cac6f4c
Move `to_const_value` from `MPlaceTy` to its only use site
oli-obk Dec 26, 2019
4fbe434
Poison any `MemPlace` created from a zst Operand (or otherwise via `M…
oli-obk Dec 26, 2019
23b0c47
Ensure we don't accidentally turn non-zsts into zsts
oli-obk Dec 26, 2019
a1990db
Remove a bunch of dead functions and make some functions private
oli-obk Dec 26, 2019
f7f5952
Add warning label to `try_as_mplace`
oli-obk Dec 27, 2019
29c372b
Add more documentation
oli-obk Jan 7, 2020
d0b24e5
Actually use the poison value
oli-obk Jan 7, 2020
9c0000c
Point at opaque and closure type definitions in type errors
estebank Nov 16, 2019
c556151
review comments
estebank Dec 15, 2019
0dcdbae
Point at the def span of trait refs E0277
estebank Dec 16, 2019
542be6f
review comment: wording
estebank Dec 16, 2019
b522ba0
review comments
estebank Jan 8, 2020
ffcdbad
review comments
estebank Jan 8, 2020
705e087
reduce code duplication
estebank Jan 8, 2020
33ae322
remove unnecessary `Debug`
estebank Jan 8, 2020
bcab59e
lowering: simplify HoFs
Centril Jan 6, 2020
956265d
lowering: elide some lifetimes
Centril Jan 6, 2020
f75ccde
extract pattern lowering -> pat.rs
Centril Jan 6, 2020
ae6e31b
move lower_binding_mode -> pat.rs
Centril Jan 6, 2020
4e6329e
extract path lowering -> path.rs
Centril Jan 6, 2020
2db97ed
refactor 'Output = $ty' & reduce rustc dep
Centril Jan 6, 2020
69b1e5c
{rustc::util -> rustc_data_structures}::captures
Centril Jan 6, 2020
402907f
lowering: rustc::session -> rustc_session
Centril Jan 6, 2020
7472f9e
lowering: remove dep on CrateStore
Centril Jan 6, 2020
b743af6
rename a method in Resolver trait
Centril Jan 8, 2020
5dafa6a
add CStore::item_generics_num_lifetimes
Centril Jan 9, 2020
e632940
Update src/librustc_mir/interpret/place.rs
oli-obk Jan 9, 2020
a4fa5bb
Rename `Unsized` to `Meta`
oli-obk Jan 9, 2020
c5c4fa8
Switch assertion order to be more helpful to ppl that encounter them
oli-obk Jan 9, 2020
915db7a
expect `fn` after `const unsafe` / `const extern`
Centril Jan 9, 2020
c751961
Extend support of `_` in type parameters
estebank Jan 9, 2020
6e04cf0
review comments: more tests
estebank Jan 9, 2020
63e2e44
Add `const_trait_impl` feature gate
ecstatic-morse Jan 2, 2020
6fc4158
Add `const_trait_bound_opt_out` feature gate
ecstatic-morse Jan 2, 2020
fd4a6a1
Add a `constness` field to `ast::TraitRef`
ecstatic-morse Jan 2, 2020
1c3fe9d
Parse `impl const Trait for Ty` syntax
ecstatic-morse Jan 2, 2020
0cf52a7
Parse `?const Trait` bound syntax
ecstatic-morse Jan 2, 2020
b390fc4
Error when new syntax is lowered
ecstatic-morse Jan 3, 2020
31edbe9
Reject `const` in inherent impls
ecstatic-morse Jan 4, 2020
d843e00
Check for `?const` in invalid contexts during AST validation
ecstatic-morse Jan 5, 2020
343e157
Add tests for RFC 2632
ecstatic-morse Jan 3, 2020
b6b11f0
Call all visit methods on trait definitions
ecstatic-morse Jan 5, 2020
9950a1f
Add test for `?const` and `?` on the same bound
ecstatic-morse Jan 5, 2020
14730ed
Make `bound_context` more like neighboring functions
ecstatic-morse Jan 6, 2020
fd1c003
Add test for `?const` in nested impl/dyn trait
ecstatic-morse Jan 6, 2020
aabb037
Rollup merge of #66463 - estebank:point-at-closure-and-opaque-types, …
Centril Jan 10, 2020
e180d36
Rollup merge of #67501 - oli-obk:test-slice-patterns, r=RalfJung
Centril Jan 10, 2020
f396387
Rollup merge of #67820 - ecstatic-morse:const-trait, r=oli-obk
Centril Jan 10, 2020
3bfa28c
Rollup merge of #67922 - Centril:lowering-cleanup, r=petrochenkov
Centril Jan 10, 2020
2307f0c
Rollup merge of #68071 - estebank:ice-67995, r=Centril
Centril Jan 10, 2020
6f3f1c5
Rollup merge of #68073 - Centril:fix-68062, r=estebank
Centril Jan 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_parse/parser/generics.rs
Original file line number Diff line number Diff line change
@@ -156,7 +156,7 @@ impl<'a> Parser<'a> {
self.expect_gt()?;
(params, span_lo.to(self.prev_span))
} else {
(vec![], self.prev_span.between(self.token.span))
(vec![], self.prev_span.shrink_to_hi())
};
Ok(ast::Generics {
params,
6 changes: 5 additions & 1 deletion src/librustc_parse/parser/item.rs
Original file line number Diff line number Diff line change
@@ -556,7 +556,11 @@ impl<'a> Parser<'a> {
let mut generics = if self.choose_generics_over_qpath() {
self.parse_generics()?
} else {
Generics::default()
let mut generics = Generics::default();
// impl A for B {}
// /\ this is where `generics.span` should point when there are no type params.
generics.span = self.prev_span.shrink_to_hi();
generics
};

let constness = if self.eat_keyword(kw::Const) {
2 changes: 1 addition & 1 deletion src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
@@ -2803,7 +2803,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// allowed. `allow_ty_infer` gates this behavior.
crate::collect::placeholder_type_error(
tcx,
ident_span.unwrap_or(DUMMY_SP),
ident_span.map(|sp| sp.shrink_to_hi()).unwrap_or(DUMMY_SP),
generic_params,
visitor.0,
ident_span.is_some(),
36 changes: 28 additions & 8 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
@@ -127,7 +127,7 @@ struct CollectItemTypesVisitor<'tcx> {
/// all already existing generic type parameters to avoid suggesting a name that is already in use.
crate fn placeholder_type_error(
tcx: TyCtxt<'tcx>,
ident_span: Span,
span: Span,
generics: &[hir::GenericParam<'_>],
placeholder_types: Vec<Span>,
suggest: bool,
@@ -153,7 +153,14 @@ crate fn placeholder_type_error(
let mut sugg: Vec<_> =
placeholder_types.iter().map(|sp| (*sp, type_name.to_string())).collect();
if generics.is_empty() {
sugg.push((ident_span.shrink_to_hi(), format!("<{}>", type_name)));
sugg.push((span, format!("<{}>", type_name)));
} else if let Some(arg) = generics.iter().find(|arg| match arg.name {
hir::ParamName::Plain(Ident { name: kw::Underscore, .. }) => true,
_ => false,
}) {
// Account for `_` already present in cases like `struct S<_>(_);` and suggest
// `struct S<T>(T);` instead of `struct S<_, T>(T);`.
sugg.push((arg.span, format!("{}", type_name)));
} else {
sugg.push((
generics.iter().last().unwrap().span.shrink_to_hi(),
@@ -175,16 +182,20 @@ fn reject_placeholder_type_signatures_in_item(tcx: TyCtxt<'tcx>, item: &'tcx hir
let (generics, suggest) = match &item.kind {
hir::ItemKind::Union(_, generics)
| hir::ItemKind::Enum(_, generics)
| hir::ItemKind::Struct(_, generics) => (&generics.params[..], true),
hir::ItemKind::TyAlias(_, generics) => (&generics.params[..], false),
| hir::ItemKind::TraitAlias(generics, _)
| hir::ItemKind::Trait(_, _, generics, ..)
| hir::ItemKind::Impl(_, _, _, generics, ..)
| hir::ItemKind::Struct(_, generics) => (generics, true),
hir::ItemKind::OpaqueTy(hir::OpaqueTy { generics, .. })
| hir::ItemKind::TyAlias(_, generics) => (generics, false),
// `static`, `fn` and `const` are handled elsewhere to suggest appropriate type.
_ => return,
};

let mut visitor = PlaceholderHirTyCollector::default();
visitor.visit_item(item);

placeholder_type_error(tcx, item.ident.span, generics, visitor.0, suggest);
placeholder_type_error(tcx, generics.span, &generics.params[..], visitor.0, suggest);
}

impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
@@ -1798,10 +1809,19 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
/// Whether `ty` is a type with `_` placeholders that can be infered. Used in diagnostics only to
/// use inference to provide suggestions for the appropriate type if possible.
fn is_suggestable_infer_ty(ty: &hir::Ty<'_>) -> bool {
use hir::TyKind::*;
match &ty.kind {
hir::TyKind::Infer => true,
hir::TyKind::Slice(ty) | hir::TyKind::Array(ty, _) => is_suggestable_infer_ty(ty),
hir::TyKind::Tup(tys) => tys.iter().any(|ty| is_suggestable_infer_ty(ty)),
Infer => true,
Slice(ty) | Array(ty, _) => is_suggestable_infer_ty(ty),
Tup(tys) => tys.iter().any(is_suggestable_infer_ty),
Ptr(mut_ty) | Rptr(_, mut_ty) => is_suggestable_infer_ty(mut_ty.ty),
Def(_, generic_args) => generic_args
.iter()
.filter_map(|arg| match arg {
hir::GenericArg::Type(ty) => Some(ty),
_ => None,
})
.any(is_suggestable_infer_ty),
_ => false,
}
}
45 changes: 45 additions & 0 deletions src/test/ui/typeck/typeck_type_placeholder_item.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(type_alias_impl_trait)] // Needed for single test `type Y = impl Trait<_>`
// This test checks that it is not possible to enable global type
// inference by using the `_` type placeholder.

@@ -42,6 +43,16 @@ impl Test9 {
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
}

fn test11(x: &usize) -> &_ {
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
&x
}

unsafe fn test12(x: *const usize) -> *const *const _ {
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
&x
}

impl Clone for Test9 {
fn clone(&self) -> _ { Test9 }
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
@@ -131,3 +142,37 @@ trait T {
fn assoc_fn_test3() -> _;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
}

struct BadStruct<_>(_);
//~^ ERROR expected identifier, found reserved identifier `_`
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
trait BadTrait<_> {}
//~^ ERROR expected identifier, found reserved identifier `_`
impl BadTrait<_> for BadStruct<_> {}
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures

fn impl_trait() -> impl BadTrait<_> {
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
unimplemented!()
}

struct BadStruct1<_, _>(_);
//~^ ERROR expected identifier, found reserved identifier `_`
//~| ERROR expected identifier, found reserved identifier `_`
//~| ERROR the name `_` is already used
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
struct BadStruct2<_, T>(_, T);
//~^ ERROR expected identifier, found reserved identifier `_`
//~| ERROR the type placeholder `_` is not allowed within types on item signatures

type X = Box<_>;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures

struct Struct;
trait Trait<T> {}
impl Trait<usize> for Struct {}
type Y = impl Trait<_>;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
fn foo() -> Y {
Struct
}
280 changes: 200 additions & 80 deletions src/test/ui/typeck/typeck_type_placeholder_item.stderr

Large diffs are not rendered by default.