Skip to content

Rollup of 11 pull requests #103452

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

Merged
merged 24 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
289ad1a
Clarify `array:from_fn` documentation
zohnannor Aug 12, 2022
908bdea
Document surprising and dangerous fs::Permissions behaviour on Unix
Timmmm Sep 10, 2022
76bec17
kmc-solid: Handle errors returned by `SOLID_FS_ReadDir`
kawadakk Oct 13, 2022
f543770
rustdoc: Do not filter out `Self: Sized` bounds
fmease Oct 19, 2022
1225c3f
fix #103112, add diagnostic for calling a function with the same name…
chenyukang Oct 16, 2022
f90bf50
fix span for suggestion
chenyukang Oct 17, 2022
bdc4acb
bootstrap: also create rustc-src component in sysroot
RalfJung Oct 21, 2022
c0cda2b
Pretty print lifetimes captured by RPIT
compiler-errors Oct 22, 2022
36662df
Fix wrapped valid-range handling in ty_find_init_error
joshtriplett Oct 22, 2022
7ff9bc1
rustdoc: remove no-op CSS `.code-header { border-bottom: none }`
notriddle Oct 23, 2022
f112c3a
Use functions for jump-to-def-background rustodoc GUI test
GuillaumeGomez Oct 23, 2022
560433a
MaybeUninit: use assume_init_drop() in the partially initialized arra…
ajtribick Oct 23, 2022
c5df620
Annotate static lifetimes too
compiler-errors Oct 23, 2022
acc269d
Rollup merge of #100462 - zohnannor:master, r=thomcc
notriddle Oct 23, 2022
214fa9f
Rollup merge of #101644 - Timmmm:file_permissions_docs, r=thomcc
notriddle Oct 23, 2022
23d1b05
Rollup merge of #103005 - solid-rs:patch/kmc-solid/readdir-terminator…
notriddle Oct 23, 2022
3df030d
Rollup merge of #103140 - chenyukang:yukang/fix-103112, r=estebank
notriddle Oct 23, 2022
28a1baf
Rollup merge of #103254 - fmease:fix-24183, r=GuillaumeGomez
notriddle Oct 23, 2022
646e0d3
Rollup merge of #103347 - RalfJung:rustc-src, r=Mark-Simulacrum
notriddle Oct 23, 2022
9f06fbd
Rollup merge of #103402 - joshtriplett:niche-wrap-fix, r=oli-obk
notriddle Oct 23, 2022
039e9b6
Rollup merge of #103414 - compiler-errors:rpit-print-lt, r=cjgillot
notriddle Oct 23, 2022
88e0546
Rollup merge of #103424 - notriddle:notriddle/code-header-border-bott…
notriddle Oct 23, 2022
296700e
Rollup merge of #103434 - GuillaumeGomez:gui-test-jump-to-def-backgro…
notriddle Oct 23, 2022
ae2b1f0
Rollup merge of #103447 - ajtribick:maybe_uninit_doc_update, r=scottmcm
notriddle Oct 23, 2022
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
5 changes: 4 additions & 1 deletion compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2526,7 +2526,10 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
// return `Bound::Excluded`. (And we have tests checking that we
// handle the attribute correctly.)
// We don't add a span since users cannot declare such types anyway.
(Bound::Included(lo), _) if lo > 0 => {
(Bound::Included(lo), Bound::Included(hi)) if 0 < lo && lo < hi => {
return Some((format!("`{}` must be non-null", ty), None));
}
(Bound::Included(lo), Bound::Unbounded) if 0 < lo => {
return Some((format!("`{}` must be non-null", ty), None));
}
(Bound::Included(_), _) | (_, Bound::Included(_))
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use rustc_session::cstore::{ExternCrate, ExternCrateSource};
use rustc_span::symbol::{kw, Ident, Symbol};
use rustc_target::abi::Size;
use rustc_target::spec::abi::Abi;
use smallvec::SmallVec;

use std::cell::Cell;
use std::char;
Expand Down Expand Up @@ -794,6 +795,7 @@ pub trait PrettyPrinter<'tcx>:
let mut traits = FxIndexMap::default();
let mut fn_traits = FxIndexMap::default();
let mut is_sized = false;
let mut lifetimes = SmallVec::<[ty::Region<'tcx>; 1]>::new();

for (predicate, _) in bounds.subst_iter_copied(tcx, substs) {
let bound_predicate = predicate.kind();
Expand Down Expand Up @@ -824,6 +826,9 @@ pub trait PrettyPrinter<'tcx>:
&mut fn_traits,
);
}
ty::PredicateKind::TypeOutlives(outlives) => {
lifetimes.push(outlives.1);
}
_ => {}
}
}
Expand Down Expand Up @@ -977,6 +982,11 @@ pub trait PrettyPrinter<'tcx>:
write!(self, "Sized")?;
}

for re in lifetimes {
write!(self, " + ")?;
self = self.print_region(re)?;
}

Ok(self)
}

Expand Down
16 changes: 14 additions & 2 deletions compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_attr::StabilityLevel;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::intern::Interned;
use rustc_data_structures::sync::Lrc;
use rustc_errors::struct_span_err;
use rustc_errors::{struct_span_err, Applicability};
use rustc_expand::base::{Annotatable, DeriveResolutions, Indeterminate, ResolverExpand};
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
use rustc_expand::compile_declarative_macro;
Expand Down Expand Up @@ -694,7 +694,19 @@ impl<'a> Resolver<'a> {
check_consistency(self, &path, path_span, kind, initial_res, res)
}
path_res @ PathResult::NonModule(..) | path_res @ PathResult::Failed { .. } => {
let mut suggestion = None;
let (span, label) = if let PathResult::Failed { span, label, .. } = path_res {
// try to suggest if it's not a macro, maybe a function
if let PathResult::NonModule(partial_res) = self.maybe_resolve_path(&path, Some(ValueNS), &parent_scope)
&& partial_res.unresolved_segments() == 0 {
let sm = self.session.source_map();
let exclamation_span = sm.next_point(span);
suggestion = Some((
vec![(exclamation_span, "".to_string())],
format!("{} is not a macro, but a {}, try to remove `!`", Segment::names_to_string(&path), partial_res.base_res().descr()),
Applicability::MaybeIncorrect
));
}
(span, label)
} else {
(
Expand All @@ -708,7 +720,7 @@ impl<'a> Resolver<'a> {
};
self.report_error(
span,
ResolutionError::FailedToResolve { label, suggestion: None },
ResolutionError::FailedToResolve { label, suggestion },
);
}
PathResult::Module(..) | PathResult::Indeterminate => unreachable!(),
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ pub use iter::IntoIter;
/// # Example
///
/// ```rust
/// // type inference is helping us here, the way `from_fn` knows how many
/// // elements to produce is the length of array down there: only arrays of
/// // equal lengths can be compared, so the const generic parameter `N` is
/// // inferred to be 5, thus creating array of 5 elements.
/// let array = core::array::from_fn(|i| i);
/// assert_eq!(array, [0, 1, 2, 3, 4]);
/// ```
Expand Down
3 changes: 1 addition & 2 deletions library/core/src/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ use crate::slice;
///
/// ```
/// use std::mem::MaybeUninit;
/// use std::ptr;
///
/// // Create an uninitialized array of `MaybeUninit`. The `assume_init` is
/// // safe because the type we are claiming to have initialized here is a
Expand All @@ -162,7 +161,7 @@ use crate::slice;
///
/// // For each item in the array, drop if we allocated it.
/// for elem in &mut data[0..data_len] {
/// unsafe { ptr::drop_in_place(elem.as_mut_ptr()); }
/// unsafe { elem.assume_init_drop(); }
/// }
/// ```
///
Expand Down
67 changes: 64 additions & 3 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,34 @@ impl FileTimes {
impl Permissions {
/// Returns `true` if these permissions describe a readonly (unwritable) file.
///
/// # Note
///
/// This function does not take Access Control Lists (ACLs) or Unix group
/// membership into account.
///
/// # Windows
///
/// On Windows this returns [`FILE_ATTRIBUTE_READONLY`](https://docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants).
/// If `FILE_ATTRIBUTE_READONLY` is set then writes to the file will fail
/// but the user may still have permission to change this flag. If
/// `FILE_ATTRIBUTE_READONLY` is *not* set then writes may still fail due
/// to lack of write permission.
/// The behavior of this attribute for directories depends on the Windows
/// version.
///
/// # Unix (including macOS)
///
/// On Unix-based platforms this checks if *any* of the owner, group or others
/// write permission bits are set. It does not check if the current
/// user is in the file's assigned group. It also does not check ACLs.
/// Therefore even if this returns true you may not be able to write to the
/// file, and vice versa. The [`PermissionsExt`] trait gives direct access
/// to the permission bits but also does not read ACLs. If you need to
/// accurately know whether or not a file is writable use the `access()`
/// function from libc.
///
/// [`PermissionsExt`]: crate::os::unix::fs::PermissionsExt
///
/// # Examples
///
/// ```no_run
Expand All @@ -1390,8 +1418,40 @@ impl Permissions {
/// using the resulting `Permission` will update file permissions to allow
/// writing.
///
/// This operation does **not** modify the filesystem. To modify the
/// filesystem use the [`set_permissions`] function.
/// This operation does **not** modify the files attributes. This only
/// changes the in-memory value of these attributes for this `Permissions`
/// instance. To modify the files attributes use the [`set_permissions`]
/// function which commits these attribute changes to the file.
///
/// # Note
///
/// `set_readonly(false)` makes the file *world-writable* on Unix.
/// You can use the [`PermissionsExt`] trait on Unix to avoid this issue.
///
/// It also does not take Access Control Lists (ACLs) or Unix group
/// membership into account.
///
/// # Windows
///
/// On Windows this sets or clears [`FILE_ATTRIBUTE_READONLY`](https://docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants).
/// If `FILE_ATTRIBUTE_READONLY` is set then writes to the file will fail
/// but the user may still have permission to change this flag. If
/// `FILE_ATTRIBUTE_READONLY` is *not* set then the write may still fail if
/// the user does not have permission to write to the file.
///
/// In Windows 7 and earlier this attribute prevents deleting empty
/// directories. It does not prevent modifying the directory contents.
/// On later versions of Windows this attribute is ignored for directories.
///
/// # Unix (including macOS)
///
/// On Unix-based platforms this sets or clears the write access bit for
/// the owner, group *and* others, equivalent to `chmod a+w <file>`
/// or `chmod a-w <file>` respectively. The latter will grant write access
/// to all users! You can use the [`PermissionsExt`] trait on Unix
/// to avoid this issue.
///
/// [`PermissionsExt`]: crate::os::unix::fs::PermissionsExt
///
/// # Examples
///
Expand All @@ -1405,7 +1465,8 @@ impl Permissions {
///
/// permissions.set_readonly(true);
///
/// // filesystem doesn't change
/// // filesystem doesn't change, only the in memory state of the
/// // readonly permission
/// assert_eq!(false, metadata.permissions().readonly());
///
/// // just this particular `permissions`.
Expand Down
20 changes: 12 additions & 8 deletions library/std/src/sys/solid/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,19 @@ impl Iterator for ReadDir {
type Item = io::Result<DirEntry>;

fn next(&mut self) -> Option<io::Result<DirEntry>> {
unsafe {
let mut out_dirent = MaybeUninit::uninit();
error::SolidError::err_if_negative(abi::SOLID_FS_ReadDir(
let entry = unsafe {
let mut out_entry = MaybeUninit::uninit();
match error::SolidError::err_if_negative(abi::SOLID_FS_ReadDir(
self.inner.dirp,
out_dirent.as_mut_ptr(),
))
.ok()?;
Some(Ok(DirEntry { entry: out_dirent.assume_init(), inner: Arc::clone(&self.inner) }))
}
out_entry.as_mut_ptr(),
)) {
Ok(_) => out_entry.assume_init(),
Err(e) if e.as_raw() == abi::SOLID_ERR_NOTFOUND => return None,
Err(e) => return Some(Err(e.as_io_error())),
}
};

(entry.d_name[0] != 0).then(|| Ok(DirEntry { entry, inner: Arc::clone(&self.inner) }))
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,20 @@ impl Step for Sysroot {
);
}
}
// Same for the rustc-src component.
let sysroot_lib_rustlib_rustcsrc = sysroot.join("lib/rustlib/rustc-src");
t!(fs::create_dir_all(&sysroot_lib_rustlib_rustcsrc));
let sysroot_lib_rustlib_rustcsrc_rust = sysroot_lib_rustlib_rustcsrc.join("rust");
if let Err(e) =
symlink_dir(&builder.config, &builder.src, &sysroot_lib_rustlib_rustcsrc_rust)
{
eprintln!(
"warning: creating symbolic link `{}` to `{}` failed with {}",
sysroot_lib_rustlib_rustcsrc_rust.display(),
builder.src.display(),
e,
);
}

INTERNER.intern_path(sysroot)
}
Expand Down
41 changes: 23 additions & 18 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,31 +774,36 @@ fn clean_ty_generics<'tcx>(
let mut where_predicates =
where_predicates.into_iter().flat_map(|p| clean_predicate(*p, cx)).collect::<Vec<_>>();

// Type parameters have a Sized bound by default unless removed with
// ?Sized. Scan through the predicates and mark any type parameter with
// a Sized bound, removing the bounds as we find them.
// In the surface language, all type parameters except `Self` have an
// implicit `Sized` bound unless removed with `?Sized`.
// However, in the list of where-predicates below, `Sized` appears like a
// normal bound: It's either present (the type is sized) or
// absent (the type is unsized) but never *maybe* (i.e. `?Sized`).
//
// Note that associated types also have a sized bound by default, but we
// This is unsuitable for rendering.
// Thus, as a first step remove all `Sized` bounds that should be implicit.
//
// Note that associated types also have an implicit `Sized` bound but we
// don't actually know the set of associated types right here so that's
// handled in cleaning associated types
// handled when cleaning associated types.
let mut sized_params = FxHashSet::default();
where_predicates.retain(|pred| match *pred {
WherePredicate::BoundPredicate { ty: Generic(ref g), ref bounds, .. } => {
if bounds.iter().any(|b| b.is_sized_bound(cx)) {
sized_params.insert(*g);
false
} else {
true
}
where_predicates.retain(|pred| {
if let WherePredicate::BoundPredicate { ty: Generic(g), bounds, .. } = pred
&& *g != kw::SelfUpper
&& bounds.iter().any(|b| b.is_sized_bound(cx))
{
sized_params.insert(*g);
false
} else {
true
}
_ => true,
});

// Run through the type parameters again and insert a ?Sized
// unbound for any we didn't find to be Sized.
// As a final step, go through the type parameters again and insert a
// `?Sized` bound for each one we didn't find to be `Sized`.
for tp in &stripped_params {
if matches!(tp.kind, types::GenericParamDefKind::Type { .. })
&& !sized_params.contains(&tp.name)
if let types::GenericParamDefKind::Type { .. } = tp.kind
&& !sized_params.contains(&tp.name)
{
where_predicates.push(WherePredicate::BoundPredicate {
ty: Type::Generic(tp.name),
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ h4.code-header {
}
.code-header {
font-weight: 600;
border-bottom-style: none;
margin: 0;
padding: 0;
}
Expand Down
55 changes: 17 additions & 38 deletions src/test/rustdoc-gui/jump-to-def-background.goml
Original file line number Diff line number Diff line change
@@ -1,43 +1,22 @@
// We check the background color on the jump to definition links in the source code page.
goto: "file://" + |DOC_PATH| + "/src/link_to_definition/lib.rs.html"

// Set the theme to dark.
local-storage: {
"rustdoc-theme": "dark",
"rustdoc-preferred-dark-theme": "dark",
"rustdoc-use-system-theme": "false",
}
// We reload the page so the local storage settings are being used.
reload:

assert-css: (
"body.source .example-wrap pre.rust a",
{"background-color": "rgb(51, 51, 51)"},
ALL,
)

// Set the theme to ayu.
local-storage: {
"rustdoc-theme": "ayu",
"rustdoc-preferred-dark-theme": "ayu",
"rustdoc-use-system-theme": "false",
}
// We reload the page so the local storage settings are being used.
reload:

assert-css: (
"body.source .example-wrap pre.rust a",
{"background-color": "rgb(51, 51, 51)"},
ALL,
define-function: (
"check-background-color",
(theme, background_color),
[
// Set the theme.
("local-storage", { "rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false" }),
// We reload the page so the local storage settings are being used.
("reload"),
("assert-css", (
"body.source .example-wrap pre.rust a",
{"background-color": |background_color|},
ALL,
)),
],
)

// Set the theme to light.
local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"}
// We reload the page so the local storage settings are being used.
reload:

assert-css: (
"body.source .example-wrap pre.rust a",
{"background-color": "rgb(238, 238, 238)"},
ALL,
)
call-function: ("check-background-color", ("ayu", "rgb(51, 51, 51)"))
call-function: ("check-background-color", ("dark", "rgb(51, 51, 51)"))
call-function: ("check-background-color", ("light", "rgb(238, 238, 238)"))
14 changes: 14 additions & 0 deletions src/test/rustdoc/inline_cross/auxiliary/issue-24183.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![crate_type = "lib"]

pub trait U/*: ?Sized */ {
fn modified(self) -> Self
where
Self: Sized
{
self
}

fn touch(&self)/* where Self: ?Sized */{}
}

pub trait S: Sized {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h4 class="code-header">fn <a href="#method.touch" class="fnname">touch</a>(&amp;self)</h4>
Loading