Skip to content

Commit 7f115e3

Browse files
committed
Auto merge of rust-lang#101716 - Dylan-DPC:rollup-ayvh6nd, r=Dylan-DPC
Rollup of 9 pull requests Successful merges: - rust-lang#100293 (Add inline-llvm option for disabling/enabling LLVM inlining) - rust-lang#100767 (Remove manual <[u8]>::escape_ascii) - rust-lang#101668 (Suggest pub instead of public for const type item) - rust-lang#101671 (Fix naming format of IEEE 754 standard) - rust-lang#101676 (Check that the types in return position `impl Trait` in traits are well-formed) - rust-lang#101681 (Deny return-position `impl Trait` in traits for object safety) - rust-lang#101693 (Update browser UI test 0 10) - rust-lang#101701 (Rustdoc-Json: Add tests for trait impls.) - rust-lang#101706 (rustdoc: remove no-op `#search`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents a93214e + 9bf89e7 commit 7f115e3

File tree

41 files changed

+372
-105
lines changed

Some content is hidden

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

41 files changed

+372
-105
lines changed

compiler/rustc_ast/src/token.rs

+1
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ impl Token {
473473
kw::Extern,
474474
kw::Impl,
475475
kw::Unsafe,
476+
kw::Const,
476477
kw::Static,
477478
kw::Union,
478479
kw::Macro,

compiler/rustc_ast/src/util/literal.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,7 @@ impl LitKind {
163163
}
164164
LitKind::Str(symbol, ast::StrStyle::Raw(n)) => (token::StrRaw(n), symbol, None),
165165
LitKind::ByteStr(ref bytes) => {
166-
let string = bytes
167-
.iter()
168-
.cloned()
169-
.flat_map(ascii::escape_default)
170-
.map(Into::<char>::into)
171-
.collect::<String>();
166+
let string = bytes.escape_ascii().to_string();
172167
(token::ByteStr, Symbol::intern(&string), None)
173168
}
174169
LitKind::Byte(byte) => {

compiler/rustc_codegen_llvm/src/attributes.rs

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ pub fn apply_to_callsite(callsite: &Value, idx: AttributePlace, attrs: &[&Attrib
3535
/// Get LLVM attribute for the provided inline heuristic.
3636
#[inline]
3737
fn inline_attr<'ll>(cx: &CodegenCx<'ll, '_>, inline: InlineAttr) -> Option<&'ll Attribute> {
38+
if !cx.tcx.sess.opts.unstable_opts.inline_llvm {
39+
// disable LLVM inlining
40+
return Some(AttributeKind::NoInline.create_attr(cx.llcx));
41+
}
3842
match inline {
3943
InlineAttr::Hint => Some(AttributeKind::InlineHint.create_attr(cx.llcx)),
4044
InlineAttr::Always => Some(AttributeKind::AlwaysInline.create_attr(cx.llcx)),

compiler/rustc_codegen_ssa/src/back/link.rs

+8-17
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use std::io::{BufWriter, Write};
4444
use std::ops::Deref;
4545
use std::path::{Path, PathBuf};
4646
use std::process::{ExitStatus, Output, Stdio};
47-
use std::{ascii, char, env, fmt, fs, io, mem, str};
47+
use std::{env, fmt, fs, io, mem, str};
4848

4949
pub fn ensure_removed(diag_handler: &Handler, path: &Path) {
5050
if let Err(e) = fs::remove_file(path) {
@@ -552,14 +552,6 @@ fn link_staticlib<'a>(
552552
Ok(())
553553
}
554554

555-
fn escape_stdout_stderr_string(s: &[u8]) -> String {
556-
str::from_utf8(s).map(|s| s.to_owned()).unwrap_or_else(|_| {
557-
let mut x = "Non-UTF-8 output: ".to_string();
558-
x.extend(s.iter().flat_map(|&b| ascii::escape_default(b)).map(char::from));
559-
x
560-
})
561-
}
562-
563555
/// Use `thorin` (rust implementation of a dwarf packaging utility) to link DWARF objects into a
564556
/// DWARF package.
565557
fn link_dwarf_object<'a>(
@@ -866,7 +858,7 @@ fn link_natively<'a>(
866858
if !prog.status.success() {
867859
let mut output = prog.stderr.clone();
868860
output.extend_from_slice(&prog.stdout);
869-
let escaped_output = escape_stdout_stderr_string(&output);
861+
let escaped_output = escape_string(&output);
870862
let mut err = sess.struct_err(&format!(
871863
"linking with `{}` failed: {}",
872864
linker_path.display(),
@@ -934,8 +926,8 @@ fn link_natively<'a>(
934926

935927
sess.abort_if_errors();
936928
}
937-
info!("linker stderr:\n{}", escape_stdout_stderr_string(&prog.stderr));
938-
info!("linker stdout:\n{}", escape_stdout_stderr_string(&prog.stdout));
929+
info!("linker stderr:\n{}", escape_string(&prog.stderr));
930+
info!("linker stdout:\n{}", escape_string(&prog.stdout));
939931
}
940932
Err(e) => {
941933
let linker_not_found = e.kind() == io::ErrorKind::NotFound;
@@ -1065,11 +1057,10 @@ fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: Opti
10651057
}
10661058

10671059
fn escape_string(s: &[u8]) -> String {
1068-
str::from_utf8(s).map(|s| s.to_owned()).unwrap_or_else(|_| {
1069-
let mut x = "Non-UTF-8 output: ".to_string();
1070-
x.extend(s.iter().flat_map(|&b| ascii::escape_default(b)).map(char::from));
1071-
x
1072-
})
1060+
match str::from_utf8(s) {
1061+
Ok(s) => s.to_owned(),
1062+
Err(_) => format!("Non-UTF-8 output: {}", s.escape_ascii()),
1063+
}
10731064
}
10741065

10751066
fn add_sanitizer_libraries(sess: &Session, crate_type: CrateType, linker: &mut dyn Linker) {

compiler/rustc_middle/src/mir/mod.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -2633,15 +2633,7 @@ fn pretty_print_const<'tcx>(
26332633
}
26342634

26352635
fn pretty_print_byte_str(fmt: &mut Formatter<'_>, byte_str: &[u8]) -> fmt::Result {
2636-
fmt.write_str("b\"")?;
2637-
for &c in byte_str {
2638-
for e in std::ascii::escape_default(c) {
2639-
fmt.write_char(e as char)?;
2640-
}
2641-
}
2642-
fmt.write_str("\"")?;
2643-
2644-
Ok(())
2636+
write!(fmt, "b\"{}\"", byte_str.escape_ascii())
26452637
}
26462638

26472639
fn comma_sep<'tcx>(fmt: &mut Formatter<'_>, elems: Vec<ConstantKind<'tcx>>) -> fmt::Result {

compiler/rustc_middle/src/traits/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,12 @@ impl ObjectSafetyViolation {
915915
ObjectSafetyViolation::Method(name, MethodViolationCode::ReferencesSelfOutput, _) => {
916916
format!("method `{}` references the `Self` type in its return type", name).into()
917917
}
918+
ObjectSafetyViolation::Method(
919+
name,
920+
MethodViolationCode::ReferencesImplTraitInTrait,
921+
_,
922+
) => format!("method `{}` references an `impl Trait` type in its return type", name)
923+
.into(),
918924
ObjectSafetyViolation::Method(
919925
name,
920926
MethodViolationCode::WhereClauseReferencesSelf,
@@ -1021,6 +1027,9 @@ pub enum MethodViolationCode {
10211027
/// e.g., `fn foo(&self) -> Self`
10221028
ReferencesSelfOutput,
10231029

1030+
/// e.g., `fn foo(&self) -> impl Sized`
1031+
ReferencesImplTraitInTrait,
1032+
10241033
/// e.g., `fn foo(&self) where Self: Clone`
10251034
WhereClauseReferencesSelf,
10261035

compiler/rustc_middle/src/ty/print/pretty.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -1405,14 +1405,7 @@ pub trait PrettyPrinter<'tcx>:
14051405
}
14061406

14071407
fn pretty_print_byte_str(mut self, byte_str: &'tcx [u8]) -> Result<Self::Const, Self::Error> {
1408-
define_scoped_cx!(self);
1409-
p!("b\"");
1410-
for &c in byte_str {
1411-
for e in std::ascii::escape_default(c) {
1412-
self.write_char(e as char)?;
1413-
}
1414-
}
1415-
p!("\"");
1408+
write!(self, "b\"{}\"", byte_str.escape_ascii())?;
14161409
Ok(self)
14171410
}
14181411

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,8 @@ options! {
13451345
"hash spans relative to their parent item for incr. comp. (default: no)"),
13461346
incremental_verify_ich: bool = (false, parse_bool, [UNTRACKED],
13471347
"verify incr. comp. hashes of green query instances (default: no)"),
1348+
inline_llvm: bool = (true, parse_bool, [TRACKED],
1349+
"enable LLVM inlining (default: yes)"),
13481350
inline_mir: Option<bool> = (None, parse_opt_bool, [TRACKED],
13491351
"enable MIR inlining (default: no)"),
13501352
inline_mir_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],

compiler/rustc_trait_selection/src/traits/object_safety.rs

+26
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use super::elaborate_predicates;
1313
use crate::infer::TyCtxtInferExt;
1414
use crate::traits::query::evaluate_obligation::InferCtxtExt;
1515
use crate::traits::{self, Obligation, ObligationCause};
16+
use hir::def::DefKind;
1617
use rustc_errors::{FatalError, MultiSpan};
1718
use rustc_hir as hir;
1819
use rustc_hir::def_id::DefId;
@@ -431,6 +432,9 @@ fn virtual_call_violation_for_method<'tcx>(
431432
if contains_illegal_self_type_reference(tcx, trait_def_id, sig.output()) {
432433
return Some(MethodViolationCode::ReferencesSelfOutput);
433434
}
435+
if contains_illegal_impl_trait_in_trait(tcx, sig.output()) {
436+
return Some(MethodViolationCode::ReferencesImplTraitInTrait);
437+
}
434438

435439
// We can't monomorphize things like `fn foo<A>(...)`.
436440
let own_counts = tcx.generics_of(method.def_id).own_counts();
@@ -793,6 +797,12 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeVisitable<'tcx>>(
793797
ControlFlow::CONTINUE
794798
}
795799
}
800+
ty::Projection(ref data)
801+
if self.tcx.def_kind(data.item_def_id) == DefKind::ImplTraitPlaceholder =>
802+
{
803+
// We'll deny these later in their own pass
804+
ControlFlow::CONTINUE
805+
}
796806
ty::Projection(ref data) => {
797807
// This is a projected type `<Foo as SomeTrait>::X`.
798808

@@ -861,6 +871,22 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeVisitable<'tcx>>(
861871
.is_break()
862872
}
863873

874+
pub fn contains_illegal_impl_trait_in_trait<'tcx>(
875+
tcx: TyCtxt<'tcx>,
876+
ty: ty::Binder<'tcx, Ty<'tcx>>,
877+
) -> bool {
878+
// FIXME(RPITIT): Perhaps we should use a visitor here?
879+
ty.skip_binder().walk().any(|arg| {
880+
if let ty::GenericArgKind::Type(ty) = arg.unpack()
881+
&& let ty::Projection(proj) = ty.kind()
882+
{
883+
tcx.def_kind(proj.item_def_id) == DefKind::ImplTraitPlaceholder
884+
} else {
885+
false
886+
}
887+
})
888+
}
889+
864890
pub fn provide(providers: &mut ty::query::Providers) {
865891
*providers = ty::query::Providers { object_safety_violations, ..*providers };
866892
}

compiler/rustc_typeck/src/check/wfcheck.rs

+44
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::constrained_generic_params::{identify_constrained_generic_params, Parameter};
2+
use hir::def::DefKind;
23
use rustc_ast as ast;
34
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
45
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed};
@@ -1530,6 +1531,49 @@ fn check_fn_or_method<'tcx>(
15301531
);
15311532

15321533
check_where_clauses(wfcx, span, def_id);
1534+
1535+
check_return_position_impl_trait_in_trait_bounds(
1536+
tcx,
1537+
wfcx,
1538+
def_id,
1539+
sig.output(),
1540+
hir_decl.output.span(),
1541+
);
1542+
}
1543+
1544+
/// Basically `check_associated_type_bounds`, but separated for now and should be
1545+
/// deduplicated when RPITITs get lowered into real associated items.
1546+
fn check_return_position_impl_trait_in_trait_bounds<'tcx>(
1547+
tcx: TyCtxt<'tcx>,
1548+
wfcx: &WfCheckingCtxt<'_, 'tcx>,
1549+
fn_def_id: LocalDefId,
1550+
fn_output: Ty<'tcx>,
1551+
span: Span,
1552+
) {
1553+
if let Some(assoc_item) = tcx.opt_associated_item(fn_def_id.to_def_id())
1554+
&& assoc_item.container == ty::AssocItemContainer::TraitContainer
1555+
{
1556+
for arg in fn_output.walk() {
1557+
if let ty::GenericArgKind::Type(ty) = arg.unpack()
1558+
&& let ty::Projection(proj) = ty.kind()
1559+
&& tcx.def_kind(proj.item_def_id) == DefKind::ImplTraitPlaceholder
1560+
&& tcx.impl_trait_in_trait_parent(proj.item_def_id) == fn_def_id.to_def_id()
1561+
{
1562+
let bounds = wfcx.tcx().explicit_item_bounds(proj.item_def_id);
1563+
let wf_obligations = bounds.iter().flat_map(|&(bound, bound_span)| {
1564+
let normalized_bound = wfcx.normalize(span, None, bound);
1565+
traits::wf::predicate_obligations(
1566+
wfcx.infcx,
1567+
wfcx.param_env,
1568+
wfcx.body_id,
1569+
normalized_bound,
1570+
bound_span,
1571+
)
1572+
});
1573+
wfcx.register_obligations(wf_obligations);
1574+
}
1575+
}
1576+
}
15331577
}
15341578

15351579
const HELP_FOR_SELF_TYPE: &str = "consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, \

library/core/src/ffi/c_double.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Equivalent to C's `double` type.
22

3-
This type will almost always be [`f64`], which is guaranteed to be an [IEEE-754 double-precision float] in Rust. That said, the standard technically only guarantees that it be a floating-point number with at least the precision of a [`float`], and it may be `f32` or something entirely different from the IEEE-754 standard.
3+
This type will almost always be [`f64`], which is guaranteed to be an [IEEE 754 double-precision float] in Rust. That said, the standard technically only guarantees that it be a floating-point number with at least the precision of a [`float`], and it may be `f32` or something entirely different from the IEEE-754 standard.
44

5-
[IEEE-754 double-precision float]: https://en.wikipedia.org/wiki/IEEE_754
5+
[IEEE 754 double-precision float]: https://en.wikipedia.org/wiki/IEEE_754
66
[`float`]: c_float

library/core/src/ffi/c_float.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Equivalent to C's `float` type.
22

3-
This type will almost always be [`f32`], which is guaranteed to be an [IEEE-754 single-precision float] in Rust. That said, the standard technically only guarantees that it be a floating-point number, and it may have less precision than `f32` or not follow the IEEE-754 standard at all.
3+
This type will almost always be [`f32`], which is guaranteed to be an [IEEE 754 single-precision float] in Rust. That said, the standard technically only guarantees that it be a floating-point number, and it may have less precision than `f32` or not follow the IEEE-754 standard at all.
44

5-
[IEEE-754 single-precision float]: https://en.wikipedia.org/wiki/IEEE_754
5+
[IEEE 754 single-precision float]: https://en.wikipedia.org/wiki/IEEE_754

library/core/src/ffi/c_str.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use crate::ascii;
21
use crate::cmp::Ordering;
32
use crate::ffi::c_char;
4-
use crate::fmt::{self, Write};
3+
use crate::fmt;
54
use crate::intrinsics;
65
use crate::ops;
76
use crate::slice;
@@ -161,11 +160,7 @@ impl fmt::Display for FromBytesUntilNulError {
161160
#[stable(feature = "cstr_debug", since = "1.3.0")]
162161
impl fmt::Debug for CStr {
163162
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
164-
write!(f, "\"")?;
165-
for byte in self.to_bytes().iter().flat_map(|&b| ascii::escape_default(b)) {
166-
f.write_char(byte as char)?;
167-
}
168-
write!(f, "\"")
163+
write!(f, "\"{}\"", self.to_bytes().escape_ascii())
169164
}
170165
}
171166

library/core/src/num/dec2flt/decimal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl Default for Decimal {
3232
impl Decimal {
3333
/// The maximum number of digits required to unambiguously round a float.
3434
///
35-
/// For a double-precision IEEE-754 float, this required 767 digits,
35+
/// For a double-precision IEEE 754 float, this required 767 digits,
3636
/// so we store the max digits + 1.
3737
///
3838
/// We can exactly represent a float in radix `b` from radix 2 if

library/core/src/num/f32.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ impl f32 {
394394

395395
/// Not a Number (NaN).
396396
///
397-
/// Note that IEEE-754 doesn't define just a single NaN value;
397+
/// Note that IEEE 754 doesn't define just a single NaN value;
398398
/// a plethora of bit patterns are considered to be NaN.
399399
/// Furthermore, the standard makes a difference
400400
/// between a "signaling" and a "quiet" NaN,
@@ -632,7 +632,7 @@ impl f32 {
632632
}
633633

634634
/// Returns `true` if `self` has a positive sign, including `+0.0`, NaNs with
635-
/// positive sign bit and positive infinity. Note that IEEE-754 doesn't assign any
635+
/// positive sign bit and positive infinity. Note that IEEE 754 doesn't assign any
636636
/// meaning to the sign bit in case of a NaN, and as Rust doesn't guarantee that
637637
/// the bit pattern of NaNs are conserved over arithmetic operations, the result of
638638
/// `is_sign_positive` on a NaN might produce an unexpected result in some cases.
@@ -654,7 +654,7 @@ impl f32 {
654654
}
655655

656656
/// Returns `true` if `self` has a negative sign, including `-0.0`, NaNs with
657-
/// negative sign bit and negative infinity. Note that IEEE-754 doesn't assign any
657+
/// negative sign bit and negative infinity. Note that IEEE 754 doesn't assign any
658658
/// meaning to the sign bit in case of a NaN, and as Rust doesn't guarantee that
659659
/// the bit pattern of NaNs are conserved over arithmetic operations, the result of
660660
/// `is_sign_negative` on a NaN might produce an unexpected result in some cases.
@@ -833,7 +833,7 @@ impl f32 {
833833
/// Returns the maximum of the two numbers, ignoring NaN.
834834
///
835835
/// If one of the arguments is NaN, then the other argument is returned.
836-
/// This follows the IEEE-754 2008 semantics for maxNum, except for handling of signaling NaNs;
836+
/// This follows the IEEE 754-2008 semantics for maxNum, except for handling of signaling NaNs;
837837
/// this function handles all NaNs the same way and avoids maxNum's problems with associativity.
838838
/// This also matches the behavior of libm’s fmax.
839839
///
@@ -853,7 +853,7 @@ impl f32 {
853853
/// Returns the minimum of the two numbers, ignoring NaN.
854854
///
855855
/// If one of the arguments is NaN, then the other argument is returned.
856-
/// This follows the IEEE-754 2008 semantics for minNum, except for handling of signaling NaNs;
856+
/// This follows the IEEE 754-2008 semantics for minNum, except for handling of signaling NaNs;
857857
/// this function handles all NaNs the same way and avoids minNum's problems with associativity.
858858
/// This also matches the behavior of libm’s fmin.
859859
///
@@ -1051,9 +1051,9 @@ impl f32 {
10511051
/// It turns out this is incredibly portable, for two reasons:
10521052
///
10531053
/// * Floats and Ints have the same endianness on all supported platforms.
1054-
/// * IEEE-754 very precisely specifies the bit layout of floats.
1054+
/// * IEEE 754 very precisely specifies the bit layout of floats.
10551055
///
1056-
/// However there is one caveat: prior to the 2008 version of IEEE-754, how
1056+
/// However there is one caveat: prior to the 2008 version of IEEE 754, how
10571057
/// to interpret the NaN signaling bit wasn't actually specified. Most platforms
10581058
/// (notably x86 and ARM) picked the interpretation that was ultimately
10591059
/// standardized in 2008, but some didn't (notably MIPS). As a result, all

0 commit comments

Comments
 (0)