Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #70688

Closed
wants to merge 12 commits into from
4 changes: 2 additions & 2 deletions src/doc/unstable-book/src/language-features/generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Feedback on the design and usage is always appreciated!

The `Generator` trait in `std::ops` currently looks like:

```
```rust
# #![feature(arbitrary_self_types, generator_trait)]
# use std::ops::GeneratorState;
# use std::pin::Pin;
Expand All @@ -107,7 +107,7 @@ point for executing the `Generator` itself.

The return value of `resume`, `GeneratorState`, looks like:

```
```rust
pub enum GeneratorState<Y, R> {
Yielded(Y),
Complete(R),
Expand Down
8 changes: 8 additions & 0 deletions src/libcore/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#![stable(feature = "rust1", since = "1.0.0")]

use crate::fmt;
use crate::hash::{Hash, Hasher};

mod num;

Expand Down Expand Up @@ -746,3 +747,10 @@ impl From<!> for Infallible {
x
}
}

#[stable(feature = "convert_infallible_hash", since = "1.44.0")]
impl Hash for Infallible {
fn hash<H: Hasher>(&self, _: &mut H) {
match *self {}
}
}
9 changes: 8 additions & 1 deletion src/librustc_lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ pub enum LiteralKind {
pub struct UnvalidatedRawStr {
/// The prefix (`r###"`) is valid
valid_start: bool,

/// The postfix (`"###`) is valid
valid_end: bool,

/// The number of leading `#`
n_start_hashes: usize,
/// The number of trailing `#`. `n_end_hashes` <= `n_start_hashes`
Expand Down Expand Up @@ -197,7 +201,7 @@ impl UnvalidatedRawStr {
let n_start_safe: u16 =
self.n_start_hashes.try_into().map_err(|_| LexRawStrError::TooManyDelimiters)?;

if self.n_start_hashes > self.n_end_hashes {
if self.n_start_hashes > self.n_end_hashes || !self.valid_end {
Err(LexRawStrError::NoTerminator {
expected: self.n_start_hashes,
found: self.n_end_hashes,
Expand Down Expand Up @@ -687,6 +691,7 @@ impl Cursor<'_> {
_ => {
return UnvalidatedRawStr {
valid_start,
valid_end: false,
n_start_hashes,
n_end_hashes: 0,
possible_terminator_offset,
Expand All @@ -702,6 +707,7 @@ impl Cursor<'_> {
if self.is_eof() {
return UnvalidatedRawStr {
valid_start,
valid_end: false,
n_start_hashes,
n_end_hashes: max_hashes,
possible_terminator_offset,
Expand All @@ -727,6 +733,7 @@ impl Cursor<'_> {
if n_end_hashes == n_start_hashes {
return UnvalidatedRawStr {
valid_start,
valid_end: true,
n_start_hashes,
n_end_hashes,
possible_terminator_offset: None,
Expand Down
27 changes: 27 additions & 0 deletions src/librustc_lexer/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mod tests {
n_start_hashes: 0,
n_end_hashes: 0,
valid_start: true,
valid_end: true,
possible_terminator_offset: None,
},
Ok(ValidatedRawStr { n_hashes: 0 }),
Expand All @@ -37,6 +38,7 @@ mod tests {
n_start_hashes: 0,
n_end_hashes: 0,
valid_start: true,
valid_end: true,
possible_terminator_offset: None,
},
Ok(ValidatedRawStr { n_hashes: 0 }),
Expand All @@ -51,6 +53,7 @@ mod tests {
UnvalidatedRawStr {
n_start_hashes: 1,
n_end_hashes: 1,
valid_end: true,
valid_start: true,
possible_terminator_offset: None,
},
Expand All @@ -65,6 +68,7 @@ mod tests {
UnvalidatedRawStr {
n_start_hashes: 1,
n_end_hashes: 0,
valid_end: false,
valid_start: true,
possible_terminator_offset: None,
},
Expand All @@ -80,6 +84,7 @@ mod tests {
n_start_hashes: 2,
n_end_hashes: 1,
valid_start: true,
valid_end: false,
possible_terminator_offset: Some(7),
},
Err(LexRawStrError::NoTerminator {
Expand All @@ -95,6 +100,7 @@ mod tests {
n_start_hashes: 2,
n_end_hashes: 0,
valid_start: true,
valid_end: false,
possible_terminator_offset: None,
},
Err(LexRawStrError::NoTerminator {
Expand All @@ -113,9 +119,30 @@ mod tests {
n_start_hashes: 1,
n_end_hashes: 0,
valid_start: false,
valid_end: false,
possible_terminator_offset: None,
},
Err(LexRawStrError::InvalidStarter),
);
}

#[test]
fn test_unterminated_no_pound() {
// https://github.com/rust-lang/rust/issues/70677
check_raw_str(
r#"""#,
UnvalidatedRawStr {
n_start_hashes: 0,
n_end_hashes: 0,
valid_start: true,
valid_end: false,
possible_terminator_offset: None,
},
Err(LexRawStrError::NoTerminator {
expected: 0,
found: 0,
possible_terminator_offset: None,
}),
);
}
}
52 changes: 26 additions & 26 deletions src/librustc_metadata/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}

fn maybe_kind(&self, item_id: DefIndex) -> Option<EntryKind> {
self.root.per_def.kind.get(self, item_id).map(|k| k.decode(self))
self.root.tables.kind.get(self, item_id).map(|k| k.decode(self))
}

fn kind(&self, item_id: DefIndex) -> EntryKind {
Expand Down Expand Up @@ -665,7 +665,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.expect("no name in item_ident");
let span = self
.root
.per_def
.tables
.ident_span
.get(self, item_index)
.map(|data| data.decode((self, sess)))
Expand All @@ -688,7 +688,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}

fn get_span(&self, index: DefIndex, sess: &Session) -> Span {
self.root.per_def.span.get(self, index).unwrap().decode((self, sess))
self.root.tables.span.get(self, index).unwrap().decode((self, sess))
}

fn load_proc_macro(&self, id: DefIndex, sess: &Session) -> SyntaxExtension {
Expand Down Expand Up @@ -781,7 +781,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
ctor_did,
data.discr,
self.root
.per_def
.tables
.children
.get(self, index)
.unwrap_or(Lazy::empty())
Expand Down Expand Up @@ -812,7 +812,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {

let variants = if let ty::AdtKind::Enum = adt_kind {
self.root
.per_def
.tables
.children
.get(self, item_id)
.unwrap_or(Lazy::empty())
Expand All @@ -831,7 +831,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
item_id: DefIndex,
tcx: TyCtxt<'tcx>,
) -> ty::GenericPredicates<'tcx> {
self.root.per_def.explicit_predicates.get(self, item_id).unwrap().decode((self, tcx))
self.root.tables.explicit_predicates.get(self, item_id).unwrap().decode((self, tcx))
}

fn get_inferred_outlives(
Expand All @@ -840,7 +840,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
tcx: TyCtxt<'tcx>,
) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
self.root
.per_def
.tables
.inferred_outlives
.get(self, item_id)
.map(|predicates| predicates.decode((self, tcx)))
Expand All @@ -852,31 +852,31 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
item_id: DefIndex,
tcx: TyCtxt<'tcx>,
) -> ty::GenericPredicates<'tcx> {
self.root.per_def.super_predicates.get(self, item_id).unwrap().decode((self, tcx))
self.root.tables.super_predicates.get(self, item_id).unwrap().decode((self, tcx))
}

fn get_generics(&self, item_id: DefIndex, sess: &Session) -> ty::Generics {
self.root.per_def.generics.get(self, item_id).unwrap().decode((self, sess))
self.root.tables.generics.get(self, item_id).unwrap().decode((self, sess))
}

fn get_type(&self, id: DefIndex, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
self.root.per_def.ty.get(self, id).unwrap().decode((self, tcx))
self.root.tables.ty.get(self, id).unwrap().decode((self, tcx))
}

fn get_stability(&self, id: DefIndex) -> Option<attr::Stability> {
match self.is_proc_macro(id) {
true => self.root.proc_macro_stability,
false => self.root.per_def.stability.get(self, id).map(|stab| stab.decode(self)),
false => self.root.tables.stability.get(self, id).map(|stab| stab.decode(self)),
}
}

fn get_const_stability(&self, id: DefIndex) -> Option<attr::ConstStability> {
self.root.per_def.const_stability.get(self, id).map(|stab| stab.decode(self))
self.root.tables.const_stability.get(self, id).map(|stab| stab.decode(self))
}

fn get_deprecation(&self, id: DefIndex) -> Option<attr::Deprecation> {
self.root
.per_def
.tables
.deprecation
.get(self, id)
.filter(|_| !self.is_proc_macro(id))
Expand All @@ -886,7 +886,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
fn get_visibility(&self, id: DefIndex) -> ty::Visibility {
match self.is_proc_macro(id) {
true => ty::Visibility::Public,
false => self.root.per_def.visibility.get(self, id).unwrap().decode(self),
false => self.root.tables.visibility.get(self, id).unwrap().decode(self),
}
}

Expand Down Expand Up @@ -914,7 +914,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}

fn get_impl_trait(&self, id: DefIndex, tcx: TyCtxt<'tcx>) -> Option<ty::TraitRef<'tcx>> {
self.root.per_def.impl_trait_ref.get(self, id).map(|tr| tr.decode((self, tcx)))
self.root.tables.impl_trait_ref.get(self, id).map(|tr| tr.decode((self, tcx)))
}

/// Iterates over all the stability attributes in the given crate.
Expand Down Expand Up @@ -984,7 +984,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {

// Iterate over all children.
let macros_only = self.dep_kind.lock().macros_only();
let children = self.root.per_def.children.get(self, id).unwrap_or(Lazy::empty());
let children = self.root.tables.children.get(self, id).unwrap_or(Lazy::empty());
for child_index in children.decode((self, sess)) {
if macros_only {
continue;
Expand All @@ -1004,7 +1004,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
EntryKind::ForeignMod => {
let child_children = self
.root
.per_def
.tables
.children
.get(self, child_index)
.unwrap_or(Lazy::empty());
Expand All @@ -1016,7 +1016,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
vis: self.get_visibility(child_index),
span: self
.root
.per_def
.tables
.span
.get(self, child_index)
.unwrap()
Expand Down Expand Up @@ -1096,13 +1096,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}

fn is_item_mir_available(&self, id: DefIndex) -> bool {
!self.is_proc_macro(id) && self.root.per_def.mir.get(self, id).is_some()
!self.is_proc_macro(id) && self.root.tables.mir.get(self, id).is_some()
}

fn get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> BodyAndCache<'tcx> {
let mut cache = self
.root
.per_def
.tables
.mir
.get(self, id)
.filter(|_| !self.is_proc_macro(id))
Expand All @@ -1121,7 +1121,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
) -> IndexVec<Promoted, BodyAndCache<'tcx>> {
let mut cache = self
.root
.per_def
.tables
.promoted_mir
.get(self, id)
.filter(|_| !self.is_proc_macro(id))
Expand Down Expand Up @@ -1172,7 +1172,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}

fn get_item_variances(&self, id: DefIndex) -> Vec<ty::Variance> {
self.root.per_def.variances.get(self, id).unwrap_or(Lazy::empty()).decode(self).collect()
self.root.tables.variances.get(self, id).unwrap_or(Lazy::empty()).decode(self).collect()
}

fn get_ctor_kind(&self, node_id: DefIndex) -> CtorKind {
Expand Down Expand Up @@ -1209,7 +1209,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {

Lrc::from(
self.root
.per_def
.tables
.attributes
.get(self, item_id)
.unwrap_or(Lazy::empty())
Expand All @@ -1220,7 +1220,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {

fn get_struct_field_names(&self, id: DefIndex, sess: &Session) -> Vec<Spanned<ast::Name>> {
self.root
.per_def
.tables
.children
.get(self, id)
.unwrap_or(Lazy::empty())
Expand All @@ -1236,7 +1236,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
) -> &'tcx [DefId] {
tcx.arena.alloc_from_iter(
self.root
.per_def
.tables
.inherent_impls
.get(self, id)
.unwrap_or(Lazy::empty())
Expand Down Expand Up @@ -1416,7 +1416,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}

fn fn_sig(&self, id: DefIndex, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'tcx> {
self.root.per_def.fn_sig.get(self, id).unwrap().decode((self, tcx))
self.root.tables.fn_sig.get(self, id).unwrap().decode((self, tcx))
}

#[inline]
Expand Down
Loading