File tree 2 files changed +37
-4
lines changed
2 files changed +37
-4
lines changed Original file line number Diff line number Diff line change @@ -142,6 +142,7 @@ fn attach_std_deps(
142
142
std_unit_deps : UnitGraph ,
143
143
) {
144
144
// Attach the standard library as a dependency of every target unit.
145
+ let mut found = false ;
145
146
for ( unit, deps) in state. unit_dependencies . iter_mut ( ) {
146
147
if !unit. kind . is_host ( ) && !unit. mode . is_run_custom_build ( ) {
147
148
deps. extend ( std_roots[ & unit. kind ] . iter ( ) . map ( |unit| UnitDep {
@@ -152,12 +153,16 @@ fn attach_std_deps(
152
153
public : true ,
153
154
noprelude : true ,
154
155
} ) ) ;
156
+ found = true ;
155
157
}
156
158
}
157
- // And also include the dependencies of the standard library itself.
158
- for ( unit, deps) in std_unit_deps. into_iter ( ) {
159
- if let Some ( other_unit) = state. unit_dependencies . insert ( unit, deps) {
160
- panic ! ( "std unit collision with existing unit: {:?}" , other_unit) ;
159
+ // And also include the dependencies of the standard library itself. Don't
160
+ // include these if no units actually needed the standard library.
161
+ if found {
162
+ for ( unit, deps) in std_unit_deps. into_iter ( ) {
163
+ if let Some ( other_unit) = state. unit_dependencies . insert ( unit, deps) {
164
+ panic ! ( "std unit collision with existing unit: {:?}" , other_unit) ;
165
+ }
161
166
}
162
167
}
163
168
}
Original file line number Diff line number Diff line change @@ -662,3 +662,31 @@ fn no_roots() {
662
662
. with_stderr_contains ( "[FINISHED] [..]" )
663
663
. run ( ) ;
664
664
}
665
+
666
+ #[ cargo_test]
667
+ fn proc_macro_only ( ) {
668
+ // Checks for a bug where it would panic if building a proc-macro only
669
+ let setup = match setup ( ) {
670
+ Some ( s) => s,
671
+ None => return ,
672
+ } ;
673
+ let p = project ( )
674
+ . file (
675
+ "Cargo.toml" ,
676
+ r#"
677
+ [package]
678
+ name = "pm"
679
+ version = "0.1.0"
680
+
681
+ [lib]
682
+ proc-macro = true
683
+ "# ,
684
+ )
685
+ . file ( "src/lib.rs" , "" )
686
+ . build ( ) ;
687
+ p. cargo ( "build" )
688
+ . build_std ( & setup)
689
+ . target_host ( )
690
+ . with_stderr_contains ( "[FINISHED] [..]" )
691
+ . run ( ) ;
692
+ }
You can’t perform that action at this time.
0 commit comments