Skip to content

Commit 026447b

Browse files
committed
Auto merge of #65322 - tmandry:rollup-frr651r, r=tmandry
Rollup of 15 pull requests Successful merges: - #64337 (libstd: Fix typos in doc) - #64986 (Function pointers as const generic arguments) - #65048 (Added doc about behavior of extend on HashMap) - #65191 (Add some regression tests) - #65200 (Add ?Sized bound to a supertrait listing in E0038 error documentation) - #65205 (Add long error explanation for E0568) - #65220 (Update LLVM for Emscripten exception handling support) - #65263 (Deduplicate is_{freeze,copy,sized}_raw) - #65266 (Mark Path::join as must_use) - #65276 (Don't cc rust-lang/compiler for toolstate changes) - #65277 (Query generator kind for error reporting) - #65283 (stability: Do not use `buffer_lint` after lowering to HIR) - #65289 (Fix suggested bound addition diagnostic) - #65310 (deriving: avoid dummy Span on an artificial `type_ident` path) - #65321 (Remove painful test that is not pulling its weight) Failed merges: r? @ghost
2 parents 4b42e91 + b93203f commit 026447b

File tree

71 files changed

+731
-281
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+731
-281
lines changed

src/librustc/error_codes.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ trait Foo {
259259
This is similar to the second sub-error, but subtler. It happens in situations
260260
like the following:
261261
262-
```compile_fail
263-
trait Super<A> {}
262+
```compile_fail,E0038
263+
trait Super<A: ?Sized> {}
264264
265265
trait Trait: Super<Self> {
266266
}
@@ -270,17 +270,21 @@ struct Foo;
270270
impl Super<Foo> for Foo{}
271271
272272
impl Trait for Foo {}
273+
274+
fn main() {
275+
let x: Box<dyn Trait>;
276+
}
273277
```
274278
275279
Here, the supertrait might have methods as follows:
276280
277281
```
278-
trait Super<A> {
279-
fn get_a(&self) -> A; // note that this is object safe!
282+
trait Super<A: ?Sized> {
283+
fn get_a(&self) -> &A; // note that this is object safe!
280284
}
281285
```
282286
283-
If the trait `Foo` was deriving from something like `Super<String>` or
287+
If the trait `Trait` was deriving from something like `Super<String>` or
284288
`Super<T>` (where `Foo` itself is `Foo<T>`), this is okay, because given a type
285289
`get_a()` will definitely return an object of that type.
286290

src/librustc/hir/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,10 @@ impl Body {
13661366
hir_id: self.value.hir_id,
13671367
}
13681368
}
1369+
1370+
pub fn generator_kind(&self) -> Option<GeneratorKind> {
1371+
self.generator_kind
1372+
}
13691373
}
13701374

13711375
/// The type of source expression that caused this generator to be created.

src/librustc/middle/stability.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,13 @@ pub fn provide(providers: &mut Providers<'_>) {
485485
}
486486

487487
pub fn report_unstable(
488-
sess: &Session, feature: Symbol, reason: Option<Symbol>, issue: u32, is_soft: bool, span: Span
488+
sess: &Session,
489+
feature: Symbol,
490+
reason: Option<Symbol>,
491+
issue: u32,
492+
is_soft: bool,
493+
span: Span,
494+
soft_handler: impl FnOnce(&'static lint::Lint, Span, &str),
489495
) {
490496
let msg = match reason {
491497
Some(r) => format!("use of unstable library feature '{}': {}", feature, r),
@@ -511,7 +517,7 @@ pub fn report_unstable(
511517
let fresh = sess.one_time_diagnostics.borrow_mut().insert(error_id);
512518
if fresh {
513519
if is_soft {
514-
sess.buffer_lint(lint::builtin::SOFT_UNSTABLE, CRATE_NODE_ID, span, &msg);
520+
soft_handler(lint::builtin::SOFT_UNSTABLE, span, &msg)
515521
} else {
516522
emit_feature_err(
517523
&sess.parse_sess, feature, span, GateIssue::Library(Some(issue)), &msg
@@ -779,10 +785,12 @@ impl<'tcx> TyCtxt<'tcx> {
779785
/// Additionally, this function will also check if the item is deprecated. If so, and `id` is
780786
/// not `None`, a deprecated lint attached to `id` will be emitted.
781787
pub fn check_stability(self, def_id: DefId, id: Option<HirId>, span: Span) {
788+
let soft_handler =
789+
|lint, span, msg: &_| self.lint_hir(lint, id.unwrap_or(hir::CRATE_HIR_ID), span, msg);
782790
match self.eval_stability(def_id, id, span) {
783791
EvalResult::Allow => {}
784792
EvalResult::Deny { feature, reason, issue, is_soft } =>
785-
report_unstable(self.sess, feature, reason, issue, is_soft, span),
793+
report_unstable(self.sess, feature, reason, issue, is_soft, span, soft_handler),
786794
EvalResult::Unmarked => {
787795
// The API could be uncallable for other reasons, for example when a private module
788796
// was referenced.

src/librustc/mir/interpret/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,14 @@ impl<'tcx> AllocMap<'tcx> {
470470
}
471471
}
472472

473+
/// Panics if the `AllocId` does not refer to a function
474+
pub fn unwrap_fn(&self, id: AllocId) -> Instance<'tcx> {
475+
match self.get(id) {
476+
Some(GlobalAlloc::Function(instance)) => instance,
477+
_ => bug!("expected allocation ID {} to point to a function", id),
478+
}
479+
}
480+
473481
/// Freezes an `AllocId` created with `reserve` by pointing it at an `Allocation`. Trying to
474482
/// call this function twice, even with the same `Allocation` will ICE the compiler.
475483
pub fn set_alloc_id_memory(&mut self, id: AllocId, mem: &'tcx Allocation) {

src/librustc/mir/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -2602,7 +2602,14 @@ impl<'tcx> Debug for Constant<'tcx> {
26022602
impl<'tcx> Display for Constant<'tcx> {
26032603
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
26042604
write!(fmt, "const ")?;
2605-
write!(fmt, "{}", self.literal)
2605+
// FIXME make the default pretty printing of raw pointers more detailed. Here we output the
2606+
// debug representation of raw pointers, so that the raw pointers in the mir dump output are
2607+
// detailed and just not '{pointer}'.
2608+
if let ty::RawPtr(_) = self.literal.ty.kind {
2609+
write!(fmt, "{:?} : {}", self.literal.val, self.literal.ty)
2610+
} else {
2611+
write!(fmt, "{}", self.literal)
2612+
}
26062613
}
26072614
}
26082615

src/librustc/ty/print/pretty.rs

+107-111
Original file line numberDiff line numberDiff line change
@@ -863,125 +863,121 @@ pub trait PrettyPrinter<'tcx>:
863863
}
864864

865865
let u8 = self.tcx().types.u8;
866-
if let ty::FnDef(did, substs) = ct.ty.kind {
867-
p!(print_value_path(did, substs));
868-
return Ok(self);
869-
}
870-
if let ConstValue::Unevaluated(did, substs) = ct.val {
871-
match self.tcx().def_kind(did) {
872-
| Some(DefKind::Static)
873-
| Some(DefKind::Const)
874-
| Some(DefKind::AssocConst) => p!(print_value_path(did, substs)),
875-
_ => if did.is_local() {
876-
let span = self.tcx().def_span(did);
877-
if let Ok(snip) = self.tcx().sess.source_map().span_to_snippet(span) {
878-
p!(write("{}", snip))
866+
867+
match (ct.val, &ct.ty.kind) {
868+
(_, ty::FnDef(did, substs)) => p!(print_value_path(*did, substs)),
869+
(ConstValue::Unevaluated(did, substs), _) => {
870+
match self.tcx().def_kind(did) {
871+
| Some(DefKind::Static)
872+
| Some(DefKind::Const)
873+
| Some(DefKind::AssocConst) => p!(print_value_path(did, substs)),
874+
_ => if did.is_local() {
875+
let span = self.tcx().def_span(did);
876+
if let Ok(snip) = self.tcx().sess.source_map().span_to_snippet(span) {
877+
p!(write("{}", snip))
878+
} else {
879+
p!(write("_: "), print(ct.ty))
880+
}
879881
} else {
880882
p!(write("_: "), print(ct.ty))
881-
}
883+
},
884+
}
885+
},
886+
(ConstValue::Infer(..), _) => p!(write("_: "), print(ct.ty)),
887+
(ConstValue::Param(ParamConst { name, .. }), _) => p!(write("{}", name)),
888+
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Bool) =>
889+
p!(write("{}", if data == 0 { "false" } else { "true" })),
890+
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Float(ast::FloatTy::F32)) =>
891+
p!(write("{}f32", Single::from_bits(data))),
892+
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Float(ast::FloatTy::F64)) =>
893+
p!(write("{}f64", Double::from_bits(data))),
894+
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Uint(ui)) => {
895+
let bit_size = Integer::from_attr(&self.tcx(), UnsignedInt(*ui)).size();
896+
let max = truncate(u128::max_value(), bit_size);
897+
898+
if data == max {
899+
p!(write("std::{}::MAX", ui))
882900
} else {
883-
p!(write("_: "), print(ct.ty))
884-
},
885-
}
886-
return Ok(self);
887-
}
888-
if let ConstValue::Infer(..) = ct.val {
889-
p!(write("_: "), print(ct.ty));
890-
return Ok(self);
891-
}
892-
if let ConstValue::Param(ParamConst { name, .. }) = ct.val {
893-
p!(write("{}", name));
894-
return Ok(self);
895-
}
896-
if let ConstValue::Scalar(Scalar::Raw { data, .. }) = ct.val {
897-
match ct.ty.kind {
898-
ty::Bool => {
899-
p!(write("{}", if data == 0 { "false" } else { "true" }));
900-
return Ok(self);
901-
},
902-
ty::Float(ast::FloatTy::F32) => {
903-
p!(write("{}f32", Single::from_bits(data)));
904-
return Ok(self);
905-
},
906-
ty::Float(ast::FloatTy::F64) => {
907-
p!(write("{}f64", Double::from_bits(data)));
908-
return Ok(self);
909-
},
910-
ty::Uint(ui) => {
911-
let bit_size = Integer::from_attr(&self.tcx(), UnsignedInt(ui)).size();
912-
let max = truncate(u128::max_value(), bit_size);
901+
p!(write("{}{}", data, ui))
902+
};
903+
},
904+
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Int(i)) => {
905+
let bit_size = Integer::from_attr(&self.tcx(), SignedInt(*i))
906+
.size().bits() as u128;
907+
let min = 1u128 << (bit_size - 1);
908+
let max = min - 1;
909+
910+
let ty = self.tcx().lift(&ct.ty).unwrap();
911+
let size = self.tcx().layout_of(ty::ParamEnv::empty().and(ty))
912+
.unwrap()
913+
.size;
914+
match data {
915+
d if d == min => p!(write("std::{}::MIN", i)),
916+
d if d == max => p!(write("std::{}::MAX", i)),
917+
_ => p!(write("{}{}", sign_extend(data, size) as i128, i))
918+
}
919+
},
920+
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Char) =>
921+
p!(write("{:?}", ::std::char::from_u32(data as u32).unwrap())),
922+
(ConstValue::Scalar(_), ty::RawPtr(_)) => p!(write("{{pointer}}")),
923+
(ConstValue::Scalar(Scalar::Ptr(ptr)), ty::FnPtr(_)) => {
924+
let instance = {
925+
let alloc_map = self.tcx().alloc_map.lock();
926+
alloc_map.unwrap_fn(ptr.alloc_id)
927+
};
928+
p!(print_value_path(instance.def_id(), instance.substs));
929+
},
930+
_ => {
931+
let printed = if let ty::Ref(_, ref_ty, _) = ct.ty.kind {
932+
let byte_str = match (ct.val, &ref_ty.kind) {
933+
(ConstValue::Scalar(Scalar::Ptr(ptr)), ty::Array(t, n)) if *t == u8 => {
934+
let n = n.eval_usize(self.tcx(), ty::ParamEnv::empty());
935+
Some(self.tcx()
936+
.alloc_map.lock()
937+
.unwrap_memory(ptr.alloc_id)
938+
.get_bytes(&self.tcx(), ptr, Size::from_bytes(n)).unwrap())
939+
},
940+
(ConstValue::Slice { data, start, end }, ty::Slice(t)) if *t == u8 => {
941+
// The `inspect` here is okay since we checked the bounds, and there are
942+
// no relocations (we have an active slice reference here). We don't use
943+
// this result to affect interpreter execution.
944+
Some(data.inspect_with_undef_and_ptr_outside_interpreter(start..end))
945+
},
946+
_ => None,
947+
};
913948

914-
if data == max {
915-
p!(write("std::{}::MAX", ui))
949+
if let Some(byte_str) = byte_str {
950+
p!(write("b\""));
951+
for &c in byte_str {
952+
for e in std::ascii::escape_default(c) {
953+
self.write_char(e as char)?;
954+
}
955+
}
956+
p!(write("\""));
957+
true
958+
} else if let (ConstValue::Slice { data, start, end }, ty::Str) =
959+
(ct.val, &ref_ty.kind)
960+
{
961+
// The `inspect` here is okay since we checked the bounds, and there are no
962+
// relocations (we have an active `str` reference here). We don't use this
963+
// result to affect interpreter execution.
964+
let slice = data.inspect_with_undef_and_ptr_outside_interpreter(start..end);
965+
let s = ::std::str::from_utf8(slice)
966+
.expect("non utf8 str from miri");
967+
p!(write("{:?}", s));
968+
true
916969
} else {
917-
p!(write("{}{}", data, ui))
918-
};
919-
return Ok(self);
920-
},
921-
ty::Int(i) =>{
922-
let bit_size = Integer::from_attr(&self.tcx(), SignedInt(i))
923-
.size().bits() as u128;
924-
let min = 1u128 << (bit_size - 1);
925-
let max = min - 1;
926-
927-
let ty = self.tcx().lift(&ct.ty).unwrap();
928-
let size = self.tcx().layout_of(ty::ParamEnv::empty().and(ty))
929-
.unwrap()
930-
.size;
931-
match data {
932-
d if d == min => p!(write("std::{}::MIN", i)),
933-
d if d == max => p!(write("std::{}::MAX", i)),
934-
_ => p!(write("{}{}", sign_extend(data, size) as i128, i))
935-
}
936-
return Ok(self);
937-
},
938-
ty::Char => {
939-
p!(write("{:?}", ::std::char::from_u32(data as u32).unwrap()));
940-
return Ok(self);
941-
}
942-
_ => {},
943-
}
944-
}
945-
if let ty::Ref(_, ref_ty, _) = ct.ty.kind {
946-
let byte_str = match (ct.val, &ref_ty.kind) {
947-
(ConstValue::Scalar(Scalar::Ptr(ptr)), ty::Array(t, n)) if *t == u8 => {
948-
let n = n.eval_usize(self.tcx(), ty::ParamEnv::empty());
949-
Some(self.tcx()
950-
.alloc_map.lock()
951-
.unwrap_memory(ptr.alloc_id)
952-
.get_bytes(&self.tcx(), ptr, Size::from_bytes(n)).unwrap())
953-
},
954-
(ConstValue::Slice { data, start, end }, ty::Slice(t)) if *t == u8 => {
955-
// The `inspect` here is okay since we checked the bounds, and there are no
956-
// relocations (we have an active slice reference here). We don't use this
957-
// result to affect interpreter execution.
958-
Some(data.inspect_with_undef_and_ptr_outside_interpreter(start..end))
959-
},
960-
(ConstValue::Slice { data, start, end }, ty::Str) => {
961-
// The `inspect` here is okay since we checked the bounds, and there are no
962-
// relocations (we have an active `str` reference here). We don't use this
963-
// result to affect interpreter execution.
964-
let slice = data.inspect_with_undef_and_ptr_outside_interpreter(start..end);
965-
let s = ::std::str::from_utf8(slice)
966-
.expect("non utf8 str from miri");
967-
p!(write("{:?}", s));
968-
return Ok(self);
969-
},
970-
_ => None,
971-
};
972-
if let Some(byte_str) = byte_str {
973-
p!(write("b\""));
974-
for &c in byte_str {
975-
for e in std::ascii::escape_default(c) {
976-
self.write_char(e as char)?;
970+
false
977971
}
972+
} else {
973+
false
974+
};
975+
if !printed {
976+
// fallback
977+
p!(write("{:?} : ", ct.val), print(ct.ty))
978978
}
979-
p!(write("\""));
980-
return Ok(self);
981979
}
982-
}
983-
p!(write("{:?} : ", ct.val), print(ct.ty));
984-
980+
};
985981
Ok(self)
986982
}
987983
}

0 commit comments

Comments
 (0)