Skip to content

Commit 7feb003

Browse files
committed
Auto merge of rust-lang#103452 - notriddle:rollup-peewevm, r=notriddle
Rollup of 11 pull requests Successful merges: - rust-lang#100462 (Clarify `array::from_fn` documentation) - rust-lang#101644 (Document surprising and dangerous fs::Permissions behaviour on Unix) - rust-lang#103005 (kmc-solid: Handle errors returned by `SOLID_FS_ReadDir`) - rust-lang#103140 (Add diagnostic for calling a function with the same name with unresolved Macro) - rust-lang#103254 (rustdoc: do not filter out cross-crate `Self: Sized` bounds) - rust-lang#103347 (bootstrap: also create rustc-src component in sysroot) - rust-lang#103402 (Fix wrapped valid-range handling in ty_find_init_error) - rust-lang#103414 (Pretty print lifetimes captured by RPIT) - rust-lang#103424 (rustdoc: remove no-op CSS `.code-header { border-bottom: none }`) - rust-lang#103434 (Use functions for jump-to-def-background rustdoc GUI test) - rust-lang#103447 (`MaybeUninit`: use `assume_init_drop()` in the partially initialized array example) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7aa3613 + ae2b1f0 commit 7feb003

File tree

23 files changed

+305
-145
lines changed

23 files changed

+305
-145
lines changed

compiler/rustc_lint/src/builtin.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2526,7 +2526,10 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
25262526
// return `Bound::Excluded`. (And we have tests checking that we
25272527
// handle the attribute correctly.)
25282528
// We don't add a span since users cannot declare such types anyway.
2529-
(Bound::Included(lo), _) if lo > 0 => {
2529+
(Bound::Included(lo), Bound::Included(hi)) if 0 < lo && lo < hi => {
2530+
return Some((format!("`{}` must be non-null", ty), None));
2531+
}
2532+
(Bound::Included(lo), Bound::Unbounded) if 0 < lo => {
25302533
return Some((format!("`{}` must be non-null", ty), None));
25312534
}
25322535
(Bound::Included(_), _) | (_, Bound::Included(_))

compiler/rustc_middle/src/ty/print/pretty.rs

+10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_session::cstore::{ExternCrate, ExternCrateSource};
1616
use rustc_span::symbol::{kw, Ident, Symbol};
1717
use rustc_target::abi::Size;
1818
use rustc_target::spec::abi::Abi;
19+
use smallvec::SmallVec;
1920

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

798800
for (predicate, _) in bounds.subst_iter_copied(tcx, substs) {
799801
let bound_predicate = predicate.kind();
@@ -824,6 +826,9 @@ pub trait PrettyPrinter<'tcx>:
824826
&mut fn_traits,
825827
);
826828
}
829+
ty::PredicateKind::TypeOutlives(outlives) => {
830+
lifetimes.push(outlives.1);
831+
}
827832
_ => {}
828833
}
829834
}
@@ -977,6 +982,11 @@ pub trait PrettyPrinter<'tcx>:
977982
write!(self, "Sized")?;
978983
}
979984

985+
for re in lifetimes {
986+
write!(self, " + ")?;
987+
self = self.print_region(re)?;
988+
}
989+
980990
Ok(self)
981991
}
982992

compiler/rustc_resolve/src/macros.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_attr::StabilityLevel;
1212
use rustc_data_structures::fx::FxHashSet;
1313
use rustc_data_structures::intern::Interned;
1414
use rustc_data_structures::sync::Lrc;
15-
use rustc_errors::struct_span_err;
15+
use rustc_errors::{struct_span_err, Applicability};
1616
use rustc_expand::base::{Annotatable, DeriveResolutions, Indeterminate, ResolverExpand};
1717
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
1818
use rustc_expand::compile_declarative_macro;
@@ -694,7 +694,19 @@ impl<'a> Resolver<'a> {
694694
check_consistency(self, &path, path_span, kind, initial_res, res)
695695
}
696696
path_res @ PathResult::NonModule(..) | path_res @ PathResult::Failed { .. } => {
697+
let mut suggestion = None;
697698
let (span, label) = if let PathResult::Failed { span, label, .. } = path_res {
699+
// try to suggest if it's not a macro, maybe a function
700+
if let PathResult::NonModule(partial_res) = self.maybe_resolve_path(&path, Some(ValueNS), &parent_scope)
701+
&& partial_res.unresolved_segments() == 0 {
702+
let sm = self.session.source_map();
703+
let exclamation_span = sm.next_point(span);
704+
suggestion = Some((
705+
vec![(exclamation_span, "".to_string())],
706+
format!("{} is not a macro, but a {}, try to remove `!`", Segment::names_to_string(&path), partial_res.base_res().descr()),
707+
Applicability::MaybeIncorrect
708+
));
709+
}
698710
(span, label)
699711
} else {
700712
(
@@ -708,7 +720,7 @@ impl<'a> Resolver<'a> {
708720
};
709721
self.report_error(
710722
span,
711-
ResolutionError::FailedToResolve { label, suggestion: None },
723+
ResolutionError::FailedToResolve { label, suggestion },
712724
);
713725
}
714726
PathResult::Module(..) | PathResult::Indeterminate => unreachable!(),

library/core/src/array/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ pub use iter::IntoIter;
3232
/// # Example
3333
///
3434
/// ```rust
35+
/// // type inference is helping us here, the way `from_fn` knows how many
36+
/// // elements to produce is the length of array down there: only arrays of
37+
/// // equal lengths can be compared, so the const generic parameter `N` is
38+
/// // inferred to be 5, thus creating array of 5 elements.
3539
/// let array = core::array::from_fn(|i| i);
3640
/// assert_eq!(array, [0, 1, 2, 3, 4]);
3741
/// ```

library/core/src/mem/maybe_uninit.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ use crate::slice;
146146
///
147147
/// ```
148148
/// use std::mem::MaybeUninit;
149-
/// use std::ptr;
150149
///
151150
/// // Create an uninitialized array of `MaybeUninit`. The `assume_init` is
152151
/// // safe because the type we are claiming to have initialized here is a
@@ -162,7 +161,7 @@ use crate::slice;
162161
///
163162
/// // For each item in the array, drop if we allocated it.
164163
/// for elem in &mut data[0..data_len] {
165-
/// unsafe { ptr::drop_in_place(elem.as_mut_ptr()); }
164+
/// unsafe { elem.assume_init_drop(); }
166165
/// }
167166
/// ```
168167
///

library/std/src/fs.rs

+64-3
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,34 @@ impl FileTimes {
13651365
impl Permissions {
13661366
/// Returns `true` if these permissions describe a readonly (unwritable) file.
13671367
///
1368+
/// # Note
1369+
///
1370+
/// This function does not take Access Control Lists (ACLs) or Unix group
1371+
/// membership into account.
1372+
///
1373+
/// # Windows
1374+
///
1375+
/// On Windows this returns [`FILE_ATTRIBUTE_READONLY`](https://docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants).
1376+
/// If `FILE_ATTRIBUTE_READONLY` is set then writes to the file will fail
1377+
/// but the user may still have permission to change this flag. If
1378+
/// `FILE_ATTRIBUTE_READONLY` is *not* set then writes may still fail due
1379+
/// to lack of write permission.
1380+
/// The behavior of this attribute for directories depends on the Windows
1381+
/// version.
1382+
///
1383+
/// # Unix (including macOS)
1384+
///
1385+
/// On Unix-based platforms this checks if *any* of the owner, group or others
1386+
/// write permission bits are set. It does not check if the current
1387+
/// user is in the file's assigned group. It also does not check ACLs.
1388+
/// Therefore even if this returns true you may not be able to write to the
1389+
/// file, and vice versa. The [`PermissionsExt`] trait gives direct access
1390+
/// to the permission bits but also does not read ACLs. If you need to
1391+
/// accurately know whether or not a file is writable use the `access()`
1392+
/// function from libc.
1393+
///
1394+
/// [`PermissionsExt`]: crate::os::unix::fs::PermissionsExt
1395+
///
13681396
/// # Examples
13691397
///
13701398
/// ```no_run
@@ -1390,8 +1418,40 @@ impl Permissions {
13901418
/// using the resulting `Permission` will update file permissions to allow
13911419
/// writing.
13921420
///
1393-
/// This operation does **not** modify the filesystem. To modify the
1394-
/// filesystem use the [`set_permissions`] function.
1421+
/// This operation does **not** modify the files attributes. This only
1422+
/// changes the in-memory value of these attributes for this `Permissions`
1423+
/// instance. To modify the files attributes use the [`set_permissions`]
1424+
/// function which commits these attribute changes to the file.
1425+
///
1426+
/// # Note
1427+
///
1428+
/// `set_readonly(false)` makes the file *world-writable* on Unix.
1429+
/// You can use the [`PermissionsExt`] trait on Unix to avoid this issue.
1430+
///
1431+
/// It also does not take Access Control Lists (ACLs) or Unix group
1432+
/// membership into account.
1433+
///
1434+
/// # Windows
1435+
///
1436+
/// On Windows this sets or clears [`FILE_ATTRIBUTE_READONLY`](https://docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants).
1437+
/// If `FILE_ATTRIBUTE_READONLY` is set then writes to the file will fail
1438+
/// but the user may still have permission to change this flag. If
1439+
/// `FILE_ATTRIBUTE_READONLY` is *not* set then the write may still fail if
1440+
/// the user does not have permission to write to the file.
1441+
///
1442+
/// In Windows 7 and earlier this attribute prevents deleting empty
1443+
/// directories. It does not prevent modifying the directory contents.
1444+
/// On later versions of Windows this attribute is ignored for directories.
1445+
///
1446+
/// # Unix (including macOS)
1447+
///
1448+
/// On Unix-based platforms this sets or clears the write access bit for
1449+
/// the owner, group *and* others, equivalent to `chmod a+w <file>`
1450+
/// or `chmod a-w <file>` respectively. The latter will grant write access
1451+
/// to all users! You can use the [`PermissionsExt`] trait on Unix
1452+
/// to avoid this issue.
1453+
///
1454+
/// [`PermissionsExt`]: crate::os::unix::fs::PermissionsExt
13951455
///
13961456
/// # Examples
13971457
///
@@ -1405,7 +1465,8 @@ impl Permissions {
14051465
///
14061466
/// permissions.set_readonly(true);
14071467
///
1408-
/// // filesystem doesn't change
1468+
/// // filesystem doesn't change, only the in memory state of the
1469+
/// // readonly permission
14091470
/// assert_eq!(false, metadata.permissions().readonly());
14101471
///
14111472
/// // just this particular `permissions`.

library/std/src/sys/solid/fs.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,19 @@ impl Iterator for ReadDir {
175175
type Item = io::Result<DirEntry>;
176176

177177
fn next(&mut self) -> Option<io::Result<DirEntry>> {
178-
unsafe {
179-
let mut out_dirent = MaybeUninit::uninit();
180-
error::SolidError::err_if_negative(abi::SOLID_FS_ReadDir(
178+
let entry = unsafe {
179+
let mut out_entry = MaybeUninit::uninit();
180+
match error::SolidError::err_if_negative(abi::SOLID_FS_ReadDir(
181181
self.inner.dirp,
182-
out_dirent.as_mut_ptr(),
183-
))
184-
.ok()?;
185-
Some(Ok(DirEntry { entry: out_dirent.assume_init(), inner: Arc::clone(&self.inner) }))
186-
}
182+
out_entry.as_mut_ptr(),
183+
)) {
184+
Ok(_) => out_entry.assume_init(),
185+
Err(e) if e.as_raw() == abi::SOLID_ERR_NOTFOUND => return None,
186+
Err(e) => return Some(Err(e.as_io_error())),
187+
}
188+
};
189+
190+
(entry.d_name[0] != 0).then(|| Ok(DirEntry { entry, inner: Arc::clone(&self.inner) }))
187191
}
188192
}
189193

src/bootstrap/compile.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,20 @@ impl Step for Sysroot {
11771177
);
11781178
}
11791179
}
1180+
// Same for the rustc-src component.
1181+
let sysroot_lib_rustlib_rustcsrc = sysroot.join("lib/rustlib/rustc-src");
1182+
t!(fs::create_dir_all(&sysroot_lib_rustlib_rustcsrc));
1183+
let sysroot_lib_rustlib_rustcsrc_rust = sysroot_lib_rustlib_rustcsrc.join("rust");
1184+
if let Err(e) =
1185+
symlink_dir(&builder.config, &builder.src, &sysroot_lib_rustlib_rustcsrc_rust)
1186+
{
1187+
eprintln!(
1188+
"warning: creating symbolic link `{}` to `{}` failed with {}",
1189+
sysroot_lib_rustlib_rustcsrc_rust.display(),
1190+
builder.src.display(),
1191+
e,
1192+
);
1193+
}
11801194

11811195
INTERNER.intern_path(sysroot)
11821196
}

src/librustdoc/clean/mod.rs

+23-18
Original file line numberDiff line numberDiff line change
@@ -774,31 +774,36 @@ fn clean_ty_generics<'tcx>(
774774
let mut where_predicates =
775775
where_predicates.into_iter().flat_map(|p| clean_predicate(*p, cx)).collect::<Vec<_>>();
776776

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

797-
// Run through the type parameters again and insert a ?Sized
798-
// unbound for any we didn't find to be Sized.
802+
// As a final step, go through the type parameters again and insert a
803+
// `?Sized` bound for each one we didn't find to be `Sized`.
799804
for tp in &stripped_params {
800-
if matches!(tp.kind, types::GenericParamDefKind::Type { .. })
801-
&& !sized_params.contains(&tp.name)
805+
if let types::GenericParamDefKind::Type { .. } = tp.kind
806+
&& !sized_params.contains(&tp.name)
802807
{
803808
where_predicates.push(WherePredicate::BoundPredicate {
804809
ty: Type::Generic(tp.name),

src/librustdoc/html/static/css/rustdoc.css

-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ h4.code-header {
184184
}
185185
.code-header {
186186
font-weight: 600;
187-
border-bottom-style: none;
188187
margin: 0;
189188
padding: 0;
190189
}
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,22 @@
11
// We check the background color on the jump to definition links in the source code page.
22
goto: "file://" + |DOC_PATH| + "/src/link_to_definition/lib.rs.html"
33

4-
// Set the theme to dark.
5-
local-storage: {
6-
"rustdoc-theme": "dark",
7-
"rustdoc-preferred-dark-theme": "dark",
8-
"rustdoc-use-system-theme": "false",
9-
}
10-
// We reload the page so the local storage settings are being used.
11-
reload:
12-
13-
assert-css: (
14-
"body.source .example-wrap pre.rust a",
15-
{"background-color": "rgb(51, 51, 51)"},
16-
ALL,
17-
)
18-
19-
// Set the theme to ayu.
20-
local-storage: {
21-
"rustdoc-theme": "ayu",
22-
"rustdoc-preferred-dark-theme": "ayu",
23-
"rustdoc-use-system-theme": "false",
24-
}
25-
// We reload the page so the local storage settings are being used.
26-
reload:
27-
28-
assert-css: (
29-
"body.source .example-wrap pre.rust a",
30-
{"background-color": "rgb(51, 51, 51)"},
31-
ALL,
4+
define-function: (
5+
"check-background-color",
6+
(theme, background_color),
7+
[
8+
// Set the theme.
9+
("local-storage", { "rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false" }),
10+
// We reload the page so the local storage settings are being used.
11+
("reload"),
12+
("assert-css", (
13+
"body.source .example-wrap pre.rust a",
14+
{"background-color": |background_color|},
15+
ALL,
16+
)),
17+
],
3218
)
3319

34-
// Set the theme to light.
35-
local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"}
36-
// We reload the page so the local storage settings are being used.
37-
reload:
38-
39-
assert-css: (
40-
"body.source .example-wrap pre.rust a",
41-
{"background-color": "rgb(238, 238, 238)"},
42-
ALL,
43-
)
20+
call-function: ("check-background-color", ("ayu", "rgb(51, 51, 51)"))
21+
call-function: ("check-background-color", ("dark", "rgb(51, 51, 51)"))
22+
call-function: ("check-background-color", ("light", "rgb(238, 238, 238)"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![crate_type = "lib"]
2+
3+
pub trait U/*: ?Sized */ {
4+
fn modified(self) -> Self
5+
where
6+
Self: Sized
7+
{
8+
self
9+
}
10+
11+
fn touch(&self)/* where Self: ?Sized */{}
12+
}
13+
14+
pub trait S: Sized {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h4 class="code-header">fn <a href="#method.touch" class="fnname">touch</a>(&amp;self)</h4>

0 commit comments

Comments
 (0)