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 12 pull requests #65299

Closed
wants to merge 68 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
897d278
libstd: Fix typos in doc
rick68 Sep 10, 2019
00d9db1
Added doc about behavior of extend on HashMap
Kixunil Oct 3, 2019
70c14dd
Move const generic regression tests to their old folder
varkor Oct 7, 2019
5e65e2b
Add a regression test for issue 62187
varkor Oct 7, 2019
2328a7e
Move stray issue tests into src/test/ui/issues
varkor Oct 7, 2019
4eba21e
Add regression test for #64792
varkor Oct 7, 2019
85b7aa2
Add a regression test for #57399
varkor Oct 7, 2019
c990744
Add a regression test for #57271
varkor Oct 7, 2019
5808971
Add ?Sized bound to a supertrait listing in E0038 error documentation
KamilaBorowska Oct 8, 2019
2afd277
Fix calling function pointer const parameters. Also fixes inference of
skinnyBat Oct 1, 2019
a59eb6d
Pretty print function pointer const values.
skinnyBat Oct 2, 2019
cf3b561
Gate use of raw and function pointers in const generics behind
skinnyBat Oct 4, 2019
43badf9
Substitute and normalize all types of consts within collect const
skinnyBat Oct 4, 2019
9677cbe
Refactor pretty print const to use a big match statement
skinnyBat Oct 4, 2019
50ea5f4
Fix reify_fn_ptr test as we now pretty print const function pointers.
skinnyBat Oct 5, 2019
16b7f44
Update feature gate error message
skinnyBat Oct 7, 2019
5986fe2
Update ui tests
skinnyBat Oct 8, 2019
7dc4bf4
Change incorrect trait name in E0038 error documentation
KamilaBorowska Oct 8, 2019
3f9d834
Add failing example for Self in supertrait listing in E0038 documenta…
KamilaBorowska Oct 9, 2019
9dbd7be
Cache the DepNodeIndex of upstream crates in order to avoid multiple …
michaelwoerister Oct 9, 2019
003d5a6
self-profiling: Add events for tracking crate metadata loading relate…
michaelwoerister Oct 9, 2019
0ee6a96
Remove some outdated comments about dependency tracking from cstore_i…
michaelwoerister Oct 9, 2019
89cc046
Pretty print raw pointers in consts as '{pointer}'.
skinnyBat Oct 9, 2019
4bb1592
Suggest `if let` on `let` refutable binding
estebank Oct 9, 2019
af3f8de
Delegate is_{freeze,copy,sized}_raw to is_item_raw
mbStavola Oct 10, 2019
ee08114
Qualify LangItem
mbStavola Oct 10, 2019
a9853fc
Add 'unlikely' annotation to branch in crate DepNodeIndex caching.
michaelwoerister Oct 10, 2019
a185061
Sort long error code explanation by error code
GuillaumeGomez Oct 10, 2019
019fba8
Uncomment E0386 to let users have access to its old definition
GuillaumeGomez Oct 10, 2019
8569dd1
Preserve output of raw pointers in mir dump.
skinnyBat Oct 10, 2019
19bc0a8
Mark Path::join as must_use
matklad Oct 10, 2019
847ad6a
Add long error explanation for E0568
GuillaumeGomez Oct 8, 2019
3c62bdc
Update ui tests
GuillaumeGomez Oct 8, 2019
fb392c5
Don't cc rust-lang/compiler for toolstate changes
varkor Oct 10, 2019
9f69420
query generator kind for error reporting
csmoe Oct 10, 2019
e8af4c1
resolve: Mark macros starting with an underscore as used
petrochenkov Oct 9, 2019
1270140
expand: Simplify expansion of derives
petrochenkov Oct 9, 2019
ceb4c3f
stability: Do not use `buffer_lint` after lowering to HIR
petrochenkov Oct 10, 2019
06a02b5
Unification and cleanup of librustc_mir error codes
GuillaumeGomez Oct 10, 2019
c97d715
Fix issue 65284
varkor Oct 10, 2019
4fde07d
Rollup merge of #64337 - rick68:patch-17, r=Dylan-DPC
tmandry Oct 11, 2019
54769b0
Rollup merge of #64986 - skinny121:fn-ptr-const-generics, r=varkor
tmandry Oct 11, 2019
a12b9c0
Rollup merge of #65048 - Kixunil:patch-1, r=KodrAus
tmandry Oct 11, 2019
ece23fc
Rollup merge of #65191 - varkor:const-generics-test-cases, r=nikomats…
tmandry Oct 11, 2019
c4a9302
Rollup merge of #65200 - xfix:patch-20, r=GuillaumeGomez
tmandry Oct 11, 2019
b37301a
Rollup merge of #65205 - GuillaumeGomez:long-err-explanation-E0568, r…
tmandry Oct 11, 2019
5d55d46
Rollup merge of #65240 - michaelwoerister:sp-review-3, r=Mark-Simulacrum
tmandry Oct 11, 2019
f0dbdd6
Rollup merge of #65248 - estebank:mention-if-let, r=cramertj
tmandry Oct 11, 2019
4180187
Rollup merge of #65252 - petrochenkov:deriveholders2, r=matthewjasper
tmandry Oct 11, 2019
4e7633d
Rollup merge of #65263 - mbStavola:dedup-raw-item-fns, r=Centril
tmandry Oct 11, 2019
1d70283
Rollup merge of #65265 - GuillaumeGomez:cleanup-librustc_mir-err-code…
tmandry Oct 11, 2019
8be5481
Rollup merge of #65266 - rust-lang:must-use-join, r=dtolnay
tmandry Oct 11, 2019
f1d2d95
Rollup merge of #65276 - varkor:toolstate-no-ping, r=Mark-Simulacrum
tmandry Oct 11, 2019
2252ea1
Rollup merge of #65277 - csmoe:fix-move, r=estebank
tmandry Oct 11, 2019
1cecbff
Rollup merge of #65283 - petrochenkov:softstab2, r=estebank
tmandry Oct 11, 2019
9f143a7
Rollup merge of #65289 - varkor:issue-65284, r=estebank
tmandry Oct 11, 2019
1f8aa05
Rollup merge of #64337 - rick68:patch-17, r=Dylan-DPC
tmandry Oct 11, 2019
5670c7f
Rollup merge of #64986 - skinny121:fn-ptr-const-generics, r=varkor
tmandry Oct 11, 2019
b851efb
Rollup merge of #65048 - Kixunil:patch-1, r=KodrAus
tmandry Oct 11, 2019
c2e7af5
Rollup merge of #65191 - varkor:const-generics-test-cases, r=nikomats…
tmandry Oct 11, 2019
873f251
Rollup merge of #65200 - xfix:patch-20, r=GuillaumeGomez
tmandry Oct 11, 2019
b5c4a82
Rollup merge of #65205 - GuillaumeGomez:long-err-explanation-E0568, r…
tmandry Oct 11, 2019
f55e9b9
Rollup merge of #65263 - mbStavola:dedup-raw-item-fns, r=Centril
tmandry Oct 11, 2019
d26439d
Rollup merge of #65266 - rust-lang:must-use-join, r=dtolnay
tmandry Oct 11, 2019
7ed57bb
Rollup merge of #65276 - varkor:toolstate-no-ping, r=Mark-Simulacrum
tmandry Oct 11, 2019
d2501c2
Rollup merge of #65277 - csmoe:fix-move, r=estebank
tmandry Oct 11, 2019
1346802
Rollup merge of #65283 - petrochenkov:softstab2, r=estebank
tmandry Oct 11, 2019
c7c6cbf
Rollup merge of #65297 - tmandry:rollup-pe7a2i2, r=tmandry
tmandry Oct 11, 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
2 changes: 1 addition & 1 deletion src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ rustc_index::newtype_index! {
}

impl DepNodeIndex {
const INVALID: DepNodeIndex = DepNodeIndex::MAX;
pub const INVALID: DepNodeIndex = DepNodeIndex::MAX;
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
Expand Down
14 changes: 9 additions & 5 deletions src/librustc/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ trait Foo {
This is similar to the second sub-error, but subtler. It happens in situations
like the following:

```compile_fail
trait Super<A> {}
```compile_fail,E0038
trait Super<A: ?Sized> {}

trait Trait: Super<Self> {
}
Expand All @@ -270,17 +270,21 @@ struct Foo;
impl Super<Foo> for Foo{}

impl Trait for Foo {}

fn main() {
let x: Box<dyn Trait>;
}
```

Here, the supertrait might have methods as follows:

```
trait Super<A> {
fn get_a(&self) -> A; // note that this is object safe!
trait Super<A: ?Sized> {
fn get_a(&self) -> &A; // note that this is object safe!
}
```

If the trait `Foo` was deriving from something like `Super<String>` or
If the trait `Trait` was deriving from something like `Super<String>` or
`Super<T>` (where `Foo` itself is `Foo<T>`), this is okay, because given a type
`get_a()` will definitely return an object of that type.

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<'a> DefCollector<'a> {
}
}

pub fn visit_macro_invoc(&mut self, id: NodeId) {
fn visit_macro_invoc(&mut self, id: NodeId) {
self.definitions.set_invocation_parent(id.placeholder_to_expn_id(), self.parent_def);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,10 @@ impl Body {
hir_id: self.value.hir_id,
}
}

pub fn generator_kind(&self) -> Option<GeneratorKind> {
self.generator_kind
}
}

/// The type of source expression that caused this generator to be created.
Expand Down
14 changes: 11 additions & 3 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,13 @@ pub fn provide(providers: &mut Providers<'_>) {
}

pub fn report_unstable(
sess: &Session, feature: Symbol, reason: Option<Symbol>, issue: u32, is_soft: bool, span: Span
sess: &Session,
feature: Symbol,
reason: Option<Symbol>,
issue: u32,
is_soft: bool,
span: Span,
soft_handler: impl FnOnce(&'static lint::Lint, Span, &str),
) {
let msg = match reason {
Some(r) => format!("use of unstable library feature '{}': {}", feature, r),
Expand All @@ -511,7 +517,7 @@ pub fn report_unstable(
let fresh = sess.one_time_diagnostics.borrow_mut().insert(error_id);
if fresh {
if is_soft {
sess.buffer_lint(lint::builtin::SOFT_UNSTABLE, CRATE_NODE_ID, span, &msg);
soft_handler(lint::builtin::SOFT_UNSTABLE, span, &msg)
} else {
emit_feature_err(
&sess.parse_sess, feature, span, GateIssue::Library(Some(issue)), &msg
Expand Down Expand Up @@ -779,10 +785,12 @@ impl<'tcx> TyCtxt<'tcx> {
/// Additionally, this function will also check if the item is deprecated. If so, and `id` is
/// not `None`, a deprecated lint attached to `id` will be emitted.
pub fn check_stability(self, def_id: DefId, id: Option<HirId>, span: Span) {
let soft_handler =
|lint, span, msg: &_| self.lint_hir(lint, id.unwrap_or(hir::CRATE_HIR_ID), span, msg);
match self.eval_stability(def_id, id, span) {
EvalResult::Allow => {}
EvalResult::Deny { feature, reason, issue, is_soft } =>
report_unstable(self.sess, feature, reason, issue, is_soft, span),
report_unstable(self.sess, feature, reason, issue, is_soft, span, soft_handler),
EvalResult::Unmarked => {
// The API could be uncallable for other reasons, for example when a private module
// was referenced.
Expand Down
8 changes: 8 additions & 0 deletions src/librustc/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,14 @@ impl<'tcx> AllocMap<'tcx> {
}
}

/// Panics if the `AllocId` does not refer to a function
pub fn unwrap_fn(&self, id: AllocId) -> Instance<'tcx> {
match self.get(id) {
Some(GlobalAlloc::Function(instance)) => instance,
_ => bug!("expected allocation ID {} to point to a function", id),
}
}

/// Freezes an `AllocId` created with `reserve` by pointing it at an `Allocation`. Trying to
/// call this function twice, even with the same `Allocation` will ICE the compiler.
pub fn set_alloc_id_memory(&mut self, id: AllocId, mem: &'tcx Allocation) {
Expand Down
9 changes: 8 additions & 1 deletion src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2602,7 +2602,14 @@ impl<'tcx> Debug for Constant<'tcx> {
impl<'tcx> Display for Constant<'tcx> {
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
write!(fmt, "const ")?;
write!(fmt, "{}", self.literal)
// FIXME make the default pretty printing of raw pointers more detailed. Here we output the
// debug representation of raw pointers, so that the raw pointers in the mir dump output are
// detailed and just not '{pointer}'.
if let ty::RawPtr(_) = self.literal.ty.kind {
write!(fmt, "{:?} : {}", self.literal.val, self.literal.ty)
} else {
write!(fmt, "{}", self.literal)
}
}
}

Expand Down
218 changes: 107 additions & 111 deletions src/librustc/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,125 +863,121 @@ pub trait PrettyPrinter<'tcx>:
}

let u8 = self.tcx().types.u8;
if let ty::FnDef(did, substs) = ct.ty.kind {
p!(print_value_path(did, substs));
return Ok(self);
}
if let ConstValue::Unevaluated(did, substs) = ct.val {
match self.tcx().def_kind(did) {
| Some(DefKind::Static)
| Some(DefKind::Const)
| Some(DefKind::AssocConst) => p!(print_value_path(did, substs)),
_ => if did.is_local() {
let span = self.tcx().def_span(did);
if let Ok(snip) = self.tcx().sess.source_map().span_to_snippet(span) {
p!(write("{}", snip))

match (ct.val, &ct.ty.kind) {
(_, ty::FnDef(did, substs)) => p!(print_value_path(*did, substs)),
(ConstValue::Unevaluated(did, substs), _) => {
match self.tcx().def_kind(did) {
| Some(DefKind::Static)
| Some(DefKind::Const)
| Some(DefKind::AssocConst) => p!(print_value_path(did, substs)),
_ => if did.is_local() {
let span = self.tcx().def_span(did);
if let Ok(snip) = self.tcx().sess.source_map().span_to_snippet(span) {
p!(write("{}", snip))
} else {
p!(write("_: "), print(ct.ty))
}
} else {
p!(write("_: "), print(ct.ty))
}
},
}
},
(ConstValue::Infer(..), _) => p!(write("_: "), print(ct.ty)),
(ConstValue::Param(ParamConst { name, .. }), _) => p!(write("{}", name)),
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Bool) =>
p!(write("{}", if data == 0 { "false" } else { "true" })),
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Float(ast::FloatTy::F32)) =>
p!(write("{}f32", Single::from_bits(data))),
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Float(ast::FloatTy::F64)) =>
p!(write("{}f64", Double::from_bits(data))),
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Uint(ui)) => {
let bit_size = Integer::from_attr(&self.tcx(), UnsignedInt(*ui)).size();
let max = truncate(u128::max_value(), bit_size);

if data == max {
p!(write("std::{}::MAX", ui))
} else {
p!(write("_: "), print(ct.ty))
},
}
return Ok(self);
}
if let ConstValue::Infer(..) = ct.val {
p!(write("_: "), print(ct.ty));
return Ok(self);
}
if let ConstValue::Param(ParamConst { name, .. }) = ct.val {
p!(write("{}", name));
return Ok(self);
}
if let ConstValue::Scalar(Scalar::Raw { data, .. }) = ct.val {
match ct.ty.kind {
ty::Bool => {
p!(write("{}", if data == 0 { "false" } else { "true" }));
return Ok(self);
},
ty::Float(ast::FloatTy::F32) => {
p!(write("{}f32", Single::from_bits(data)));
return Ok(self);
},
ty::Float(ast::FloatTy::F64) => {
p!(write("{}f64", Double::from_bits(data)));
return Ok(self);
},
ty::Uint(ui) => {
let bit_size = Integer::from_attr(&self.tcx(), UnsignedInt(ui)).size();
let max = truncate(u128::max_value(), bit_size);
p!(write("{}{}", data, ui))
};
},
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Int(i)) => {
let bit_size = Integer::from_attr(&self.tcx(), SignedInt(*i))
.size().bits() as u128;
let min = 1u128 << (bit_size - 1);
let max = min - 1;

let ty = self.tcx().lift(&ct.ty).unwrap();
let size = self.tcx().layout_of(ty::ParamEnv::empty().and(ty))
.unwrap()
.size;
match data {
d if d == min => p!(write("std::{}::MIN", i)),
d if d == max => p!(write("std::{}::MAX", i)),
_ => p!(write("{}{}", sign_extend(data, size) as i128, i))
}
},
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Char) =>
p!(write("{:?}", ::std::char::from_u32(data as u32).unwrap())),
(ConstValue::Scalar(_), ty::RawPtr(_)) => p!(write("{{pointer}}")),
(ConstValue::Scalar(Scalar::Ptr(ptr)), ty::FnPtr(_)) => {
let instance = {
let alloc_map = self.tcx().alloc_map.lock();
alloc_map.unwrap_fn(ptr.alloc_id)
};
p!(print_value_path(instance.def_id(), instance.substs));
},
_ => {
let printed = if let ty::Ref(_, ref_ty, _) = ct.ty.kind {
let byte_str = match (ct.val, &ref_ty.kind) {
(ConstValue::Scalar(Scalar::Ptr(ptr)), ty::Array(t, n)) if *t == u8 => {
let n = n.eval_usize(self.tcx(), ty::ParamEnv::empty());
Some(self.tcx()
.alloc_map.lock()
.unwrap_memory(ptr.alloc_id)
.get_bytes(&self.tcx(), ptr, Size::from_bytes(n)).unwrap())
},
(ConstValue::Slice { data, start, end }, ty::Slice(t)) if *t == u8 => {
// The `inspect` here is okay since we checked the bounds, and there are
// no relocations (we have an active slice reference here). We don't use
// this result to affect interpreter execution.
Some(data.inspect_with_undef_and_ptr_outside_interpreter(start..end))
},
_ => None,
};

if data == max {
p!(write("std::{}::MAX", ui))
if let Some(byte_str) = byte_str {
p!(write("b\""));
for &c in byte_str {
for e in std::ascii::escape_default(c) {
self.write_char(e as char)?;
}
}
p!(write("\""));
true
} else if let (ConstValue::Slice { data, start, end }, ty::Str) =
(ct.val, &ref_ty.kind)
{
// The `inspect` here is okay since we checked the bounds, and there are no
// relocations (we have an active `str` reference here). We don't use this
// result to affect interpreter execution.
let slice = data.inspect_with_undef_and_ptr_outside_interpreter(start..end);
let s = ::std::str::from_utf8(slice)
.expect("non utf8 str from miri");
p!(write("{:?}", s));
true
} else {
p!(write("{}{}", data, ui))
};
return Ok(self);
},
ty::Int(i) =>{
let bit_size = Integer::from_attr(&self.tcx(), SignedInt(i))
.size().bits() as u128;
let min = 1u128 << (bit_size - 1);
let max = min - 1;

let ty = self.tcx().lift(&ct.ty).unwrap();
let size = self.tcx().layout_of(ty::ParamEnv::empty().and(ty))
.unwrap()
.size;
match data {
d if d == min => p!(write("std::{}::MIN", i)),
d if d == max => p!(write("std::{}::MAX", i)),
_ => p!(write("{}{}", sign_extend(data, size) as i128, i))
}
return Ok(self);
},
ty::Char => {
p!(write("{:?}", ::std::char::from_u32(data as u32).unwrap()));
return Ok(self);
}
_ => {},
}
}
if let ty::Ref(_, ref_ty, _) = ct.ty.kind {
let byte_str = match (ct.val, &ref_ty.kind) {
(ConstValue::Scalar(Scalar::Ptr(ptr)), ty::Array(t, n)) if *t == u8 => {
let n = n.eval_usize(self.tcx(), ty::ParamEnv::empty());
Some(self.tcx()
.alloc_map.lock()
.unwrap_memory(ptr.alloc_id)
.get_bytes(&self.tcx(), ptr, Size::from_bytes(n)).unwrap())
},
(ConstValue::Slice { data, start, end }, ty::Slice(t)) if *t == u8 => {
// The `inspect` here is okay since we checked the bounds, and there are no
// relocations (we have an active slice reference here). We don't use this
// result to affect interpreter execution.
Some(data.inspect_with_undef_and_ptr_outside_interpreter(start..end))
},
(ConstValue::Slice { data, start, end }, ty::Str) => {
// The `inspect` here is okay since we checked the bounds, and there are no
// relocations (we have an active `str` reference here). We don't use this
// result to affect interpreter execution.
let slice = data.inspect_with_undef_and_ptr_outside_interpreter(start..end);
let s = ::std::str::from_utf8(slice)
.expect("non utf8 str from miri");
p!(write("{:?}", s));
return Ok(self);
},
_ => None,
};
if let Some(byte_str) = byte_str {
p!(write("b\""));
for &c in byte_str {
for e in std::ascii::escape_default(c) {
self.write_char(e as char)?;
false
}
} else {
false
};
if !printed {
// fallback
p!(write("{:?} : ", ct.val), print(ct.ty))
}
p!(write("\""));
return Ok(self);
}
}
p!(write("{:?} : ", ct.val), print(ct.ty));

};
Ok(self)
}
}
Expand Down
Loading