@@ -571,15 +571,27 @@ pub fn find_crate_name(sess: Option<&Session>,
571
571
} ;
572
572
573
573
// Look in attributes 100% of the time to make sure the attribute is marked
574
- // as used. After doing this, however, favor crate names from the command
575
- // line.
574
+ // as used. After doing this, however, we still prioritize a crate name from
575
+ // the command line over one found in the #[crate_name] attribute. If we
576
+ // find both we ensure that they're the same later on as well.
576
577
let attr_crate_name = attrs. iter ( ) . find ( |at| at. check_name ( "crate_name" ) )
577
578
. and_then ( |at| at. value_str ( ) . map ( |s| ( at, s) ) ) ;
578
579
579
580
match sess {
580
581
Some ( sess) => {
581
582
match sess. opts . crate_name {
582
- Some ( ref s) => return validate ( s. clone ( ) , None ) ,
583
+ Some ( ref s) => {
584
+ match attr_crate_name {
585
+ Some ( ( attr, ref name) ) if s. as_slice ( ) != name. get ( ) => {
586
+ let msg = format ! ( "--crate-name and #[crate_name] \
587
+ are required to match, but `{}` \
588
+ != `{}`", s, name) ;
589
+ sess. span_err ( attr. span , msg. as_slice ( ) ) ;
590
+ }
591
+ _ => { } ,
592
+ }
593
+ return validate ( s. clone ( ) , None ) ;
594
+ }
583
595
None => { }
584
596
}
585
597
}
@@ -1547,7 +1559,7 @@ fn add_upstream_rust_crates(cmd: &mut Command, sess: &Session,
1547
1559
add_dynamic_crate ( cmd, sess, src. dylib . unwrap ( ) )
1548
1560
}
1549
1561
cstore:: RequireStatic => {
1550
- add_static_crate ( cmd, sess, tmpdir, cnum , src. rlib . unwrap ( ) )
1562
+ add_static_crate ( cmd, sess, tmpdir, src. rlib . unwrap ( ) )
1551
1563
}
1552
1564
}
1553
1565
@@ -1564,7 +1576,7 @@ fn add_upstream_rust_crates(cmd: &mut Command, sess: &Session,
1564
1576
1565
1577
// Adds the static "rlib" versions of all crates to the command line.
1566
1578
fn add_static_crate ( cmd : & mut Command , sess : & Session , tmpdir : & Path ,
1567
- cnum : ast :: CrateNum , cratepath : Path ) {
1579
+ cratepath : Path ) {
1568
1580
// When performing LTO on an executable output, all of the
1569
1581
// bytecode from the upstream libraries has already been
1570
1582
// included in our object file output. We need to modify all of
@@ -1580,7 +1592,8 @@ fn add_upstream_rust_crates(cmd: &mut Command, sess: &Session,
1580
1592
// If we're not doing LTO, then our job is simply to just link
1581
1593
// against the archive.
1582
1594
if sess. lto ( ) {
1583
- let name = sess. cstore . get_crate_data ( cnum) . name . clone ( ) ;
1595
+ let name = cratepath. filename_str ( ) . unwrap ( ) ;
1596
+ let name = name. slice ( 3 , name. len ( ) - 5 ) ; // chop off lib/.rlib
1584
1597
time ( sess. time_passes ( ) ,
1585
1598
format ! ( "altering {}.rlib" , name) . as_slice ( ) ,
1586
1599
( ) , |( ) | {
0 commit comments