Skip to content

Commit d3ad51b

Browse files
committed
Auto merge of rust-lang#94369 - matthiaskrgr:rollup-qtripm2, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - rust-lang#93850 (Don't ICE when an extern static is too big for the current architecture) - rust-lang#94154 (Wire up unstable rustc --check-cfg to rustdoc) - rust-lang#94353 (Fix debug_assert in unused lint pass) - rust-lang#94366 (Add missing item to release notes) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents d981633 + 152af5a commit d3ad51b

20 files changed

+182
-18
lines changed

RELEASES.md

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Stabilized APIs
5858
- [`NonZeroU32::is_power_of_two`][is_power_of_two32]
5959
- [`NonZeroU64::is_power_of_two`][is_power_of_two64]
6060
- [`NonZeroU128::is_power_of_two`][is_power_of_two128]
61+
- [`NonZeroUsize::is_power_of_two`][is_power_of_two_usize]
6162
- [`DoubleEndedIterator for ToLowercase`][lowercase]
6263
- [`DoubleEndedIterator for ToUppercase`][uppercase]
6364
- [`TryFrom<&mut [T]> for [T; N]`][tryfrom_ref_arr]
@@ -178,6 +179,7 @@ and related tools.
178179
[is_power_of_two32]: https://doc.rust-lang.org/stable/core/num/struct.NonZeroU32.html#method.is_power_of_two
179180
[is_power_of_two64]: https://doc.rust-lang.org/stable/core/num/struct.NonZeroU64.html#method.is_power_of_two
180181
[is_power_of_two128]: https://doc.rust-lang.org/stable/core/num/struct.NonZeroU128.html#method.is_power_of_two
182+
[is_power_of_two_usize]: https://doc.rust-lang.org/stable/core/num/struct.NonZeroUsize.html#method.is_power_of_two
181183
[stdarch/1266]: https://github.com/rust-lang/stdarch/pull/1266
182184

183185
Version 1.58.1 (2022-01-19)

compiler/rustc_lint/src/unused.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -240,17 +240,17 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
240240
}
241241
ty::Tuple(ref tys) => {
242242
let mut has_emitted = false;
243-
let spans = if let hir::ExprKind::Tup(comps) = &expr.kind {
243+
let comps = if let hir::ExprKind::Tup(comps) = expr.kind {
244244
debug_assert_eq!(comps.len(), tys.len());
245-
comps.iter().map(|e| e.span).collect()
245+
comps
246246
} else {
247-
vec![]
247+
&[]
248248
};
249249
for (i, ty) in tys.iter().enumerate() {
250250
let descr_post = &format!(" in tuple element {}", i);
251-
let span = *spans.get(i).unwrap_or(&span);
252-
if check_must_use_ty(cx, ty, expr, span, descr_pre, descr_post, plural_len)
253-
{
251+
let e = comps.get(i).unwrap_or(expr);
252+
let span = e.span;
253+
if check_must_use_ty(cx, ty, e, span, descr_pre, descr_post, plural_len) {
254254
has_emitted = true;
255255
}
256256
}

compiler/rustc_typeck/src/check/check.rs

+25-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKi
1414
use rustc_infer::infer::{RegionVariableOrigin, TyCtxtInferExt};
1515
use rustc_middle::hir::nested_filter;
1616
use rustc_middle::ty::fold::TypeFoldable;
17-
use rustc_middle::ty::layout::MAX_SIMD_LANES;
17+
use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES};
1818
use rustc_middle::ty::subst::GenericArgKind;
1919
use rustc_middle::ty::util::{Discr, IntTypeExt};
2020
use rustc_middle::ty::{self, OpaqueTypeKey, ParamEnv, Ty, TyCtxt};
@@ -417,10 +417,31 @@ fn check_static_inhabited<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, span: Spa
417417
// have UB during initialization if they are uninhabited, but there also seems to be no good
418418
// reason to allow any statics to be uninhabited.
419419
let ty = tcx.type_of(def_id);
420-
let Ok(layout) = tcx.layout_of(ParamEnv::reveal_all().and(ty)) else {
420+
let layout = match tcx.layout_of(ParamEnv::reveal_all().and(ty)) {
421+
Ok(l) => l,
422+
// Foreign statics that overflow their allowed size should emit an error
423+
Err(LayoutError::SizeOverflow(_))
424+
if {
425+
let node = tcx.hir().get_by_def_id(def_id);
426+
matches!(
427+
node,
428+
hir::Node::ForeignItem(hir::ForeignItem {
429+
kind: hir::ForeignItemKind::Static(..),
430+
..
431+
})
432+
)
433+
} =>
434+
{
435+
tcx.sess
436+
.struct_span_err(span, "extern static is too large for the current architecture")
437+
.emit();
438+
return;
439+
}
421440
// Generic statics are rejected, but we still reach this case.
422-
tcx.sess.delay_span_bug(span, "generic static must be rejected");
423-
return;
441+
Err(e) => {
442+
tcx.sess.delay_span_bug(span, &e.to_string());
443+
return;
444+
}
424445
};
425446
if layout.abi.is_uninhabited() {
426447
tcx.struct_span_lint_hir(

src/doc/rustdoc/src/unstable-features.md

+14
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,17 @@ crate being documented (`foobar`) and a path to output the calls
512512

513513
To scrape examples from test code, e.g. functions marked `#[test]`, then
514514
add the `--scrape-tests` flag.
515+
516+
### `--check-cfg`: check configuration flags
517+
518+
This flag accepts the same values as `rustc --check-cfg`, and uses it to check configuration flags.
519+
520+
Using this flag looks like this:
521+
522+
```bash
523+
$ rustdoc src/lib.rs -Z unstable-options \
524+
--check-cfg='names()' --check-cfg='values(feature, "foo", "bar")'
525+
```
526+
527+
The example above check every well known names (`target_os`, `doc`, `test`, ... via `names()`)
528+
and check the values of `feature`: `foo` and `bar`.

src/librustdoc/config.rs

+5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ crate struct Options {
8080
crate extern_strs: Vec<String>,
8181
/// List of `cfg` flags to hand to the compiler. Always includes `rustdoc`.
8282
crate cfgs: Vec<String>,
83+
/// List of check cfg flags to hand to the compiler.
84+
crate check_cfgs: Vec<String>,
8385
/// Codegen options to hand to the compiler.
8486
crate codegen_options: CodegenOptions,
8587
/// Codegen options strings to hand to the compiler.
@@ -172,6 +174,7 @@ impl fmt::Debug for Options {
172174
.field("libs", &self.libs)
173175
.field("externs", &FmtExterns(&self.externs))
174176
.field("cfgs", &self.cfgs)
177+
.field("check-cfgs", &self.check_cfgs)
175178
.field("codegen_options", &"...")
176179
.field("debugging_options", &"...")
177180
.field("target", &self.target)
@@ -506,6 +509,7 @@ impl Options {
506509
};
507510

508511
let cfgs = matches.opt_strs("cfg");
512+
let check_cfgs = matches.opt_strs("check-cfg");
509513

510514
let extension_css = matches.opt_str("e").map(|s| PathBuf::from(&s));
511515

@@ -677,6 +681,7 @@ impl Options {
677681
externs,
678682
extern_strs,
679683
cfgs,
684+
check_cfgs,
680685
codegen_options,
681686
codegen_options_strs,
682687
debugging_opts,

src/librustdoc/core.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ crate fn create_config(
192192
libs,
193193
externs,
194194
mut cfgs,
195+
check_cfgs,
195196
codegen_options,
196197
debugging_opts,
197198
target,
@@ -219,6 +220,7 @@ crate fn create_config(
219220
// these are definitely not part of rustdoc, but we want to warn on them anyway.
220221
rustc_lint::builtin::RENAMED_AND_REMOVED_LINTS.name.to_string(),
221222
rustc_lint::builtin::UNKNOWN_LINTS.name.to_string(),
223+
rustc_lint::builtin::UNEXPECTED_CFGS.name.to_string(),
222224
];
223225
lints_to_show.extend(crate::lint::RUSTDOC_LINTS.iter().map(|lint| lint.name.to_string()));
224226

@@ -253,7 +255,7 @@ crate fn create_config(
253255
interface::Config {
254256
opts: sessopts,
255257
crate_cfg: interface::parse_cfgspecs(cfgs),
256-
crate_check_cfg: interface::parse_check_cfg(vec![]),
258+
crate_check_cfg: interface::parse_check_cfg(check_cfgs),
257259
input,
258260
input_path: cpath,
259261
output_file: None,

src/librustdoc/doctest.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ crate fn run(options: RustdocOptions) -> Result<(), ErrorReported> {
9191
let config = interface::Config {
9292
opts: sessopts,
9393
crate_cfg: interface::parse_cfgspecs(cfgs),
94-
crate_check_cfg: interface::parse_check_cfg(vec![]),
94+
crate_check_cfg: interface::parse_check_cfg(options.check_cfgs.clone()),
9595
input,
9696
input_path: None,
9797
output_file: None,
@@ -321,6 +321,12 @@ fn run_test(
321321
for cfg in &rustdoc_options.cfgs {
322322
compiler.arg("--cfg").arg(&cfg);
323323
}
324+
if !rustdoc_options.check_cfgs.is_empty() {
325+
compiler.arg("-Z").arg("unstable-options");
326+
for check_cfg in &rustdoc_options.check_cfgs {
327+
compiler.arg("--check-cfg").arg(&check_cfg);
328+
}
329+
}
324330
if let Some(sysroot) = rustdoc_options.maybe_sysroot {
325331
compiler.arg("--sysroot").arg(sysroot);
326332
}

src/librustdoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ fn opts() -> Vec<RustcOptGroup> {
260260
o.optmulti("L", "library-path", "directory to add to crate search path", "DIR")
261261
}),
262262
stable("cfg", |o| o.optmulti("", "cfg", "pass a --cfg to rustc", "")),
263+
unstable("check-cfg", |o| o.optmulti("", "check-cfg", "pass a --check-cfg to rustc", "")),
263264
stable("extern", |o| o.optmulti("", "extern", "pass an --extern to rustc", "NAME[=PATH]")),
264265
unstable("extern-html-root-url", |o| {
265266
o.optmulti(

src/test/rustdoc-ui/check-cfg-test.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// check-pass
2+
// compile-flags: --test --nocapture --check-cfg=values(feature,"test") -Z unstable-options
3+
// normalize-stderr-test: "src/test/rustdoc-ui" -> "$$DIR"
4+
// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR"
5+
// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
6+
7+
/// The doctest will produce a warning because feature invalid is unexpected
8+
/// ```
9+
/// #[cfg(feature = "invalid")]
10+
/// assert!(false);
11+
/// ```
12+
pub struct Foo;
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: unexpected `cfg` condition value
2+
--> $DIR/check-cfg-test.rs:9:7
3+
|
4+
LL | #[cfg(feature = "invalid")]
5+
| ^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(unexpected_cfgs)]` on by default
8+
= note: expected values for `feature` are: test
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
running 1 test
3+
test $DIR/check-cfg-test.rs - Foo (line 8) ... ok
4+
5+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// check-fail
2+
// compile-flags: --check-cfg=names()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: the `-Z unstable-options` flag must also be passed to enable the flag `check-cfg`
2+

src/test/rustdoc-ui/check-cfg.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// check-pass
2+
// compile-flags: --check-cfg=names() -Z unstable-options
3+
4+
/// uniz is nor a builtin nor pass as arguments so is unexpected
5+
#[cfg(uniz)]
6+
//~^ WARNING unexpected `cfg` condition name
7+
pub struct Bar;

src/test/rustdoc-ui/check-cfg.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: unexpected `cfg` condition name
2+
--> $DIR/check-cfg.rs:5:7
3+
|
4+
LL | #[cfg(uniz)]
5+
| ^^^^ help: did you mean: `unix`
6+
|
7+
= note: `#[warn(unexpected_cfgs)]` on by default
8+
9+
warning: 1 warning emitted
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#[repr(C)]
2+
struct ReallyBig {
3+
_a: [u8; usize::MAX],
4+
}
5+
6+
// The limit for "too big for the current architecture" is dependent on the target pointer size
7+
// however it's artifically limited on 64 bits
8+
// logic copied from rustc_target::abi::TargetDataLayout::obj_size_bound()
9+
const fn max_size() -> usize {
10+
#[cfg(target_pointer_width = "16")]
11+
{
12+
1 << 15
13+
}
14+
15+
#[cfg(target_pointer_width = "32")]
16+
{
17+
1 << 31
18+
}
19+
20+
#[cfg(target_pointer_width = "64")]
21+
{
22+
1 << 47
23+
}
24+
25+
#[cfg(not(any(
26+
target_pointer_width = "16",
27+
target_pointer_width = "32",
28+
target_pointer_width = "64"
29+
)))]
30+
{
31+
isize::MAX as usize
32+
}
33+
}
34+
35+
extern "C" {
36+
static FOO: [u8; 1];
37+
static BAR: [u8; max_size() - 1];
38+
static BAZ: [u8; max_size()]; //~ ERROR extern static is too large
39+
static UWU: [usize; usize::MAX]; //~ ERROR extern static is too large
40+
static A: ReallyBig; //~ ERROR extern static is too large
41+
}
42+
43+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: extern static is too large for the current architecture
2+
--> $DIR/extern-static-size-overflow.rs:38:5
3+
|
4+
LL | static BAZ: [u8; max_size()];
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: extern static is too large for the current architecture
8+
--> $DIR/extern-static-size-overflow.rs:39:5
9+
|
10+
LL | static UWU: [usize; usize::MAX];
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: extern static is too large for the current architecture
14+
--> $DIR/extern-static-size-overflow.rs:40:5
15+
|
16+
LL | static A: ReallyBig;
17+
| ^^^^^^^^^^^^^^^^^^^^
18+
19+
error: aborting due to 3 previous errors
20+

src/test/ui/lint/unused/must_use-array.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ error: unused array of boxed `T` trait objects in tuple element 1 that must be u
3232
--> $DIR/must_use-array.rs:43:5
3333
|
3434
LL | impl_array();
35-
| ^^^^^^^^^^^^^
35+
| ^^^^^^^^^^^^
3636

3737
error: unused array of arrays of arrays of `S` that must be used
3838
--> $DIR/must_use-array.rs:45:5

src/test/ui/lint/unused/must_use-trait.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ error: unused boxed `Critical` trait object in tuple element 1 that must be used
2626
--> $DIR/must_use-trait.rs:37:5
2727
|
2828
LL | get_critical_tuple();
29-
| ^^^^^^^^^^^^^^^^^^^^^
29+
| ^^^^^^^^^^^^^^^^^^^^
3030

3131
error: unused implementer of `Critical` in tuple element 2 that must be used
3232
--> $DIR/must_use-trait.rs:37:5
3333
|
3434
LL | get_critical_tuple();
35-
| ^^^^^^^^^^^^^^^^^^^^^
35+
| ^^^^^^^^^^^^^^^^^^^^
3636

3737
error: aborting due to 5 previous errors
3838

src/test/ui/lint/unused/must_use-tuple.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ error: unused `Result` in tuple element 0 that must be used
3131
--> $DIR/must_use-tuple.rs:14:5
3232
|
3333
LL | foo();
34-
| ^^^^^^
34+
| ^^^^^
3535
|
3636
= note: this `Result` may be an `Err` variant, which should be handled
3737

3838
error: unused `Result` in tuple element 0 that must be used
39-
--> $DIR/must_use-tuple.rs:16:6
39+
--> $DIR/must_use-tuple.rs:16:7
4040
|
4141
LL | ((Err::<(), ()>(()), ()), ());
42-
| ^^^^^^^^^^^^^^^^^^^^^^^
42+
| ^^^^^^^^^^^^^^^^^
4343
|
4444
= note: this `Result` may be an `Err` variant, which should be handled
4545

0 commit comments

Comments
 (0)