Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 11 pull requests #91485

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
7430b22
Make `Option::expect` const
lilasta Oct 25, 2021
f99e358
Merge commit 'ea199bacef07213dbe008841b89c450e3bf0c638' into rustfmt-…
calebcartwright Nov 8, 2021
e6d1bf5
Link tracking issues in Configurations.md (#4096)
Mar 31, 2020
34b7566
Type can be unsized and uninhabited
sanxiyn Nov 13, 2021
eee8f04
refactor: cleanup duplicative Impl handling code
calebcartwright Nov 17, 2021
0023abf
tests: add cases for type alias issues
calebcartwright Nov 18, 2021
2c442cc
fix: correct some type alias issues
calebcartwright Nov 18, 2021
196e676
Preserve normalized comments after last list item
mujpao Nov 19, 2021
826eba8
Add a few missing tracking issues in Configurations.md (#5084)
karyon Nov 20, 2021
4389a4c
fix: do not wrap reference-style doc links
domodwyer Nov 19, 2021
4198fac
Preload the most commonly used fonts.
jsha Nov 24, 2021
f99469d
Change how the fn params span is calculated
estebank Nov 24, 2021
243cec7
Update README.md
bluenote10 Nov 24, 2021
0da3a0f
Fix ICE #91268 by checking that the snippet ends with a `)`
Badel2 Nov 26, 2021
ea042b9
Add more tests for comments in lists
mujpao Nov 24, 2021
67fd9ec
Run Windows, Linux, and Mac CI tests with nightly and stable channels
ytmimi Nov 24, 2021
a21f1b6
Conditionally compile tests based on CFG_RELEASE_CHANNEL env var
ytmimi Nov 27, 2021
0fc846f
refactor: maintain more AST info when formatting a RHS
calebcartwright Nov 28, 2021
1f28683
Update nightly only test with #[nightly_only_test] attribute
ytmimi Nov 29, 2021
41e2a53
Android: -ldl must appear after -lgcc when linking
Amanieu Nov 30, 2021
ec46ffd
Determine when new comment lines are needed for itemized blocks
ytmimi Nov 19, 2021
7a14525
Document Windows TLS drop behaviour
ChrisDenton Dec 2, 2021
41e21aa
Implement write() method for Box<MaybeUninit<T>>
Kixunil Sep 13, 2021
6544097
Only shown relevant type params in E0283 label
estebank Nov 8, 2021
5d8b835
Refer to uninferred `const` params by their name, instead of `{ _: _ }`
estebank Nov 8, 2021
b97e078
Refer to const params as "const params" and not "type params"
estebank Nov 8, 2021
00f15c5
Add test with multiple type params failing inference
estebank Nov 19, 2021
b988151
Fix rebase
estebank Dec 2, 2021
0fdb109
suppress warning about set_errno being unused on DragonFly
rtzoeller Dec 2, 2021
a11994e
use try_normalize_erasing_regions in needs_drop
b-naber Dec 2, 2021
e305322
Merge remote-tracking branch 'upstream/master' into subtree-sync-2021…
calebcartwright Dec 3, 2021
8da8371
Merge pull request #5121 from calebcartwright/subtree-sync-2021-12-02
calebcartwright Dec 3, 2021
f6ade7c
Merge commit '8da837185714cefbb261e93e9846afb11c1dc60e' into sync-rus…
calebcartwright Dec 3, 2021
0a4caa2
Rollup merge of #88906 - Kixunil:box-maybe-uninit-write, r=dtolnay
matthiaskrgr Dec 3, 2021
9d92340
Rollup merge of #90269 - woppopo:const_option_expect, r=yaahc
matthiaskrgr Dec 3, 2021
021e18c
Rollup merge of #90709 - estebank:erase-known-type-params, r=nagisa
matthiaskrgr Dec 3, 2021
34fd8d6
Rollup merge of #90854 - sanxiyn:unsized-and-uninhabited, r=estebank
matthiaskrgr Dec 3, 2021
538beef
Rollup merge of #91170 - jsha:preload-fonts, r=GuillaumeGomez
matthiaskrgr Dec 3, 2021
7af2859
Rollup merge of #91273 - Badel2:ice-index-str, r=estebank
matthiaskrgr Dec 3, 2021
c441004
Rollup merge of #91381 - Amanieu:android_libdl, r=petrochenkov
matthiaskrgr Dec 3, 2021
d1e09f9
Rollup merge of #91453 - ChrisDenton:doc-win-tls-dtors, r=dtolnay
matthiaskrgr Dec 3, 2021
26b278c
Rollup merge of #91462 - b-naber:use-try-normalize-erasing-regions, r…
matthiaskrgr Dec 3, 2021
d1ce18c
Rollup merge of #91474 - rtzoeller:dfly_set_errno, r=cuviper
matthiaskrgr Dec 3, 2021
d1096fd
Rollup merge of #91483 - calebcartwright:sync-rustfmt-subtree, r=cale…
matthiaskrgr Dec 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions compiler/rustc_ast_lowering/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,19 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
if let Ok(snippet) = self.sess.source_map().span_to_snippet(data.span) {
// Do not suggest going from `Trait()` to `Trait<>`
if !data.inputs.is_empty() {
if let Some(split) = snippet.find('(') {
let trait_name = &snippet[0..split];
let args = &snippet[split + 1..snippet.len() - 1];
err.span_suggestion(
data.span,
"use angle brackets instead",
format!("{}<{}>", trait_name, args),
Applicability::MaybeIncorrect,
);
// Suggest replacing `(` and `)` with `<` and `>`
// The snippet may be missing the closing `)`, skip that case
if snippet.ends_with(')') {
if let Some(split) = snippet.find('(') {
let trait_name = &snippet[0..split];
let args = &snippet[split + 1..snippet.len() - 1];
err.span_suggestion(
data.span,
"use angle brackets instead",
format!("{}<{}>", trait_name, args),
Applicability::MaybeIncorrect,
);
}
}
}
};
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_data_structures/src/functor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ impl<T> IdFunctor for Box<T> {
let value = raw.read();
// SAFETY: Converts `Box<T>` to `Box<MaybeUninit<T>>` which is the
// inverse of `Box::assume_init()` and should be safe.
let mut raw: Box<mem::MaybeUninit<T>> = Box::from_raw(raw.cast());
let raw: Box<mem::MaybeUninit<T>> = Box::from_raw(raw.cast());
// SAFETY: Write the mapped value back into the `Box`.
raw.write(f(value)?);
// SAFETY: We just initialized `raw`.
raw.assume_init()
Box::write(raw, f(value)?)
})
}
}
Expand Down
137 changes: 132 additions & 5 deletions compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::infer::type_variable::TypeVariableOriginKind;
use crate::infer::InferCtxt;
use crate::infer::{InferCtxt, Symbol};
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Namespace};
Expand All @@ -10,7 +10,7 @@ use rustc_middle::hir::map::Map;
use rustc_middle::infer::unify_key::ConstVariableOriginKind;
use rustc_middle::ty::print::Print;
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
use rustc_middle::ty::{self, DefIdTree, InferConst, Ty, TyCtxt};
use rustc_middle::ty::{self, Const, DefIdTree, InferConst, Ty, TyCtxt, TypeFoldable, TypeFolder};
use rustc_span::symbol::kw;
use rustc_span::Span;
use std::borrow::Cow;
Expand Down Expand Up @@ -305,6 +305,15 @@ pub enum UnderspecifiedArgKind {
Const { is_parameter: bool },
}

impl UnderspecifiedArgKind {
fn descr(&self) -> &'static str {
match self {
Self::Type { .. } => "type",
Self::Const { .. } => "const",
}
}
}

impl InferenceDiagnosticsData {
/// Generate a label for a generic argument which can't be inferred. When not
/// much is known about the argument, `use_diag` may be used to describe the
Expand Down Expand Up @@ -548,6 +557,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}
}

let param_type = arg_data.kind.descr();
let suffix = match local_visitor.found_node_ty {
Some(ty) if ty.is_closure() => {
let substs =
Expand Down Expand Up @@ -586,13 +596,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}
Some(ty) if is_named_and_not_impl_trait(ty) && arg_data.name == "_" => {
let ty = ty_to_string(ty);
format!("the explicit type `{}`, with the type parameters specified", ty)
format!("the explicit type `{}`, with the {} parameters specified", ty, param_type)
}
Some(ty) if is_named_and_not_impl_trait(ty) && ty.to_string() != arg_data.name => {
let ty = ResolvedTypeParamEraser::new(self.tcx).fold_ty(ty).unwrap();
let ty = ErrTypeParamEraser(self.tcx).fold_ty(ty).unwrap();
let ty = ty_to_string(ty);
format!(
"the explicit type `{}`, where the type parameter `{}` is specified",
ty, arg_data.name,
"the explicit type `{}`, where the {} parameter `{}` is specified",
ty, param_type, arg_data.name,
)
}
_ => "a type".to_string(),
Expand Down Expand Up @@ -868,3 +880,118 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
err
}
}

/// Turn *resolved* type params into `[type error]` to signal we don't want to display them. After
/// performing that replacement, we'll turn all remaining infer type params to use their name from
/// their definition, and replace all the `[type error]`s back to being infer so they display in
/// the output as `_`. If we didn't go through `[type error]`, we would either show all type params
/// by their name *or* `_`, neither of which is desireable: we want to show all types that we could
/// infer as `_` to reduce verbosity and avoid telling the user about unnecessary type annotations.
struct ResolvedTypeParamEraser<'tcx> {
tcx: TyCtxt<'tcx>,
level: usize,
}

impl<'tcx> ResolvedTypeParamEraser<'tcx> {
fn new(tcx: TyCtxt<'tcx>) -> Self {
ResolvedTypeParamEraser { tcx, level: 0 }
}

/// Replace not yet inferred const params with their def name.
fn replace_infers(&self, c: &'tcx Const<'tcx>, index: u32, name: Symbol) -> &'tcx Const<'tcx> {
match c.val {
ty::ConstKind::Infer(..) => self.tcx().mk_const_param(index, name, c.ty),
_ => c,
}
}
}

impl<'tcx> TypeFolder<'tcx> for ResolvedTypeParamEraser<'tcx> {
fn tcx<'a>(&'a self) -> TyCtxt<'tcx> {
self.tcx
}
fn fold_ty(&mut self, t: Ty<'tcx>) -> Result<Ty<'tcx>, !> {
self.level += 1;
let t = match t.kind() {
// We'll hide this type only if all its type params are hidden as well.
ty::Adt(def, substs) => {
let generics = self.tcx().generics_of(def.did);
// Account for params with default values, like `Vec`, where we
// want to show `Vec<T>`, not `Vec<T, _>`. If we replaced that
// subst, then we'd get the incorrect output, so we passthrough.
let substs = substs
.iter()
.zip(generics.params.iter())
.map(|(subst, param)| match &(subst.unpack(), &param.kind) {
(_, ty::GenericParamDefKind::Type { has_default: true, .. }) => Ok(subst),
(crate::infer::GenericArgKind::Const(c), _) => {
Ok(self.replace_infers(c, param.index, param.name).into())
}
_ => subst.super_fold_with(self),
})
.collect::<Result<Vec<_>, !>>()?;
let should_keep = |subst: &GenericArg<'_>| match subst.unpack() {
ty::subst::GenericArgKind::Type(t) => match t.kind() {
ty::Error(_) => false,
_ => true,
},
// Account for `const` params here, otherwise `doesnt_infer.rs`
// shows `_` instead of `Foo<{ _: u32 }>`
ty::subst::GenericArgKind::Const(_) => true,
_ => false,
};
if self.level == 1 || substs.iter().any(should_keep) {
let substs = self.tcx().intern_substs(&substs[..]);
self.tcx().mk_ty(ty::Adt(def, substs))
} else {
self.tcx().ty_error()
}
}
ty::Ref(_, ty, _) => {
let ty = self.fold_ty(ty)?;
match ty.kind() {
// Avoid `&_`, these can be safely presented as `_`.
ty::Error(_) => self.tcx().ty_error(),
_ => t.super_fold_with(self)?,
}
}
// We could account for `()` if we wanted to replace it, but it's assured to be short.
ty::Tuple(_)
| ty::Slice(_)
| ty::RawPtr(_)
| ty::FnDef(..)
| ty::FnPtr(_)
| ty::Opaque(..)
| ty::Projection(_)
| ty::Never => t.super_fold_with(self)?,
ty::Array(ty, c) => self.tcx().mk_ty(ty::Array(
self.fold_ty(ty)?,
self.replace_infers(c, 0, Symbol::intern("N")),
)),
// We don't want to hide type params that haven't been resolved yet.
// This would be the type that will be written out with the type param
// name in the output.
ty::Infer(_) => t,
// We don't want to hide the outermost type, only its type params.
_ if self.level == 1 => t.super_fold_with(self)?,
// Hide this type
_ => self.tcx().ty_error(),
};
self.level -= 1;
Ok(t)
}
}

/// Replace `[type error]` with `ty::Infer(ty::Var)` to display `_`.
struct ErrTypeParamEraser<'tcx>(TyCtxt<'tcx>);
impl<'tcx> TypeFolder<'tcx> for ErrTypeParamEraser<'tcx> {
fn tcx<'a>(&'a self) -> TyCtxt<'tcx> {
self.0
}
fn fold_ty(&mut self, t: Ty<'tcx>) -> Result<Ty<'tcx>, !> {
match t.kind() {
ty::Error(_) => Ok(self.tcx().mk_ty_var(ty::TyVid::from_u32(0))),
_ => t.super_fold_with(self),
}
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
}
}

if sized && fields.iter().any(|f| f.abi.is_uninhabited()) {
if fields.iter().any(|f| f.abi.is_uninhabited()) {
abi = Abi::Uninhabited;
}

Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,10 +788,14 @@ impl<'tcx> ty::TyS<'tcx> {
[component_ty] => component_ty,
_ => self,
};

// This doesn't depend on regions, so try to minimize distinct
// query keys used.
let erased = tcx.normalize_erasing_regions(param_env, query_ty);
tcx.needs_drop_raw(param_env.and(erased))
// If normalization fails, we just use `query_ty`.
let query_ty =
tcx.try_normalize_erasing_regions(param_env, query_ty).unwrap_or(query_ty);

tcx.needs_drop_raw(param_env.and(query_ty))
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_ty_utils/src/needs_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ where
Ok(tys) => tys,
};
for required_ty in tys {
let required =
tcx.normalize_erasing_regions(self.param_env, required_ty);
let required = tcx
.try_normalize_erasing_regions(self.param_env, required_ty)
.unwrap_or(required_ty);

queue_type(self, required);
}
}
Expand Down
36 changes: 36 additions & 0 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,42 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
let (raw, alloc) = Box::into_raw_with_allocator(self);
unsafe { Box::from_raw_in(raw as *mut T, alloc) }
}

/// Writes the value and converts to `Box<T, A>`.
///
/// This method converts the box similarly to [`Box::assume_init`] but
/// writes `value` into it before conversion thus guaranteeing safety.
/// In some scenarios use of this method may improve performance because
/// the compiler may be able to optimize copying from stack.
///
/// # Examples
///
/// ```
/// #![feature(new_uninit)]
///
/// let big_box = Box::<[usize; 1024]>::new_uninit();
///
/// let mut array = [0; 1024];
/// for (i, place) in array.iter_mut().enumerate() {
/// *place = i;
/// }
///
/// // The optimizer may be able to elide this copy, so previous code writes
/// // to heap directly.
/// let big_box = Box::write(big_box, array);
///
/// for (i, x) in big_box.iter().enumerate() {
/// assert_eq!(*x, i);
/// }
/// ```
#[unstable(feature = "new_uninit", issue = "63291")]
#[inline]
pub fn write(mut boxed: Self, value: T) -> Box<T, A> {
unsafe {
(*boxed).write(value);
boxed.assume_init()
}
}
}

impl<T, A: Allocator> Box<[mem::MaybeUninit<T>], A> {
Expand Down
5 changes: 3 additions & 2 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,8 @@ impl<T> Option<T> {
#[inline]
#[track_caller]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn expect(self, msg: &str) -> T {
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
pub const fn expect(self, msg: &str) -> T {
match self {
Some(val) => val,
None => expect_failed(msg),
Expand Down Expand Up @@ -1658,7 +1659,7 @@ impl<T, E> Option<Result<T, E>> {
#[inline(never)]
#[cold]
#[track_caller]
fn expect_failed(msg: &str) -> ! {
const fn expect_failed(msg: &str) -> ! {
panic!("{}", msg)
}

Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub fn errno() -> i32 {
}

#[cfg(target_os = "dragonfly")]
#[allow(dead_code)]
pub fn set_errno(e: i32) {
extern "C" {
#[thread_local]
Expand Down
14 changes: 14 additions & 0 deletions library/std/src/thread/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,21 @@ use crate::fmt;
/// destroyed, but not all platforms have this guard. Those platforms that do
/// not guard typically have a synthetic limit after which point no more
/// destructors are run.
/// 3. When the process exits on Windows systems, TLS destructors may only be
/// run on the thread that causes the process to exit. This is because the
/// other threads may be forcibly terminated.
///
/// ## Synchronization in thread-local destructors
///
/// On Windows, synchronization operations (such as [`JoinHandle::join`]) in
/// thread local destructors are prone to deadlocks and so should be avoided.
/// This is because the [loader lock] is held while a destructor is run. The
/// lock is acquired whenever a thread starts or exits or when a DLL is loaded
/// or unloaded. Therefore these events are blocked for as long as a thread
/// local destructor is running.
///
/// [loader lock]: https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-best-practices
/// [`JoinHandle::join`]: crate::thread::JoinHandle::join
/// [`with`]: LocalKey::with
#[stable(feature = "rust1", since = "1.0.0")]
pub struct LocalKey<T: 'static> {
Expand Down
3 changes: 3 additions & 0 deletions library/unwind/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ fn main() {
} else {
println!("cargo:rustc-link-lib=gcc");
}

// Android's unwinding library depends on dl_iterate_phdr in `libdl`.
println!("cargo:rustc-link-lib=dl");
} else if target.contains("freebsd") {
println!("cargo:rustc-link-lib=gcc_s");
} else if target.contains("netbsd") {
Expand Down
6 changes: 6 additions & 0 deletions src/librustdoc/html/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<meta name="description" content="{{page.description}}"> {#- -#}
<meta name="keywords" content="{{page.keywords}}"> {#- -#}
<title>{{page.title}}</title> {#- -#}
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path | safe}}SourceSerif4-Regular.ttf.woff2"> {#- -#}
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path | safe}}FiraSans-Regular.woff2"> {#- -#}
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path | safe}}FiraSans-Medium.woff2"> {#- -#}
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path | safe}}SourceCodePro-Regular.ttf.woff2"> {#- -#}
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path | safe}}SourceSerif4-Bold.ttf.woff2"> {#- -#}
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path | safe}}SourceCodePro-Semibold.ttf.woff2"> {#- -#}
<link rel="stylesheet" type="text/css" {# -#}
href="{{static_root_path | safe}}normalize{{page.resource_suffix}}.css"> {#- -#}
<link rel="stylesheet" type="text/css" {# -#}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/defaults/doesnt_infer.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0282]: type annotations needed for `Foo<{_: u32}>`
LL | let foo = Foo::foo();
| --- ^^^^^^^^ cannot infer the value of const parameter `N`
| |
| consider giving `foo` the explicit type `Foo<{_: u32}>`, where the type parameter `N` is specified
| consider giving `foo` the explicit type `Foo<N>`, where the const parameter `N` is specified

error: aborting due to previous error

Expand Down
Loading