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 9 pull requests #106587

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b8d560c
Stabilize `main_separator_str`
SUPERCILEX Oct 16, 2022
0b3061a
Stabilize `::{core,std}::pin::pin!`
danielhenrymantilla Oct 31, 2022
8f80a23
adjust comments about pre-push.sh hook
kadiwa4 Jan 4, 2023
23c3a30
Explain error with `&mut self` for unsized trait impls
clubby789 Jan 3, 2023
d4139b3
jsondoclint: Check local items in `paths` are also in `index`.
aDotInTheVoid Jan 6, 2023
09382db
minor fixes for `error_codes.rs` tidy check
Ezrashaw Jan 7, 2023
fed3499
Clarify examples for `VecDeque::get/get_mut`
clubby789 Jan 7, 2023
ae61c25
doc/test: add UI test and reword docs for `E0013` and `E0015`
Ezrashaw Jan 7, 2023
93c0d8d
remove unreachable error code `E0313`
Ezrashaw Jan 8, 2023
d85d38b
Add test
estebank Jan 8, 2023
ebbc5da
Do not emit wrong E0308 suggestion for closure mismatch
estebank Jan 8, 2023
4aac9b0
Rollup merge of #103104 - SUPERCILEX:sep-ref, r=dtolnay
Jan 8, 2023
5378aea
Rollup merge of #103800 - danielhenrymantilla:stabilize-pin-macro, r=…
Jan 8, 2023
59421fa
Rollup merge of #106410 - clubby789:borrow-mut-self-mut-self-diag, r=…
Jan 8, 2023
63c05bc
Rollup merge of #106457 - kadiwa4:no-bless, r=Mark-Simulacrum
Jan 8, 2023
4f138f1
Rollup merge of #106546 - aDotInTheVoid:jsondoclint-path-local-item, …
Jan 8, 2023
fddd27b
Rollup merge of #106557 - Ezrashaw:ui-test-fixups-1, r=GuillaumeGomez
Jan 8, 2023
bfbd959
Rollup merge of #106562 - clubby789:vec-deque-example, r=Mark-Simulacrum
Jan 8, 2023
ec549d9
Rollup merge of #106580 - Ezrashaw:remove-e0313, r=compiler-errors
Jan 8, 2023
6375c2e
Rollup merge of #106581 - estebank:bad-suggestion, r=compiler-errors
Jan 8, 2023
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
27 changes: 16 additions & 11 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,20 +344,25 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
} else {
err.span_help(source_info.span, "try removing `&mut` here");
}
} else if decl.mutability == Mutability::Not
&& !matches!(
} else if decl.mutability == Mutability::Not {
if matches!(
decl.local_info,
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::ImplicitSelf(
hir::ImplicitSelfKind::MutRef
))))
)
{
err.span_suggestion_verbose(
decl.source_info.span.shrink_to_lo(),
"consider making the binding mutable",
"mut ",
Applicability::MachineApplicable,
);
),)))
) {
err.note(
"as `Self` may be unsized, this call attempts to take `&mut &mut self`",
);
err.note("however, `&mut self` expands to `self: &mut Self`, therefore `self` cannot be borrowed mutably");
} else {
err.span_suggestion_verbose(
decl.source_info.span.shrink_to_lo(),
"consider making the binding mutable",
"mut ",
Applicability::MachineApplicable,
);
};
}
}

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,7 @@ E0791: include_str!("./error_codes/E0791.md"),
// E0300, // unexpanded macro
// E0304, // expected signed integer constant
// E0305, // expected constant
E0313, // lifetime of borrowed pointer outlives lifetime of captured
// variable
// E0313, // removed: found unreachable
// E0314, // closure outlives stack frame
// E0315, // cannot invoke closure outside of its lifetime
// E0319, // trait impls for defaulted traits allowed just for structs/enums
Expand Down
23 changes: 8 additions & 15 deletions compiler/rustc_error_codes/src/error_codes/E0015.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
A constant item was initialized with something that is not a constant
expression.
A non-`const` function was called in a `const` context.

Erroneous code example:

Expand All @@ -8,26 +7,20 @@ fn create_some() -> Option<u8> {
Some(1)
}

const FOO: Option<u8> = create_some(); // error!
// error: cannot call non-const fn `create_some` in constants
const FOO: Option<u8> = create_some();
```

The only functions that can be called in static or constant expressions are
`const` functions, and struct/enum constructors.
All functions used in a `const` context (constant or static expression) must
be marked `const`.

To fix this error, you can declare `create_some` as a constant function:

```
const fn create_some() -> Option<u8> { // declared as a const function
// declared as a `const` function:
const fn create_some() -> Option<u8> {
Some(1)
}

const FOO: Option<u8> = create_some(); // ok!

// These are also working:
struct Bar {
x: u8,
}

const OTHER_FOO: Option<u8> = Some(1);
const BAR: Bar = Bar {x: 1};
const FOO: Option<u8> = create_some(); // no error!
```
5 changes: 4 additions & 1 deletion compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
// If we've reached our target type with just removing `&`, then just print now.
if steps == 0 {
if steps == 0 && !remove.trim().is_empty() {
return Some((
prefix_span,
format!("consider removing the `{}`", remove.trim()),
Expand Down Expand Up @@ -1438,6 +1438,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else {
(prefix_span, format!("{}{}", prefix, "*".repeat(steps)))
};
if suggestion.trim().is_empty() {
return None;
}

return Some((
span,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ignore-tidy-filelength
//! Error Reporting Code for the inference engine
//!
//! Because of the way inference, and in particular region inference,
Expand Down
37 changes: 0 additions & 37 deletions compiler/rustc_infer/src/infer/error_reporting/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
infer::Reborrow(span) => {
RegionOriginNote::Plain { span, msg: fluent::infer_reborrow }.add_to_diagnostic(err)
}
infer::ReborrowUpvar(span, ref upvar_id) => {
let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id);
RegionOriginNote::WithName {
span,
msg: fluent::infer_reborrow,
name: &var_name.to_string(),
continues: false,
}
.add_to_diagnostic(err);
}
infer::RelateObjectBound(span) => {
RegionOriginNote::Plain { span, msg: fluent::infer_relate_object_bound }
.add_to_diagnostic(err);
Expand Down Expand Up @@ -162,33 +152,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
);
err
}
infer::ReborrowUpvar(span, ref upvar_id) => {
let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id);
let mut err = struct_span_err!(
self.tcx.sess,
span,
E0313,
"lifetime of borrowed pointer outlives lifetime of captured variable `{}`...",
var_name
);
note_and_explain_region(
self.tcx,
&mut err,
"...the borrowed pointer is valid for ",
sub,
"...",
None,
);
note_and_explain_region(
self.tcx,
&mut err,
&format!("...but `{}` is only valid for ", var_name),
sup,
"",
None,
);
err
}
infer::RelateObjectBound(span) => {
let mut err = struct_span_err!(
self.tcx.sess,
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,6 @@ pub enum SubregionOrigin<'tcx> {
/// Creating a pointer `b` to contents of another reference
Reborrow(Span),

/// Creating a pointer `b` to contents of an upvar
ReborrowUpvar(Span, ty::UpvarId),

/// Data with type `Ty<'tcx>` was borrowed
DataBorrowed(Ty<'tcx>, Span),

Expand Down Expand Up @@ -1954,7 +1951,6 @@ impl<'tcx> SubregionOrigin<'tcx> {
RelateParamBound(a, ..) => a,
RelateRegionParamBound(a) => a,
Reborrow(a) => a,
ReborrowUpvar(a, _) => a,
DataBorrowed(_, a) => a,
ReferenceOutlivesReferent(_, a) => a,
CompareImplItemObligation { span, .. } => span,
Expand Down
4 changes: 3 additions & 1 deletion library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// buf.push_back(3);
/// buf.push_back(4);
/// buf.push_back(5);
/// buf.push_back(6);
/// assert_eq!(buf.get(1), Some(&4));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -661,10 +662,11 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// buf.push_back(3);
/// buf.push_back(4);
/// buf.push_back(5);
/// buf.push_back(6);
/// assert_eq!(buf[1], 4);
/// if let Some(elem) = buf.get_mut(1) {
/// *elem = 7;
/// }
///
/// assert_eq!(buf[1], 7);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
7 changes: 2 additions & 5 deletions library/core/src/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,6 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
/// ### Basic usage
///
/// ```rust
/// #![feature(pin_macro)]
/// # use core::marker::PhantomPinned as Foo;
/// use core::pin::{pin, Pin};
///
Expand All @@ -1044,7 +1043,6 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
/// ### Manually polling a `Future` (without `Unpin` bounds)
///
/// ```rust
/// #![feature(pin_macro)]
/// use std::{
/// future::Future,
/// pin::pin,
Expand Down Expand Up @@ -1083,7 +1081,7 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
/// ### With `Generator`s
///
/// ```rust
/// #![feature(generators, generator_trait, pin_macro)]
/// #![feature(generators, generator_trait)]
/// use core::{
/// ops::{Generator, GeneratorState},
/// pin::pin,
Expand Down Expand Up @@ -1126,7 +1124,6 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
/// The following, for instance, fails to compile:
///
/// ```rust,compile_fail
/// #![feature(pin_macro)]
/// use core::pin::{pin, Pin};
/// # use core::{marker::PhantomPinned as Foo, mem::drop as stuff};
///
Expand Down Expand Up @@ -1168,7 +1165,7 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
/// constructor.
///
/// [`Box::pin`]: ../../std/boxed/struct.Box.html#method.pin
#[unstable(feature = "pin_macro", issue = "93178")]
#[stable(feature = "pin_macro", since = "CURRENT_RUSTC_VERSION")]
#[rustc_macro_transparency = "semitransparent"]
#[allow_internal_unstable(unsafe_pin_internals)]
pub macro pin($value:expr $(,)?) {
Expand Down
1 change: 0 additions & 1 deletion library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#![feature(is_sorted)]
#![feature(layout_for_ptr)]
#![feature(pattern)]
#![feature(pin_macro)]
#![feature(sort_internals)]
#![feature(slice_take)]
#![feature(slice_from_ptr_range)]
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ pub const MAIN_SEPARATOR: char = crate::sys::path::MAIN_SEP;
/// The primary separator of path components for the current platform.
///
/// For example, `/` on Unix and `\` on Windows.
#[unstable(feature = "main_separator_str", issue = "94071")]
#[stable(feature = "main_separator_str", since = "CURRENT_RUSTC_VERSION")]
pub const MAIN_SEPARATOR_STR: &str = crate::sys::path::MAIN_SEP_STR;

////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ pub fn interactive_path() -> io::Result<Profile> {
Ok(template)
}

// install a git hook to automatically run tidy --bless, if they want
// install a git hook to automatically run tidy, if they want
fn install_git_hook_maybe(config: &Config) -> io::Result<()> {
let git = t!(config.git().args(&["rev-parse", "--git-common-dir"]).output().map(|output| {
assert!(output.status.success(), "failed to run `git`");
Expand All @@ -367,7 +367,7 @@ fn install_git_hook_maybe(config: &Config) -> io::Result<()> {
println!();
println!(
"Rust's CI will automatically fail if it doesn't pass `tidy`, the internal tool for ensuring code quality.
If you'd like, x.py can install a git hook for you that will automatically run `tidy --bless` before
If you'd like, x.py can install a git hook for you that will automatically run `test tidy` before
pushing your code to ensure your code is up to par. If you decide later that this behavior is
undesirable, simply delete the `pre-push` file from .git/hooks."
);
Expand Down
2 changes: 1 addition & 1 deletion src/etc/pre-push.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
#
# Call `tidy --bless` before git push
# Call `tidy` before git push
# Copy this script to .git/hooks to activate,
# and remove it from .git/hooks to deactivate.
#
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/borrowck/issue-93078.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
trait Modify {
fn modify(&mut self) ;
}

impl<T> Modify for T {
fn modify(&mut self) {}
}

trait Foo {
fn mute(&mut self) {
self.modify(); //~ ERROR cannot borrow `self` as mutable
}
}

fn main() {}
12 changes: 12 additions & 0 deletions src/test/ui/borrowck/issue-93078.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
--> $DIR/issue-93078.rs:11:9
|
LL | self.modify();
| ^^^^^^^^^^^^^ cannot borrow as mutable
|
= note: as `Self` may be unsized, this call attempts to take `&mut &mut self`
= note: however, `&mut self` expands to `self: &mut Self`, therefore `self` cannot be borrowed mutably

error: aborting due to previous error

For more information about this error, try `rustc --explain E0596`.
4 changes: 4 additions & 0 deletions src/test/ui/error-codes/E0013.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
static X: i32 = 42;
const Y: i32 = X; //~ ERROR constants cannot refer to statics [E0013]

fn main() {}
11 changes: 11 additions & 0 deletions src/test/ui/error-codes/E0013.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0013]: constants cannot refer to statics
--> $DIR/E0013.rs:2:16
|
LL | const Y: i32 = X;
| ^
|
= help: consider extracting the value of the `static` to a `const`, and referring to that

error: aborting due to previous error

For more information about this error, try `rustc --explain E0013`.
8 changes: 8 additions & 0 deletions src/test/ui/error-codes/E0015.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn create_some() -> Option<u8> {
Some(1)
}

const FOO: Option<u8> = create_some();
//~^ ERROR cannot call non-const fn `create_some` in constants [E0015]

fn main() {}
11 changes: 11 additions & 0 deletions src/test/ui/error-codes/E0015.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0015]: cannot call non-const fn `create_some` in constants
--> $DIR/E0015.rs:5:25
|
LL | const FOO: Option<u8> = create_some();
| ^^^^^^^^^^^^^
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants

error: aborting due to previous error

For more information about this error, try `rustc --explain E0015`.
1 change: 0 additions & 1 deletion src/test/ui/pin-macro/cant_access_internals.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// edition:2018
#![feature(pin_macro)]

use core::{
marker::PhantomPinned,
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/pin-macro/cant_access_internals.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0658]: use of unstable library feature 'unsafe_pin_internals'
--> $DIR/cant_access_internals.rs:12:15
--> $DIR/cant_access_internals.rs:11:15
|
LL | mem::take(phantom_pinned.pointer);
| ^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// edition:2018
#![feature(pin_macro)]

use core::{
convert::identity,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0716]: temporary value dropped while borrowed
--> $DIR/lifetime_errors_on_promotion_misusage.rs:12:35
--> $DIR/lifetime_errors_on_promotion_misusage.rs:11:35
|
LL | let phantom_pinned = identity(pin!(PhantomPinned));
| ^^^^^^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
Expand All @@ -13,7 +13,7 @@ LL | stuff(phantom_pinned)
= note: this error originates in the macro `pin` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0716]: temporary value dropped while borrowed
--> $DIR/lifetime_errors_on_promotion_misusage.rs:19:30
--> $DIR/lifetime_errors_on_promotion_misusage.rs:18:30
|
LL | let phantom_pinned = {
| -------------- borrow later stored here
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/type/closure-with-wrong-borrows.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
struct S<'a>(&'a str);

fn f(inner: fn(&str, &S)) {
}

#[allow(unreachable_code)]
fn main() {
let inner: fn(_, _) = unimplemented!();
f(inner); //~ ERROR mismatched types
}
Loading