Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7d289ae

Browse files
committedSep 5, 2020
Auto merge of #76376 - Dylan-DPC:rollup-8chsbw9, r=Dylan-DPC
Rollup of 11 pull requests Successful merges: - #75695 (Add a regression test for issue-72793) - #75741 (Refactor byteorder to std in rustc_middle) - #75954 (Unstable Book: add links to tracking issues for FFI features) - #75994 (`impl Rc::new_cyclic`) - #76060 (Link vec doc to & reference) - #76078 (Remove disambiguators from intra doc link text) - #76082 (Fix intra-doc links on pub re-exports) - #76254 (Fold length constant in Rvalue::Repeat) - #76258 (x.py check checks tests/examples/benches) - #76263 (inliner: Check for codegen fn attributes compatibility) - #76285 (Move jointness censoring to proc_macro) Failed merges: r? @ghost
2 parents 81a769f + 85cee57 commit 7d289ae

31 files changed

+714
-86
lines changed
 

‎Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3722,7 +3722,6 @@ name = "rustc_middle"
37223722
version = "0.0.0"
37233723
dependencies = [
37243724
"bitflags",
3725-
"byteorder",
37263725
"chalk-ir",
37273726
"measureme",
37283727
"polonius-engine",

‎compiler/rustc_ast/src/tokenstream.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,8 @@ impl Cursor {
403403
self.index = index;
404404
}
405405

406-
pub fn look_ahead(&self, n: usize) -> Option<TokenTree> {
407-
self.stream.0[self.index..].get(n).map(|(tree, _)| tree.clone())
406+
pub fn look_ahead(&self, n: usize) -> Option<&TokenTree> {
407+
self.stream.0[self.index..].get(n).map(|(tree, _)| tree)
408408
}
409409
}
410410

‎compiler/rustc_expand/src/proc_macro_server.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,26 @@ impl ToInternal<token::DelimToken> for Delimiter {
4747
}
4848
}
4949

50-
impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
51-
for TokenTree<Group, Punct, Ident, Literal>
50+
impl
51+
FromInternal<(
52+
TreeAndJoint,
53+
Option<&'_ tokenstream::TokenTree>,
54+
&'_ ParseSess,
55+
&'_ mut Vec<Self>,
56+
)> for TokenTree<Group, Punct, Ident, Literal>
5257
{
5358
fn from_internal(
54-
((tree, is_joint), sess, stack): (TreeAndJoint, &ParseSess, &mut Vec<Self>),
59+
((tree, is_joint), look_ahead, sess, stack): (
60+
TreeAndJoint,
61+
Option<&tokenstream::TokenTree>,
62+
&ParseSess,
63+
&mut Vec<Self>,
64+
),
5565
) -> Self {
5666
use rustc_ast::token::*;
5767

58-
let joint = is_joint == Joint;
68+
let joint = is_joint == Joint
69+
&& matches!(look_ahead, Some(tokenstream::TokenTree::Token(t)) if t.is_op());
5970
let Token { kind, span } = match tree {
6071
tokenstream::TokenTree::Delimited(span, delim, tts) => {
6172
let delimiter = Delimiter::from_internal(delim);
@@ -445,7 +456,8 @@ impl server::TokenStreamIter for Rustc<'_> {
445456
loop {
446457
let tree = iter.stack.pop().or_else(|| {
447458
let next = iter.cursor.next_with_joint()?;
448-
Some(TokenTree::from_internal((next, self.sess, &mut iter.stack)))
459+
let lookahead = iter.cursor.look_ahead(0);
460+
Some(TokenTree::from_internal((next, lookahead, self.sess, &mut iter.stack)))
449461
})?;
450462
// A hack used to pass AST fragments to attribute and derive macros
451463
// as a single nonterminal token instead of a token stream.

‎compiler/rustc_middle/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ rustc_index = { path = "../rustc_index" }
2626
rustc_serialize = { path = "../rustc_serialize" }
2727
rustc_ast = { path = "../rustc_ast" }
2828
rustc_span = { path = "../rustc_span" }
29-
byteorder = { version = "1.3" }
3029
chalk-ir = "0.21.0"
3130
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
3231
measureme = "0.7.1"

‎compiler/rustc_middle/src/mir/interpret/allocation.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,8 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
345345

346346
/// Reads a *non-ZST* scalar.
347347
///
348-
/// ZSTs can't be read for two reasons:
349-
/// * byte-order cannot work with zero-element buffers;
350-
/// * in order to obtain a `Pointer`, we need to check for ZSTness anyway due to integer
351-
/// pointers being valid for ZSTs.
348+
/// ZSTs can't be read because in order to obtain a `Pointer`, we need to check
349+
/// for ZSTness anyway due to integer pointers being valid for ZSTs.
352350
///
353351
/// It is the caller's responsibility to check bounds and alignment beforehand.
354352
/// Most likely, you want to call `InterpCx::read_scalar` instead of this method.
@@ -397,10 +395,8 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
397395

398396
/// Writes a *non-ZST* scalar.
399397
///
400-
/// ZSTs can't be read for two reasons:
401-
/// * byte-order cannot work with zero-element buffers;
402-
/// * in order to obtain a `Pointer`, we need to check for ZSTness anyway due to integer
403-
/// pointers being valid for ZSTs.
398+
/// ZSTs can't be read because in order to obtain a `Pointer`, we need to check
399+
/// for ZSTness anyway due to integer pointers being valid for ZSTs.
404400
///
405401
/// It is the caller's responsibility to check bounds and alignment beforehand.
406402
/// Most likely, you want to call `InterpCx::write_scalar` instead of this method.

‎compiler/rustc_middle/src/mir/interpret/mod.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ mod value;
9898
use std::convert::TryFrom;
9999
use std::fmt;
100100
use std::io;
101+
use std::io::{Read, Write};
101102
use std::num::NonZeroU32;
102103
use std::sync::atomic::{AtomicU32, Ordering};
103104

104-
use byteorder::{BigEndian, LittleEndian, ReadBytesExt, WriteBytesExt};
105105
use rustc_ast::LitKind;
106106
use rustc_data_structures::fx::FxHashMap;
107107
use rustc_data_structures::sync::{HashMapExt, Lock};
@@ -561,19 +561,33 @@ pub fn write_target_uint(
561561
mut target: &mut [u8],
562562
data: u128,
563563
) -> Result<(), io::Error> {
564-
let len = target.len();
564+
// This u128 holds an "any-size uint" (since smaller uints can fits in it)
565+
// So we do not write all bytes of the u128, just the "payload".
565566
match endianness {
566-
Endian::Little => target.write_uint128::<LittleEndian>(data, len),
567-
Endian::Big => target.write_uint128::<BigEndian>(data, len),
568-
}
567+
Endian::Little => target.write(&data.to_le_bytes())?,
568+
Endian::Big => target.write(&data.to_be_bytes()[16 - target.len()..])?,
569+
};
570+
debug_assert!(target.len() == 0); // We should have filled the target buffer.
571+
Ok(())
569572
}
570573

571574
#[inline]
572575
pub fn read_target_uint(endianness: Endian, mut source: &[u8]) -> Result<u128, io::Error> {
573-
match endianness {
574-
Endian::Little => source.read_uint128::<LittleEndian>(source.len()),
575-
Endian::Big => source.read_uint128::<BigEndian>(source.len()),
576-
}
576+
// This u128 holds an "any-size uint" (since smaller uints can fits in it)
577+
let mut buf = [0u8; std::mem::size_of::<u128>()];
578+
// So we do not read exactly 16 bytes into the u128, just the "payload".
579+
let uint = match endianness {
580+
Endian::Little => {
581+
source.read(&mut buf)?;
582+
Ok(u128::from_le_bytes(buf))
583+
}
584+
Endian::Big => {
585+
source.read(&mut buf[16 - source.len()..])?;
586+
Ok(u128::from_be_bytes(buf))
587+
}
588+
};
589+
debug_assert!(source.len() == 0); // We should have consumed the source buffer.
590+
uint
577591
}
578592

579593
////////////////////////////////////////////////////////////////////////////////

‎compiler/rustc_middle/src/mir/type_foldable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
175175
use crate::mir::Rvalue::*;
176176
match *self {
177177
Use(ref op) => Use(op.fold_with(folder)),
178-
Repeat(ref op, len) => Repeat(op.fold_with(folder), len),
178+
Repeat(ref op, len) => Repeat(op.fold_with(folder), len.fold_with(folder)),
179179
ThreadLocalRef(did) => ThreadLocalRef(did.fold_with(folder)),
180180
Ref(region, bk, ref place) => {
181181
Ref(region.fold_with(folder), bk, place.fold_with(folder))

‎compiler/rustc_mir/src/transform/inline.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_attr as attr;
44
use rustc_hir::def_id::DefId;
55
use rustc_index::bit_set::BitSet;
66
use rustc_index::vec::{Idx, IndexVec};
7-
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
7+
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
88
use rustc_middle::mir::visit::*;
99
use rustc_middle::mir::*;
1010
use rustc_middle::ty::subst::{Subst, SubstsRef};
@@ -45,7 +45,8 @@ impl<'tcx> MirPass<'tcx> for Inline {
4545
// based function.
4646
debug!("function inlining is disabled when compiling with `instrument_coverage`");
4747
} else {
48-
Inliner { tcx, source }.run_pass(body);
48+
Inliner { tcx, source, codegen_fn_attrs: tcx.codegen_fn_attrs(source.def_id()) }
49+
.run_pass(body);
4950
}
5051
}
5152
}
@@ -54,6 +55,7 @@ impl<'tcx> MirPass<'tcx> for Inline {
5455
struct Inliner<'tcx> {
5556
tcx: TyCtxt<'tcx>,
5657
source: MirSource<'tcx>,
58+
codegen_fn_attrs: &'tcx CodegenFnAttrs,
5759
}
5860

5961
impl Inliner<'tcx> {
@@ -242,9 +244,19 @@ impl Inliner<'tcx> {
242244
return false;
243245
}
244246

245-
// Avoid inlining functions marked as no_sanitize if sanitizer is enabled,
246-
// since instrumentation might be enabled and performed on the caller.
247-
if self.tcx.sess.opts.debugging_opts.sanitizer.intersects(codegen_fn_attrs.no_sanitize) {
247+
let self_features = &self.codegen_fn_attrs.target_features;
248+
let callee_features = &codegen_fn_attrs.target_features;
249+
if callee_features.iter().any(|feature| !self_features.contains(feature)) {
250+
debug!("`callee has extra target features - not inlining");
251+
return false;
252+
}
253+
254+
let self_no_sanitize =
255+
self.codegen_fn_attrs.no_sanitize & self.tcx.sess.opts.debugging_opts.sanitizer;
256+
let callee_no_sanitize =
257+
codegen_fn_attrs.no_sanitize & self.tcx.sess.opts.debugging_opts.sanitizer;
258+
if self_no_sanitize != callee_no_sanitize {
259+
debug!("`callee has incompatible no_sanitize attribute - not inlining");
248260
return false;
249261
}
250262

‎compiler/rustc_parse/src/lexer/tokentrees.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,7 @@ impl<'a> TokenTreesReader<'a> {
262262
}
263263
_ => {
264264
let tt = TokenTree::Token(self.token.take());
265-
let mut is_joint = self.bump();
266-
if !self.token.is_op() {
267-
is_joint = NonJoint;
268-
}
265+
let is_joint = self.bump();
269266
Ok((tt, is_joint))
270267
}
271268
}

‎compiler/rustc_parse/src/parser/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -822,15 +822,15 @@ impl<'a> Parser<'a> {
822822
}
823823

824824
let frame = &self.token_cursor.frame;
825-
looker(&match frame.tree_cursor.look_ahead(dist - 1) {
825+
match frame.tree_cursor.look_ahead(dist - 1) {
826826
Some(tree) => match tree {
827-
TokenTree::Token(token) => token,
827+
TokenTree::Token(token) => looker(token),
828828
TokenTree::Delimited(dspan, delim, _) => {
829-
Token::new(token::OpenDelim(delim), dspan.open)
829+
looker(&Token::new(token::OpenDelim(delim.clone()), dspan.open))
830830
}
831831
},
832-
None => Token::new(token::CloseDelim(frame.delim), frame.span.close),
833-
})
832+
None => looker(&Token::new(token::CloseDelim(frame.delim), frame.span.close)),
833+
}
834834
}
835835

836836
/// Returns whether any of the given keywords are `dist` tokens ahead of the current one.

‎library/alloc/src/rc.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,50 @@ impl<T> Rc<T> {
325325
)
326326
}
327327

328+
/// Constructs a new `Rc<T>` using a weak reference to itself. Attempting
329+
/// to upgrade the weak reference before this function returns will result
330+
/// in a `None` value. However, the weak reference may be cloned freely and
331+
/// stored for use at a later time.
332+
#[unstable(feature = "arc_new_cyclic", issue = "75861")]
333+
pub fn new_cyclic(data_fn: impl FnOnce(&Weak<T>) -> T) -> Rc<T> {
334+
// Construct the inner in the "uninitialized" state with a single
335+
// weak reference.
336+
let uninit_ptr: NonNull<_> = Box::leak(box RcBox {
337+
strong: Cell::new(0),
338+
weak: Cell::new(1),
339+
value: mem::MaybeUninit::<T>::uninit(),
340+
})
341+
.into();
342+
343+
let init_ptr: NonNull<RcBox<T>> = uninit_ptr.cast();
344+
345+
let weak = Weak { ptr: init_ptr };
346+
347+
// It's important we don't give up ownership of the weak pointer, or
348+
// else the memory might be freed by the time `data_fn` returns. If
349+
// we really wanted to pass ownership, we could create an additional
350+
// weak pointer for ourselves, but this would result in additional
351+
// updates to the weak reference count which might not be necessary
352+
// otherwise.
353+
let data = data_fn(&weak);
354+
355+
unsafe {
356+
let inner = init_ptr.as_ptr();
357+
ptr::write(&raw mut (*inner).value, data);
358+
359+
let prev_value = (*inner).strong.get();
360+
debug_assert_eq!(prev_value, 0, "No prior strong references should exist");
361+
(*inner).strong.set(1);
362+
}
363+
364+
let strong = Rc::from_inner(init_ptr);
365+
366+
// Strong references should collectively own a shared weak reference,
367+
// so don't run the destructor for our old weak reference.
368+
mem::forget(weak);
369+
strong
370+
}
371+
328372
/// Constructs a new `Rc` with uninitialized contents.
329373
///
330374
/// # Examples

‎library/alloc/src/rc/tests.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,3 +434,69 @@ fn test_array_from_slice() {
434434
let a: Result<Rc<[u32; 2]>, _> = r.clone().try_into();
435435
assert!(a.is_err());
436436
}
437+
438+
#[test]
439+
fn test_rc_cyclic_with_zero_refs() {
440+
struct ZeroRefs {
441+
inner: Weak<ZeroRefs>,
442+
}
443+
444+
let zero_refs = Rc::new_cyclic(|inner| {
445+
assert_eq!(inner.strong_count(), 0);
446+
assert!(inner.upgrade().is_none());
447+
ZeroRefs { inner: Weak::new() }
448+
});
449+
450+
assert_eq!(Rc::strong_count(&zero_refs), 1);
451+
assert_eq!(Rc::weak_count(&zero_refs), 0);
452+
assert_eq!(zero_refs.inner.strong_count(), 0);
453+
assert_eq!(zero_refs.inner.weak_count(), 0);
454+
}
455+
456+
#[test]
457+
fn test_rc_cyclic_with_one_ref() {
458+
struct OneRef {
459+
inner: Weak<OneRef>,
460+
}
461+
462+
let one_ref = Rc::new_cyclic(|inner| {
463+
assert_eq!(inner.strong_count(), 0);
464+
assert!(inner.upgrade().is_none());
465+
OneRef { inner: inner.clone() }
466+
});
467+
468+
assert_eq!(Rc::strong_count(&one_ref), 1);
469+
assert_eq!(Rc::weak_count(&one_ref), 1);
470+
471+
let one_ref2 = Weak::upgrade(&one_ref.inner).unwrap();
472+
assert!(Rc::ptr_eq(&one_ref, &one_ref2));
473+
474+
assert_eq!(one_ref.inner.strong_count(), 2);
475+
assert_eq!(one_ref.inner.weak_count(), 1);
476+
}
477+
478+
#[test]
479+
fn test_rc_cyclic_with_two_ref() {
480+
struct TwoRefs {
481+
inner: Weak<TwoRefs>,
482+
inner1: Weak<TwoRefs>,
483+
}
484+
485+
let two_refs = Rc::new_cyclic(|inner| {
486+
assert_eq!(inner.strong_count(), 0);
487+
assert!(inner.upgrade().is_none());
488+
TwoRefs { inner: inner.clone(), inner1: inner.clone() }
489+
});
490+
491+
assert_eq!(Rc::strong_count(&two_refs), 1);
492+
assert_eq!(Rc::weak_count(&two_refs), 2);
493+
494+
let two_ref3 = Weak::upgrade(&two_refs.inner).unwrap();
495+
assert!(Rc::ptr_eq(&two_refs, &two_ref3));
496+
497+
let two_ref2 = Weak::upgrade(&two_refs.inner1).unwrap();
498+
assert!(Rc::ptr_eq(&two_refs, &two_ref2));
499+
500+
assert_eq!(Rc::strong_count(&two_refs), 3);
501+
assert_eq!(Rc::weak_count(&two_refs), 2);
502+
}

‎library/alloc/src/vec.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ use crate::raw_vec::RawVec;
159159
/// # Slicing
160160
///
161161
/// A `Vec` can be mutable. Slices, on the other hand, are read-only objects.
162-
/// To get a slice, use `&`. Example:
162+
/// To get a [slice], use [`&`]. Example:
163163
///
164164
/// ```
165165
/// fn read_slice(slice: &[usize]) {
@@ -287,6 +287,8 @@ use crate::raw_vec::RawVec;
287287
/// [`insert`]: Vec::insert
288288
/// [`reserve`]: Vec::reserve
289289
/// [owned slice]: Box
290+
/// [slice]: ../../std/primitive.slice.html
291+
/// [`&`]: ../../std/primitive.reference.html
290292
#[stable(feature = "rust1", since = "1.0.0")]
291293
#[cfg_attr(not(test), rustc_diagnostic_item = "vec_type")]
292294
pub struct Vec<T> {

‎src/bootstrap/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl<'a> Builder<'a> {
382382
native::Lld
383383
),
384384
Kind::Check | Kind::Clippy | Kind::Fix | Kind::Format => {
385-
describe!(check::Std, check::Rustc, check::Rustdoc, check::Clippy)
385+
describe!(check::Std, check::Rustc, check::Rustdoc, check::Clippy, check::Bootstrap)
386386
}
387387
Kind::Test => describe!(
388388
crate::toolstate::ToolStateCheck,

‎src/bootstrap/check.rs

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,43 @@ impl Step for Std {
6666
let libdir = builder.sysroot_libdir(compiler, target);
6767
let hostdir = builder.sysroot_libdir(compiler, compiler.host);
6868
add_to_sysroot(&builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
69+
70+
// Then run cargo again, once we've put the rmeta files for the library
71+
// crates into the sysroot. This is needed because e.g., core's tests
72+
// depend on `libtest` -- Cargo presumes it will exist, but it doesn't
73+
// since we initialize with an empty sysroot.
74+
//
75+
// Currently only the "libtest" tree of crates does this.
76+
77+
let mut cargo = builder.cargo(
78+
compiler,
79+
Mode::Std,
80+
SourceType::InTree,
81+
target,
82+
cargo_subcommand(builder.kind),
83+
);
84+
std_cargo(builder, target, compiler.stage, &mut cargo);
85+
cargo.arg("--all-targets");
86+
87+
// Explicitly pass -p for all dependencies krates -- this will force cargo
88+
// to also check the tests/benches/examples for these crates, rather
89+
// than just the leaf crate.
90+
for krate in builder.in_tree_crates("test") {
91+
cargo.arg("-p").arg(krate.name);
92+
}
93+
94+
builder.info(&format!(
95+
"Checking std test/bench/example targets ({} -> {})",
96+
&compiler.host, target
97+
));
98+
run_cargo(
99+
builder,
100+
cargo,
101+
args(builder.kind),
102+
&libstd_test_stamp(builder, compiler, target),
103+
vec![],
104+
true,
105+
);
69106
}
70107
}
71108

@@ -106,6 +143,14 @@ impl Step for Rustc {
106143
cargo_subcommand(builder.kind),
107144
);
108145
rustc_cargo(builder, &mut cargo, target);
146+
cargo.arg("--all-targets");
147+
148+
// Explicitly pass -p for all compiler krates -- this will force cargo
149+
// to also check the tests/benches/examples for these crates, rather
150+
// than just the leaf crate.
151+
for krate in builder.in_tree_crates("rustc-main") {
152+
cargo.arg("-p").arg(krate.name);
153+
}
109154

110155
builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
111156
run_cargo(
@@ -149,7 +194,7 @@ macro_rules! tool_check_step {
149194

150195
builder.ensure(Rustc { target });
151196

152-
let cargo = prepare_tool_cargo(
197+
let mut cargo = prepare_tool_cargo(
153198
builder,
154199
compiler,
155200
Mode::ToolRustc,
@@ -160,12 +205,14 @@ macro_rules! tool_check_step {
160205
&[],
161206
);
162207

163-
println!(
208+
cargo.arg("--all-targets");
209+
210+
builder.info(&format!(
164211
"Checking {} artifacts ({} -> {})",
165212
stringify!($name).to_lowercase(),
166213
&compiler.host.triple,
167214
target.triple
168-
);
215+
));
169216
run_cargo(
170217
builder,
171218
cargo,
@@ -202,12 +249,24 @@ tool_check_step!(Rustdoc, "src/tools/rustdoc", SourceType::InTree);
202249
// rejected.
203250
tool_check_step!(Clippy, "src/tools/clippy", SourceType::InTree);
204251

252+
tool_check_step!(Bootstrap, "src/bootstrap", SourceType::InTree);
253+
205254
/// Cargo's output path for the standard library in a given stage, compiled
206255
/// by a particular compiler for the specified target.
207256
fn libstd_stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> PathBuf {
208257
builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
209258
}
210259

260+
/// Cargo's output path for the standard library in a given stage, compiled
261+
/// by a particular compiler for the specified target.
262+
fn libstd_test_stamp(
263+
builder: &Builder<'_>,
264+
compiler: Compiler,
265+
target: TargetSelection,
266+
) -> PathBuf {
267+
builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check-test.stamp")
268+
}
269+
211270
/// Cargo's output path for librustc in a given stage, compiled by a particular
212271
/// compiler for the specified target.
213272
fn librustc_stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> PathBuf {

‎src/doc/unstable-book/src/language-features/ffi-const.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# `ffi_const`
22

3+
The tracking issue for this feature is: [#58328]
4+
5+
------
6+
37
The `#[ffi_const]` attribute applies clang's `const` attribute to foreign
48
functions declarations.
59

@@ -42,6 +46,7 @@ implemented in this way on all of them. It is therefore also worth verifying
4246
that the semantics of the C toolchain used to compile the binary being linked
4347
against are compatible with those of the `#[ffi_const]`.
4448

49+
[#58328]: https://github.com/rust-lang/rust/issues/58328
4550
[ARM C/C++ compiler]: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0491c/Cacgigch.html
4651
[GCC]: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-const-function-attribute
4752
[IBM ILE C/C++]: https://www.ibm.com/support/knowledgecenter/fr/ssw_ibm_i_71/rzarg/fn_attrib_const.htm

‎src/doc/unstable-book/src/language-features/ffi-pure.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# `ffi_pure`
22

3+
The tracking issue for this feature is: [#58329]
4+
5+
------
6+
37
The `#[ffi_pure]` attribute applies clang's `pure` attribute to foreign
48
functions declarations.
59

@@ -46,6 +50,7 @@ that the semantics of the C toolchain used to compile the binary being linked
4650
against are compatible with those of the `#[ffi_pure]`.
4751

4852

53+
[#58329]: https://github.com/rust-lang/rust/issues/58329
4954
[ARM C/C++ compiler]: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0491c/Cacigdac.html
5055
[GCC]: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-pure-function-attribute
5156
[IBM ILE C/C++]: https://www.ibm.com/support/knowledgecenter/fr/ssw_ibm_i_71/rzarg/fn_attrib_pure.htm

‎src/librustdoc/clean/types.rs

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl Item {
118118
self.attrs.collapsed_doc_value()
119119
}
120120

121-
pub fn links(&self) -> Vec<(String, String)> {
121+
pub fn links(&self) -> Vec<RenderedLink> {
122122
self.attrs.links(&self.def_id.krate)
123123
}
124124

@@ -425,10 +425,38 @@ pub struct Attributes {
425425
pub cfg: Option<Arc<Cfg>>,
426426
pub span: Option<rustc_span::Span>,
427427
/// map from Rust paths to resolved defs and potential URL fragments
428-
pub links: Vec<(String, Option<DefId>, Option<String>)>,
428+
pub links: Vec<ItemLink>,
429429
pub inner_docs: bool,
430430
}
431431

432+
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
433+
/// A link that has not yet been rendered.
434+
///
435+
/// This link will be turned into a rendered link by [`Attributes::links`]
436+
pub struct ItemLink {
437+
/// The original link written in the markdown
438+
pub(crate) link: String,
439+
/// The link text displayed in the HTML.
440+
///
441+
/// This may not be the same as `link` if there was a disambiguator
442+
/// in an intra-doc link (e.g. \[`fn@f`\])
443+
pub(crate) link_text: String,
444+
pub(crate) did: Option<DefId>,
445+
/// The url fragment to append to the link
446+
pub(crate) fragment: Option<String>,
447+
}
448+
449+
pub struct RenderedLink {
450+
/// The text the link was original written as.
451+
///
452+
/// This could potentially include disambiguators and backticks.
453+
pub(crate) original_text: String,
454+
/// The text to display in the HTML
455+
pub(crate) new_text: String,
456+
/// The URL to put in the `href`
457+
pub(crate) href: String,
458+
}
459+
432460
impl Attributes {
433461
/// Extracts the content from an attribute `#[doc(cfg(content))]`.
434462
pub fn extract_cfg(mi: &ast::MetaItem) -> Option<&ast::MetaItem> {
@@ -605,21 +633,25 @@ impl Attributes {
605633
/// Gets links as a vector
606634
///
607635
/// Cache must be populated before call
608-
pub fn links(&self, krate: &CrateNum) -> Vec<(String, String)> {
636+
pub fn links(&self, krate: &CrateNum) -> Vec<RenderedLink> {
609637
use crate::html::format::href;
610638
use crate::html::render::CURRENT_DEPTH;
611639

612640
self.links
613641
.iter()
614-
.filter_map(|&(ref s, did, ref fragment)| {
615-
match did {
642+
.filter_map(|ItemLink { link: s, link_text, did, fragment }| {
643+
match *did {
616644
Some(did) => {
617645
if let Some((mut href, ..)) = href(did) {
618646
if let Some(ref fragment) = *fragment {
619647
href.push_str("#");
620648
href.push_str(fragment);
621649
}
622-
Some((s.clone(), href))
650+
Some(RenderedLink {
651+
original_text: s.clone(),
652+
new_text: link_text.clone(),
653+
href,
654+
})
623655
} else {
624656
None
625657
}
@@ -639,16 +671,17 @@ impl Attributes {
639671
};
640672
// This is a primitive so the url is done "by hand".
641673
let tail = fragment.find('#').unwrap_or_else(|| fragment.len());
642-
Some((
643-
s.clone(),
644-
format!(
674+
Some(RenderedLink {
675+
original_text: s.clone(),
676+
new_text: link_text.clone(),
677+
href: format!(
645678
"{}{}std/primitive.{}.html{}",
646679
url,
647680
if !url.ends_with('/') { "/" } else { "" },
648681
&fragment[..tail],
649682
&fragment[tail..]
650683
),
651-
))
684+
})
652685
} else {
653686
panic!("This isn't a primitive?!");
654687
}

‎src/librustdoc/html/markdown.rs

Lines changed: 97 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use std::fmt::Write;
3434
use std::ops::Range;
3535
use std::str;
3636

37+
use crate::clean::RenderedLink;
3738
use crate::doctest;
3839
use crate::html::highlight;
3940
use crate::html::toc::TocBuilder;
@@ -52,7 +53,7 @@ fn opts() -> Options {
5253
pub struct Markdown<'a>(
5354
pub &'a str,
5455
/// A list of link replacements.
55-
pub &'a [(String, String)],
56+
pub &'a [RenderedLink],
5657
/// The current list of used header IDs.
5758
pub &'a mut IdMap,
5859
/// Whether to allow the use of explicit error codes in doctest lang strings.
@@ -78,7 +79,7 @@ pub struct MarkdownHtml<'a>(
7879
pub &'a Option<Playground>,
7980
);
8081
/// A tuple struct like `Markdown` that renders only the first paragraph.
81-
pub struct MarkdownSummaryLine<'a>(pub &'a str, pub &'a [(String, String)]);
82+
pub struct MarkdownSummaryLine<'a>(pub &'a str, pub &'a [RenderedLink]);
8283

8384
#[derive(Copy, Clone, PartialEq, Debug)]
8485
pub enum ErrorCodes {
@@ -337,31 +338,107 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
337338
}
338339

339340
/// Make headings links with anchor IDs and build up TOC.
340-
struct LinkReplacer<'a, 'b, I: Iterator<Item = Event<'a>>> {
341+
struct LinkReplacer<'a, I: Iterator<Item = Event<'a>>> {
341342
inner: I,
342-
links: &'b [(String, String)],
343+
links: &'a [RenderedLink],
344+
shortcut_link: Option<&'a RenderedLink>,
343345
}
344346

345-
impl<'a, 'b, I: Iterator<Item = Event<'a>>> LinkReplacer<'a, 'b, I> {
346-
fn new(iter: I, links: &'b [(String, String)]) -> Self {
347-
LinkReplacer { inner: iter, links }
347+
impl<'a, I: Iterator<Item = Event<'a>>> LinkReplacer<'a, I> {
348+
fn new(iter: I, links: &'a [RenderedLink]) -> Self {
349+
LinkReplacer { inner: iter, links, shortcut_link: None }
348350
}
349351
}
350352

351-
impl<'a, 'b, I: Iterator<Item = Event<'a>>> Iterator for LinkReplacer<'a, 'b, I> {
353+
impl<'a, I: Iterator<Item = Event<'a>>> Iterator for LinkReplacer<'a, I> {
352354
type Item = Event<'a>;
353355

354356
fn next(&mut self) -> Option<Self::Item> {
355-
let event = self.inner.next();
356-
if let Some(Event::Start(Tag::Link(kind, dest, text))) = event {
357-
if let Some(&(_, ref replace)) = self.links.iter().find(|link| link.0 == *dest) {
358-
Some(Event::Start(Tag::Link(kind, replace.to_owned().into(), text)))
359-
} else {
360-
Some(Event::Start(Tag::Link(kind, dest, text)))
357+
use pulldown_cmark::LinkType;
358+
359+
let mut event = self.inner.next();
360+
361+
// Replace intra-doc links and remove disambiguators from shortcut links (`[fn@f]`).
362+
match &mut event {
363+
// This is a shortcut link that was resolved by the broken_link_callback: `[fn@f]`
364+
// Remove any disambiguator.
365+
Some(Event::Start(Tag::Link(
366+
// [fn@f] or [fn@f][]
367+
LinkType::ShortcutUnknown | LinkType::CollapsedUnknown,
368+
dest,
369+
title,
370+
))) => {
371+
debug!("saw start of shortcut link to {} with title {}", dest, title);
372+
// If this is a shortcut link, it was resolved by the broken_link_callback.
373+
// So the URL will already be updated properly.
374+
let link = self.links.iter().find(|&link| *link.href == **dest);
375+
// Since this is an external iterator, we can't replace the inner text just yet.
376+
// Store that we saw a link so we know to replace it later.
377+
if let Some(link) = link {
378+
trace!("it matched");
379+
assert!(self.shortcut_link.is_none(), "shortcut links cannot be nested");
380+
self.shortcut_link = Some(link);
381+
}
361382
}
362-
} else {
363-
event
383+
// Now that we're done with the shortcut link, don't replace any more text.
384+
Some(Event::End(Tag::Link(
385+
LinkType::ShortcutUnknown | LinkType::CollapsedUnknown,
386+
dest,
387+
_,
388+
))) => {
389+
debug!("saw end of shortcut link to {}", dest);
390+
if self.links.iter().find(|&link| *link.href == **dest).is_some() {
391+
assert!(self.shortcut_link.is_some(), "saw closing link without opening tag");
392+
self.shortcut_link = None;
393+
}
394+
}
395+
// Handle backticks in inline code blocks, but only if we're in the middle of a shortcut link.
396+
// [`fn@f`]
397+
Some(Event::Code(text)) => {
398+
trace!("saw code {}", text);
399+
if let Some(link) = self.shortcut_link {
400+
trace!("original text was {}", link.original_text);
401+
// NOTE: this only replaces if the code block is the *entire* text.
402+
// If only part of the link has code highlighting, the disambiguator will not be removed.
403+
// e.g. [fn@`f`]
404+
// This is a limitation from `collect_intra_doc_links`: it passes a full link,
405+
// and does not distinguish at all between code blocks.
406+
// So we could never be sure we weren't replacing too much:
407+
// [fn@my_`f`unc] is treated the same as [my_func()] in that pass.
408+
//
409+
// NOTE: &[1..len() - 1] is to strip the backticks
410+
if **text == link.original_text[1..link.original_text.len() - 1] {
411+
debug!("replacing {} with {}", text, link.new_text);
412+
*text = CowStr::Borrowed(&link.new_text);
413+
}
414+
}
415+
}
416+
// Replace plain text in links, but only in the middle of a shortcut link.
417+
// [fn@f]
418+
Some(Event::Text(text)) => {
419+
trace!("saw text {}", text);
420+
if let Some(link) = self.shortcut_link {
421+
trace!("original text was {}", link.original_text);
422+
// NOTE: same limitations as `Event::Code`
423+
if **text == *link.original_text {
424+
debug!("replacing {} with {}", text, link.new_text);
425+
*text = CowStr::Borrowed(&link.new_text);
426+
}
427+
}
428+
}
429+
// If this is a link, but not a shortcut link,
430+
// replace the URL, since the broken_link_callback was not called.
431+
Some(Event::Start(Tag::Link(_, dest, _))) => {
432+
if let Some(link) = self.links.iter().find(|&link| *link.original_text == **dest) {
433+
*dest = CowStr::Borrowed(link.href.as_ref());
434+
}
435+
}
436+
// Anything else couldn't have been a valid Rust path, so no need to replace the text.
437+
_ => {}
364438
}
439+
440+
// Yield the modified event
441+
event
365442
}
366443
}
367444

@@ -855,8 +932,8 @@ impl Markdown<'_> {
855932
return String::new();
856933
}
857934
let replacer = |_: &str, s: &str| {
858-
if let Some(&(_, ref replace)) = links.iter().find(|link| &*link.0 == s) {
859-
Some((replace.clone(), s.to_owned()))
935+
if let Some(link) = links.iter().find(|link| &*link.original_text == s) {
936+
Some((link.href.clone(), link.new_text.clone()))
860937
} else {
861938
None
862939
}
@@ -933,8 +1010,8 @@ impl MarkdownSummaryLine<'_> {
9331010
}
9341011

9351012
let replacer = |_: &str, s: &str| {
936-
if let Some(&(_, ref replace)) = links.iter().find(|link| &*link.0 == s) {
937-
Some((replace.clone(), s.to_owned()))
1013+
if let Some(link) = links.iter().find(|link| &*link.original_text == s) {
1014+
Some((link.href.clone(), link.new_text.clone()))
9381015
} else {
9391016
None
9401017
}

‎src/librustdoc/html/render/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ use rustc_span::symbol::{sym, Symbol};
6363
use serde::ser::SerializeSeq;
6464
use serde::{Serialize, Serializer};
6565

66-
use crate::clean::{self, AttributesExt, Deprecation, GetDefId, SelfTy, TypeKind};
67-
use crate::config::RenderInfo;
68-
use crate::config::RenderOptions;
66+
use crate::clean::{self, AttributesExt, Deprecation, GetDefId, RenderedLink, SelfTy, TypeKind};
67+
use crate::config::{RenderInfo, RenderOptions};
6968
use crate::docfs::{DocFS, PathError};
7069
use crate::doctree;
7170
use crate::error::Error;
@@ -1774,7 +1773,7 @@ fn render_markdown(
17741773
w: &mut Buffer,
17751774
cx: &Context,
17761775
md_text: &str,
1777-
links: Vec<(String, String)>,
1776+
links: Vec<RenderedLink>,
17781777
prefix: &str,
17791778
is_hidden: bool,
17801779
) {

‎src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,9 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
582582
let parent_node = if item.is_fake() {
583583
// FIXME: is this correct?
584584
None
585+
// If we're documenting the crate root itself, it has no parent. Use the root instead.
586+
} else if item.def_id.is_top_level_module() {
587+
Some(item.def_id)
585588
} else {
586589
let mut current = item.def_id;
587590
// The immediate parent might not always be a module.
@@ -593,6 +596,12 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
593596
}
594597
current = parent;
595598
} else {
599+
debug!(
600+
"{:?} has no parent (kind={:?}, original was {:?})",
601+
current,
602+
self.cx.tcx.def_kind(current),
603+
item.def_id
604+
);
596605
break None;
597606
}
598607
}
@@ -697,11 +706,12 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
697706
// This is an anchor to an element of the current page, nothing to do in here!
698707
continue;
699708
}
700-
(parts[0].to_owned(), Some(parts[1].to_owned()))
709+
(parts[0], Some(parts[1].to_owned()))
701710
} else {
702-
(parts[0].to_owned(), None)
711+
(parts[0], None)
703712
};
704713
let resolved_self;
714+
let link_text;
705715
let mut path_str;
706716
let disambiguator;
707717
let (mut res, mut fragment) = {
@@ -718,6 +728,12 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
718728
continue;
719729
}
720730

731+
// We stripped `()` and `!` when parsing the disambiguator.
732+
// Add them back to be displayed, but not prefix disambiguators.
733+
link_text = disambiguator
734+
.map(|d| d.display_for(path_str))
735+
.unwrap_or_else(|| path_str.to_owned());
736+
721737
// In order to correctly resolve intra-doc-links we need to
722738
// pick a base AST node to work from. If the documentation for
723739
// this module came from an inner comment (//!) then we anchor
@@ -906,7 +922,12 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
906922
if let Res::PrimTy(_) = res {
907923
match disambiguator {
908924
Some(Disambiguator::Primitive | Disambiguator::Namespace(_)) | None => {
909-
item.attrs.links.push((ori_link, None, fragment))
925+
item.attrs.links.push(ItemLink {
926+
link: ori_link,
927+
link_text: path_str.to_owned(),
928+
did: None,
929+
fragment,
930+
});
910931
}
911932
Some(other) => {
912933
report_mismatch(other, Disambiguator::Primitive);
@@ -957,7 +978,12 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
957978
}
958979
}
959980
let id = register_res(cx, res);
960-
item.attrs.links.push((ori_link, Some(id), fragment));
981+
item.attrs.links.push(ItemLink {
982+
link: ori_link,
983+
link_text,
984+
did: Some(id),
985+
fragment,
986+
});
961987
}
962988
}
963989

@@ -985,6 +1011,18 @@ enum Disambiguator {
9851011
}
9861012

9871013
impl Disambiguator {
1014+
/// The text that should be displayed when the path is rendered as HTML.
1015+
///
1016+
/// NOTE: `path` is not the original link given by the user, but a name suitable for passing to `resolve`.
1017+
fn display_for(&self, path: &str) -> String {
1018+
match self {
1019+
// FIXME: this will have different output if the user had `m!()` originally.
1020+
Self::Kind(DefKind::Macro(MacroKind::Bang)) => format!("{}!", path),
1021+
Self::Kind(DefKind::Fn) => format!("{}()", path),
1022+
_ => path.to_owned(),
1023+
}
1024+
}
1025+
9881026
/// (disambiguator, path_str)
9891027
fn from_str(link: &str) -> Result<(Self, &str), ()> {
9901028
use Disambiguator::{Kind, Namespace as NS, Primitive};
@@ -1037,7 +1075,7 @@ impl Disambiguator {
10371075
}
10381076

10391077
/// Return (description of the change, suggestion)
1040-
fn display_for(self, path_str: &str) -> (&'static str, String) {
1078+
fn suggestion_for(self, path_str: &str) -> (&'static str, String) {
10411079
const PREFIX: &str = "prefix with the item kind";
10421080
const FUNCTION: &str = "add parentheses";
10431081
const MACRO: &str = "add an exclamation mark";
@@ -1292,7 +1330,7 @@ fn suggest_disambiguator(
12921330
sp: Option<rustc_span::Span>,
12931331
link_range: &Option<Range<usize>>,
12941332
) {
1295-
let (action, mut suggestion) = disambiguator.display_for(path_str);
1333+
let (action, mut suggestion) = disambiguator.suggestion_for(path_str);
12961334
let help = format!("to link to the {}, {}", disambiguator.descr(), action);
12971335

12981336
if let Some(sp) = sp {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Checks that only functions with compatible attributes are inlined.
2+
//
3+
// only-x86_64
4+
// needs-sanitizer-address
5+
// compile-flags: -Zsanitizer=address
6+
7+
#![crate_type = "lib"]
8+
#![feature(no_sanitize)]
9+
#![feature(target_feature_11)]
10+
11+
// EMIT_MIR inline_compatibility.inlined_target_feature.Inline.diff
12+
#[target_feature(enable = "sse2")]
13+
pub unsafe fn inlined_target_feature() {
14+
target_feature();
15+
}
16+
17+
// EMIT_MIR inline_compatibility.not_inlined_target_feature.Inline.diff
18+
pub unsafe fn not_inlined_target_feature() {
19+
target_feature();
20+
}
21+
22+
// EMIT_MIR inline_compatibility.inlined_no_sanitize.Inline.diff
23+
#[no_sanitize(address)]
24+
pub unsafe fn inlined_no_sanitize() {
25+
no_sanitize();
26+
}
27+
28+
// EMIT_MIR inline_compatibility.not_inlined_no_sanitize.Inline.diff
29+
pub unsafe fn not_inlined_no_sanitize() {
30+
no_sanitize();
31+
}
32+
33+
#[inline]
34+
#[target_feature(enable = "sse2")]
35+
pub unsafe fn target_feature() {}
36+
37+
#[inline]
38+
#[no_sanitize(address, memory)]
39+
pub unsafe fn no_sanitize() {}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
- // MIR for `inlined_no_sanitize` before Inline
2+
+ // MIR for `inlined_no_sanitize` after Inline
3+
4+
fn inlined_no_sanitize() -> () {
5+
let mut _0: (); // return place in scope 0 at $DIR/inline-compatibility.rs:24:37: 24:37
6+
let _1: (); // in scope 0 at $DIR/inline-compatibility.rs:25:5: 25:18
7+
+ scope 1 {
8+
+ }
9+
10+
bb0: {
11+
StorageLive(_1); // scope 0 at $DIR/inline-compatibility.rs:25:5: 25:18
12+
- _1 = no_sanitize() -> bb1; // scope 0 at $DIR/inline-compatibility.rs:25:5: 25:18
13+
- // mir::Constant
14+
- // + span: $DIR/inline-compatibility.rs:25:5: 25:16
15+
- // + literal: Const { ty: unsafe fn() {no_sanitize}, val: Value(Scalar(<ZST>)) }
16+
- }
17+
-
18+
- bb1: {
19+
+ _1 = const (); // scope 1 at $DIR/inline-compatibility.rs:39:29: 39:31
20+
StorageDead(_1); // scope 0 at $DIR/inline-compatibility.rs:25:18: 25:19
21+
_0 = const (); // scope 0 at $DIR/inline-compatibility.rs:24:37: 26:2
22+
return; // scope 0 at $DIR/inline-compatibility.rs:26:2: 26:2
23+
}
24+
}
25+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
- // MIR for `inlined_target_feature` before Inline
2+
+ // MIR for `inlined_target_feature` after Inline
3+
4+
fn inlined_target_feature() -> () {
5+
let mut _0: (); // return place in scope 0 at $DIR/inline-compatibility.rs:13:40: 13:40
6+
let _1: (); // in scope 0 at $DIR/inline-compatibility.rs:14:5: 14:21
7+
+ scope 1 {
8+
+ }
9+
10+
bb0: {
11+
StorageLive(_1); // scope 0 at $DIR/inline-compatibility.rs:14:5: 14:21
12+
- _1 = target_feature() -> bb1; // scope 0 at $DIR/inline-compatibility.rs:14:5: 14:21
13+
- // mir::Constant
14+
- // + span: $DIR/inline-compatibility.rs:14:5: 14:19
15+
- // + literal: Const { ty: unsafe fn() {target_feature}, val: Value(Scalar(<ZST>)) }
16+
- }
17+
-
18+
- bb1: {
19+
+ _1 = const (); // scope 1 at $DIR/inline-compatibility.rs:35:32: 35:34
20+
StorageDead(_1); // scope 0 at $DIR/inline-compatibility.rs:14:21: 14:22
21+
_0 = const (); // scope 0 at $DIR/inline-compatibility.rs:13:40: 15:2
22+
return; // scope 0 at $DIR/inline-compatibility.rs:15:2: 15:2
23+
}
24+
}
25+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
- // MIR for `not_inlined_no_sanitize` before Inline
2+
+ // MIR for `not_inlined_no_sanitize` after Inline
3+
4+
fn not_inlined_no_sanitize() -> () {
5+
let mut _0: (); // return place in scope 0 at $DIR/inline-compatibility.rs:29:41: 29:41
6+
let _1: (); // in scope 0 at $DIR/inline-compatibility.rs:30:5: 30:18
7+
8+
bb0: {
9+
StorageLive(_1); // scope 0 at $DIR/inline-compatibility.rs:30:5: 30:18
10+
_1 = no_sanitize() -> bb1; // scope 0 at $DIR/inline-compatibility.rs:30:5: 30:18
11+
// mir::Constant
12+
// + span: $DIR/inline-compatibility.rs:30:5: 30:16
13+
// + literal: Const { ty: unsafe fn() {no_sanitize}, val: Value(Scalar(<ZST>)) }
14+
}
15+
16+
bb1: {
17+
StorageDead(_1); // scope 0 at $DIR/inline-compatibility.rs:30:18: 30:19
18+
_0 = const (); // scope 0 at $DIR/inline-compatibility.rs:29:41: 31:2
19+
return; // scope 0 at $DIR/inline-compatibility.rs:31:2: 31:2
20+
}
21+
}
22+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
- // MIR for `not_inlined_target_feature` before Inline
2+
+ // MIR for `not_inlined_target_feature` after Inline
3+
4+
fn not_inlined_target_feature() -> () {
5+
let mut _0: (); // return place in scope 0 at $DIR/inline-compatibility.rs:18:44: 18:44
6+
let _1: (); // in scope 0 at $DIR/inline-compatibility.rs:19:5: 19:21
7+
8+
bb0: {
9+
StorageLive(_1); // scope 0 at $DIR/inline-compatibility.rs:19:5: 19:21
10+
_1 = target_feature() -> bb1; // scope 0 at $DIR/inline-compatibility.rs:19:5: 19:21
11+
// mir::Constant
12+
// + span: $DIR/inline-compatibility.rs:19:5: 19:19
13+
// + literal: Const { ty: unsafe fn() {target_feature}, val: Value(Scalar(<ZST>)) }
14+
}
15+
16+
bb1: {
17+
StorageDead(_1); // scope 0 at $DIR/inline-compatibility.rs:19:21: 19:22
18+
_0 = const (); // scope 0 at $DIR/inline-compatibility.rs:18:44: 20:2
19+
return; // scope 0 at $DIR/inline-compatibility.rs:20:2: 20:2
20+
}
21+
}
22+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![crate_name = "inner"]
2+
3+
/// Documentation, including a link to [std::ptr]
4+
pub fn f() {}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// ignore-tidy-linelength
2+
#![deny(intra_doc_link_resolution_failure)]
3+
// first try backticks
4+
/// Trait: [`trait@Name`], fn: [`fn@Name`], [`Name`][`macro@Name`]
5+
// @has intra_link_disambiguators_removed/struct.AtDisambiguator.html
6+
// @has - '//a[@href="../intra_link_disambiguators_removed/trait.Name.html"][code]' "Name"
7+
// @has - '//a[@href="../intra_link_disambiguators_removed/fn.Name.html"][code]' "Name"
8+
// @has - '//a[@href="../intra_link_disambiguators_removed/macro.Name.html"][code]' "Name"
9+
pub struct AtDisambiguator;
10+
11+
/// fn: [`Name()`], macro: [`Name!`]
12+
// @has intra_link_disambiguators_removed/struct.SymbolDisambiguator.html
13+
// @has - '//a[@href="../intra_link_disambiguators_removed/fn.Name.html"][code]' "Name()"
14+
// @has - '//a[@href="../intra_link_disambiguators_removed/macro.Name.html"][code]' "Name!"
15+
pub struct SymbolDisambiguator;
16+
17+
// Now make sure that backticks aren't added if they weren't already there
18+
/// [fn@Name]
19+
// @has intra_link_disambiguators_removed/trait.Name.html
20+
// @has - '//a[@href="../intra_link_disambiguators_removed/fn.Name.html"]' "Name"
21+
// @!has - '//a[@href="../intra_link_disambiguators_removed/fn.Name.html"][code]' "Name"
22+
23+
// FIXME: this will turn !() into ! alone
24+
/// [Name!()]
25+
// @has - '//a[@href="../intra_link_disambiguators_removed/macro.Name.html"]' "Name!"
26+
pub trait Name {}
27+
28+
#[allow(non_snake_case)]
29+
30+
// Try collapsed reference links
31+
/// [macro@Name][]
32+
// @has intra_link_disambiguators_removed/fn.Name.html
33+
// @has - '//a[@href="../intra_link_disambiguators_removed/macro.Name.html"]' "Name"
34+
35+
// Try links that have the same text as a generated URL
36+
/// Weird URL aligned [../intra_link_disambiguators_removed/macro.Name.html][trait@Name]
37+
// @has - '//a[@href="../intra_link_disambiguators_removed/trait.Name.html"]' "../intra_link_disambiguators_removed/macro.Name.html"
38+
pub fn Name() {}
39+
40+
#[macro_export]
41+
// Rustdoc doesn't currently handle links that have weird interspersing of inline code blocks.
42+
/// [fn@Na`m`e]
43+
// @has intra_link_disambiguators_removed/macro.Name.html
44+
// @has - '//a[@href="../intra_link_disambiguators_removed/fn.Name.html"]' "fn@Name"
45+
46+
// It also doesn't handle any case where the code block isn't the whole link text:
47+
/// [trait@`Name`]
48+
// @has - '//a[@href="../intra_link_disambiguators_removed/trait.Name.html"]' "trait@Name"
49+
macro_rules! Name {
50+
() => ()
51+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// aux-build: intra-link-pub-use.rs
2+
#![deny(broken_intra_doc_links)]
3+
#![crate_name = "outer"]
4+
5+
extern crate inner;
6+
7+
/// [mod@std::env] [g]
8+
9+
// FIXME: This can't be tested because rustdoc doesn't show documentation on pub re-exports.
10+
// Until then, comment out the `htmldocck` test.
11+
// This test still does something; namely check that no incorrect errors are emitted when
12+
// documenting the re-export.
13+
14+
// @has outer/index.html
15+
// @ has - '//a[@href="https://doc.rust-lang.org/nightly/std/env/fn.var.html"]' "std::env"
16+
// @ has - '//a[@href="../outer/fn.f.html"]' "g"
17+
pub use f as g;
18+
19+
// FIXME: same as above
20+
/// [std::env]
21+
extern crate self as _;
22+
23+
// Make sure the documentation is actually correct by documenting an inlined re-export
24+
/// [mod@std::env]
25+
// @has outer/fn.f.html
26+
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/env/index.html"]' "std::env"
27+
pub use inner::f;

‎src/test/ui/mir/issue-76248.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This used to ICE during codegen after MIR inlining of g into f.
2+
// The root cause was a missing fold of length constant in Rvalue::Repeat.
3+
// Regression test for #76248.
4+
//
5+
// build-pass
6+
// compile-flags: -Zmir-opt-level=2
7+
8+
const N: usize = 1;
9+
10+
pub struct Elem<M> {
11+
pub x: [usize; N],
12+
pub m: M,
13+
}
14+
15+
pub fn f() -> Elem<()> {
16+
g(())
17+
}
18+
19+
#[inline]
20+
pub fn g<M>(m: M) -> Elem<M> {
21+
Elem {
22+
x: [0; N],
23+
m,
24+
}
25+
}
26+
27+
pub fn main() {
28+
f();
29+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// build-pass
2+
3+
// Regression test for #72793.
4+
// FIXME: This still shows ICE with `-Zmir-opt-level=2`.
5+
6+
#![feature(type_alias_impl_trait)]
7+
8+
trait T { type Item; }
9+
10+
type Alias<'a> = impl T<Item = &'a ()>;
11+
12+
struct S;
13+
impl<'a> T for &'a S {
14+
type Item = &'a ();
15+
}
16+
17+
fn filter_positive<'a>() -> Alias<'a> {
18+
&S
19+
}
20+
21+
fn with_positive(fun: impl Fn(Alias<'_>)) {
22+
fun(filter_positive());
23+
}
24+
25+
fn main() {
26+
with_positive(|_| ());
27+
}

0 commit comments

Comments
 (0)
Please sign in to comment.