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 16 pull requests #81998

Closed
wants to merge 135 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
2b9ba46
fix indefinite article in cell.rs
petar-dambovaliev Dec 12, 2020
949b125
Add unit tests for new lint
nahuakang Jan 27, 2021
5753614
Draft skeleton for new lint
nahuakang Jan 27, 2021
3da25ed
Rename lint
nahuakang Jan 27, 2021
8973f2c
Run cargo dev update_lints
nahuakang Jan 27, 2021
b87e189
Implement manual flatten lint
nahuakang Jan 29, 2021
7825bf3
Fix suggestions that need parens
ThibsG Jan 31, 2021
e07cd5b
Enhance manual flatten
nahuakang Feb 2, 2021
c8cb90a
Merge commit '3e4179766bcecd712824da04356621b8df012ea4' into sync-fro…
Manishearth Feb 3, 2021
0f5e71f
Add additional check on if arg type has iter method
nahuakang Feb 3, 2021
f2e82af
Use PrimTy in builtin type shadow lint
camsteffen Feb 2, 2021
6396b8f
Fix file names of flat_map_identity test
magurotuna Feb 3, 2021
876ffa4
Auto merge of #6669 - magurotuna:fix-test-name, r=flip1995
bors Feb 3, 2021
78ef0f2
Add additional test cases and improve span lint
nahuakang Feb 3, 2021
0767a0f
Fix/allow non_fmt_panic in clippy tests.
m-ou-se Feb 2, 2021
9f7f8b7
Suggest panic!("{}", ..) instead of panic!(..) clippy::expect_fun_call.
m-ou-se Feb 3, 2021
86a4b27
Increment `self.index` before calling `Iterator::self.a.__iterator_ge…
sdroege Feb 4, 2021
2f8a8d3
Improve lint message; add note for future autofixable updates
nahuakang Feb 4, 2021
357c6a7
Auto merge of #6646 - nahuakang:for_loops_over_options_or_results, r=…
bors Feb 4, 2021
233fe11
Set turbofish for every sugg and add more test cases
ThibsG Feb 4, 2021
7b7e3ca
Support free functions in disallowed-methods lint
phlip9 Jan 30, 2021
67d48e1
fix typo
TaKO8Ki Feb 5, 2021
79dbf10
Use absolute path to Rust repo in ra_setup
flip1995 Feb 5, 2021
56f7fbb
Cleanup path to local checks
camsteffen Feb 2, 2021
89f266a
Auto merge of #6678 - TaKO8Ki:fix-typo, r=flip1995
bors Feb 5, 2021
a507c27
Auto merge of #6679 - flip1995:ra_setup_abs_path, r=Manishearth
bors Feb 5, 2021
eb9c669
First version of the lint
1c3t3a Dec 20, 2020
f907986
Added documentation
1c3t3a Dec 21, 2020
55bfaa1
Fixed macro edge case for `semicolon_if_nothing_returned lint`
1c3t3a Feb 5, 2021
ac5e9c8
Fix let_underscore_drop implements Drop logic
camsteffen Feb 5, 2021
a9ad492
Bump clippy version
Mark-Simulacrum Feb 5, 2021
93daf27
tests: ignore check_that_clippy_has_the_same_major_version_as_rustc()…
matthiaskrgr Feb 5, 2021
a60c143
Add new lint `filter_map_identity`
magurotuna Feb 3, 2021
fbe436b
Use flatten instead of filter_map
magurotuna Feb 6, 2021
cb30219
lintcheck: update logs
matthiaskrgr Feb 6, 2021
64982cc
lintcheck: make TomlCrate also accept git-data from lintcheck_crates.…
matthiaskrgr Feb 5, 2021
10fbafa
implement the download_and_extract() step for git sources
matthiaskrgr Feb 6, 2021
9ab505a
lintcheck: add git source as an example and update logs
matthiaskrgr Feb 6, 2021
e1c284b
lintcheck: cleanup, fix --only for git crates, better error msgs
matthiaskrgr Feb 6, 2021
6626295
Fixed for loop problem, corrected all occurences that got linted
1c3t3a Feb 6, 2021
dfb34c0
Auto merge of #6684 - matthiaskrgr:versiontest_dont_break_upstream, r…
bors Feb 6, 2021
cd67487
Revert "Fixed for loop problem, corrected all occurences that got lin…
1c3t3a Feb 6, 2021
85c2b1e
Switched to `snippet_with_macro_callsite`
1c3t3a Feb 6, 2021
a5d442c
Rollup merge of #81680 - camsteffen:primty, r=oli-obk
jonas-schievink Feb 6, 2021
f1c1584
Changed lint level to `restriction`
1c3t3a Feb 6, 2021
915e9b8
Fix cargo_common_metadata warning on `publish = false`.
daxpedda Jan 29, 2021
d4bc7d2
Test names were flipped.
daxpedda Feb 3, 2021
f0d3fd7
Implement `_cargo_ignore_publish`.
daxpedda Feb 3, 2021
8805931
Hide clippy configuration option.
daxpedda Feb 6, 2021
f2391a5
Change clippy configuration option.
daxpedda Feb 6, 2021
8b89087
Add test for `publish = true`.
daxpedda Feb 6, 2021
cd361a5
Add back `publish = false` to the old test.
daxpedda Feb 6, 2021
e2e33b4
Pick up `clippy.toml` in `ui-cargo` tests.
daxpedda Feb 6, 2021
3c8f754
Fux `toml_unknown_key` test.
daxpedda Feb 6, 2021
ea0b832
Document condition.
daxpedda Feb 6, 2021
fd8b5fa
Confused about my own explanation.
daxpedda Feb 6, 2021
2bffbfc
lintcheck: avoid dbg!() calls
matthiaskrgr Feb 6, 2021
0585c34
Stabilize workspace wrapper.
ehuss Feb 6, 2021
6b4789d
Fixed suggestion in macro invocations
1c3t3a Feb 6, 2021
40ce056
Eat dogfood
camsteffen Feb 5, 2021
dfe08f4
Update triagebot.toml to new label names
flip1995 Feb 6, 2021
55ca27f
use rwlock for accessing ENV
the8472 Feb 6, 2021
d792210
Auto merge of #6682 - camsteffen:let-underscore-ref, r=llogiq
bors Feb 7, 2021
b36d1a4
Auto merge of #6688 - rust-lang:triagebot_update, r=phansch
bors Feb 7, 2021
d51db24
Auto merge of #6660 - camsteffen:path-to-local, r=llogiq
bors Feb 7, 2021
406fd3a
silence dead code warnings on windows
the8472 Feb 7, 2021
001185d
Auto merge of #6681 - 1c3t3a:1c3t3a-issue-6467, r=xFrednet,flip1995,p…
bors Feb 7, 2021
ad9ceee
Auto merge of #6685 - magurotuna:filter_map_identity, r=phansch
bors Feb 7, 2021
83b7b16
Auto merge of #6674 - phlip9:disallowed_functions, r=llogiq
bors Feb 7, 2021
c1ce78f
Auto merge of #6686 - matthiaskrgr:lintcheck_git, r=flip1995
bors Feb 7, 2021
6f3eeac
lintcheck: add a cmdline option --crates-toml <TOML PATH> to override…
matthiaskrgr Feb 7, 2021
1c3033d
add a new lint `bytes_nth`
TaKO8Ki Feb 7, 2021
de35c29
Auto merge of #6694 - matthiaskrgr:lintcheck-cfg, r=Manishearth
bors Feb 7, 2021
fd35517
Downgrade trivial_regex to nursery
dtolnay Feb 8, 2021
4bbd7e4
Auto merge of #6696 - dtolnay-contrib:regex, r=Manishearth
bors Feb 8, 2021
1d30422
Enhance LocalUsedVisitor to check closure bodies
camsteffen Feb 3, 2021
5db48a3
Refactor out UnusedSelfVisitor
camsteffen Feb 3, 2021
37555f8
Use path_to_local_id
camsteffen Feb 8, 2021
2200cf1
avoid &mut on the read path since it now allows concurrent readers
the8472 Feb 8, 2021
44abad5
introduce StaticRWLock wrapper to make methods safe
the8472 Feb 8, 2021
34b373d
Rename HIR UnOp variants
osa1 Feb 9, 2021
775ce47
Rename "good first issue" back to "good-first-issue"
flip1995 Feb 9, 2021
03a0dd5
Auto merge of #6704 - rust-lang:flip1995-patch-1, r=phansch
bors Feb 9, 2021
b932587
Add better turbofish extractor
ThibsG Feb 9, 2021
03737e2
Remove rustfmt from rust-toolchain file
flip1995 Feb 9, 2021
08b4d50
Auto merge of #6709 - rust-lang:flip1995-patch-1, r=matthiaskrgr
bors Feb 9, 2021
4fc181d
split guard into read and write types
the8472 Feb 9, 2021
471ed5f
Use ItemCtxt::to_ty
camsteffen Feb 10, 2021
883988b
RELEASES.md 1.50: Group platform support notes together
joshtriplett Feb 10, 2021
d3fea13
bootstrap: Locate llvm-dwp based on llvm-config bindir
dtolnay Feb 10, 2021
0e371b8
Auto merge of #6698 - camsteffen:path-to-local, r=phansch
bors Feb 10, 2021
932cc08
Update clippy_lints/src/methods/bytes_nth.rs
TaKO8Ki Feb 10, 2021
5996ae1
add some test cases
TaKO8Ki Feb 10, 2021
a6d4137
Fix assosiated typo
therealprof Feb 10, 2021
d64b749
Allow casting mut array ref to mut ptr
osa1 Jan 28, 2021
9c0ae2a
Auto merge of #6687 - ehuss:stabilize-wrapper, r=flip1995
bors Feb 10, 2021
f13bbea
Catch errors on localStorage setting failure
lovasoa Feb 10, 2021
b5e4389
Auto merge of #6695 - TaKO8Ki:add-bytes-nth, r=phansch
bors Feb 10, 2021
16f0ccd
Fix getCurrentValue
lovasoa Feb 10, 2021
94b8f23
Fix typo
alpaca-tc Feb 10, 2021
a6d6b1b
Auto merge of #6714 - alpaca-tc:fixed_tiny_typo, r=flip1995
bors Feb 10, 2021
5034b50
bootstrap: fix wrong docs installation path
pietroalbini Feb 10, 2021
3784cdf
Auto merge of #6657 - ThibsG:FromIterParens, r=llogiq
bors Feb 10, 2021
bfd1ccf
Seal the CommandExt, OsStrExt and OsStringExt traits
Amanieu Feb 10, 2021
e03f097
Make suggestion of changing mutability of arguments broader
hkmatsumoto Feb 11, 2021
beb49ba
Auto merge of #6650 - daxpedda:cargo-common-metadata-publish, r=flip1995
bors Feb 11, 2021
1025cd3
lintcheck toml: explain why tokei is commented out
matthiaskrgr Feb 9, 2021
c7241b6
lintcheck: make the log file be ${source-file}-logs.txt
matthiaskrgr Feb 9, 2021
cfe154b
start a clippy-dev readme and some rough info on how to use lintcheck
matthiaskrgr Feb 9, 2021
5e29aa6
lintcheck: add support for path sources
matthiaskrgr Feb 10, 2021
a6d493d
lintcheck: collect ICEs
matthiaskrgr Feb 10, 2021
8dbcffe
Auto merge of #6708 - matthiaskrgr:lintcheck, r=flip1995
bors Feb 11, 2021
00f9981
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Feb 11, 2021
4efc454
Bump nightly version -> 2021-02-11
flip1995 Feb 11, 2021
70c0f90
Auto merge of #6718 - flip1995:rustup, r=flip1995
bors Feb 11, 2021
d2e2f64
Merge commit '70c0f90453701e7d6d9b99aaa1fc6a765937b736' into clippyup
flip1995 Feb 11, 2021
a99d869
Improve long explanation for E0542 and E0546
jesusprubio Feb 11, 2021
788e4bb
Fix suggestion to introduce explicit lifetime
0yoyoyo Feb 11, 2021
f492b25
dist: include src/build_helper as part of the crate graph for rustc-dev.
bnjbvr Feb 11, 2021
15e1528
Rollup merge of #79983 - petar-dambovaliev:master, r=Dylan-DPC
jonas-schievink Feb 11, 2021
660d58f
Rollup merge of #81479 - osa1:issue24151, r=lcnr
jonas-schievink Feb 11, 2021
ff5a47d
Rollup merge of #81741 - sdroege:zip-trusted-random-access-specializa…
jonas-schievink Feb 11, 2021
9977d8f
Rollup merge of #81850 - the8472:env-rwlock, r=m-ou-se
jonas-schievink Feb 11, 2021
9b03649
Rollup merge of #81947 - camsteffen:to-ty, r=jyn514
jonas-schievink Feb 11, 2021
316d307
Rollup merge of #81954 - joshtriplett:release-notes-group-platform-no…
jonas-schievink Feb 11, 2021
732016c
Rollup merge of #81955 - dtolnay:dwp, r=Mark-Simulacrum
jonas-schievink Feb 11, 2021
9fbea53
Rollup merge of #81959 - therealprof:fix-typo, r=oli-obk
jonas-schievink Feb 11, 2021
0127e60
Rollup merge of #81964 - lovasoa:patch-1, r=GuillaumeGomez
jonas-schievink Feb 11, 2021
06cf63c
Rollup merge of #81968 - pietroalbini:fix-doc-install-path, r=Mark-Si…
jonas-schievink Feb 11, 2021
0fc60ab
Rollup merge of #81975 - Amanieu:seal2, r=m-ou-se
jonas-schievink Feb 11, 2021
a96135e
Rollup merge of #81990 - matsujika:suggest-mut-reference, r=estebank
jonas-schievink Feb 11, 2021
a987ed5
Rollup merge of #81993 - flip1995:clippyup, r=Manishearth
jonas-schievink Feb 11, 2021
cf9266c
Rollup merge of #81994 - jesusprubio:improve-long-explanation-e0542-e…
jonas-schievink Feb 11, 2021
99e79ea
Rollup merge of #81995 - 0yoyoyo:fix-issue-81650-explicit-lifetime-er…
jonas-schievink Feb 11, 2021
98187bb
Rollup merge of #81997 - bnjbvr:dist-include-build-helper, r=Mark-Sim…
jonas-schievink Feb 11, 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
2 changes: 1 addition & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Compiler
- [Added tier 3\* support for the `armv5te-unknown-linux-uclibceabi` target.][78142]
- [Added tier 3 support for the `aarch64-apple-ios-macabi` target.][77484]
- [The `x86_64-unknown-freebsd` is now built with the full toolset.][79484]
- [Dropped support for all cloudabi targets.][78439]

\* Refer to Rust's [platform support page][forge-platform-support] for more
information on Rust's tiered platform support.
Expand Down Expand Up @@ -77,7 +78,6 @@ Compatibility Notes
- [`#![test]` as an inner attribute is now considered unstable like other inner macro
attributes, and reports an error by default through the `soft_unstable` lint.][79003]
- [Overriding a `forbid` lint at the same level that it was set is now a hard error.][78864]
- [Dropped support for all cloudabi targets.][78439]
- [You can no longer intercept `panic!` calls by supplying your own macro.][78343] It's
recommended to use the `#[panic_handler]` attribute to provide your own implementation.
- [Semi-colons after item statements (e.g. `struct Foo {};`) now produce a warning.][78296]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes/E0542.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn _stable_const_fn() {}
fn _deprecated_fn() {}
```

To fix the issue you need to provide the `since` field.
To fix this issue, you need to provide the `since` field. Example:

```
#![feature(staged_api)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes/E0546.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn unstable_fn() {}
fn stable_fn() {}
```

To fix the issue you need to provide the `feature` field.
To fix this issue, you need to provide the `feature` field. Example:

```
#![feature(staged_api)]
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2248,13 +2248,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
"...",
);
if let Some(infer::RelateParamBound(_, t)) = origin {
let return_impl_trait = self
.in_progress_typeck_results
.map(|typeck_results| typeck_results.borrow().hir_owner)
.and_then(|owner| self.tcx.return_type_impl_trait(owner))
.is_some();
let t = self.resolve_vars_if_possible(t);
match t.kind() {
// We've got:
// fn get_later<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
// suggest:
// fn get_later<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a
ty::Closure(_, _substs) | ty::Opaque(_, _substs) => {
ty::Closure(_, _substs) | ty::Opaque(_, _substs) if return_impl_trait => {
new_binding_suggestion(&mut err, type_param_span, bound_kind);
}
_ => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
);
}

// Attempt to search similar mutable assosiated items for suggestion.
// Attempt to search similar mutable associated items for suggestion.
// In the future, attempt in all path but initially for RHS of for_loop
fn suggest_similar_mut_method_for_for_loop(&self, err: &mut DiagnosticBuilder<'_>) {
let hir = self.infcx.tcx.hir();
Expand Down
39 changes: 24 additions & 15 deletions compiler/rustc_mir/src/borrow_check/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2191,19 +2191,18 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
CastKind::Pointer(PointerCast::ArrayToPointer) => {
let ty_from = op.ty(body, tcx);

let opt_ty_elem = match ty_from.kind() {
ty::RawPtr(ty::TypeAndMut {
mutbl: hir::Mutability::Not,
ty: array_ty,
}) => match array_ty.kind() {
ty::Array(ty_elem, _) => Some(ty_elem),
_ => None,
},
let opt_ty_elem_mut = match ty_from.kind() {
ty::RawPtr(ty::TypeAndMut { mutbl: array_mut, ty: array_ty }) => {
match array_ty.kind() {
ty::Array(ty_elem, _) => Some((ty_elem, *array_mut)),
_ => None,
}
}
_ => None,
};

let ty_elem = match opt_ty_elem {
Some(ty_elem) => ty_elem,
let (ty_elem, ty_mut) = match opt_ty_elem_mut {
Some(ty_elem_mut) => ty_elem_mut,
None => {
span_mirbug!(
self,
Expand All @@ -2215,11 +2214,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}
};

let ty_to = match ty.kind() {
ty::RawPtr(ty::TypeAndMut {
mutbl: hir::Mutability::Not,
ty: ty_to,
}) => ty_to,
let (ty_to, ty_to_mut) = match ty.kind() {
ty::RawPtr(ty::TypeAndMut { mutbl: ty_to_mut, ty: ty_to }) => {
(ty_to, *ty_to_mut)
}
_ => {
span_mirbug!(
self,
Expand All @@ -2231,6 +2229,17 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}
};

if ty_to_mut == Mutability::Mut && ty_mut == Mutability::Not {
span_mirbug!(
self,
rvalue,
"ArrayToPointer cast from const {:?} to mut {:?}",
ty,
ty_to
);
return;
}

if let Err(terr) = self.sub_types(
ty_elem,
ty_to,
Expand Down
31 changes: 15 additions & 16 deletions compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,22 +468,21 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
trait_ref,
obligation.cause.body_id,
);
} else {
if !have_alt_message {
// Can't show anything else useful, try to find similar impls.
let impl_candidates = self.find_similar_impl_candidates(trait_ref);
self.report_similar_impl_candidates(impl_candidates, &mut err);
}
// Changing mutability doesn't make a difference to whether we have
// an `Unsize` impl (Fixes ICE in #71036)
if !is_unsize {
self.suggest_change_mut(
&obligation,
&mut err,
trait_ref,
points_at_arg,
);
}
} else if !have_alt_message {
// Can't show anything else useful, try to find similar impls.
let impl_candidates = self.find_similar_impl_candidates(trait_ref);
self.report_similar_impl_candidates(impl_candidates, &mut err);
}

// Changing mutability doesn't make a difference to whether we have
// an `Unsize` impl (Fixes ICE in #71036)
if !is_unsize {
self.suggest_change_mut(
&obligation,
&mut err,
trait_ref,
points_at_arg,
);
}

// If this error is due to `!: Trait` not implemented but `(): Trait` is
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_typeck/src/check/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,8 @@ impl<'a, 'tcx> CastCheck<'tcx> {
m_expr: ty::TypeAndMut<'tcx>,
m_cast: ty::TypeAndMut<'tcx>,
) -> Result<CastKind, CastError> {
// array-ptr-cast.

if m_expr.mutbl == hir::Mutability::Not && m_cast.mutbl == hir::Mutability::Not {
// array-ptr-cast: allow mut-to-mut, mut-to-const, const-to-const
if m_expr.mutbl == hir::Mutability::Mut || m_cast.mutbl == hir::Mutability::Not {
if let ty::Array(ety, _) = m_expr.ty.kind() {
// Due to the limitations of LLVM global constants,
// region pointers end up pointing at copies of
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl ItemCtxt<'tcx> {
ItemCtxt { tcx, item_def_id }
}

pub fn to_ty(&self, ast_ty: &'tcx hir::Ty<'tcx>) -> Ty<'tcx> {
pub fn to_ty(&self, ast_ty: &hir::Ty<'_>) -> Ty<'tcx> {
AstConv::ast_ty_to_ty(self, ast_ty)
}

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,7 @@ pub fn hir_ty_to_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty<'_>) -> Ty<'tcx> {
let env_node_id = tcx.hir().get_parent_item(hir_ty.hir_id);
let env_def_id = tcx.hir().local_def_id(env_node_id);
let item_cx = self::collect::ItemCtxt::new(tcx, env_def_id.to_def_id());

astconv::AstConv::ast_ty_to_ty(&item_cx, hir_ty)
item_cx.to_ty(hir_ty)
}

pub fn hir_trait_to_predicates<'tcx>(
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,7 @@ impl<T: ?Sized + fmt::Display> fmt::Display for RefMut<'_, T> {
/// `UnsafeCell<T>` is a type that wraps some `T` and indicates unsafe interior operations on the
/// wrapped type. Types with an `UnsafeCell<T>` field are considered to have an 'unsafe interior'.
/// The `UnsafeCell<T>` type is the only legal way to obtain aliasable data that is considered
/// mutable. In general, transmuting an `&T` type into an `&mut T` is considered undefined behavior.
/// mutable. In general, transmuting a `&T` type into a `&mut T` is considered undefined behavior.
///
/// If you have a reference `&SomeStruct`, then normally in Rust all fields of `SomeStruct` are
/// immutable. The compiler makes optimizations based on the knowledge that `&T` is not mutably
Expand Down
7 changes: 4 additions & 3 deletions library/core/src/iter/adapters/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,13 @@ where
Some((self.a.__iterator_get_unchecked(i), self.b.__iterator_get_unchecked(i)))
}
} else if A::may_have_side_effect() && self.index < self.a.size() {
let i = self.index;
self.index += 1;
// match the base implementation's potential side effects
// SAFETY: we just checked that `self.index` < `self.a.len()`
// SAFETY: we just checked that `i` < `self.a.len()`
unsafe {
self.a.__iterator_get_unchecked(self.index);
self.a.__iterator_get_unchecked(i);
}
self.index += 1;
None
} else {
None
Expand Down
8 changes: 8 additions & 0 deletions library/std/src/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ pub struct OsString {
inner: Buf,
}

/// Allows extension traits within `std`.
#[unstable(feature = "sealed", issue = "none")]
impl crate::sealed::Sealed for OsString {}

/// Borrowed reference to an OS string (see [`OsString`]).
///
/// This type represents a borrowed reference to a string in the operating system's preferred
Expand All @@ -100,6 +104,10 @@ pub struct OsStr {
inner: Slice,
}

/// Allows extension traits within `std`.
#[unstable(feature = "sealed", issue = "none")]
impl crate::sealed::Sealed for OsStr {}

impl OsString {
/// Constructs a new empty `OsString`.
///
Expand Down
8 changes: 8 additions & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,3 +582,11 @@ include!("keyword_docs.rs");
// is unconditional, so the unstable feature needs to be defined somewhere.
#[unstable(feature = "restricted_std", issue = "none")]
mod __restricted_std_workaround {}

mod sealed {
/// This trait being unreachable from outside the crate
/// prevents outside implementations of our extension traits.
/// This allows adding more trait methods in the future.
#[unstable(feature = "sealed", issue = "none")]
pub trait Sealed {}
}
8 changes: 8 additions & 0 deletions library/std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,10 @@ pub struct Command {
inner: imp::Command,
}

/// Allows extension traits within `std`.
#[unstable(feature = "sealed", issue = "none")]
impl crate::sealed::Sealed for Command {}

impl Command {
/// Constructs a new `Command` for launching the program at
/// path `program`, with the following default configuration:
Expand Down Expand Up @@ -1375,6 +1379,10 @@ impl From<fs::File> for Stdio {
#[stable(feature = "process", since = "1.0.0")]
pub struct ExitStatus(imp::ExitStatus);

/// Allows extension traits within `std`.
#[unstable(feature = "sealed", issue = "none")]
impl crate::sealed::Sealed for ExitStatus {}

impl ExitStatus {
/// Was termination successful? Signal termination is not considered a
/// success, and success is defined as a zero exit status.
Expand Down
19 changes: 6 additions & 13 deletions library/std/src/sys/unix/ext/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,16 @@ use crate::ffi::OsStr;
use crate::io;
use crate::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
use crate::process;
use crate::sealed::Sealed;
use crate::sys;
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};

mod private {
/// This trait being unreachable from outside the crate
/// prevents other implementations of the `ExitStatusExt` trait,
/// which allows potentially adding more trait methods in the future.
#[stable(feature = "none", since = "1.51.0")]
pub trait Sealed {}
}

/// Unix-specific extensions to the [`process::Command`] builder.
///
/// This trait is sealed: it cannot be implemented outside the standard library.
/// This is so that future additional methods are not breaking changes.
#[stable(feature = "rust1", since = "1.0.0")]
pub trait CommandExt {
pub trait CommandExt: Sealed {
/// Sets the child process's user ID. This translates to a
/// `setuid` call in the child process. Failure in the `setuid`
/// call will cause the spawn to fail.
Expand Down Expand Up @@ -193,7 +189,7 @@ impl CommandExt for process::Command {
/// This trait is sealed: it cannot be implemented outside the standard library.
/// This is so that future additional methods are not breaking changes.
#[stable(feature = "rust1", since = "1.0.0")]
pub trait ExitStatusExt: private::Sealed {
pub trait ExitStatusExt: Sealed {
/// Creates a new `ExitStatus` from the raw underlying `i32` return value of
/// a process.
#[stable(feature = "exit_status_from", since = "1.12.0")]
Expand Down Expand Up @@ -228,9 +224,6 @@ pub trait ExitStatusExt: private::Sealed {
fn into_raw(self) -> i32;
}

#[stable(feature = "none", since = "1.51.0")]
impl private::Sealed for process::ExitStatus {}

#[stable(feature = "rust1", since = "1.0.0")]
impl ExitStatusExt for process::ExitStatus {
fn from_raw(raw: i32) -> Self {
Expand Down
19 changes: 10 additions & 9 deletions library/std/src/sys/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::str;
use crate::sys::cvt;
use crate::sys::fd;
use crate::sys_common::mutex::{StaticMutex, StaticMutexGuard};
use crate::sys_common::rwlock::{RWLockReadGuard, StaticRWLock};
use crate::vec;

use libc::{c_char, c_int, c_void};
Expand Down Expand Up @@ -490,20 +491,20 @@ pub unsafe fn environ() -> *mut *const *const c_char {
extern "C" {
static mut environ: *const *const c_char;
}
&mut environ
ptr::addr_of_mut!(environ)
}

pub unsafe fn env_lock() -> StaticMutexGuard {
// It is UB to attempt to acquire this mutex reentrantly!
static ENV_LOCK: StaticMutex = StaticMutex::new();
ENV_LOCK.lock()
static ENV_LOCK: StaticRWLock = StaticRWLock::new();

pub fn env_read_lock() -> RWLockReadGuard {
ENV_LOCK.read_with_guard()
}

/// Returns a vector of (variable, value) byte-vector pairs for all the
/// environment variables of the current process.
pub fn env() -> Env {
unsafe {
let _guard = env_lock();
let _guard = env_read_lock();
let mut environ = *environ();
let mut result = Vec::new();
if !environ.is_null() {
Expand Down Expand Up @@ -540,7 +541,7 @@ pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> {
// always None as well
let k = CString::new(k.as_bytes())?;
unsafe {
let _guard = env_lock();
let _guard = env_read_lock();
let s = libc::getenv(k.as_ptr()) as *const libc::c_char;
let ret = if s.is_null() {
None
Expand All @@ -556,7 +557,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> {
let v = CString::new(v.as_bytes())?;

unsafe {
let _guard = env_lock();
let _guard = ENV_LOCK.write_with_guard();
cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(drop)
}
}
Expand All @@ -565,7 +566,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> {
let nbuf = CString::new(n.as_bytes())?;

unsafe {
let _guard = env_lock();
let _guard = ENV_LOCK.write_with_guard();
cvt(libc::unsetenv(nbuf.as_ptr())).map(drop)
}
}
Expand Down
Loading