Skip to content

Commit ab3dba9

Browse files
committed
Auto merge of #123628 - matthiaskrgr:rollup-6otgb94, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #115984 (extending filesystem support for Hermit) - #120144 (privacy: Stabilize lint `unnameable_types`) - #122807 (Add consistency with phrases "meantime" and "mean time") - #123089 (Add invariant to VecDeque::pop_* that len < cap if pop successful) - #123595 (Documentation fix) - #123625 (Stop exporting `TypeckRootCtxt` and `FnCtxt`.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 75fd074 + f825271 commit ab3dba9

File tree

28 files changed

+403
-203
lines changed

28 files changed

+403
-203
lines changed

compiler/rustc_driver_impl/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ driver_impl_ice = the compiler unexpectedly panicked. this is a bug.
22
driver_impl_ice_bug_report = we would appreciate a bug report: {$bug_report_url}
33
driver_impl_ice_bug_report_internal_feature = using internal features is not supported and expected to cause internal compiler errors when used incorrectly
44
driver_impl_ice_bug_report_outdated =
5-
it seems that this compiler `{$version}` is outdated, a newer nightly should have been released in the mean time
5+
it seems that this compiler `{$version}` is outdated, a newer nightly should have been released in the meantime
66
.update = please consider running `rustup update nightly` to update the nightly channel and check if this problem still persists
77
.url = if the problem still persists, we would appreciate a bug report: {$bug_report_url}
88
driver_impl_ice_exclude_cargo_defaults = some of the compiler flags provided by cargo are hidden

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ declare_features! (
355355
(accepted, type_alias_enum_variants, "1.37.0", Some(49683)),
356356
/// Allows macros to appear in the type position.
357357
(accepted, type_macros, "1.13.0", Some(27245)),
358+
/// Allows using type privacy lints (`private_interfaces`, `private_bounds`, `unnameable_types`).
359+
(accepted, type_privacy_lints, "CURRENT_RUSTC_VERSION", Some(48054)),
358360
/// Allows `const _: TYPE = VALUE`.
359361
(accepted, underscore_const_names, "1.37.0", Some(54912)),
360362
/// Allows `use path as _;` and `extern crate c as _;`.

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,6 @@ declare_features! (
615615
/// Allows creation of instances of a struct by moving fields that have
616616
/// not changed from prior instances of the same struct (RFC #2528)
617617
(unstable, type_changing_struct_update, "1.58.0", Some(86555)),
618-
/// Allows using type privacy lints (`private_interfaces`, `private_bounds`, `unnameable_types`).
619-
(unstable, type_privacy_lints, "1.72.0", Some(48054)),
620618
/// Enables rustc to generate code that instructs libstd to NOT ignore SIGPIPE.
621619
(unstable, unix_sigpipe, "1.65.0", Some(97889)),
622620
/// Allows unnamed fields of struct and union type

compiler/rustc_hir_typeck/src/cast.rs

+34-7
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,19 @@ use rustc_middle::mir::Mutability;
4040
use rustc_middle::ty::adjustment::AllowTwoPhase;
4141
use rustc_middle::ty::cast::{CastKind, CastTy};
4242
use rustc_middle::ty::error::TypeError;
43+
use rustc_middle::ty::TyCtxt;
4344
use rustc_middle::ty::{self, Ty, TypeAndMut, TypeVisitableExt, VariantDef};
4445
use rustc_session::lint;
4546
use rustc_span::def_id::{DefId, LOCAL_CRATE};
4647
use rustc_span::symbol::sym;
4748
use rustc_span::Span;
49+
use rustc_span::DUMMY_SP;
4850
use rustc_trait_selection::infer::InferCtxtExt;
4951

5052
/// Reifies a cast check to be checked once we have full type information for
5153
/// a function context.
5254
#[derive(Debug)]
53-
pub struct CastCheck<'tcx> {
55+
pub(crate) struct CastCheck<'tcx> {
5456
/// The expression whose value is being casted
5557
expr: &'tcx hir::Expr<'tcx>,
5658
/// The source type for the cast expression
@@ -60,8 +62,6 @@ pub struct CastCheck<'tcx> {
6062
cast_ty: Ty<'tcx>,
6163
cast_span: Span,
6264
span: Span,
63-
/// whether the cast is made in a const context or not.
64-
pub constness: hir::Constness,
6565
}
6666

6767
/// The kind of pointer and associated metadata (thin, length or vtable) - we
@@ -194,18 +194,45 @@ fn make_invalid_casting_error<'a, 'tcx>(
194194
)
195195
}
196196

197+
/// If a cast from `from_ty` to `to_ty` is valid, returns a `Some` containing the kind
198+
/// of the cast.
199+
///
200+
/// This is a helper used from clippy.
201+
pub fn check_cast<'tcx>(
202+
tcx: TyCtxt<'tcx>,
203+
param_env: ty::ParamEnv<'tcx>,
204+
e: &'tcx hir::Expr<'tcx>,
205+
from_ty: Ty<'tcx>,
206+
to_ty: Ty<'tcx>,
207+
) -> Option<CastKind> {
208+
let hir_id = e.hir_id;
209+
let local_def_id = hir_id.owner.def_id;
210+
211+
let root_ctxt = crate::TypeckRootCtxt::new(tcx, local_def_id);
212+
let fn_ctxt = FnCtxt::new(&root_ctxt, param_env, local_def_id);
213+
214+
if let Ok(check) = CastCheck::new(
215+
&fn_ctxt, e, from_ty, to_ty,
216+
// We won't show any errors to the user, so the span is irrelevant here.
217+
DUMMY_SP, DUMMY_SP,
218+
) {
219+
check.do_check(&fn_ctxt).ok()
220+
} else {
221+
None
222+
}
223+
}
224+
197225
impl<'a, 'tcx> CastCheck<'tcx> {
198-
pub fn new(
226+
pub(crate) fn new(
199227
fcx: &FnCtxt<'a, 'tcx>,
200228
expr: &'tcx hir::Expr<'tcx>,
201229
expr_ty: Ty<'tcx>,
202230
cast_ty: Ty<'tcx>,
203231
cast_span: Span,
204232
span: Span,
205-
constness: hir::Constness,
206233
) -> Result<CastCheck<'tcx>, ErrorGuaranteed> {
207234
let expr_span = expr.span.find_ancestor_inside(span).unwrap_or(expr.span);
208-
let check = CastCheck { expr, expr_ty, expr_span, cast_ty, cast_span, span, constness };
235+
let check = CastCheck { expr, expr_ty, expr_span, cast_ty, cast_span, span };
209236

210237
// For better error messages, check for some obviously unsized
211238
// cases now. We do a more thorough check at the end, once
@@ -644,7 +671,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
644671
/// Checks a cast, and report an error if one exists. In some cases, this
645672
/// can return Ok and create type errors in the fcx rather than returning
646673
/// directly. coercion-cast is handled in check instead of here.
647-
pub fn do_check(&self, fcx: &FnCtxt<'a, 'tcx>) -> Result<CastKind, CastError> {
674+
fn do_check(&self, fcx: &FnCtxt<'a, 'tcx>) -> Result<CastKind, CastError> {
648675
use rustc_middle::ty::cast::CastTy::*;
649676
use rustc_middle::ty::cast::IntTy::*;
650677

compiler/rustc_hir_typeck/src/coercion.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13181318
}
13191319
}
13201320

1321+
/// Check whether `ty` can be coerced to `output_ty`.
1322+
/// Used from clippy.
1323+
pub fn can_coerce<'tcx>(
1324+
tcx: TyCtxt<'tcx>,
1325+
param_env: ty::ParamEnv<'tcx>,
1326+
body_id: LocalDefId,
1327+
ty: Ty<'tcx>,
1328+
output_ty: Ty<'tcx>,
1329+
) -> bool {
1330+
let root_ctxt = crate::typeck_root_ctxt::TypeckRootCtxt::new(tcx, body_id);
1331+
let fn_ctxt = FnCtxt::new(&root_ctxt, param_env, body_id);
1332+
fn_ctxt.can_coerce(ty, output_ty)
1333+
}
1334+
13211335
/// CoerceMany encapsulates the pattern you should use when you have
13221336
/// many expressions that are all getting coerced to a common
13231337
/// type. This arises, for example, when you have a match (the result

compiler/rustc_hir_typeck/src/expr.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -1390,15 +1390,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13901390
} else {
13911391
// Defer other checks until we're done type checking.
13921392
let mut deferred_cast_checks = self.deferred_cast_checks.borrow_mut();
1393-
match cast::CastCheck::new(
1394-
self,
1395-
e,
1396-
t_expr,
1397-
t_cast,
1398-
t.span,
1399-
expr.span,
1400-
hir::Constness::NotConst,
1401-
) {
1393+
match cast::CastCheck::new(self, e, t_expr, t_cast, t.span, expr.span) {
14021394
Ok(cast_check) => {
14031395
debug!(
14041396
"check_expr_cast: deferring cast from {:?} to {:?}: {:?}",

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use std::ops::Deref;
3838
///
3939
/// [`ItemCtxt`]: rustc_hir_analysis::collect::ItemCtxt
4040
/// [`InferCtxt`]: infer::InferCtxt
41-
pub struct FnCtxt<'a, 'tcx> {
41+
pub(crate) struct FnCtxt<'a, 'tcx> {
4242
pub(super) body_id: LocalDefId,
4343

4444
/// The parameter environment used for proving trait obligations

compiler/rustc_hir_typeck/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ mod typeck_root_ctxt;
4242
mod upvar;
4343
mod writeback;
4444

45-
pub use fn_ctxt::FnCtxt;
46-
pub use typeck_root_ctxt::TypeckRootCtxt;
45+
pub use coercion::can_coerce;
46+
use fn_ctxt::FnCtxt;
47+
use typeck_root_ctxt::TypeckRootCtxt;
4748

4849
use crate::check::check_fn;
4950
use crate::coercion::DynamicCoerceMany;

compiler/rustc_hir_typeck/src/typeck_root_ctxt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use std::ops::Deref;
2727
/// `bar()` will each have their own `FnCtxt`, but they will
2828
/// share the inference context, will process obligations together,
2929
/// can access each other's local types (scoping permitted), etc.
30-
pub struct TypeckRootCtxt<'tcx> {
30+
pub(crate) struct TypeckRootCtxt<'tcx> {
3131
pub(super) infcx: InferCtxt<'tcx>,
3232

3333
pub(super) typeck_results: RefCell<ty::TypeckResults<'tcx>>,

compiler/rustc_lint/src/builtin.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1337,8 +1337,9 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
13371337
}
13381338

13391339
declare_lint! {
1340-
/// The `unreachable_pub` lint triggers for `pub` items not reachable from
1341-
/// the crate root.
1340+
/// The `unreachable_pub` lint triggers for `pub` items not reachable from other crates - that
1341+
/// means neither directly accessible, nor reexported, nor leaked through things like return
1342+
/// types.
13421343
///
13431344
/// ### Example
13441345
///

compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ declare_lint! {
2020
/// This functionality was removed in #97346, but then rolled back in #99860
2121
/// because it caused regressions.
2222
///
23-
/// We plan on reintroducing this as a hard error, but in the mean time,
23+
/// We plan on reintroducing this as a hard error, but in the meantime,
2424
/// this lint serves to warn and suggest fixes for any use-cases which rely
2525
/// on this behavior.
2626
///

compiler/rustc_lint_defs/src/builtin.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -4311,7 +4311,6 @@ declare_lint! {
43114311
/// ### Example
43124312
///
43134313
/// ```rust,compile_fail
4314-
/// # #![feature(type_privacy_lints)]
43154314
/// # #![allow(unused)]
43164315
/// #![deny(unnameable_types)]
43174316
/// mod m {
@@ -4328,10 +4327,14 @@ declare_lint! {
43284327
///
43294328
/// It is often expected that if you can obtain an object of type `T`, then
43304329
/// you can name the type `T` as well, this lint attempts to enforce this rule.
4330+
/// The recommended action is to either reexport the type properly to make it nameable,
4331+
/// or document that users are not supposed to be able to name it for one reason or another.
4332+
///
4333+
/// Besides types, this lint applies to traits because traits can also leak through signatures,
4334+
/// and you may obtain objects of their `dyn Trait` or `impl Trait` types.
43314335
pub UNNAMEABLE_TYPES,
43324336
Allow,
43334337
"effective visibility of a type is larger than the area in which it can be named",
4334-
@feature_gate = sym::type_privacy_lints;
43354338
}
43364339

43374340
declare_lint! {

compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef Child, size_t *Size) {
147147
Expected<StringRef> NameOrErr = Child->getName();
148148
if (!NameOrErr) {
149149
// rustc_codegen_llvm currently doesn't use this error string, but it might be
150-
// useful in the future, and in the mean time this tells LLVM that the
150+
// useful in the future, and in the meantime this tells LLVM that the
151151
// error was not ignored and that it shouldn't abort the process.
152152
LLVMRustSetLastError(toString(NameOrErr.takeError()).c_str());
153153
return nullptr;

library/alloc/src/collections/vec_deque/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,10 @@ impl<T, A: Allocator> VecDeque<T, A> {
16141614
let old_head = self.head;
16151615
self.head = self.to_physical_idx(1);
16161616
self.len -= 1;
1617-
Some(unsafe { self.buffer_read(old_head) })
1617+
unsafe {
1618+
core::hint::assert_unchecked(self.len < self.capacity());
1619+
Some(self.buffer_read(old_head))
1620+
}
16181621
}
16191622
}
16201623

@@ -1638,7 +1641,10 @@ impl<T, A: Allocator> VecDeque<T, A> {
16381641
None
16391642
} else {
16401643
self.len -= 1;
1641-
Some(unsafe { self.buffer_read(self.to_physical_idx(self.len)) })
1644+
unsafe {
1645+
core::hint::assert_unchecked(self.len < self.capacity());
1646+
Some(self.buffer_read(self.to_physical_idx(self.len)))
1647+
}
16421648
}
16431649
}
16441650

library/core/src/ops/try_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ pub trait FromResidual<R = <Self as Try>::Residual> {
310310
/// This should be implemented consistently with the `branch` method such
311311
/// that applying the `?` operator will get back an equivalent residual:
312312
/// `FromResidual::from_residual(r).branch() --> ControlFlow::Break(r)`.
313-
/// (It must not be an *identical* residual when interconversion is involved.)
313+
/// (The residual is not mandated to be *identical* when interconversion is involved.)
314314
///
315315
/// # Examples
316316
///

library/std/src/sys/pal/hermit/fd.rs

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ impl FileDesc {
4848
pub fn set_nonblocking(&self, _nonblocking: bool) -> io::Result<()> {
4949
unsupported()
5050
}
51+
52+
pub fn fstat(&self, stat: *mut abi::stat) -> io::Result<()> {
53+
cvt(unsafe { abi::fstat(self.fd.as_raw_fd(), stat) })?;
54+
Ok(())
55+
}
5156
}
5257

5358
impl<'a> Read for &'a FileDesc {

0 commit comments

Comments
 (0)