Skip to content

Commit

Permalink
Auto merge of rust-lang#85664 - GuillaumeGomez:rollup-o7qgo8c, r=Guil…
Browse files Browse the repository at this point in the history
…laumeGomez

Rollup of 6 pull requests

Successful merges:

 - rust-lang#85361 (Use TargetTriple::from_path in rustdoc)
 - rust-lang#85605 (Replace Local::new(1) with CAPTURE_STRUCT_LOCAL)
 - rust-lang#85631 (Move keyword primitive css dom)
 - rust-lang#85644 (Better English for documenting when to use unimplemented!())
 - rust-lang#85650 (Add some backticks to the `rustc_middle::ty::adjustment::Adjustment` docs)
 - rust-lang#85657 (Remove doubled braces in non_exhaustive structs’ documentation text.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed May 25, 2021
2 parents cdbe288 + afec726 commit fbf1b1a
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 57 deletions.
10 changes: 5 additions & 5 deletions compiler/rustc_middle/src/ty/adjustment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub enum PointerCast {
/// 1. The simplest cases are where a pointer is not adjusted fat vs thin.
/// Here the pointer will be dereferenced N times (where a dereference can
/// happen to raw or borrowed pointers or any smart pointer which implements
/// Deref, including Box<_>). The types of dereferences is given by
/// `Deref`, including `Box<_>`). The types of dereferences is given by
/// `autoderefs`. It can then be auto-referenced zero or one times, indicated
/// by `autoref`, to either a raw or borrowed pointer. In these cases unsize is
/// `false`.
Expand All @@ -56,7 +56,7 @@ pub enum PointerCast {
/// with a thin pointer, deref a number of times, unsize the underlying data,
/// then autoref. The 'unsize' phase may change a fixed length array to a
/// dynamically sized one, a concrete object to a trait object, or statically
/// sized struct to a dynamically sized one. E.g., &[i32; 4] -> &[i32] is
/// sized struct to a dynamically sized one. E.g., `&[i32; 4]` -> `&[i32]` is
/// represented by:
///
/// ```
Expand All @@ -66,7 +66,7 @@ pub enum PointerCast {
/// ```
///
/// Note that for a struct, the 'deep' unsizing of the struct is not recorded.
/// E.g., `struct Foo<T> { x: T }` we can coerce &Foo<[i32; 4]> to &Foo<[i32]>
/// E.g., `struct Foo<T> { x: T }` we can coerce `&Foo<[i32; 4]>` to `&Foo<[i32]>`
/// The autoderef and -ref are the same as in the above example, but the type
/// stored in `unsize` is `Foo<[i32]>`, we don't store any further detail about
/// the underlying conversions from `[i32; 4]` to `[i32]`.
Expand All @@ -75,8 +75,8 @@ pub enum PointerCast {
/// that case, we have the pointer we need coming in, so there are no
/// autoderefs, and no autoref. Instead we just do the `Unsize` transformation.
/// At some point, of course, `Box` should move out of the compiler, in which
/// case this is analogous to transforming a struct. E.g., Box<[i32; 4]> ->
/// Box<[i32]> is an `Adjust::Unsize` with the target `Box<[i32]>`.
/// case this is analogous to transforming a struct. E.g., `Box<[i32; 4]>` ->
/// `Box<[i32]>` is an `Adjust::Unsize` with the target `Box<[i32]>`.
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
pub struct Adjustment<'tcx> {
pub kind: Adjust<'tcx>,
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_middle/src/ty/closure.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::hir::place::{
Place as HirPlace, PlaceBase as HirPlaceBase, ProjectionKind as HirProjectionKind,
};
use crate::ty;
use crate::{mir, ty};

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

use self::BorrowKind::*;

// Captures are represented using fields inside a structure.
// This represents accessing self in the closure structure
pub const CAPTURE_STRUCT_LOCAL: mir::Local = mir::Local::from_u32(1);

#[derive(
Clone,
Copy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::{AsyncGeneratorKind, GeneratorKind};
use rustc_index::vec::Idx;
use rustc_middle::mir::{
self, AggregateKind, BindingForm, BorrowKind, ClearCrossCrate, ConstraintCategory,
FakeReadCause, Local, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef,
FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef,
ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm,
};
use rustc_middle::ty::{self, suggest_constraining_type_param, Ty, TypeFoldable};
Expand Down Expand Up @@ -1274,7 +1273,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
bug!("temporary or return pointer with a name")
}
LocalKind::Var => "local variable ",
LocalKind::Arg if !self.upvars.is_empty() && local == Local::new(1) => {
LocalKind::Arg
if !self.upvars.is_empty() && local == ty::CAPTURE_STRUCT_LOCAL =>
{
"variable captured by `move` "
}
LocalKind::Arg => "function parameter ",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use rustc_hir as hir;
use rustc_hir::Node;
use rustc_index::vec::Idx;
use rustc_middle::hir::map::Map;
use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem};
use rustc_middle::ty::{self, Ty, TyCtxt};
Expand Down Expand Up @@ -115,12 +114,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}
}
PlaceRef { local: _, projection: [proj_base @ .., ProjectionElem::Deref] } => {
if the_place_err.local == Local::new(1)
if the_place_err.local == ty::CAPTURE_STRUCT_LOCAL
&& proj_base.is_empty()
&& !self.upvars.is_empty()
{
item_msg = format!("`{}`", access_place_desc.unwrap());
debug_assert!(self.body.local_decls[Local::new(1)].ty.is_region_ptr());
debug_assert!(
self.body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty.is_region_ptr()
);
debug_assert!(is_closure_or_generator(
Place::ty_from(
the_place_err.local,
Expand Down Expand Up @@ -478,11 +479,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}
}

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

Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_mir_build/src/build/expr/as_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,7 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
match from_builder.base {
PlaceBase::Local(_) => Ok(from_builder),
PlaceBase::Upvar { var_hir_id, closure_def_id, closure_kind } => {
// Captures are represented using fields inside a structure.
// This represents accessing self in the closure structure
let mut upvar_resolved_place_builder = PlaceBuilder::from(Local::new(1));
let mut upvar_resolved_place_builder = PlaceBuilder::from(ty::CAPTURE_STRUCT_LOCAL);
match closure_kind {
ty::ClosureKind::Fn | ty::ClosureKind::FnMut => {
upvar_resolved_place_builder = upvar_resolved_place_builder.deref();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
} => {
// Not in a closure
debug_assert!(
local == Local::new(1),
local == ty::CAPTURE_STRUCT_LOCAL,
"Expected local to be Local(1), found {:?}",
local
);
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_mir_build/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,9 +953,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// the given closure and use the necessary information to create upvar
// debuginfo and to fill `self.upvar_mutbls`.
if hir_typeck_results.closure_min_captures.get(&fn_def_id).is_some() {
let closure_env_arg = Local::new(1);
let mut closure_env_projs = vec![];
let mut closure_ty = self.local_decls[closure_env_arg].ty;
let mut closure_ty = self.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty;
if let ty::Ref(_, ty, _) = closure_ty.kind() {
closure_env_projs.push(ProjectionElem::Deref);
closure_ty = ty;
Expand Down Expand Up @@ -1001,7 +1000,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
name,
source_info: SourceInfo::outermost(tcx_hir.span(var_id)),
value: VarDebugInfoContents::Place(Place {
local: closure_env_arg,
local: ty::CAPTURE_STRUCT_LOCAL,
projection: tcx.intern_place_elems(&projs),
}),
});
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,10 @@ fn collect_print_requests(
prints
}

fn parse_target_triple(matches: &getopts::Matches, error_format: ErrorOutputType) -> TargetTriple {
pub fn parse_target_triple(
matches: &getopts::Matches,
error_format: ErrorOutputType,
) -> TargetTriple {
match matches.opt_str("target") {
Some(target) if target.ends_with(".json") => {
let path = Path::new(&target);
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ macro_rules! unreachable {
/// Indicates unimplemented code by panicking with a message of "not implemented".
///
/// This allows your code to type-check, which is useful if you are prototyping or
/// implementing a trait that requires multiple methods which you don't plan of using all of.
/// implementing a trait that requires multiple methods which you don't plan to use all of.
///
/// The difference between `unimplemented!` and [`todo!`] is that while `todo!`
/// conveys an intent of implementing the functionality later and the message is "not yet
Expand Down
15 changes: 5 additions & 10 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ use std::path::PathBuf;
use std::str::FromStr;

use rustc_data_structures::fx::FxHashMap;
use rustc_session::config::{self, parse_crate_types_from_list, parse_externs, CrateType};
use rustc_session::config::{get_cmd_lint_options, host_triple, nightly_options};
use rustc_session::config::{
self, parse_crate_types_from_list, parse_externs, parse_target_triple, CrateType,
};
use rustc_session::config::{get_cmd_lint_options, nightly_options};
use rustc_session::config::{CodegenOptions, DebuggingOptions, ErrorOutputType, Externs};
use rustc_session::getopts;
use rustc_session::lint::Level;
Expand Down Expand Up @@ -562,14 +564,7 @@ impl Options {
}
}

let target =
matches.opt_str("target").map_or(TargetTriple::from_triple(host_triple()), |target| {
if target.ends_with(".json") {
TargetTriple::TargetPath(PathBuf::from(target))
} else {
TargetTriple::TargetTriple(target)
}
});
let target = parse_target_triple(matches, error_format);

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

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ fn document_non_exhaustive(w: &mut Buffer, item: &clean::Item) {
w.write_str(
"Non-exhaustive structs could have additional fields added in future. \
Therefore, non-exhaustive structs cannot be constructed in external crates \
using the traditional <code>Struct {{ .. }}</code> syntax; cannot be \
using the traditional <code>Struct { .. }</code> syntax; cannot be \
matched against without a wildcard <code>..</code>; and \
struct update syntax will not work.",
);
Expand Down
10 changes: 0 additions & 10 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -796,16 +796,6 @@ a {
display: inline-block;
}

.result-name span.primitive::after {
content: ' (primitive type)';
font-style: italic;
}

.result-name span.keyword::after {
content: ' (keyword)';
font-style: italic;
}

body.blur > :not(#help) {
filter: blur(8px);
-webkit-filter: blur(8px);
Expand Down
18 changes: 12 additions & 6 deletions src/librustdoc/html/static/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -975,26 +975,32 @@ window.initSearch = function(rawSearchIndex) {
output = "<div class=\"search-results " + extraClass + "\">";

array.forEach(function(item) {
var name, type;

name = item.name;
type = itemTypes[item.ty];

if (item.is_alias !== true) {
if (duplicates[item.fullPath]) {
return;
}
duplicates[item.fullPath] = true;
}

var name = item.name;
var type = itemTypes[item.ty];

length += 1;

var extra = "";
if (type === "primitive") {
extra = " <i>(primitive type)</i>";
} else if (type === "keyword") {
extra = " <i>(keyword)</i>";
}

output += "<a class=\"result-" + type + "\" href=\"" + item.href + "\">" +
"<div><div class=\"result-name\">" +
(item.is_alias === true ?
("<span class=\"alias\"><b>" + item.alias + " </b></span><span " +
"class=\"grey\"><i>&nbsp;- see&nbsp;</i></span>") : "") +
item.displayPath + "<span class=\"" + type + "\">" +
name + "</span></div><div class=\"desc\">" +
name + extra + "</span></div><div class=\"desc\">" +
"<span>" + item.desc +
"&nbsp;</span></div></div></a>";
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include ../tools.mk

# Test that rustdoc will properly canonicalize the target spec json path just like rustc

OUTPUT_DIR := "$(TMPDIR)/rustdoc-target-spec-json-path"

all:
$(RUSTC) --crate-type lib dummy_core.rs --target target.json
$(RUSTDOC) -o $(OUTPUT_DIR) -L $(TMPDIR) my_crate.rs --target target.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#![feature(no_core)]
#![no_core]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#![feature(no_core)]
#![no_core]
extern crate dummy_core;
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"arch": "x86_64",
"cpu": "x86-64",
"crt-static-respected": true,
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
"dynamic-linking": true,
"env": "gnu",
"executables": true,
"has-elf-tls": true,
"has-rpath": true,
"is-builtin": true,
"linker-is-gnu": true,
"llvm-target": "x86_64-unknown-linux-gnu",
"max-atomic-width": 64,
"os": "linux",
"position-independent-executables": true,
"pre-link-args": {
"gcc": [
"-m64"
]
},
"relro-level": "full",
"stack-probes": {
"kind": "inline-or-call",
"min-llvm-version-for-inline": [
11,
0,
1
]
},
"supported-sanitizers": [
"address",
"leak",
"memory",
"thread"
],
"target-family": "unix",
"target-pointer-width": "64"
}
7 changes: 3 additions & 4 deletions src/test/rustdoc-gui/search-result-keyword.goml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ wait-for: "#titles"
// Note: The two next assert commands could be merged as one but readability would be
// less good.
//
// Checking that the CSS is displaying " (keyword)"...
assert: (".result-name span.keyword::after", {"content": '" (keyword)"'})
// ... in italic.
assert: (".result-name span.keyword::after", {"font-style": "italic"})
// Checking that the CSS is displaying " (keyword)" in italic.
assert: (".result-name span.keyword > i", "(keyword)")
assert: (".result-name span.keyword", "CookieMonster (keyword)")

0 comments on commit fbf1b1a

Please sign in to comment.