Skip to content

Commit c090c68

Browse files
committed
Auto merge of rust-lang#105125 - matthiaskrgr:rollup-fr0snmj, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - rust-lang#105078 (Fix `expr_to_spanned_string` ICE) - rust-lang#105087 (Extract llvm datalayout parsing out of spec module) - rust-lang#105088 (rustdoc: remove redundant CSS `div.desc { display: block }`) - rust-lang#105106 (Fix ICE from rust-lang#105101) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 367ecff + ee9eaa6 commit c090c68

File tree

10 files changed

+156
-100
lines changed

10 files changed

+156
-100
lines changed

compiler/rustc_abi/src/lib.rs

+96
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,102 @@ pub enum TargetDataLayoutErrors<'a> {
211211
}
212212

213213
impl TargetDataLayout {
214+
/// Parse data layout from an [llvm data layout string](https://llvm.org/docs/LangRef.html#data-layout)
215+
///
216+
/// This function doesn't fill `c_enum_min_size` and it will always be `I32` since it can not be
217+
/// determined from llvm string.
218+
pub fn parse_from_llvm_datalayout_string<'a>(
219+
input: &'a str,
220+
) -> Result<TargetDataLayout, TargetDataLayoutErrors<'a>> {
221+
// Parse an address space index from a string.
222+
let parse_address_space = |s: &'a str, cause: &'a str| {
223+
s.parse::<u32>().map(AddressSpace).map_err(|err| {
224+
TargetDataLayoutErrors::InvalidAddressSpace { addr_space: s, cause, err }
225+
})
226+
};
227+
228+
// Parse a bit count from a string.
229+
let parse_bits = |s: &'a str, kind: &'a str, cause: &'a str| {
230+
s.parse::<u64>().map_err(|err| TargetDataLayoutErrors::InvalidBits {
231+
kind,
232+
bit: s,
233+
cause,
234+
err,
235+
})
236+
};
237+
238+
// Parse a size string.
239+
let size = |s: &'a str, cause: &'a str| parse_bits(s, "size", cause).map(Size::from_bits);
240+
241+
// Parse an alignment string.
242+
let align = |s: &[&'a str], cause: &'a str| {
243+
if s.is_empty() {
244+
return Err(TargetDataLayoutErrors::MissingAlignment { cause });
245+
}
246+
let align_from_bits = |bits| {
247+
Align::from_bits(bits)
248+
.map_err(|err| TargetDataLayoutErrors::InvalidAlignment { cause, err })
249+
};
250+
let abi = parse_bits(s[0], "alignment", cause)?;
251+
let pref = s.get(1).map_or(Ok(abi), |pref| parse_bits(pref, "alignment", cause))?;
252+
Ok(AbiAndPrefAlign { abi: align_from_bits(abi)?, pref: align_from_bits(pref)? })
253+
};
254+
255+
let mut dl = TargetDataLayout::default();
256+
let mut i128_align_src = 64;
257+
for spec in input.split('-') {
258+
let spec_parts = spec.split(':').collect::<Vec<_>>();
259+
260+
match &*spec_parts {
261+
["e"] => dl.endian = Endian::Little,
262+
["E"] => dl.endian = Endian::Big,
263+
[p] if p.starts_with('P') => {
264+
dl.instruction_address_space = parse_address_space(&p[1..], "P")?
265+
}
266+
["a", ref a @ ..] => dl.aggregate_align = align(a, "a")?,
267+
["f32", ref a @ ..] => dl.f32_align = align(a, "f32")?,
268+
["f64", ref a @ ..] => dl.f64_align = align(a, "f64")?,
269+
[p @ "p", s, ref a @ ..] | [p @ "p0", s, ref a @ ..] => {
270+
dl.pointer_size = size(s, p)?;
271+
dl.pointer_align = align(a, p)?;
272+
}
273+
[s, ref a @ ..] if s.starts_with('i') => {
274+
let Ok(bits) = s[1..].parse::<u64>() else {
275+
size(&s[1..], "i")?; // For the user error.
276+
continue;
277+
};
278+
let a = align(a, s)?;
279+
match bits {
280+
1 => dl.i1_align = a,
281+
8 => dl.i8_align = a,
282+
16 => dl.i16_align = a,
283+
32 => dl.i32_align = a,
284+
64 => dl.i64_align = a,
285+
_ => {}
286+
}
287+
if bits >= i128_align_src && bits <= 128 {
288+
// Default alignment for i128 is decided by taking the alignment of
289+
// largest-sized i{64..=128}.
290+
i128_align_src = bits;
291+
dl.i128_align = a;
292+
}
293+
}
294+
[s, ref a @ ..] if s.starts_with('v') => {
295+
let v_size = size(&s[1..], "v")?;
296+
let a = align(a, s)?;
297+
if let Some(v) = dl.vector_align.iter_mut().find(|v| v.0 == v_size) {
298+
v.1 = a;
299+
continue;
300+
}
301+
// No existing entry, add a new one.
302+
dl.vector_align.push((v_size, a));
303+
}
304+
_ => {} // Ignore everything else.
305+
}
306+
}
307+
Ok(dl)
308+
}
309+
214310
/// Returns exclusive upper bound on object size.
215311
///
216312
/// The theoretical maximum object size is defined as the maximum positive `isize` value.

compiler/rustc_builtin_macros/src/deriving/default.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn extract_default_variant<'a>(
145145
let suggestion = default_variants
146146
.iter()
147147
.filter_map(|v| {
148-
if v.ident == variant.ident {
148+
if v.span == variant.span {
149149
None
150150
} else {
151151
Some((cx.sess.find_by_name(&v.attrs, kw::Default)?.span, String::new()))

compiler/rustc_expand/src/base.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_errors::{
1616
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
1717
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics};
1818
use rustc_parse::{self, parser, MACRO_ARGUMENTS};
19+
use rustc_session::errors::report_lit_error;
1920
use rustc_session::{parse::ParseSess, Limit, Session};
2021
use rustc_span::def_id::{CrateNum, DefId, LocalDefId};
2122
use rustc_span::edition::Edition;
@@ -1245,7 +1246,10 @@ pub fn expr_to_spanned_string<'a>(
12451246
Some((err, true))
12461247
}
12471248
Ok(ast::LitKind::Err) => None,
1248-
Err(_) => None,
1249+
Err(err) => {
1250+
report_lit_error(&cx.sess.parse_sess, err, token_lit, expr.span);
1251+
None
1252+
}
12491253
_ => Some((cx.struct_span_err(expr.span, err_msg), false)),
12501254
},
12511255
ast::ExprKind::Err => None,

compiler/rustc_session/src/errors.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ pub enum UnleashedFeatureHelp {
197197

198198
#[derive(Diagnostic)]
199199
#[diag(session_invalid_literal_suffix)]
200-
pub(crate) struct InvalidLiteralSuffix {
200+
pub(crate) struct InvalidLiteralSuffix<'a> {
201201
#[primary_span]
202202
#[label]
203203
pub span: Span,
204204
// FIXME(#100717)
205-
pub kind: String,
205+
pub kind: &'a str,
206206
pub suffix: Symbol,
207207
}
208208

@@ -311,11 +311,7 @@ pub fn report_lit_error(sess: &ParseSess, err: LitError, lit: token::Lit, span:
311311
LitError::LexerError => {}
312312
LitError::InvalidSuffix => {
313313
if let Some(suffix) = suffix {
314-
sess.emit_err(InvalidLiteralSuffix {
315-
span,
316-
kind: format!("{}", kind.descr()),
317-
suffix,
318-
});
314+
sess.emit_err(InvalidLiteralSuffix { span, kind: kind.descr(), suffix });
319315
}
320316
}
321317
LitError::InvalidIntSuffix => {

compiler/rustc_target/src/spec/mod.rs

+2-90
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@
3535
//! to the list specified by the target, rather than replace.
3636
3737
use crate::abi::call::Conv;
38-
use crate::abi::{
39-
AbiAndPrefAlign, AddressSpace, Align, Endian, Integer, Size, TargetDataLayout,
40-
TargetDataLayoutErrors,
41-
};
38+
use crate::abi::{Endian, Integer, Size, TargetDataLayout, TargetDataLayoutErrors};
4239
use crate::json::{Json, ToJson};
4340
use crate::spec::abi::{lookup as lookup_abi, Abi};
4441
use crate::spec::crt_objects::{CrtObjects, LinkSelfContainedDefault};
@@ -1322,92 +1319,7 @@ pub struct Target {
13221319

13231320
impl Target {
13241321
pub fn parse_data_layout<'a>(&'a self) -> Result<TargetDataLayout, TargetDataLayoutErrors<'a>> {
1325-
// Parse an address space index from a string.
1326-
let parse_address_space = |s: &'a str, cause: &'a str| {
1327-
s.parse::<u32>().map(AddressSpace).map_err(|err| {
1328-
TargetDataLayoutErrors::InvalidAddressSpace { addr_space: s, cause, err }
1329-
})
1330-
};
1331-
1332-
// Parse a bit count from a string.
1333-
let parse_bits = |s: &'a str, kind: &'a str, cause: &'a str| {
1334-
s.parse::<u64>().map_err(|err| TargetDataLayoutErrors::InvalidBits {
1335-
kind,
1336-
bit: s,
1337-
cause,
1338-
err,
1339-
})
1340-
};
1341-
1342-
// Parse a size string.
1343-
let size = |s: &'a str, cause: &'a str| parse_bits(s, "size", cause).map(Size::from_bits);
1344-
1345-
// Parse an alignment string.
1346-
let align = |s: &[&'a str], cause: &'a str| {
1347-
if s.is_empty() {
1348-
return Err(TargetDataLayoutErrors::MissingAlignment { cause });
1349-
}
1350-
let align_from_bits = |bits| {
1351-
Align::from_bits(bits)
1352-
.map_err(|err| TargetDataLayoutErrors::InvalidAlignment { cause, err })
1353-
};
1354-
let abi = parse_bits(s[0], "alignment", cause)?;
1355-
let pref = s.get(1).map_or(Ok(abi), |pref| parse_bits(pref, "alignment", cause))?;
1356-
Ok(AbiAndPrefAlign { abi: align_from_bits(abi)?, pref: align_from_bits(pref)? })
1357-
};
1358-
1359-
let mut dl = TargetDataLayout::default();
1360-
let mut i128_align_src = 64;
1361-
for spec in self.data_layout.split('-') {
1362-
let spec_parts = spec.split(':').collect::<Vec<_>>();
1363-
1364-
match &*spec_parts {
1365-
["e"] => dl.endian = Endian::Little,
1366-
["E"] => dl.endian = Endian::Big,
1367-
[p] if p.starts_with('P') => {
1368-
dl.instruction_address_space = parse_address_space(&p[1..], "P")?
1369-
}
1370-
["a", ref a @ ..] => dl.aggregate_align = align(a, "a")?,
1371-
["f32", ref a @ ..] => dl.f32_align = align(a, "f32")?,
1372-
["f64", ref a @ ..] => dl.f64_align = align(a, "f64")?,
1373-
[p @ "p", s, ref a @ ..] | [p @ "p0", s, ref a @ ..] => {
1374-
dl.pointer_size = size(s, p)?;
1375-
dl.pointer_align = align(a, p)?;
1376-
}
1377-
[s, ref a @ ..] if s.starts_with('i') => {
1378-
let Ok(bits) = s[1..].parse::<u64>() else {
1379-
size(&s[1..], "i")?; // For the user error.
1380-
continue;
1381-
};
1382-
let a = align(a, s)?;
1383-
match bits {
1384-
1 => dl.i1_align = a,
1385-
8 => dl.i8_align = a,
1386-
16 => dl.i16_align = a,
1387-
32 => dl.i32_align = a,
1388-
64 => dl.i64_align = a,
1389-
_ => {}
1390-
}
1391-
if bits >= i128_align_src && bits <= 128 {
1392-
// Default alignment for i128 is decided by taking the alignment of
1393-
// largest-sized i{64..=128}.
1394-
i128_align_src = bits;
1395-
dl.i128_align = a;
1396-
}
1397-
}
1398-
[s, ref a @ ..] if s.starts_with('v') => {
1399-
let v_size = size(&s[1..], "v")?;
1400-
let a = align(a, s)?;
1401-
if let Some(v) = dl.vector_align.iter_mut().find(|v| v.0 == v_size) {
1402-
v.1 = a;
1403-
continue;
1404-
}
1405-
// No existing entry, add a new one.
1406-
dl.vector_align.push((v_size, a));
1407-
}
1408-
_ => {} // Ignore everything else.
1409-
}
1410-
}
1322+
let mut dl = TargetDataLayout::parse_from_llvm_datalayout_string(&self.data_layout)?;
14111323

14121324
// Perform consistency checks against the Target information.
14131325
if dl.endian != self.endian {

src/librustdoc/html/static/css/rustdoc.css

-1
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,6 @@ so that we can apply CSS-filters to change the arrow color in themes */
894894
white-space: nowrap;
895895
text-overflow: ellipsis;
896896
overflow: hidden;
897-
display: block;
898897
}
899898

900899
.search-results a:hover,

src/test/ui/deriving/issue-105101.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// compile-flags: --crate-type=lib
2+
3+
#[derive(Default)] //~ ERROR multiple declared defaults
4+
enum E {
5+
#[default]
6+
A,
7+
#[default]
8+
A, //~ ERROR defined multiple times
9+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error: multiple declared defaults
2+
--> $DIR/issue-105101.rs:3:10
3+
|
4+
LL | #[derive(Default)]
5+
| ^^^^^^^
6+
...
7+
LL | A,
8+
| - first default
9+
LL | #[default]
10+
LL | A,
11+
| - additional default
12+
|
13+
= note: only one variant can be default
14+
= note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
15+
16+
error[E0428]: the name `A` is defined multiple times
17+
--> $DIR/issue-105101.rs:8:5
18+
|
19+
LL | A,
20+
| - previous definition of the type `A` here
21+
LL | #[default]
22+
LL | A,
23+
| ^ `A` redefined here
24+
|
25+
= note: `A` must be defined only once in the type namespace of this enum
26+
27+
error: aborting due to 2 previous errors
28+
29+
For more information about this error, try `rustc --explain E0428`.

src/test/ui/macros/issue-105011.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!(""y); //~ ERROR suffixes on string literals are invalid
3+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: suffixes on string literals are invalid
2+
--> $DIR/issue-105011.rs:2:14
3+
|
4+
LL | println!(""y);
5+
| ^^^ invalid suffix `y`
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)