Skip to content

Commit 05f2326

Browse files
committed
Auto merge of rust-lang#87347 - GuillaumeGomez:rollup-ke92xxc, r=GuillaumeGomez
Rollup of 9 pull requests Successful merges: - rust-lang#87187 (Fix NixOS detection) - rust-lang#87206 (avoid temporary vectors/reuse iterators) - rust-lang#87230 (Fix docblock <table> overflow) - rust-lang#87273 (Recognize bounds on impls as const bounds) - rust-lang#87279 (Add comments explaining the unix command-line argument support.) - rust-lang#87301 (Fix typo in compile.rs) - rust-lang#87311 (Get back the more precise suggestion spans of old regionck) - rust-lang#87321 (Add long explanation for E0722) - rust-lang#87342 (Add long explanation for E0757) Failed merges: - rust-lang#87270 (Don't display <table> in item summary) r? `@ghost` `@rustbot` modify labels: rollup
2 parents cf932aa + 3a8bc0d commit 05f2326

File tree

28 files changed

+184
-61
lines changed

28 files changed

+184
-61
lines changed

compiler/rustc_builtin_macros/src/deriving/generic/ty.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,9 @@ impl Path {
7272
) -> ast::Path {
7373
let mut idents = self.path.iter().map(|s| Ident::new(*s, span)).collect();
7474
let lt = mk_lifetimes(cx, span, &self.lifetime);
75-
let tys: Vec<P<ast::Ty>> =
76-
self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)).collect();
77-
let params = lt
78-
.into_iter()
79-
.map(GenericArg::Lifetime)
80-
.chain(tys.into_iter().map(GenericArg::Type))
81-
.collect();
75+
let tys = self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics));
76+
let params =
77+
lt.into_iter().map(GenericArg::Lifetime).chain(tys.map(GenericArg::Type)).collect();
8278

8379
match self.kind {
8480
PathKind::Global => cx.path_all(span, true, idents, params),

compiler/rustc_error_codes/src/error_codes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ E0716: include_str!("./error_codes/E0716.md"),
418418
E0718: include_str!("./error_codes/E0718.md"),
419419
E0719: include_str!("./error_codes/E0719.md"),
420420
E0720: include_str!("./error_codes/E0720.md"),
421+
E0722: include_str!("./error_codes/E0722.md"),
421422
E0724: include_str!("./error_codes/E0724.md"),
422423
E0725: include_str!("./error_codes/E0725.md"),
423424
E0727: include_str!("./error_codes/E0727.md"),
@@ -449,6 +450,7 @@ E0753: include_str!("./error_codes/E0753.md"),
449450
E0754: include_str!("./error_codes/E0754.md"),
450451
E0755: include_str!("./error_codes/E0755.md"),
451452
E0756: include_str!("./error_codes/E0756.md"),
453+
E0757: include_str!("./error_codes/E0757.md"),
452454
E0758: include_str!("./error_codes/E0758.md"),
453455
E0759: include_str!("./error_codes/E0759.md"),
454456
E0760: include_str!("./error_codes/E0760.md"),
@@ -634,10 +636,8 @@ E0783: include_str!("./error_codes/E0783.md"),
634636
E0711, // a feature has been declared with conflicting stability attributes
635637
E0717, // rustc_promotable without stability attribute
636638
// E0721, // `await` keyword
637-
E0722, // Malformed `#[optimize]` attribute
638639
// E0723, unstable feature in `const` context
639640
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
640641
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
641-
E0757, // `#[ffi_const]` functions cannot be `#[ffi_pure]`
642642
E0772, // `'static' obligation coming from `impl dyn Trait {}` or `impl Foo for dyn Bar {}`.
643643
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
The `optimize` attribute was malformed.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0722
6+
#![feature(optimize_attribute)]
7+
8+
#[optimize(something)] // error: invalid argument
9+
pub fn something() {}
10+
```
11+
12+
The `#[optimize]` attribute should be used as follows:
13+
14+
- `#[optimize(size)]` -- instructs the optimization pipeline to generate code
15+
that's smaller rather than faster
16+
17+
- `#[optimize(speed)]` -- instructs the optimization pipeline to generate code
18+
that's faster rather than smaller
19+
20+
For example:
21+
22+
```
23+
#![feature(optimize_attribute)]
24+
25+
#[optimize(size)]
26+
pub fn something() {}
27+
```
28+
29+
See [RFC 2412] for more details.
30+
31+
[RFC 2412]: https://rust-lang.github.io/rfcs/2412-optimize-attr.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
A function was given both the `ffi_const` and `ffi_pure` attributes.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0757
6+
#![feature(ffi_const, ffi_pure)]
7+
8+
extern "C" {
9+
#[ffi_const]
10+
#[ffi_pure] // error: `#[ffi_const]` function cannot be `#[ffi_pure]`
11+
pub fn square(num: i32) -> i32;
12+
}
13+
```
14+
15+
As `ffi_const` provides stronger guarantees than `ffi_pure`, remove the
16+
`ffi_pure` attribute:
17+
18+
```
19+
#![feature(ffi_const)]
20+
21+
extern "C" {
22+
#[ffi_const]
23+
pub fn square(num: i32) -> i32;
24+
}
25+
```
26+
27+
You can get more information about `const` and `pure` in the [GCC documentation
28+
on Common Function Attributes]. The unstable Rust Book has more information
29+
about [`ffi_const`] and [`ffi_pure`].
30+
31+
[GCC documentation on Common Function Attributes]: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html
32+
[`ffi_const`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/ffi-const.html
33+
[`ffi_pure`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/ffi-pure.html

compiler/rustc_hir/src/hir.rs

+21
Original file line numberDiff line numberDiff line change
@@ -3060,6 +3060,27 @@ impl<'hir> Node<'hir> {
30603060
Node::Crate(_) | Node::Visibility(_) => None,
30613061
}
30623062
}
3063+
3064+
/// Returns `Constness::Const` when this node is a const fn/impl.
3065+
pub fn constness(&self) -> Constness {
3066+
match self {
3067+
Node::Item(Item {
3068+
kind: ItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..),
3069+
..
3070+
})
3071+
| Node::TraitItem(TraitItem {
3072+
kind: TraitItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..),
3073+
..
3074+
})
3075+
| Node::ImplItem(ImplItem {
3076+
kind: ImplItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..),
3077+
..
3078+
})
3079+
| Node::Item(Item { kind: ItemKind::Impl(Impl { constness, .. }), .. }) => *constness,
3080+
3081+
_ => Constness::NotConst,
3082+
}
3083+
}
30633084
}
30643085

30653086
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
21302130
let new_lt = generics
21312131
.as_ref()
21322132
.and_then(|(parent_g, g)| {
2133-
let possible: Vec<_> = (b'a'..=b'z').map(|c| format!("'{}", c as char)).collect();
2133+
let mut possible = (b'a'..=b'z').map(|c| format!("'{}", c as char));
21342134
let mut lts_names = g
21352135
.params
21362136
.iter()
@@ -2146,7 +2146,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
21462146
);
21472147
}
21482148
let lts = lts_names.iter().map(|s| -> &str { &*s }).collect::<Vec<_>>();
2149-
possible.into_iter().find(|candidate| !lts.contains(&candidate.as_str()))
2149+
possible.find(|candidate| !lts.contains(&candidate.as_str()))
21502150
})
21512151
.unwrap_or("'lt".to_string());
21522152
let add_lt_sugg = generics

compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::mir::{ConstraintCategory, ReturnConstraint};
99
use rustc_middle::ty::subst::Subst;
1010
use rustc_middle::ty::{self, RegionVid, Ty};
1111
use rustc_span::symbol::{kw, sym};
12-
use rustc_span::Span;
12+
use rustc_span::{BytePos, Span};
1313

1414
use crate::util::borrowck_errors;
1515

@@ -641,12 +641,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
641641
} else {
642642
"'_".to_string()
643643
};
644-
let suggestion = if snippet.ends_with(';') {
644+
let span = if snippet.ends_with(';') {
645645
// `type X = impl Trait;`
646-
format!("{} + {};", &snippet[..snippet.len() - 1], suggestable_fr_name)
646+
span.with_hi(span.hi() - BytePos(1))
647647
} else {
648-
format!("{} + {}", snippet, suggestable_fr_name)
648+
span
649649
};
650+
let suggestion = format!(" + {}", suggestable_fr_name);
651+
let span = span.shrink_to_hi();
650652
diag.span_suggestion(
651653
span,
652654
&format!(

compiler/rustc_mir/src/transform/check_consts/validation.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -897,16 +897,19 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
897897
permitted = true;
898898
}
899899
}
900-
let mut const_impls = true;
901-
tcx.for_each_relevant_impl(trait_id, substs.type_at(0), |imp| {
902-
if const_impls {
903-
if let hir::Constness::NotConst = tcx.impl_constness(imp) {
904-
const_impls = false;
900+
if !permitted {
901+
// if trait's impls are all const, permit the call.
902+
let mut const_impls = true;
903+
tcx.for_each_relevant_impl(trait_id, substs.type_at(0), |imp| {
904+
if const_impls {
905+
if let hir::Constness::NotConst = tcx.impl_constness(imp) {
906+
const_impls = false;
907+
}
905908
}
909+
});
910+
if const_impls {
911+
permitted = true;
906912
}
907-
});
908-
if const_impls {
909-
permitted = true;
910913
}
911914
}
912915

compiler/rustc_typeck/src/check/fn_ctxt/mod.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc_hir::def_id::DefId;
1515
use rustc_infer::infer;
1616
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
1717
use rustc_infer::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
18-
use rustc_middle::hir::map::blocks::FnLikeNode;
1918
use rustc_middle::ty::fold::TypeFoldable;
2019
use rustc_middle::ty::subst::GenericArgKind;
2120
use rustc_middle::ty::{self, Const, Ty, TyCtxt};
@@ -175,13 +174,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
175174
}
176175

177176
fn default_constness_for_trait_bounds(&self) -> hir::Constness {
178-
// FIXME: refactor this into a method
179-
let node = self.tcx.hir().get(self.body_id);
180-
if let Some(fn_like) = FnLikeNode::from_node(node) {
181-
fn_like.constness()
182-
} else {
183-
hir::Constness::NotConst
184-
}
177+
self.tcx.hir().get(self.body_id).constness()
185178
}
186179

187180
fn get_type_parameter_bounds(

compiler/rustc_typeck/src/collect.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
3535
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
3636
use rustc_hir::weak_lang_items;
3737
use rustc_hir::{GenericParamKind, HirId, Node};
38-
use rustc_middle::hir::map::blocks::FnLikeNode;
3938
use rustc_middle::hir::map::Map;
4039
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
4140
use rustc_middle::mir::mono::Linkage;
@@ -358,11 +357,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
358357
}
359358

360359
fn default_constness_for_trait_bounds(&self) -> hir::Constness {
361-
if let Some(fn_like) = FnLikeNode::from_node(self.node()) {
362-
fn_like.constness()
363-
} else {
364-
hir::Constness::NotConst
365-
}
360+
self.node().constness()
366361
}
367362

368363
fn get_type_parameter_bounds(

library/std/src/sys/unix/args.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,18 @@ mod imp {
7777
use crate::ptr;
7878
use crate::sync::atomic::{AtomicIsize, AtomicPtr, Ordering};
7979

80+
// The system-provided argc and argv, which we store in static memory
81+
// here so that we can defer the work of parsing them until its actually
82+
// needed.
83+
//
84+
// Note that we never mutate argv/argc, the argv array, or the argv
85+
// strings, which allows the code in this file to be very simple.
8086
static ARGC: AtomicIsize = AtomicIsize::new(0);
8187
static ARGV: AtomicPtr<*const u8> = AtomicPtr::new(ptr::null_mut());
8288

8389
unsafe fn really_init(argc: isize, argv: *const *const u8) {
90+
// These don't need to be ordered with each other or other stores,
91+
// because they only hold the unmodified system-provide argv/argc.
8492
ARGC.store(argc, Ordering::Relaxed);
8593
ARGV.store(argv as *mut _, Ordering::Relaxed);
8694
}
@@ -122,8 +130,14 @@ mod imp {
122130

123131
fn clone() -> Vec<OsString> {
124132
unsafe {
125-
// Load ARGC and ARGV without a lock. If the store to either ARGV or
126-
// ARGC isn't visible yet, we'll return an empty argument list.
133+
// Load ARGC and ARGV, which hold the unmodified system-provided
134+
// argc/argv, so we can read the pointed-to memory without atomics
135+
// or synchronization.
136+
//
137+
// If either ARGC or ARGV is still zero or null, then either there
138+
// really are no arguments, or someone is asking for `args()`
139+
// before initialization has completed, and we return an empty
140+
// list.
127141
let argv = ARGV.load(Ordering::Relaxed);
128142
let argc = if argv.is_null() { 0 } else { ARGC.load(Ordering::Relaxed) };
129143
(0..argc)

src/bootstrap/bootstrap.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,13 @@ def fix_bin_or_dylib(self, fname):
580580
if ostype != "Linux":
581581
return
582582

583-
if not os.path.exists("/etc/NIXOS"):
583+
# Use `/etc/os-release` instead of `/etc/NIXOS`.
584+
# The latter one does not exist on NixOS when using tmpfs as root.
585+
try:
586+
with open("/etc/os-release", "r") as f:
587+
if not any(line.strip() == "ID=nixos" for line in f):
588+
return
589+
except FileNotFoundError:
584590
return
585591
if os.path.exists("/lib"):
586592
return

src/bootstrap/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! library.
33
//!
44
//! This module contains some of the real meat in the rustbuild build system
5-
//! which is where Cargo is used to compiler the standard library, libtest, and
5+
//! which is where Cargo is used to compile the standard library, libtest, and
66
//! compiler. This module is also responsible for assembling the sysroot as it
77
//! goes along from the output of the previous stage.
88

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,8 @@ nav.sub {
560560
.docblock table {
561561
margin: .5em 0;
562562
width: calc(100% - 2px);
563-
border: 1px dashed;
563+
overflow-x: auto;
564+
display: block;
564565
}
565566

566567
.docblock table td {

src/librustdoc/html/static/css/themes/ayu.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pre, .rustdoc.source .example-wrap {
140140
border-bottom-color: #5c6773;
141141
}
142142

143-
.docblock table, .docblock table td, .docblock table th {
143+
.docblock table td, .docblock table th {
144144
border-color: #5c6773;
145145
}
146146

src/librustdoc/html/static/css/themes/dark.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pre, .rustdoc.source .example-wrap {
9797
border-bottom-color: #DDD;
9898
}
9999

100-
.docblock table, .docblock table td, .docblock table th {
100+
.docblock table td, .docblock table th {
101101
border-color: #ddd;
102102
}
103103

src/librustdoc/html/static/css/themes/light.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pre, .rustdoc.source .example-wrap {
9797
border-bottom-color: #ddd;
9898
}
9999

100-
.docblock table, .docblock table td, .docblock table th {
100+
.docblock table td, .docblock table th {
101101
border-color: #ddd;
102102
}
103103

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This test ensures that the type declaration content overflow is handled inside the <pre> directly.
2+
goto: file://|DOC_PATH|/lib2/long_table/struct.Foo.html
3+
// We set a fixed size so there is no chance of "random" resize.
4+
size: (1100, 800)
5+
// Logically, the ".docblock" and the "<p>" should have the same scroll width.
6+
compare-elements-property: (".top-doc .docblock", ".top-doc .docblock > p", ["scrollWidth"])
7+
assert-property: (".top-doc .docblock", {"scrollWidth": "816"})
8+
// However, since there is overflow in the <table>, its scroll width is bigger.
9+
assert-property: (".top-doc .docblock table", {"scrollWidth": "1573"})

src/test/rustdoc-gui/src/lib2/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,12 @@ pub mod long_trait {
5757
pub trait ALongNameBecauseItHelpsTestingTheCurrentProblem: DerefMut<Target = u32>
5858
+ From<u128> + Send + Sync + AsRef<str> + 'static {}
5959
}
60+
61+
pub mod long_table {
62+
/// | This::is::a::kinda::very::long::header::number::one | This::is::a::kinda::very::long::header::number::two | This::is::a::kinda::very::long::header::number::one | This::is::a::kinda::very::long::header::number::two |
63+
/// | ----------- | ----------- | ----------- | ----------- |
64+
/// | This::is::a::kinda::long::content::number::one | This::is::a::kinda::very::long::content::number::two | This::is::a::kinda::long::content::number::one | This::is::a::kinda::very::long::content::number::two |
65+
///
66+
/// I wanna sqdkfnqds f dsqf qds f dsqf dsq f dsq f qds f qds f qds f dsqq f dsf sqdf dsq fds f dsq f dq f ds fq sd fqds f dsq f sqd fsq df sd fdsqfqsd fdsq f dsq f dsqfd s dfq
67+
pub struct Foo;
68+
}

src/test/rustdoc-gui/src/lib2/src/lib.rs

-7
This file was deleted.

src/test/ui/feature-gates/feature-gate-optimize_attribute.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ LL | #[optimize(banana)]
5151

5252
error: aborting due to 6 previous errors
5353

54-
For more information about this error, try `rustc --explain E0658`.
54+
Some errors have detailed explanations: E0658, E0722.
55+
For more information about an error, try `rustc --explain E0658`.

src/test/ui/ffi_const2.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | #[ffi_pure]
66

77
error: aborting due to previous error
88

9+
For more information about this error, try `rustc --explain E0757`.

0 commit comments

Comments
 (0)