Skip to content

Commit

Permalink
Auto merge of rust-lang#79017 - GuillaumeGomez:rollup-5orhudd, r=Guil…
Browse files Browse the repository at this point in the history
…laumeGomez

Rollup of 6 pull requests

Successful merges:

 - rust-lang#77151 (Add regression test for issue rust-lang#76042)
 - rust-lang#77996 (Doc change: Remove mention of `fnv` in HashMap)
 - rust-lang#78463 (Add type to `ConstKind::Placeholder`)
 - rust-lang#78984 (Rustdoc check option)
 - rust-lang#78985 (add dropck test for const params)
 - rust-lang#78996 (add explicit test for const param promotion)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Nov 13, 2020
2 parents a1f7ca7 + 7ea8e32 commit f2a11a2
Show file tree
Hide file tree
Showing 22 changed files with 286 additions and 62 deletions.
10 changes: 5 additions & 5 deletions compiler/rustc_infer/src/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl CanonicalizeRegionMode for CanonicalizeFreeRegionsOtherThanStatic {
struct Canonicalizer<'cx, 'tcx> {
infcx: Option<&'cx InferCtxt<'cx, 'tcx>>,
tcx: TyCtxt<'tcx>,
variables: SmallVec<[CanonicalVarInfo; 8]>,
variables: SmallVec<[CanonicalVarInfo<'tcx>; 8]>,
query_state: &'cx mut OriginalQueryValues<'tcx>,
// Note that indices is only used once `var_values` is big enough to be
// heap-allocated.
Expand Down Expand Up @@ -542,7 +542,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
/// or returns an existing variable if `kind` has already been
/// seen. `kind` is expected to be an unbound variable (or
/// potentially a free region).
fn canonical_var(&mut self, info: CanonicalVarInfo, kind: GenericArg<'tcx>) -> BoundVar {
fn canonical_var(&mut self, info: CanonicalVarInfo<'tcx>, kind: GenericArg<'tcx>) -> BoundVar {
let Canonicalizer { variables, query_state, indices, .. } = self;

let var_values = &mut query_state.var_values;
Expand Down Expand Up @@ -621,7 +621,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
/// representing the region `r`; return a region referencing it.
fn canonical_var_for_region(
&mut self,
info: CanonicalVarInfo,
info: CanonicalVarInfo<'tcx>,
r: ty::Region<'tcx>,
) -> ty::Region<'tcx> {
let var = self.canonical_var(info, r.into());
Expand All @@ -633,7 +633,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
/// if `ty_var` is bound to anything; if so, canonicalize
/// *that*. Otherwise, create a new canonical variable for
/// `ty_var`.
fn canonicalize_ty_var(&mut self, info: CanonicalVarInfo, ty_var: Ty<'tcx>) -> Ty<'tcx> {
fn canonicalize_ty_var(&mut self, info: CanonicalVarInfo<'tcx>, ty_var: Ty<'tcx>) -> Ty<'tcx> {
let infcx = self.infcx.expect("encountered ty-var without infcx");
let bound_to = infcx.shallow_resolve(ty_var);
if bound_to != ty_var {
Expand All @@ -650,7 +650,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
/// `const_var`.
fn canonicalize_const_var(
&mut self,
info: CanonicalVarInfo,
info: CanonicalVarInfo<'tcx>,
const_var: &'tcx ty::Const<'tcx>,
) -> &'tcx ty::Const<'tcx> {
let infcx = self.infcx.expect("encountered const-var without infcx");
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/canonical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
fn instantiate_canonical_vars(
&self,
span: Span,
variables: &List<CanonicalVarInfo>,
variables: &List<CanonicalVarInfo<'tcx>>,
universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex,
) -> CanonicalVarValues<'tcx> {
let var_values: IndexVec<BoundVar, GenericArg<'tcx>> = variables
Expand All @@ -100,7 +100,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
fn instantiate_canonical_var(
&self,
span: Span,
cv_info: CanonicalVarInfo,
cv_info: CanonicalVarInfo<'tcx>,
universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex,
) -> GenericArg<'tcx> {
match cv_info.kind {
Expand Down Expand Up @@ -154,7 +154,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
self.tcx
.mk_const(ty::Const {
val: ty::ConstKind::Placeholder(placeholder_mapped),
ty: self.tcx.ty_error(), // FIXME(const_generics)
ty: name.ty,
})
.into()
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/higher_ranked/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
self.tcx.mk_const(ty::Const {
val: ty::ConstKind::Placeholder(ty::PlaceholderConst {
universe: next_universe,
name: bound_var,
name: ty::BoundConst { var: bound_var, ty },
}),
ty,
})
Expand Down
22 changes: 12 additions & 10 deletions compiler/rustc_middle/src/infer/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct Canonical<'tcx, V> {
pub value: V,
}

pub type CanonicalVarInfos<'tcx> = &'tcx List<CanonicalVarInfo>;
pub type CanonicalVarInfos<'tcx> = &'tcx List<CanonicalVarInfo<'tcx>>;

/// A set of values corresponding to the canonical variables from some
/// `Canonical`. You can give these values to
Expand Down Expand Up @@ -88,11 +88,11 @@ impl Default for OriginalQueryValues<'tcx> {
/// a copy of the canonical value in some other inference context,
/// with fresh inference variables replacing the canonical values.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyDecodable, TyEncodable, HashStable)]
pub struct CanonicalVarInfo {
pub kind: CanonicalVarKind,
pub struct CanonicalVarInfo<'tcx> {
pub kind: CanonicalVarKind<'tcx>,
}

impl CanonicalVarInfo {
impl<'tcx> CanonicalVarInfo<'tcx> {
pub fn universe(&self) -> ty::UniverseIndex {
self.kind.universe()
}
Expand All @@ -113,7 +113,7 @@ impl CanonicalVarInfo {
/// in the type-theory sense of the term -- i.e., a "meta" type system
/// that analyzes type-like values.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyDecodable, TyEncodable, HashStable)]
pub enum CanonicalVarKind {
pub enum CanonicalVarKind<'tcx> {
/// Some kind of type inference variable.
Ty(CanonicalTyVarKind),

Expand All @@ -132,10 +132,10 @@ pub enum CanonicalVarKind {
Const(ty::UniverseIndex),

/// A "placeholder" that represents "any const".
PlaceholderConst(ty::PlaceholderConst),
PlaceholderConst(ty::PlaceholderConst<'tcx>),
}

impl CanonicalVarKind {
impl<'tcx> CanonicalVarKind<'tcx> {
pub fn universe(self) -> ty::UniverseIndex {
match self {
CanonicalVarKind::Ty(kind) => match kind {
Expand Down Expand Up @@ -287,9 +287,11 @@ pub type QueryOutlivesConstraint<'tcx> =
ty::Binder<ty::OutlivesPredicate<GenericArg<'tcx>, Region<'tcx>>>;

CloneTypeFoldableAndLiftImpls! {
crate::infer::canonical::Certainty,
crate::infer::canonical::CanonicalVarInfo,
crate::infer::canonical::CanonicalVarKind,
for <'tcx> {
crate::infer::canonical::Certainty,
crate::infer::canonical::CanonicalVarInfo<'tcx>,
crate::infer::canonical::CanonicalVarKind<'tcx>,
}
}

CloneTypeFoldableImpls! {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::Region<'tcx> {
impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for CanonicalVarInfos<'tcx> {
fn decode(decoder: &mut D) -> Result<Self, D::Error> {
let len = decoder.read_usize()?;
let interned: Result<Vec<CanonicalVarInfo>, _> =
let interned: Result<Vec<CanonicalVarInfo<'tcx>>, _> =
(0..len).map(|_| Decodable::decode(decoder)).collect();
Ok(decoder.tcx().intern_canonical_var_infos(interned?.as_slice()))
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/consts/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum ConstKind<'tcx> {
Bound(ty::DebruijnIndex, ty::BoundVar),

/// A placeholder const - universally quantified higher-ranked const.
Placeholder(ty::PlaceholderConst),
Placeholder(ty::PlaceholderConst<'tcx>),

/// Used in the HIR by using `Unevaluated` everywhere and later normalizing to one of the other
/// variants when the code is monomorphic enough for that.
Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub struct CtxtInterners<'tcx> {
type_: InternedSet<'tcx, TyS<'tcx>>,
type_list: InternedSet<'tcx, List<Ty<'tcx>>>,
substs: InternedSet<'tcx, InternalSubsts<'tcx>>,
canonical_var_infos: InternedSet<'tcx, List<CanonicalVarInfo>>,
canonical_var_infos: InternedSet<'tcx, List<CanonicalVarInfo<'tcx>>>,
region: InternedSet<'tcx, RegionKind>,
existential_predicates: InternedSet<'tcx, List<ExistentialPredicate<'tcx>>>,
predicate: InternedSet<'tcx, PredicateInner<'tcx>>,
Expand Down Expand Up @@ -1613,7 +1613,7 @@ nop_lift! {predicate; &'a PredicateInner<'a> => &'tcx PredicateInner<'tcx>}
nop_list_lift! {type_list; Ty<'a> => Ty<'tcx>}
nop_list_lift! {existential_predicates; ExistentialPredicate<'a> => ExistentialPredicate<'tcx>}
nop_list_lift! {predicates; Predicate<'a> => Predicate<'tcx>}
nop_list_lift! {canonical_var_infos; CanonicalVarInfo => CanonicalVarInfo}
nop_list_lift! {canonical_var_infos; CanonicalVarInfo<'a> => CanonicalVarInfo<'tcx>}
nop_list_lift! {projs; ProjectionKind => ProjectionKind}

// This is the impl for `&'a InternalSubsts<'a>`.
Expand Down Expand Up @@ -2049,7 +2049,7 @@ macro_rules! slice_interners {
slice_interners!(
type_list: _intern_type_list(Ty<'tcx>),
substs: _intern_substs(GenericArg<'tcx>),
canonical_var_infos: _intern_canonical_var_infos(CanonicalVarInfo),
canonical_var_infos: _intern_canonical_var_infos(CanonicalVarInfo<'tcx>),
existential_predicates: _intern_existential_predicates(ExistentialPredicate<'tcx>),
predicates: _intern_predicates(Predicate<'tcx>),
projs: _intern_projs(ProjectionKind),
Expand Down Expand Up @@ -2448,7 +2448,10 @@ impl<'tcx> TyCtxt<'tcx> {
if ts.is_empty() { List::empty() } else { self._intern_place_elems(ts) }
}

pub fn intern_canonical_var_infos(self, ts: &[CanonicalVarInfo]) -> CanonicalVarInfos<'tcx> {
pub fn intern_canonical_var_infos(
self,
ts: &[CanonicalVarInfo<'tcx>],
) -> CanonicalVarInfos<'tcx> {
if ts.is_empty() { List::empty() } else { self._intern_canonical_var_infos(ts) }
}

Expand Down
17 changes: 11 additions & 6 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1580,11 +1580,9 @@ impl UniverseIndex {
}
}

/// The "placeholder index" fully defines a placeholder region.
/// Placeholder regions are identified by both a **universe** as well
/// as a "bound-region" within that universe. The `bound_region` is
/// basically a name -- distinct bound regions within the same
/// universe are just two regions with an unknown relationship to one
/// The "placeholder index" fully defines a placeholder region, type, or const. Placeholders are
/// identified by both a universe, as well as a name residing within that universe. Distinct bound
/// regions/types/consts within the same universe simply have an unknown relationship to one
/// another.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, PartialOrd, Ord)]
pub struct Placeholder<T> {
Expand All @@ -1606,7 +1604,14 @@ pub type PlaceholderRegion = Placeholder<BoundRegion>;

pub type PlaceholderType = Placeholder<BoundVar>;

pub type PlaceholderConst = Placeholder<BoundVar>;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)]
#[derive(TyEncodable, TyDecodable, PartialOrd, Ord)]
pub struct BoundConst<'tcx> {
pub var: BoundVar,
pub ty: Ty<'tcx>,
}

pub type PlaceholderConst<'tcx> = Placeholder<BoundConst<'tcx>>;

/// A `DefId` which is potentially bundled with its corresponding generic parameter
/// in case `did` is a const argument.
Expand Down
6 changes: 3 additions & 3 deletions library/std/src/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ use crate::sys;
/// attacks such as HashDoS.
///
/// The hashing algorithm can be replaced on a per-`HashMap` basis using the
/// [`default`], [`with_hasher`], and [`with_capacity_and_hasher`] methods. Many
/// alternative algorithms are available on crates.io, such as the [`fnv`] crate.
/// [`default`], [`with_hasher`], and [`with_capacity_and_hasher`] methods.
/// There are many alternative [hashing algorithms available on crates.io].
///
/// It is required that the keys implement the [`Eq`] and [`Hash`] traits, although
/// this can frequently be achieved by using `#[derive(PartialEq, Eq, Hash)]`.
Expand All @@ -57,6 +57,7 @@ use crate::sys;
/// The original C++ version of SwissTable can be found [here], and this
/// [CppCon talk] gives an overview of how the algorithm works.
///
/// [hashing algorithms available on crates.io]: https://crates.io/keywords/hasher
/// [SwissTable]: https://abseil.io/blog/20180927-swisstables
/// [here]: https://github.com/abseil/abseil-cpp/blob/master/absl/container/internal/raw_hash_set.h
/// [CppCon talk]: https://www.youtube.com/watch?v=ncHmEUmJZf4
Expand Down Expand Up @@ -154,7 +155,6 @@ use crate::sys;
/// [`default`]: Default::default
/// [`with_hasher`]: Self::with_hasher
/// [`with_capacity_and_hasher`]: Self::with_capacity_and_hasher
/// [`fnv`]: https://crates.io/crates/fnv
///
/// ```
/// use std::collections::HashMap;
Expand Down
6 changes: 6 additions & 0 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ pub struct Options {
pub render_options: RenderOptions,
/// Output format rendering (used only for "show-coverage" option for the moment)
pub output_format: Option<OutputFormat>,
/// If this option is set to `true`, rustdoc will only run checks and not generate
/// documentation.
pub run_check: bool,
}

impl fmt::Debug for Options {
Expand Down Expand Up @@ -185,6 +188,7 @@ impl fmt::Debug for Options {
.field("runtool", &self.runtool)
.field("runtool_args", &self.runtool_args)
.field("enable-per-target-ignores", &self.enable_per_target_ignores)
.field("run_check", &self.run_check)
.finish()
}
}
Expand Down Expand Up @@ -581,6 +585,7 @@ impl Options {
let enable_per_target_ignores = matches.opt_present("enable-per-target-ignores");
let document_private = matches.opt_present("document-private-items");
let document_hidden = matches.opt_present("document-hidden-items");
let run_check = matches.opt_present("check");

let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);

Expand Down Expand Up @@ -616,6 +621,7 @@ impl Options {
runtool_args,
enable_per_target_ignores,
test_builder,
run_check,
render_options: RenderOptions {
output,
external_html,
Expand Down
5 changes: 5 additions & 0 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ fn opts() -> Vec<RustcOptGroup> {
"specified the rustc-like binary to use as the test builder",
)
}),
unstable("check", |o| o.optflag("", "check", "Run rustdoc checks")),
]
}

Expand Down Expand Up @@ -515,6 +516,7 @@ fn main_options(options: config::Options) -> MainResult {
// but we can't crates the Handler ahead of time because it's not Send
let diag_opts = (options.error_format, options.edition, options.debugging_opts.clone());
let show_coverage = options.show_coverage;
let run_check = options.run_check;

// First, parse the crate and extract all relevant information.
info!("starting to run rustc");
Expand All @@ -540,6 +542,9 @@ fn main_options(options: config::Options) -> MainResult {
// if we ran coverage, bail early, we don't need to also generate docs at this point
// (also we didn't load in any of the useful passes)
return Ok(());
} else if run_check {
// Since we're in "check" mode, no need to generate anything beyond this point.
return Ok(());
}

info!("going to format");
Expand Down
21 changes: 21 additions & 0 deletions src/test/rustdoc-ui/check-fail.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// compile-flags: -Z unstable-options --check

#![deny(missing_docs)]
#![deny(rustdoc)]

//! ```rust,testharness
//~^ ERROR
//! let x = 12;
//! ```

pub fn foo() {}
//~^ ERROR
//~^^ ERROR

/// hello
//~^ ERROR
///
/// ```rust,testharness
/// let x = 12;
/// ```
pub fn bar() {}
57 changes: 57 additions & 0 deletions src/test/rustdoc-ui/check-fail.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
error: missing documentation for a function
--> $DIR/check-fail.rs:11:1
|
LL | pub fn foo() {}
| ^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/check-fail.rs:3:9
|
LL | #![deny(missing_docs)]
| ^^^^^^^^^^^^

error: missing code example in this documentation
--> $DIR/check-fail.rs:11:1
|
LL | pub fn foo() {}
| ^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/check-fail.rs:4:9
|
LL | #![deny(rustdoc)]
| ^^^^^^^
= note: `#[deny(missing_doc_code_examples)]` implied by `#[deny(rustdoc)]`

error: unknown attribute `testharness`. Did you mean `test_harness`?
--> $DIR/check-fail.rs:6:1
|
LL | / //! ```rust,testharness
LL | |
LL | | //! let x = 12;
LL | | //! ```
| |_______^
|
note: the lint level is defined here
--> $DIR/check-fail.rs:4:9
|
LL | #![deny(rustdoc)]
| ^^^^^^^
= note: `#[deny(invalid_codeblock_attributes)]` implied by `#[deny(rustdoc)]`
= help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function

error: unknown attribute `testharness`. Did you mean `test_harness`?
--> $DIR/check-fail.rs:15:1
|
LL | / /// hello
LL | |
LL | | ///
LL | | /// ```rust,testharness
LL | | /// let x = 12;
LL | | /// ```
| |_______^
|
= help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function

error: aborting due to 4 previous errors

Loading

0 comments on commit f2a11a2

Please sign in to comment.