@@ -26,6 +26,7 @@ use rustc_span::source_map::{BytePos, FilePathMapping, MultiSpan, SourceMap, Spa
26
26
use rustc_span:: { sym, FileName , Pos } ;
27
27
use std:: io;
28
28
use std:: ops:: Range ;
29
+ use std:: thread;
29
30
use url:: Url ;
30
31
31
32
declare_clippy_lint ! {
@@ -584,10 +585,10 @@ fn get_current_span(spans: &[(usize, Span)], idx: usize) -> (usize, Span) {
584
585
}
585
586
586
587
fn check_code ( cx : & LateContext < ' _ > , text : & str , edition : Edition , span : Span ) {
587
- fn has_needless_main ( code : & str , edition : Edition ) -> bool {
588
+ fn has_needless_main ( code : String , edition : Edition ) -> bool {
588
589
rustc_driver:: catch_fatal_errors ( || {
589
- rustc_span:: with_session_globals ( edition, || {
590
- let filename = FileName :: anon_source_code ( code) ;
590
+ rustc_span:: create_session_globals_then ( edition, || {
591
+ let filename = FileName :: anon_source_code ( & code) ;
591
592
592
593
let sm = Lrc :: new ( SourceMap :: new ( FilePathMapping :: empty ( ) ) ) ;
593
594
let emitter = EmitterWriter :: new ( box io:: sink ( ) , None , false , false , false , None , false ) ;
@@ -649,7 +650,10 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
649
650
. unwrap_or_default ( )
650
651
}
651
652
652
- if has_needless_main ( text, edition) {
653
+ // Because of the global session, we need to create a new session in a different thread with
654
+ // the edition we need.
655
+ let text = text. to_owned ( ) ;
656
+ if thread:: spawn ( move || has_needless_main ( text, edition) ) . join ( ) . expect ( "thread::spawn failed" ) {
653
657
span_lint ( cx, NEEDLESS_DOCTEST_MAIN , span, "needless `fn main` in doctest" ) ;
654
658
}
655
659
}
0 commit comments