Skip to content

Commit 15d1f81

Browse files
committed
Auto merge of rust-lang#80253 - Dylan-DPC:rollup-bkmn74z, r=Dylan-DPC
Rollup of 11 pull requests Successful merges: - rust-lang#80159 (Add array search aliases) - rust-lang#80166 (Edit rustc_middle docs) - rust-lang#80170 (Fix ICE when lookup method in trait for type that have bound vars) - rust-lang#80171 (Edit rustc_middle::ty::TyKind docs) - rust-lang#80199 (also const-check FakeRead) - rust-lang#80211 (Handle desugaring in impl trait bound suggestion) - rust-lang#80236 (Use pointer type in AtomicPtr::swap implementation) - rust-lang#80239 (Update Clippy) - rust-lang#80240 (make sure installer only creates directories in DESTDIR) - rust-lang#80244 (Cleanup markdown span handling) - rust-lang#80250 (Minor cleanups in LateResolver) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents c813545 + 0947e05 commit 15d1f81

File tree

140 files changed

+3573
-1234
lines changed

Some content is hidden

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

140 files changed

+3573
-1234
lines changed

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,19 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
524524
};
525525

526526
let ty = substs.type_at(0);
527-
if int_type_width_signed(ty, bx.tcx()).is_some() {
528-
bx.atomic_rmw(atom_op, args[0].immediate(), args[1].immediate(), order)
527+
if int_type_width_signed(ty, bx.tcx()).is_some()
528+
|| (ty.is_unsafe_ptr() && op == "xchg")
529+
{
530+
let mut ptr = args[0].immediate();
531+
let mut val = args[1].immediate();
532+
if ty.is_unsafe_ptr() {
533+
// Some platforms do not support atomic operations on pointers,
534+
// so we cast to integer first.
535+
let ptr_llty = bx.type_ptr_to(bx.type_isize());
536+
ptr = bx.pointercast(ptr, ptr_llty);
537+
val = bx.ptrtoint(val, bx.type_isize());
538+
}
539+
bx.atomic_rmw(atom_op, ptr, val, order)
529540
} else {
530541
return invalid_monomorphization(ty);
531542
}

compiler/rustc_middle/src/hir/place.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ use rustc_target::abi::VariantIdx;
1717
HashStable
1818
)]
1919
pub enum PlaceBase {
20-
/// A temporary variable
20+
/// A temporary variable.
2121
Rvalue,
22-
/// A named `static` item
22+
/// A named `static` item.
2323
StaticItem,
24-
/// A named local variable
24+
/// A named local variable.
2525
Local(HirId),
26-
/// An upvar referenced by closure env
26+
/// An upvar referenced by closure env.
2727
Upvar(ty::UpvarId),
2828
}
2929

@@ -40,7 +40,7 @@ pub enum PlaceBase {
4040
HashStable
4141
)]
4242
pub enum ProjectionKind {
43-
/// A dereference of a pointer, reference or `Box<T>` of the given type
43+
/// A dereference of a pointer, reference or `Box<T>` of the given type.
4444
Deref,
4545

4646
/// `B.F` where `B` is the base expression and `F` is
@@ -71,16 +71,16 @@ pub enum ProjectionKind {
7171
HashStable
7272
)]
7373
pub struct Projection<'tcx> {
74-
/// Type after the projection is being applied.
74+
/// Type after the projection is applied.
7575
pub ty: Ty<'tcx>,
7676

77-
/// Defines the type of access
77+
/// Defines the kind of access made by the projection.
7878
pub kind: ProjectionKind,
7979
}
8080

8181
/// A `Place` represents how a value is located in memory.
8282
///
83-
/// This is an HIR version of `mir::Place`
83+
/// This is an HIR version of [`rustc_middle::mir::Place`].
8484
#[derive(Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, TypeFoldable, HashStable)]
8585
pub struct Place<'tcx> {
8686
/// The type of the `PlaceBase`
@@ -93,13 +93,13 @@ pub struct Place<'tcx> {
9393

9494
/// A `PlaceWithHirId` represents how a value is located in memory.
9595
///
96-
/// This is an HIR version of `mir::Place`
96+
/// This is an HIR version of [`rustc_middle::mir::Place`].
9797
#[derive(Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, TypeFoldable, HashStable)]
9898
pub struct PlaceWithHirId<'tcx> {
9999
/// `HirId` of the expression or pattern producing this value.
100100
pub hir_id: HirId,
101101

102-
/// Information about the `Place`
102+
/// Information about the `Place`.
103103
pub place: Place<'tcx>,
104104
}
105105

compiler/rustc_middle/src/ty/sty.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ impl BoundRegionKind {
8888
}
8989
}
9090

91+
/// Defines the kinds of types.
92+
///
9193
/// N.B., if you change this, you'll probably want to change the corresponding
9294
/// AST structure in `librustc_ast/ast.rs` as well.
9395
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable, Debug)]
@@ -110,7 +112,7 @@ pub enum TyKind<'tcx> {
110112
/// A primitive floating-point type. For example, `f64`.
111113
Float(ast::FloatTy),
112114

113-
/// Structures, enumerations and unions.
115+
/// Algebraic data types (ADT). For example: structures, enumerations and unions.
114116
///
115117
/// InternalSubsts here, possibly against intuition, *may* contain `Param`s.
116118
/// That is, even after substitution it is possible that there are type
@@ -170,11 +172,11 @@ pub enum TyKind<'tcx> {
170172
/// `|a| yield a`.
171173
Generator(DefId, SubstsRef<'tcx>, hir::Movability),
172174

173-
/// A type representin the types stored inside a generator.
175+
/// A type representing the types stored inside a generator.
174176
/// This should only appear in GeneratorInteriors.
175177
GeneratorWitness(Binder<&'tcx List<Ty<'tcx>>>),
176178

177-
/// The never type `!`
179+
/// The never type `!`.
178180
Never,
179181

180182
/// A tuple type. For example, `(i32, bool)`.

compiler/rustc_mir/src/transform/check_consts/validation.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -722,17 +722,16 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
722722
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
723723
trace!("visit_statement: statement={:?} location={:?}", statement, location);
724724

725-
match statement.kind {
726-
StatementKind::Assign(..) | StatementKind::SetDiscriminant { .. } => {
727-
self.super_statement(statement, location);
728-
}
725+
self.super_statement(statement, location);
729726

727+
match statement.kind {
730728
StatementKind::LlvmInlineAsm { .. } => {
731-
self.super_statement(statement, location);
732729
self.check_op(ops::InlineAsm);
733730
}
734731

735-
StatementKind::FakeRead(..)
732+
StatementKind::Assign(..)
733+
| StatementKind::SetDiscriminant { .. }
734+
| StatementKind::FakeRead(..)
736735
| StatementKind::StorageLive(_)
737736
| StatementKind::StorageDead(_)
738737
| StatementKind::Retag { .. }

compiler/rustc_resolve/src/late.rs

+29-36
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc_span::Span;
2929
use smallvec::{smallvec, SmallVec};
3030

3131
use rustc_span::source_map::{respan, Spanned};
32-
use std::collections::BTreeSet;
32+
use std::collections::{hash_map::Entry, BTreeSet};
3333
use std::mem::{replace, take};
3434
use tracing::debug;
3535

@@ -953,8 +953,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
953953
});
954954
};
955955

956-
for item in trait_items {
957-
this.with_trait_items(trait_items, |this| {
956+
this.with_trait_items(trait_items, |this| {
957+
for item in trait_items {
958958
match &item.kind {
959959
AssocItemKind::Const(_, ty, default) => {
960960
this.visit_ty(ty);
@@ -983,8 +983,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
983983
panic!("unexpanded macro in resolve!")
984984
}
985985
};
986-
});
987-
}
986+
}
987+
});
988988
});
989989
});
990990
}
@@ -1060,36 +1060,29 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
10601060
continue;
10611061
}
10621062

1063-
let def_kind = match param.kind {
1064-
GenericParamKind::Type { .. } => DefKind::TyParam,
1065-
GenericParamKind::Const { .. } => DefKind::ConstParam,
1066-
_ => unreachable!(),
1067-
};
1068-
10691063
let ident = param.ident.normalize_to_macros_2_0();
10701064
debug!("with_generic_param_rib: {}", param.id);
10711065

1072-
if seen_bindings.contains_key(&ident) {
1073-
let span = seen_bindings.get(&ident).unwrap();
1074-
let err = ResolutionError::NameAlreadyUsedInParameterList(ident.name, *span);
1075-
self.report_error(param.ident.span, err);
1066+
match seen_bindings.entry(ident) {
1067+
Entry::Occupied(entry) => {
1068+
let span = *entry.get();
1069+
let err = ResolutionError::NameAlreadyUsedInParameterList(ident.name, span);
1070+
self.report_error(param.ident.span, err);
1071+
}
1072+
Entry::Vacant(entry) => {
1073+
entry.insert(param.ident.span);
1074+
}
10761075
}
1077-
seen_bindings.entry(ident).or_insert(param.ident.span);
10781076

10791077
// Plain insert (no renaming).
1080-
let res = Res::Def(def_kind, self.r.local_def_id(param.id).to_def_id());
1081-
1082-
match param.kind {
1083-
GenericParamKind::Type { .. } => {
1084-
function_type_rib.bindings.insert(ident, res);
1085-
self.r.record_partial_res(param.id, PartialRes::new(res));
1086-
}
1087-
GenericParamKind::Const { .. } => {
1088-
function_value_rib.bindings.insert(ident, res);
1089-
self.r.record_partial_res(param.id, PartialRes::new(res));
1090-
}
1078+
let (rib, def_kind) = match param.kind {
1079+
GenericParamKind::Type { .. } => (&mut function_type_rib, DefKind::TyParam),
1080+
GenericParamKind::Const { .. } => (&mut function_value_rib, DefKind::ConstParam),
10911081
_ => unreachable!(),
1092-
}
1082+
};
1083+
let res = Res::Def(def_kind, self.r.local_def_id(param.id).to_def_id());
1084+
self.r.record_partial_res(param.id, PartialRes::new(res));
1085+
rib.bindings.insert(ident, res);
10931086
}
10941087

10951088
self.ribs[ValueNS].push(function_value_rib);
@@ -1778,7 +1771,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
17781771
path
17791772
);
17801773
let ns = source.namespace();
1781-
let is_expected = &|res| source.is_expected(res);
17821774

17831775
let report_errors = |this: &mut Self, res: Option<Res>| {
17841776
if this.should_report_errs() {
@@ -1881,7 +1873,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
18811873
crate_lint,
18821874
) {
18831875
Ok(Some(partial_res)) if partial_res.unresolved_segments() == 0 => {
1884-
if is_expected(partial_res.base_res()) || partial_res.base_res() == Res::Err {
1876+
if source.is_expected(partial_res.base_res()) || partial_res.base_res() == Res::Err
1877+
{
18851878
partial_res
18861879
} else {
18871880
report_errors(self, Some(partial_res.base_res()))
@@ -1898,11 +1891,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
18981891
self.r.trait_map.insert(id, traits);
18991892
}
19001893

1901-
let mut std_path = vec![Segment::from_ident(Ident::with_dummy_span(sym::std))];
1902-
1903-
std_path.extend(path);
1904-
19051894
if self.r.primitive_type_table.primitive_types.contains_key(&path[0].ident.name) {
1895+
let mut std_path = Vec::with_capacity(1 + path.len());
1896+
1897+
std_path.push(Segment::from_ident(Ident::with_dummy_span(sym::std)));
1898+
std_path.extend(path);
19061899
if let PathResult::Module(_) | PathResult::NonModule(_) =
19071900
self.resolve_path(&std_path, Some(ns), false, span, CrateLint::No)
19081901
{
@@ -1983,7 +1976,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
19831976
) -> Result<Option<PartialRes>, Spanned<ResolutionError<'a>>> {
19841977
let mut fin_res = None;
19851978

1986-
for (i, ns) in [primary_ns, TypeNS, ValueNS].iter().cloned().enumerate() {
1979+
for (i, &ns) in [primary_ns, TypeNS, ValueNS].iter().enumerate() {
19871980
if i == 0 || ns != primary_ns {
19881981
match self.resolve_qpath(id, qself, path, ns, span, crate_lint)? {
19891982
Some(partial_res)
@@ -1993,7 +1986,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
19931986
}
19941987
partial_res => {
19951988
if fin_res.is_none() {
1996-
fin_res = partial_res
1989+
fin_res = partial_res;
19971990
}
19981991
}
19991992
}

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -254,27 +254,21 @@ fn suggest_restriction(
254254
let pred = trait_ref.without_const().to_predicate(tcx).to_string();
255255
let pred = pred.replace(&impl_trait_str, &type_param_name);
256256
let mut sugg = vec![
257+
// Find the last of the generic parameters contained within the span of
258+
// the generics
257259
match generics
258260
.params
259261
.iter()
260-
.filter(|p| match p.kind {
261-
hir::GenericParamKind::Type {
262-
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
263-
..
264-
} => false,
265-
_ => true,
266-
})
267-
.last()
262+
.map(|p| p.bounds_span().unwrap_or(p.span))
263+
.filter(|&span| generics.span.contains(span) && span.desugaring_kind().is_none())
264+
.max_by_key(|span| span.hi())
268265
{
269266
// `fn foo(t: impl Trait)`
270267
// ^ suggest `<T: Trait>` here
271268
None => (generics.span, format!("<{}>", type_param)),
272269
// `fn foo<A>(t: impl Trait)`
273270
// ^^^ suggest `<A, T: Trait>` here
274-
Some(param) => (
275-
param.bounds_span().unwrap_or(param.span).shrink_to_hi(),
276-
format!(", {}", type_param),
277-
),
271+
Some(span) => (span.shrink_to_hi(), format!(", {}", type_param)),
278272
},
279273
// `fn foo(t: impl Trait)`
280274
// ^ suggest `where <T as Trait>::A: Bound`

compiler/rustc_typeck/src/check/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3131
_ => (false, false, false),
3232
};
3333

34-
// Type check the descriminant and get its type.
34+
// Type check the discriminant and get its type.
3535
let scrutinee_ty = if force_scrutinee_bool {
3636
// Here we want to ensure:
3737
//

compiler/rustc_typeck/src/check/op.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
503503
if !self.tcx.has_typeck_results(def_id) {
504504
return false;
505505
}
506-
// We're emitting a suggestion, so we can just ignore regions
507-
let fn_sig = self.tcx.fn_sig(def_id).skip_binder();
506+
// FIXME: Instead of exiting early when encountering bound vars in
507+
// the function signature, consider keeping the binder here and
508+
// propagating it downwards.
509+
let fn_sig = if let Some(fn_sig) = self.tcx.fn_sig(def_id).no_bound_vars() {
510+
fn_sig
511+
} else {
512+
return false;
513+
};
508514

509515
let other_ty = if let FnDef(def_id, _) = *other_ty.kind() {
510516
if !self.tcx.has_typeck_results(def_id) {

library/core/src/sync/atomic.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1040,8 +1040,16 @@ impl<T> AtomicPtr<T> {
10401040
#[stable(feature = "rust1", since = "1.0.0")]
10411041
#[cfg(target_has_atomic = "ptr")]
10421042
pub fn swap(&self, ptr: *mut T, order: Ordering) -> *mut T {
1043+
#[cfg(bootstrap)]
10431044
// SAFETY: data races are prevented by atomic intrinsics.
1044-
unsafe { atomic_swap(self.p.get() as *mut usize, ptr as usize, order) as *mut T }
1045+
unsafe {
1046+
atomic_swap(self.p.get() as *mut usize, ptr as usize, order) as *mut T
1047+
}
1048+
#[cfg(not(bootstrap))]
1049+
// SAFETY: data races are prevented by atomic intrinsics.
1050+
unsafe {
1051+
atomic_swap(self.p.get(), ptr, order)
1052+
}
10451053
}
10461054

10471055
/// Stores a value into the pointer if the current value is the same as the `current` value.

library/std/src/primitive_docs.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,10 @@ mod prim_unit {}
478478
#[stable(feature = "rust1", since = "1.0.0")]
479479
mod prim_pointer {}
480480

481+
#[doc(alias = "[]")]
482+
#[doc(alias = "[T;N]")] // unfortunately, rustdoc doesn't have fuzzy search for aliases
483+
#[doc(alias = "[T; N]")]
481484
#[doc(primitive = "array")]
482-
//
483485
/// A fixed-size array, denoted `[T; N]`, for the element type, `T`, and the
484486
/// non-negative compile-time constant size, `N`.
485487
///

src/bootstrap/install.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,7 @@ fn install_sh(
7373
let docdir_default = datadir_default.join("doc/rust");
7474
let libdir_default = PathBuf::from("lib");
7575
let mandir_default = datadir_default.join("man");
76-
let prefix = builder.config.prefix.as_ref().map_or(prefix_default, |p| {
77-
fs::create_dir_all(p)
78-
.unwrap_or_else(|err| panic!("could not create {}: {}", p.display(), err));
79-
fs::canonicalize(p)
80-
.unwrap_or_else(|err| panic!("could not canonicalize {}: {}", p.display(), err))
81-
});
76+
let prefix = builder.config.prefix.as_ref().unwrap_or(&prefix_default);
8277
let sysconfdir = builder.config.sysconfdir.as_ref().unwrap_or(&sysconfdir_default);
8378
let datadir = builder.config.datadir.as_ref().unwrap_or(&datadir_default);
8479
let docdir = builder.config.docdir.as_ref().unwrap_or(&docdir_default);
@@ -103,6 +98,13 @@ fn install_sh(
10398
let libdir = add_destdir(&libdir, &destdir);
10499
let mandir = add_destdir(&mandir, &destdir);
105100

101+
let prefix = {
102+
fs::create_dir_all(&prefix)
103+
.unwrap_or_else(|err| panic!("could not create {}: {}", prefix.display(), err));
104+
fs::canonicalize(&prefix)
105+
.unwrap_or_else(|err| panic!("could not canonicalize {}: {}", prefix.display(), err))
106+
};
107+
106108
let empty_dir = builder.out.join("tmp/empty_dir");
107109

108110
t!(fs::create_dir_all(&empty_dir));

0 commit comments

Comments
 (0)