Skip to content

Range is not a lang item #53720

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

Closed
bjorn3 opened this issue Aug 26, 2018 · 3 comments
Closed

Range is not a lang item #53720

bjorn3 opened this issue Aug 26, 2018 · 3 comments
Labels
A-lang-item Area: Language items C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bjorn3
Copy link
Member

bjorn3 commented Aug 26, 2018

#[doc(alias = "..")]
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Range<Idx> {
/// The lower bound of the range (inclusive).
#[stable(feature = "rust1", since = "1.0.0")]
pub start: Idx,
/// The upper bound of the range (exclusive).
#[stable(feature = "rust1", since = "1.0.0")]
pub end: Idx,
}

Rustc always lowers it to ::ops::Range.

ExprKind::Range(ref e1, ref e2, lims) => {
use syntax::ast::RangeLimits::*;
let path = match (e1, e2, lims) {
(&None, &None, HalfOpen) => "RangeFull",
(&Some(..), &None, HalfOpen) => "RangeFrom",
(&None, &Some(..), HalfOpen) => "RangeTo",
(&Some(..), &Some(..), HalfOpen) => "Range",
(&None, &Some(..), Closed) => "RangeToInclusive",
(&Some(..), &Some(..), Closed) => unreachable!(),
(_, &None, Closed) => self.diagnostic()
.span_fatal(e.span, "inclusive range with no end")
.raise(),
};
let fields = e1.iter()
.map(|e| ("start", e))
.chain(e2.iter().map(|e| ("end", e)))
.map(|(s, e)| {
let expr = P(self.lower_expr(&e));
let ident = Ident::new(Symbol::intern(s), e.span);
self.field(ident, expr, e.span)
})
.collect::<P<[hir::Field]>>();
let is_unit = fields.is_empty();
let struct_path = iter::once("ops")
.chain(iter::once(path))
.collect::<Vec<_>>();

Found some more lowerings like this

let path = &["ops", "Try", "into_result"];

let path = &["ops", "Try", method];

let ty_path = P(self.std_path(e.span, &["ops", "RangeInclusive"], None, false));

They should probably be a lang item.

@Centril Centril added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 27, 2018
@kennytm kennytm added the C-cleanup Category: PRs that clean code up or issues documenting cleanup. label Aug 27, 2018
@durka
Copy link
Contributor

durka commented Aug 27, 2018

Related to #20541.

@varkor varkor added the A-lang-item Area: Language items label May 8, 2019
@Mark-Simulacrum
Copy link
Member

This is still the case today, though is a bit harder to grep for as rustc uses symbols now for the elements, e.g.,

&[sym::ops, sym::RangeInclusive],

@davidtwco
Copy link
Member

Closing, fixed by #75145.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lang-item Area: Language items C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants