Skip to content

Commit d494502

Browse files
author
mejrs
committed
Fix tests
1 parent fe212ec commit d494502

File tree

4 files changed

+168
-160
lines changed

4 files changed

+168
-160
lines changed

compiler/rustc_macros/src/diagnostics/diagnostic.rs

+39-31
Original file line numberDiff line numberDiff line change
@@ -165,40 +165,48 @@ impl<'a> LintDiagnosticDerive<'a> {
165165
fn make_check(slug: &syn::Path) -> TokenStream {
166166
quote! {
167167
const _: () = {
168-
let krate = env!("CARGO_MANIFEST_DIR").as_bytes();
169-
170-
let mut start = 0;
171-
while !(krate[start] == b'r'
172-
&& krate[start + 1] == b'u'
173-
&& krate[start + 2] == b's'
174-
&& krate[start + 3] == b't'
175-
&& krate[start + 4] == b'c'
176-
&& krate[start + 5] == b'_')
168+
const krate_str: &str = match option_env!("CARGO_CRATE_NAME") {
169+
Some(c) => c,
170+
None => "",
171+
};
172+
const krate: &[u8] = krate_str.as_bytes();
173+
174+
if krate.len() > 6
175+
&& krate[0] == b'r'
176+
&& krate[1] == b'u'
177+
&& krate[2] == b's'
178+
&& krate[3] == b't'
179+
&& krate[4] == b'c'
180+
&& krate[5] == b'_'
177181
{
178-
if krate.len() == start + 5 {
179-
panic!(concat!("crate does not contain \"rustc_\": ", env!("CARGO_MANIFEST_DIR")));
180-
}
181-
start += 1;
182-
}
183-
start += 6;
184-
185-
let slug = stringify!(#slug).as_bytes();
186-
187-
let mut pos = 0;
188-
loop {
189-
let b = slug[pos];
190-
if krate.len() == start + pos {
191-
if b != b'_' {
192-
panic!(concat!("slug \"", stringify!(#slug), "\" does not match the crate (", env!("CARGO_MANIFEST_DIR") ,") it is in"));
182+
let slug = stringify!(#slug).as_bytes();
183+
184+
let mut pos = 0;
185+
loop {
186+
let b = slug[pos];
187+
if krate.len() == pos + 6 {
188+
if b != b'_' {
189+
panic!(concat!(
190+
"slug \"",
191+
stringify!(#slug),
192+
"\" does not match the crate it is in"
193+
));
194+
}
195+
break;
193196
}
194-
break
195-
}
196-
let a = krate[start+pos];
197-
198-
if a != b {
199-
panic!(concat!("slug \"", stringify!(#slug), "\" does not match the crate (", env!("CARGO_MANIFEST_DIR") ,") it is in"));
197+
let a = krate[pos + 6];
198+
199+
if a != b {
200+
panic!(concat!(
201+
"slug \"",
202+
stringify!(#slug),
203+
"\" does not match the crate it is in"
204+
));
205+
}
206+
pos += 1;
200207
}
201-
pos += 1;
208+
} else {
209+
// Crate does not start with "rustc_"
202210
}
203211
};
204212
}

src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ struct NoApplicability {
471471
}
472472

473473
#[derive(Subdiagnostic)]
474-
#[note(parser_add_paren)]
474+
#[note(parse_add_paren)]
475475
struct Note;
476476

477477
#[derive(Diagnostic)]

0 commit comments

Comments
 (0)