File tree Expand file tree Collapse file tree 2 files changed +58
-2
lines changed
Expand file tree Collapse file tree 2 files changed +58
-2
lines changed Original file line number Diff line number Diff line change @@ -73,7 +73,6 @@ use crate::util::cache_lock::CacheLockMode;
7373use crate :: util:: errors:: CargoResult ;
7474use crate :: util:: CanonicalUrl ;
7575use anyhow:: Context as _;
76- use cargo_util_schemas:: manifest:: RustVersion ;
7776use std:: collections:: { HashMap , HashSet } ;
7877use tracing:: { debug, trace} ;
7978
@@ -304,7 +303,14 @@ pub fn resolve_with_previous<'gctx>(
304303 version_prefs. version_ordering ( VersionOrdering :: MinimumVersionsFirst )
305304 }
306305 if ws. resolve_honors_rust_version ( ) {
307- version_prefs. max_rust_version ( ws. rust_version ( ) . cloned ( ) . map ( RustVersion :: into_partial) ) ;
306+ let rust_version = if let Some ( ver) = ws. rust_version ( ) {
307+ ver. clone ( ) . into_partial ( )
308+ } else {
309+ let rustc = ws. gctx ( ) . load_global_rustc ( Some ( ws) ) ?;
310+ let rustc_version = rustc. version . clone ( ) . into ( ) ;
311+ rustc_version
312+ } ;
313+ version_prefs. max_rust_version ( Some ( rust_version) ) ;
308314 }
309315
310316 let avoid_patch_ids = if register_patches {
Original file line number Diff line number Diff line change @@ -370,6 +370,56 @@ fn dependency_rust_version_older_and_newer_than_package() {
370370 . run ( ) ;
371371}
372372
373+ #[ cargo_test]
374+ fn resolve_with_rustc ( ) {
375+ Package :: new ( "bar" , "1.5.0" )
376+ . rust_version ( "1.0" )
377+ . file ( "src/lib.rs" , "fn other_stuff() {}" )
378+ . publish ( ) ;
379+ Package :: new ( "bar" , "1.6.0" )
380+ . rust_version ( "1.2345" )
381+ . file ( "src/lib.rs" , "fn other_stuff() {}" )
382+ . publish ( ) ;
383+
384+ let p = project ( )
385+ . file (
386+ "Cargo.toml" ,
387+ r#"
388+ [package]
389+ name = "foo"
390+ version = "0.0.1"
391+ edition = "2015"
392+ authors = []
393+ [dependencies]
394+ bar = "1.0.0"
395+ "# ,
396+ )
397+ . file ( "src/main.rs" , "fn main(){}" )
398+ . build ( ) ;
399+
400+ p. cargo ( "generate-lockfile --ignore-rust-version" )
401+ . arg ( "-Zmsrv-policy" )
402+ . masquerade_as_nightly_cargo ( & [ "msrv-policy" ] )
403+ . with_stderr (
404+ "\
405+ [UPDATING] `dummy-registry` index
406+ [LOCKING] 2 packages
407+ " ,
408+ )
409+ . run ( ) ;
410+ p. cargo ( "generate-lockfile" )
411+ . arg ( "-Zmsrv-policy" )
412+ . masquerade_as_nightly_cargo ( & [ "msrv-policy" ] )
413+ . with_stderr (
414+ "\
415+ [UPDATING] `dummy-registry` index
416+ [LOCKING] 2 packages
417+ [ADDING] bar v1.5.0 (latest: v1.6.0)
418+ " ,
419+ )
420+ . run ( ) ;
421+ }
422+
373423#[ cargo_test]
374424fn dependency_rust_version_backtracking ( ) {
375425 Package :: new ( "has-rust-version" , "1.6.0" )
You can’t perform that action at this time.
0 commit comments