Skip to content

Commit 5648add

Browse files
authored
Rollup merge of #100230 - cjgillot:noice-multibyte-amp, r=compiler-errors
Use start_point instead of next_point to point to elided lifetime amp… Using `next_point` creates a span which points inside the multibyte token, ICEing. Fixes #100224
2 parents 07315fe + f6af4ef commit 5648add

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12281228
} else {
12291229
self.next_node_id()
12301230
};
1231-
let span = self.tcx.sess.source_map().next_point(t.span.shrink_to_lo());
1231+
let span = self.tcx.sess.source_map().start_point(t.span);
12321232
Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id }
12331233
});
12341234
let lifetime = self.lower_lifetime(&region);

Diff for: compiler/rustc_resolve/src/late.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
629629
// Elided lifetime in reference: we resolve as if there was some lifetime `'_` with
630630
// NodeId `ty.id`.
631631
// This span will be used in case of elision failure.
632-
let span = self.r.session.source_map().next_point(ty.span.shrink_to_lo());
632+
let span = self.r.session.source_map().start_point(ty.span);
633633
self.resolve_elided_lifetime(ty.id, span);
634634
visit::walk_ty(self, ty);
635635
}

Diff for: src/test/ui/lifetimes/fullwidth-ampersand.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Verify that we do not ICE when the user uses a multubyte ampersand.
2+
3+
fn f(_: &()) -> &() { todo!() }
4+
//~^ ERROR unknown start of token: \u{ff06}
5+
//~| ERROR missing lifetime specifier [E0106]
6+
7+
fn main() {}

Diff for: src/test/ui/lifetimes/fullwidth-ampersand.stderr

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: unknown start of token: \u{ff06}
2+
--> $DIR/fullwidth-ampersand.rs:3:10
3+
|
4+
LL | fn f(_: &&()) -> &() { todo!() }
5+
| ^^
6+
|
7+
help: Unicode character '&' (Fullwidth Ampersand) looks like '&' (Ampersand), but it is not
8+
|
9+
LL | fn f(_: &&()) -> &() { todo!() }
10+
| ~
11+
12+
error[E0106]: missing lifetime specifier
13+
--> $DIR/fullwidth-ampersand.rs:3:18
14+
|
15+
LL | fn f(_: &&()) -> &() { todo!() }
16+
| ----- ^ expected named lifetime parameter
17+
|
18+
= help: this function's return type contains a borrowed value, but the signature does not say which one of argument 1's 2 lifetimes it is borrowed from
19+
help: consider introducing a named lifetime parameter
20+
|
21+
LL | fn f<'a>(_: &'a &'a ()) -> &'a () { todo!() }
22+
| ++++ ++ ++ ++
23+
24+
error: aborting due to 2 previous errors
25+
26+
For more information about this error, try `rustc --explain E0106`.

0 commit comments

Comments
 (0)