I'm trying to achieve the following:

I know I can do that with help of intersections tikz library. However, the main requirement is to avoid any temporary paths (\path[name path=t] (2,0) -- (2,\ymaxv);) and name them somehow. In big projects it becomes messy.
Here are two my attempts that unfortunately doesn't work:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines = center]
\def\ymaxv{\pgfkeysvalueof{/pgfplots/ymax}}
\addplot[blue, name path global=x] {x};
% this doesn't work
\draw[red] (2,0) -- (intersection of {2,0--2,\ymaxv} and x);
% neither this does
\draw[red, name intersections={of={2,0--2,\ymaxv} and x}] (2,0) -- (intersection-1);
\end{axis}
\end{tikzpicture}
\end{document}
The first one (I know that is deprecated) doesn't see x path, but the other cannot work with 2,0--2,\ymaxv path.

