Skip to content

Commit 619c27a

Browse files
committed
Auto merge of rust-lang#87003 - m-ou-se:rollup-x7mhv3v, r=m-ou-se
Rollup of 5 pull requests Successful merges: - rust-lang#86855 (Fix comments about unique borrows) - rust-lang#86881 (Inline implementation of lookup_line) - rust-lang#86937 (Change linked tracking issue for more_qualified_paths) - rust-lang#86994 (Update the comment on `lower_expr_try`) - rust-lang#87000 (Use #[track_caller] in const panic diagnostics.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents e916b7c + 2152c14 commit 619c27a

File tree

12 files changed

+83
-55
lines changed

12 files changed

+83
-55
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1559,13 +1559,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
15591559

15601560
/// Desugar `ExprKind::Try` from: `<expr>?` into:
15611561
/// ```rust
1562-
/// match Try::into_result(<expr>) {
1563-
/// Ok(val) => #[allow(unreachable_code)] val,
1564-
/// Err(err) => #[allow(unreachable_code)]
1565-
/// // If there is an enclosing `try {...}`:
1566-
/// break 'catch_target Try::from_error(From::from(err)),
1567-
/// // Otherwise:
1568-
/// return Try::from_error(From::from(err)),
1562+
/// match Try::branch(<expr>) {
1563+
/// ControlFlow::Continue(val) => #[allow(unreachable_code)] val,,
1564+
/// ControlFlow::Break(residual) =>
1565+
/// #[allow(unreachable_code)]
1566+
/// // If there is an enclosing `try {...}`:
1567+
/// break 'catch_target Try::from_residual(residual),
1568+
/// // Otherwise:
1569+
/// return Try::from_residual(residual),
15691570
/// }
15701571
/// ```
15711572
fn lower_expr_try(&mut self, span: Span, sub_expr: &Expr) -> hir::ExprKind<'hir> {

compiler/rustc_feature/src/active.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ declare_features! (
685685
(incomplete, unnamed_fields, "1.53.0", Some(49804), None),
686686

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

690690
// -------------------------------------------------------------------------
691691
// feature-group-end: actual feature gates

compiler/rustc_middle/src/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ pub enum BorrowKind {
651651
/// in an aliasable location. To solve, you'd have to translate with
652652
/// an `&mut` borrow:
653653
///
654-
/// struct Env { x: & &mut isize }
654+
/// struct Env { x: &mut &mut isize }
655655
/// let x: &mut isize = ...;
656656
/// let y = (&mut Env { &mut x }, fn_ptr); // changed from &x to &mut x
657657
/// fn fn_ptr(env: &mut Env) { **env.x += 5; }

compiler/rustc_middle/src/ty/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ pub enum BorrowKind {
347347
/// an `&mut` borrow:
348348
///
349349
/// ```
350-
/// struct Env { x: & &mut isize }
350+
/// struct Env { x: &mut &mut isize }
351351
/// let x: &mut isize = ...;
352352
/// let y = (&mut Env { &mut x }, fn_ptr); // changed from &x to &mut x
353353
/// fn fn_ptr(env: &mut Env) { **env.x += 5; }

compiler/rustc_mir/src/interpret/eval_context.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
398398

399399
#[inline(always)]
400400
pub fn cur_span(&self) -> Span {
401-
self.stack().last().map_or(self.tcx.span, |f| f.current_span())
401+
self.stack()
402+
.iter()
403+
.rev()
404+
.find(|frame| !frame.instance.def.requires_caller_location(*self.tcx))
405+
.map_or(self.tcx.span, |f| f.current_span())
402406
}
403407

404408
#[inline(always)]
@@ -927,7 +931,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
927931
#[must_use]
928932
pub fn generate_stacktrace(&self) -> Vec<FrameInfo<'tcx>> {
929933
let mut frames = Vec::new();
930-
for frame in self.stack().iter().rev() {
934+
for frame in self
935+
.stack()
936+
.iter()
937+
.rev()
938+
.skip_while(|frame| frame.instance.def.requires_caller_location(*self.tcx))
939+
{
931940
let lint_root = frame.current_source_info().and_then(|source_info| {
932941
match &frame.body.source_scopes[source_info.scope].local_data {
933942
mir::ClearCrossCrate::Set(data) => Some(data.lint_root),

compiler/rustc_span/src/lib.rs

+4-16
Original file line numberDiff line numberDiff line change
@@ -1552,13 +1552,11 @@ impl SourceFile {
15521552
/// number. If the source_file is empty or the position is located before the
15531553
/// first line, `None` is returned.
15541554
pub fn lookup_line(&self, pos: BytePos) -> Option<usize> {
1555-
if self.lines.is_empty() {
1556-
return None;
1555+
match self.lines.binary_search(&pos) {
1556+
Ok(idx) => Some(idx),
1557+
Err(0) => None,
1558+
Err(idx) => Some(idx - 1),
15571559
}
1558-
1559-
let line_index = lookup_line(&self.lines[..], pos);
1560-
assert!(line_index < self.lines.len() as isize);
1561-
if line_index >= 0 { Some(line_index as usize) } else { None }
15621560
}
15631561

15641562
pub fn line_bounds(&self, line_index: usize) -> Range<BytePos> {
@@ -1957,16 +1955,6 @@ impl InnerSpan {
19571955
}
19581956
}
19591957

1960-
// Given a slice of line start positions and a position, returns the index of
1961-
// the line the position is on. Returns -1 if the position is located before
1962-
// the first line.
1963-
fn lookup_line(lines: &[BytePos], pos: BytePos) -> isize {
1964-
match lines.binary_search(&pos) {
1965-
Ok(line) => line as isize,
1966-
Err(line) => line as isize - 1,
1967-
}
1968-
}
1969-
19701958
/// Requirements for a `StableHashingContext` to be used in this crate.
19711959
///
19721960
/// This is a hack to allow using the [`HashStable_Generic`] derive macro

compiler/rustc_span/src/tests.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ use super::*;
22

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

7-
assert_eq!(lookup_line(lines, BytePos(0)), -1);
8-
assert_eq!(lookup_line(lines, BytePos(3)), 0);
9-
assert_eq!(lookup_line(lines, BytePos(4)), 0);
10+
assert_eq!(sf.lookup_line(BytePos(0)), None);
11+
assert_eq!(sf.lookup_line(BytePos(3)), Some(0));
12+
assert_eq!(sf.lookup_line(BytePos(4)), Some(0));
1013

11-
assert_eq!(lookup_line(lines, BytePos(16)), 0);
12-
assert_eq!(lookup_line(lines, BytePos(17)), 1);
13-
assert_eq!(lookup_line(lines, BytePos(18)), 1);
14+
assert_eq!(sf.lookup_line(BytePos(16)), Some(0));
15+
assert_eq!(sf.lookup_line(BytePos(17)), Some(1));
16+
assert_eq!(sf.lookup_line(BytePos(18)), Some(1));
1417

15-
assert_eq!(lookup_line(lines, BytePos(28)), 2);
16-
assert_eq!(lookup_line(lines, BytePos(29)), 2);
18+
assert_eq!(sf.lookup_line(BytePos(28)), Some(2));
19+
assert_eq!(sf.lookup_line(BytePos(29)), Some(2));
1720
}
1821

1922
#[test]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#![feature(const_panic)]
2+
#![allow(non_fmt_panics)]
3+
#![crate_type = "lib"]
4+
5+
#[track_caller]
6+
const fn a() -> u32 {
7+
panic!("hey")
8+
}
9+
10+
#[track_caller]
11+
const fn b() -> u32 {
12+
a()
13+
}
14+
15+
const fn c() -> u32 {
16+
b()
17+
//~^ ERROR evaluation of constant value failed
18+
//~| NOTE the evaluated program panicked
19+
//~| NOTE inside
20+
}
21+
22+
const X: u32 = c();
23+
//~^ NOTE inside
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0080]: evaluation of constant value failed
2+
--> $DIR/const_panic_track_caller.rs:16:5
3+
|
4+
LL | b()
5+
| ^^^
6+
| |
7+
| the evaluated program panicked at 'hey', $DIR/const_panic_track_caller.rs:16:5
8+
| inside `c` at $DIR/const_panic_track_caller.rs:16:5
9+
...
10+
LL | const X: u32 = c();
11+
| --- inside `X` at $DIR/const_panic_track_caller.rs:22:16
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0080`.

src/test/ui/consts/const-unwrap.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

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

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

1110
fn main() {
1211
println!("{}", FOO);

src/test/ui/consts/const-unwrap.stderr

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
error[E0080]: evaluation of constant value failed
2-
--> $SRC_DIR/core/src/option.rs:LL:COL
3-
|
4-
LL | None => panic!("called `Option::unwrap()` on a `None` value"),
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
| |
7-
| the evaluated program panicked at 'called `Option::unwrap()` on a `None` value', $DIR/const-unwrap.rs:9:38
8-
| inside `Option::<i32>::unwrap` at $SRC_DIR/core/src/panic.rs:LL:COL
9-
|
10-
::: $DIR/const-unwrap.rs:9:18
2+
--> $DIR/const-unwrap.rs:7:18
113
|
124
LL | const BAR: i32 = Option::<i32>::None.unwrap();
13-
| ---------------------------- inside `BAR` at $DIR/const-unwrap.rs:9:18
14-
|
15-
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'called `Option::unwrap()` on a `None` value', $DIR/const-unwrap.rs:7:38
166

177
error: aborting due to previous error
188

src/test/ui/feature-gates/feature-gate-more-qualified-paths.stderr

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

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

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

2828
error: aborting due to 3 previous errors

0 commit comments

Comments
 (0)