Skip to content

Commit 49720d2

Browse files
committed
Auto merge of rust-lang#78512 - JohnTitor:rollup-a7qwjah, r=JohnTitor
Rollup of 11 pull requests Successful merges: - rust-lang#77213 (rustdoc options to set default theme (and other settings)) - rust-lang#78224 (min_const_generics: allow ty param in repeat expr) - rust-lang#78428 (MinConstGenerics UI test for invalid values for bool & char) - rust-lang#78460 (Adjust turbofish help message for const generics) - rust-lang#78470 (Clean up intra-doc links in `std::path`) - rust-lang#78475 (fix a comment in validity check) - rust-lang#78478 (Add const generics tests for supertraits + dyn traits.) - rust-lang#78487 (Fix typo "compiltest") - rust-lang#78491 (Inline NonZeroN::from(n)) - rust-lang#78492 (Update books) - rust-lang#78494 (Fix typos) Failed merges: r? `@ghost`
2 parents f9187ad + 30d1d8f commit 49720d2

38 files changed

+562
-112
lines changed

compiler/rustc_hir/src/def.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,10 @@ pub enum Res<Id = hir::HirId> {
206206
/// ```rust
207207
/// impl Foo { fn test() -> [u8; std::mem::size_of::<Self>()] {} }
208208
/// ```
209+
/// We do however allow `Self` in repeat expression even if it is generic to not break code
210+
/// which already works on stable while causing the `const_evaluatable_unchecked` future compat lint.
209211
///
210-
/// FIXME(lazy_normalization_consts): Remove this bodge once this feature is stable.
212+
/// FIXME(lazy_normalization_consts): Remove this bodge once that feature is stable.
211213
SelfTy(Option<DefId> /* trait */, Option<(DefId, bool)> /* impl */),
212214
ToolMod, // e.g., `rustfmt` in `#[rustfmt::skip]`
213215

compiler/rustc_infer/src/infer/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
678678

679679
pub fn unsolved_variables(&self) -> Vec<Ty<'tcx>> {
680680
let mut inner = self.inner.borrow_mut();
681-
// FIXME(const_generics): should there be an equivalent function for const variables?
682-
683681
let mut vars: Vec<Ty<'_>> = inner
684682
.type_variables()
685683
.unsolved_variables()

compiler/rustc_mir/src/dataflow/impls/borrows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
177177
//
178178
// We are careful always to call this function *before* we
179179
// set up the gen-bits for the statement or
180-
// termanator. That way, if the effect of the statement or
180+
// terminator. That way, if the effect of the statement or
181181
// terminator *does* introduce a new loan of the same
182182
// region, then setting that gen-bit will override any
183183
// potential kill introduced here.

compiler/rustc_mir/src/dataflow/impls/liveness.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::dataflow::{AnalysisDomain, Backward, GenKill, GenKillAnalysis};
88
///
99
/// This analysis considers references as being used only at the point of the
1010
/// borrow. In other words, this analysis does not track uses because of references that already
11-
/// exist. See [this `mir-datalow` test][flow-test] for an example. You almost never want to use
11+
/// exist. See [this `mir-dataflow` test][flow-test] for an example. You almost never want to use
1212
/// this analysis without also looking at the results of [`MaybeBorrowedLocals`].
1313
///
1414
/// [`MaybeBorrowedLocals`]: ../struct.MaybeBorrowedLocals.html
@@ -134,7 +134,7 @@ impl DefUse {
134134

135135
// `MutatingUseContext::Call` and `MutatingUseContext::Yield` indicate that this is the
136136
// destination place for a `Call` return or `Yield` resume respectively. Since this is
137-
// only a `Def` when the function returns succesfully, we handle this case separately
137+
// only a `Def` when the function returns successfully, we handle this case separately
138138
// in `call_return_effect` above.
139139
PlaceContext::MutatingUse(MutatingUseContext::Call | MutatingUseContext::Yield) => None,
140140

compiler/rustc_mir/src/interpret/validity.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
579579
// Nothing to check.
580580
Ok(true)
581581
}
582-
// The above should be all the (inhabited) primitive types. The rest is compound, we
582+
// The above should be all the primitive types. The rest is compound, we
583583
// check them by visiting their fields/variants.
584-
// (`Str` UTF-8 check happens in `visit_aggregate`, too.)
585584
ty::Adt(..)
586585
| ty::Tuple(..)
587586
| ty::Array(..)

compiler/rustc_parse/src/parser/diagnostics.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use rustc_span::{MultiSpan, Span, SpanSnippetError, DUMMY_SP};
2020

2121
use tracing::{debug, trace};
2222

23-
const TURBOFISH: &str = "use `::<...>` instead of `<...>` to specify type arguments";
23+
const TURBOFISH_SUGGESTION_STR: &str =
24+
"use `::<...>` instead of `<...>` to specify type or const arguments";
2425

2526
/// Creates a placeholder argument.
2627
pub(super) fn dummy_arg(ident: Ident) -> Param {
@@ -659,7 +660,7 @@ impl<'a> Parser<'a> {
659660
Ok(_) => {
660661
e.span_suggestion_verbose(
661662
binop.span.shrink_to_lo(),
662-
"use `::<...>` instead of `<...>` to specify type arguments",
663+
TURBOFISH_SUGGESTION_STR,
663664
"::".to_string(),
664665
Applicability::MaybeIncorrect,
665666
);
@@ -814,7 +815,7 @@ impl<'a> Parser<'a> {
814815
let suggest = |err: &mut DiagnosticBuilder<'_>| {
815816
err.span_suggestion_verbose(
816817
op.span.shrink_to_lo(),
817-
TURBOFISH,
818+
TURBOFISH_SUGGESTION_STR,
818819
"::".to_string(),
819820
Applicability::MaybeIncorrect,
820821
);
@@ -888,7 +889,7 @@ impl<'a> Parser<'a> {
888889
{
889890
// All we know is that this is `foo < bar >` and *nothing* else. Try to
890891
// be helpful, but don't attempt to recover.
891-
err.help(TURBOFISH);
892+
err.help(TURBOFISH_SUGGESTION_STR);
892893
err.help("or use `(...)` if you meant to specify fn arguments");
893894
}
894895

compiler/rustc_resolve/src/late.rs

+70-18
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ enum PatternSource {
5757
FnParam,
5858
}
5959

60+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
61+
enum IsRepeatExpr {
62+
No,
63+
Yes,
64+
}
65+
6066
impl PatternSource {
6167
fn descr(self) -> &'static str {
6268
match self {
@@ -437,10 +443,8 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
437443
self.resolve_block(block);
438444
}
439445
fn visit_anon_const(&mut self, constant: &'ast AnonConst) {
440-
debug!("visit_anon_const {:?}", constant);
441-
self.with_constant_rib(constant.value.is_potential_trivial_const_param(), |this| {
442-
visit::walk_anon_const(this, constant);
443-
});
446+
// We deal with repeat expressions explicitly in `resolve_expr`.
447+
self.resolve_anon_const(constant, IsRepeatExpr::No);
444448
}
445449
fn visit_expr(&mut self, expr: &'ast Expr) {
446450
self.resolve_expr(expr, None);
@@ -647,7 +651,11 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
647651
if !check_ns(TypeNS) && check_ns(ValueNS) {
648652
// This must be equivalent to `visit_anon_const`, but we cannot call it
649653
// directly due to visitor lifetimes so we have to copy-paste some code.
650-
self.with_constant_rib(true, |this| {
654+
//
655+
// Note that we might not be inside of an repeat expression here,
656+
// but considering that `IsRepeatExpr` is only relevant for
657+
// non-trivial constants this is doesn't matter.
658+
self.with_constant_rib(IsRepeatExpr::No, true, |this| {
651659
this.smart_resolve_path(
652660
ty.id,
653661
qself.as_ref(),
@@ -980,9 +988,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
980988
//
981989
// Type parameters can already be used and as associated consts are
982990
// not used as part of the type system, this is far less surprising.
983-
this.with_constant_rib(true, |this| {
984-
this.visit_expr(expr)
985-
});
991+
this.with_constant_rib(
992+
IsRepeatExpr::No,
993+
true,
994+
|this| this.visit_expr(expr),
995+
);
986996
}
987997
}
988998
AssocItemKind::Fn(_, _, generics, _) => {
@@ -1023,7 +1033,9 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
10231033
self.with_item_rib(HasGenericParams::No, |this| {
10241034
this.visit_ty(ty);
10251035
if let Some(expr) = expr {
1026-
this.with_constant_rib(expr.is_potential_trivial_const_param(), |this| {
1036+
// We already forbid generic params because of the above item rib,
1037+
// so it doesn't matter whether this is a trivial constant.
1038+
this.with_constant_rib(IsRepeatExpr::No, true, |this| {
10271039
this.visit_expr(expr)
10281040
});
10291041
}
@@ -1122,12 +1134,29 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
11221134
self.with_rib(ValueNS, kind, |this| this.with_rib(TypeNS, kind, f))
11231135
}
11241136

1125-
fn with_constant_rib(&mut self, trivial: bool, f: impl FnOnce(&mut Self)) {
1126-
debug!("with_constant_rib");
1127-
self.with_rib(ValueNS, ConstantItemRibKind(trivial), |this| {
1128-
this.with_rib(TypeNS, ConstantItemRibKind(trivial), |this| {
1129-
this.with_label_rib(ConstantItemRibKind(trivial), f);
1130-
})
1137+
// HACK(min_const_generics,const_evaluatable_unchecked): We
1138+
// want to keep allowing `[0; std::mem::size_of::<*mut T>()]`
1139+
// with a future compat lint for now. We do this by adding an
1140+
// additional special case for repeat expressions.
1141+
//
1142+
// Note that we intentionally still forbid `[0; N + 1]` during
1143+
// name resolution so that we don't extend the future
1144+
// compat lint to new cases.
1145+
fn with_constant_rib(
1146+
&mut self,
1147+
is_repeat: IsRepeatExpr,
1148+
is_trivial: bool,
1149+
f: impl FnOnce(&mut Self),
1150+
) {
1151+
debug!("with_constant_rib: is_repeat={:?} is_trivial={}", is_repeat, is_trivial);
1152+
self.with_rib(ValueNS, ConstantItemRibKind(is_trivial), |this| {
1153+
this.with_rib(
1154+
TypeNS,
1155+
ConstantItemRibKind(is_repeat == IsRepeatExpr::Yes || is_trivial),
1156+
|this| {
1157+
this.with_label_rib(ConstantItemRibKind(is_trivial), f);
1158+
},
1159+
)
11311160
});
11321161
}
11331162

@@ -1272,9 +1301,17 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
12721301
//
12731302
// Type parameters can already be used and as associated consts are
12741303
// not used as part of the type system, this is far less surprising.
1275-
this.with_constant_rib(true, |this| {
1276-
visit::walk_assoc_item(this, item, AssocCtxt::Impl)
1277-
});
1304+
this.with_constant_rib(
1305+
IsRepeatExpr::No,
1306+
true,
1307+
|this| {
1308+
visit::walk_assoc_item(
1309+
this,
1310+
item,
1311+
AssocCtxt::Impl,
1312+
)
1313+
},
1314+
);
12781315
}
12791316
AssocItemKind::Fn(_, _, generics, _) => {
12801317
// We also need a new scope for the impl item type parameters.
@@ -2199,6 +2236,17 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
21992236
debug!("(resolving block) leaving block");
22002237
}
22012238

2239+
fn resolve_anon_const(&mut self, constant: &'ast AnonConst, is_repeat: IsRepeatExpr) {
2240+
debug!("resolve_anon_const {:?} is_repeat: {:?}", constant, is_repeat);
2241+
self.with_constant_rib(
2242+
is_repeat,
2243+
constant.value.is_potential_trivial_const_param(),
2244+
|this| {
2245+
visit::walk_anon_const(this, constant);
2246+
},
2247+
);
2248+
}
2249+
22022250
fn resolve_expr(&mut self, expr: &'ast Expr, parent: Option<&'ast Expr>) {
22032251
// First, record candidate traits for this expression if it could
22042252
// result in the invocation of a method call.
@@ -2322,6 +2370,10 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
23222370
ExprKind::Async(..) | ExprKind::Closure(..) => {
23232371
self.with_label_rib(ClosureOrAsyncRibKind, |this| visit::walk_expr(this, expr));
23242372
}
2373+
ExprKind::Repeat(ref elem, ref ct) => {
2374+
self.visit_expr(elem);
2375+
self.resolve_anon_const(ct, IsRepeatExpr::Yes);
2376+
}
23252377
_ => {
23262378
visit::walk_expr(self, expr);
23272379
}

library/core/src/num/nonzero.rs

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ assert_eq!(size_of::<Option<core::num::", stringify!($Ty), ">>(), size_of::<", s
9292
doc_comment! {
9393
concat!(
9494
"Converts a `", stringify!($Ty), "` into an `", stringify!($Int), "`"),
95+
#[inline]
9596
fn from(nonzero: $Ty) -> Self {
9697
nonzero.0
9798
}

library/std/src/path.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ impl Hash for PrefixComponent<'_> {
446446
/// (`/` or `\`).
447447
///
448448
/// This `enum` is created by iterating over [`Components`], which in turn is
449-
/// created by the [`components`][`Path::components`] method on [`Path`].
449+
/// created by the [`components`](Path::components) method on [`Path`].
450450
///
451451
/// # Examples
452452
///
@@ -1319,7 +1319,7 @@ impl PathBuf {
13191319
self.inner
13201320
}
13211321

1322-
/// Converts this `PathBuf` into a [boxed][`Box`] [`Path`].
1322+
/// Converts this `PathBuf` into a [boxed](Box) [`Path`].
13231323
#[stable(feature = "into_boxed_path", since = "1.20.0")]
13241324
pub fn into_boxed_path(self) -> Box<Path> {
13251325
let rw = Box::into_raw(self.inner.into_boxed_os_str()) as *mut Path;
@@ -1686,8 +1686,7 @@ pub struct Path {
16861686
inner: OsStr,
16871687
}
16881688

1689-
/// An error returned from [`Path::strip_prefix`][`strip_prefix`] if the prefix
1690-
/// was not found.
1689+
/// An error returned from [`Path::strip_prefix`] if the prefix was not found.
16911690
///
16921691
/// This `struct` is created by the [`strip_prefix`] method on [`Path`].
16931692
/// See its documentation for more.
@@ -2470,7 +2469,7 @@ impl Path {
24702469
fs::metadata(self).map(|m| m.is_dir()).unwrap_or(false)
24712470
}
24722471

2473-
/// Converts a [`Box<Path>`][`Box`] into a [`PathBuf`] without copying or
2472+
/// Converts a [`Box<Path>`](Box) into a [`PathBuf`] without copying or
24742473
/// allocating.
24752474
#[stable(feature = "into_boxed_path", since = "1.20.0")]
24762475
pub fn into_path_buf(self: Box<Path>) -> PathBuf {
@@ -2498,7 +2497,7 @@ impl fmt::Debug for Path {
24982497
///
24992498
/// A [`Path`] might contain non-Unicode data. This `struct` implements the
25002499
/// [`Display`] trait in a way that mitigates that. It is created by the
2501-
/// [`display`][`Path::display`] method on [`Path`].
2500+
/// [`display`](Path::display) method on [`Path`].
25022501
///
25032502
/// # Examples
25042503
///

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ Using this flag looks like this:
348348
$ rustdoc src/lib.rs -Z unstable-options --enable-per-target-ignores
349349
```
350350

351-
This flag allows you to tag doctests with compiltest style `ignore-foo` filters that prevent
351+
This flag allows you to tag doctests with compiletest style `ignore-foo` filters that prevent
352352
rustdoc from running that test if the target triple string contains foo. For example:
353353

354354
```rust

src/librustdoc/config.rs

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::BTreeMap;
1+
use std::collections::{BTreeMap, HashMap};
22
use std::convert::TryFrom;
33
use std::ffi::OsStr;
44
use std::fmt;
@@ -216,6 +216,9 @@ pub struct RenderOptions {
216216
pub extension_css: Option<PathBuf>,
217217
/// A map of crate names to the URL to use instead of querying the crate's `html_root_url`.
218218
pub extern_html_root_urls: BTreeMap<String, String>,
219+
/// A map of the default settings (values are as for DOM storage API). Keys should lack the
220+
/// `rustdoc-` prefix.
221+
pub default_settings: HashMap<String, String>,
219222
/// If present, suffix added to CSS/JavaScript files when referencing them in generated pages.
220223
pub resource_suffix: String,
221224
/// Whether to run the static CSS/JavaScript through a minifier when outputting them. `true` by
@@ -374,6 +377,32 @@ impl Options {
374377
}
375378
};
376379

380+
let default_settings: Vec<Vec<(String, String)>> = vec![
381+
matches
382+
.opt_str("default-theme")
383+
.iter()
384+
.map(|theme| {
385+
vec![
386+
("use-system-theme".to_string(), "false".to_string()),
387+
("theme".to_string(), theme.to_string()),
388+
]
389+
})
390+
.flatten()
391+
.collect(),
392+
matches
393+
.opt_strs("default-setting")
394+
.iter()
395+
.map(|s| {
396+
let mut kv = s.splitn(2, '=');
397+
// never panics because `splitn` always returns at least one element
398+
let k = kv.next().unwrap().to_string();
399+
let v = kv.next().unwrap_or("true").to_string();
400+
(k, v)
401+
})
402+
.collect(),
403+
];
404+
let default_settings = default_settings.into_iter().flatten().collect();
405+
377406
let test_args = matches.opt_strs("test-args");
378407
let test_args: Vec<String> =
379408
test_args.iter().flat_map(|s| s.split_whitespace()).map(|s| s.to_string()).collect();
@@ -596,6 +625,7 @@ impl Options {
596625
themes,
597626
extension_css,
598627
extern_html_root_urls,
628+
default_settings,
599629
resource_suffix,
600630
enable_minification,
601631
enable_index_page,

0 commit comments

Comments
 (0)