Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
5397dfc
Remove obsolete “should not have to exist” reasons
SimonSapin Jul 8, 2019
01d93bf
Split the SliceConcat trait into Concat and Join
SimonSapin Jul 8, 2019
283f676
Take separator by value in `[T]::join`
SimonSapin Jul 8, 2019
b62a77b
Add joining slices of slices with a slice separator, not just a singl…
SimonSapin Jul 8, 2019
50840ee
Delay bug; this sidesteps ICE'ing when compiler is just doing error-r…
pnkfelix Jul 9, 2019
837fe7b
Regression test.
pnkfelix Jul 9, 2019
d0635ee
Update src/liballoc/slice.rs
SimonSapin Jul 9, 2019
bbc9366
Update src/liballoc/slice.rs
SimonSapin Jul 9, 2019
5f7768a
Update src/liballoc/str.rs
SimonSapin Jul 9, 2019
d73c23d
explain how to search without owned data
RalfJung Jul 13, 2019
3f77f2c
better comments
RalfJung Jul 14, 2019
469b7a9
rustc_typeck: improve diagnostics for _ const/static declarations
lundibundi Jul 18, 2019
c6735a6
fixup! rustc_typeck: improve diagnostics for _ const/static declarations
lundibundi Jul 19, 2019
10d4159
Revert "Disable stack probing for gnux32."
crlf0710 Jul 19, 2019
b361864
fixup! rustc_typeck: improve diagnostics for _ const/static declarations
lundibundi Jul 19, 2019
c1b4d62
rustc: Compile the `fmt_macros` crate as an rlib
alexcrichton Jul 19, 2019
c6e027d
fixup! rustc_typeck: improve diagnostics for _ const/static declarations
lundibundi Jul 19, 2019
0e73386
Use sharded maps for interning
Zoxc Jun 12, 2019
2641bed
Tweak span for variant not found error
estebank Jul 20, 2019
97e8d67
Break dependencies between `syntax_ext` and some other crates
petrochenkov Jul 17, 2019
995429d
Move proc macro server into libsyntax
petrochenkov Jul 18, 2019
1196dfe
Move test harness generation into libsyntax_ext
petrochenkov Jul 18, 2019
b93d2ac
Merge `rustc_allocator` into `libsyntax_ext`
petrochenkov Jul 16, 2019
188330b
Move standard library injection into libsyntax_ext
petrochenkov Jul 18, 2019
ec5f089
syntax_ext: `proc_macro_decls` -> `proc_macro_harness`
petrochenkov Jul 18, 2019
21b502b
warn that raw pointers must be aligned when used, and that writes cau…
RalfJung Jul 20, 2019
2e6b13a
references must be aligned; also move up the warning that fn ptrs mus…
RalfJung Jul 20, 2019
18dceab
Add tests for issue-58887
JohnTitor Jul 21, 2019
f502bf7
sync with nomicon: raw ptr must be non-dangling and aligned every tim…
RalfJung Jul 21, 2019
4081222
apply feedback
RalfJung Jul 21, 2019
e75ae15
Move into existential-type dir
JohnTitor Jul 21, 2019
795d96d
Place::as_place_ref is now Place::as_ref
spastorino Jul 21, 2019
a7b9246
weasle, weasle
RalfJung Jul 22, 2019
9196781
account for non-drop-glue types
RalfJung Jul 22, 2019
c3aa3d8
Rollup merge of #61779 - Zoxc:sharded, r=oli-obk
Centril Jul 22, 2019
723fd5d
Rollup merge of #62523 - pnkfelix:delay-bug-to-resolve-issue-62203-ic…
Centril Jul 22, 2019
9785008
Rollup merge of #62528 - SimonSapin:concat, r=alexcrichton
Centril Jul 22, 2019
966ba8d
Rollup merge of #62656 - RalfJung:contains-no-own, r=Dylan-DPC
Centril Jul 22, 2019
8fad976
Rollup merge of #62771 - petrochenkov:depext, r=eddyb
Centril Jul 22, 2019
823d575
Rollup merge of #62804 - lundibundi:help-infer-const-static, r=eddyb
Centril Jul 22, 2019
8311f71
Rollup merge of #62808 - crlf0710:gnux32_stack_probe, r=nikic
Centril Jul 22, 2019
b704be5
Rollup merge of #62813 - alexcrichton:less-dylib, r=Mark-Simulacrum
Centril Jul 22, 2019
cb1b6c9
Rollup merge of #62817 - estebank:variant-sp, r=matthewjasper
Centril Jul 22, 2019
1d5ea88
Rollup merge of #62822 - RalfJung:pointers, r=Centril
Centril Jul 22, 2019
f7621c5
Rollup merge of #62842 - JohnTitor:test-for-58887, r=alexreg
Centril Jul 22, 2019
80aa34d
Rollup merge of #62859 - spastorino:rename-to-as-ref, r=Centril
Centril Jul 22, 2019
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
Prev Previous commit
Next Next commit
rustc_typeck: improve diagnostics for _ const/static declarations
  • Loading branch information
lundibundi committed Jul 19, 2019
commit 469b7a916164d48a78d4bd8a10257bfe3b4a1dbe
31 changes: 17 additions & 14 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,40 +759,40 @@ fn adt_destructor(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::Destructor> {
fn primary_body_of(
tcx: TyCtxt<'_>,
id: hir::HirId,
) -> Option<(hir::BodyId, Option<&hir::FnHeader>, Option<&hir::FnDecl>)> {
) -> Option<(hir::BodyId, Option<&hir::Ty>, Option<&hir::FnHeader>, Option<&hir::FnDecl>)> {
match tcx.hir().get(id) {
Node::Item(item) => {
match item.node {
hir::ItemKind::Const(_, body) |
hir::ItemKind::Static(_, _, body) =>
Some((body, None, None)),
hir::ItemKind::Const(ref ty, body) |
hir::ItemKind::Static(ref ty, _, body) =>
Some((body, Some(ty), None, None)),
hir::ItemKind::Fn(ref decl, ref header, .., body) =>
Some((body, Some(header), Some(decl))),
Some((body, None, Some(header), Some(decl))),
_ =>
None,
}
}
Node::TraitItem(item) => {
match item.node {
hir::TraitItemKind::Const(_, Some(body)) =>
Some((body, None, None)),
hir::TraitItemKind::Const(ref ty, Some(body)) =>
Some((body, Some(ty), None, None)),
hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) =>
Some((body, Some(&sig.header), Some(&sig.decl))),
Some((body, None, Some(&sig.header), Some(&sig.decl))),
_ =>
None,
}
}
Node::ImplItem(item) => {
match item.node {
hir::ImplItemKind::Const(_, body) =>
Some((body, None, None)),
hir::ImplItemKind::Const(ref ty, body) =>
Some((body, Some(ty), None, None)),
hir::ImplItemKind::Method(ref sig, body) =>
Some((body, Some(&sig.header), Some(&sig.decl))),
Some((body, None, Some(&sig.header), Some(&sig.decl))),
_ =>
None,
}
}
Node::AnonConst(constant) => Some((constant.body, None, None)),
Node::AnonConst(constant) => Some((constant.body, None, None, None)),
_ => None,
}
}
Expand Down Expand Up @@ -825,7 +825,7 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> {
let span = tcx.hir().span(id);

// Figure out what primary body this item has.
let (body_id, fn_header, fn_decl) = primary_body_of(tcx, id)
let (body_id, body_ty, fn_header, fn_decl) = primary_body_of(tcx, id)
.unwrap_or_else(|| {
span_bug!(span, "can't type-check body of {:?}", def_id);
});
Expand Down Expand Up @@ -856,7 +856,10 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> {
fcx
} else {
let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id);
let expected_type = tcx.type_of(def_id);
let expected_type = body_ty.and_then(|ty| match ty.node {
hir::TyKind::Infer => Some(AstConv::ast_ty_to_ty(&fcx, ty)),
_ => None
}).unwrap_or_else(|| tcx.type_of(def_id));
let expected_type = fcx.normalize_associated_types_in(body.value.span, &expected_type);
fcx.require_type_is_sized(expected_type, body.value.span, traits::ConstSized);

Expand Down
53 changes: 47 additions & 6 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,26 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
checked_type_of(tcx, def_id, true).unwrap()
}

fn infer_placeholder_type(
tcx: TyCtxt<'_>,
def_id: DefId,
body_id: hir::BodyId,
span: Span,
) -> Ty<'_> {
let ty = tcx.typeck_tables_of(def_id).node_type(body_id.hir_id);
let mut diag = bad_placeholder_type(tcx, span);
if ty != tcx.types.err {
diag.span_suggestion(
span,
"replace `_` with the correct type",
ty.to_string(),
Applicability::MaybeIncorrect,
);
}
diag.emit();
ty
}

/// Same as [`type_of`] but returns [`Option`] instead of failing.
///
/// If you want to fail anyway, you can set the `fail` parameter to true, but in this case,
Expand All @@ -1160,7 +1180,16 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
let substs = InternalSubsts::identity_for_item(tcx, def_id);
tcx.mk_fn_def(def_id, substs)
}
TraitItemKind::Const(ref ty, _) | TraitItemKind::Type(_, Some(ref ty)) => icx.to_ty(ty),
TraitItemKind::Const(ref ty, body_id) => {
body_id.and_then(|body_id| {
if let hir::TyKind::Infer = ty.node {
Some(infer_placeholder_type(tcx, def_id, body_id, ty.span))
} else {
None
}
}).unwrap_or_else(|| icx.to_ty(ty))
},
TraitItemKind::Type(_, Some(ref ty)) => icx.to_ty(ty),
TraitItemKind::Type(_, None) => {
if !fail {
return None;
Expand All @@ -1174,7 +1203,13 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
let substs = InternalSubsts::identity_for_item(tcx, def_id);
tcx.mk_fn_def(def_id, substs)
}
ImplItemKind::Const(ref ty, _) => icx.to_ty(ty),
ImplItemKind::Const(ref ty, body_id) => {
if let hir::TyKind::Infer = ty.node {
infer_placeholder_type(tcx, def_id, body_id, ty.span)
} else {
icx.to_ty(ty)
}
},
ImplItemKind::Existential(_) => {
if tcx
.impl_trait_ref(tcx.hir().get_parent_did(hir_id))
Expand All @@ -1199,10 +1234,16 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<

Node::Item(item) => {
match item.node {
ItemKind::Static(ref t, ..)
| ItemKind::Const(ref t, _)
| ItemKind::Ty(ref t, _)
| ItemKind::Impl(.., ref t, _) => icx.to_ty(t),
ItemKind::Static(ref ty, .., body_id)
| ItemKind::Const(ref ty, body_id) => {
if let hir::TyKind::Infer = ty.node {
infer_placeholder_type(tcx, def_id, body_id, ty.span)
} else {
icx.to_ty(ty)
}
},
ItemKind::Ty(ref ty, _)
| ItemKind::Impl(.., ref ty, _) => icx.to_ty(ty),
ItemKind::Fn(..) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id);
tcx.mk_fn_def(def_id, substs)
Expand Down
20 changes: 16 additions & 4 deletions src/test/ui/typeck/typeck_type_placeholder_item.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ error[E0121]: the type placeholder `_` is not allowed within types on item signa
--> $DIR/typeck_type_placeholder_item.rs:11:15
|
LL | static TEST3: _ = "test";
| ^ not allowed in type signatures
| ^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `&'static str`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:14:15
|
LL | static TEST4: _ = 145;
| ^ not allowed in type signatures
| ^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `i32`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:17:16
Expand Down Expand Up @@ -122,13 +128,19 @@ error[E0121]: the type placeholder `_` is not allowed within types on item signa
--> $DIR/typeck_type_placeholder_item.rs:64:22
|
LL | static FN_TEST3: _ = "test";
| ^ not allowed in type signatures
| ^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `&'static str`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:67:22
|
LL | static FN_TEST4: _ = 145;
| ^ not allowed in type signatures
| ^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `i32`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:70:23
Expand Down