Skip to content

Commit 839d99c

Browse files
committed
Auto merge of #53884 - kennytm:rollup, r=kennytm
Rollup of 9 pull requests Successful merges: - #53076 (set cfg(rustdoc) when rustdoc is running on a crate) - #53622 (cleanup: Add main functions to some UI tests) - #53769 (Also link Clippy repo in the CONTRIBUTING.md file) - #53774 (Add rust-gdbgui script.) - #53781 (bench: libcore: fix build failure of any.rs benchmark (use "dyn Any")) - #53782 (Make Arc cloning mechanics clearer in module docs) - #53790 (Add regression test for issue #52060) - #53801 (Prevent duplicated impl on foreign types) - #53850 (Nuke the `const_to_allocation` query)
2 parents fea32f1 + d0f8cf3 commit 839d99c

File tree

75 files changed

+282
-241
lines changed

Some content is hidden

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

75 files changed

+282
-241
lines changed

CONTRIBUTING.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ before the PR is merged.
405405
[breaking-tools-built-with-the-compiler]: #breaking-tools-built-with-the-compiler
406406

407407
Rust's build system builds a number of tools that make use of the
408-
internals of the compiler. This includes clippy,
408+
internals of the compiler. This includes
409+
[Clippy](https://github.com/rust-lang-nursery/rust-clippy),
409410
[RLS](https://github.com/rust-lang-nursery/rls) and
410411
[rustfmt](https://github.com/rust-lang-nursery/rustfmt). If these tools
411412
break because of your changes, you may run into a sort of "chicken and egg"

src/bootstrap/bin/rustdoc.rs

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ fn main() {
3737
let mut dylib_path = bootstrap::util::dylib_path();
3838
dylib_path.insert(0, PathBuf::from(libdir.clone()));
3939

40+
//FIXME(misdreavus): once stdsimd uses cfg(rustdoc) instead of cfg(dox), remove the `--cfg dox`
41+
//arguments here
4042
let mut cmd = Command::new(rustdoc);
4143
cmd.args(&args)
4244
.arg("--cfg")

src/doc/rustdoc/src/unstable-features.md

+9-11
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,25 @@ The `#[doc(cfg(...))]` attribute has another effect: When Rustdoc renders docume
106106
item, it will be accompanied by a banner explaining that the item is only available on certain
107107
platforms.
108108

109-
As mentioned earlier, getting the items to Rustdoc requires some extra preparation. The standard
110-
library adds a `--cfg dox` flag to every Rustdoc command, but the same thing can be accomplished by
111-
adding a feature to your Cargo.toml and adding `--feature dox` (or whatever you choose to name the
112-
feature) to your `cargo doc` calls.
109+
For Rustdoc to document an item, it needs to see it, regardless of what platform it's currently
110+
running on. To aid this, Rustdoc sets the flag `#[cfg(rustdoc)]` when running on your crate.
111+
Combining this with the target platform of a given item allows it to appear when building your crate
112+
normally on that platform, as well as when building documentation anywhere.
113113

114-
Either way, once you create an environment for the documentation, you can start to augment your
115-
`#[cfg]` attributes to allow both the target platform *and* the documentation configuration to leave
116-
the item in. For example, `#[cfg(any(windows, feature = "dox"))]` will preserve the item either on
117-
Windows or during the documentation process. Then, adding a new attribute `#[doc(cfg(windows))]`
118-
will tell Rustdoc that the item is supposed to be used on Windows. For example:
114+
For example, `#[cfg(any(windows, rustdoc))]` will preserve the item either on Windows or during the
115+
documentation process. Then, adding a new attribute `#[doc(cfg(windows))]` will tell Rustdoc that
116+
the item is supposed to be used on Windows. For example:
119117

120118
```rust
121119
#![feature(doc_cfg)]
122120

123121
/// Token struct that can only be used on Windows.
124-
#[cfg(any(windows, feature = "dox"))]
122+
#[cfg(any(windows, rustdoc))]
125123
#[doc(cfg(windows))]
126124
pub struct WindowsToken;
127125

128126
/// Token struct that can only be used on Unix.
129-
#[cfg(any(unix, feature = "dox"))]
127+
#[cfg(any(unix, rustdoc))]
130128
#[doc(cfg(unix))]
131129
pub struct UnixToken;
132130
```

src/doc/unstable-book/src/language-features/doc-cfg.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ This attribute has two effects:
1212

1313
2. The item's doc-tests will only run on the specific platform.
1414

15+
In addition to allowing the use of the `#[doc(cfg)]` attribute, this feature enables the use of a
16+
special conditional compilation flag, `#[cfg(rustdoc)]`, set whenever building documentation on your
17+
crate.
18+
1519
This feature was introduced as part of PR [#43348] to allow the platform-specific parts of the
1620
standard library be documented.
1721

1822
```rust
1923
#![feature(doc_cfg)]
2024

21-
#[cfg(any(windows, feature = "documentation"))]
25+
#[cfg(any(windows, rustdoc))]
2226
#[doc(cfg(windows))]
2327
/// The application's icon in the notification area (a.k.a. system tray).
2428
///
@@ -39,4 +43,4 @@ pub struct Icon {
3943
```
4044

4145
[#43781]: https://github.com/rust-lang/rust/issues/43781
42-
[#43348]: https://github.com/rust-lang/rust/issues/43348
46+
[#43348]: https://github.com/rust-lang/rust/issues/43348

src/etc/rust-gdbgui

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/sh
2+
# Copyright 2014 The Rust Project Developers. See the COPYRIGHT
3+
# file at the top-level directory of this distribution and at
4+
# http://rust-lang.org/COPYRIGHT.
5+
#
6+
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
7+
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8+
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
9+
# option. This file may not be copied, modified, or distributed
10+
# except according to those terms.
11+
12+
# Exit if anything fails
13+
set -e
14+
15+
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ] || [ "$1" = "--help" ]; then
16+
echo "
17+
rust-gdbgui
18+
===========
19+
gdbgui - https://gdbgui.com - is a graphical front-end to GDB
20+
that runs in a browser. This script invokes gdbgui with the Rust
21+
pretty printers loaded.
22+
23+
Simple usage : rust-gdbgui target/debug/myprog
24+
With arguments: rust-gdbgui 'target/debug/myprog arg1 arg2...'
25+
(note the quotes)
26+
27+
28+
Hints
29+
=====
30+
gdbgui won't be able to find the rust 'main' method automatically, so
31+
in its options make sure to disable the 'Add breakpoint to main after
32+
loading executable' setting to avoid a 'File not found: main' warning
33+
on startup.
34+
35+
Instead, type 'main' into gdbgui's file browser and you should get
36+
auto-completion on the filename. Just pick 'main.rs', add a breakpoint
37+
by clicking in the line number gutter, and type 'r' or hit the Restart
38+
icon to start your program running.
39+
"
40+
exit 0
41+
fi
42+
43+
# Find out where the pretty printer Python module is
44+
RUSTC_SYSROOT=`rustc --print=sysroot`
45+
GDB_PYTHON_MODULE_DIRECTORY="$RUSTC_SYSROOT/lib/rustlib/etc"
46+
47+
# Set the environment variable `RUST_GDB` to overwrite the call to a
48+
# different/specific command (defaults to `gdb`).
49+
RUST_GDB="${RUST_GDB:-gdb}"
50+
51+
# Set the environment variable `RUST_GDBGUI` to overwrite the call to a
52+
# different/specific command (defaults to `gdbgui`).
53+
RUST_GDBGUI="${RUST_GDBGUI:-gdbgui}"
54+
55+
# These arguments get passed through to GDB and make it load the
56+
# Rust pretty printers.
57+
GDB_ARGS="--directory=\"$GDB_PYTHON_MODULE_DIRECTORY\" -iex \"add-auto-load-safe-path $GDB_PYTHON_MODULE_DIRECTORY\""
58+
59+
# Finally we execute gdbgui.
60+
PYTHONPATH="$PYTHONPATH:$GDB_PYTHON_MODULE_DIRECTORY" \
61+
exec ${RUST_GDBGUI} \
62+
--gdb ${RUST_GDB} \
63+
--gdb-args "${GDB_ARGS}" \
64+
"${@}"
65+

src/liballoc/sync.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
4949
///
5050
/// The type `Arc<T>` provides shared ownership of a value of type `T`,
5151
/// allocated in the heap. Invoking [`clone`][clone] on `Arc` produces
52-
/// a new pointer to the same value in the heap. When the last `Arc`
53-
/// pointer to a given value is destroyed, the pointed-to value is
54-
/// also destroyed.
52+
/// a new `Arc` instance, which points to the same value on the heap as the
53+
/// source `Arc`, while increasing a reference count. When the last `Arc`
54+
/// pointer to a given value is destroyed, the pointed-to value is also
55+
/// destroyed.
5556
///
5657
/// Shared references in Rust disallow mutation by default, and `Arc` is no
5758
/// exception: you cannot generally obtain a mutable reference to something
@@ -107,7 +108,7 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
107108
/// // The two syntaxes below are equivalent.
108109
/// let a = foo.clone();
109110
/// let b = Arc::clone(&foo);
110-
/// // a and b both point to the same memory location as foo.
111+
/// // a, b, and foo are all Arcs that point to the same memory location
111112
/// ```
112113
///
113114
/// The [`Arc::clone(&from)`] syntax is the most idiomatic because it conveys more explicitly

src/libcore/benches/any.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use test::{Bencher, black_box};
1515
fn bench_downcast_ref(b: &mut Bencher) {
1616
b.iter(|| {
1717
let mut x = 0;
18-
let mut y = &mut x as &mut Any;
18+
let mut y = &mut x as &mut dyn Any;
1919
black_box(&mut y);
2020
black_box(y.downcast_ref::<isize>() == Some(&0));
2121
});

src/libcore/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ macro_rules! unimplemented {
541541
/// into libsyntax itself.
542542
///
543543
/// For more information, see documentation for `std`'s macros.
544-
#[cfg(dox)]
544+
#[cfg(rustdoc)]
545545
mod builtin {
546546

547547
/// Unconditionally causes compilation to fail with the given error message when encountered.

src/librustc/dep_graph/dep_node.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ use traits::query::{
7575
CanonicalPredicateGoal, CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpNormalizeGoal,
7676
};
7777
use ty::{TyCtxt, FnSig, Instance, InstanceDef,
78-
ParamEnv, ParamEnvAnd, Predicate, PolyFnSig, PolyTraitRef, Ty, self};
78+
ParamEnv, ParamEnvAnd, Predicate, PolyFnSig, PolyTraitRef, Ty};
7979
use ty::subst::Substs;
8080

8181
// erase!() just makes tokens go away. It's used to specify which macro argument
@@ -632,7 +632,6 @@ define_dep_nodes!( <'tcx>
632632
// queries). Making them anonymous avoids hashing the result, which
633633
// may save a bit of time.
634634
[anon] EraseRegionsTy { ty: Ty<'tcx> },
635-
[anon] ConstToAllocation { val: &'tcx ty::Const<'tcx> },
636635

637636
[input] Freevars(DefId),
638637
[input] MaybeUnusedTraitImport(DefId),

src/librustc/ty/query/config.rs

-6
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::super_predicates_of<'tcx> {
198198
}
199199
}
200200

201-
impl<'tcx> QueryDescription<'tcx> for queries::const_to_allocation<'tcx> {
202-
fn describe(_tcx: TyCtxt, val: &'tcx ty::Const<'tcx>) -> String {
203-
format!("converting constant `{:?}` to an allocation", val)
204-
}
205-
}
206-
207201
impl<'tcx> QueryDescription<'tcx> for queries::erase_regions_ty<'tcx> {
208202
fn describe(_tcx: TyCtxt, ty: Ty<'tcx>) -> String {
209203
format!("erasing regions from `{:?}`", ty)

src/librustc/ty/query/mod.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use middle::exported_symbols::{SymbolExportLevel, ExportedSymbol};
3030
use mir::interpret::ConstEvalResult;
3131
use mir::mono::{CodegenUnit, Stats};
3232
use mir;
33-
use mir::interpret::{GlobalId, Allocation};
33+
use mir::interpret::GlobalId;
3434
use session::{CompileResult, CrateDisambiguator};
3535
use session::config::OutputFilenames;
3636
use traits::{self, Vtable};
@@ -286,11 +286,6 @@ define_queries! { <'tcx>
286286
/// other items (such as enum variant explicit discriminants).
287287
[] fn const_eval: const_eval_dep_node(ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
288288
-> ConstEvalResult<'tcx>,
289-
290-
/// Converts a constant value to a constant allocation
291-
[] fn const_to_allocation: const_to_allocation(
292-
&'tcx ty::Const<'tcx>
293-
) -> &'tcx Allocation,
294289
},
295290

296291
TypeChecking {
@@ -706,12 +701,6 @@ fn erase_regions_ty<'tcx>(ty: Ty<'tcx>) -> DepConstructor<'tcx> {
706701
DepConstructor::EraseRegionsTy { ty }
707702
}
708703

709-
fn const_to_allocation<'tcx>(
710-
val: &'tcx ty::Const<'tcx>,
711-
) -> DepConstructor<'tcx> {
712-
DepConstructor::ConstToAllocation { val }
713-
}
714-
715704
fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
716705
DepConstructor::TypeParamPredicates {
717706
item_id,

src/librustc/ty/query/plumbing.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,6 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
10621062
DepKind::FulfillObligation |
10631063
DepKind::VtableMethods |
10641064
DepKind::EraseRegionsTy |
1065-
DepKind::ConstToAllocation |
10661065
DepKind::NormalizeProjectionTy |
10671066
DepKind::NormalizeTyAfterErasingRegions |
10681067
DepKind::ImpliedOutlivesBounds |

src/librustc_mir/interpret/memory.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::ptr;
2222

2323
use rustc::ty::{self, Instance, query::TyCtxtAt};
2424
use rustc::ty::layout::{self, Align, TargetDataLayout, Size, HasDataLayout};
25-
use rustc::mir::interpret::{Pointer, AllocId, Allocation, ScalarMaybeUndef, GlobalId,
25+
use rustc::mir::interpret::{Pointer, AllocId, Allocation, ConstValue, ScalarMaybeUndef, GlobalId,
2626
EvalResult, Scalar, EvalErrorKind, AllocType, PointerArithmetic,
2727
truncate};
2828
pub use rustc::mir::interpret::{write_target_uint, read_target_uint};
@@ -340,9 +340,12 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
340340
// no need to report anything, the const_eval call takes care of that for statics
341341
assert!(tcx.is_static(def_id).is_some());
342342
EvalErrorKind::ReferencedConstant(err).into()
343-
}).map(|val| {
344-
// FIXME We got our static (will be a ByRef), now we make a *copy*?!?
345-
tcx.const_to_allocation(val)
343+
}).map(|const_val| {
344+
if let ConstValue::ByRef(_, allocation, _) = const_val.val {
345+
allocation
346+
} else {
347+
bug!("Matching on non-ByRef static")
348+
}
346349
})
347350
}
348351

src/librustc_mir/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ pub fn provide(providers: &mut Providers) {
9292
shim::provide(providers);
9393
transform::provide(providers);
9494
providers.const_eval = interpret::const_eval_provider;
95-
providers.const_to_allocation = interpret::const_to_allocation_provider;
9695
providers.check_match = hair::pattern::check_match;
9796
}
9897

src/librustc_typeck/check/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ use rustc::infer::{self, InferCtxt, InferOk, RegionVariableOrigin};
9494
use rustc::infer::anon_types::AnonTypeDecl;
9595
use rustc::infer::type_variable::{TypeVariableOrigin};
9696
use rustc::middle::region;
97-
use rustc::mir::interpret::{GlobalId};
97+
use rustc::mir::interpret::{ConstValue, GlobalId};
9898
use rustc::ty::subst::{CanonicalSubsts, UnpackedKind, Subst, Substs};
9999
use rustc::traits::{self, ObligationCause, ObligationCauseCode, TraitEngine};
100100
use rustc::ty::{self, Ty, TyCtxt, GenericParamDefKind, Visibility, ToPredicate, RegionKind};
@@ -1375,7 +1375,11 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt, id: DefId, span: Span) {
13751375
};
13761376
let param_env = ty::ParamEnv::reveal_all();
13771377
if let Ok(static_) = tcx.const_eval(param_env.and(cid)) {
1378-
let alloc = tcx.const_to_allocation(static_);
1378+
let alloc = if let ConstValue::ByRef(_, allocation, _) = static_.val {
1379+
allocation
1380+
} else {
1381+
bug!("Matching on non-ByRef static")
1382+
};
13791383
if alloc.relocations.len() != 0 {
13801384
let msg = "statics with a custom `#[link_section]` must be a \
13811385
simple list of bytes on the wasm target with no \

src/librustdoc/html/render.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -2956,12 +2956,16 @@ fn item_trait(
29562956
</h2>
29572957
")?;
29582958

2959+
let mut foreign_cache = FxHashSet();
29592960
for implementor in foreign {
2960-
let assoc_link = AssocItemLink::GotoSource(
2961-
implementor.impl_item.def_id, &implementor.inner_impl().provided_trait_methods
2962-
);
2963-
render_impl(w, cx, &implementor, assoc_link,
2964-
RenderMode::Normal, implementor.impl_item.stable_since(), false)?;
2961+
if foreign_cache.insert(implementor.inner_impl().to_string()) {
2962+
let assoc_link = AssocItemLink::GotoSource(
2963+
implementor.impl_item.def_id,
2964+
&implementor.inner_impl().provided_trait_methods
2965+
);
2966+
render_impl(w, cx, &implementor, assoc_link,
2967+
RenderMode::Normal, implementor.impl_item.stable_since(), false)?;
2968+
}
29652969
}
29662970
}
29672971

src/librustdoc/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,8 @@ fn main_args(args: &[String]) -> isize {
477477

478478
let output = matches.opt_str("o").map(|s| PathBuf::from(&s));
479479
let css_file_extension = matches.opt_str("e").map(|s| PathBuf::from(&s));
480-
let cfgs = matches.opt_strs("cfg");
480+
let mut cfgs = matches.opt_strs("cfg");
481+
cfgs.push("rustdoc".to_string());
481482

482483
if let Some(ref p) = css_file_extension {
483484
if !p.is_file() {
@@ -671,7 +672,8 @@ where R: 'static + Send,
671672
for s in &matches.opt_strs("L") {
672673
paths.add_path(s, ErrorOutputType::default());
673674
}
674-
let cfgs = matches.opt_strs("cfg");
675+
let mut cfgs = matches.opt_strs("cfg");
676+
cfgs.push("rustdoc".to_string());
675677
let triple = matches.opt_str("target").map(|target| {
676678
if target.ends_with(".json") {
677679
TargetTriple::TargetPath(PathBuf::from(target))

src/libstd/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ macro_rules! assert_approx_eq {
309309
/// These macros do not have any corresponding definition with a `macro_rules!`
310310
/// macro, but are documented here. Their implementations can be found hardcoded
311311
/// into libsyntax itself.
312-
#[cfg(dox)]
312+
#[cfg(rustdoc)]
313313
mod builtin {
314314

315315
/// Unconditionally causes compilation to fail with the given error message when encountered.

src/libstd/os/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#![allow(missing_docs, nonstandard_style, missing_debug_implementations)]
1515

1616
cfg_if! {
17-
if #[cfg(dox)] {
17+
if #[cfg(rustdoc)] {
1818

1919
// When documenting libstd we want to show unix/windows/linux modules as
2020
// these are the "main modules" that are used across platforms. This

src/libstd/sys/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ cfg_if! {
5757
// then later used in the `std::os` module when documenting, for example,
5858
// Windows when we're compiling for Linux.
5959

60-
#[cfg(dox)]
60+
#[cfg(rustdoc)]
6161
cfg_if! {
6262
if #[cfg(any(unix, target_os = "redox"))] {
6363
// On unix we'll document what's already available
@@ -77,7 +77,7 @@ cfg_if! {
7777
}
7878
}
7979

80-
#[cfg(dox)]
80+
#[cfg(rustdoc)]
8181
cfg_if! {
8282
if #[cfg(windows)] {
8383
// On windows we'll just be documenting what's already available

0 commit comments

Comments
 (0)