Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit fbf1b1a

Browse files
committed
Auto merge of rust-lang#85664 - GuillaumeGomez:rollup-o7qgo8c, r=GuillaumeGomez
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
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 7 additions & 8 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 10 deletions
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

0 commit comments

Comments
 (0)