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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 25 additions & 4 deletions
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

Lines changed: 14 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 7 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 12 additions & 0 deletions
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;
Lines changed: 11 additions & 0 deletions
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+

0 commit comments

Comments
 (0)