@@ -77,13 +77,14 @@ use crate::sources::CRATES_IO_REGISTRY;
77
77
use crate :: util:: errors:: CargoResult ;
78
78
use crate :: util:: network:: http:: configure_http_handle;
79
79
use crate :: util:: network:: http:: http_handle;
80
- use crate :: util:: { internal, CanonicalUrl } ;
80
+ use crate :: util:: { closest_msg , internal, CanonicalUrl } ;
81
81
use crate :: util:: { Filesystem , IntoUrl , IntoUrlWithBase , Rustc } ;
82
82
use anyhow:: { anyhow, bail, format_err, Context as _} ;
83
83
use cargo_credential:: Secret ;
84
84
use cargo_util:: paths;
85
85
use cargo_util_schemas:: manifest:: RegistryName ;
86
86
use curl:: easy:: Easy ;
87
+ use itertools:: Itertools ;
87
88
use lazycell:: LazyCell ;
88
89
use serde:: de:: IntoDeserializer as _;
89
90
use serde:: Deserialize ;
@@ -678,15 +679,27 @@ impl GlobalContext {
678
679
} ) ,
679
680
] ;
680
681
682
+ let template_variables = replacements
683
+ . iter ( )
684
+ . map ( |( key, _) | key[ 1 ..key. len ( ) - 1 ] . to_string ( ) )
685
+ . collect_vec ( ) ;
686
+
681
687
let path = val
682
688
. resolve_templated_path ( self , replacements)
683
689
. map_err ( |e| match e {
684
690
path:: ResolveTemplateError :: UnexpectedVariable {
685
691
variable,
686
692
raw_template,
687
- } => anyhow ! (
688
- "unexpected variable `{variable}` in build.build-dir path `{raw_template}`"
689
- ) ,
693
+ } => {
694
+ let mut suggestion = closest_msg ( & variable, template_variables. iter ( ) , |key| key, "template variable" ) ;
695
+ if suggestion == "" {
696
+ let variables = template_variables. iter ( ) . map ( |v| format ! ( "`{{{v}}}`" ) ) . join ( ", " ) ;
697
+ suggestion = format ! ( "\n \n help: available template variables are [{variables}]" ) ;
698
+ }
699
+ anyhow ! (
700
+ "unexpected variable `{variable}` in build.build-dir path `{raw_template}`{suggestion}"
701
+ )
702
+ } ,
690
703
path:: ResolveTemplateError :: UnexpectedBracket { bracket_type, raw_template } => {
691
704
let ( btype, literal) = match bracket_type {
692
705
path:: BracketType :: Opening => ( "opening" , "{" ) ,
0 commit comments