Skip to content

Commit

Permalink
Rollup merge of #100230 - cjgillot:noice-multibyte-amp, r=compiler-er…
Browse files Browse the repository at this point in the history
…rors

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
  • Loading branch information
matthiaskrgr authored Aug 7, 2022
2 parents 07315fe + f6af4ef commit 5648add
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} else {
self.next_node_id()
};
let span = self.tcx.sess.source_map().next_point(t.span.shrink_to_lo());
let span = self.tcx.sess.source_map().start_point(t.span);
Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id }
});
let lifetime = self.lower_lifetime(&region);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
// Elided lifetime in reference: we resolve as if there was some lifetime `'_` with
// NodeId `ty.id`.
// This span will be used in case of elision failure.
let span = self.r.session.source_map().next_point(ty.span.shrink_to_lo());
let span = self.r.session.source_map().start_point(ty.span);
self.resolve_elided_lifetime(ty.id, span);
visit::walk_ty(self, ty);
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/lifetimes/fullwidth-ampersand.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Verify that we do not ICE when the user uses a multubyte ampersand.

fn f(_: &()) -> &() { todo!() }
//~^ ERROR unknown start of token: \u{ff06}
//~| ERROR missing lifetime specifier [E0106]

fn main() {}
26 changes: 26 additions & 0 deletions src/test/ui/lifetimes/fullwidth-ampersand.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error: unknown start of token: \u{ff06}
--> $DIR/fullwidth-ampersand.rs:3:10
|
LL | fn f(_: &&()) -> &() { todo!() }
| ^^
|
help: Unicode character '&' (Fullwidth Ampersand) looks like '&' (Ampersand), but it is not
|
LL | fn f(_: &&()) -> &() { todo!() }
| ~

error[E0106]: missing lifetime specifier
--> $DIR/fullwidth-ampersand.rs:3:18
|
LL | fn f(_: &&()) -> &() { todo!() }
| ----- ^ expected named lifetime parameter
|
= 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
help: consider introducing a named lifetime parameter
|
LL | fn f<'a>(_: &'a &'a ()) -> &'a () { todo!() }
| ++++ ++ ++ ++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0106`.

0 comments on commit 5648add

Please sign in to comment.