Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #90165

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4333091
Update E0637 description to mention `&` w/o an explicit lifetime name
JohnTitor Oct 15, 2021
d2470e7
rustc_ast: Turn `MutVisitor::token_visiting_enabled` into a constant
petrochenkov Oct 17, 2021
7581bae
Fix const qualification when executed after promotion
tmiasko Oct 19, 2021
21d02bf
Add a regression test for issue-83479
JohnTitor Oct 20, 2021
396a4f4
Increase `ROOT_ENTRY_LIMIT` to 1331
JohnTitor Oct 20, 2021
6469fba
Trait objects
BoxyUwU Oct 20, 2021
a81e489
Return pos impl trait
BoxyUwU Oct 20, 2021
83a1834
Wfness
BoxyUwU Oct 20, 2021
8f23779
Inference
BoxyUwU Oct 20, 2021
7a8bd2d
add fixme
BoxyUwU Oct 20, 2021
c75d8cb
Ordering
BoxyUwU Oct 20, 2021
e7a9e82
*dust dust*
BoxyUwU Oct 20, 2021
74c6636
Verify that only NeedsNonConstDrop expects promoteds
tmiasko Oct 21, 2021
ab44e46
Add test for issue #78561
samlich Oct 20, 2021
d50832b
triagebot: Treat `I-*nominated` like `I-nominated`
joshtriplett Oct 21, 2021
04c1ec5
Clarify undefined behaviour for binary heap, btree and hashset
Wilfred Jul 28, 2021
a1cf430
Rollup merge of #87537 - Wilfred:improve-min-heap-docs, r=Mark-Simula…
matthiaskrgr Oct 22, 2021
42e4846
Rollup merge of #89922 - JohnTitor:update-e0637, r=jackh726
matthiaskrgr Oct 22, 2021
fd1a3c9
Rollup merge of #89991 - petrochenkov:visitok2, r=jackh726
matthiaskrgr Oct 22, 2021
089f754
Rollup merge of #90069 - tmiasko:promoted-const-qualif, r=oli-obk
matthiaskrgr Oct 22, 2021
1b1fa74
Rollup merge of #90078 - JohnTitor:test-83479, r=Mark-Simulacrum
matthiaskrgr Oct 22, 2021
4998ce1
Rollup merge of #90114 - BoxyUwU:cg_defaults_tests, r=lcnr
matthiaskrgr Oct 22, 2021
f80d02b
Rollup merge of #90115 - samlich:test-issue-78561, r=oli-obk
matthiaskrgr Oct 22, 2021
d3b9a1a
Rollup merge of #90129 - joshtriplett:triagebot-nominated, r=Mark-Sim…
matthiaskrgr Oct 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ pub trait MutVisitor: Sized {
/// Mutable token visiting only exists for the `macro_rules` token marker and should not be
/// used otherwise. Token visitor would be entirely separate from the regular visitor if
/// the marker didn't have to visit AST fragments in nonterminal tokens.
fn token_visiting_enabled(&self) -> bool {
false
}
const VISIT_TOKENS: bool = false;

// Methods in this trait have one of three forms:
//
Expand Down Expand Up @@ -363,7 +361,7 @@ pub fn visit_mac_args<T: MutVisitor>(args: &mut MacArgs, vis: &mut T) {
}
MacArgs::Eq(eq_span, token) => {
vis.visit_span(eq_span);
if vis.token_visiting_enabled() {
if T::VISIT_TOKENS {
visit_token(token, vis);
} else {
// The value in `#[key = VALUE]` must be visited as an expression for backward
Expand Down Expand Up @@ -682,7 +680,7 @@ pub fn visit_tt<T: MutVisitor>(tt: &mut TokenTree, vis: &mut T) {

// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
pub fn visit_tts<T: MutVisitor>(TokenStream(tts): &mut TokenStream, vis: &mut T) {
if vis.token_visiting_enabled() && !tts.is_empty() {
if T::VISIT_TOKENS && !tts.is_empty() {
let tts = Lrc::make_mut(tts);
visit_vec(tts, |(tree, _is_joint)| visit_tt(tree, vis));
}
Expand All @@ -692,14 +690,14 @@ pub fn visit_attr_annotated_tts<T: MutVisitor>(
AttrAnnotatedTokenStream(tts): &mut AttrAnnotatedTokenStream,
vis: &mut T,
) {
if vis.token_visiting_enabled() && !tts.is_empty() {
if T::VISIT_TOKENS && !tts.is_empty() {
let tts = Lrc::make_mut(tts);
visit_vec(tts, |(tree, _is_joint)| visit_attr_annotated_tt(tree, vis));
}
}

pub fn visit_lazy_tts_opt_mut<T: MutVisitor>(lazy_tts: Option<&mut LazyTokenStream>, vis: &mut T) {
if vis.token_visiting_enabled() {
if T::VISIT_TOKENS {
if let Some(lazy_tts) = lazy_tts {
let mut tts = lazy_tts.create_token_stream();
visit_attr_annotated_tts(&mut tts, vis);
Expand Down
11 changes: 9 additions & 2 deletions compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ pub trait Qualif {
/// Whether this `Qualif` is cleared when a local is moved from.
const IS_CLEARED_ON_MOVE: bool = false;

/// Whether this `Qualif` might be evaluated after the promotion and can encounter a promoted.
const ALLOW_PROMOTED: bool = false;

/// Extracts the field of `ConstQualifs` that corresponds to this `Qualif`.
fn in_qualifs(qualifs: &ConstQualifs) -> bool;

Expand Down Expand Up @@ -129,6 +132,7 @@ pub struct NeedsNonConstDrop;
impl Qualif for NeedsNonConstDrop {
const ANALYSIS_NAME: &'static str = "flow_needs_nonconst_drop";
const IS_CLEARED_ON_MOVE: bool = true;
const ALLOW_PROMOTED: bool = true;

fn in_qualifs(qualifs: &ConstQualifs) -> bool {
qualifs.needs_non_const_drop
Expand Down Expand Up @@ -310,9 +314,12 @@ where
// Check the qualifs of the value of `const` items.
if let Some(ct) = constant.literal.const_for_ty() {
if let ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs_: _, promoted }) = ct.val {
assert!(promoted.is_none());
// Use qualifs of the type for the promoted. Promoteds in MIR body should be possible
// only for `NeedsNonConstDrop` with precise drop checking. This is the only const
// check performed after the promotion. Verify that with an assertion.
assert!(promoted.is_none() || Q::ALLOW_PROMOTED);
// Don't peek inside trait associated constants.
if cx.tcx.trait_of_item(def.did).is_none() {
if promoted.is_none() && cx.tcx.trait_of_item(def.did).is_none() {
let qualifs = if let Some((did, param_did)) = def.as_const_arg() {
cx.tcx.at(constant.span).mir_const_qualif_const_arg((did, param_did))
} else {
Expand Down
36 changes: 26 additions & 10 deletions compiler/rustc_error_codes/src/error_codes/E0637.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,51 @@
An underscore `_` character has been used as the identifier for a lifetime.
`'_` lifetime name or `&T` without an explicit lifetime name has been used
on illegal place.

Erroneous code example:

```compile_fail,E0106,E0637
fn longest<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {
//^^ `'_` is a reserved lifetime name
fn underscore_lifetime<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {
//^^ `'_` is a reserved lifetime name
if str1.len() > str2.len() {
str1
} else {
str2
}
}

fn and_without_explicit_lifetime<T>()
where
T: Into<&u32>,
//^ `&` without an explicit lifetime name
{
}
```

`'_`, cannot be used as a lifetime identifier because it is a reserved for the
anonymous lifetime. To fix this, use a lowercase letter such as 'a, or a series
of lowercase letters such as `'foo`. For more information, see [the
book][bk-no]. For more information on using the anonymous lifetime in rust
nightly, see [the nightly book][bk-al].
First, `'_` cannot be used as a lifetime identifier in some places
because it is a reserved for the anonymous lifetime. Second, `&T`
without an explicit lifetime name cannot also be used in some places.
To fix them, use a lowercase letter such as `'a`, or a series
of lowercase letters such as `'foo`. For more information about lifetime
identifier, see [the book][bk-no]. For more information on using
the anonymous lifetime in Rust 2018, see [the Rust 2018 blog post][blog-al].

Corrected example:

```
fn longest<'a>(str1: &'a str, str2: &'a str) -> &'a str {
fn underscore_lifetime<'a>(str1: &'a str, str2: &'a str) -> &'a str {
if str1.len() > str2.len() {
str1
} else {
str2
}
}

fn and_without_explicit_lifetime<'foo, T>()
where
T: Into<&'foo u32>,
{
}
```

[bk-no]: https://doc.rust-lang.org/book/appendix-02-operators.html#non-operator-symbols
[bk-al]: https://doc.rust-lang.org/nightly/edition-guide/rust-2018/ownership-and-lifetimes/the-anonymous-lifetime.html
[blog-al]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html#more-lifetime-elision-rules
4 changes: 1 addition & 3 deletions compiler/rustc_expand/src/mbe/transcribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ use std::mem;
struct Marker(LocalExpnId, Transparency);

impl MutVisitor for Marker {
fn token_visiting_enabled(&self) -> bool {
true
}
const VISIT_TOKENS: bool = true;

fn visit_span(&mut self, span: &mut Span) {
*span = span.apply_mark(self.0.to_expn_id(), self.1)
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_expand/src/mut_visit/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ fn print_crate_items(krate: &ast::Crate) -> String {
struct ToZzIdentMutVisitor;

impl MutVisitor for ToZzIdentMutVisitor {
fn token_visiting_enabled(&self) -> bool {
true
}
const VISIT_TOKENS: bool = true;

fn visit_ident(&mut self, ident: &mut Ident) {
*ident = Ident::from_str("zz");
}
Expand Down
6 changes: 3 additions & 3 deletions library/alloc/src/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ use super::SpecExtend;
/// item's ordering relative to any other item, as determined by the [`Ord`]
/// trait, changes while it is in the heap. This is normally only possible
/// through [`Cell`], [`RefCell`], global state, I/O, or unsafe code. The
/// behavior resulting from such a logic error is not specified, but will
/// not result in undefined behavior. This could include panics, incorrect
/// results, aborts, memory leaks, and non-termination.
/// behavior resulting from such a logic error is not specified (it
/// could include panics, incorrect results, aborts, memory leaks, or
/// non-termination) but will not be undefined behavior.
///
/// # Examples
///
Expand Down
6 changes: 3 additions & 3 deletions library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
/// It is a logic error for a key to be modified in such a way that the key's ordering relative to
/// any other key, as determined by the [`Ord`] trait, changes while it is in the map. This is
/// normally only possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code.
/// The behavior resulting from such a logic error is not specified, but will not result in
/// undefined behavior. This could include panics, incorrect results, aborts, memory leaks, and
/// non-termination.
/// The behavior resulting from such a logic error is not specified (it could include panics,
/// incorrect results, aborts, memory leaks, or non-termination) but will not be undefined
/// behavior.
///
/// [B-Tree]: https://en.wikipedia.org/wiki/B-tree
/// [`Cell`]: core::cell::Cell
Expand Down
6 changes: 3 additions & 3 deletions library/alloc/src/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ use super::Recover;
/// It is a logic error for an item to be modified in such a way that the item's ordering relative
/// to any other item, as determined by the [`Ord`] trait, changes while it is in the set. This is
/// normally only possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code.
/// The behavior resulting from such a logic error is not specified, but will not result in
/// undefined behavior. This could include panics, incorrect results, aborts, memory leaks, and
/// non-termination.
/// The behavior resulting from such a logic error is not specified (it could include panics,
/// incorrect results, aborts, memory leaks, or non-termination) but will not be undefined
/// behavior.
///
/// [`Ord`]: core::cmp::Ord
/// [`Cell`]: core::cell::Cell
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/collections/hash/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ use super::map::{map_try_reserve_error, RandomState};
/// determined by the [`Eq`] trait, changes while it is in the set. This is
/// normally only possible through [`Cell`], [`RefCell`], global state, I/O, or
/// unsafe code. The behavior resulting from such a logic error is not
/// specified, but will not result in undefined behavior. This could include
/// panics, incorrect results, aborts, memory leaks, and non-termination.
/// specified (it could include panics, incorrect results, aborts, memory
/// leaks, or non-termination) but will not be undefined behavior.
///
/// # Examples
///
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/defaults/default-annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![feature(staged_api)]
#![feature(const_generics_defaults)]
#![allow(incomplete_features)]
// FIXME(const_generics): It seems like we aren't testing the right thing here,
// FIXME(const_generics_defaults): It seems like we aren't testing the right thing here,
// I would assume that we want the attributes to apply to the const parameter defaults
// themselves.
#![stable(feature = "const_default_test", since="none")]
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/const-generics/defaults/doesnt_infer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![feature(const_generics_defaults)]

// test that defaulted const params are not used to help type inference

struct Foo<const N: u32 = 2>;

impl<const N: u32> Foo<N> {
fn foo() -> Self { loop {} }
}

fn main() {
let foo = Foo::<1>::foo();
let foo = Foo::foo();
//~^ error: type annotations needed for `Foo<{_: u32}>`
}
11 changes: 11 additions & 0 deletions src/test/ui/const-generics/defaults/doesnt_infer.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0282]: type annotations needed for `Foo<{_: u32}>`
--> $DIR/doesnt_infer.rs:13:15
|
LL | let foo = Foo::foo();
| --- ^^^^^^^^ cannot infer the value of const parameter `N`
| |
| consider giving `foo` the explicit type `Foo<{_: u32}>`, where the type parameter `N` is specified

error: aborting due to previous error

For more information about this error, try `rustc --explain E0282`.
31 changes: 31 additions & 0 deletions src/test/ui/const-generics/defaults/rp_impl_trait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// run-pass
#![feature(const_generics_defaults)]

struct Uwu<const N: u32 = 1, const M: u32 = N>;

trait Trait {}
impl<const N: u32> Trait for Uwu<N> {}

fn rawr<const N: u32>() -> impl Trait {
Uwu::<N>
}

trait Traitor<const N: u8 = 1, const M: u8 = N> { }

impl<const N: u8> Traitor<N> for u32 {}
impl Traitor<1, 1> for u64 {}

fn uwu<const N: u8>() -> impl Traitor<N> {
1_u32
}

fn owo() -> impl Traitor {
1_u64
}

fn main() {
rawr::<3>();
rawr::<7>();
uwu::<{ u8::MAX }>();
owo();
}
33 changes: 33 additions & 0 deletions src/test/ui/const-generics/defaults/rp_impl_trait_fail.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#![feature(const_generics_defaults)]

struct Uwu<const N: u32 = 1, const M: u32 = N>;

trait Trait {}
impl<const N: u32> Trait for Uwu<N> {}

fn rawr() -> impl Trait {
//~^ error: the trait bound `Uwu<10_u32, 12_u32>: Trait` is not satisfied
Uwu::<10, 12>
}

trait Traitor<const N: u8 = 1, const M: u8 = N> { }

impl<const N: u8> Traitor<N, 2> for u32 {}
impl Traitor<1, 2> for u64 {}


fn uwu<const N: u8>() -> impl Traitor<N> {
//~^ error: the trait bound `u32: Traitor<N, N>` is not satisfied
1_u32
}

fn owo() -> impl Traitor {
//~^ error: the trait bound `u64: Traitor<1_u8, 1_u8>` is not satisfied
1_u64
}

fn main() {
rawr();
uwu();
owo();
}
30 changes: 30 additions & 0 deletions src/test/ui/const-generics/defaults/rp_impl_trait_fail.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
error[E0277]: the trait bound `Uwu<10_u32, 12_u32>: Trait` is not satisfied
--> $DIR/rp_impl_trait_fail.rs:8:14
|
LL | fn rawr() -> impl Trait {
| ^^^^^^^^^^ the trait `Trait` is not implemented for `Uwu<10_u32, 12_u32>`
|
= help: the following implementations were found:
<Uwu<N> as Trait>

error[E0277]: the trait bound `u32: Traitor<N, N>` is not satisfied
--> $DIR/rp_impl_trait_fail.rs:19:26
|
LL | fn uwu<const N: u8>() -> impl Traitor<N> {
| ^^^^^^^^^^^^^^^ the trait `Traitor<N, N>` is not implemented for `u32`
|
= help: the following implementations were found:
<u32 as Traitor<N, 2_u8>>

error[E0277]: the trait bound `u64: Traitor<1_u8, 1_u8>` is not satisfied
--> $DIR/rp_impl_trait_fail.rs:24:13
|
LL | fn owo() -> impl Traitor {
| ^^^^^^^^^^^^ the trait `Traitor<1_u8, 1_u8>` is not implemented for `u64`
|
= help: the following implementations were found:
<u64 as Traitor<1_u8, 2_u8>>

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0277`.
45 changes: 45 additions & 0 deletions src/test/ui/const-generics/defaults/trait_objects.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// run-pass
#![feature(const_generics_defaults)]

trait Trait<const N: u8 = 12> {
fn uwu(&self) -> u8 {
N
}
}

impl Trait for u32 {}

impl Trait<12> for u64 {
fn uwu(&self) -> u8 {
*self as u8
}
}

fn foo(arg: &dyn Trait) -> u8 {
arg.uwu()
}

trait Traitor<const N: u8 = 1, const M: u8 = N> {
fn owo(&self) -> u8 {
M
}
}

impl Traitor<2> for bool { }
impl Traitor for u8 {
fn owo(&self) -> u8 {
*self
}
}

fn bar<const N: u8>(arg: &dyn Traitor<N>) -> u8 {
arg.owo()
}

fn main() {
assert_eq!(foo(&10_u32), 12);
assert_eq!(foo(&3_u64), 3);

assert_eq!(bar(&true), 2);
assert_eq!(bar(&1_u8), 1);
}
Loading