Skip to content

Rollup of 5 pull requests #87003

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

Merged
merged 10 commits into from
Jul 9, 2021
15 changes: 8 additions & 7 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1559,13 +1559,14 @@ impl<'hir> LoweringContext<'_, 'hir> {

/// Desugar `ExprKind::Try` from: `<expr>?` into:
/// ```rust
/// match Try::into_result(<expr>) {
/// Ok(val) => #[allow(unreachable_code)] val,
/// Err(err) => #[allow(unreachable_code)]
/// // If there is an enclosing `try {...}`:
/// break 'catch_target Try::from_error(From::from(err)),
/// // Otherwise:
/// return Try::from_error(From::from(err)),
/// match Try::branch(<expr>) {
/// ControlFlow::Continue(val) => #[allow(unreachable_code)] val,,
/// ControlFlow::Break(residual) =>
/// #[allow(unreachable_code)]
/// // If there is an enclosing `try {...}`:
/// break 'catch_target Try::from_residual(residual),
/// // Otherwise:
/// return Try::from_residual(residual),
/// }
/// ```
fn lower_expr_try(&mut self, span: Span, sub_expr: &Expr) -> hir::ExprKind<'hir> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ declare_features! (
(incomplete, unnamed_fields, "1.53.0", Some(49804), None),

/// Allows qualified paths in struct expressions, struct patterns and tuple struct patterns.
(active, more_qualified_paths, "1.54.0", Some(80080), None),
(active, more_qualified_paths, "1.54.0", Some(86935), None),

// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ pub enum BorrowKind {
/// in an aliasable location. To solve, you'd have to translate with
/// an `&mut` borrow:
///
/// struct Env { x: & &mut isize }
/// struct Env { x: &mut &mut isize }
/// let x: &mut isize = ...;
/// let y = (&mut Env { &mut x }, fn_ptr); // changed from &x to &mut x
/// fn fn_ptr(env: &mut Env) { **env.x += 5; }
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ pub enum BorrowKind {
/// an `&mut` borrow:
///
/// ```
/// struct Env { x: & &mut isize }
/// struct Env { x: &mut &mut isize }
/// let x: &mut isize = ...;
/// let y = (&mut Env { &mut x }, fn_ptr); // changed from &x to &mut x
/// fn fn_ptr(env: &mut Env) { **env.x += 5; }
Expand Down
13 changes: 11 additions & 2 deletions compiler/rustc_mir/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {

#[inline(always)]
pub fn cur_span(&self) -> Span {
self.stack().last().map_or(self.tcx.span, |f| f.current_span())
self.stack()
.iter()
.rev()
.find(|frame| !frame.instance.def.requires_caller_location(*self.tcx))
.map_or(self.tcx.span, |f| f.current_span())
}

#[inline(always)]
Expand Down Expand Up @@ -927,7 +931,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
#[must_use]
pub fn generate_stacktrace(&self) -> Vec<FrameInfo<'tcx>> {
let mut frames = Vec::new();
for frame in self.stack().iter().rev() {
for frame in self
.stack()
.iter()
.rev()
.skip_while(|frame| frame.instance.def.requires_caller_location(*self.tcx))
{
let lint_root = frame.current_source_info().and_then(|source_info| {
match &frame.body.source_scopes[source_info.scope].local_data {
mir::ClearCrossCrate::Set(data) => Some(data.lint_root),
Expand Down
20 changes: 4 additions & 16 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1552,13 +1552,11 @@ impl SourceFile {
/// number. If the source_file is empty or the position is located before the
/// first line, `None` is returned.
pub fn lookup_line(&self, pos: BytePos) -> Option<usize> {
if self.lines.is_empty() {
return None;
match self.lines.binary_search(&pos) {
Ok(idx) => Some(idx),
Err(0) => None,
Err(idx) => Some(idx - 1),
}

let line_index = lookup_line(&self.lines[..], pos);
assert!(line_index < self.lines.len() as isize);
if line_index >= 0 { Some(line_index as usize) } else { None }
}

pub fn line_bounds(&self, line_index: usize) -> Range<BytePos> {
Expand Down Expand Up @@ -1957,16 +1955,6 @@ impl InnerSpan {
}
}

// Given a slice of line start positions and a position, returns the index of
// the line the position is on. Returns -1 if the position is located before
// the first line.
fn lookup_line(lines: &[BytePos], pos: BytePos) -> isize {
match lines.binary_search(&pos) {
Ok(line) => line as isize,
Err(line) => line as isize - 1,
}
}

/// Requirements for a `StableHashingContext` to be used in this crate.
///
/// This is a hack to allow using the [`HashStable_Generic`] derive macro
Expand Down
21 changes: 12 additions & 9 deletions compiler/rustc_span/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ use super::*;

#[test]
fn test_lookup_line() {
let lines = &[BytePos(3), BytePos(17), BytePos(28)];
let source = "abcdefghijklm\nabcdefghij\n...".to_owned();
let sf =
SourceFile::new(FileName::Anon(0), source, BytePos(3), SourceFileHashAlgorithm::Sha256);
assert_eq!(sf.lines.as_slice(), &[BytePos(3), BytePos(17), BytePos(28)]);

assert_eq!(lookup_line(lines, BytePos(0)), -1);
assert_eq!(lookup_line(lines, BytePos(3)), 0);
assert_eq!(lookup_line(lines, BytePos(4)), 0);
assert_eq!(sf.lookup_line(BytePos(0)), None);
assert_eq!(sf.lookup_line(BytePos(3)), Some(0));
assert_eq!(sf.lookup_line(BytePos(4)), Some(0));

assert_eq!(lookup_line(lines, BytePos(16)), 0);
assert_eq!(lookup_line(lines, BytePos(17)), 1);
assert_eq!(lookup_line(lines, BytePos(18)), 1);
assert_eq!(sf.lookup_line(BytePos(16)), Some(0));
assert_eq!(sf.lookup_line(BytePos(17)), Some(1));
assert_eq!(sf.lookup_line(BytePos(18)), Some(1));

assert_eq!(lookup_line(lines, BytePos(28)), 2);
assert_eq!(lookup_line(lines, BytePos(29)), 2);
assert_eq!(sf.lookup_line(BytePos(28)), Some(2));
assert_eq!(sf.lookup_line(BytePos(29)), Some(2));
}

#[test]
Expand Down
23 changes: 23 additions & 0 deletions src/test/ui/consts/const-eval/const_panic_track_caller.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![feature(const_panic)]
#![allow(non_fmt_panics)]
#![crate_type = "lib"]

#[track_caller]
const fn a() -> u32 {
panic!("hey")
}

#[track_caller]
const fn b() -> u32 {
a()
}

const fn c() -> u32 {
b()
//~^ ERROR evaluation of constant value failed
//~| NOTE the evaluated program panicked
//~| NOTE inside
}

const X: u32 = c();
//~^ NOTE inside
15 changes: 15 additions & 0 deletions src/test/ui/consts/const-eval/const_panic_track_caller.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0080]: evaluation of constant value failed
--> $DIR/const_panic_track_caller.rs:16:5
|
LL | b()
| ^^^
| |
| the evaluated program panicked at 'hey', $DIR/const_panic_track_caller.rs:16:5
| inside `c` at $DIR/const_panic_track_caller.rs:16:5
...
LL | const X: u32 = c();
| --- inside `X` at $DIR/const_panic_track_caller.rs:22:16

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.
5 changes: 2 additions & 3 deletions src/test/ui/consts/const-unwrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

const FOO: i32 = Some(42i32).unwrap();

// This causes an error, but it is attributed to the `panic` *inside* `Option::unwrap` (maybe due
// to `track_caller`?). A note points to the originating `const`.
const BAR: i32 = Option::<i32>::None.unwrap(); //~ NOTE
const BAR: i32 = Option::<i32>::None.unwrap();
//~^ERROR: evaluation of constant value failed

fn main() {
println!("{}", FOO);
Expand Down
14 changes: 2 additions & 12 deletions src/test/ui/consts/const-unwrap.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/option.rs:LL:COL
|
LL | None => panic!("called `Option::unwrap()` on a `None` value"),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| the evaluated program panicked at 'called `Option::unwrap()` on a `None` value', $DIR/const-unwrap.rs:9:38
| inside `Option::<i32>::unwrap` at $SRC_DIR/core/src/panic.rs:LL:COL
|
::: $DIR/const-unwrap.rs:9:18
--> $DIR/const-unwrap.rs:7:18
|
LL | const BAR: i32 = Option::<i32>::None.unwrap();
| ---------------------------- inside `BAR` at $DIR/const-unwrap.rs:9:18
|
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'called `Option::unwrap()` on a `None` value', $DIR/const-unwrap.rs:7:38

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0658]: usage of qualified paths in this context is experimental
LL | let <Foo as A>::Assoc { br } = StructStruct { br: 2 };
| ^^^^^^^^^^^^^^^^^
|
= note: see issue #80080 <https://github.com/rust-lang/rust/issues/80080> for more information
= note: see issue #86935 <https://github.com/rust-lang/rust/issues/86935> for more information
= help: add `#![feature(more_qualified_paths)]` to the crate attributes to enable

error[E0658]: usage of qualified paths in this context is experimental
Expand All @@ -13,7 +13,7 @@ error[E0658]: usage of qualified paths in this context is experimental
LL | let _ = <Foo as A>::Assoc { br: 2 };
| ^^^^^^^^^^^^^^^^^
|
= note: see issue #80080 <https://github.com/rust-lang/rust/issues/80080> for more information
= note: see issue #86935 <https://github.com/rust-lang/rust/issues/86935> for more information
= help: add `#![feature(more_qualified_paths)]` to the crate attributes to enable

error[E0658]: usage of qualified paths in this context is experimental
Expand All @@ -22,7 +22,7 @@ error[E0658]: usage of qualified paths in this context is experimental
LL | let <E>::V(..) = E::V(0);
| ^^^^^^
|
= note: see issue #80080 <https://github.com/rust-lang/rust/issues/80080> for more information
= note: see issue #86935 <https://github.com/rust-lang/rust/issues/86935> for more information
= help: add `#![feature(more_qualified_paths)]` to the crate attributes to enable

error: aborting due to 3 previous errors
Expand Down