diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2022-08-07 14:35:11 +0200 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2022-08-07 14:35:11 +0200 |
| commit | f6af4efec579edc8d10f8c2ba5d3c43331130b39 (patch) | |
| tree | 45b07c47717ae0dd4f5ec33455169ad50797c76f | |
| parent | 55f46419afd2e49acfc6be176ad4aeadaa5686d7 (diff) | |
| download | rust-f6af4efec579edc8d10f8c2ba5d3c43331130b39.tar.gz rust-f6af4efec579edc8d10f8c2ba5d3c43331130b39.zip | |
Use start_point instead of next_point to point to elided lifetime ampersand.
| -rw-r--r-- | compiler/rustc_ast_lowering/src/lib.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/late.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/lifetimes/fullwidth-ampersand.rs | 7 | ||||
| -rw-r--r-- | src/test/ui/lifetimes/fullwidth-ampersand.stderr | 26 |
4 files changed, 35 insertions, 2 deletions
diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index a5b089b032d..0562f7b88a3 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -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(®ion); diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index dea3eaecda6..ac8d26fb072 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -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); } diff --git a/src/test/ui/lifetimes/fullwidth-ampersand.rs b/src/test/ui/lifetimes/fullwidth-ampersand.rs new file mode 100644 index 00000000000..7d8948bd844 --- /dev/null +++ b/src/test/ui/lifetimes/fullwidth-ampersand.rs @@ -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() {} diff --git a/src/test/ui/lifetimes/fullwidth-ampersand.stderr b/src/test/ui/lifetimes/fullwidth-ampersand.stderr new file mode 100644 index 00000000000..4645254f4b7 --- /dev/null +++ b/src/test/ui/lifetimes/fullwidth-ampersand.stderr @@ -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`. |
