Skip to content

Commit f2a11a2

Browse files
committedNov 13, 2020
Auto merge of rust-lang#79017 - GuillaumeGomez:rollup-5orhudd, r=GuillaumeGomez
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
2 parents a1f7ca7 + 7ea8e32 commit f2a11a2

File tree

22 files changed

+286
-62
lines changed

22 files changed

+286
-62
lines changed
 

‎compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl CanonicalizeRegionMode for CanonicalizeFreeRegionsOtherThanStatic {
277277
struct Canonicalizer<'cx, 'tcx> {
278278
infcx: Option<&'cx InferCtxt<'cx, 'tcx>>,
279279
tcx: TyCtxt<'tcx>,
280-
variables: SmallVec<[CanonicalVarInfo; 8]>,
280+
variables: SmallVec<[CanonicalVarInfo<'tcx>; 8]>,
281281
query_state: &'cx mut OriginalQueryValues<'tcx>,
282282
// Note that indices is only used once `var_values` is big enough to be
283283
// heap-allocated.
@@ -542,7 +542,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
542542
/// or returns an existing variable if `kind` has already been
543543
/// seen. `kind` is expected to be an unbound variable (or
544544
/// potentially a free region).
545-
fn canonical_var(&mut self, info: CanonicalVarInfo, kind: GenericArg<'tcx>) -> BoundVar {
545+
fn canonical_var(&mut self, info: CanonicalVarInfo<'tcx>, kind: GenericArg<'tcx>) -> BoundVar {
546546
let Canonicalizer { variables, query_state, indices, .. } = self;
547547

548548
let var_values = &mut query_state.var_values;
@@ -621,7 +621,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
621621
/// representing the region `r`; return a region referencing it.
622622
fn canonical_var_for_region(
623623
&mut self,
624-
info: CanonicalVarInfo,
624+
info: CanonicalVarInfo<'tcx>,
625625
r: ty::Region<'tcx>,
626626
) -> ty::Region<'tcx> {
627627
let var = self.canonical_var(info, r.into());
@@ -633,7 +633,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
633633
/// if `ty_var` is bound to anything; if so, canonicalize
634634
/// *that*. Otherwise, create a new canonical variable for
635635
/// `ty_var`.
636-
fn canonicalize_ty_var(&mut self, info: CanonicalVarInfo, ty_var: Ty<'tcx>) -> Ty<'tcx> {
636+
fn canonicalize_ty_var(&mut self, info: CanonicalVarInfo<'tcx>, ty_var: Ty<'tcx>) -> Ty<'tcx> {
637637
let infcx = self.infcx.expect("encountered ty-var without infcx");
638638
let bound_to = infcx.shallow_resolve(ty_var);
639639
if bound_to != ty_var {
@@ -650,7 +650,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
650650
/// `const_var`.
651651
fn canonicalize_const_var(
652652
&mut self,
653-
info: CanonicalVarInfo,
653+
info: CanonicalVarInfo<'tcx>,
654654
const_var: &'tcx ty::Const<'tcx>,
655655
) -> &'tcx ty::Const<'tcx> {
656656
let infcx = self.infcx.expect("encountered const-var without infcx");

‎compiler/rustc_infer/src/infer/canonical/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
8282
fn instantiate_canonical_vars(
8383
&self,
8484
span: Span,
85-
variables: &List<CanonicalVarInfo>,
85+
variables: &List<CanonicalVarInfo<'tcx>>,
8686
universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex,
8787
) -> CanonicalVarValues<'tcx> {
8888
let var_values: IndexVec<BoundVar, GenericArg<'tcx>> = variables
@@ -100,7 +100,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
100100
fn instantiate_canonical_var(
101101
&self,
102102
span: Span,
103-
cv_info: CanonicalVarInfo,
103+
cv_info: CanonicalVarInfo<'tcx>,
104104
universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex,
105105
) -> GenericArg<'tcx> {
106106
match cv_info.kind {
@@ -154,7 +154,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
154154
self.tcx
155155
.mk_const(ty::Const {
156156
val: ty::ConstKind::Placeholder(placeholder_mapped),
157-
ty: self.tcx.ty_error(), // FIXME(const_generics)
157+
ty: name.ty,
158158
})
159159
.into()
160160
}

‎compiler/rustc_infer/src/infer/higher_ranked/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
9595
self.tcx.mk_const(ty::Const {
9696
val: ty::ConstKind::Placeholder(ty::PlaceholderConst {
9797
universe: next_universe,
98-
name: bound_var,
98+
name: ty::BoundConst { var: bound_var, ty },
9999
}),
100100
ty,
101101
})

‎compiler/rustc_middle/src/infer/canonical.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub struct Canonical<'tcx, V> {
4040
pub value: V,
4141
}
4242

43-
pub type CanonicalVarInfos<'tcx> = &'tcx List<CanonicalVarInfo>;
43+
pub type CanonicalVarInfos<'tcx> = &'tcx List<CanonicalVarInfo<'tcx>>;
4444

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

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

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

134134
/// A "placeholder" that represents "any const".
135-
PlaceholderConst(ty::PlaceholderConst),
135+
PlaceholderConst(ty::PlaceholderConst<'tcx>),
136136
}
137137

138-
impl CanonicalVarKind {
138+
impl<'tcx> CanonicalVarKind<'tcx> {
139139
pub fn universe(self) -> ty::UniverseIndex {
140140
match self {
141141
CanonicalVarKind::Ty(kind) => match kind {
@@ -287,9 +287,11 @@ pub type QueryOutlivesConstraint<'tcx> =
287287
ty::Binder<ty::OutlivesPredicate<GenericArg<'tcx>, Region<'tcx>>>;
288288

289289
CloneTypeFoldableAndLiftImpls! {
290-
crate::infer::canonical::Certainty,
291-
crate::infer::canonical::CanonicalVarInfo,
292-
crate::infer::canonical::CanonicalVarKind,
290+
for <'tcx> {
291+
crate::infer::canonical::Certainty,
292+
crate::infer::canonical::CanonicalVarInfo<'tcx>,
293+
crate::infer::canonical::CanonicalVarKind<'tcx>,
294+
}
293295
}
294296

295297
CloneTypeFoldableImpls! {

‎compiler/rustc_middle/src/ty/codec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::Region<'tcx> {
278278
impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for CanonicalVarInfos<'tcx> {
279279
fn decode(decoder: &mut D) -> Result<Self, D::Error> {
280280
let len = decoder.read_usize()?;
281-
let interned: Result<Vec<CanonicalVarInfo>, _> =
281+
let interned: Result<Vec<CanonicalVarInfo<'tcx>>, _> =
282282
(0..len).map(|_| Decodable::decode(decoder)).collect();
283283
Ok(decoder.tcx().intern_canonical_var_infos(interned?.as_slice()))
284284
}

‎compiler/rustc_middle/src/ty/consts/kind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub enum ConstKind<'tcx> {
2323
Bound(ty::DebruijnIndex, ty::BoundVar),
2424

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

2828
/// Used in the HIR by using `Unevaluated` everywhere and later normalizing to one of the other
2929
/// variants when the code is monomorphic enough for that.

‎compiler/rustc_middle/src/ty/context.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub struct CtxtInterners<'tcx> {
8383
type_: InternedSet<'tcx, TyS<'tcx>>,
8484
type_list: InternedSet<'tcx, List<Ty<'tcx>>>,
8585
substs: InternedSet<'tcx, InternalSubsts<'tcx>>,
86-
canonical_var_infos: InternedSet<'tcx, List<CanonicalVarInfo>>,
86+
canonical_var_infos: InternedSet<'tcx, List<CanonicalVarInfo<'tcx>>>,
8787
region: InternedSet<'tcx, RegionKind>,
8888
existential_predicates: InternedSet<'tcx, List<ExistentialPredicate<'tcx>>>,
8989
predicate: InternedSet<'tcx, PredicateInner<'tcx>>,
@@ -1613,7 +1613,7 @@ nop_lift! {predicate; &'a PredicateInner<'a> => &'tcx PredicateInner<'tcx>}
16131613
nop_list_lift! {type_list; Ty<'a> => Ty<'tcx>}
16141614
nop_list_lift! {existential_predicates; ExistentialPredicate<'a> => ExistentialPredicate<'tcx>}
16151615
nop_list_lift! {predicates; Predicate<'a> => Predicate<'tcx>}
1616-
nop_list_lift! {canonical_var_infos; CanonicalVarInfo => CanonicalVarInfo}
1616+
nop_list_lift! {canonical_var_infos; CanonicalVarInfo<'a> => CanonicalVarInfo<'tcx>}
16171617
nop_list_lift! {projs; ProjectionKind => ProjectionKind}
16181618

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

2451-
pub fn intern_canonical_var_infos(self, ts: &[CanonicalVarInfo]) -> CanonicalVarInfos<'tcx> {
2451+
pub fn intern_canonical_var_infos(
2452+
self,
2453+
ts: &[CanonicalVarInfo<'tcx>],
2454+
) -> CanonicalVarInfos<'tcx> {
24522455
if ts.is_empty() { List::empty() } else { self._intern_canonical_var_infos(ts) }
24532456
}
24542457

‎compiler/rustc_middle/src/ty/mod.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -1580,11 +1580,9 @@ impl UniverseIndex {
15801580
}
15811581
}
15821582

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

16071605
pub type PlaceholderType = Placeholder<BoundVar>;
16081606

1609-
pub type PlaceholderConst = Placeholder<BoundVar>;
1607+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)]
1608+
#[derive(TyEncodable, TyDecodable, PartialOrd, Ord)]
1609+
pub struct BoundConst<'tcx> {
1610+
pub var: BoundVar,
1611+
pub ty: Ty<'tcx>,
1612+
}
1613+
1614+
pub type PlaceholderConst<'tcx> = Placeholder<BoundConst<'tcx>>;
16101615

16111616
/// A `DefId` which is potentially bundled with its corresponding generic parameter
16121617
/// in case `did` is a const argument.

‎library/std/src/collections/hash/map.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ use crate::sys;
3434
/// attacks such as HashDoS.
3535
///
3636
/// The hashing algorithm can be replaced on a per-`HashMap` basis using the
37-
/// [`default`], [`with_hasher`], and [`with_capacity_and_hasher`] methods. Many
38-
/// alternative algorithms are available on crates.io, such as the [`fnv`] crate.
37+
/// [`default`], [`with_hasher`], and [`with_capacity_and_hasher`] methods.
38+
/// There are many alternative [hashing algorithms available on crates.io].
3939
///
4040
/// It is required that the keys implement the [`Eq`] and [`Hash`] traits, although
4141
/// this can frequently be achieved by using `#[derive(PartialEq, Eq, Hash)]`.
@@ -57,6 +57,7 @@ use crate::sys;
5757
/// The original C++ version of SwissTable can be found [here], and this
5858
/// [CppCon talk] gives an overview of how the algorithm works.
5959
///
60+
/// [hashing algorithms available on crates.io]: https://crates.io/keywords/hasher
6061
/// [SwissTable]: https://abseil.io/blog/20180927-swisstables
6162
/// [here]: https://github.com/abseil/abseil-cpp/blob/master/absl/container/internal/raw_hash_set.h
6263
/// [CppCon talk]: https://www.youtube.com/watch?v=ncHmEUmJZf4
@@ -154,7 +155,6 @@ use crate::sys;
154155
/// [`default`]: Default::default
155156
/// [`with_hasher`]: Self::with_hasher
156157
/// [`with_capacity_and_hasher`]: Self::with_capacity_and_hasher
157-
/// [`fnv`]: https://crates.io/crates/fnv
158158
///
159159
/// ```
160160
/// use std::collections::HashMap;

‎src/librustdoc/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ pub struct Options {
145145
pub render_options: RenderOptions,
146146
/// Output format rendering (used only for "show-coverage" option for the moment)
147147
pub output_format: Option<OutputFormat>,
148+
/// If this option is set to `true`, rustdoc will only run checks and not generate
149+
/// documentation.
150+
pub run_check: bool,
148151
}
149152

150153
impl fmt::Debug for Options {
@@ -185,6 +188,7 @@ impl fmt::Debug for Options {
185188
.field("runtool", &self.runtool)
186189
.field("runtool_args", &self.runtool_args)
187190
.field("enable-per-target-ignores", &self.enable_per_target_ignores)
191+
.field("run_check", &self.run_check)
188192
.finish()
189193
}
190194
}
@@ -581,6 +585,7 @@ impl Options {
581585
let enable_per_target_ignores = matches.opt_present("enable-per-target-ignores");
582586
let document_private = matches.opt_present("document-private-items");
583587
let document_hidden = matches.opt_present("document-hidden-items");
588+
let run_check = matches.opt_present("check");
584589

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

@@ -616,6 +621,7 @@ impl Options {
616621
runtool_args,
617622
enable_per_target_ignores,
618623
test_builder,
624+
run_check,
619625
render_options: RenderOptions {
620626
output,
621627
external_html,

‎src/librustdoc/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ fn opts() -> Vec<RustcOptGroup> {
423423
"specified the rustc-like binary to use as the test builder",
424424
)
425425
}),
426+
unstable("check", |o| o.optflag("", "check", "Run rustdoc checks")),
426427
]
427428
}
428429

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

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

545550
info!("going to format");

‎src/test/rustdoc-ui/check-fail.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// compile-flags: -Z unstable-options --check
2+
3+
#![deny(missing_docs)]
4+
#![deny(rustdoc)]
5+
6+
//! ```rust,testharness
7+
//~^ ERROR
8+
//! let x = 12;
9+
//! ```
10+
11+
pub fn foo() {}
12+
//~^ ERROR
13+
//~^^ ERROR
14+
15+
/// hello
16+
//~^ ERROR
17+
///
18+
/// ```rust,testharness
19+
/// let x = 12;
20+
/// ```
21+
pub fn bar() {}

‎src/test/rustdoc-ui/check-fail.stderr

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
error: missing documentation for a function
2+
--> $DIR/check-fail.rs:11:1
3+
|
4+
LL | pub fn foo() {}
5+
| ^^^^^^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/check-fail.rs:3:9
9+
|
10+
LL | #![deny(missing_docs)]
11+
| ^^^^^^^^^^^^
12+
13+
error: missing code example in this documentation
14+
--> $DIR/check-fail.rs:11:1
15+
|
16+
LL | pub fn foo() {}
17+
| ^^^^^^^^^^^^^^^
18+
|
19+
note: the lint level is defined here
20+
--> $DIR/check-fail.rs:4:9
21+
|
22+
LL | #![deny(rustdoc)]
23+
| ^^^^^^^
24+
= note: `#[deny(missing_doc_code_examples)]` implied by `#[deny(rustdoc)]`
25+
26+
error: unknown attribute `testharness`. Did you mean `test_harness`?
27+
--> $DIR/check-fail.rs:6:1
28+
|
29+
LL | / //! ```rust,testharness
30+
LL | |
31+
LL | | //! let x = 12;
32+
LL | | //! ```
33+
| |_______^
34+
|
35+
note: the lint level is defined here
36+
--> $DIR/check-fail.rs:4:9
37+
|
38+
LL | #![deny(rustdoc)]
39+
| ^^^^^^^
40+
= note: `#[deny(invalid_codeblock_attributes)]` implied by `#[deny(rustdoc)]`
41+
= 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
42+
43+
error: unknown attribute `testharness`. Did you mean `test_harness`?
44+
--> $DIR/check-fail.rs:15:1
45+
|
46+
LL | / /// hello
47+
LL | |
48+
LL | | ///
49+
LL | | /// ```rust,testharness
50+
LL | | /// let x = 12;
51+
LL | | /// ```
52+
| |_______^
53+
|
54+
= 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
55+
56+
error: aborting due to 4 previous errors
57+

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

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// check-pass
2+
// compile-flags: -Z unstable-options --check
3+
4+
#![warn(missing_docs)]
5+
//~^ WARN
6+
//~^^ WARN
7+
#![warn(rustdoc)]
8+
9+
pub fn foo() {}
10+
//~^ WARN
11+
//~^^ WARN

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

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
warning: missing documentation for the crate
2+
--> $DIR/check.rs:4:1
3+
|
4+
LL | / #![warn(missing_docs)]
5+
LL | |
6+
LL | |
7+
LL | | #![warn(rustdoc)]
8+
LL | |
9+
LL | | pub fn foo() {}
10+
| |_______________^
11+
|
12+
note: the lint level is defined here
13+
--> $DIR/check.rs:4:9
14+
|
15+
LL | #![warn(missing_docs)]
16+
| ^^^^^^^^^^^^
17+
18+
warning: missing documentation for a function
19+
--> $DIR/check.rs:9:1
20+
|
21+
LL | pub fn foo() {}
22+
| ^^^^^^^^^^^^
23+
24+
warning: missing code example in this documentation
25+
--> $DIR/check.rs:4:1
26+
|
27+
LL | / #![warn(missing_docs)]
28+
LL | |
29+
LL | |
30+
LL | | #![warn(rustdoc)]
31+
LL | |
32+
LL | | pub fn foo() {}
33+
| |_______________^
34+
|
35+
note: the lint level is defined here
36+
--> $DIR/check.rs:7:9
37+
|
38+
LL | #![warn(rustdoc)]
39+
| ^^^^^^^
40+
= note: `#[warn(missing_doc_code_examples)]` implied by `#[warn(rustdoc)]`
41+
42+
warning: missing code example in this documentation
43+
--> $DIR/check.rs:9:1
44+
|
45+
LL | pub fn foo() {}
46+
| ^^^^^^^^^^^^^^^
47+
48+
warning: 4 warnings emitted
49+

‎src/test/rustdoc/check.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// compile-flags: -Z unstable-options --check
2+
3+
// @!has check/fn.foo.html
4+
// @!has check/index.html
5+
pub fn foo() {}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// run-pass
2+
// tests that promoting expressions containing const parameters is allowed.
3+
#![feature(min_const_generics)]
4+
5+
fn promotion_test<const N: usize>() -> &'static usize {
6+
&(3 + N)
7+
}
8+
9+
fn main() {
10+
assert_eq!(promotion_test::<13>(), &16);
11+
}
File renamed without changes.
File renamed without changes.

‎src/test/ui/reject-specialized-drops-8142.rs ‎src/test/ui/dropck/reject-specialized-drops-8142.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Issue 8142: Test that Drop impls cannot be specialized beyond the
22
// predicates attached to the type definition itself.
3+
#![feature(min_const_generics)]
34

45
trait Bound { fn foo(&self) { } }
56
struct K<'l1,'l2> { x: &'l1 i8, y: &'l2 u8 }
@@ -15,6 +16,8 @@ struct T<'t,Ts:'t> { x: &'t Ts }
1516
struct U;
1617
struct V<Tva, Tvb> { x: *const Tva, y: *const Tvb }
1718
struct W<'l1, 'l2> { x: &'l1 i8, y: &'l2 u8 }
19+
struct X<const Ca: usize>;
20+
struct Y<const Ca: usize, const Cb: usize>;
1821

1922
enum Enum<T> { Variant(T) }
2023
struct TupleStruct<T>(T);
@@ -58,6 +61,12 @@ impl<One> Drop for V<One,One> { fn drop(&mut self) { } } // REJECT
5861
impl<'lw> Drop for W<'lw,'lw> { fn drop(&mut self) { } } // REJECT
5962
//~^ ERROR cannot infer an appropriate lifetime for lifetime parameter `'lw`
6063

64+
impl Drop for X<3> { fn drop(&mut self) { } } // REJECT
65+
//~^ ERROR `Drop` impls cannot be specialized
66+
67+
impl<const Ca: usize> Drop for Y<Ca, Ca> { fn drop(&mut self) { } } // REJECT
68+
//~^ ERROR `Drop` impls cannot be specialized
69+
6170
impl<AddsBnd:Bound> Drop for Enum<AddsBnd> { fn drop(&mut self) { } } // REJECT
6271
//~^ ERROR `Drop` impl requires `AddsBnd: Bound`
6372

Original file line numberDiff line numberDiff line change
@@ -1,151 +1,175 @@
11
error[E0367]: `Drop` impl requires `'adds_bnd: 'al` but the struct it is implemented for does not
2-
--> $DIR/reject-specialized-drops-8142.rs:23:20
2+
--> $DIR/reject-specialized-drops-8142.rs:26:20
33
|
44
LL | impl<'al,'adds_bnd:'al> Drop for K<'al,'adds_bnd> { // REJECT
55
| ^^^
66
|
77
note: the implementor must specify the same requirement
8-
--> $DIR/reject-specialized-drops-8142.rs:5:1
8+
--> $DIR/reject-specialized-drops-8142.rs:6:1
99
|
1010
LL | struct K<'l1,'l2> { x: &'l1 i8, y: &'l2 u8 }
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error[E0367]: `Drop` impl requires `'adds_bnd: 'al` but the struct it is implemented for does not
14-
--> $DIR/reject-specialized-drops-8142.rs:27:67
14+
--> $DIR/reject-specialized-drops-8142.rs:30:67
1515
|
1616
LL | impl<'al,'adds_bnd> Drop for L<'al,'adds_bnd> where 'adds_bnd:'al { // REJECT
1717
| ^^^
1818
|
1919
note: the implementor must specify the same requirement
20-
--> $DIR/reject-specialized-drops-8142.rs:6:1
20+
--> $DIR/reject-specialized-drops-8142.rs:7:1
2121
|
2222
LL | struct L<'l1,'l2> { x: &'l1 i8, y: &'l2 u8 }
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2424

2525
error[E0308]: mismatched types
26-
--> $DIR/reject-specialized-drops-8142.rs:33:1
26+
--> $DIR/reject-specialized-drops-8142.rs:36:1
2727
|
2828
LL | impl Drop for N<'static> { fn drop(&mut self) { } } // REJECT
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
3030
|
3131
= note: expected struct `N<'n>`
3232
found struct `N<'static>`
33-
note: the lifetime `'n` as defined on the struct at 8:10...
34-
--> $DIR/reject-specialized-drops-8142.rs:8:10
33+
note: the lifetime `'n` as defined on the struct at 9:10...
34+
--> $DIR/reject-specialized-drops-8142.rs:9:10
3535
|
3636
LL | struct N<'n> { x: &'n i8 }
3737
| ^^
3838
= note: ...does not necessarily outlive the static lifetime
3939

4040
error[E0366]: `Drop` impls cannot be specialized
41-
--> $DIR/reject-specialized-drops-8142.rs:40:1
41+
--> $DIR/reject-specialized-drops-8142.rs:43:1
4242
|
4343
LL | impl Drop for P<i8> { fn drop(&mut self) { } } // REJECT
4444
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4545
|
4646
note: use the same sequence of generic type, lifetime and const parameters as the struct definition
47-
--> $DIR/reject-specialized-drops-8142.rs:10:1
47+
--> $DIR/reject-specialized-drops-8142.rs:11:1
4848
|
4949
LL | struct P<Tp> { x: *const Tp }
5050
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5151

5252
error[E0367]: `Drop` impl requires `AddsBnd: Bound` but the struct it is implemented for does not
53-
--> $DIR/reject-specialized-drops-8142.rs:43:14
53+
--> $DIR/reject-specialized-drops-8142.rs:46:14
5454
|
5555
LL | impl<AddsBnd:Bound> Drop for Q<AddsBnd> { fn drop(&mut self) { } } // REJECT
5656
| ^^^^^
5757
|
5858
note: the implementor must specify the same requirement
59-
--> $DIR/reject-specialized-drops-8142.rs:11:1
59+
--> $DIR/reject-specialized-drops-8142.rs:12:1
6060
|
6161
LL | struct Q<Tq> { x: *const Tq }
6262
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6363

6464
error[E0367]: `Drop` impl requires `AddsRBnd: 'rbnd` but the struct it is implemented for does not
65-
--> $DIR/reject-specialized-drops-8142.rs:46:21
65+
--> $DIR/reject-specialized-drops-8142.rs:49:21
6666
|
6767
LL | impl<'rbnd,AddsRBnd:'rbnd> Drop for R<AddsRBnd> { fn drop(&mut self) { } } // REJECT
6868
| ^^^^^
6969
|
7070
note: the implementor must specify the same requirement
71-
--> $DIR/reject-specialized-drops-8142.rs:12:1
71+
--> $DIR/reject-specialized-drops-8142.rs:13:1
7272
|
7373
LL | struct R<Tr> { x: *const Tr }
7474
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7575

7676
error[E0366]: `Drop` impls cannot be specialized
77-
--> $DIR/reject-specialized-drops-8142.rs:55:1
77+
--> $DIR/reject-specialized-drops-8142.rs:58:1
7878
|
7979
LL | impl<One> Drop for V<One,One> { fn drop(&mut self) { } } // REJECT
8080
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8181
|
8282
note: use the same sequence of generic type, lifetime and const parameters as the struct definition
83-
--> $DIR/reject-specialized-drops-8142.rs:16:1
83+
--> $DIR/reject-specialized-drops-8142.rs:17:1
8484
|
8585
LL | struct V<Tva, Tvb> { x: *const Tva, y: *const Tvb }
8686
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8787

8888
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'lw` due to conflicting requirements
89-
--> $DIR/reject-specialized-drops-8142.rs:58:1
89+
--> $DIR/reject-specialized-drops-8142.rs:61:1
9090
|
9191
LL | impl<'lw> Drop for W<'lw,'lw> { fn drop(&mut self) { } } // REJECT
9292
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9393
|
94-
note: first, the lifetime cannot outlive the lifetime `'l1` as defined on the struct at 17:10...
95-
--> $DIR/reject-specialized-drops-8142.rs:17:10
94+
note: first, the lifetime cannot outlive the lifetime `'l1` as defined on the struct at 18:10...
95+
--> $DIR/reject-specialized-drops-8142.rs:18:10
9696
|
9797
LL | struct W<'l1, 'l2> { x: &'l1 i8, y: &'l2 u8 }
9898
| ^^^
99-
note: ...but the lifetime must also be valid for the lifetime `'l2` as defined on the struct at 17:15...
100-
--> $DIR/reject-specialized-drops-8142.rs:17:15
99+
note: ...but the lifetime must also be valid for the lifetime `'l2` as defined on the struct at 18:15...
100+
--> $DIR/reject-specialized-drops-8142.rs:18:15
101101
|
102102
LL | struct W<'l1, 'l2> { x: &'l1 i8, y: &'l2 u8 }
103103
| ^^^
104104
note: ...so that the types are compatible
105-
--> $DIR/reject-specialized-drops-8142.rs:58:1
105+
--> $DIR/reject-specialized-drops-8142.rs:61:1
106106
|
107107
LL | impl<'lw> Drop for W<'lw,'lw> { fn drop(&mut self) { } } // REJECT
108108
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
109109
= note: expected `W<'l1, 'l2>`
110110
found `W<'_, '_>`
111111

112+
error[E0366]: `Drop` impls cannot be specialized
113+
--> $DIR/reject-specialized-drops-8142.rs:64:1
114+
|
115+
LL | impl Drop for X<3> { fn drop(&mut self) { } } // REJECT
116+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
117+
|
118+
note: use the same sequence of generic type, lifetime and const parameters as the struct definition
119+
--> $DIR/reject-specialized-drops-8142.rs:19:1
120+
|
121+
LL | struct X<const Ca: usize>;
122+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
123+
124+
error[E0366]: `Drop` impls cannot be specialized
125+
--> $DIR/reject-specialized-drops-8142.rs:67:1
126+
|
127+
LL | impl<const Ca: usize> Drop for Y<Ca, Ca> { fn drop(&mut self) { } } // REJECT
128+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
129+
|
130+
note: use the same sequence of generic type, lifetime and const parameters as the struct definition
131+
--> $DIR/reject-specialized-drops-8142.rs:20:1
132+
|
133+
LL | struct Y<const Ca: usize, const Cb: usize>;
134+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
135+
112136
error[E0367]: `Drop` impl requires `AddsBnd: Bound` but the enum it is implemented for does not
113-
--> $DIR/reject-specialized-drops-8142.rs:61:14
137+
--> $DIR/reject-specialized-drops-8142.rs:70:14
114138
|
115139
LL | impl<AddsBnd:Bound> Drop for Enum<AddsBnd> { fn drop(&mut self) { } } // REJECT
116140
| ^^^^^
117141
|
118142
note: the implementor must specify the same requirement
119-
--> $DIR/reject-specialized-drops-8142.rs:19:1
143+
--> $DIR/reject-specialized-drops-8142.rs:22:1
120144
|
121145
LL | enum Enum<T> { Variant(T) }
122146
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
123147

124148
error[E0367]: `Drop` impl requires `AddsBnd: Bound` but the struct it is implemented for does not
125-
--> $DIR/reject-specialized-drops-8142.rs:64:14
149+
--> $DIR/reject-specialized-drops-8142.rs:73:14
126150
|
127151
LL | impl<AddsBnd:Bound> Drop for TupleStruct<AddsBnd> { fn drop(&mut self) { } } // REJECT
128152
| ^^^^^
129153
|
130154
note: the implementor must specify the same requirement
131-
--> $DIR/reject-specialized-drops-8142.rs:20:1
155+
--> $DIR/reject-specialized-drops-8142.rs:23:1
132156
|
133157
LL | struct TupleStruct<T>(T);
134158
| ^^^^^^^^^^^^^^^^^^^^^^^^^
135159

136160
error[E0367]: `Drop` impl requires `AddsBnd: Bound` but the union it is implemented for does not
137-
--> $DIR/reject-specialized-drops-8142.rs:67:21
161+
--> $DIR/reject-specialized-drops-8142.rs:76:21
138162
|
139163
LL | impl<AddsBnd:Copy + Bound> Drop for Union<AddsBnd> { fn drop(&mut self) { } } // REJECT
140164
| ^^^^^
141165
|
142166
note: the implementor must specify the same requirement
143-
--> $DIR/reject-specialized-drops-8142.rs:21:1
167+
--> $DIR/reject-specialized-drops-8142.rs:24:1
144168
|
145169
LL | union Union<T: Copy> { f: T }
146170
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
147171

148-
error: aborting due to 11 previous errors
172+
error: aborting due to 13 previous errors
149173

150174
Some errors have detailed explanations: E0308, E0366, E0367, E0495.
151175
For more information about an error, try `rustc --explain E0308`.

‎src/test/ui/issues/issue-76042.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// run-pass
2+
// compile-flags: -Coverflow-checks=off -Ccodegen-units=1 -Copt-level=0
3+
4+
fn foo(a: i128, b: i128, s: u32) -> (i128, i128) {
5+
if s == 128 {
6+
(0, 0)
7+
} else {
8+
(b >> s, a >> s)
9+
}
10+
}
11+
fn main() {
12+
let r = foo(0, 8, 1);
13+
if r.0 != 4 {
14+
panic!();
15+
}
16+
}

0 commit comments

Comments
 (0)
Please sign in to comment.