Skip to content

Commit fbf1b1a

Browse files
committed
Auto merge of #85664 - GuillaumeGomez:rollup-o7qgo8c, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - #85361 (Use TargetTriple::from_path in rustdoc) - #85605 (Replace Local::new(1) with CAPTURE_STRUCT_LOCAL) - #85631 (Move keyword primitive css dom) - #85644 (Better English for documenting when to use unimplemented!()) - #85650 (Add some backticks to the `rustc_middle::ty::adjustment::Adjustment` docs) - #85657 (Remove doubled braces in non_exhaustive structs’ documentation text.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents cdbe288 + afec726 commit fbf1b1a

File tree

18 files changed

+104
-57
lines changed

18 files changed

+104
-57
lines changed

compiler/rustc_middle/src/ty/adjustment.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub enum PointerCast {
4747
/// 1. The simplest cases are where a pointer is not adjusted fat vs thin.
4848
/// Here the pointer will be dereferenced N times (where a dereference can
4949
/// happen to raw or borrowed pointers or any smart pointer which implements
50-
/// Deref, including Box<_>). The types of dereferences is given by
50+
/// `Deref`, including `Box<_>`). The types of dereferences is given by
5151
/// `autoderefs`. It can then be auto-referenced zero or one times, indicated
5252
/// by `autoref`, to either a raw or borrowed pointer. In these cases unsize is
5353
/// `false`.
@@ -56,7 +56,7 @@ pub enum PointerCast {
5656
/// with a thin pointer, deref a number of times, unsize the underlying data,
5757
/// then autoref. The 'unsize' phase may change a fixed length array to a
5858
/// dynamically sized one, a concrete object to a trait object, or statically
59-
/// sized struct to a dynamically sized one. E.g., &[i32; 4] -> &[i32] is
59+
/// sized struct to a dynamically sized one. E.g., `&[i32; 4]` -> `&[i32]` is
6060
/// represented by:
6161
///
6262
/// ```
@@ -66,7 +66,7 @@ pub enum PointerCast {
6666
/// ```
6767
///
6868
/// Note that for a struct, the 'deep' unsizing of the struct is not recorded.
69-
/// E.g., `struct Foo<T> { x: T }` we can coerce &Foo<[i32; 4]> to &Foo<[i32]>
69+
/// E.g., `struct Foo<T> { x: T }` we can coerce `&Foo<[i32; 4]>` to `&Foo<[i32]>`
7070
/// The autoderef and -ref are the same as in the above example, but the type
7171
/// stored in `unsize` is `Foo<[i32]>`, we don't store any further detail about
7272
/// the underlying conversions from `[i32; 4]` to `[i32]`.
@@ -75,8 +75,8 @@ pub enum PointerCast {
7575
/// that case, we have the pointer we need coming in, so there are no
7676
/// autoderefs, and no autoref. Instead we just do the `Unsize` transformation.
7777
/// At some point, of course, `Box` should move out of the compiler, in which
78-
/// case this is analogous to transforming a struct. E.g., Box<[i32; 4]> ->
79-
/// Box<[i32]> is an `Adjust::Unsize` with the target `Box<[i32]>`.
78+
/// case this is analogous to transforming a struct. E.g., `Box<[i32; 4]>` ->
79+
/// `Box<[i32]>` is an `Adjust::Unsize` with the target `Box<[i32]>`.
8080
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
8181
pub struct Adjustment<'tcx> {
8282
pub kind: Adjust<'tcx>,

compiler/rustc_middle/src/ty/closure.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::hir::place::{
22
Place as HirPlace, PlaceBase as HirPlaceBase, ProjectionKind as HirProjectionKind,
33
};
4-
use crate::ty;
4+
use crate::{mir, ty};
55

66
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
77
use rustc_hir as hir;
@@ -12,6 +12,10 @@ use super::{Ty, TyCtxt};
1212

1313
use self::BorrowKind::*;
1414

15+
// Captures are represented using fields inside a structure.
16+
// This represents accessing self in the closure structure
17+
pub const CAPTURE_STRUCT_LOCAL: mir::Local = mir::Local::from_u32(1);
18+
1519
#[derive(
1620
Clone,
1721
Copy,

compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ use rustc_errors::{Applicability, DiagnosticBuilder};
44
use rustc_hir as hir;
55
use rustc_hir::def_id::DefId;
66
use rustc_hir::{AsyncGeneratorKind, GeneratorKind};
7-
use rustc_index::vec::Idx;
87
use rustc_middle::mir::{
98
self, AggregateKind, BindingForm, BorrowKind, ClearCrossCrate, ConstraintCategory,
10-
FakeReadCause, Local, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef,
9+
FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef,
1110
ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm,
1211
};
1312
use rustc_middle::ty::{self, suggest_constraining_type_param, Ty, TypeFoldable};
@@ -1274,7 +1273,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12741273
bug!("temporary or return pointer with a name")
12751274
}
12761275
LocalKind::Var => "local variable ",
1277-
LocalKind::Arg if !self.upvars.is_empty() && local == Local::new(1) => {
1276+
LocalKind::Arg
1277+
if !self.upvars.is_empty() && local == ty::CAPTURE_STRUCT_LOCAL =>
1278+
{
12781279
"variable captured by `move` "
12791280
}
12801281
LocalKind::Arg => "function parameter ",

compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use rustc_hir as hir;
22
use rustc_hir::Node;
3-
use rustc_index::vec::Idx;
43
use rustc_middle::hir::map::Map;
54
use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem};
65
use rustc_middle::ty::{self, Ty, TyCtxt};
@@ -115,12 +114,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
115114
}
116115
}
117116
PlaceRef { local: _, projection: [proj_base @ .., ProjectionElem::Deref] } => {
118-
if the_place_err.local == Local::new(1)
117+
if the_place_err.local == ty::CAPTURE_STRUCT_LOCAL
119118
&& proj_base.is_empty()
120119
&& !self.upvars.is_empty()
121120
{
122121
item_msg = format!("`{}`", access_place_desc.unwrap());
123-
debug_assert!(self.body.local_decls[Local::new(1)].ty.is_region_ptr());
122+
debug_assert!(
123+
self.body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty.is_region_ptr()
124+
);
124125
debug_assert!(is_closure_or_generator(
125126
Place::ty_from(
126127
the_place_err.local,
@@ -478,11 +479,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
478479
}
479480
}
480481

481-
PlaceRef {
482-
local,
483-
projection: [ProjectionElem::Deref],
484-
// FIXME document what is this 1 magic number about
485-
} if local == Local::new(1) && !self.upvars.is_empty() => {
482+
PlaceRef { local, projection: [ProjectionElem::Deref] }
483+
if local == ty::CAPTURE_STRUCT_LOCAL && !self.upvars.is_empty() =>
484+
{
486485
self.expected_fn_found_fn_mut_call(&mut err, span, act);
487486
}
488487

compiler/rustc_mir_build/src/build/expr/as_place.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,7 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
209209
match from_builder.base {
210210
PlaceBase::Local(_) => Ok(from_builder),
211211
PlaceBase::Upvar { var_hir_id, closure_def_id, closure_kind } => {
212-
// Captures are represented using fields inside a structure.
213-
// This represents accessing self in the closure structure
214-
let mut upvar_resolved_place_builder = PlaceBuilder::from(Local::new(1));
212+
let mut upvar_resolved_place_builder = PlaceBuilder::from(ty::CAPTURE_STRUCT_LOCAL);
215213
match closure_kind {
216214
ty::ClosureKind::Fn | ty::ClosureKind::FnMut => {
217215
upvar_resolved_place_builder = upvar_resolved_place_builder.deref();

compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
446446
} => {
447447
// Not in a closure
448448
debug_assert!(
449-
local == Local::new(1),
449+
local == ty::CAPTURE_STRUCT_LOCAL,
450450
"Expected local to be Local(1), found {:?}",
451451
local
452452
);

compiler/rustc_mir_build/src/build/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -953,9 +953,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
953953
// the given closure and use the necessary information to create upvar
954954
// debuginfo and to fill `self.upvar_mutbls`.
955955
if hir_typeck_results.closure_min_captures.get(&fn_def_id).is_some() {
956-
let closure_env_arg = Local::new(1);
957956
let mut closure_env_projs = vec![];
958-
let mut closure_ty = self.local_decls[closure_env_arg].ty;
957+
let mut closure_ty = self.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty;
959958
if let ty::Ref(_, ty, _) = closure_ty.kind() {
960959
closure_env_projs.push(ProjectionElem::Deref);
961960
closure_ty = ty;
@@ -1001,7 +1000,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10011000
name,
10021001
source_info: SourceInfo::outermost(tcx_hir.span(var_id)),
10031002
value: VarDebugInfoContents::Place(Place {
1004-
local: closure_env_arg,
1003+
local: ty::CAPTURE_STRUCT_LOCAL,
10051004
projection: tcx.intern_place_elems(&projs),
10061005
}),
10071006
});

compiler/rustc_session/src/config.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,10 @@ fn collect_print_requests(
15071507
prints
15081508
}
15091509

1510-
fn parse_target_triple(matches: &getopts::Matches, error_format: ErrorOutputType) -> TargetTriple {
1510+
pub fn parse_target_triple(
1511+
matches: &getopts::Matches,
1512+
error_format: ErrorOutputType,
1513+
) -> TargetTriple {
15111514
match matches.opt_str("target") {
15121515
Some(target) if target.ends_with(".json") => {
15131516
let path = Path::new(&target);

library/core/src/macros/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ macro_rules! unreachable {
595595
/// Indicates unimplemented code by panicking with a message of "not implemented".
596596
///
597597
/// This allows your code to type-check, which is useful if you are prototyping or
598-
/// implementing a trait that requires multiple methods which you don't plan of using all of.
598+
/// implementing a trait that requires multiple methods which you don't plan to use all of.
599599
///
600600
/// The difference between `unimplemented!` and [`todo!`] is that while `todo!`
601601
/// conveys an intent of implementing the functionality later and the message is "not yet

src/librustdoc/config.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ use std::path::PathBuf;
66
use std::str::FromStr;
77

88
use rustc_data_structures::fx::FxHashMap;
9-
use rustc_session::config::{self, parse_crate_types_from_list, parse_externs, CrateType};
10-
use rustc_session::config::{get_cmd_lint_options, host_triple, nightly_options};
9+
use rustc_session::config::{
10+
self, parse_crate_types_from_list, parse_externs, parse_target_triple, CrateType,
11+
};
12+
use rustc_session::config::{get_cmd_lint_options, nightly_options};
1113
use rustc_session::config::{CodegenOptions, DebuggingOptions, ErrorOutputType, Externs};
1214
use rustc_session::getopts;
1315
use rustc_session::lint::Level;
@@ -562,14 +564,7 @@ impl Options {
562564
}
563565
}
564566

565-
let target =
566-
matches.opt_str("target").map_or(TargetTriple::from_triple(host_triple()), |target| {
567-
if target.ends_with(".json") {
568-
TargetTriple::TargetPath(PathBuf::from(target))
569-
} else {
570-
TargetTriple::TargetTriple(target)
571-
}
572-
});
567+
let target = parse_target_triple(matches, error_format);
573568

574569
let show_coverage = matches.opt_present("show-coverage");
575570

src/librustdoc/html/render/print_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,7 @@ fn document_non_exhaustive(w: &mut Buffer, item: &clean::Item) {
15021502
w.write_str(
15031503
"Non-exhaustive structs could have additional fields added in future. \
15041504
Therefore, non-exhaustive structs cannot be constructed in external crates \
1505-
using the traditional <code>Struct {{ .. }}</code> syntax; cannot be \
1505+
using the traditional <code>Struct { .. }</code> syntax; cannot be \
15061506
matched against without a wildcard <code>..</code>; and \
15071507
struct update syntax will not work.",
15081508
);

src/librustdoc/html/static/rustdoc.css

-10
Original file line numberDiff line numberDiff line change
@@ -796,16 +796,6 @@ a {
796796
display: inline-block;
797797
}
798798

799-
.result-name span.primitive::after {
800-
content: ' (primitive type)';
801-
font-style: italic;
802-
}
803-
804-
.result-name span.keyword::after {
805-
content: ' (keyword)';
806-
font-style: italic;
807-
}
808-
809799
body.blur > :not(#help) {
810800
filter: blur(8px);
811801
-webkit-filter: blur(8px);

src/librustdoc/html/static/search.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -975,26 +975,32 @@ window.initSearch = function(rawSearchIndex) {
975975
output = "<div class=\"search-results " + extraClass + "\">";
976976

977977
array.forEach(function(item) {
978-
var name, type;
979-
980-
name = item.name;
981-
type = itemTypes[item.ty];
982-
983978
if (item.is_alias !== true) {
984979
if (duplicates[item.fullPath]) {
985980
return;
986981
}
987982
duplicates[item.fullPath] = true;
988983
}
984+
985+
var name = item.name;
986+
var type = itemTypes[item.ty];
987+
989988
length += 1;
990989

990+
var extra = "";
991+
if (type === "primitive") {
992+
extra = " <i>(primitive type)</i>";
993+
} else if (type === "keyword") {
994+
extra = " <i>(keyword)</i>";
995+
}
996+
991997
output += "<a class=\"result-" + type + "\" href=\"" + item.href + "\">" +
992998
"<div><div class=\"result-name\">" +
993999
(item.is_alias === true ?
9941000
("<span class=\"alias\"><b>" + item.alias + " </b></span><span " +
9951001
"class=\"grey\"><i>&nbsp;- see&nbsp;</i></span>") : "") +
9961002
item.displayPath + "<span class=\"" + type + "\">" +
997-
name + "</span></div><div class=\"desc\">" +
1003+
name + extra + "</span></div><div class=\"desc\">" +
9981004
"<span>" + item.desc +
9991005
"&nbsp;</span></div></div></a>";
10001006
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
include ../tools.mk
2+
3+
# Test that rustdoc will properly canonicalize the target spec json path just like rustc
4+
5+
OUTPUT_DIR := "$(TMPDIR)/rustdoc-target-spec-json-path"
6+
7+
all:
8+
$(RUSTC) --crate-type lib dummy_core.rs --target target.json
9+
$(RUSTDOC) -o $(OUTPUT_DIR) -L $(TMPDIR) my_crate.rs --target target.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#![feature(no_core)]
2+
#![no_core]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#![feature(no_core)]
2+
#![no_core]
3+
extern crate dummy_core;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"arch": "x86_64",
3+
"cpu": "x86-64",
4+
"crt-static-respected": true,
5+
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
6+
"dynamic-linking": true,
7+
"env": "gnu",
8+
"executables": true,
9+
"has-elf-tls": true,
10+
"has-rpath": true,
11+
"is-builtin": true,
12+
"linker-is-gnu": true,
13+
"llvm-target": "x86_64-unknown-linux-gnu",
14+
"max-atomic-width": 64,
15+
"os": "linux",
16+
"position-independent-executables": true,
17+
"pre-link-args": {
18+
"gcc": [
19+
"-m64"
20+
]
21+
},
22+
"relro-level": "full",
23+
"stack-probes": {
24+
"kind": "inline-or-call",
25+
"min-llvm-version-for-inline": [
26+
11,
27+
0,
28+
1
29+
]
30+
},
31+
"supported-sanitizers": [
32+
"address",
33+
"leak",
34+
"memory",
35+
"thread"
36+
],
37+
"target-family": "unix",
38+
"target-pointer-width": "64"
39+
}

src/test/rustdoc-gui/search-result-keyword.goml

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ wait-for: "#titles"
55
// Note: The two next assert commands could be merged as one but readability would be
66
// less good.
77
//
8-
// Checking that the CSS is displaying " (keyword)"...
9-
assert: (".result-name span.keyword::after", {"content": '" (keyword)"'})
10-
// ... in italic.
11-
assert: (".result-name span.keyword::after", {"font-style": "italic"})
8+
// Checking that the CSS is displaying " (keyword)" in italic.
9+
assert: (".result-name span.keyword > i", "(keyword)")
10+
assert: (".result-name span.keyword", "CookieMonster (keyword)")

0 commit comments

Comments
 (0)