Skip to content

Commit bdb32bd

Browse files
committed
Auto merge of rust-lang#110440 - matthiaskrgr:rollup-eit19vi, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#110038 (Erase regions when confirming transmutability candidate) - rust-lang#110341 (rustdoc: stop passing a title to `replaceState` second argument) - rust-lang#110388 (Add a message for if an overflow occurs in `core::intrinsics::is_nonoverlapping`.) - rust-lang#110404 (fix clippy::toplevel_ref_arg and ::manual_map) - rust-lang#110421 (Spelling librustdoc) - rust-lang#110423 (Spelling srcdoc) - rust-lang#110433 (Windows: map a few more error codes to ErrorKind) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 53ac4f8 + 35e6389 commit bdb32bd

File tree

43 files changed

+179
-160
lines changed

Some content is hidden

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

43 files changed

+179
-160
lines changed

compiler/rustc_builtin_macros/src/format.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,7 @@ fn parse_args<'a>(ecx: &mut ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<
141141
args: args
142142
.named_args()
143143
.iter()
144-
.filter_map(|a| {
145-
if let Some(ident) = a.kind.ident() {
146-
Some((a, ident))
147-
} else {
148-
None
149-
}
150-
})
144+
.filter_map(|a| a.kind.ident().map(|ident| (a, ident)))
151145
.map(|(arg, n)| n.span.to(arg.expr.span))
152146
.collect(),
153147
});

compiler/rustc_data_structures/src/sso/map.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,9 @@ impl<K: Eq + Hash, V> SsoHashMap<K, V> {
256256
pub fn remove(&mut self, key: &K) -> Option<V> {
257257
match self {
258258
SsoHashMap::Array(array) => {
259-
if let Some(index) = array.iter().position(|(k, _v)| k == key) {
260-
Some(array.swap_remove(index).1)
261-
} else {
262-
None
263-
}
259+
array.iter().position(|(k, _v)| k == key).map(|index| array.swap_remove(index).1)
264260
}
261+
265262
SsoHashMap::Map(map) => map.remove(key),
266263
}
267264
}

compiler/rustc_lint/src/unused.rs

+16-23
Original file line numberDiff line numberDiff line change
@@ -636,20 +636,14 @@ trait UnusedDelimLint {
636636
return;
637637
}
638638
let spans = match value.kind {
639-
ast::ExprKind::Block(ref block, None) if block.stmts.len() == 1 => {
640-
if let Some(span) = block.stmts[0].span.find_ancestor_inside(value.span) {
641-
Some((value.span.with_hi(span.lo()), value.span.with_lo(span.hi())))
642-
} else {
643-
None
644-
}
645-
}
639+
ast::ExprKind::Block(ref block, None) if block.stmts.len() == 1 => block.stmts[0]
640+
.span
641+
.find_ancestor_inside(value.span)
642+
.map(|span| (value.span.with_hi(span.lo()), value.span.with_lo(span.hi()))),
646643
ast::ExprKind::Paren(ref expr) => {
647-
let expr_span = expr.span.find_ancestor_inside(value.span);
648-
if let Some(expr_span) = expr_span {
649-
Some((value.span.with_hi(expr_span.lo()), value.span.with_lo(expr_span.hi())))
650-
} else {
651-
None
652-
}
644+
expr.span.find_ancestor_inside(value.span).map(|expr_span| {
645+
(value.span.with_hi(expr_span.lo()), value.span.with_lo(expr_span.hi()))
646+
})
653647
}
654648
_ => return,
655649
};
@@ -928,11 +922,10 @@ impl UnusedParens {
928922
// Otherwise proceed with linting.
929923
_ => {}
930924
}
931-
let spans = if let Some(inner) = inner.span.find_ancestor_inside(value.span) {
932-
Some((value.span.with_hi(inner.lo()), value.span.with_lo(inner.hi())))
933-
} else {
934-
None
935-
};
925+
let spans = inner
926+
.span
927+
.find_ancestor_inside(value.span)
928+
.map(|inner| (value.span.with_hi(inner.lo()), value.span.with_lo(inner.hi())));
936929
self.emit_unused_delims(cx, value.span, spans, "pattern", keep_space);
937930
}
938931
}
@@ -1043,11 +1036,11 @@ impl EarlyLintPass for UnusedParens {
10431036
if self.with_self_ty_parens && b.generic_params.len() > 0 => {}
10441037
ast::TyKind::ImplTrait(_, bounds) if bounds.len() > 1 => {}
10451038
_ => {
1046-
let spans = if let Some(r) = r.span.find_ancestor_inside(ty.span) {
1047-
Some((ty.span.with_hi(r.lo()), ty.span.with_lo(r.hi())))
1048-
} else {
1049-
None
1050-
};
1039+
let spans = r
1040+
.span
1041+
.find_ancestor_inside(ty.span)
1042+
.map(|r| (ty.span.with_hi(r.lo()), ty.span.with_lo(r.hi())));
1043+
10511044
self.emit_unused_delims(cx, ty.span, spans, "type", (false, false));
10521045
}
10531046
}

compiler/rustc_mir_transform/src/const_prop_lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
493493
cond: &Operand<'tcx>,
494494
location: Location,
495495
) -> Option<!> {
496-
let ref value = self.eval_operand(&cond, location)?;
496+
let value = &self.eval_operand(&cond, location)?;
497497
trace!("assertion on {:?} should be {:?}", value, expected);
498498

499499
let expected = Scalar::from_bool(expected);

compiler/rustc_parse/src/parser/attr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ impl<'a> Parser<'a> {
4545
Some(InnerAttrForbiddenReason::AfterOuterDocComment {
4646
prev_doc_comment_span: prev_outer_attr_sp.unwrap(),
4747
})
48-
} else if let Some(prev_outer_attr_sp) = prev_outer_attr_sp {
49-
Some(InnerAttrForbiddenReason::AfterOuterAttribute { prev_outer_attr_sp })
5048
} else {
51-
None
49+
prev_outer_attr_sp.map(|prev_outer_attr_sp| {
50+
InnerAttrForbiddenReason::AfterOuterAttribute { prev_outer_attr_sp }
51+
})
5252
};
5353
let inner_parse_policy = InnerAttrPolicy::Forbidden(inner_error_reason);
5454
just_parsed_doc_comment = false;

compiler/rustc_resolve/src/diagnostics.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1869,15 +1869,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
18691869
Some(LexicalScopeBinding::Item(name_binding)) => Some(name_binding.span),
18701870
_ => None,
18711871
};
1872-
let suggestion = if let Some(span) = match_span {
1873-
Some((
1872+
let suggestion = match_span.map(|span| {
1873+
(
18741874
vec![(span, String::from(""))],
18751875
format!("`{}` is defined here, but is not a type", ident),
18761876
Applicability::MaybeIncorrect,
1877-
))
1878-
} else {
1879-
None
1880-
};
1877+
)
1878+
});
18811879

18821880
(format!("use of undeclared type `{}`", ident), suggestion)
18831881
} else {

compiler/rustc_span/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1663,10 +1663,11 @@ impl SourceFile {
16631663

16641664
if let Some(ref src) = self.src {
16651665
Some(Cow::from(get_until_newline(src, begin)))
1666-
} else if let Some(src) = self.external_src.borrow().get_source() {
1667-
Some(Cow::Owned(String::from(get_until_newline(src, begin))))
16681666
} else {
1669-
None
1667+
self.external_src
1668+
.borrow()
1669+
.get_source()
1670+
.map(|src| Cow::Owned(String::from(get_until_newline(src, begin))))
16701671
}
16711672
}
16721673

compiler/rustc_span/src/source_map.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -906,10 +906,8 @@ impl SourceMap {
906906

907907
let snippet = if let Some(ref src) = local_begin.sf.src {
908908
Some(&src[start_index..])
909-
} else if let Some(src) = src.get_source() {
910-
Some(&src[start_index..])
911909
} else {
912-
None
910+
src.get_source().map(|src| &src[start_index..])
913911
};
914912

915913
match snippet {

compiler/rustc_trait_selection/src/solve/eval_ctxt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
649649
// FIXME(transmutability): This really should be returning nested goals for `Answer::If*`
650650
match rustc_transmute::TransmuteTypeEnv::new(self.infcx).is_transmutable(
651651
ObligationCause::dummy(),
652-
ty::Binder::dummy(src_and_dst),
652+
src_and_dst,
653653
scope,
654654
assume,
655655
) {

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
742742
{
743743
// Recompute the safe transmute reason and use that for the error reporting
744744
self.get_safe_transmute_error_and_reason(
745-
trait_predicate,
746745
obligation.clone(),
747746
trait_ref,
748747
span,
@@ -1629,7 +1628,6 @@ trait InferCtxtPrivExt<'tcx> {
16291628

16301629
fn get_safe_transmute_error_and_reason(
16311630
&self,
1632-
trait_predicate: ty::Binder<'tcx, ty::TraitPredicate<'tcx>>,
16331631
obligation: Obligation<'tcx, ty::Predicate<'tcx>>,
16341632
trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
16351633
span: Span,
@@ -2921,18 +2919,20 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
29212919

29222920
fn get_safe_transmute_error_and_reason(
29232921
&self,
2924-
trait_predicate: ty::Binder<'tcx, ty::TraitPredicate<'tcx>>,
29252922
obligation: Obligation<'tcx, ty::Predicate<'tcx>>,
29262923
trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
29272924
span: Span,
29282925
) -> (String, Option<String>) {
2929-
let src_and_dst = trait_predicate.map_bound(|p| rustc_transmute::Types {
2930-
dst: p.trait_ref.substs.type_at(0),
2931-
src: p.trait_ref.substs.type_at(1),
2932-
});
2933-
let scope = trait_ref.skip_binder().substs.type_at(2);
2926+
// Erase regions because layout code doesn't particularly care about regions.
2927+
let trait_ref = self.tcx.erase_regions(self.tcx.erase_late_bound_regions(trait_ref));
2928+
2929+
let src_and_dst = rustc_transmute::Types {
2930+
dst: trait_ref.substs.type_at(0),
2931+
src: trait_ref.substs.type_at(1),
2932+
};
2933+
let scope = trait_ref.substs.type_at(2);
29342934
let Some(assume) =
2935-
rustc_transmute::Assume::from_const(self.infcx.tcx, obligation.param_env, trait_ref.skip_binder().substs.const_at(3)) else {
2935+
rustc_transmute::Assume::from_const(self.infcx.tcx, obligation.param_env, trait_ref.substs.const_at(3)) else {
29362936
span_bug!(span, "Unable to construct rustc_transmute::Assume where it was previously possible");
29372937
};
29382938
match rustc_transmute::TransmuteTypeEnv::new(self.infcx).is_transmutable(
@@ -2942,8 +2942,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
29422942
assume,
29432943
) {
29442944
rustc_transmute::Answer::No(reason) => {
2945-
let dst = trait_ref.skip_binder().substs.type_at(0);
2946-
let src = trait_ref.skip_binder().substs.type_at(1);
2945+
let dst = trait_ref.substs.type_at(0);
2946+
let src = trait_ref.substs.type_at(1);
29472947
let custom_err_msg = format!(
29482948
"`{src}` cannot be safely transmuted into `{dst}` in the defining scope of `{scope}`"
29492949
);

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+25-23
Original file line numberDiff line numberDiff line change
@@ -275,33 +275,35 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
275275
) -> Result<ImplSourceBuiltinData<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
276276
debug!(?obligation, "confirm_transmutability_candidate");
277277

278-
let predicate = obligation.predicate;
279-
280-
let type_at = |i| predicate.map_bound(|p| p.trait_ref.substs.type_at(i));
281-
let const_at = |i| predicate.skip_binder().trait_ref.substs.const_at(i);
282-
283-
let src_and_dst = predicate.map_bound(|p| rustc_transmute::Types {
284-
dst: p.trait_ref.substs.type_at(0),
285-
src: p.trait_ref.substs.type_at(1),
286-
});
287-
288-
let scope = type_at(2).skip_binder();
289-
290-
let Some(assume) =
291-
rustc_transmute::Assume::from_const(self.infcx.tcx, obligation.param_env, const_at(3)) else {
292-
return Err(Unimplemented);
293-
};
294-
295-
let cause = obligation.cause.clone();
278+
// We erase regions here because transmutability calls layout queries,
279+
// which does not handle inference regions and doesn't particularly
280+
// care about other regions. Erasing late-bound regions is equivalent
281+
// to instantiating the binder with placeholders then erasing those
282+
// placeholder regions.
283+
let predicate =
284+
self.tcx().erase_regions(self.tcx().erase_late_bound_regions(obligation.predicate));
285+
286+
let Some(assume) = rustc_transmute::Assume::from_const(
287+
self.infcx.tcx,
288+
obligation.param_env,
289+
predicate.trait_ref.substs.const_at(3)
290+
) else {
291+
return Err(Unimplemented);
292+
};
296293

297294
let mut transmute_env = rustc_transmute::TransmuteTypeEnv::new(self.infcx);
298-
299-
let maybe_transmutable = transmute_env.is_transmutable(cause, src_and_dst, scope, assume);
300-
301-
use rustc_transmute::Answer;
295+
let maybe_transmutable = transmute_env.is_transmutable(
296+
obligation.cause.clone(),
297+
rustc_transmute::Types {
298+
dst: predicate.trait_ref.substs.type_at(0),
299+
src: predicate.trait_ref.substs.type_at(1),
300+
},
301+
predicate.trait_ref.substs.type_at(2),
302+
assume,
303+
);
302304

303305
match maybe_transmutable {
304-
Answer::Yes => Ok(ImplSourceBuiltinData { nested: vec![] }),
306+
rustc_transmute::Answer::Yes => Ok(ImplSourceBuiltinData { nested: vec![] }),
305307
_ => Err(Unimplemented),
306308
}
307309
}

compiler/rustc_trait_selection/src/traits/util.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,11 @@ pub fn get_vtable_index_of_object_method<'tcx, N>(
243243
) -> Option<usize> {
244244
// Count number of methods preceding the one we are selecting and
245245
// add them to the total offset.
246-
if let Some(index) = tcx
247-
.own_existential_vtable_entries(object.upcast_trait_ref.def_id())
246+
tcx.own_existential_vtable_entries(object.upcast_trait_ref.def_id())
248247
.iter()
249248
.copied()
250249
.position(|def_id| def_id == method_def_id)
251-
{
252-
Some(object.vtable_base + index)
253-
} else {
254-
None
255-
}
250+
.map(|index| object.vtable_base + index)
256251
}
257252

258253
pub fn closure_trait_ref_and_return_type<'tcx>(

compiler/rustc_transmute/src/lib.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ mod rustc {
6464
use rustc_infer::infer::InferCtxt;
6565
use rustc_macros::{TypeFoldable, TypeVisitable};
6666
use rustc_middle::traits::ObligationCause;
67-
use rustc_middle::ty::Binder;
6867
use rustc_middle::ty::Const;
6968
use rustc_middle::ty::ParamEnv;
7069
use rustc_middle::ty::Ty;
@@ -92,15 +91,13 @@ mod rustc {
9291
pub fn is_transmutable(
9392
&mut self,
9493
cause: ObligationCause<'tcx>,
95-
src_and_dst: Binder<'tcx, Types<'tcx>>,
94+
types: Types<'tcx>,
9695
scope: Ty<'tcx>,
9796
assume: crate::Assume,
9897
) -> crate::Answer<crate::layout::rustc::Ref<'tcx>> {
99-
let src = src_and_dst.map_bound(|types| types.src).skip_binder();
100-
let dst = src_and_dst.map_bound(|types| types.dst).skip_binder();
10198
crate::maybe_transmutable::MaybeTransmutableQuery::new(
102-
src,
103-
dst,
99+
types.src,
100+
types.dst,
104101
scope,
105102
assume,
106103
self.infcx.tcx,

compiler/rustc_ty_utils/src/instance.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,12 @@ fn resolve_associated_item<'tcx>(
234234
_ => None,
235235
},
236236
traits::ImplSource::Object(ref data) => {
237-
if let Some(index) = traits::get_vtable_index_of_object_method(tcx, data, trait_item_id)
238-
{
239-
Some(Instance {
237+
traits::get_vtable_index_of_object_method(tcx, data, trait_item_id).map(|index| {
238+
Instance {
240239
def: ty::InstanceDef::Virtual(trait_item_id, index),
241240
substs: rcvr_substs,
242-
})
243-
} else {
244-
None
245-
}
241+
}
242+
})
246243
}
247244
traits::ImplSource::Builtin(..) => {
248245
let lang_items = tcx.lang_items();

compiler/rustc_ty_utils/src/structural_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_trait_selection::traits::{ObligationCause, ObligationCtxt};
1313
/// Note that this does *not* recursively check if the substructure of `adt_ty`
1414
/// implements the traits.
1515
fn has_structural_eq_impls<'tcx>(tcx: TyCtxt<'tcx>, adt_ty: Ty<'tcx>) -> bool {
16-
let ref infcx = tcx.infer_ctxt().build();
16+
let infcx = &tcx.infer_ctxt().build();
1717
let cause = ObligationCause::dummy();
1818

1919
let ocx = ObligationCtxt::new(infcx);

library/core/src/intrinsics.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2519,7 +2519,9 @@ pub(crate) fn is_valid_allocation_size<T>(len: usize) -> bool {
25192519
pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -> bool {
25202520
let src_usize = src.addr();
25212521
let dst_usize = dst.addr();
2522-
let size = mem::size_of::<T>().checked_mul(count).unwrap();
2522+
let size = mem::size_of::<T>()
2523+
.checked_mul(count)
2524+
.expect("is_nonoverlapping: `size_of::<T>() * count` overflows a usize");
25232525
let diff = if src_usize > dst_usize { src_usize - dst_usize } else { dst_usize - src_usize };
25242526
// If the absolute distance between the ptrs is at least as big as the size of the buffer,
25252527
// they do not overlap.

library/std/src/sys/windows/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,13 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
6868
c::ERROR_ALREADY_EXISTS => return AlreadyExists,
6969
c::ERROR_FILE_EXISTS => return AlreadyExists,
7070
c::ERROR_BROKEN_PIPE => return BrokenPipe,
71-
c::ERROR_FILE_NOT_FOUND => return NotFound,
72-
c::ERROR_PATH_NOT_FOUND => return NotFound,
71+
c::ERROR_FILE_NOT_FOUND
72+
| c::ERROR_PATH_NOT_FOUND
73+
| c::ERROR_INVALID_DRIVE
74+
| c::ERROR_BAD_NETPATH
75+
| c::ERROR_BAD_NET_NAME => return NotFound,
7376
c::ERROR_NO_DATA => return BrokenPipe,
74-
c::ERROR_INVALID_NAME => return InvalidFilename,
77+
c::ERROR_INVALID_NAME | c::ERROR_BAD_PATHNAME => return InvalidFilename,
7578
c::ERROR_INVALID_PARAMETER => return InvalidInput,
7679
c::ERROR_NOT_ENOUGH_MEMORY | c::ERROR_OUTOFMEMORY => return OutOfMemory,
7780
c::ERROR_SEM_TIMEOUT

src/doc/rustc/src/instrument-coverage.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ $ ls formatjson5.profraw
117117
formatjson5.profraw
118118
```
119119

120-
If `LLVM_PROFILE_FILE` contains a path to a non-existent directory, the missing directory structure will be created. Additionally, the following special pattern strings are rewritten:
120+
If `LLVM_PROFILE_FILE` contains a path to a nonexistent directory, the missing directory structure will be created. Additionally, the following special pattern strings are rewritten:
121121

122122
- `%p` - The process ID.
123123
- `%h` - The hostname of the machine running the program.

0 commit comments

Comments
 (0)